Skip to content
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

Verify ascribed types of parameters really exist #6584

Merged
merged 25 commits into from
May 14, 2023

Conversation

JaroslavTulach
Copy link
Member

@JaroslavTulach JaroslavTulach commented May 5, 2023

Pull Request Description

Verify ascribed types (a : Xyz) are checked for existence.

Checklist

Please ensure that the following checklist has been satisfied before submitting the PR:

  • All code follows the
    Scala,
    Java,
    style guides.
  • All code has been tested:
    • Unit tests have been written where possible.

@JaroslavTulach JaroslavTulach added the CI: No changelog needed Do not require a changelog entry for this PR. label May 5, 2023
@JaroslavTulach JaroslavTulach self-assigned this May 5, 2023
Copy link
Member

@Akirathan Akirathan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding tests to TypeSignaturesTest.scala would probably be less amount of work, since there are already some tests.

@JaroslavTulach JaroslavTulach linked an issue May 9, 2023 that may be closed by this pull request
@JaroslavTulach
Copy link
Member Author

JaroslavTulach commented May 9, 2023

There is a lot of unresolved symbols when parsing the standard library. I was investigating it and it seems to me that BindingMap is properly created for a module:

BindingsMap: Standard.Base.System.Platform
        at org.enso.compiler.data.BindingsMap.<init>(BindingsMap.scala:35)
        at org.enso.compiler.data.BindingsMap.copy(BindingsMap.scala:30)
        at org.enso.compiler.data.BindingsMap.$anonfun$toConcrete$1(BindingsMap.scala:91)
        at scala.Option.map(Option.scala:242)
        at org.enso.compiler.data.BindingsMap.toConcrete(BindingsMap.scala:90)
        at org.enso.compiler.phase.ImportResolver.go$1(ImportResolver.scala:99)
        at org.enso.compiler.phase.ImportResolver.mapImports(ImportResolver.scala:132)
        at org.enso.compiler.Compiler.liftedTree1$1(Compiler.scala:439)
        at org.enso.compiler.Compiler.runImportsAndExportsResolution(Compiler.scala:438)
        at org.enso.compiler.Compiler.$anonfun$runCompilerPipeline$2(Compiler.scala:272)
        at scala.collection.immutable.List.flatMap(List.scala:293)
        at org.enso.compiler.Compiler.runCompilerPipeline(Compiler.scala:271)
        at org.enso.compiler.Compiler.go$1(Compiler.scala:254)
        at org.enso.compiler.Compiler.runInternal(Compiler.scala:260)
        at org.enso.compiler.Compiler.run(Compiler.scala:157)
        at org.enso.interpreter.runtime.Module.compile(Module.java:406)
        at org.enso.interpreter.runtime.Module.compileScope(Module.java:333)

filled with symbols properly, but then it gets created once again and this time the symbols remain empty:

java.lang.Exception: BindingsMap: Standard.Base.System.Platform
        at org.enso.compiler.data.BindingsMap.<init>(BindingsMap.scala:35)
        at org.enso.compiler.pass.analyse.BindingAnalysis$.runModule(BindingAnalysis.scala:99)
        at org.enso.compiler.pass.PassManager.$anonfun$runPassesOnModule$2(PassManager.scala:101)
        at scala.collection.LinearSeqOps.foldLeft(LinearSeq.scala:169)
        at scala.collection.LinearSeqOps.foldLeft$(LinearSeq.scala:165)
        at scala.collection.immutable.List.foldLeft(List.scala:79)
        at org.enso.compiler.pass.PassManager.runPassesOnModule(PassManager.scala:92)
        at org.enso.compiler.Compiler.recognizeBindings(Compiler.scala:796)
        at org.enso.compiler.Compiler.uncachedParseModule(Compiler.scala:595)
        at org.enso.compiler.Compiler.parseModule(Compiler.scala:552)
        at org.enso.compiler.Compiler.ensureParsed(Compiler.scala:634)
        at org.enso.compiler.Compiler.ensureParsedAndAnalyzed(Compiler.scala:472)
        at org.enso.compiler.Compiler.$anonfun$runImportsAndExportsResolution$1(Compiler.scala:456)
        at scala.collection.immutable.List.map(List.scala:250)
        at org.enso.compiler.Compiler.runImportsAndExportsResolution(Compiler.scala:449)
        at org.enso.compiler.Compiler.$anonfun$runCompilerPipeline$2(Compiler.scala:272)
        at scala.collection.immutable.List.flatMap(List.scala:293)
        at org.enso.compiler.Compiler.runCompilerPipeline(Compiler.scala:271)
        at org.enso.compiler.Compiler.go$1(Compiler.scala:254)
        at org.enso.compiler.Compiler.runInternal(Compiler.scala:260)
        at org.enso.compiler.Compiler.run(Compiler.scala:157)
        at org.enso.interpreter.runtime.Module.compile(Module.java:406)
        at org.enso.interpreter.runtime.Module.compileScope(Module.java:333)

Update: solved by 0711186

Copy link
Contributor

@hubertp hubertp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nits

@JaroslavTulach
Copy link
Member Author

JaroslavTulach commented May 9, 2023

There is a lot of unresolved symbols ....

Thank you all for your help. These three lines are causing all the failures:

enso$ git diff
diff --git engine/runtime/src/main/scala/org/enso/compiler/pass/resolve/TypeSignatures.scala engine/runtime/src/main/scala/org/enso/compiler/pass/resolve/TypeSignatures.scala
index bbe19d43fc..5be235da81 100644
--- engine/runtime/src/main/scala/org/enso/compiler/pass/resolve/TypeSignatures.scala
+++ engine/runtime/src/main/scala/org/enso/compiler/pass/resolve/TypeSignatures.scala
@@ -134,9 +134,9 @@ case object TypeSignatures extends IRPass {
         lastSignature = None
         res
       case ut: IR.Module.Scope.Definition.Type =>
-        ut.members.foreach(d => {
-          verifyAscribedArguments(d.arguments)
-        })
+        //ut.members.foreach(d => {
+        //  verifyAscribedArguments(d.arguments)
+        //})
         Some(ut.mapExpressions(resolveExpression))
       case err: IR.Error                  => Some(err)
       case ann: IR.Name.GenericAnnotation => Some(ann)

Update: solved by 0711186

Co-authored-by: Hubert Plociniczak <hubert.plociniczak@gmail.com>
@JaroslavTulach JaroslavTulach force-pushed the wip/jtulach/CheckAscribedTypes_6527 branch from c52e045 to 6e2ce12 Compare May 10, 2023 07:24
Co-authored-by: Hubert Plociniczak <hubert.plociniczak@gmail.com>
@JaroslavTulach
Copy link
Member Author

Dropping the caches didn't help - the failure is still there. The following patch seems to help me locally: #6135 (comment)

@JaroslavTulach
Copy link
Member Author

JaroslavTulach commented May 11, 2023

There is a:

@JaroslavTulach
Copy link
Member Author

JaroslavTulach commented May 12, 2023

TypeNamesTest failure

Looks like the first test in TypeNamesTest now influences the other one. Disabling the first one, or running just the second one makes the test pass. Also allocating different mkModuleContext helps.

enso$ git diff
diff --git engine/runtime/src/test/scala/org/enso/compiler/test/pass/resolve/TypeNamesTest.scala engine/runtime/src/test/scala/org/enso/compiler/test/pass/resolve/TypeNamesTest.scala
index a7147210cb..b00cfe4191 100644
--- engine/runtime/src/test/scala/org/enso/compiler/test/pass/resolve/TypeNamesTest.scala
+++ engine/runtime/src/test/scala/org/enso/compiler/test/pass/resolve/TypeNamesTest.scala
@@ -76,7 +76,7 @@ class TypeNamesTest extends CompilerTest {
   "Resolution of type names in modules" should {
     implicit val ctx: ModuleContext = mkModuleContext
 
-    "should correctly resolve local type names" in {
+    "should correctly resolve local type names" ignore {
       val ir =
         """
           |type A

@@ -102,6 +108,7 @@ public boolean isBefore(CompilationStage stage) {
private boolean hasCrossModuleLinks;
private final boolean synthetic;
private List<QualifiedName> directModulesRefs;
private BindingsMap bindings;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have hard times understanding why this field is needed. Why can't we operate with the BindingsMap only via ir.unsafeGetMetadata(BindingAnalysis)? How do we ensure that the values of this field will always be exactly the same as the value of this.ir.unsafeGetMetadata(BindingAnalysis)? Note that the BindingAnalysis phase is run on a particular module prior to import resolution, which means that the BindingMap is available soon.

Why cannot the problems with caches be resolved only via this.ir.usafeGetMetadata(BindingAnalysis)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not 100% sure yet, but it seems that when the BindingsMap gets read from stdlib caches, there are some inconsistencies.

When the caches exist the BindingsMap gets created sooner than IR. That's good, for purposes of #6100 we don't want to load IR just to resolve imports. However that means, having BindingsMap inside of IR is problematic in any case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BindingMap not being part of IR's metadata sounds reasonable. In that case, I would forbid to access BindingMap via ir.getMetadata, and only implement one way of accessing BindingMap - for example via Module.getBindings. I have a feeling that it is a bad idea for BindingMap to extend IRPass.Metadata anyway, since it is somewhat special in a sense that this metadata is filled even before import resolution starts. We should probably refactor BindingMap such that it is an internal part of the compiler and it is tightly coupled with a particular Module. What do you think?

@enso-bot enso-bot bot mentioned this pull request May 12, 2023
2 tasks
@JaroslavTulach
Copy link
Member Author

Removing most of own modifications and using #6655 implementation. Looks like SignatureTest and ImportsTest are failing.

@JaroslavTulach JaroslavTulach added the CI: Ready to merge This PR is eligible for automatic merge label May 14, 2023
@mergify mergify bot merged commit 41bb52c into develop May 14, 2023
@mergify mergify bot deleted the wip/jtulach/CheckAscribedTypes_6527 branch May 14, 2023 07:23
Procrat added a commit that referenced this pull request May 15, 2023
…z-6260

* develop:
  Build nightlies every day. (#6681)
  Force `newDashboard` default on the CI-built packages. (#6680)
  Verify ascribed types of parameters really exist (#6584)
  SuggestionBuilder needs to send ascribedType of constructor parameters (#6655)
  Improvements to the Table visualization. (#6653)
  Removing flush (#6670)
  Improving widgets for take/drop (#6641)
Procrat added a commit that referenced this pull request May 16, 2023
* develop:
  Build nightlies every day. (#6681)
  Force `newDashboard` default on the CI-built packages. (#6680)
  Verify ascribed types of parameters really exist (#6584)
  SuggestionBuilder needs to send ascribedType of constructor parameters (#6655)
  Improvements to the Table visualization. (#6653)
  Removing flush (#6670)
  Improving widgets for take/drop (#6641)
  disable authentication and newDashboard by default (#6664)
  Add COOP+COEP+CORP headers (#6646)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: No changelog needed Do not require a changelog entry for this PR. CI: Ready to merge This PR is eligible for automatic merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ascribed type of an argument isn't checked for correctness
8 participants