Skip to content

SIL: Allow lowering Optional<T> against a nested type of an opaque result type [5.5] #38377

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
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
6 changes: 1 addition & 5 deletions lib/SIL/IR/AbstractionPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,6 @@ bool AbstractionPattern::matchesTuple(CanTupleType substType) {
auto type = getType();
if (auto tuple = dyn_cast<TupleType>(type))
return (tuple->getNumElements() == substType->getNumElements());
if (isa<OpaqueTypeArchetypeType>(type))
return true;
return false;
}
}
Expand Down Expand Up @@ -872,9 +870,7 @@ AbstractionPattern AbstractionPattern::getOptionalObjectType() const {
return *this;

case Kind::Type:
if (isTypeParameter())
return AbstractionPattern::getOpaque();
if (isa<OpaqueTypeArchetypeType>(getType()))
if (isTypeParameterOrOpaqueArchetype())
return AbstractionPattern::getOpaque();
return AbstractionPattern(getGenericSignature(),
::getOptionalObjectType(getType()));
Expand Down
14 changes: 14 additions & 0 deletions test/SILGen/Inputs/opaque_result_type_nested_optional_other.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public protocol P {
associatedtype A
}

public func bar<T : P>(_: T) -> T.A {
fatalError()
}

public struct S<A> : P {}

public func foo() -> some P {
return S<Int?>()
}

15 changes: 15 additions & 0 deletions test/SILGen/opaque_result_type_nested_optional.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// RUN: %empty-directory(%t)
// 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
// RUN: %target-swift-emit-silgen %s -I %t | %FileCheck %s

import opaque_result_type_nested_optional_other

_ = bar(foo())

// CHECK-LABEL: sil [ossa] @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 {
// CHECK: [[OUTER:%.*]] = alloc_stack $Optional<Int>
// CHECK: [[UNUSED:%.*]] = alloc_stack $S<Optional<Int>>
// CHECK: [[INNER:%.*]] = alloc_stack $S<Optional<Int>>
// 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
// CHECK: apply [[FN]]<S<Int?>>([[OUTER]], [[INNER]]) : $@convention(thin) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> @out τ_0_0.A
// CHECK: return