Skip to content

Commit afb0d50

Browse files
authored
Merge pull request #1847 from swiftwasm/main
[pull] swiftwasm from main
2 parents 0240f08 + d96ea28 commit afb0d50

File tree

18 files changed

+332
-94
lines changed

18 files changed

+332
-94
lines changed

docs/ABI/Mangling.rst

Lines changed: 3 additions & 1 deletion
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/AST/Decl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5946,7 +5946,7 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
59465946
/// Returns true if the function is an @asyncHandler.
59475947
bool isAsyncHandler() const;
59485948

5949-
/// Returns true if the function if the signature matches the form of an
5949+
/// Returns true if the function signature matches the form of an
59505950
/// @asyncHandler.
59515951
bool canBeAsyncHandler() const;
59525952

include/swift/Demangling/TypeDecoder.h

Lines changed: 2 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 5 additions & 0 deletions
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/AST/ASTVerifier.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,30 +1828,30 @@ class Verifier : public ASTWalker {
18281828
Out << "\n";
18291829
abort();
18301830
}
1831-
1831+
1832+
if (!isa<VarDecl>(E->getMember().getDecl())) {
1833+
Out << "Member reference to a non-VarDecl\n";
1834+
E->dump(Out);
1835+
Out << "\n";
1836+
abort();
1837+
}
1838+
1839+
auto baseType = E->getBase()->getType();
1840+
if (baseType->is<InOutType>()) {
1841+
Out << "Member reference to an inout type\n";
1842+
E->dump(Out);
1843+
Out << "\n";
1844+
abort();
1845+
}
1846+
18321847
// The base of a member reference cannot be an existential type.
1833-
if (E->getBase()->getType()->getWithoutSpecifierType()
1834-
->isExistentialType()) {
1848+
if (baseType->getWithoutSpecifierType()->isExistentialType()) {
18351849
Out << "Member reference into an unopened existential type\n";
18361850
E->dump(Out);
18371851
Out << "\n";
18381852
abort();
18391853
}
18401854

1841-
// The only time the base is allowed to be inout is if we are accessing
1842-
// a computed property or if the base is a protocol or existential.
1843-
if (auto *baseIOT = E->getBase()->getType()->getAs<InOutType>()) {
1844-
if (!baseIOT->getObjectType()->is<ArchetypeType>()) {
1845-
auto *VD = dyn_cast<VarDecl>(E->getMember().getDecl());
1846-
if (!VD || !VD->requiresOpaqueAccessors()) {
1847-
Out << "member_ref_expr on value of inout type\n";
1848-
E->dump(Out);
1849-
Out << "\n";
1850-
abort();
1851-
}
1852-
}
1853-
}
1854-
18551855
// FIXME: Check container/member types through substitutions.
18561856

18571857
verifyCheckedBase(E);

lib/Demangling/Demangler.cpp

Lines changed: 5 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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;

0 commit comments

Comments
 (0)