Skip to content

Commit d96ea28

Browse files
authored
Merge pull request swiftlang#34093 from DougGregor/concurrency-mangle-sil-async
[Concurrency] (De-)mangling for SIL @async function types.
2 parents 2ad5b43 + 81f0f37 commit d96ea28

File tree

9 files changed

+51
-1
lines changed

9 files changed

+51
-1
lines changed

docs/ABI/Mangling.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ mangled in to disambiguate.
600600
impl-function-type ::= type* 'I' FUNC-ATTRIBUTES '_'
601601
impl-function-type ::= type* generic-signature 'I' FUNC-ATTRIBUTES '_'
602602

603-
FUNC-ATTRIBUTES ::= PATTERN-SUBS? INVOCATION-SUBS? PSEUDO-GENERIC? CALLEE-ESCAPE? DIFFERENTIABILITY-KIND? CALLEE-CONVENTION FUNC-REPRESENTATION? COROUTINE-KIND? (PARAM-CONVENTION PARAM-DIFFERENTIABILITY?)* RESULT-CONVENTION* ('Y' PARAM-CONVENTION)* ('z' RESULT-CONVENTION RESULT-DIFFERENTIABILITY?)?
603+
FUNC-ATTRIBUTES ::= PATTERN-SUBS? INVOCATION-SUBS? PSEUDO-GENERIC? CALLEE-ESCAPE? DIFFERENTIABILITY-KIND? CALLEE-CONVENTION FUNC-REPRESENTATION? COROUTINE-KIND? ASYNC? (PARAM-CONVENTION PARAM-DIFFERENTIABILITY?)* RESULT-CONVENTION* ('Y' PARAM-CONVENTION)* ('z' RESULT-CONVENTION RESULT-DIFFERENTIABILITY?)?
604604

605605
PATTERN-SUBS ::= 's' // has pattern substitutions
606606
INVOCATION-SUB ::= 'I' // has invocation substitutions
@@ -627,6 +627,8 @@ mangled in to disambiguate.
627627
COROUTINE-KIND ::= 'A' // yield-once coroutine
628628
COROUTINE-KIND ::= 'G' // yield-many coroutine
629629

630+
ASYNC ::= 'H' // @async
631+
630632
PARAM-CONVENTION ::= 'i' // indirect in
631633
PARAM-CONVENTION ::= 'c' // indirect in constant
632634
PARAM-CONVENTION ::= 'l' // indirect inout

include/swift/Demangling/TypeDecoder.h

+2
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,8 @@ class TypeDecoder {
706706
} else if (text == "@convention(block)") {
707707
flags =
708708
flags.withRepresentation(ImplFunctionRepresentation::Block);
709+
} else if (text == "@async") {
710+
flags = flags.withAsync();
709711
}
710712
} else if (child->getKind() == NodeKind::ImplDifferentiable) {
711713
flags = flags.withDifferentiabilityKind(

include/swift/Reflection/TypeRefBuilder.h

+2
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,8 @@ class TypeRefBuilder {
443443
break;
444444
}
445445

446+
funcFlags = funcFlags.withAsync(flags.isAsync());
447+
446448
auto result = createTupleType({}, "");
447449
return FunctionTypeRef::create(*this, {}, result, funcFlags);
448450
}

lib/AST/ASTMangler.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -1689,6 +1689,11 @@ void ASTMangler::appendImplFunctionType(SILFunctionType *fn) {
16891689
break;
16901690
}
16911691

1692+
// Asynchronous functions.
1693+
if (fn->isAsync()) {
1694+
OpArgs.push_back('H');
1695+
}
1696+
16921697
auto outerGenericSig = CurGenericSignature;
16931698
CurGenericSignature = fn->getSubstGenericSignature();
16941699

lib/Demangling/Demangler.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -1829,6 +1829,11 @@ NodePointer Demangler::demangleImplFunctionType() {
18291829
if (CoroAttr)
18301830
type->addChild(createNode(Node::Kind::ImplFunctionAttribute, CoroAttr), *this);
18311831

1832+
if (nextIf('H')) {
1833+
type->addChild(createNode(Node::Kind::ImplFunctionAttribute, "@async"),
1834+
*this);
1835+
}
1836+
18321837
addChild(type, GenSig);
18331838

18341839
int NumTypesToAdd = 0;

lib/Demangling/OldDemangler.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -2148,6 +2148,9 @@ class OldDemangler {
21482148
return nullptr;
21492149
}
21502150

2151+
if (Mangled.nextIf('H'))
2152+
addImplFunctionAttribute(type, "@async");
2153+
21512154
// Enter a new generic context if this type is generic.
21522155
// FIXME: replace with std::optional, when we have it.
21532156
bool isPseudogeneric = false;

lib/Demangling/OldRemangler.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -1255,6 +1255,8 @@ void Remangler::mangleImplFunctionAttribute(Node *node) {
12551255
Buffer << "A";
12561256
} else if (text == "@yield_many") {
12571257
Buffer << "G";
1258+
} else if (text == "@async") {
1259+
Buffer << "H";
12581260
} else {
12591261
unreachable("bad impl-function-attribute");
12601262
}

lib/Demangling/Remangler.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1537,6 +1537,7 @@ void Remangler::mangleImplFunctionType(Node *node) {
15371537
.Case("@convention(witness_method)", 'W')
15381538
.Case("@yield_once", 'A')
15391539
.Case("@yield_many", 'G')
1540+
.Case("@async", 'H')
15401541
.Default(0);
15411542
assert(FuncAttr && "invalid impl function attribute");
15421543
Buffer << FuncAttr;

test/TypeDecoder/concurrency.swift

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %target-build-swift -emit-executable %s -g -o %t/concurrency -emit-module -Xfrontend -enable-experimental-concurrency
4+
5+
// RUN: sed -ne '/\/\/ *DEMANGLE-TYPE: /s/\/\/ *DEMANGLE-TYPE: *//p' < %s > %t/input
6+
// RUN: %lldb-moduleimport-test-with-sdk %t/concurrency -type-from-mangled=%t/input | %FileCheck %s --check-prefix=CHECK-TYPE
7+
8+
func blackHole(_: Any...) {}
9+
10+
public var lookAtMeeee: [(Int) async -> Void] = []
11+
12+
func foo() {
13+
do {
14+
let x1 = [(Int) async -> Void]()
15+
let x2 = [(Int) async throws -> Void]()
16+
17+
blackHole(x1, x2)
18+
}
19+
}
20+
21+
// DEMANGLE-TYPE: $sSayySiYcG
22+
// CHECK-TYPE: Array<(Int) async -> ()>
23+
24+
// DEMANGLE-TYPE: $sSayySiYKcG
25+
// CHECK-TYPE: Array<(Int) async throws -> ()>
26+
27+
// DEMANGLE-TYPE: $sIegH_D
28+
// CHECK-TYPE: @async @callee_guaranteed () -> ()

0 commit comments

Comments
 (0)