Skip to content

Commit edb0b92

Browse files
committed
Parser: Register all availability macro definition buffers before parsing
The availability macro definitions from the command line are copied into source buffers for parsing. Let's register all of these buffers in one go, before starting to parse any of them. Parsing triggers using `findBuffer` services which sorts all buffers. The new logic should ensure this sorting happens only once for availability macros.
1 parent ff803c6 commit edb0b92

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2120,11 +2120,18 @@ AvailabilityMacroMap &Parser::parseAllAvailabilityMacroArguments() {
21202120
SourceManager &SM = Context.SourceMgr;
21212121
LangOptions LangOpts = Context.LangOpts;
21222122

2123+
// Allocate all buffers in one go to avoid repeating the sorting in
2124+
// findBufferContainingLocInternal.
2125+
llvm::SmallVector<unsigned, 4> bufferIDs;
21232126
for (StringRef macro: LangOpts.AvailabilityMacros) {
2127+
unsigned bufferID = SM.addMemBufferCopy(macro,
2128+
"-define-availability argument");
2129+
bufferIDs.push_back(bufferID);
2130+
}
21242131

2132+
// Parse each macro definition.
2133+
for (unsigned bufferID: bufferIDs) {
21252134
// Create temporary parser.
2126-
int bufferID = SM.addMemBufferCopy(macro,
2127-
"-define-availability argument");
21282135
swift::ParserUnit PU(SM, SourceFileKind::Main, bufferID, LangOpts,
21292136
TypeCheckerOptions(), SILOptions(), "unknown");
21302137

0 commit comments

Comments
 (0)