Skip to content

Commit a8c2aaa

Browse files
authored
Merge pull request #38377 from slavapestov/opaque-result-type-optional-5.5
SIL: Allow lowering Optional<T> against a nested type of an opaque result type [5.5]
2 parents dc0f53d + 154939c commit a8c2aaa

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

lib/SIL/IR/AbstractionPattern.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,6 @@ bool AbstractionPattern::matchesTuple(CanTupleType substType) {
322322
auto type = getType();
323323
if (auto tuple = dyn_cast<TupleType>(type))
324324
return (tuple->getNumElements() == substType->getNumElements());
325-
if (isa<OpaqueTypeArchetypeType>(type))
326-
return true;
327325
return false;
328326
}
329327
}
@@ -872,9 +870,7 @@ AbstractionPattern AbstractionPattern::getOptionalObjectType() const {
872870
return *this;
873871

874872
case Kind::Type:
875-
if (isTypeParameter())
876-
return AbstractionPattern::getOpaque();
877-
if (isa<OpaqueTypeArchetypeType>(getType()))
873+
if (isTypeParameterOrOpaqueArchetype())
878874
return AbstractionPattern::getOpaque();
879875
return AbstractionPattern(getGenericSignature(),
880876
::getOptionalObjectType(getType()));
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
public protocol P {
2+
associatedtype A
3+
}
4+
5+
public func bar<T : P>(_: T) -> T.A {
6+
fatalError()
7+
}
8+
9+
public struct S<A> : P {}
10+
11+
public func foo() -> some P {
12+
return S<Int?>()
13+
}
14+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-module %S/Inputs/opaque_result_type_nested_optional_other.swift -emit-module-path %t/opaque_result_type_nested_optional_other.swiftmodule -disable-availability-checking
3+
// RUN: %target-swift-emit-silgen %s -I %t | %FileCheck %s
4+
5+
import opaque_result_type_nested_optional_other
6+
7+
_ = bar(foo())
8+
9+
// CHECK-LABEL: sil [ossa] @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 {
10+
// CHECK: [[OUTER:%.*]] = alloc_stack $Optional<Int>
11+
// CHECK: [[UNUSED:%.*]] = alloc_stack $S<Optional<Int>>
12+
// CHECK: [[INNER:%.*]] = alloc_stack $S<Optional<Int>>
13+
// CHECK: [[FN:%.*]] = function_ref @$s40opaque_result_type_nested_optional_other3bary1AQzxAA1PRzlF : $@convention(thin) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> @out τ_0_0.A
14+
// CHECK: apply [[FN]]<S<Int?>>([[OUTER]], [[INNER]]) : $@convention(thin) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> @out τ_0_0.A
15+
// CHECK: return

0 commit comments

Comments
 (0)