Skip to content

Commit 095824e

Browse files
committed
AST: Fix a bug in ReplaceOpaqueTypesWithUnderlyingTypes
There was a logic error in canSubstituteTypeInto(). An existing test (test/IRGen/opaque_result_type_private_underlying.swift) triggered this issue with a change I'm working on. Upon further inspection I noticed the problem can already be triggered in the same test if we build with -O. The problem was that we were too agressive with substituting away opaque types away in the body of an inlinable function in a non-resilient build. While opaque types are not resilient in this case, we still need to keep them around if the underlying type is insufficiently visible.
1 parent 59a218a commit 095824e

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

lib/AST/Type.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3150,7 +3150,7 @@ static bool canSubstituteTypeInto(Type ty, const DeclContext *dc,
31503150
case OpaqueSubstitutionKind::SubstituteNonResilientModule:
31513151
// Can't access types that are not public from a different module.
31523152
if (dc->getParentModule() == typeDecl->getDeclContext()->getParentModule())
3153-
return true;
3153+
return typeDecl->getEffectiveAccess() > AccessLevel::FilePrivate;
31543154

31553155
return typeDecl->getEffectiveAccess() > AccessLevel::Internal;
31563156
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fileprivate struct PrivateS {}
2+
3+
public func callee() -> some Any {
4+
return PrivateS()
5+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %target-swift-frontend -disable-availability-checking -emit-silgen -primary-file %s -primary-file %S/Inputs/opaque_result_type_inlinable_other.swift | %FileCheck %s
2+
// RUN: %target-swift-frontend -disable-availability-checking -emit-silgen -primary-file %s %S/Inputs/opaque_result_type_inlinable_other.swift | %FileCheck %s
3+
// RUN: %target-swift-frontend -disable-availability-checking -emit-silgen %s %S/Inputs/opaque_result_type_inlinable_other.swift | %FileCheck %s
4+
5+
// CHECK-LABEL: sil [serialized] [ossa] @$s28opaque_result_type_inlinable6callerQryF : $@convention(thin) () -> @out @_opaqueReturnTypeOf("$s28opaque_result_type_inlinable6callerQryF", 0) __ {
6+
// CHECK: bb0(%0 : $*@_opaqueReturnTypeOf("$s28opaque_result_type_inlinable6calleeQryF", 0) __):
7+
// CHECK: function_ref @$s28opaque_result_type_inlinable6calleeQryF : $@convention(thin) () -> @out @_opaqueReturnTypeOf("$s28opaque_result_type_inlinable6calleeQryF", 0) __
8+
9+
@inlinable public func caller() -> some Any {
10+
return callee()
11+
}

0 commit comments

Comments
 (0)