Skip to content

[AST] A couple of PatternBindingInitializer cleanups #70591

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

Merged
merged 9 commits into from
Jan 18, 2024

Conversation

hamishknight
Copy link
Contributor

Remove SerializedPatternBindingInitializer & SerializedDefaultArgumentInitializer since we can deserialize PatternBindingInitializer & DefaultArgumentInitializer directly (as I understand it, the SerializedXXX decl contexts only exist for cases where we don't want to serialize e.g a full ClosureExpr/TopLevelDecl, that doesn't apply here). This then allows us to clean up PatternBindingDecl's handling of PatternBindingInitializer a bit.

This stores the same state as
PatternBindingInitializer, we can use that
instead.
This stores the same state as
DefaultArgumentInitializer, use that instead.
Switch from promising a DeclContext to a
PatternBindingInitializer.

This has a couple of benefits:
- It eliminates a few places where we were force
`cast`'ing to PatternBindingInitializer.
- It improves the clarity of what's being stored,
it's not whatever the parent context of the
initializer is, it's specifically the
PatternBindingInitializer context if it exists.
Use the PatternBindingInitializer context if we
have one. This also uncovered a parser issue where
we would mistakenly create a
PatternBindingInitializer in top-level code after
parsing the initializers.
Most clients only want to set one of the two
parameters, split it into `setPattern` and
`setInitContext` (the latter of which now
handles calling `setBinding`).
And add some assertions to ensure we don't attempt
to re-set the binding or index (the parent context
can unfortunately change currently).
This could result in us changing the binding
index after-the-fact.
@hamishknight
Copy link
Contributor Author

@swift-ci please test

@hamishknight
Copy link
Contributor Author

@swift-ci please test source compatibility

@hamishknight hamishknight marked this pull request as ready for review January 17, 2024 16:03
Copy link
Contributor

@slavapestov slavapestov left a comment

Choose a reason for hiding this comment

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

Nice!

@@ -115,8 +113,6 @@ enum class DeclContextKind : unsigned {
/// \see SerializedLocalDeclContext.
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment is out of date. Is DeclContextKind::SerializedLocal also dead now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah looks like we can probably just rip out SerializedLocalDeclContext at this point, I'll do that in a follow-up

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hamishknight
Copy link
Contributor Author

Source compat failures are unrelated

@hamishknight hamishknight merged commit f6b7301 into swiftlang:main Jan 18, 2024
@hamishknight hamishknight deleted the doritos-and-fritos branch January 18, 2024 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants