-
-
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
WIP Generalize Fix1 and Fix2 #36180
WIP Generalize Fix1 and Fix2 #36180
Conversation
Co-authored-by: Takafumi Arakaki <takafumi.a@gmail.com>
BTW, (But the implementation itself LGTM so maybe it's nice to share this as a package.) |
OK, I commented in the issue. |
I think even if functions in |
This makes me nervous (mostly in terms of compiler performance), since it uses something very general and complex to implement something very simple and low-level. I don't have an easy answer though. |
I think I understand the nervousness but I don't understand the details. This might not help me get a better sense, but I'll try to ask a question. If there were an abstract type Then you could avoid the structural recursion in Then would that be more or less general/complex/low-level/simple? |
This would also be very useful for long-term serialization of objects containing partial function applications. Anonymous functions get temporary symbols, which break if you deserialize from a context where the owning module has fewer/more anonymous functions defined than at serialization time. So your deserialization can fail even if all you did was add a completely unrelated function that contains an anonymous function definition to the package. This happens for JLD2, which is for long term storage, and obviously also for julia serialization, which is not. With this PR, you can replace enclosed anonymous functions with One domain where you're likely to want to long-term-serialize objects is machine learning, where you've trained a model for a long time and want to use it months later; models often contain anonymous data reshaping/wrangling functions. |
@kolia there is registered package https://github.com/goretkin/FixArgs.jl . It would be great if you could see if it is suitable for (de-)serialization. |
Yup, both The main issue for long-term serialization is the gensymming, because the gensymmed names are all that julia's serializer and JLD2 store, and that is fragile; adding unrelated code to the module often changes existing gensymmed names. [It doesn't have to be this way though, a serializer could be implemented that serializes anonymous functions themselves instead of just references to their names. |
Replaced by #54653 |
I have wanted a generalized version of Fix1 and Fix2 that allows binding any pattern of positional arguments. I think something like the implementation in this PR should be a drop-in replacement.
But I'm having trouble trying it out because I am getting an error during compilation
I tried allowing
pred.x
by defining thegetproperty
method, but I got a different error during compilation: "cannot add methods to a builtin function". Perhapsgetproperty
during bootstrapping andgetproperty
in the runtime are different. That is fine, since the occurances of e.g.pred.x
inBase
can be fixed, and thegetproperty
method can be used for a deprecation cycle.