-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SILGen] Optimize generated dealloc for linearly recursive data struc… #41459
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
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ec0750c
[SILGen] Optimize generated dealloc for linearly recursive data struc…
drexin 014fd2b
Small cleanup
drexin d61e386
Add tests and incorporate feedback
drexin c1bed74
Fix deinit_recursive test by using non-trivial type for elem
drexin 0f58bf6
Add tests for generics and fix handling of generics
drexin 32616ee
Fix symbols in tests after reorganizing
drexin 542c395
Addressed more review feedback
drexin 06aa334
Address review feedback
drexin ba0de89
Addressed more review feedback
drexin 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
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,20 @@ | ||
// RUN: %target-run-simple-swift | ||
|
||
// REQUIRES: executable_test | ||
|
||
class Node { | ||
var next: Node? | ||
} | ||
|
||
var first: Node? = nil | ||
for _ in 1...3_000_000 { | ||
let next = Node() | ||
next.next = first | ||
first = next | ||
} | ||
|
||
@inline(never) | ||
func deallocList() { | ||
first = nil | ||
} | ||
deallocList() |
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,23 @@ | ||
// RUN: %target-swift-emit-silgen %s | %FileCheck %s | ||
|
||
// Non-linearly recursive structures should not get optimized | ||
class Tree { | ||
var left: Tree? | ||
var right: Tree? | ||
} | ||
|
||
// CHECK: sil hidden [ossa] @$s26deinit_recursive_branching4TreeCfd : $@convention(method) (@guaranteed Tree) -> @owned Builtin.NativeObject { | ||
// CHECK: // [[SELF:%.*]] "self" | ||
// CHECK: bb0([[SELF]] : @guaranteed $Tree): | ||
// CHECK: [[LEFT:%.*]] = ref_element_addr [[SELF]] : $Tree, #Tree.left | ||
// CHECK: [[LEFT_ACCESS:%.*]] = begin_access [deinit] [static] [[LEFT]] : $*Optional<Tree> | ||
// CHECK: destroy_addr [[LEFT_ACCESS]] : $*Optional<Tree> | ||
// CHECK: end_access [[LEFT_ACCESS]] : $*Optional<Tree> | ||
// CHECK: [[RIGHT:%.*]] = ref_element_addr [[SELF]] : $Tree, #Tree.right | ||
// CHECK: [[RIGHT_ACCESS:%.*]] = begin_access [deinit] [static] [[RIGHT]] : $*Optional<Tree> | ||
// CHECK: destroy_addr [[RIGHT_ACCESS]] : $*Optional<Tree> | ||
// CHECK: end_access [[RIGHT_ACCESS]] : $*Optional<Tree> // id: %9 | ||
// CHECK: [[SELF_NATIVE:%.*]] = unchecked_ref_cast [[SELF]] : $Tree to $Builtin.NativeObject | ||
// CHECK: [[SELF_NATIVE_OWNED:%.*]] = unchecked_ownership_conversion [[SELF_NATIVE]] : $Builtin.NativeObject, @guaranteed to @owned | ||
// CHECK: return [[SELF_NATIVE_OWNED]] : $Builtin.NativeObject | ||
// CHECK: } // end sil function '$s26deinit_recursive_branching4TreeCfd' |
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,57 @@ | ||
// RUN: %target-swift-emit-silgen %s | %FileCheck %s | ||
|
||
class Node { | ||
var elem: [Int64] = [] | ||
var next: Node? | ||
} | ||
|
||
// CHECK: sil hidden [ossa] @$s23deinit_recursive_linear4NodeCfd : $@convention(method) (@guaranteed Node) -> @owned Builtin.NativeObject { | ||
// CHECK: [[SELF:%.*]] "self" | ||
// CHECK: bb0([[SELF]] : @guaranteed $Node): | ||
// CHECK: [[ELEM:%.*]] = ref_element_addr [[SELF]] : $Node, #Node.elem | ||
// CHECK: [[ELEM_ACCESS:%.*]] = begin_access [deinit] [static] [[ELEM]] : $*Array<Int64> | ||
// CHECK: destroy_addr [[ELEM_ACCESS]] : $*Array<Int64> | ||
// CHECK: end_access [[ELEM_ACCESS]] : $*Array<Int64> | ||
// CHECK: [[NIL:%.*]] = enum $Optional<Node>, #Optional.none!enumelt | ||
// CHECK: [[SELF_NEXT:%.*]] = ref_element_addr [[SELF]] : $Node, #Node.next | ||
// CHECK: [[ITER:%.*]] = alloc_stack $Optional<Node> | ||
// CHECK: [[SELF_NEXT_ACCESS:%.*]] = begin_access [modify] [static] [no_nested_conflict] [[SELF_NEXT]] : $*Optional<Node> | ||
// CHECK: [[SELF_NEXT_COPY:%.*]] = load [take] [[SELF_NEXT_ACCESS]] : $*Optional<Node> | ||
// CHECK: store [[NIL]] to [init] [[SELF_NEXT_ACCESS]] : $*Optional<Node> | ||
// CHECK: end_access [[SELF_NEXT_ACCESS]] : $*Optional<Node> | ||
// CHECK: store [[SELF_NEXT_COPY]] to [init] [[ITER]] : $*Optional<Node> | ||
// CHECK: br [[LOOPBB:bb.*]] // | ||
|
||
// CHECK: [[LOOPBB]]: | ||
// CHECK: [[ITER_COPY:%.*]] = load [copy] [[ITER]] : $*Optional<Node> | ||
// CHECK: switch_enum [[ITER_COPY]] : $Optional<Node>, case #Optional.some!enumelt: [[IS_SOME_BB:bb.*]], case #Optional.none!enumelt: [[IS_NONE_BB:bb[0-9]+]] | ||
|
||
// CHECK: [[IS_SOME_BB]]([[NODE:%.*]] : @owned $Node): | ||
// CHECK: destroy_value [[NODE]] : $Node | ||
// CHECK: [[IS_UNIQUE:%.*]] = is_unique [[ITER]] : $*Optional<Node> | ||
// CHECK: cond_br [[IS_UNIQUE]], [[IS_UNIQUE_BB:bb.*]], [[NOT_UNIQUE_BB:bb[0-9]*]] | ||
|
||
// CHECK: [[IS_UNIQUE_BB]]: | ||
// CHECK: [[ITER_BORROW:%.*]] = load_borrow [[ITER]] : $*Optional<Node> | ||
// CHECK: [[ITER_UNWRAPPED:%.*]] = unchecked_enum_data [[ITER_BORROW]] : $Optional<Node>, #Optional.some!enumelt | ||
// CHECK: [[NEXT_ADDR:%.*]] = ref_element_addr [[ITER_UNWRAPPED]] : $Node, #Node.next | ||
// CHECK: [[NEXT_ADDR_ACCESS:%.*]] = begin_access [read] [static] [no_nested_conflict] [[NEXT_ADDR]] : $*Optional<Node> | ||
// CHECK: [[NEXT_COPY:%.*]] = load [copy] [[NEXT_ADDR_ACCESS]] : $*Optional<Node> | ||
// CHECK: end_access [[NEXT_ADDR_ACCESS]] : $*Optional<Node> | ||
// CHECK: end_borrow [[ITER_BORROW]] : $Optional<Node> | ||
// CHECK: store [[NEXT_COPY]] to [assign] [[ITER]] : $*Optional<Node> | ||
// CHECK: br [[LOOPBB]] | ||
|
||
// CHECK: [[NOT_UNIQUE_BB]]: | ||
// CHECK: br bb6 | ||
|
||
// CHECK: [[IS_NONE_BB]]: | ||
// CHECK: br [[CLEAN_BB:bb[0-9]+]] | ||
|
||
// CHECK: [[CLEAN_BB]]: | ||
// CHECK: destroy_addr [[ITER]] : $*Optional<Node> | ||
// CHECK: dealloc_stack [[ITER]] : $*Optional<Node> | ||
// CHECK: [[SELF_NATIVE:%.*]] = unchecked_ref_cast [[SELF]] : $Node to $Builtin.NativeObject | ||
// CHECK: [[SELF_NATIVE_OWNED:%.*]] = unchecked_ownership_conversion [[SELF_NATIVE]] : $Builtin.NativeObject, @guaranteed to @owned | ||
// CHECK: return [[SELF_NATIVE_OWNED]] : $Builtin.NativeObject | ||
// CHECK: } // end sil function '$s23deinit_recursive_linear4NodeCfd' |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.