Skip to content

[5.7] Add test case for disabling lexical lifetimes. #42233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions test/SILOptimizer/lexical_lifetime_elim.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// RUN: %target-swift-frontend -emit-sil -O -parse-as-library -enable-copy-propagation=false -Xllvm -sil-print-all -module-name=main %s 2>&1 | %FileCheck %s
// RUN: %target-swift-frontend -emit-sil -O -parse-as-library -enable-lexical-lifetimes=false -Xllvm -sil-print-all -module-name=main %s 2>&1 | %FileCheck %s

@inline(never)
func takeGuaranteed(_ a: AnyObject) -> AnyObject {
return a
}

// CHECK-LABEL: // testLexical(a:)
// CHECK: [[B:%.*]] = begin_borrow [lexical] %0
// CHECK: apply %{{.*}}([[B]])
// CHECK: apply
// CHECK: end_borrow [[B]]
// CHECK-LABEL: } // end sil function

// LexicalLifetimeEliminator must strip the [lexical] flag
// before the first round of SemanticARCOpts.

// CHECK-NOT: *** SIL function after {{.*}} (semantic-arc-opts)

// CHECK-LABEL: *** SIL function after {{.*}} (sil-lexical-lifetime-eliminator)
// CHECK-LABEL: // testLexical(a:)
// CHECK: [[B:%.*]] = begin_borrow %0
// CHECK: apply %{{.*}}([[B]])
// CHECK: apply
// CHECK: end_borrow [[B]]
// CHECK-LABEL: } // end sil function

// The first round of SemanticARCOpts must eliminate the borrow scope
// that was only needed for a lexical lifetime.

// CHECK-LABEL: *** SIL function after {{.*}} (semantic-arc-opts)
// CHECK-LABEL: // testLexical(a:)
// CHECK: apply %{{.*}}(%0)
// CHECK-LABEL: } // end sil function
public func testLexical(a: __owned AnyObject) -> AnyObject {
// Without lexical lifetimes, the lifetime of 'a' ends in between the two calls:
return takeGuaranteed(takeGuaranteed(a))
}