-
Notifications
You must be signed in to change notification settings - Fork 12
fe: infer result types from the result type of redefined features #1833
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
fe: infer result types from the result type of redefined features #1833
Conversation
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.
Nice you found a solution to this.
I have added a number of comments and request to make this more generic, hope this helps your understanding of the front end and to improve this patch.
|
||
var rf = f.redefines() | ||
.stream() | ||
.filter(x -> x.state().atLeast(State.RESOLVED_TYPES)) |
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.
Instead of filtering what happens to have been resolved already (which depends on whether we are lucky or not), maybe explicitly resolve x
via a call to res.resolveTypes(x)
.
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.
I attempted this, but it causes a postcondition failure during the build of base.fum:
error 1: java.lang.Error: ensure-condition failed: dev.flang.ast.Resolution:resolveTypes:465
at dev.flang.util.ANY.ensure(ANY.java:236)
at dev.flang.ast.Resolution.resolveTypes(Resolution.java:465)
at dev.flang.ast.Impl.lambda$typeFromRedefinedOrCode$0(Impl.java:544)
at java.base/java.util.stream.ReferencePipeline$15$1.accept(ReferencePipeline.java:540)
at java.base/java.util.TreeMap$KeySpliterator.forEachRemaining(TreeMap.java:3064)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
at dev.flang.ast.Impl.typeFromRedefinedOrCode(Impl.java:550)
at dev.flang.ast.Impl.inferredType(Impl.java:528)
at dev.flang.ast.Feature.resultTypeRaw(Feature.java:2280)
at dev.flang.ast.AbstractFeature.resultTypeRaw(AbstractFeature.java:967)
at dev.flang.ast.AbstractFeature.resultTypeIfPresent(AbstractFeature.java:996)
at dev.flang.ast.Call.resolveTypes(Call.java:2188)
at dev.flang.ast.Feature$ResolveTypes.action(Feature.java:1292)
at dev.flang.ast.Feature$ResolveTypes.action(Feature.java:1284)
at dev.flang.ast.Call.visit(Call.java:1127)
at dev.flang.ast.Block.visit(Block.java:226)
at dev.flang.ast.Block.visit(Block.java:40)
at dev.flang.ast.Impl.visit(Impl.java:312)
at dev.flang.ast.Feature.visit(Feature.java:1050)
at dev.flang.ast.Feature.internalResolveTypes(Feature.java:1342)
at dev.flang.ast.Resolution.resolveTypes(Resolution.java:461)
at dev.flang.ast.AbstractFeature.resultTypeIfPresent(AbstractFeature.java:994)
at dev.flang.ast.Call.resolveTypes(Call.java:2188)
at dev.flang.ast.Feature$ResolveTypes.action(Feature.java:1292)
at dev.flang.ast.Feature$ResolveTypes.action(Feature.java:1284)
at dev.flang.ast.Call.visit(Call.java:1127)
at dev.flang.ast.Block.visit(Block.java:226)
at dev.flang.ast.Block.visit(Block.java:40)
at dev.flang.ast.Call.visit(Call.java:1124)
at dev.flang.ast.Resolution.resolveType(Resolution.java:497)
at dev.flang.ast.Call.lambda$resolveTypesOfActuals$5(Call.java:842)
at dev.flang.ast.Feature.internalResolveTypes(Feature.java:1358)
at dev.flang.ast.Resolution.resolveTypes(Resolution.java:461)
at dev.flang.ast.AbstractFeature.resultTypeIfPresent(AbstractFeature.java:994)
at dev.flang.ast.Call.resolveTypes(Call.java:2188)
at dev.flang.ast.Feature$ResolveTypes.action(Feature.java:1292)
at dev.flang.ast.Feature$ResolveTypes.action(Feature.java:1284)
at dev.flang.ast.Call.visit(Call.java:1127)
at dev.flang.ast.Block.visit(Block.java:226)
at dev.flang.ast.Block.visit(Block.java:40)
at dev.flang.ast.Impl.visit(Impl.java:312)
at dev.flang.ast.Feature.visit(Feature.java:1050)
at dev.flang.ast.Feature.internalResolveTypes(Feature.java:1342)
at dev.flang.ast.Resolution.resolveTypes(Resolution.java:461)
at dev.flang.ast.AbstractFeature.resultTypeIfPresent(AbstractFeature.java:994)
at dev.flang.ast.Call.resolveTypes(Call.java:2188)
at dev.flang.ast.Feature$ResolveTypes.action(Feature.java:1292)
at dev.flang.ast.Feature$ResolveTypes.action(Feature.java:1284)
at dev.flang.ast.Call.visit(Call.java:1127)
at dev.flang.ast.Block.visit(Block.java:226)
at dev.flang.ast.Case.visit(Case.java:199)
at dev.flang.ast.Match.visit(Match.java:129)
at dev.flang.ast.Match.visit(Match.java:43)
at dev.flang.ast.Block.visit(Block.java:226)
at dev.flang.ast.Block.visit(Block.java:40)
at dev.flang.ast.Impl.visit(Impl.java:312)
at dev.flang.ast.Feature.visit(Feature.java:1050)
at dev.flang.ast.Feature.internalResolveTypes(Feature.java:1342)
at dev.flang.ast.Resolution.resolveTypes(Resolution.java:461)
at dev.flang.ast.AbstractFeature.resultTypeIfPresent(AbstractFeature.java:994)
at dev.flang.ast.Call.resolveTypes(Call.java:2188)
at dev.flang.ast.Feature$ResolveTypes.action(Feature.java:1292)
at dev.flang.ast.Feature$ResolveTypes.action(Feature.java:1284)
at dev.flang.ast.Call.visit(Call.java:1127)
at dev.flang.ast.Block.visit(Block.java:226)
at dev.flang.ast.Block.visit(Block.java:40)
at dev.flang.ast.Impl.visit(Impl.java:312)
at dev.flang.ast.Feature.visit(Feature.java:1050)
at dev.flang.ast.Feature.internalResolveTypes(Feature.java:1342)
at dev.flang.ast.Resolution.resolveTypes(Resolution.java:461)
at dev.flang.ast.AbstractFeature.resultTypeIfPresent(AbstractFeature.java:994)
at dev.flang.ast.Call.resolveTypes(Call.java:2188)
at dev.flang.ast.Feature$ResolveTypes.action(Feature.java:1292)
at dev.flang.ast.Feature$ResolveTypes.action(Feature.java:1284)
at dev.flang.ast.Call.visit(Call.java:1127)
at dev.flang.ast.Block.visit(Block.java:226)
at dev.flang.ast.Block.visit(Block.java:40)
at dev.flang.ast.Impl.visit(Impl.java:312)
at dev.flang.ast.Feature.visit(Feature.java:1050)
at dev.flang.ast.Feature.internalResolveTypes(Feature.java:1342)
at dev.flang.ast.Resolution.resolveTypes(Resolution.java:461)
at dev.flang.ast.AbstractFeature.resultTypeIfPresent(AbstractFeature.java:994)
at dev.flang.ast.Call.resolveTypes(Call.java:2188)
at dev.flang.ast.Feature$ResolveTypes.action(Feature.java:1292)
at dev.flang.ast.Feature$ResolveTypes.action(Feature.java:1284)
at dev.flang.ast.Call.visit(Call.java:1127)
at dev.flang.ast.Call.visit(Call.java:1124)
at dev.flang.ast.Block.visit(Block.java:226)
at dev.flang.ast.Block.visit(Block.java:40)
at dev.flang.ast.Impl.visit(Impl.java:312)
at dev.flang.ast.Feature.visit(Feature.java:1050)
at dev.flang.ast.Feature.internalResolveTypes(Feature.java:1342)
at dev.flang.ast.Resolution.resolveTypes(Resolution.java:461)
at dev.flang.ast.Impl.lambda$typeFromRedefinedOrCode$0(Impl.java:544)
at java.base/java.util.stream.ReferencePipeline$15$1.accept(ReferencePipeline.java:540)
at java.base/java.util.TreeMap$KeySpliterator.forEachRemaining(TreeMap.java:3064)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
at dev.flang.ast.Impl.typeFromRedefinedOrCode(Impl.java:550)
at dev.flang.ast.Impl.inferredType(Impl.java:528)
at dev.flang.ast.Feature.resultTypeRaw(Feature.java:2280)
at dev.flang.ast.AbstractFeature.resultTypeRaw(AbstractFeature.java:967)
at dev.flang.ast.AbstractFeature.resultTypeIfPresent(AbstractFeature.java:996)
at dev.flang.ast.Call.resolveTypes(Call.java:2188)
at dev.flang.ast.Feature$ResolveTypes.action(Feature.java:1292)
at dev.flang.ast.Feature$ResolveTypes.action(Feature.java:1284)
at dev.flang.ast.Call.visit(Call.java:1127)
at dev.flang.ast.Feature.visit(Feature.java:1933)
at dev.flang.ast.Block.visit(Block.java:226)
at dev.flang.ast.Block.visit(Block.java:40)
at dev.flang.ast.Block.visit(Block.java:226)
at dev.flang.ast.Block.visit(Block.java:40)
at dev.flang.ast.Impl.visit(Impl.java:312)
at dev.flang.ast.Feature.visit(Feature.java:1050)
at dev.flang.ast.Feature.internalResolveTypes(Feature.java:1342)
at dev.flang.ast.Resolution.resolveTypes(Resolution.java:461)
at dev.flang.ast.AbstractFeature.resultTypeIfPresent(AbstractFeature.java:994)
at dev.flang.ast.Call.resolveTypes(Call.java:2188)
at dev.flang.ast.Feature$ResolveTypes.action(Feature.java:1292)
at dev.flang.ast.Feature$ResolveTypes.action(Feature.java:1284)
at dev.flang.ast.Call.visit(Call.java:1127)
at dev.flang.ast.Block.visit(Block.java:226)
at dev.flang.ast.Block.visit(Block.java:40)
at dev.flang.ast.Impl.visit(Impl.java:312)
at dev.flang.ast.Feature.visit(Feature.java:1050)
at dev.flang.ast.Feature.internalResolveTypes(Feature.java:1342)
at dev.flang.ast.Resolution.resolveOne(Resolution.java:371)
at dev.flang.ast.Resolution.resolve(Resolution.java:338)
at dev.flang.fe.SourceModule.createASTandResolve(SourceModule.java:261)
at dev.flang.fe.FrontEnd.<init>(FrontEnd.java:183)
at dev.flang.tools.Fuzion.lambda$parseArgsForBackend$3(Fuzion.java:868)
at dev.flang.tools.Tool.lambda$run$0(Tool.java:156)
at dev.flang.util.Errors.runAndExit(Errors.java:748)
at dev.flang.tools.Tool.run(Tool.java:156)
at dev.flang.tools.Fuzion.main(Fuzion.java:519)
*** fatal errors encountered, stopping.
.filter(x -> !x.isGenericArgument()) | ||
.filter(x -> x.generics().size() == 0) | ||
.filter(x -> !x.isThisType()) |
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.
Instead of these restrictions, it should be possible to use AbstractFeature.handDownNonOpen
to get the type after it was inherited. Admittedly, handDownNonOpen
could have a nicer name handDownType
or inheritedType
or similar.
The remaining restriction before using handDownNonOpen
is that !x.isOpenGeneric()
. Would be great if you could try to create an example that uses an open generic result type and redefines that feature to check what makes sense here (in a separate issue / PR).
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.
error 1: java.lang.Error: require-condition3 failed: dev.flang.ast.AbstractFeature:handDownNonOpen:1294
at dev.flang.util.ANY.require(ANY.java:113)
at dev.flang.ast.AbstractFeature.handDownNonOpen(AbstractFeature.java:1294)
at dev.flang.ast.Impl.lambda$typeFromRedefinedOrCode$2(Impl.java:546)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
at java.base/java.util.TreeMap$KeySpliterator.forEachRemaining(TreeMap.java:3064)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
at dev.flang.ast.Impl.typeFromRedefinedOrCode(Impl.java:547)
at dev.flang.ast.Impl.inferredType(Impl.java:528)
at dev.flang.ast.Feature.resultTypeRaw(Feature.java:2280)
at dev.flang.ast.AbstractFeature.resultTypeRaw(AbstractFeature.java:967)
at dev.flang.ast.AbstractFeature.resultTypeIfPresent(AbstractFeature.java:996)
at dev.flang.ast.Call.resolveTypes(Call.java:2188)
at dev.flang.ast.Feature$ResolveTypes.action(Feature.java:1292)
at dev.flang.ast.Feature$ResolveTypes.action(Feature.java:1284)
at dev.flang.ast.Call.visit(Call.java:1127)
at dev.flang.ast.Feature.visit(Feature.java:1933)
at dev.flang.ast.Block.visit(Block.java:226)
at dev.flang.ast.Block.visit(Block.java:40)
at dev.flang.ast.Block.visit(Block.java:226)
at dev.flang.ast.Block.visit(Block.java:40)
at dev.flang.ast.Impl.visit(Impl.java:312)
at dev.flang.ast.Feature.visit(Feature.java:1050)
at dev.flang.ast.Feature.internalResolveTypes(Feature.java:1342)
at dev.flang.ast.Resolution.resolveOne(Resolution.java:371)
at dev.flang.ast.Resolution.resolve(Resolution.java:338)
at dev.flang.fe.SourceModule.createASTandResolve(SourceModule.java:261)
at dev.flang.fe.FrontEnd.<init>(FrontEnd.java:183)
at dev.flang.tools.Fuzion.lambda$parseArgsForBackend$3(Fuzion.java:868)
at dev.flang.tools.Tool.lambda$run$0(Tool.java:156)
at dev.flang.util.Errors.runAndExit(Errors.java:748)
at dev.flang.tools.Tool.run(Tool.java:156)
at dev.flang.tools.Fuzion.main(Fuzion.java:519)
*** fatal errors encountered, stopping.
when building base.fum (note that this is not the !x.isOpenGeneric()
precondition).
Superseded by #4023 |
No description provided.