Skip to content

Deinit-Devirtualization: fix a crash when trying to de-virtualize a non-copyable generic #74474

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
Jun 17, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ private func devirtualize(destroy: some DevirtualizableDestroy, _ context: some
if !type.isMoveOnly {
return true
}
precondition(type.isNominal, "non-copyable non-nominal types not supported, yet")

if !type.isNominal {
// E.g. a non-copyable generic function parameter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment confuses me. Is a Copyable generic parameter “nominal”?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, e.g. func foo<T: ~Copyable>(_ t: T). T is not copyable and not a nominal type

return true
}

let result: Bool
if type.nominal.hasValueDeinit && !destroy.shouldDropDeinit {
Expand Down
10 changes: 10 additions & 0 deletions test/SILOptimizer/devirt_deinits.sil
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,16 @@ bb0(%0 : $*S4):
return %r : $()
}

// CHECK-LABEL: sil [ossa] @nonCopyable_generic :
// CHECK: destroy_addr %0
// CHECK: } // end sil function 'nonCopyable_generic'
sil [ossa] @nonCopyable_generic : $@convention(thin) <T where T : ~Copyable> (@in T) -> () {
bb0(%0 : $*T):
destroy_addr %0 : $*T
%r = tuple ()
return %r : $()
}

sil @s1_deinit : $@convention(method) (@owned S1) -> ()
sil @s2_deinit : $@convention(method) (@owned S2) -> ()
sil @s3_deinit : $@convention(method) <T> (@in S3<T>) -> ()
Expand Down