lingua-franca icon indicating copy to clipboard operation
lingua-franca copied to clipboard

LFC crashes if platform target property is used for a federated program

Open erlingrj opened this issue 2 years ago • 4 comments

When trying to set the platform option of a simple federated program. E.g.

target C {
  platform: "Linux" // Or "zephyr" which I am interested in
}

reactor R {
}

federated reactor {
    r1 = new R()
    r2 = new R()
}

LFC crashes with:

lfc: info: ##### Generating code for federate federate__r1 in directory /home/erling/dev/lf/lfz/test/C/fed-gen/Timer/src
lfc: fatal error: Error running generator
java.lang.NullPointerException: Cannot invoke "org.eclipse.emf.ecore.EObject.eClass()" because "eObject" is null
        at org.eclipse.emf.ecore.util.Switch.doSwitch(Switch.java:69)
        at org.lflang.ast.ToLf.doSwitch(ToLf.java:109)
        at org.lflang.ast.ToLf.caseKeyValuePair(ToLf.java:842)
        at org.lflang.ast.ToLf.caseKeyValuePair(ToLf.java:87)
        at org.lflang.lf.util.LfSwitch.doSwitch(LfSwitch.java:296)
        at org.eclipse.emf.ecore.util.Switch.doSwitch(Switch.java:53)
        at org.eclipse.emf.ecore.util.Switch.doSwitch(Switch.java:69)
        at org.lflang.ast.ToLf.doSwitch(ToLf.java:109)
        at org.lflang.ast.ToLf.lambda$list$13(ToLf.java:1074)
        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.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:992)
        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 org.lflang.ast.ToLf.list(ToLf.java:1077)
        at org.lflang.ast.ToLf.list(ToLf.java:1046)
        at org.lflang.ast.ToLf.caseKeyValuePairs(ToLf.java:813)
        at org.lflang.ast.ToLf.caseKeyValuePairs(ToLf.java:87)
        at org.lflang.lf.util.LfSwitch.doSwitch(LfSwitch.java:289)
        at org.eclipse.emf.ecore.util.Switch.doSwitch(Switch.java:53)
        at org.eclipse.emf.ecore.util.Switch.doSwitch(Switch.java:69)
        at org.lflang.ast.ToLf.doSwitch(ToLf.java:109)
        at org.lflang.ast.ToLf.caseElement(ToLf.java:859)
        at org.lflang.ast.ToLf.caseElement(ToLf.java:87)
        at org.lflang.lf.util.LfSwitch.doSwitch(LfSwitch.java:310)
        at org.eclipse.emf.ecore.util.Switch.doSwitch(Switch.java:53)
        at org.eclipse.emf.ecore.util.Switch.doSwitch(Switch.java:69)
        at org.lflang.ast.ToLf.doSwitch(ToLf.java:109)
        at org.lflang.ast.ToLf.caseKeyValuePair(ToLf.java:842)
        at org.lflang.ast.ToLf.caseKeyValuePair(ToLf.java:87)
        at org.lflang.lf.util.LfSwitch.doSwitch(LfSwitch.java:296)
        at org.eclipse.emf.ecore.util.Switch.doSwitch(Switch.java:53)
        at org.eclipse.emf.ecore.util.Switch.doSwitch(Switch.java:69)
        at org.lflang.ast.ToLf.doSwitch(ToLf.java:109)
        at org.lflang.ast.ToLf.lambda$list$13(ToLf.java:1074)
        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.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:992)
        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 org.lflang.ast.ToLf.list(ToLf.java:1077)
        at org.lflang.ast.ToLf.list(ToLf.java:1046)
        at org.lflang.ast.ToLf.caseKeyValuePairs(ToLf.java:813)
        at org.lflang.ast.ToLf.caseKeyValuePairs(ToLf.java:87)
        at org.lflang.lf.util.LfSwitch.doSwitch(LfSwitch.java:289)
        at org.eclipse.emf.ecore.util.Switch.doSwitch(Switch.java:53)
        at org.eclipse.emf.ecore.util.Switch.doSwitch(Switch.java:69)
        at org.lflang.ast.ToLf.doSwitch(ToLf.java:109)
        at org.lflang.ast.ToLf.caseTargetDecl(ToLf.java:472)
        at org.lflang.ast.ToLf.caseTargetDecl(ToLf.java:87)
        at org.lflang.lf.util.LfSwitch.doSwitch(LfSwitch.java:123)
        at org.eclipse.emf.ecore.util.Switch.doSwitch(Switch.java:53)
        at org.eclipse.emf.ecore.util.Switch.doSwitch(Switch.java:69)
        at org.lflang.ast.ToLf.doSwitch(ToLf.java:109)
        at org.lflang.ast.FormattingUtil.render(FormattingUtil.java:59)
        at org.lflang.ast.FormattingUtil.lambda$renderer$0(FormattingUtil.java:51)
        at org.lflang.federated.generator.FedTargetEmitter.generateTarget(FedTargetEmitter.java:31)
        at org.lflang.federated.generator.FedEmitter.generateFederate(FedEmitter.java:55)
        at org.lflang.federated.generator.FedGenerator.doGenerate(FedGenerator.java:151)
        at org.lflang.generator.LFGenerator.doGenerate(LFGenerator.java:114)
        at org.eclipse.xtext.generator.GeneratorDelegate.doGenerate(GeneratorDelegate.java:44)
        at org.eclipse.xtext.generator.GeneratorDelegate.generate(GeneratorDelegate.java:35)
        at org.lflang.cli.Lfc.invokeGenerator(Lfc.java:193)
        at org.lflang.cli.Lfc.doRun(Lfc.java:156)
        at org.lflang.cli.CliBase.run(CliBase.java:145)
        at picocli.CommandLine.executeUserObject(CommandLine.java:2026)
        at picocli.CommandLine.access$1500(CommandLine.java:148)
        at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2461)
        at picocli.CommandLine$RunLast.handle(CommandLine.java:2453)
        at picocli.CommandLine$RunLast.handle(CommandLine.java:2415)
        at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2273)
        at picocli.CommandLine$RunLast.execute(CommandLine.java:2417)
        at picocli.CommandLine.execute(CommandLine.java:2170)
        at org.lflang.cli.CliBase.doExecute(CliBase.java:117)
        at org.lflang.cli.CliBase.cliMain(CliBase.java:109)
        at org.lflang.cli.Lfc.main(Lfc.java:143)
        at org.lflang.cli.Lfc.main(Lfc.java:133)

Any ideas? I have already spent a little time trying to understand but it is a bit hard to follow the tree of nested function calls here

erlingrj avatar Jul 26 '23 08:07 erlingrj

Thanks for the bug report; this shouldn't be that hard of a fix. Will look into it.

lhstrh avatar Jul 26 '23 17:07 lhstrh

Seems closely related to https://github.com/lf-lang/lingua-franca/issues/1919

cmnrd avatar Jul 27 '23 11:07 cmnrd

I was working on this actually back when we were testing compiling federated programs onto individual Arduino boards (which relies on the platform definition to be carried over to each of the generated lf files), let me see if the fixes are still there.

arengarajan99 avatar Jul 27 '23 21:07 arengarajan99

Fixed. See the above pull request.

arengarajan99 avatar Jul 27 '23 21:07 arengarajan99