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

Fix syntactic match of impl decl to definition #4709

Merged
merged 4 commits into from
Dec 20, 2024

Conversation

josh11b
Copy link
Contributor

@josh11b josh11b commented Dec 18, 2024

No description provided.

Comment on lines 220 to 222
// Subtracting 1 since we don't want to include the final `{` or `;` of the
// declaration when performing syntactic match.
Parse::NodeId last_param_node_id(end_of_decl_node_id.index - 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional: what do you think about a CHECK that the final token we're excluding is in fact { or ;?

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, along with a TODO comment.

// CHECK:STDOUT: %Interface.ref: type = name_ref Interface, file.%Interface.decl [template = constants.%Interface.type]
// CHECK:STDOUT: %T.param: %I.type = value_param runtime_param<invalid>
// CHECK:STDOUT: %T.loc11_14.1: %I.type = bind_symbolic_name T, 0, %T.param [symbolic = %T.loc11_14.2 (constants.%T.1)]
// CHECK:STDOUT: %I.ref.loc11: type = name_ref I, file.%I.decl [template = constants.%I.type]
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a surprising change for this PR -- is there some other change that was included when generating this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason this name changes is because before we had a separate definition with another %I.ref and after this change that definition instead reopens this impl declaration, so now there are two %I.refs in one scope.

// CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template = constants.%int_32]
// CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
// CHECK:STDOUT: %I.ref: type = name_ref I, file.%I.decl [template = constants.%I.type]
// CHECK:STDOUT: impl_decl @impl [template] {} {
Copy link
Contributor

Choose a reason for hiding this comment

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

My understanding is this is the result of no longer considering ;and { sufficient to differentiate two impls?

Is it possible yet to write a test that fundamentally fails without this fix rather than relying on catching it in the SemIR?

Copy link
Contributor Author

@josh11b josh11b Dec 19, 2024

Choose a reason for hiding this comment

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

I have a future PR that detects these errors. The fact that the tests before were passing is because it was ignoring the declaration, making it hard to create a failure when matching fails.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Future PR is #4719, which is currently failing but should pass once this is merged.

Copy link
Contributor

@chandlerc chandlerc left a comment

Choose a reason for hiding this comment

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

LG!

@josh11b josh11b added this pull request to the merge queue Dec 20, 2024
Merged via the queue into carbon-language:trunk with commit 85ea848 Dec 20, 2024
8 checks passed
@josh11b josh11b deleted the impl_match branch December 20, 2024 00:39
github-merge-queue bot pushed a commit that referenced this pull request Dec 20, 2024
This PR detects the failures that #4709 fixes.

---------

Co-authored-by: Josh L <josh11b@users.noreply.github.com>
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.

2 participants