-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Clang importer + macros] Handle name lookup and type checking for expanded macros #77580
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
[Clang importer + macros] Handle name lookup and type checking for expanded macros #77580
Conversation
@swift-ci please smoke test |
39afec7
to
0bcd251
Compare
generatedInfo->kind != GeneratedSourceInfo::PrettyPrinted) | ||
generatedInfo->kind != GeneratedSourceInfo::PrettyPrinted && | ||
generatedInfo->kind != GeneratedSourceInfo::DefaultArgument && | ||
generatedInfo->kind != GeneratedSourceInfo::Attribute) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment above says "We only care about macros, so skip everything else", but aren't macros attributes in the grammar? I wouldn't expect us to skip GeneratedSourceInfo::Attribute
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment means "we only care about macro expansion buffers." I'll clarify it
// RUN: %FileCheck -input-file %t/imported.printed.txt %s | ||
// RUN: echo "" >> %t/stderr.log | ||
// RUN: %FileCheck -check-prefix DIAGS -input-file %t/stderr.log %s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it not possible to instead have swift-ide-test
return an error code if the input has errors? That seems like a simpler solution. Not sure what effect they have, but it sounds like --test-input-complete
or --typecheck
could be useful.
@@ -122,7 +122,8 @@ public func parseSourceFile( | |||
.preambleMacroExpansion, | |||
.replacedFunctionBody, | |||
.prettyPrinted, | |||
.defaultArgument: | |||
.defaultArgument, | |||
.attribute: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you move .attribute
to . memberAttributeMacroExpansion
branch below, it's still not implemented and doing the same thing, but just not to forget to move it later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, done!
While you are here, could you make the parsing use |
@@ -364,7 +366,8 @@ SourceFileParsingResult parseSourceFile(SourceFile &SF) { | |||
break; | |||
} | |||
|
|||
case GeneratedSourceInfo::MemberAttributeMacroExpansion: { | |||
case GeneratedSourceInfo::MemberAttributeMacroExpansion: | |||
case GeneratedSourceInfo::Attribute: { | |||
parser.parseExpandedAttributeList(items); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh apparently, swift_attr
accepts modifiers OR attributes, but parseExpandedAttributeList
only accepts attributes? 🤔
swift/lib/ClangImporter/ImportDecl.cpp
Lines 8411 to 8427 in 0bcd251
if (parser.Tok.is(tok::at_sign)) { | |
SourceLoc atEndLoc = parser.Tok.getRange().getEnd(); | |
SourceLoc atLoc = parser.consumeToken(tok::at_sign); | |
hadError = parser | |
.parseDeclAttribute(MappedDecl->getAttrs(), atLoc, | |
atEndLoc, initContext, | |
/*isFromClangAttribute=*/true) | |
.isError(); | |
} else { | |
SourceLoc staticLoc; | |
StaticSpellingKind staticSpelling; | |
hadError = parser | |
.parseDeclModifierList(MappedDecl->getAttrs(), staticLoc, | |
staticSpelling, | |
/*isFromClangAttribute=*/true) | |
.isError(); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, and we have some things that are permitted but are neither attributes nor modifiers, which is odd. I'm going to have to think about this refactoring more.
… as attributes Previously, they were being parsed as top-level code, which would cause errors because there are no definitions. Introduce a new GeneratedSourceInfo kind to mark the purpose of these buffers so the parser can handle them appropriately.
…ule-sensitive We need different buffers for each imported module that has swift_attr attributes, so cache them appropriately.
Right now, we're creating a bunch of throwaway ErrorExpr nodes in the AST.
…panded macros Introduce a number of fixes to allow us to fully use declarations that are produced by applying a peer macro to an imported declarations. These changes include: * Ensuring that we have the right set of imports in the source file containing the macro expansion, because it depends only on the module it comes from * Ensuring that name lookup looks in that file even when the DeclContext hierarchy doesn't contain the source file (because it's based on the Clang module structure) Expand testing to be sure that we're getting the right calls, diagnostics, and generated IR symbols.
c579a63
to
8f5e941
Compare
@swift-ci please smoke test |
@swift-ci please smoke test |
@swift-ci please smoke test |
Introduce a number of fixes to allow us to fully use declarations that are produced by applying a peer macro to an imported declarations.
These changes include:
swift_attr
macros as one that stores macros, so we don't parse it as top-level codeExpand testing to be sure that we're getting the right calls, diagnostics, printing APIs, and generated IR symbols.