Skip to content

Commit dfa916a

Browse files
authored
Merge pull request swiftlang#74147 from slavapestov/fix-rdar129255744-6.0
AST: Don't skip function bodies that follow a top-level guard [6.0]
2 parents 9d3ac43 + 270eb43 commit dfa916a

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

lib/AST/Decl.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9495,6 +9495,12 @@ bool IsFunctionBodySkippedRequest::evaluate(
94959495
skippingMode == FunctionBodySkipping::NonInlinableWithoutTypes)
94969496
return false;
94979497

9498+
// Don't skip functions that follow a top-level guard statement.
9499+
if (afd->getDeclContext()->isModuleScopeContext() &&
9500+
isa<FuncDecl>(afd) &&
9501+
cast<FuncDecl>(afd)->hasTopLevelLocalContextCaptures())
9502+
return false;
9503+
94989504
// Skip functions that don't need to be serialized.
94999505
return afd->getResilienceExpansion() != ResilienceExpansion::Minimal;
95009506
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %target-swift-frontend -experimental-skip-non-inlinable-function-bodies-without-types -emit-module %s
2+
3+
let s: Int? = nil
4+
guard let m = s else { fatalError() }
5+
6+
let x = m
7+
8+
public func f(_: Int = m, _: String = "") {}
9+
10+
f()

test/SILGen/top_level_captures.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
guard let x: Int = nil else { while true { } }
66

77
// 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) -> () {
8+
// SKIPPED-FUNC-EMITTED-LABEL: sil hidden [ossa] @$s18top_level_captures0C1XyyF : $@convention(thin) (Int) -> () {
99
func capturesX() {
1010
_ = x
1111
}
1212

1313
// CHECK-LABEL: sil hidden [ossa] @$s18top_level_captures17transitiveCaptureyyF : $@convention(thin) (Int) -> () {
1414
// 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) -> ()
15+
// SKIPPED-FUNC-EMITTED-LABEL: sil hidden [ossa] @$s18top_level_captures17transitiveCaptureyyF : $@convention(thin) (Int) -> () {
16+
// SKIPPED-FUNC-EMITTED: [[FUNC:%.*]] = function_ref @$s18top_level_captures0C1XyyF : $@convention(thin) (Int) -> ()
1717
func transitiveCapture() {
1818
capturesX()
1919
}

0 commit comments

Comments
 (0)