[Macros] Top-level freestanding macros (#63553)

Allow freestanding macros to be used at top-level.
- Parse top-level `#…` as `MacroExpansionDecl` when we are not in scripting mode.
- Add macro expansion decls to the source lookup cache with name-driven lazy expansion. Not supporting arbitrary name yet.
- Experimental support for script mode and brace-level declaration macro expansions: When type-checking a `MacroExpansionExpr`, assign it a substitute `MacroExpansionDecl` if the macro reference resolves to a declaration macro. This doesn’t work quite fully yet and will be enabled in a future fix.
This commit is contained in:
Richard Wei
2023-03-06 07:15:20 -08:00
committed by GitHub
parent 19335a1dcf
commit 833338f9ce
37 changed files with 486 additions and 188 deletions

View File

@@ -2246,7 +2246,7 @@ static uint8_t getRawStableMacroRole(swift::MacroRole context) {
}
#undef CASE
llvm_unreachable("bad result declaration macro kind");
}
}
static uint8_t getRawStableMacroIntroducedDeclNameKind(
swift::MacroIntroducedDeclNameKind kind) {
@@ -6133,7 +6133,7 @@ void Serializer::writeAST(ModuleOrSourceFile DC) {
// FIXME: Switch to a visitor interface?
SmallVector<Decl *, 32> fileDecls;
nextFile->getTopLevelDecls(fileDecls);
nextFile->getTopLevelDeclsWithAuxiliaryDecls(fileDecls);
for (auto D : fileDecls) {
if (isa<ImportDecl>(D) || isa<IfConfigDecl>(D) ||