Skip to content

Commit 427d9cb

Browse files
committed
[TypeLowering] Loosen assertion.
1 parent 10dd581 commit 427d9cb

File tree

4 files changed

+126
-1
lines changed

4 files changed

+126
-1
lines changed

lib/SIL/IR/TypeLowering.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3187,10 +3187,19 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
31873187
if (!lowering.isTrivial() && conformance) {
31883188
// A non-trivial type can have a conformance in one case:
31893189
// (1) contains a conforming archetype
3190+
// (2) is resilient with minimal expansion
31903191
bool hasNoConformingArchetypeNode = visitAggregateLeaves(
31913192
origType, substType, forExpansion,
31923193
/*isLeaf=*/
31933194
[&](auto ty, auto origTy, auto *field, auto index) -> bool {
3195+
// A resilient type that's with minimal expansion may be non-trivial
3196+
// but still conform (case (2)).
3197+
auto *nominal = ty.getAnyNominal();
3198+
if (nominal && nominal->isResilient() &&
3199+
forExpansion.getResilienceExpansion() ==
3200+
ResilienceExpansion::Minimal) {
3201+
return true;
3202+
}
31943203
// Walk into every aggregate.
31953204
return false;
31963205
},
@@ -3201,7 +3210,16 @@ void TypeConverter::verifyTrivialLowering(const TypeLowering &lowering,
32013210
"leaf of non-trivial BitwiseCopyable type that doesn't "
32023211
"conform to BitwiseCopyable!?");
32033212

3204-
// An archetype may conform but be non-trivial (case (2)).
3213+
// A resilient type that's with minimal expansion may be non-trivial
3214+
// but still conform (case (2)).
3215+
auto *nominal = ty.getAnyNominal();
3216+
if (nominal && nominal->isResilient() &&
3217+
forExpansion.getResilienceExpansion() ==
3218+
ResilienceExpansion::Minimal) {
3219+
return false;
3220+
}
3221+
3222+
// An archetype may conform but be non-trivial (case (1)).
32053223
if (origTy.isTypeParameter())
32063224
return false;
32073225

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: split-file %s %t
3+
4+
// RUN: %target-swift-frontend \
5+
// RUN: %t/Library.swift \
6+
// RUN: -emit-module \
7+
// RUN: -enable-library-evolution \
8+
// RUN: -enable-experimental-feature BitwiseCopyable \
9+
// RUN: -module-name Library \
10+
// RUN: -emit-module-path %t/Library.swiftmodule
11+
12+
// RUN: %target-swift-frontend \
13+
// RUN: %t/Downstream.swift \
14+
// RUN: -typecheck -verify \
15+
// RUN: -debug-diagnostic-names \
16+
// RUN: -enable-experimental-feature BitwiseCopyable \
17+
// RUN: -I %t
18+
19+
//--- Library.swift
20+
public enum Oopsional<T> {
21+
case someone(T)
22+
case nobody
23+
}
24+
25+
@frozen public enum Woopsional<T> {
26+
case somebody(T)
27+
case noone
28+
}
29+
30+
public struct Integer {
31+
var value: Int
32+
}
33+
34+
//--- Downstream.swift
35+
import Library
36+
37+
func take<T: _BitwiseCopyable>(_ t: T) {}
38+
39+
struct S_Explicit_With_Oopsional<T> : _BitwiseCopyable {
40+
var o: Oopsional<T> // expected-error{{non_bitwise_copyable_type_member}}
41+
}
42+
43+
func passOopsional<T>(_ t: Oopsional<T>) { take(t) } // expected-error {{type_does_not_conform_decl_owner}}
44+
// expected-note@-7 {{where_requirement_failure_one_subst}}
45+
46+
47+
struct S_Explicit_With_Woopsional<T> : _BitwiseCopyable {
48+
var o: Woopsional<T> // expected-error{{non_bitwise_copyable_type_member}}
49+
}
50+
51+
func passWoopsional<T>(_ t: Woopsional<T>) { take(t) } // expected-error {{type_does_not_conform_decl_owner}}
52+
// expected-note@-15 {{where_requirement_failure_one_subst}}
53+
54+
extension Integer : @retroactive _BitwiseCopyable {} // expected-error {{bitwise_copyable_outside_module}}
55+

test/Sema/bitwise_copyable_2.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,13 @@ indirect enum E_Explicit_Indirect : _BitwiseCopyable { // expected-error {{non_b
2525
enum E_Explicit_Indirect_Case : _BitwiseCopyable { // expected-error {{non_bitwise_copyable_type_indirect_enum_element}}
2626
indirect case s(S) // expected-note {{note_non_bitwise_copyable_type_indirect_enum_element}}
2727
}
28+
29+
func take<T : _BitwiseCopyable>(_ t: T) {}
30+
31+
// public (effectively) => !conforms
32+
@usableFromInline internal struct InternalUsableStruct {
33+
public var int: Int
34+
}
35+
36+
func passInternalUsableStruct(_ s: InternalUsableStruct) { take(s) } // expected-error{{type_does_not_conform_decl_owner}}
37+
// expected-note@-8{{where_requirement_failure_one_subst}}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: split-file %s %t
3+
4+
// RUN: %target-swift-frontend \
5+
// RUN: %t/Library.swift \
6+
// RUN: -emit-module \
7+
// RUN: -package-name Package \
8+
// RUN: -enable-library-evolution \
9+
// RUN: -enable-experimental-feature BitwiseCopyable \
10+
// RUN: -module-name Library \
11+
// RUN: -emit-module-path %t/Library.swiftmodule \
12+
// RUN: -emit-module-interface-path %t/Library.swiftinterface
13+
14+
// RUN: %target-swift-frontend \
15+
// RUN: %t/Downstream.swift \
16+
// RUN: -typecheck -verify \
17+
// RUN: -package-name Package \
18+
// RUN: -debug-diagnostic-names \
19+
// RUN: -enable-experimental-feature BitwiseCopyable \
20+
// RUN: -I %t
21+
22+
//--- Library.swift
23+
24+
// !public => conforms
25+
package struct PackageStruct {
26+
package var int: Int
27+
}
28+
29+
// Public => !conforms
30+
public struct PublicStruct {
31+
public var int: Int
32+
}
33+
34+
//--- Downstream.swift
35+
import Library
36+
37+
func take<T : _BitwiseCopyable>(_ t: T) {}
38+
39+
func passPackageStruct(_ s: PackageStruct) { take(s) }
40+
41+
func passPublicStruct(_ s: PublicStruct) { take(s) } // expected-error{{type_does_not_conform_decl_owner}}
42+
// expected-note@-5{{where_requirement_failure_one_subst}}

0 commit comments

Comments
 (0)