-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
julep: conditional modules #6195
Comments
Using modules to delimit optional code seems like a potentially very good idea. |
I was mentally going over similar ground yesterday. Would it be reasonable to declare that interacting code can't be loaded until after the types are defined? |
Very similar to #2025 I do not get the crucial point here. Why does anything need to be reloaded? I would assume that most of this could be solved with a |
The comment about reloading would only be triggered in the case where the user replaced the module. However, perhaps that condition does not need to be defined. Using modules to define the separation allows Julia to pre-compile and cache the results (in the future). Thus, it is almost just as flexible, but it can be optimized to be fast. |
I wonder if parametric modules are relevant here. Consider that |
@StefanKarpinski that sounds rather clever. however, who would be responsible for instantiating the necessarily templates? |
Julia? |
I mean, how would Julia know which templates to instantiate if the user wrote:
what is |
That would be up to the user. If they wrote |
What's the reasoning of using modules for optional code vs. arbitrary blocks of code? Something like: when A
using A
# do stuff with module A
# define functions, call methods, optionally wrap them in a module, etc.
elsewhen B
using B
# if A isn't loaded, but B is; do stuff with B
else
# fallback if A or B can't be found; could just throw a "Need A or B error"
end There's probably some good implementation detail to require modules, but I can imagine there are a lot of cases where you really only need a few lines, so not needing the submodule would be convenient. |
this is all covered in the discussion on the pull-request thread |
I've run into a use case which could really benefit from conditional package loading in JuliaLinearAlgebra/IterativeSolvers.jl#35 |
Any progress on this topic? I really feel the need for conditional imports :) |
I've been wanting this to be merged for about six months now. |
Requires.jl is a very nice stop-gap that has worked well for my purposes. |
What's standing in its way? I'm having trouble seeing how your pull request helps my issue. Basically I have a module |
@vtjnash, have you abandoned this issue? You haven't commented on it since almost a year ago. |
not entirely, i was just finally getting back to even older issues (#2818) and have no shortage of other unresolved proposals (https://github.com/JuliaLang/julia/pulls/vtjnash) |
Yeah. We had to break out a bunch of things into a separate module in order to keep LightGraphs from imploding due to fragility issues with all the dependencies. We also now have a policy in place with respect to PRs that severely restricts what we allow in LightGraphs now (not a good thing):
Conditional dependencies would go a long way to reducing the problems of "dependence fragility" within Julia packages. (We don't want to get to a point where Node found itself a few months back.) |
#15705 is the latest thinking. needs an implementation that ties into precompilation correctly. in the meantime, when it comes to conditional dependencies, either disable precompilation or don't do things conditionally. Make separate packages for features that have additional dependencies that won't always be needed by a "main" package. |
The latest latest thinking (based on a discussion @JeffBezanson, @vtjnash and I had last week), is that what we want is very similar to what I originally proposed in #2025 – i.e. have a mechanism whereby packages, when they're loaded, can register a module for later loading once some set of modules have all been loaded. Note that if you want code for A that depends on both B and C then you'll want to wait until all of A, B and C have been loaded, so this isn't just a binary relation. |
This is the "Requires" model, and if that was built-in and played well with The other use case is when you want to do something only when a package is I think both uses would share the tricky parts of the implementation, On Tuesday, October 11, 2016, Stefan Karpinski notifications@github.com
|
The problem we had with |
But wasn't that because Requires was an external hack to try to get the functionality we wanted? If this was built into the core of the language, presumably macros could be deferred until they were ready to be run. |
A bit more on @StefanKarpinski 's description above: #15705 (comment) |
I see this has been moved to a 1.0 milestone, so I presume this is a way off now, but is it still in someone's plans, because it would be incredibly useful! |
Yes, we really need this in 1.0 – it's a big problem for the package ecosystem currently. |
Good to know, thanks. |
@StefanKarpinski So does this mean conditional modules are not going into 1.0 any more? Or are they already implemented somewhere? |
currently, some modules (incorrectly and unfortunately) use
Pkg.installed
to decide whether it should include some additional functionality. I would like to propose the following extension to module initialization that could help simplify this situation of optional dependencies:Rules:
__init__
functions have run, any modules that declaredmodule B require Main.C
will be (re-)loaded.Example:
The text was updated successfully, but these errors were encountered: