Files
swift-mirror/test/embedded/deinit-noncopyable-2.swift
Doug Gregor beeb45def1 [IRGen] Look for a specialized deinit when forming a call in IRGen
When outlining a destroy operation, we form direct calls to the deinit
of noncopyable types. For generic types, this was always calling into
unspecialized generics, which is... deeply unfortunate.

Look for a specialized deinit and call that instead. This eliminates a
compiler assertion in Embedded Swift, and should improve performance
with noncopyable generics elsewhere.

Fixes rdar://159054138 and #72627 / rdar://157131184.
2025-08-25 16:13:12 -07:00

43 lines
936 B
Swift

// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend %s -g -enable-experimental-feature Embedded -c -o %t/main.o
// REQUIRES: swift_in_compiler
// REQUIRES: swift_feature_Embedded
// https://github.com/swiftlang/swift/issues/72627 - crash with noncopyable
// generic deinit.
final class Box<T: ~Copyable> {
var value: T
init(_ value: consuming T) {
self.value = value
}
}
struct ListNode<Element: ~Copyable>: ~Copyable {
typealias Link = Box<ListNode<Element>>?
var element: Element
var next: Link
}
struct List<Element: ~Copyable>: ~Copyable {
typealias Link = Box<ListNode<Element>>?
var head: Link = nil
init(head: consuming Link = nil) {
self.head = head
}
mutating func push(_ element: consuming Element) {
self = Self(head: Box(ListNode(element: element, next: self.head)))
}
}
public func main() {
var myList = List<Int>()
myList.push(1)
let _ = consume myList
}