Skip to content

Commit 72bcb75

Browse files
Merge pull request #67831 from nate-chandler/opaque-values/20230809/opaque-result-types
[AddressLowering] Type SILFunctionArguments for @out results with opaque types substituted.
2 parents bd618f1 + fa98212 commit 72bcb75

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

lib/DriverTool/sil_opt_main.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,10 @@ struct SILOptOptions {
495495
llvm::cl::opt<bool> BypassResilienceChecks = llvm::cl::opt<bool>(
496496
"bypass-resilience-checks",
497497
llvm::cl::desc("Ignore all checks for module resilience."));
498+
499+
llvm::cl::opt<bool> DebugDiagnosticNames = llvm::cl::opt<bool>(
500+
"debug-diagnostic-names",
501+
llvm::cl::desc("Include diagnostic names when printing"));
498502
};
499503

500504
/// Regular expression corresponding to the value given in one of the
@@ -609,6 +613,8 @@ int sil_opt_main(ArrayRef<const char *> argv, void *MainAddr) {
609613
}
610614
Invocation.getLangOptions().BypassResilienceChecks =
611615
options.BypassResilienceChecks;
616+
Invocation.getDiagnosticOptions().PrintDiagnosticNames =
617+
options.DebugDiagnosticNames;
612618
for (auto &featureName : options.ExperimentalFeatures) {
613619
if (auto feature = getExperimentalFeature(featureName)) {
614620
Invocation.getLangOptions().Features.insert(*feature);

lib/SILOptimizer/Mandatory/AddressLowering.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,9 @@ static unsigned insertIndirectReturnArgs(AddressLoweringState &pass) {
689689

690690
unsigned argIdx = 0;
691691
for (auto resultTy : pass.loweredFnConv.getIndirectSILResultTypes(typeCtx)) {
692-
auto bodyResultTy = pass.function->mapTypeIntoContext(resultTy);
692+
auto resultTyInContext = pass.function->mapTypeIntoContext(resultTy);
693+
auto bodyResultTy = pass.function->getModule().Types.getLoweredType(
694+
resultTyInContext.getASTType(), *pass.function);
693695
auto var = new (astCtx) ParamDecl(
694696
SourceLoc(), SourceLoc(), astCtx.getIdentifier("$return_value"),
695697
SourceLoc(), astCtx.getIdentifier("$return_value"), declCtx);

test/SILOptimizer/address_lowering.sil

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ protocol P {
1818
func foo()
1919
}
2020

21+
struct S : P {
22+
func foo()
23+
}
24+
2125
enum Optional<T> {
2226
case none
2327
case some(T)
@@ -549,6 +553,23 @@ bb0(%0 : @owned $T, %1 : @owned $C):
549553
return %2 : $(T, C)
550554
}
551555

556+
// CHECK-LABEL: sil [ossa] @f076_opaqueResult : {{.*}} {
557+
// CHECK: {{bb[0-9]+}}([[S_ADDR:%[^,]+]] : $*S):
558+
// CHECK: [[GET:%[^,]+]] = function_ref @getT
559+
// CHECK: [[TEMP:%[^,]+]] = alloc_stack $S
560+
// CHECK: apply [[GET]]<S>([[TEMP]])
561+
// CHECK: [[S:%[^,]+]] = load [trivial] [[TEMP]]
562+
// CHECK: store [[S]] to [trivial] [[S_ADDR]]
563+
// CHECK: dealloc_stack [[TEMP]]
564+
// CHECK-LABEL: } // end sil function 'f076_opaqueResult'
565+
// The following getS definition enables use of the type <<@_opaqueReturnTypeOf("$s5Swift4getSQryF", 0) opaque>>
566+
@_silgen_name("getS") public func getS() -> some P { return S() }
567+
sil [ossa] @f076_opaqueResult : $@convention(thin) <T> () -> @out @_opaqueReturnTypeOf("$s5Swift4getSQryF", 0) __<T> {
568+
%get = function_ref @getT : $@convention(thin) <T> () -> (@out T)
569+
%s = apply %get<S>() : $@convention(thin) <T> () -> (@out T)
570+
return %s : $S
571+
}
572+
552573
// CHECK-LABEL: sil [ossa] @f080_optional : $@convention(thin) <T> (@in T) -> @out Optional<T> {
553574
// CHECK: bb0(%0 : $*Optional<T>, %1 : $*T):
554575
// CHECK: [[DATA:%.*]] = init_enum_data_addr %0 : $*Optional<T>, #Optional.some!enumelt

0 commit comments

Comments
 (0)