Skip to content

Commit 5deb21d

Browse files
committed
FineModuleTrace: avoid emitting trace file when lazy type checking is enabled.
When lazy type checking is enabled, the generated AST to walk on may contain function bodies that are not fully type-checked. Walking on these function bodies could expose latent bugs. Resolves rdar://140818215
1 parent efd33de commit 5deb21d

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

lib/FrontendTool/LoadedModuleTrace.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,10 @@ static void createFineModuleTraceFile(const InputFile &input, ModuleDecl *MD) {
917917

918918
bool swift::emitFineModuleTraceIfNeeded(ModuleDecl *mainModule,
919919
const FrontendOptions &opts) {
920+
// When lazy type checking is enabled, we may end up with a partial AST.
921+
// Walking on these partial AST completely may expose latent bugs.
922+
if (mainModule->getASTContext().TypeCheckerOpts.EnableLazyTypecheck)
923+
return false;
920924
ASTContext &ctxt = mainModule->getASTContext();
921925
assert(!ctxt.hadError() &&
922926
"We should've already exited earlier if there was an error.");

test/IDE/objc_send_collector_1.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
// RUN: SWIFT_COMPILER_FINE_GRAINED_TRACE_PATH=%t/given_trace.json %target-swift-frontend -I %t/lib/swift -typecheck %s %S/Inputs/objc_send_collector_2.swift -module-name main -swift-version 5 -F %S/Inputs/mock-sdk -emit-loaded-module-trace-path %t/.MODULE_TRACE
88
// RUN: cat %t/given_trace.json | %{python} -c 'import json, sys; json.dump(json.loads(sys.stdin.read()), sys.stdout, sort_keys=True, indent=2)' | %FileCheck %s
99

10+
// RUN: SWIFT_COMPILER_FINE_GRAINED_TRACE_PATH=%t/given_trace_2.json %target-swift-frontend -I %t/lib/swift -typecheck %s %S/Inputs/objc_send_collector_2.swift -module-name main -swift-version 5 -F %S/Inputs/mock-sdk -emit-loaded-module-trace-path %t/.MODULE_TRACE -enable-library-evolution -experimental-lazy-typecheck
11+
// RUN: not ls %t/given_trace_2.json
12+
1013
// REQUIRES: objc_interop
1114

1215
import Foo

0 commit comments

Comments
 (0)