Skip to content

Commit 2f0a22c

Browse files
committed
Sema: Only build the root TypeRefinementContext node once.
Previously, the root TypeRefinementContext could contain duplicate top level nodes for any source file that had its TRC built on-demand to satisfy type checking requests before that file was explicitly typechecked.
1 parent 07a987c commit 2f0a22c

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,18 +1342,20 @@ class TypeRefinementContextBuilder : private ASTWalker {
13421342
} // end anonymous namespace
13431343

13441344
void TypeChecker::buildTypeRefinementContextHierarchy(SourceFile &SF) {
1345-
TypeRefinementContext *RootTRC = SF.getTypeRefinementContext();
13461345
ASTContext &Context = SF.getASTContext();
13471346
assert(!Context.LangOpts.DisableAvailabilityChecking);
13481347

1349-
if (!RootTRC) {
1350-
// The root type refinement context reflects the fact that all parts of
1351-
// the source file are guaranteed to be executing on at least the minimum
1352-
// platform version for inlining.
1353-
auto MinPlatformReq = AvailabilityRange::forInliningTarget(Context);
1354-
RootTRC = TypeRefinementContext::createForSourceFile(&SF, MinPlatformReq);
1355-
SF.setTypeRefinementContext(RootTRC);
1356-
}
1348+
// If there's already a root node, then we're done.
1349+
if (SF.getTypeRefinementContext())
1350+
return;
1351+
1352+
// The root type refinement context reflects the fact that all parts of
1353+
// the source file are guaranteed to be executing on at least the minimum
1354+
// platform version for inlining.
1355+
auto MinPlatformReq = AvailabilityRange::forInliningTarget(Context);
1356+
TypeRefinementContext *RootTRC =
1357+
TypeRefinementContext::createForSourceFile(&SF, MinPlatformReq);
1358+
SF.setTypeRefinementContext(RootTRC);
13571359

13581360
// Build refinement contexts, if necessary, for all declarations starting
13591361
// with StartElem.

0 commit comments

Comments
 (0)