-
-
Notifications
You must be signed in to change notification settings - Fork 89
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
Revisit reify "one class with all interfaces" #549
Comments
Thinking here, patching would have an issue with third-part code, would be unsustainable for Babashka to patch those. |
Yes, that's what I meant with "since there might be native functions in babashka which do the instance checks manually". As a last resort, we could make a preselection of common groups. Most reify usage only uses one class at a time, with exceptions like your smart map case. So we could make groups for individual Java classes like FileFilter or whatnot and then the collection-like interfaces in one group which you then must all implement. Then we are basically back to the previous approach, but with less groups. |
If we go with preselected groups, for e.g. smart maps, and pathom3 is using this, but meanwhile babashka decides to add one more interface to this group, then pathom3 will break. So the "last resort" might not be feasible either. I'm starting to think it might be better to drop all support for reify, except for protocols, unless we have a better answer. |
Been thinking but haven't got much with promise.
😬 nothing great, I'll keep thinking. |
Looking at the Graal issue:
Doesn't this also mean you have to decide which classes you want to create dynamically at compile time? About pods: this won't help much, because all pods do is send data back and forth. You can't create new classes from some data. If this were true, then we would have already solution. Maybe it's good to think about the impact of potential bugs. The current approach leads to false positives with instance checks in core or other library functions. And this could be followed by a potential "not implemented" exception at runtime. Is this worse than not supporting reify at all? |
Yeah, I do agree that it's not worth supporting in the current state for the bug risk. (Re-reading, agree that the graal PR wouldn't help) |
I posted this in the native-image channel of the GraalVM slack community:
|
Thought from Slack: 4:18 PM |
The direction I want to go next: Support code that was supported before 0.2.13: clj-commons/fs uses reify with one interface. In general I want to support just one interface at a time for now since that is the most common use case of reify and is better than having nothing. For pathom3, I want to investigate if we can add proxy + APersistentMap like described in this blog post: |
Another thought: Note that
in the sense that they return true for instance checks while not all methods are implemented.
This is similar to our |
Thank you very much for digging into this. Do you think we could also have a way to make a custom MapEntry? I don't see an abstract protocol for that, this is why I wonder. |
@wilkerlucio Actually I think it might be better to migrate to See babashka master:
|
Implementing reify has the restriction on GraalVM that we cannot generate new Java classes at runtime. So we have to do this at compile time.
Previous approach: generate classes for each subset of supported interfaces.
Problem: combinatorial explosion of combinations.
Current approach: one class that implements all interfaces which then "proxies" to the user-defined functions, or throws an exception "not implemented".
The current approach has the problem that all reified objects are "Seqable", "clojure.lang.IFn", etc. But when passing this to functions like
seqable?
orifn?
you will always get true, which might result in some very weird bugs.Possible solutions:
The text was updated successfully, but these errors were encountered: