Skip to content

Commit 8ab3475

Browse files
authored
Merge pull request #38376 from slavapestov/opaque-result-type-optional
SIL: Allow lowering Optional<T> against a nested type of an opaque result type
2 parents db35cab + 76a5fd9 commit 8ab3475

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
}
@@ -873,9 +871,7 @@ AbstractionPattern AbstractionPattern::getOptionalObjectType() const {
873871
return *this;
874872

875873
case Kind::Type:
876-
if (isTypeParameter())
877-
return AbstractionPattern::getOpaque();
878-
if (isa<OpaqueTypeArchetypeType>(getType()))
874+
if (isTypeParameterOrOpaqueArchetype())
879875
return AbstractionPattern::getOpaque();
880876
return AbstractionPattern(getGenericSignature(),
881877
::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)