-
Notifications
You must be signed in to change notification settings - Fork 29
Allow nested generic specialization keys #1266
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
fa0eba3
Allow nested generic specialization keys
Frotty 15c16ef
Normalize nested specialization bindings
Frotty 214566c
Isolate Lua generic static storage
Frotty d181a14
Track erased generic static ownership
Frotty 94adc34
Materialize statics for erased instantiations
Frotty 48c2f77
Preserve generic static initializer order
Frotty 9861d7a
Specialize static-owning generic factories
Frotty bd05ff7
Handle inherited generic static storage
Frotty 408e1c9
Register erased generic helper statics
Frotty cdc2a90
Collect fixed generic method operations
Frotty 5d41865
Preserve implicit generic reachability
Frotty File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
240 changes: 209 additions & 31 deletions
240
...cript/src/main/java/de/peeeq/wurstscript/translation/imtranslation/EliminateGenerics.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...cript/src/test/java/de/peeeq/wurstscript/translation/imtranslation/GenericTypesTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| package de.peeeq.wurstscript.translation.imtranslation; | ||
|
|
||
| import de.peeeq.wurstscript.ast.Ast; | ||
| import de.peeeq.wurstscript.jassIm.ImClass; | ||
| import de.peeeq.wurstscript.jassIm.ImClassType; | ||
| import de.peeeq.wurstscript.jassIm.ImFunction; | ||
| import de.peeeq.wurstscript.jassIm.ImMethod; | ||
| import de.peeeq.wurstscript.jassIm.ImSimpleType; | ||
| import de.peeeq.wurstscript.jassIm.ImTypeArgument; | ||
| import de.peeeq.wurstscript.jassIm.ImTypeClassFunc; | ||
| import de.peeeq.wurstscript.jassIm.JassIm; | ||
| import io.vavr.control.Either; | ||
| import org.testng.annotations.Test; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import static org.testng.Assert.assertEquals; | ||
|
|
||
| public class GenericTypesTests { | ||
|
|
||
| @Test | ||
| public void nestedTypeClassBindingsDoNotSplitSpecializationKeys() { | ||
| ImClass box = genericClass("Box"); | ||
| ImClass list = genericClass("List"); | ||
| ImSimpleType integer = JassIm.ImSimpleType("integer"); | ||
| ImTypeClassFunc requirement = JassIm.ImTypeClassFunc(Ast.NoExpr(), "toIndex", | ||
| JassIm.ImTypeVars(), JassIm.ImVars(), integer); | ||
| ImFunction instance = JassIm.ImFunction(Ast.NoExpr(), "intToIndex", JassIm.ImTypeVars(), | ||
| JassIm.ImVars(), integer, JassIm.ImVars(), JassIm.ImStmts(), List.of()); | ||
|
|
||
| Map<ImTypeClassFunc, Either<ImMethod, ImFunction>> binding = new LinkedHashMap<>(); | ||
| binding.put(requirement, Either.right(instance)); | ||
| ImClassType unboundBox = JassIm.ImClassType(box, | ||
| JassIm.ImTypeArguments(argument(integer, Collections.emptyMap()))); | ||
| ImClassType boundBox = JassIm.ImClassType(box, | ||
| JassIm.ImTypeArguments(argument(integer, binding))); | ||
|
|
||
| GenericTypes unbound = key(list, unboundBox); | ||
| GenericTypes bound = key(list, boundBox); | ||
|
|
||
| assertEquals(bound, unbound, | ||
| "type-class dispatch metadata must not change a structural specialization key"); | ||
| assertEquals(bound.hashCode(), unbound.hashCode()); | ||
| } | ||
|
|
||
| private static GenericTypes key(ImClass list, ImClassType nestedType) { | ||
| ImClassType listType = JassIm.ImClassType(list, | ||
| JassIm.ImTypeArguments(argument(nestedType, Collections.emptyMap()))); | ||
| return new GenericTypes(List.of(argument(listType, Collections.emptyMap()))); | ||
| } | ||
|
|
||
| private static ImTypeArgument argument(de.peeeq.wurstscript.jassIm.ImType type, | ||
| Map<ImTypeClassFunc, Either<ImMethod, ImFunction>> binding) { | ||
| return JassIm.ImTypeArgument(type, binding); | ||
| } | ||
|
|
||
| private static ImClass genericClass(String name) { | ||
| return JassIm.ImClass(Ast.NoExpr(), name, JassIm.ImTypeVars(JassIm.ImTypeVar("T")), | ||
| JassIm.ImVars(), JassIm.ImMethods(), JassIm.ImFunctions(), List.of()); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.