Skip to content

Commit b04ec81

Browse files
authored
Merge pull request #33428 from slavapestov/fix-type-expansion-context-from-sil-function
SIL: Fix TypeExpansionContext() constructor to get the right DeclContext from a SILFunction
2 parents fcb0b2b + 198519c commit b04ec81

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
lines changed

lib/SIL/IR/SILFunctionType.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4477,19 +4477,9 @@ StringRef SILFunctionType::ABICompatibilityCheckResult::getMessage() const {
44774477
llvm_unreachable("Covered switch isn't completely covered?!");
44784478
}
44794479

4480-
static DeclContext *getDeclContextForExpansion(const SILFunction &f) {
4481-
auto *dc = f.getDeclContext();
4482-
if (!dc)
4483-
dc = f.getModule().getSwiftModule();
4484-
auto *currentModule = f.getModule().getSwiftModule();
4485-
if (!dc || !dc->isChildContextOf(currentModule))
4486-
dc = currentModule;
4487-
return dc;
4488-
}
4489-
44904480
TypeExpansionContext::TypeExpansionContext(const SILFunction &f)
44914481
: expansion(f.getResilienceExpansion()),
4492-
inContext(getDeclContextForExpansion(f)),
4482+
inContext(f.getModule().getAssociatedContext()),
44934483
isContextWholeModule(f.getModule().isWholeModule()) {}
44944484

44954485
CanSILFunctionType SILFunction::getLoweredFunctionTypeInContext(
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: %target-swift-emit-silgen -primary-file %s -disable-availability-checking | %FileCheck %s
2+
// RUN: %target-swift-emit-sil -primary-file %s -O -disable-availability-checking
3+
4+
// CHECK-LABEL: sil [ossa] @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 {
5+
6+
// CHECK: [[BOX:%.*]] = alloc_stack $PrivateClass
7+
// CHECK: [[FN:%.*]] = function_ref @$s26opaque_result_type_private19returnPrivateOpaqueQryF : $@convention(thin) () -> @out PrivateClass
8+
// CHECK: apply [[FN]]([[BOX]]) : $@convention(thin) () -> @out PrivateClass
9+
// CHECK: [[RESULT:%.*]] = load [take] [[BOX]] : $*PrivateClass
10+
// CHECK: destroy_value [[RESULT]] : $PrivateClass
11+
// CHECK: dealloc_stack [[BOX]] : $*PrivateClass
12+
_ = returnPrivateOpaque()
13+
14+
// CHECK: [[BOX:%.*]] = alloc_stack $LocalClass
15+
// CHECK: [[FN:%.*]] = function_ref @$s26opaque_result_type_private17returnLocalOpaqueQryF : $@convention(thin) () -> @out LocalClass
16+
// CHECK: apply [[FN]]([[BOX]]) : $@convention(thin) () -> @out LocalClass
17+
// CHECK: [[RESULT:%.*]] = load [take] [[BOX]] : $*LocalClass
18+
// CHECK: destroy_value [[RESULT]] : $LocalClass
19+
// CHECK: dealloc_stack [[BOX]] : $*LocalClass
20+
_ = returnLocalOpaque()
21+
22+
fileprivate class PrivateClass {}
23+
24+
// CHECK-LABEL: sil hidden [ossa] @$s26opaque_result_type_private19returnPrivateOpaqueQryF : $@convention(thin) () -> @out @_opaqueReturnTypeOf("$s26opaque_result_type_private19returnPrivateOpaqueQryF", 0) 🦸
25+
func returnPrivateOpaque() -> some Any {
26+
return PrivateClass()
27+
}
28+
29+
// CHECK-LABEL: sil hidden [ossa] @$s26opaque_result_type_private17returnLocalOpaqueQryF : $@convention(thin) () -> @out @_opaqueReturnTypeOf("$s26opaque_result_type_private17returnLocalOpaqueQryF", 0) 🦸
30+
func returnLocalOpaque() -> some Any {
31+
class LocalClass {}
32+
33+
return LocalClass()
34+
}

0 commit comments

Comments
 (0)