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

Parser: Full constructor syntax for type definitions; Field syntax; Complex operator sections; Template functions; Text improvements; Operator methods; eliminate Unsupported; better ArgumentDefinitions #3716

Merged
merged 39 commits into from
Oct 5, 2022

Conversation

kazcw
Copy link
Contributor

@kazcw kazcw commented Sep 15, 2022

Pull Request Description

I believe all parse failures remaining after these changes are because the new parser is intentionally stricter about some things. I'll be reviewing those failures and opening a bug to change the library/tests code.

Implements:

Breaking API changes

TypeDef is more specifically typed:

  • name has been restricted from Tree to Ident
  • argument values have been restricted from Tree to ArgumentDefinition

ArgumentDefinition now parses the default-value, ascribed-type, and execution-suspension-operator into fields, so that information can no longer be obtained by decomposing the pattern field.

Checklist

Please include the following checklist in your PR:

  • The documentation has been updated if necessary.
  • All code conforms to the
    Scala,
    Java,
    and
    Rust
    style guides.
  • All code has been tested:
    • Unit tests have been written where possible.
    • If GUI codebase was changed: Enso GUI was tested when built using BOTH
      ./run ide build and ./run ide watch.

[ci no changelog needed]

@kazcw kazcw self-assigned this Sep 15, 2022
@kazcw kazcw marked this pull request as ready for review September 15, 2022 20:47
@kazcw kazcw changed the title Parser: Full constructor syntax for type definitions Parser: Full constructor syntax for type definitions; Field syntax Sep 15, 2022
@kazcw kazcw changed the title Parser: Full constructor syntax for type definitions; Field syntax Parser: Full constructor syntax for type definitions; Field syntax; Complex operator sections; Template functions Sep 16, 2022
@kazcw kazcw marked this pull request as draft September 20, 2022 21:13
@kazcw
Copy link
Contributor Author

kazcw commented Sep 20, 2022

(Not ready for integration: I'm planning further changes to TypeDef tomorrow.)

@kazcw kazcw marked this pull request as draft September 30, 2022 05:57
@kazcw kazcw marked this pull request as ready for review September 30, 2022 05:57
data = ['data', self.to_vector.take (First max_data)])
data = ['data', self.to_vector.take (First max_data)]
Copy link
Member

Choose a reason for hiding this comment

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

Wow, the fact that we did not notice this is slightly concerning

}

private Option<IdentifiedLocation> getIdentifiedLocation(Token ast) {
return Option.apply(ast).map(ast_ -> {
Copy link
Member

Choose a reason for hiding this comment

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

There is a lot of functional style rewrites in this file! @kazcw, looks like you can (unlike me) write functionally (even) in Java.

Tree treeBody = null;
Tree.OprApp head = app;
while (head != null) {
// FIXME: Handle parameterized types here.
Copy link
Member

Choose a reason for hiding this comment

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

Do we have an Enso source example that needs handling?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a test case, with @Ignore for now. Before this PR, the test case fails due to incorrect IR (the previous code here flattened all types and their parameters into one list); after this PR, the unhandled case throws an exception from the line under this comment.

@kazcw kazcw marked this pull request as draft October 3, 2022 16:27
@kazcw kazcw marked this pull request as ready for review October 3, 2022 16:27
Copy link
Member

@JaroslavTulach JaroslavTulach left a comment

Choose a reason for hiding this comment

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

I see there is a failure in javac compilation:

INFO ide_ci::program::command: sbtℹ️ [warn] java.lang.AssertionError
 INFO ide_ci::program::command: sbtℹ️ [warn] 	at com.sun.tools.javac.util.Assert.error(Assert.java:155)
 INFO ide_ci::program::command: sbtℹ️ [warn] 	at com.sun.tools.javac.util.Assert.check(Assert.java:46)
 INFO ide_ci::program::command: sbtℹ️ [warn] 	at com.sun.tools.javac.code.Scope$ScopeImpl.leave(Scope.java:386)
 INFO ide_ci::program::command: sbtℹ️ [warn] 	at com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1474)
 INFO ide_ci::program::command: sbtℹ️ [warn] 	at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1082)
 INFO ide_ci::program::command: sbtℹ️ [warn] 	at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:696)
 INFO ide_ci::program::command: sbtℹ️ [warn] 	at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:770)
 INFO ide_ci::program::command: sbtℹ️ [warn] 	at com.sun.tools.javac.comp.Attr.visitMethodDef(Attr.java:1262)
 INFO ide_ci::program::command: sbtℹ️ [warn] 	at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:912)
 INFO ide_ci::program::command: sbtℹ️ [warn] 	at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:696)
 INFO ide_ci::program::command: sbtℹ️ [warn] 	at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:770)
 INFO ide_ci::program::command: sbtℹ️ [warn] 	at com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:5637)

I've had similar error yesterday and had to rewrite my code to be less fancy. The hardest task is to find the code that is causing the assert, however.

} else if (ast.getOpen2() != null) {
begin = ast.getOpen2().getStartCode();
} else if (ast.getSuspension() != null) {
begin = ast.getSuspension().getStartCode();
Copy link
Member

Choose a reason for hiding this comment

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

Open, open2, suspension!? That's complicated. Simple ArgumentDefinition.getOpen() with proper behavior would be better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

getOpen returns the outer parenthesis, if present. This logic is finding the textual begin and end of the ArgumentDefinition; which token begins the object depends on what syntax occurred within the argument definition. A pattern is always present, but there are optional parts that can extend to either side of it: A type annotation, a default value, and a ~ suspension operator, along with up to two pairs of parentheses (one around the type annotation and one around the default value). As noted in the comment earlier in the function, I think the proper solution is to refactor the IR so that its DefinitionArgument is not a node, and doesn't need a code span; however, I looked in to doing that, and it would require changes all across the compiler. I don't think it's worth it; this works.

@kazcw
Copy link
Contributor Author

kazcw commented Oct 4, 2022

I see there is a failure in javac compilation:

INFO ide_ci::program::command: sbtℹ️ [warn] java.lang.AssertionError
 INFO ide_ci::program::command: sbtℹ️ [warn] 	at com.sun.tools.javac.util.Assert.error(Assert.java:155)
 INFO ide_ci::program::command: sbtℹ️ [warn] 	at com.sun.tools.javac.util.Assert.check(Assert.java:46)
 INFO ide_ci::program::command: sbtℹ️ [warn] 	at com.sun.tools.javac.code.Scope$ScopeImpl.leave(Scope.java:386)
 INFO ide_ci::program::command: sbtℹ️ [warn] 	at com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1474)
 INFO ide_ci::program::command: sbtℹ️ [warn] 	at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1082)
 INFO ide_ci::program::command: sbtℹ️ [warn] 	at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:696)
 INFO ide_ci::program::command: sbtℹ️ [warn] 	at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:770)
 INFO ide_ci::program::command: sbtℹ️ [warn] 	at com.sun.tools.javac.comp.Attr.visitMethodDef(Attr.java:1262)
 INFO ide_ci::program::command: sbtℹ️ [warn] 	at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:912)
 INFO ide_ci::program::command: sbtℹ️ [warn] 	at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:696)
 INFO ide_ci::program::command: sbtℹ️ [warn] 	at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:770)
 INFO ide_ci::program::command: sbtℹ️ [warn] 	at com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:5637)

I've had similar error yesterday and had to rewrite my code to be less fancy. The hardest task is to find the code that is causing the assert, however.

Wow, I thought that was a transient glitch. We actually have to deal with a flaky compiler? I don't even know where to start debugging this, since it builds fine on my machine.

@JaroslavTulach
Copy link
Member

Wow, I thought that was a transient glitch. We actually have to deal with a flaky compiler? I don't even know where to start debugging this, since it builds fine on my machine.

Fixed in 5869412 - I could reproduce the problem by doing:

enso$ sbt> runtime/clean
enso$ sbt> buildEngineDistribution

now it seems to be fixed.

Btw. please take a look at my conflict resolution: e1c4b0a - it may not be correct.

@JaroslavTulach JaroslavTulach force-pushed the wip/kw/parser/typedefs branch from e1c4b0a to 5869412 Compare October 4, 2022 12:09
@@ -438,7 +438,6 @@ impl<'s> Resolver<'s> {
self.replace_current_with_parent_macro(parent_macro);
Step::MacroStackPop(token.into())
} else if let Some(segments) = root_macro_map.get(repr) {
// } else if let Some(segments) = root_macro_map.get(repr) && token.variant.can_start_macro() {
Copy link
Member

Choose a reason for hiding this comment

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

I wasn't sure which line to keep...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Your choice was correct, thanks for handling that merge. And thanks for fixing my too-fancy-for-the-compiler attempt at downcasting, I think instanceof is probably the more idiomatic implementation there anyway.

@JaroslavTulach
Copy link
Member

JaroslavTulach commented Oct 4, 2022

@kazcw
Copy link
Contributor Author

kazcw commented Oct 4, 2022

No, the code here is fine. There was a develop commit with broken formatting, and apparently CI merges current develop before linting (which makes sense, but was totally baffling until I figured out that was the problem).

@JaroslavTulach JaroslavTulach added the CI: Ready to merge This PR is eligible for automatic merge label Oct 5, 2022
@mergify mergify bot merged commit 44a031f into develop Oct 5, 2022
@mergify mergify bot deleted the wip/kw/parser/typedefs branch October 5, 2022 04:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: Ready to merge This PR is eligible for automatic merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants