Skip to content

Commit 5db2b28

Browse files
authored
[Runtime] Handle single payload enums in swift_resolve_resilientAccessors (swiftlang#66218)
rdar://109803119 It is sufficient to skip the header, because everything after that are regular ref counts
1 parent 17d121f commit 5db2b28

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

stdlib/public/runtime/BytecodeLayouts.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,9 @@ void swift::swift_resolve_resilientAccessors(
436436
case RefCountingKind::Metatype:
437437
i += sizeof(uintptr_t);
438438
break;
439+
case RefCountingKind::SinglePayloadEnumSimple:
440+
i += (3 * sizeof(uint64_t)) + (4 * sizeof(size_t));
441+
break;
439442
default:
440443
break;
441444
}

test/Interpreter/Inputs/layout_string_witnesses_types.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ public enum MultiPayloadEnum {
317317
case b(Int, String)
318318
case c(Bool)
319319
case d
320+
case e(SimpleClass)
320321
}
321322

322323
public struct MultiPayloadEnumWrapper {
@@ -329,6 +330,26 @@ public struct MultiPayloadEnumWrapper {
329330
}
330331
}
331332

333+
public struct MixedEnumWrapper {
334+
let x: SinglePayloadSimpleClassEnum
335+
let y: MultiPayloadEnum
336+
337+
public init(x: SinglePayloadSimpleClassEnum, y: MultiPayloadEnum) {
338+
self.x = x
339+
self.y = y
340+
}
341+
}
342+
343+
public struct MixedEnumWrapperWrapperGeneric<T> {
344+
let x: MixedEnumWrapper
345+
let y: T
346+
347+
public init(x: MixedEnumWrapper, y: T) {
348+
self.x = x
349+
self.y = y
350+
}
351+
}
352+
332353
public struct ComplexNesting<A, B, C, D> {
333354
let pre: Filler = Filler()
334355
let a: NestedA<A>

test/Interpreter/layout_string_witnesses_dynamic.swift

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,42 @@ func testGenericResilient() {
395395

396396
testGenericResilient()
397397

398+
func testMixedEnumWrapperWrapperGeneric() {
399+
let ptr = allocateInternalGenericPtr(of: MixedEnumWrapperWrapperGeneric<TestClass>.self)
400+
401+
do {
402+
let x = MixedEnumWrapperWrapperGeneric(x: MixedEnumWrapper(x: .nonEmpty(SimpleClass(x: 23)),
403+
y: .e(SimpleClass(x: 32))),
404+
y: TestClass())
405+
testGenericInit(ptr, to: x)
406+
}
407+
408+
do {
409+
let y = MixedEnumWrapperWrapperGeneric(x: MixedEnumWrapper(x: .nonEmpty(SimpleClass(x: 28)),
410+
y: .e(SimpleClass(x: 82))),
411+
y: TestClass())
412+
// CHECK: Before deinit
413+
print("Before deinit")
414+
415+
// CHECK-NEXT: SimpleClass deinitialized!
416+
// CHECK-NEXT: SimpleClass deinitialized!
417+
// CHECK-NEXT: TestClass deinitialized!
418+
testGenericAssign(ptr, from: y)
419+
}
420+
421+
// CHECK-NEXT: Before deinit
422+
print("Before deinit")
423+
424+
// CHECK-NEXT: SimpleClass deinitialized!
425+
// CHECK-NEXT: SimpleClass deinitialized!
426+
// CHECK-NEXT: TestClass deinitialized!
427+
testGenericDestroy(ptr, of: MixedEnumWrapperWrapperGeneric<TestClass>.self)
428+
429+
ptr.deallocate()
430+
}
431+
432+
testMixedEnumWrapperWrapperGeneric()
433+
398434
#if os(macOS)
399435

400436
import Foundation

0 commit comments

Comments
 (0)