File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -307,6 +307,10 @@ swift::classifyDynamicCast(ModuleDecl *M,
307
307
bool isWholeModuleOpts) {
308
308
if (source == target) return DynamicCastFeasibility::WillSucceed;
309
309
310
+ // Return a conservative answer for opaque archetypes for now.
311
+ if (source->hasOpaqueArchetype () || target->hasOpaqueArchetype ())
312
+ return DynamicCastFeasibility::MaySucceed;
313
+
310
314
auto sourceObject = source.getOptionalObjectType ();
311
315
auto targetObject = target.getOptionalObjectType ();
312
316
Original file line number Diff line number Diff line change 1
1
// RUN: %target-swift-frontend -O -emit-sil %s | %FileCheck %s
2
+ // RUN: %target-swift-frontend -Onone -emit-sil %s | %FileCheck %s --check-prefix=MANDATORY
2
3
// We want to check two things here:
3
4
// - Correctness
4
5
// - That certain "is" checks are eliminated based on static analysis at compile-time
@@ -1065,6 +1066,24 @@ public func testCastToPForOptionalFailure() -> Bool {
1065
1066
return testCastToPForOptional ( t)
1066
1067
}
1067
1068
1069
+ struct Underlying : P {
1070
+ }
1071
+
1072
+ func returnOpaque( ) -> some P {
1073
+ return Underlying ( )
1074
+ }
1075
+
1076
+ // MANDATORY-LABEL: sil{{.*}} @$s12cast_folding23testCastOpaqueArchetypeyyF
1077
+ // MANDATORY: [[O:%.*]] = alloc_stack $@_opaqueReturnTypeOf("$s12cast_folding12returnOpaqueQryF", 0)
1078
+ // MANDATORY: [[F:%.*]] = function_ref @$s12cast_folding12returnOpaqueQryF
1079
+ // MANDATORY: apply [[F]]([[O]])
1080
+ // MANDATORY: [[U:%.*]] = alloc_stack $Underlying
1081
+ // MANDATORY: unconditional_checked_cast_addr @_opaqueReturnTypeOf{{.*}}in [[O]] : $*@_opaqueReturnTypeOf{{.*}}to Underlying in [[U]] : $*Underlying
1082
+ // MANDATORY: load [[U]] : $*Underlying
1083
+ public func testCastOpaqueArchetype( ) {
1084
+ let o = returnOpaque ( ) as! Underlying
1085
+ }
1086
+
1068
1087
print ( " test0= \( test0 ( ) ) " )
1069
1088
1070
1089
print ( " test1= \( test1 ( ) ) " )
You can’t perform that action at this time.
0 commit comments