Skip to content
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
7 changes: 7 additions & 0 deletions include/swift/SIL/SILType.h
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,13 @@ class SILType {
SILType subst(SILModule &M, SubstitutionMap subs,
TypeExpansionContext context) const;

/// Strip concurrency annotations from the representation type.
SILType stripConcurrency(bool recursive, bool dropGlobalActor) {
auto strippedASTTy = getASTType()->stripConcurrency(recursive, dropGlobalActor);
return SILType::getPrimitiveType(strippedASTTy->getCanonicalType(),
getCategory());
}

/// Return true if this type references a "ref" type that has a single pointer
/// representation. Class existentials do not always qualify.
bool isHeapObjectReferenceType() const;
Expand Down
20 changes: 13 additions & 7 deletions lib/SILGen/SILGenApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1967,15 +1967,21 @@ static void emitRawApply(SILGenFunction &SGF,
SmallVector<SILValue, 4> argValues;

// Add the buffers for the indirect results if needed.
#ifndef NDEBUG
assert(indirectResultAddrs.size() == substFnConv.getNumIndirectSILResults());
unsigned resultIdx = 0;
for (auto indResultTy :
substFnConv.getIndirectSILResultTypes(SGF.getTypeExpansionContext())) {
assert(indResultTy == indirectResultAddrs[resultIdx++]->getType());
for (auto indResultTy : substFnConv.getIndirectSILResultTypes(SGF.getTypeExpansionContext())) {
auto indResultAddr = indirectResultAddrs[resultIdx++];

if (indResultAddr->getType() != indResultTy) {
// Bitcast away differences in Sendable, global actor, etc.
if (indResultAddr->getType().stripConcurrency(/*recursive*/ true, /*dropGlobalActor*/ true)
== indResultTy.stripConcurrency(/*recursive*/ true, /*dropGlobalActor*/ true)) {
indResultAddr = SGF.B.createUncheckedAddrCast(loc, indResultAddr, indResultTy);
}
}
assert(indResultTy == indResultAddr->getType());

argValues.push_back(indResultAddr);
}
#endif
argValues.append(indirectResultAddrs.begin(), indirectResultAddrs.end());

assert(!!indirectErrorAddr == substFnConv.hasIndirectSILErrorResults());
if (indirectErrorAddr)
Expand Down
10 changes: 10 additions & 0 deletions test/SILGen/preconcurrency_indirect_return.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: %target-swift-emit-silgen %s | %FileCheck %s

@preconcurrency
func test() -> (any Sendable)? { nil }

// CHECK-LABEL: sil {{.*}} @$s{{.*}}callWithPreconcurrency
func callWithPreconcurrency() {
// CHECK: unchecked_addr_cast {{.*}} to $*Optional<any Sendable>
let x = test()
}