SymbolicML/DynamicQuantities.jl

u"Ω" errors in precompilation

YingboMa opened this issue · 6 comments

MWE: write the literalu"Ω" in a package that precompiles.

caused by: LoadError: Evaluation into the closed module `UnitsParse` breaks incremental compilation because the side effects will not be permanent. This is likely due to some other module mutating `UnitsParse` with `eval` during precompilation - don't do this.
Stacktrace:
  [1] eval
    @ Core ./boot.jl:385 [inlined]
  [2] eval
    @ DynamicQuantities.UnitsParse ~/.julia/packages/DynamicQuantities/5QflN/src/uparse.jl:1 [inlined]
  [3] uparse(s::String)
    @ DynamicQuantities.UnitsParse ~/.julia/packages/DynamicQuantities/5QflN/src/uparse.jl:37
  [4] var"@u_str"(__source__::LineNumberNode, __module__::Module, s::Any)
    @ DynamicQuantities.UnitsParse ~/.julia/packages/DynamicQuantities/5QflN/src/uparse.jl:57
...

As a quick fix you could do import DynamicQuantities.Units: Ω (or .SymbolicUnits: Ω) and work with the symbols directly.

It's weird that precompilation doesn't like the string version. Does anything in that module jump out to you? This is the file:

module UnitsParse

It's probably due to the eval in

return as_quantity(eval(Meta.parse(s)))::DEFAULT_QUANTITY_TYPE

Oh I see. What other options are there for implementing this?

You can evaluate the expression yourself instead of eval.

Ah. Of course 🤦‍♂️

Thanks, will fix.

I guess we’ll need to do something a bit more complex like https://github.com/PainterQubits/Unitful.jl/blob/a09bdaac255d456e6315b77979a48956aca1d3a3/src/user.jl#L692 to get this working without eval.

Working on this in #106.

Edit: fixed!