Skip to content

Implement syntactic merge checks for parameters.#4149

Merged
jonmeow merged 4 commits into
carbon-language:trunkfrom
jonmeow:syntactic-merge
Jul 23, 2024
Merged

Implement syntactic merge checks for parameters.#4149
jonmeow merged 4 commits into
carbon-language:trunkfrom
jonmeow:syntactic-merge

Conversation

@jonmeow

@jonmeow jonmeow commented Jul 19, 2024

Copy link
Copy Markdown
Contributor

Note this isn't implementing checking through imports. The parse node there is harder to access through the context, so would require examining the entity in order to get the import declaration, to get at the ImportIR. We also don't have a parse tree attached in that case, and would need to add one to SemIR::File. But I believe we do want to add that, so it's explicitly a TODO.

Note GetTokenText re-lexes literal values, so there's a bit of potential overhead there. Not sure if we want a more efficient manner for comparing in cases like this.

@github-actions github-actions Bot requested a review from josh11b July 19, 2024 17:58
@josh11b

josh11b commented Jul 20, 2024

Copy link
Copy Markdown
Contributor

Please find another reviewer, as I'll be on vacation for the next two weeks.

@jonmeow jonmeow requested review from zygoloid and removed request for josh11b July 22, 2024 17:27

@zygoloid zygoloid left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks!

Another edge case that would be useful to explicitly test (mostly because we've had discussions about using a different rule) is grouping parentheses differing between declarations.

Comment thread toolchain/check/merge.cpp Outdated
Comment thread toolchain/check/merge.cpp Outdated
@jonmeow

jonmeow commented Jul 22, 2024

Copy link
Copy Markdown
Contributor Author

Another edge case that would be useful to explicitly test (mostly because we've had discussions about using a different rule) is grouping parentheses differing between declarations.

Added test

Also, made me realize I wasn't testing deduced params explicitly, so added that too.

@jonmeow

jonmeow commented Jul 22, 2024

Copy link
Copy Markdown
Contributor Author

Per discussion, added a test for r# identifiers (because you'd mentioned them in a comment), and made them a TODO

@jonmeow jonmeow added this pull request to the merge queue Jul 22, 2024
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 22, 2024
@zygoloid zygoloid added this pull request to the merge queue Jul 23, 2024
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 23, 2024
@jonmeow jonmeow enabled auto-merge July 23, 2024 20:15
@jonmeow jonmeow added this pull request to the merge queue Jul 23, 2024
Merged via the queue into carbon-language:trunk with commit db02265 Jul 23, 2024
@jonmeow jonmeow deleted the syntactic-merge branch July 23, 2024 20:42
brymer-meneses pushed a commit to brymer-meneses/carbon-lang that referenced this pull request Aug 15, 2024
Note this isn't implementing checking through imports. The parse node
there is harder to access through the context, so would require
examining the entity in order to get the import declaration, to get at
the ImportIR. We also don't have a parse tree attached in that case, and
would need to add one to SemIR::File. But I believe we do want to add
that, so it's explicitly a TODO.

Note GetTokenText re-lexes literal values, so there's a bit of potential
overhead there. Not sure if we want a more efficient manner for
comparing in cases like this.
github-merge-queue Bot pushed a commit that referenced this pull request Jan 21, 2025
I believe `check_syntax` is already controlling the semantic vs
syntactic merge, added in #4149. Other parts of the TODO are clarified
per discussion. But this is tested, e.g. errors with the bool flipped:

```
 impl i32 as I {
+  // CHECK:STDERR: method.carbon:[[@line+6]]:14: error: redeclaration syntax di
ffers here [RedeclParamSyntaxDiffers]
+  // CHECK:STDERR:   fn F[self: i32](other: i32) -> i32 = "int.sadd";
+  // CHECK:STDERR:              ^~~
+  // CHECK:STDERR: method.carbon:[[@Line-7]]:14: note: comparing with previous
declaration here [RedeclParamSyntaxPrevious]
+  // CHECK:STDERR:   fn F[self: Self](other: Self) -> Self;
+  // CHECK:STDERR:              ^~~~
   fn F[self: i32](other: i32) -> i32 = "int.sadd";
 }
```
dwblaikie pushed a commit to dwblaikie/carbon-lang that referenced this pull request Jan 21, 2025
I believe `check_syntax` is already controlling the semantic vs
syntactic merge, added in carbon-language#4149. Other parts of the TODO are clarified
per discussion. But this is tested, e.g. errors with the bool flipped:

```
 impl i32 as I {
+  // CHECK:STDERR: method.carbon:[[@line+6]]:14: error: redeclaration syntax di
ffers here [RedeclParamSyntaxDiffers]
+  // CHECK:STDERR:   fn F[self: i32](other: i32) -> i32 = "int.sadd";
+  // CHECK:STDERR:              ^~~
+  // CHECK:STDERR: method.carbon:[[@Line-7]]:14: note: comparing with previous
declaration here [RedeclParamSyntaxPrevious]
+  // CHECK:STDERR:   fn F[self: Self](other: Self) -> Self;
+  // CHECK:STDERR:              ^~~~
   fn F[self: i32](other: i32) -> i32 = "int.sadd";
 }
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants