JuliaReach / Reachability.jl

Reachability and Safety of Nondeterministic Dynamical Systems
MIT License
50 stars 4 forks source link

#632 - Namespace conflict with TaylorSeries.update! #667

Closed schillic closed 4 years ago

schillic commented 4 years ago

Closes #632.

The problem here was that both ProgressMeter and TaylorSeries export update!, so we had to use import instead of using for one of those packages.

Since we use ProgressMeter.update! but not TaylorSeries.update!, I thought that we should use import TaylorSeries and explicitly add the functions from TaylorSeries that we use. While trying this, I discovered an issue with Requires which I want to share here.

TaylorSeries also exports normalize_taylor, but that function only becomes visible after loading IntervalArithmetic via Requires. This can be seen as follows:

julia> using TaylorSeries

julia> normalize_taylor
ERROR: UndefVarError: normalize_taylor not defined

julia> import IntervalArithmetic

julia> normalize_taylor
normalize_taylor (generic function with 4 methods)

So I tried the following in Reachability:

julia> import IntervalArithmetic, TaylorSeries

julia> using TaylorSeries: normalize_taylor, ...

While this works perfectly in the REPL, loading this from within a module crashes in the precompilation. The reason is that Requires defers the loading to a queue and processes that queue only after the current command. Since "the current command" here is "precompile the module", the precompilation must finish before the extra code is loaded. And this means that TaylorSeries.normalize_taylor is not visible at that time. (This can be tested by adding a print output to the @require command in TaylorSeries.)

So I ended up with import ProgressMeter and writing ProgressMeter.update! everywhere. Note that ultimately there is no way around this and using MyPackage is only a convenience functionality to avoid spelling out the package in most cases.

mforets commented 4 years ago

Got it, thanks a lot for the in-depth explanation.