Skip to content

[AST] Requestify local type declarations #70737

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 1 commit into from
Jan 6, 2024

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Jan 5, 2024

Instead of recording local type declarations while parsing, make a request to collect them from the AST.
This reduces the side effect of parsing.

Instead of recording local type declarations while parsing, make a
request to collect them from the AST. This reduces the side effect of
parsing.
@rintaro
Copy link
Member Author

rintaro commented Jan 5, 2024

@swift-ci Please smoke test

@rintaro
Copy link
Member Author

rintaro commented Jan 5, 2024

@swift-ci Please Test Source Compatibility

case DeclKind::Struct:
case DeclKind::Class:
case DeclKind::Protocol:
case DeclKind::TypeAlias:
Copy link
Member Author

@rintaro rintaro Jan 5, 2024

Choose a reason for hiding this comment

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

I'm not really sure we need TypeAlias here. IRGen and SILGen don't seem to handle them. Maybe isa<NominalTypeDecl>(D) might be better?

Copy link
Member

Choose a reason for hiding this comment

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

It seems reasonable to keep type aliases here so that this request returns all local types, even if IRGen and SILGen don't care. Debugging and module emission probably care, for example.

Copy link
Member

@DougGregor DougGregor left a comment

Choose a reason for hiding this comment

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

Fantastic, thank you!

case DeclKind::Struct:
case DeclKind::Class:
case DeclKind::Protocol:
case DeclKind::TypeAlias:
Copy link
Member

Choose a reason for hiding this comment

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

It seems reasonable to keep type aliases here so that this request returns all local types, even if IRGen and SILGen don't care. Debugging and module emission probably care, for example.

@@ -1444,7 +1444,8 @@ void SourceFile::getPrecedenceGroups(
}

void SourceFile::getLocalTypeDecls(SmallVectorImpl<TypeDecl*> &Results) const {
Copy link
Contributor

Choose a reason for hiding this comment

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

I might be missing a reference, but I believe the only two uses of this can just be replaced with getLocalTypeDecls() - neither use mutates the vector after retrieving them.

Copy link
Member Author

@rintaro rintaro Jan 5, 2024

Choose a reason for hiding this comment

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

Module::getLocalTypeDecl() calls FileUnit::getLocalTypeDecls(SmallVectorImpl<TypeDecl*>). Since SerializedASTFile doesn't hold them as a list of TypeDecl * we can't simply make it return ArrayRef.

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!

@rintaro rintaro merged commit 8f29f15 into swiftlang:main Jan 6, 2024
@rintaro rintaro deleted the ast-localtypedecls branch January 6, 2024 07:14
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.

4 participants