-
Notifications
You must be signed in to change notification settings - Fork 29
Let the interpreter ask what a node was copied from, and who owns it #1249
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1629,6 +1629,11 @@ private void createSpecializedGlobals(ImClass originalClass, GenericTypes generi | |
|
|
||
| // Create + register global | ||
| translator.addGlobal(specializedGlobal); | ||
| // Both halves of what the interpreter used to read out of the name: what this was copied | ||
| // from, and which class it belongs to. | ||
| translator.recordSpecialisation(specializedGlobal, originalGlobal, generics.getTypeArguments()); | ||
| translator.recordGenericStaticOwner(specializedGlobal, originalClass); | ||
| translator.recordGenericStaticOwner(originalGlobal, originalClass); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In normal CLI/LSP builds, Useful? React with 👍 / 👎. |
||
| specializedGlobals.put(originalGlobal, key, specializedGlobal); | ||
| dbg("Created specialized global: " + specializedName + " type=" + specializedType); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package de.peeeq.wurstscript.translation.imtranslation; | ||
|
|
||
| import de.peeeq.wurstscript.jassIm.Element; | ||
| import de.peeeq.wurstscript.jassIm.ImClass; | ||
| import de.peeeq.wurstscript.jassIm.ImVar; | ||
| import org.eclipse.jdt.annotation.Nullable; | ||
|
|
||
| /** | ||
| * Answers what a specialised node was copied from. | ||
| * <p> | ||
| * The interpreter is handed a program rather than the translation which produced it, which is why it | ||
| * had no way to tell two type variables apart except by name - and two parameters which merely share | ||
| * a name are not the same parameter. This is the one question it needs answered, narrow enough to hand | ||
| * over without handing over the translator. | ||
| */ | ||
| public interface SpecialisationLookup { | ||
|
|
||
| /** The node {@code node} was ultimately copied from, or {@code node} itself. */ | ||
| <T extends Element> T canonical(T node); | ||
|
|
||
| /** | ||
| * The generic class a static field belongs to, or null when it is not one. | ||
| * <p> | ||
| * The alternative was reading the owner out of the global's name, which a class name containing | ||
| * an underscore answers wrongly and without saying so. | ||
| */ | ||
| @Nullable ImClass genericStaticOwnerOf(ImVar global); | ||
|
|
||
| /** | ||
| * For a program which did not come from a translation that recorded anything - a hand-built | ||
| * program in a test, say. Every node is its own original, which is what a program with no | ||
| * specialisation in it means. | ||
| */ | ||
| SpecialisationLookup NONE = new SpecialisationLookup() { | ||
| @Override | ||
| public <T extends Element> T canonical(T node) { | ||
| return node; | ||
| } | ||
|
|
||
| @Override | ||
| public @Nullable ImClass genericStaticOwnerOf(ImVar global) { | ||
| return null; | ||
| } | ||
| }; | ||
| } |
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.
Add a focused interpreter/
ProgramStatetest that fails with the former name-based comparison: use two unrelated same-named type variables with different bindings plus a copied variable sharing one canonical origin, and assert that only the canonical binding is returned. This commit changes the dispatch-selection behavior but modifies no tests, so neither excluding the unrelated binding nor wiring the translator intoCompiletimeFunctionRunneris demonstrated by a failing repro, contrary to the repository's test-driven bug-fix requirement.AGENTS.md reference: AGENTS.md:L62-L64
Useful? React with 👍 / 👎.