Skip to content

[ASTScope] Introduce isa/cast/dyn_cast support to ASTScope hierarchy #70272

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 7 commits into from
Dec 7, 2023

Conversation

DougGregor
Copy link
Member

The ASTScope class hierarchy rooted at ASTScopeImpl is relying entirely
on overridden virtual functions and, in some cases, string comparisons
on the class name, to provide customization for the various classes.
Introduce proper LLVM dynamic casting support to this class hierarchy,
eliminating the string comparisons and the manually-specified
implementations of getClassName (which is now used only for printing).

Replace a number of virtual query functions like getDeclIfAny, which had
to be overridden at various points in the hierarchy, with simpler
implementations based on the scope kind and dyn_cast.
Macro-metaprogram whether each scope node is associated with a
particular declaration/statement/expression/attribute so these
implementations can be efficiently macro-metaprogrammed.

We've been meaning to do this for years, but today I got angry enough.

The ASTScope class hierarchy rooted at ASTScopeImpl is relying entirely
on overridden virtual functions and, in some cases, string comparisons
on the class name, to provide customization for the various classes.
Introduce proper LLVM dynamic casting support to this class hierarchy,
eliminating the string comparisons and the manually-specified
implementations of `getClassName` (which is now used only for printing).

We've been meaning to do this for years, but today I got angry enough.
Replace a number of virtual query functions like `getDeclIfAny`, which had
to be overridden at various points in the hierarchy, with simpler
implementations based on the scope kind and `dyn_cast`.
Macro-metaprogram whether each scope node is associated with a
particular declaration/statement/expression/attribute so these
implementations can be efficiently macro-metaprogrammed.
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor DougGregor enabled auto-merge December 6, 2023 18:32
The subclasses of `GenericTypeOrExtensionScope` are customized by a `Portion`
mix-in class that effectively makes each into several different scope
nodes: one for the "whole decl", one for the where clause, one for the
body. Re-introduce the customized `getClassName()` operation so we get
the nicer debugging dumps.
The implementation of "lookup the catch node" is scattered throughout
various `ASTScopeImpl` subclasses. Remove that, and instead centralize
the code to find the innermost catch scope.
... it's just a `dyn_cast` now.
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

We only used this in one place, and then immediately filtered down
to a `CustomAttr`. Just use `dyn_cast` in the obvious way and remove
this function.
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor
Copy link
Member Author

@swift-ci please smoke test macOS

1 similar comment
@DougGregor
Copy link
Member Author

@swift-ci please smoke test macOS

@DougGregor DougGregor merged commit fbf945d into swiftlang:main Dec 7, 2023
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.

1 participant