When using the --trim functionality, it quickly becomes inconvenient to always write the io to be Core.stdout when the non-trimmable Base.stdout was so convient as the default parameter (I focus here on stdout, but the same goes for stderr).
So how can we use Core.stdout as default in programs which will be trimmed?
We can make use of world age and overwrite the corresponding functions from within our app module:
module MyApp
Base.print(x) = Base.print(Core.stdout, x)
Base.display(x) = Base.display(Core.stdout |> TextDisplay, x)
[…]
From now on we can write
print(5)
display(5)
while still being trimmable. This is nice, but only a fraction of the methods which need to be overwritten. Ah, and this leads to a direct dependency on a specific Julia patch version and to a lot of test cases you should implement, because this is worse than type piracy. How do you call this? Type terrorism?
Is there a more complete way to achieve this? The root cause is that Base.stdout needs to get the “correct” type (i.e. what it actually has and not the abstract IO).
- Could we somehow list the
Unionof types whichBase.stdoutactually can have and tell Julia to union-split/world-split until thisUnionis covered? - Can we somehow change the type of
Base.stdouttoCore.CoreSTDOUT? - Can we somehow alias
Base.stdoutto point toCore.stdout? - Can we introduce a command line flag to Julia to implement something like this?
module MyApp
Core.eval(Base, :(stdout = Core.stdout))
[…]
does not work (“Evaluation into the closed module Base breaks incremental compilation because the side effects will not be permanent. This is likely due to some other module mutating Base with eval during precompilation - don’t do this”). Julia is certainly right with “don’t do this”, but for trimmed compilation a problem with precompilation seems to be acceptable and this would be convenient.
Any ideas how to get trimmability and convenience?