metaborg / nabl

Spoofax' Name Binding Language
Apache License 2.0
7 stars 12 forks source link

Permission Analysis crashes on Unresolved Predicate Reference #92

Open MeAmAnUsername opened 2 years ago

MeAmAnUsername commented 2 years ago

Bug description Analysis of Statix Spec fails after renaming some functions

Versions Eclipse: org.eclipse.platform.ide 4.16.0.I20200604-0540 Spoofax: org.metaborg.spoofax.eclipse 2.6.0.20210914-132345-master System: Mac OS X x86_64 10.14.6 Statix setup: multi-file

Steps to reproduce the behavior https://github.com/MeAmAnUsername/pie/tree/bug-statix-spec-nabl2-analysis-fails/lang/lang (note the branch and directory) Either: Build standalone with Gradle Go to the project root directory (i.e. directory with lang, api, root etc.) in the terminal Run ./gradlew :pie.lang.root:pie.lang:build Note: make sure you use Java 8 when running Gradle, e.g. with the flag -Dorg.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home if you use sdkman

Import into eclipse and build there Requires eclipse, maybe requires Gradle installed / some Gradle plugin for Eclipse Import the language project (i.e. lang/lang) in eclipse using Gradle 6.8 or 6.9.1 and Java 8 Build the project

Build with Gradle in devenv This requires checking out some other metaborg projects as well. Go to the project root directory (i.e. directory with lang, api, root etc.) in the terminal Run ./gradlew cleanAll buildAll --info --stacktrace Note: make sure you use Java 8 when running Gradle, e.g. with the flag -Dorg.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home if you use sdkman

Observed behavior Build fails with an error. This is consistent, it happened after cleaning the project, restarting Eclipse, running in Gradle in devenv, after checking out another commit, rebuilding, and then going back to this commit, cleaning, restarting and rebuilding, and when building the language project standalone with Gradle. Error log (from Eclipse, but all of them fail with the same Stratego error)

13:10 | INFO  | s.e.m.b.GenerateSourcesBuilder - Generating sources for language project eclipse:///lang
13:10 | INFO  | o.m.c.build.Builder            - Building eclipse:///lang
13:10 | INFO  | o.m.c.build.Builder            - Building 12 sources, 4 includes of language impl. org.metaborg:org.metaborg.meta.lang.template:2.6.0-SNAPSHOT
13:11 | INFO  | o.m.c.build.Builder            - Building 32 sources, 0 includes of language impl. org.metaborg:statix.lang:2.6.0-SNAPSHOT
13:12 | ERROR | o.m.c.build.Builder            - Analysis failed unexpectedly
org.metaborg.core.analysis.AnalysisException: org.metaborg.core.MetaborgException: Invoking Stratego strategy editor-analyze failed at term:
    ( ExtParam(ExtDecl(CVar("statics/type.stx", "d-1028")), 3)
, ExtLit([Label("type_arg"{TermIndex("statics/base.stx", 2789)}){TermIndex("statics/base.stx", 2790)}])
)
Stratego trace:
    editor_analyze_0_0
    editor_analyze_0_0
    nabl2_analyze_1_0
    constraint_analysis_compat_1_0
    with_1_1
    nabl2__analyze_compat_1_0
    with_1_1
    nabl2_custom_analysis_final_hook_0_1
    with_1_1
    nabl2_custom_analysis_final_hook_p__0_1
    with_1_1
    solve_ext_constraints_0_0
    with_1_1
    filter_1_0
    ext_spec_entries_0_0
    with_1_1 <==
    nabl2_get_occurrence_name_0_0
    nabl2__occurrence_name_0_0
Internal error: 'with' clause failed unexpectedly in 'ext-spec-entries'
    at org.metaborg.spoofax.core.analysis.constraint.AbstractConstraintAnalyzer.callAnalysis(AbstractConstraintAnalyzer.java:320)
    at org.metaborg.spoofax.core.analysis.constraint.AbstractConstraintAnalyzer.doAnalysis(AbstractConstraintAnalyzer.java:186)
    at org.metaborg.spoofax.core.analysis.constraint.AbstractConstraintAnalyzer.analyzeAll(AbstractConstraintAnalyzer.java:153)
    at org.metaborg.spoofax.core.analysis.constraint.AbstractConstraintAnalyzer.analyzeAll(AbstractConstraintAnalyzer.java:1)
    at org.metaborg.core.analysis.AnalysisService.analyzeAll(AnalysisService.java:43)
    at org.metaborg.spoofax.core.analysis.SpoofaxAnalysisService.analyzeAll(SpoofaxAnalysisService.java:25)
    at org.metaborg.spoofax.core.analysis.SpoofaxAnalysisService.analyzeAll(SpoofaxAnalysisService.java:1)
    at org.metaborg.core.build.Builder.analyze(Builder.java:402)
    at org.metaborg.core.build.Builder.updateLanguageResources(Builder.java:272)
    at org.metaborg.core.build.Builder.build(Builder.java:167)
    at org.metaborg.spoofax.core.build.SpoofaxBuilder.build(SpoofaxBuilder.java:48)
    at org.metaborg.spoofax.core.build.SpoofaxBuilder.build(SpoofaxBuilder.java:1)
    at org.metaborg.spoofax.eclipse.build.BuildRunnable.run(BuildRunnable.java:60)
    at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2292)
    at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2317)
    at org.metaborg.spoofax.eclipse.processing.RunnableTask.schedule(RunnableTask.java:45)
    at org.metaborg.spoofax.eclipse.build.ProjectBuilder.build(ProjectBuilder.java:121)
    at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:832)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:220)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:263)
    at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:316)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:319)
    at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:371)
    at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:392)
    at org.eclipse.core.internal.resources.Workspace.buildInternal(Workspace.java:515)
    at org.eclipse.core.internal.resources.Workspace.build(Workspace.java:412)
    at org.eclipse.ui.actions.BuildAction$1.runInWorkspace(BuildAction.java:291)
    at org.eclipse.core.internal.resources.InternalWorkspaceJob.run(InternalWorkspaceJob.java:42)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
Caused by: org.metaborg.core.MetaborgException: Invoking Stratego strategy editor-analyze failed at term:
    ( ExtParam(ExtDecl(CVar("statics/type.stx", "d-1028")), 3)
, ExtLit([Label("type_arg"{TermIndex("statics/base.stx", 2789)}){TermIndex("statics/base.stx", 2790)}])
)
Stratego trace:
    editor_analyze_0_0
    editor_analyze_0_0
    nabl2_analyze_1_0
    constraint_analysis_compat_1_0
    with_1_1
    nabl2__analyze_compat_1_0
    with_1_1
    nabl2_custom_analysis_final_hook_0_1
    with_1_1
    nabl2_custom_analysis_final_hook_p__0_1
    with_1_1
    solve_ext_constraints_0_0
    with_1_1
    filter_1_0
    ext_spec_entries_0_0
    with_1_1 <==
    nabl2_get_occurrence_name_0_0
    nabl2__occurrence_name_0_0
Internal error: 'with' clause failed unexpectedly in 'ext-spec-entries'
    at org.metaborg.spoofax.core.stratego.StrategoCommon.handleException(StrategoCommon.java:206)
    at org.metaborg.spoofax.core.stratego.StrategoCommon.handleException(StrategoCommon.java:218)
    at org.metaborg.spoofax.core.stratego.StrategoCommon.invoke(StrategoCommon.java:154)
    at org.metaborg.spoofax.core.analysis.constraint.AbstractConstraintAnalyzer.callAnalysis(AbstractConstraintAnalyzer.java:318)
    ... 30 common frames omitted
Caused by: org.spoofax.interpreter.core.InterpreterErrorExit: Internal error: 'with' clause failed unexpectedly in 'ext-spec-entries'
    at org.strategoxt.lang.InteropSDefT.evaluate(InteropSDefT.java:194)
    at org.strategoxt.lang.InteropSDefT.evaluate(InteropSDefT.java:183)
    at org.strategoxt.lang.InteropSDefT$StrategyBody.evaluate(InteropSDefT.java:245)
    at org.spoofax.interpreter.core.Interpreter.evaluate(Interpreter.java:105)
    at org.spoofax.interpreter.core.Interpreter.invoke(Interpreter.java:80)
    at org.strategoxt.HybridInterpreter.invoke(HybridInterpreter.java:458)
    at org.metaborg.spoofax.core.stratego.StrategoCommon.invoke(StrategoCommon.java:148)
    ... 31 common frames omitted
13:12 | INFO  | o.m.c.build.Builder            - Building 27 sources, 8 includes of language impl. org.metaborg:org.metaborg.meta.lang.esv:2.6.0-SNAPSHOT
13:12 | INFO  | o.m.s.e.m.b.CompileBuilder     - Building language project eclipse:///lang
13:12 | INFO  | Build log                      - > Generate sources
13:12 | INFO  | Build log                      - > Compile normalized grammar to parse table using the Java implementation
13:12 | INFO  | Build log                      - > Extract parenthesis structure from grammar using the Java implementation
13:12 | INFO  | Build log                      - > Compile normalized grammar to parse table using the Java implementation (completions)
13:12 | INFO  | Build log                      - > Compile Stratego code
13:12 | INFO  | Build log                      - Execute strj -i /Users/ivo/programming/devenv/pie/lang/lang/trans/pie.str -o /Users/ivo/programming/devenv/pie/lang/lang/target/metaborg/stratego.ctree -p pie.lang.trans --library --clean -I /Users/ivo/programming/devenv/pie/lang/lang/trans -I /Users/ivo/programming/devenv/pie/lang/lang/src-gen -I /Users/ivo/programming/devenv/pie/lang/lang -I /Applications/spoofax_2.6.0.app/Contents/Eclipse/plugins/statix.runtime.eclipse_2.6.0.20210914-132345-master/target/unpacked/latest/trans -I /Applications/spoofax_2.6.0.app/Contents/Eclipse/plugins/statix.runtime.eclipse_2.6.0.20210914-132345-master/target/unpacked/latest/src-gen -I /Applications/spoofax_2.6.0.app/Contents/Eclipse/plugins/meta.lib.spoofax.eclipse_2.6.0.20210914-132345-master/target/unpacked/latest/trans -I /Users/ivo/programming/devenv/java-front/lang.java/src-gen -I /Users/ivo/programming/devenv/pie/lang/lang -I /Applications/spoofax_2.6.0.app/Contents/Eclipse/plugins/statix.runtime.eclipse_2.6.0.20210914-132345-master/target/unpacked/latest/trans -I /Applications/spoofax_2.6.0.app/Contents/Eclipse/plugins/statix.runtime.eclipse_2.6.0.20210914-132345-master/target/unpacked/latest/src-gen --cache-dir /Users/ivo/programming/devenv/pie/lang/lang/target/stratego-cache -la stratego-lib -la stratego-sglr -la stratego-gpp -la stratego-xtc -la stratego-aterm -la stratego-sdf -la strc -F
13:13 | INFO  | .m.s.m.c.b.LanguageSpecBuilder - Compiling Main ESV file eclipse:///lang/editor/Main.esv
13:13 | INFO  | o.m.c.build.Builder            - Building eclipse:///lang
13:13 | INFO  | o.m.c.build.Builder            - Building 1 sources, 8 includes of language impl. org.metaborg:org.metaborg.meta.lang.esv:2.6.0-SNAPSHOT
13:13 | INFO  | o.m.s.e.m.b.PackageBuilder     - Packaging language project eclipse:///lang
13:13 | INFO  | Build log                      - > Package language implementation
13:13 | INFO  | Build log                      - > Creating JAR file
13:13 | INFO  | o.m.s.e.m.b.PackageBuilder     - Archiving language project eclipse:///lang
13:13 | INFO  | Build log                      - > Archive language implementation
13:13 | INFO  | o.m.s.e.m.b.PackageBuilder     - Reloading language project eclipse:///lang
13:13 | ERROR | .m.s.c.s.p.AResourcesPrimitive - Could not find src-gen/statix/statics/project.spec.aterm

Expected behavior Build succeeds

Additional context Caused by this commit (i.e. previous commit works). This commit renames typeArgsOk to typeOfTypeArgs (along with some related functions). The error seems to indicate that it fails on the type_arg relation, which is related in the sense that the typeOfTypeArg function makes a declaration in that relation. I have no clue why this rename leads to this failure.

AZWN commented 2 years ago

Thanks for the reliable reproduction. It seems that permission analysis, an analysis step executed after regular type-checking, is failing. This can happen when regular type-checking encounters an error (often a reference that does not resolve). However, I agree that it should fail more graciously than this.

MeAmAnUsername commented 2 years ago

I retried the commit manually and then used a diff. Apparently I forgot to rename typeArgsOk on line 480 in statics/type.stx. That means the issue is resolved for me, feel free to close it.

AZWN commented 2 years ago

I'll leave it open, because we had the issue more often, and this is a nice reproduction.