-
Notifications
You must be signed in to change notification settings - Fork 10.5k
MoveOnlyChecker: Properly insert cleanup for dead try_apply def. #69887
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
jckarter
merged 1 commit into
swiftlang:main
from
jckarter:dead-resilient-deinit-on-throw
Nov 15, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
struct MyError: Error {} | ||
|
||
public struct Resilient: ~Copyable { | ||
static var nextValue: Int = 0 | ||
|
||
private(set) public var value: Int | ||
public init(nonthrowing: ()) { | ||
value = Self.nextValue | ||
Self.nextValue += 1 | ||
} | ||
deinit { print("resilient deinit \(value)") } | ||
|
||
public init(throwing: Bool) throws { | ||
if throwing { | ||
throw MyError() | ||
} | ||
self = .init(nonthrowing: ()) | ||
} | ||
public init(throwingAfterInit: Bool) throws { | ||
self = .init(nonthrowing: ()) | ||
if throwingAfterInit { | ||
throw MyError() | ||
} | ||
} | ||
|
||
public static func instanceCount() -> Int { | ||
return nextValue | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// RUN: %empty-directory(%t) | ||
// RUN: %target-build-swift -emit-module-path %t -enable-library-evolution -module-name moveonly_resilient_type -parse-as-library %S/Inputs/moveonly_resilient_type.swift -c -o %t/moveonly_resilient_type.o | ||
// RUN: %target-build-swift -enable-library-evolution -module-name moveonly_resilient_type -parse-as-library %S/Inputs/moveonly_resilient_type.swift -c -o %t/moveonly_resilient_type.o | ||
// RUN: %target-build-swift -o %t/a.out -I %t %s %t/moveonly_resilient_type.o | ||
// RUN: %target-run %t/a.out | %FileCheck %s | ||
|
||
// REQUIRES: executable_test | ||
|
||
// CHECK: starting | ||
|
||
import moveonly_resilient_type | ||
|
||
func makeItem1() throws -> Resilient { | ||
return Resilient(nonthrowing: ()) | ||
} | ||
|
||
func test1a() throws { | ||
// CHECK-NEXT: resilient deinit 0 | ||
_ = try makeItem1() | ||
} | ||
func test1b() throws { | ||
// CHECK-NEXT: resilient deinit 1 | ||
let x = try makeItem1() | ||
} | ||
|
||
func makeItem2(throwing: Bool) throws -> Resilient { | ||
return try Resilient(throwing: throwing) | ||
} | ||
|
||
func test2aa() throws { | ||
// CHECK-NEXT: resilient deinit 2 | ||
_ = try makeItem2(throwing: false) | ||
} | ||
|
||
func test2ab() throws { | ||
_ = try makeItem2(throwing: true) | ||
} | ||
|
||
func test2ba() throws { | ||
// CHECK-NEXT: resilient deinit 3 | ||
let x = try makeItem2(throwing: false) | ||
} | ||
|
||
func test2bb() throws { | ||
let x = try makeItem2(throwing: true) | ||
} | ||
|
||
func makeItem3(throwing: Bool) throws -> Resilient { | ||
return try Resilient(throwingAfterInit: throwing) | ||
} | ||
|
||
func test3aa() throws { | ||
// CHECK-NEXT: resilient deinit 4 | ||
_ = try makeItem3(throwing: false) | ||
} | ||
|
||
func test3ab() throws { | ||
// CHECK-NEXT: resilient deinit 5 | ||
_ = try makeItem3(throwing: true) | ||
} | ||
|
||
func test3ba() throws { | ||
// CHECK-NEXT: resilient deinit 6 | ||
let x = try makeItem3(throwing: false) | ||
} | ||
|
||
func test3bb() throws { | ||
// CHECK-NEXT: resilient deinit 7 | ||
let x = try makeItem3(throwing: true) | ||
} | ||
|
||
func main() { | ||
print("starting") | ||
_ = try? test1a() | ||
_ = try? test1b() | ||
_ = try? test2aa() | ||
_ = try? test2ab() | ||
_ = try? test2ba() | ||
_ = try? test2bb() | ||
_ = try? test3aa() | ||
_ = try? test3ab() | ||
_ = try? test3ba() | ||
_ = try? test3bb() | ||
|
||
// CHECK-NEXT: 8 instances in total | ||
print("\(Resilient.instanceCount()) instances in total") | ||
} | ||
main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jckarter can you add in a main only PR, a test case that validates the SILGen we emit here?