Skip to content

[4.2] IRGen: Fix multi-payload enum lowering #17590

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
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
3 changes: 3 additions & 0 deletions lib/IRGen/GenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4115,6 +4115,9 @@ IRGenModule::getResilienceExpansionForAccess(NominalTypeDecl *decl) {
// layout. Calling isResilient() with this scope will always return false.
ResilienceExpansion
IRGenModule::getResilienceExpansionForLayout(NominalTypeDecl *decl) {
if (Types.isCompletelyFragile())
return ResilienceExpansion::Minimal;

if (isResilient(decl, ResilienceExpansion::Minimal))
return ResilienceExpansion::Maximal;

Expand Down
25 changes: 25 additions & 0 deletions test/IRGen/enum_resilience_objc.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-module -enable-resilience -emit-module-path=%t/resilient_struct.swiftmodule -module-name=resilient_struct %S/../Inputs/resilient_struct.swift
// RUN: %target-swift-frontend -module-name enum_resilience -I %t -emit-ir -enable-resilience %s | %FileCheck %s -DINT=i%target-ptrsize
// RUN: %target-swift-frontend -module-name enum_resilience -I %t -emit-ir -enable-resilience -O %s

// REQUIRES: objc_interop

// Because the enum is resilient we cannot pack the tag into the pointer inside of the resilient payload.
// CHECK: %T15enum_resilience9ContainerC5Multi33_{{.*}}LLO.0 = type <{ [{{(8|4)}} x i8], [1 x i8] }>

import resilient_struct

public class Container {
private enum Multi {
case none
case some(Container)
case data(ResilientRef)
}
private var e: Multi
var i: Int
init() {
e = .none
i = 0
}
}
14 changes: 14 additions & 0 deletions test/Inputs/resilient_struct.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,17 @@ public struct ResilientDouble {
self.d = d
}
}

public class Referent {}

public struct ResilientWeakRef {
public weak var ref: Referent?

public init (_ r: Referent) {
ref = r
}
}

public struct ResilientRef {
public var r: Referent
}
24 changes: 24 additions & 0 deletions test/Interpreter/enum_resilience.swift
Original file line number Diff line number Diff line change
Expand Up @@ -436,4 +436,28 @@ ResilientEnumTestSuite.test("ResilientEnumExtension") {
expectEqual(Base.self, ResilientMultiPayloadGenericEnumFixedSize<Base>.A.getTypeParameter())
}

public class Container {
private enum Multi {
case none
case some(Container)
case other(ResilientRef)
}
private var m: Multi
var i: Int
init() {
m = .none
i = 0
switch self.m {
case .none:
print("success")
case .some(_), .other(_):
assert(false, "noooo!")
}
}
}

ResilientEnumTestSuite.test("ResilientPrivateEnumMember") {
_ = Container()
}

runAllTests()