enso-org / enso

Hybrid visual and textual functional programming.
https://enso.org
Apache License 2.0
7.34k stars 321 forks source link

Compiler crashes exposing internal errors if a comment with no code following it is encountered #10849

Closed radeusgd closed 1 week ago

radeusgd commented 3 weeks ago

See the following program:

foo =
    # TODO

main = 42

Expected behaviour

Of course we are missing any statement in the foo method. But it should just print some syntax error, or something.

Actual behaviour

Right now it crashes with:

java.lang.NullPointerException: Cannot invoke "org.enso.compiler.core.ir.Expression.transformExpressions(scala.PartialFunction)" because "ir" is null
        at org.enso.runtime/org.enso.compiler.pass.resolve.DocumentationComments$.org$enso$compiler$pass$resolve$DocumentationComments$$resolveExpression(DocumentationComments.scala:83)
        at org.enso.runtime/org.enso.compiler.pass.resolve.DocumentationComments$$anonfun$org$enso$compiler$pass$resolve$DocumentationComments$$resolveExpression$1.applyOrElse(DocumentationComments.scala:87)
        at org.enso.runtime/org.enso.compiler.pass.resolve.DocumentationComments$$anonfun$org$enso$compiler$pass$resolve$DocumentationComments$$resolveExpression$1.applyOrElse(DocumentationComments.scala:83)
        at org.enso.runtime/scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:35)
        at org.enso.runtime/org.enso.compiler.core.ir.Expression.transformExpressions(Expression.scala:22)
        at org.enso.runtime/org.enso.compiler.core.ir.Expression.transformExpressions$(Expression.scala:18)
        at org.enso.runtime/org.enso.compiler.core.ir.Expression$Block.transformExpressions(Expression.scala:58)
        at org.enso.runtime/org.enso.compiler.pass.resolve.DocumentationComments$.org$enso$compiler$pass$resolve$DocumentationComments$$resolveExpression(DocumentationComments.scala:83)
        at org.enso.runtime/org.enso.compiler.pass.resolve.DocumentationComments$.resolveDefinition(DocumentationComments.scala:167)
        at org.enso.runtime/org.enso.compiler.pass.resolve.DocumentationComments$.$anonfun$resolveModule$5(DocumentationComments.scala:211)
        at org.enso.runtime/scala.collection.immutable.List.map(List.scala:246)
        at org.enso.runtime/org.enso.compiler.pass.resolve.DocumentationComments$.resolveModule(DocumentationComments.scala:211)
        at org.enso.runtime/org.enso.compiler.pass.resolve.DocumentationComments$.runModule(DocumentationComments.scala:58)
        at org.enso.runtime/org.enso.compiler.pass.PassManager.$anonfun$runPassesOnModule$2(PassManager.scala:101)
        at org.enso.runtime/scala.collection.LinearSeqOps.foldLeft(LinearSeq.scala:183)
        at org.enso.runtime/scala.collection.LinearSeqOps.foldLeft$(LinearSeq.scala:179)
        at org.enso.runtime/scala.collection.immutable.List.foldLeft(List.scala:79)
        at org.enso.runtime/org.enso.compiler.pass.PassManager.runPassesOnModule(PassManager.scala:92)
        at org.enso.runtime/org.enso.compiler.Compiler.recognizeBindings(Compiler.scala:799)
        at org.enso.runtime/org.enso.compiler.Compiler.uncachedParseModule(Compiler.scala:631)
        at org.enso.runtime/org.enso.compiler.Compiler.parseModule(Compiler.scala:586)
        at org.enso.runtime/org.enso.compiler.Compiler.$anonfun$runCompilerPipeline$1(Compiler.scala:251)
        at org.enso.runtime/org.enso.compiler.Compiler.$anonfun$runCompilerPipeline$1$adapted(Compiler.scala:249)
        at org.enso.runtime/scala.collection.immutable.List.foreach(List.scala:333)
        at org.enso.runtime/org.enso.compiler.Compiler.runCompilerPipeline(Compiler.scala:249)
        at org.enso.runtime/org.enso.compiler.Compiler.go$1(Compiler.scala:233)
        at org.enso.runtime/org.enso.compiler.Compiler.runInternal(Compiler.scala:240)
        at org.enso.runtime/org.enso.compiler.Compiler.run(Compiler.scala:131)
        at org.enso.runtime/org.enso.interpreter.runtime.Module.compile(Module.java:393)
        at org.enso.runtime/org.enso.interpreter.runtime.Module.compileScope(Module.java:329)
        at org.enso.runtime/org.enso.interpreter.node.ProgramRootNode.execute(ProgramRootNode.java:66)
        at org.graalvm.truffle.runtime/com.oracle.truffle.runtime.OptimizedCallTarget.executeRootNode(OptimizedCallTarget.java:745)
        at org.graalvm.truffle.runtime/com.oracle.truffle.runtime.OptimizedCallTarget.profiledPERoot(OptimizedCallTarget.java:669)
        at org.graalvm.truffle.runtime/com.oracle.truffle.runtime.OptimizedCallTarget.callBoundary(OptimizedCallTarget.java:602)
        at org.graalvm.truffle.runtime/com.oracle.truffle.runtime.OptimizedCallTarget.doInvoke(OptimizedCallTarget.java:586)
        at org.graalvm.truffle.runtime/com.oracle.truffle.runtime.OptimizedCallTarget.callIndirect(OptimizedCallTarget.java:519)
        at org.graalvm.truffle.runtime/com.oracle.truffle.runtime.OptimizedCallTarget.call(OptimizedCallTarget.java:500)
        at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotContextImpl.eval(PolyglotContextImpl.java:1683)
        at org.graalvm.truffle/com.oracle.truffle.polyglot.PolyglotContextDispatch.eval(PolyglotContextDispatch.java:60)
        at org.graalvm.polyglot/org.graalvm.polyglot.Context.eval(Context.java:402)
        at org.enso.IsolatedClassLoader//org.enso.polyglot.PolyglotContext.evalModule(PolyglotContext.scala:32)
        at org.enso.IsolatedClassLoader//org.enso.runner.Main.runSingleFile(Main.java:836)
        at org.enso.IsolatedClassLoader//org.enso.runner.Main.handleRun(Main.java:740)
        at org.enso.IsolatedClassLoader//org.enso.runner.Main.mainEntry(Main.java:1093)
        at org.enso.IsolatedClassLoader//org.enso.runner.Main.lambda$launch$20(Main.java:1431)
        at org.enso.IsolatedClassLoader//org.enso.runner.Main.withProfiling(Main.java:1183)
        at org.enso.IsolatedClassLoader//org.enso.runner.Main.launch(Main.java:1427)
        at org.enso.IsolatedClassLoader//org.enso.runner.Main.launch(Main.java:1384)
        at org.enso.IsolatedClassLoader//org.enso.runner.Main.main(Main.java:1001)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
        at java.base/java.lang.reflect.Method.invoke(Method.java:580)
        at org.enso.runtime/org.enso.EngineRunnerBootLoader.main(EngineRunnerBootLoader.java:46)
[ERROR] [2024-08-20T14:33:30.643] [enso.org.enso.compiler.Compiler] Contents of module X:\NBO\enso\example.enso: foo =
    # TODO

main = 42

[ERROR] [2024-08-20T14:33:30.651] [org.enso.runner.Main] Error during execution
java.io.IOException: org.graalvm.polyglot.PolyglotException: java.lang.NullPointerException: Cannot invoke "org.enso.compiler.core.ir.Expression.transformExpressions(scala.PartialFunction)" because "ir" is null
        at org.enso.IsolatedClassLoader//org.enso.runner.Main.withProfiling(Main.java:1187)
        at org.enso.IsolatedClassLoader//org.enso.runner.Main.launch(Main.java:1427)
        at org.enso.IsolatedClassLoader//org.enso.runner.Main.launch(Main.java:1384)
        at org.enso.IsolatedClassLoader//org.enso.runner.Main.main(Main.java:1001)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
        at java.base/java.lang.reflect.Method.invoke(Method.java:580)
        at org.enso.runtime/org.enso.EngineRunnerBootLoader.main(EngineRunnerBootLoader.java:46)
Caused by: org.graalvm.polyglot.PolyglotException: java.lang.NullPointerException: Cannot invoke "org.enso.compiler.core.ir.Expression.transformExpressions(scala.PartialFunction)" because "ir" is null
        at org.enso.runtime/org.enso.compiler.pass.resolve.DocumentationComments$.org$enso$compiler$pass$resolve$DocumentationComments$$resolveExpression(DocumentationComments.scala:83)
        at org.enso.runtime/org.enso.compiler.pass.resolve.DocumentationComments$$anonfun$org$enso$compiler$pass$resolve$DocumentationComments$$resolveExpression$1.applyOrElse(DocumentationComments.scala:87)
        at org.enso.runtime/org.enso.compiler.pass.resolve.DocumentationComments$$anonfun$org$enso$compiler$pass$resolve$DocumentationComments$$resolveExpression$1.applyOrElse(DocumentationComments.scala:83)
        at org.enso.runtime/scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:35)
        at org.enso.runtime/org.enso.compiler.core.ir.Expression.transformExpressions(Expression.scala:22)
        at org.enso.runtime/org.enso.compiler.core.ir.Expression.transformExpressions$(Expression.scala:18)
        at org.enso.runtime/org.enso.compiler.core.ir.Expression$Block.transformExpressions(Expression.scala:58)
        at org.enso.runtime/org.enso.compiler.pass.resolve.DocumentationComments$.org$enso$compiler$pass$resolve$DocumentationComments$$resolveExpression(DocumentationComments.scala:83)
        at org.enso.runtime/org.enso.compiler.pass.resolve.DocumentationComments$.resolveDefinition(DocumentationComments.scala:167)
        at org.enso.runtime/org.enso.compiler.pass.resolve.DocumentationComments$.$anonfun$resolveModule$5(DocumentationComments.scala:211)
        at org.enso.runtime/scala.collection.immutable.List.map(List.scala:246)
        at org.enso.runtime/org.enso.compiler.pass.resolve.DocumentationComments$.resolveModule(DocumentationComments.scala:211)
        at org.enso.runtime/org.enso.compiler.pass.resolve.DocumentationComments$.runModule(DocumentationComments.scala:58)
        at org.enso.runtime/org.enso.compiler.pass.PassManager.$anonfun$runPassesOnModule$2(PassManager.scala:101)
        at org.enso.runtime/scala.collection.LinearSeqOps.foldLeft(LinearSeq.scala:183)
        at org.enso.runtime/scala.collection.LinearSeqOps.foldLeft$(LinearSeq.scala:179)
        at org.enso.runtime/scala.collection.immutable.List.foldLeft(List.scala:79)
        at org.enso.runtime/org.enso.compiler.pass.PassManager.runPassesOnModule(PassManager.scala:92)
        at org.enso.runtime/org.enso.compiler.Compiler.recognizeBindings(Compiler.scala:799)
        at org.enso.runtime/org.enso.compiler.Compiler.uncachedParseModule(Compiler.scala:631)
        at org.enso.runtime/org.enso.compiler.Compiler.parseModule(Compiler.scala:586)
        at org.enso.runtime/org.enso.compiler.Compiler.ensureParsed(Compiler.scala:689)
        at org.enso.runtime/org.enso.compiler.Compiler.ensureParsed(Compiler.scala:678)
        at org.enso.runtime/org.enso.compiler.phase.ImportResolver.go$1(ImportResolver.scala:152)
        at org.enso.runtime/org.enso.compiler.phase.ImportResolver.mapImports(ImportResolver.scala:165)
        at org.enso.runtime/org.enso.compiler.Compiler.liftedTree1$1(Compiler.scala:456)
        at org.enso.runtime/org.enso.compiler.Compiler.runImportsAndExportsResolution(Compiler.scala:455)
        at org.enso.runtime/org.enso.compiler.Compiler.$anonfun$runCompilerPipeline$2(Compiler.scala:273)
        at org.enso.runtime/scala.collection.immutable.List.flatMap(List.scala:293)
        at org.enso.runtime/org.enso.compiler.Compiler.runCompilerPipeline(Compiler.scala:268)
        at org.enso.runtime/org.enso.compiler.Compiler.go$1(Compiler.scala:233)
        at org.enso.runtime/org.enso.compiler.Compiler.runInternal(Compiler.scala:240)
        at org.enso.runtime/org.enso.compiler.Compiler.run(Compiler.scala:131)
        at org.enso.runtime/org.enso.interpreter.runtime.Module.compile(Module.java:393)
        at org.enso.runtime/org.enso.interpreter.runtime.Module.compileScope(Module.java:329)
        at org.enso.runtime/org.enso.interpreter.node.ProgramRootNode.execute(ProgramRootNode.java:66)
        at <enso>.(Unknown)
        at org.graalvm.polyglot/org.graalvm.polyglot.Context.eval(Context.java:402)
        at org.enso.IsolatedClassLoader//org.enso.polyglot.PolyglotContext.evalModule(PolyglotContext.scala:32)
        at org.enso.IsolatedClassLoader//org.enso.runner.Main.runSingleFile(Main.java:836)
        at org.enso.IsolatedClassLoader//org.enso.runner.Main.handleRun(Main.java:740)
        at org.enso.IsolatedClassLoader//org.enso.runner.Main.mainEntry(Main.java:1093)
        at org.enso.IsolatedClassLoader//org.enso.runner.Main.lambda$launch$20(Main.java:1431)
        at org.enso.IsolatedClassLoader//org.enso.runner.Main.withProfiling(Main.java:1183)
        ... 6 common frames omitted
Command failed with an error: java.io.IOException: org.graalvm.polyglot.PolyglotException: java.lang.NullPointerException: Cannot invoke "org.enso.compiler.core.ir.Expression.transformExpressions(scala.PartialFunction)" because "ir" is null

Comment

For comparison the following program:

foo =

main = 42

actually executes without any errors or warnings and returns 42. So it seems to be the comment that causes the issue.

enso-bot[bot] commented 1 week ago

Dmitry Bushev reports a new STANDUP for today (2024-09-03):

Progress: [10897] Working on the review comments. Fixed the locking of runtime hooks. [10849] Reproduced the issue. Updated parsing logic to allow body blocks with empty return values. Added tests. Created the PR. It should be finished by 2024-09-06.

Next Day: Next day I will be working on the #10849 task. Continue working on the task