-
Notifications
You must be signed in to change notification settings - Fork 323
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
Make extension method resolution deterministic #9844
Conversation
Now, it tests all the shadowing, not only extension methods.
…s from imported modules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you managed to detect this error during static compilation. Good!
...integration-tests/src/test/java/org/enso/interpreter/test/ExtensionMethodResolutionTest.java
Outdated
Show resolved
Hide resolved
Currently, it fails.
Inspired by code in Sieve_Without_Types.enso
This test matches the behavior of Compiler's import export resolution more closely.
All attempts to check extension method conflicts during compilation failed:
At the end, I have resolved to checks at runtime, inside UnresolvedSymbol.
|
Turns out that current ordering of modules is a "feature" not a "bug". Let's not dig in that.
So that the iteration order of the entries is deterministic.
@@ -408,12 +407,12 @@ public void reset() { | |||
* @return a copy of this scope modulo the requested types | |||
*/ | |||
public ModuleScope withTypes(List<String> typeNames) { | |||
Map<String, Object> polyglotSymbols = new HashMap<>(this.polyglotSymbols); | |||
Map<String, Type> requestedTypes = new HashMap<>(this.types); | |||
Map<Type, Map<String, Supplier<Function>>> methods = new ConcurrentHashMap<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @hubertp. Note that I am getting rid of ConcurrentHashMap
here and no tests are failing. This should be a proof that ModuleScope
is intended to be single-threaded. Note that it would even not be possible to use it from more threads, as, e.g., in reset
method in https://github.com/enso-org/enso/pull/9844/files#diff-c3869665e0ec34703f8e3eea0464924c0e4260eab392dbccdc202ec1f0270379L399, a normal HashMap
is reassigned to the methods
field instead of ConcurrentHashMap
.
Fixes #1243
Pull Request Description
Fixes the non-deterministic method resolution in some cases. Normally, method resolution tries to lookup the method in:
The third step used to be non-deterministic. I have made it deterministic simply by replacing
java.util.HashMap
byjava.util.LinkedHashMap
in ModuleScope.Important Notes
I have attempted three times to implement this feature:
IrToTruffle
, just before execution.UnresolvedSymbol
, as an error.All these attempts failed. More details in comment below.
At the end, I have decided to fix this bug by making the method resolution deterministic and not throwing any errors.
Checklist
Please ensure that the following checklist has been satisfied before submitting the PR:
Scala,
Java,
TypeScript,
and
Rust
style guides. In case you are using a language not listed above, follow the Rust style guide.