Skip to content

6.1: [BitwiseCopyable] Fix resilient enum type info. #78174

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
11 changes: 10 additions & 1 deletion lib/IRGen/GenEnum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6838,6 +6838,14 @@ namespace {
IsABIAccessible_t abiAccessible)
: EnumTypeInfoBase(strategy, irTy, copyable, abiAccessible) {}
};

class BitwiseCopyableEnumTypeInfo
: public EnumTypeInfoBase<BitwiseCopyableTypeInfo> {
public:
BitwiseCopyableEnumTypeInfo(EnumImplStrategy &strategy, llvm::Type *irTy,
IsABIAccessible_t abiAccessible)
: EnumTypeInfoBase(strategy, irTy, abiAccessible) {}
};
} // end anonymous namespace

const EnumImplStrategy &
Expand Down Expand Up @@ -7383,7 +7391,8 @@ ResilientEnumImplStrategy::completeEnumTypeLayout(TypeConverter &TC,
KnownProtocolKind::BitwiseCopyable);
if (bitwiseCopyableProtocol &&
checkConformance(Type.getASTType(), bitwiseCopyableProtocol)) {
return BitwiseCopyableTypeInfo::create(enumTy, abiAccessible);
return registerEnumTypeInfo(
new BitwiseCopyableEnumTypeInfo(*this, enumTy, abiAccessible));
}
return registerEnumTypeInfo(
new ResilientEnumTypeInfo(*this, enumTy, cp,
Expand Down
2 changes: 2 additions & 0 deletions lib/IRGen/NonFixedTypeInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ class BitwiseCopyableTypeInfo
: public WitnessSizedTypeInfo<BitwiseCopyableTypeInfo> {
using Self = BitwiseCopyableTypeInfo;
using Super = WitnessSizedTypeInfo<Self>;

protected:
BitwiseCopyableTypeInfo(llvm::Type *type, IsABIAccessible_t abiAccessible)
: Super(type, Alignment(1), IsNotTriviallyDestroyable,
IsNotBitwiseTakable, IsCopyable, abiAccessible) {}
Expand Down
27 changes: 25 additions & 2 deletions test/IRGen/bitwise_copyable_resilient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@
// RUN: -emit-module-path %t/Library.swiftmodule

// RUN: %target-swift-frontend \
// RUN: %t/Downstream.swift \
// RUN: %t/DownstreamDiagnostics.swift \
// RUN: -typecheck -verify \
// RUN: -debug-diagnostic-names \
// RUN: -I %t

// RUN: %target-swift-frontend \
// RUN: %t/Downstream.swift \
// RUN: -emit-irgen \
// RUN: -debug-diagnostic-names \
// RUN: -I %t

//--- Library.swift
public enum Oopsional<T> {
case someone(T)
Expand All @@ -29,7 +35,14 @@ public struct Integer {
var value: Int
}

//--- Downstream.swift
public enum Int2: BitwiseCopyable {
case zero
case one
case two
case three
}

//--- DownstreamDiagnostics.swift
import Library

func take<T: BitwiseCopyable>(_ t: T) {}
Expand All @@ -51,3 +64,13 @@ func passWoopsional<T>(_ t: Woopsional<T>) { take(t) } // expected-error {{ty

extension Integer : @retroactive BitwiseCopyable {} // expected-error {{bitwise_copyable_outside_module}}

struct S_Explicit_With_Int2 {
var i: Int2
}

//--- Downstream.swift
import Library

class C_With_Int2 {
let i = Int2.one
}