Skip to content

[5.1] IRGen: Fix handling of singleton aggregate projections and tupl… #25260

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
22 changes: 6 additions & 16 deletions lib/IRGen/GenType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2253,14 +2253,9 @@ SILType irgen::getSingletonAggregateFieldType(IRGenModule &IGM, SILType t,
auto field = allFields.begin();
if (!allFields.empty() && std::next(field) == allFields.end()) {
auto fieldTy = t.getFieldType(*field, IGM.getSILModule());
if (auto fieldDecl = fieldTy.getNominalOrBoundGenericNominal()) {
// The field's access level must be higher or equal to the enclosing
// struct's.
if (fieldDecl->getEffectiveAccess() >= structDecl->getEffectiveAccess())
return fieldTy;
} else {
return fieldTy;
}
if (!IGM.isTypeABIAccessible(fieldTy))
return SILType();
return fieldTy;
}

return SILType();
Expand All @@ -2278,14 +2273,9 @@ SILType irgen::getSingletonAggregateFieldType(IRGenModule &IGM, SILType t,
if (!allCases.empty() && std::next(theCase) == allCases.end()
&& (*theCase)->hasAssociatedValues()) {
auto enumEltTy = t.getEnumElementType(*theCase, IGM.getSILModule());
if (auto eltDecl = enumEltTy.getNominalOrBoundGenericNominal()) {
// The enum element's access level must be higher or equal to the
// enclosing struct's.
if (eltDecl->getEffectiveAccess() >= enumDecl->getEffectiveAccess())
return enumEltTy;
} else {
return enumEltTy;
}
if (!IGM.isTypeABIAccessible(enumEltTy))
return SILType();
return enumEltTy;
}

return SILType();
Expand Down
63 changes: 63 additions & 0 deletions test/IRGen/Inputs/metadata2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,66 @@ struct InternalContainer {
self.type = SomeEnumType(item: item)
}
}

struct InternalContainer2 {

fileprivate enum SomeEnumType {
case none
case single(Item)

init(item: [Item]) {
if item.count >= 1 {
self = .single(item.first!)
} else {
self = .none
}
}
}

private var type: (SomeEnumType, SomeEnumType)

init(item: [Item]) {
self.type = SomeEnumType(item: item)
}
}

enum InternalSingletonEnum {
fileprivate enum SomeEnumType {
case none
case single(Item)

init(item: [Item]) {
if item.count >= 1 {
self = .single(item.first!)
} else {
self = .none
}
}
}
case first(SomeEnumType)

init() {
return .first(.none)
}
}

enum InternalSingletonEnum2 {
fileprivate enum SomeEnumType {
case none
case single(Item)

init(item: [Item]) {
if item.count >= 1 {
self = .single(item.first!)
} else {
self = .none
}
}
}

case first(SomeEnumType, SomeEnumType)

init() {
return .first(.none, .none)
}
}
3 changes: 3 additions & 0 deletions test/IRGen/metadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
// CHECK: ret
class MyController {
var c = InternalContainer(item: [])
var c2 = InternalContainer2(item: [])
var e = InternalSingletonEnum()
var e2 = InternalSingletonEnum2()
func update(_ n: InternalContainer) {
c = n
}
Expand Down