Skip to content

Commit 580e83e

Browse files
committed
Skip setting type expansion context for captures of skipped functions
Type-checking and SILGen for non-inlinable functions is skipped in the presence of `-experimental-skip-non-inlinable-function-bodies` and `-experimental-skip-non-inlinable-function-bodies-without-types` flags. Such functions may be top-level and may contain captures (if they appear after a `guard` statement), for which we were setting the type expansion context during SILGen. Setting type expansion context however, relied on the capture info being computed -- which was never happening because of the abovementioned flags. Changes in this commit make setting type expansion context, for captures, conditional on a flag that ensures that the function has already been typechecked. Fixes #57646
1 parent ecca144 commit 580e83e

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

lib/SILGen/SILGen.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,14 +1430,14 @@ void SILGenModule::emitAbstractFuncDecl(AbstractFunctionDecl *AFD) {
14301430
void SILGenModule::emitFunction(FuncDecl *fd) {
14311431
assert(!shouldSkipDecl(fd));
14321432

1433-
Types.setCaptureTypeExpansionContext(SILDeclRef(fd), M);
1434-
14351433
SILDeclRef::Loc decl = fd;
14361434

14371435
emitAbstractFuncDecl(fd);
14381436

1439-
if (shouldEmitFunctionBody(fd))
1437+
if (shouldEmitFunctionBody(fd)) {
1438+
Types.setCaptureTypeExpansionContext(SILDeclRef(fd), M);
14401439
emitOrDelayFunction(SILDeclRef(decl));
1440+
}
14411441
}
14421442

14431443
void SILGenModule::addGlobalVariable(VarDecl *global) {

test/SILGen/top_level_captures.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
// RUN: %target-swift-frontend -emit-silgen %s | %FileCheck %s
22
// RUN: %target-swift-frontend -enable-experimental-async-top-level -emit-silgen %s | %FileCheck %s
3+
// RUN: %target-swift-frontend -experimental-skip-non-inlinable-function-bodies -experimental-skip-non-inlinable-function-bodies-without-types -emit-silgen %s | %FileCheck -check-prefix=SKIPPED-FUNC-EMITTED %s
34

45
guard let x: Int = nil else { while true { } }
56

67
// CHECK-LABEL: sil hidden [ossa] @$s18top_level_captures0C1XyyF : $@convention(thin) (Int) -> () {
8+
// SKIPPED-FUNC-EMITTED-LABEL-NOT: sil hidden [ossa] @$s18top_level_captures0C1XyyF : $@convention(thin) (Int) -> () {
79
func capturesX() {
810
_ = x
911
}
1012

1113
// CHECK-LABEL: sil hidden [ossa] @$s18top_level_captures17transitiveCaptureyyF : $@convention(thin) (Int) -> () {
1214
// CHECK: [[FUNC:%.*]] = function_ref @$s18top_level_captures0C1XyyF : $@convention(thin) (Int) -> ()
15+
// SKIPPED-FUNC-EMITTED-LABEL-NOT: sil hidden [ossa] @$s18top_level_captures17transitiveCaptureyyF : $@convention(thin) (Int) -> () {
16+
// SKIPPED-FUNC-EMITTED-NOT: [[FUNC:%.*]] = function_ref @$s18top_level_captures0C1XyyF : $@convention(thin) (Int) -> ()
1317
func transitiveCapture() {
1418
capturesX()
1519
}

0 commit comments

Comments
 (0)