Skip to content

Commit 6e07c8c

Browse files
committed
Mangling: Add a mangling for #_hasSymbol query functions.
1 parent 6f77e8b commit 6e07c8c

File tree

9 files changed

+48
-1
lines changed

9 files changed

+48
-1
lines changed

docs/ABI/Mangling.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,11 @@ Globals
157157
global ::= protocol-conformance 'MA' // metadata for remote mirrors: associated type descriptor
158158
global ::= nominal-type 'MC' // metadata for remote mirrors: superclass descriptor
159159

160-
// TODO check this::
161160
global ::= mangled-name 'TA' // partial application forwarder
162161
global ::= mangled-name 'Ta' // ObjC partial application forwarder
163162
global ::= mangled-name 'TQ' index // Async await continuation partial function
164163
global ::= mangled-name 'TY' index // Async suspend continuation partial function
164+
global ::= mangled-name 'TwS' // #_hasSymbol query function
165165

166166
global ::= type 'w' VALUE-WITNESS-KIND // value witness
167167

include/swift/AST/ASTMangler.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ class ASTMangler : public Mangler {
157157
AccessibleFunctionRecord,
158158
BackDeploymentThunk,
159159
BackDeploymentFallback,
160+
HasSymbolQuery,
160161
};
161162

162163
/// lldb overrides the defaulted argument to 'true'.
@@ -357,6 +358,8 @@ class ASTMangler : public Mangler {
357358

358359
std::string mangleGenericSignature(const GenericSignature sig);
359360

361+
std::string mangleHasSymbolQuery(const ValueDecl *decl);
362+
360363
enum SpecialContext {
361364
ObjCContext,
362365
ClangImporterContext,

include/swift/Demangling/DemangleNodes.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,9 @@ NODE(UniqueExtendedExistentialTypeShapeSymbolicReference)
344344
NODE(NonUniqueExtendedExistentialTypeShapeSymbolicReference)
345345
NODE(SymbolicExtendedExistentialType)
346346

347+
// Added in Swift 5.8
347348
NODE(MetatypeParamsRemoved)
349+
NODE(HasSymbolQuery)
348350

349351
#undef CONTEXT_NODE
350352
#undef NODE

lib/AST/ASTMangler.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,28 @@ std::string ASTMangler::mangleGenericSignature(const GenericSignature sig) {
861861
return finalize();
862862
}
863863

864+
std::string ASTMangler::mangleHasSymbolQuery(const ValueDecl *Decl) {
865+
beginMangling();
866+
867+
if (auto Ctor = dyn_cast<ConstructorDecl>(Decl)) {
868+
appendConstructorEntity(Ctor, /*isAllocating=*/false);
869+
} else if (auto Dtor = dyn_cast<DestructorDecl>(Decl)) {
870+
appendDestructorEntity(Dtor, /*isDeallocating=*/false);
871+
} else if (auto GTD = dyn_cast<GenericTypeDecl>(Decl)) {
872+
appendAnyGenericType(GTD);
873+
} else if (isa<AssociatedTypeDecl>(Decl)) {
874+
appendContextOf(Decl);
875+
appendDeclName(Decl);
876+
appendOperator("Qa");
877+
} else {
878+
appendEntity(Decl);
879+
}
880+
881+
appendSymbolKind(ASTMangler::SymbolKind::HasSymbolQuery);
882+
883+
return finalize();
884+
}
885+
864886
void ASTMangler::appendSymbolKind(SymbolKind SKind) {
865887
switch (SKind) {
866888
case SymbolKind::Default: return;
@@ -872,6 +894,7 @@ void ASTMangler::appendSymbolKind(SymbolKind SKind) {
872894
case SymbolKind::AccessibleFunctionRecord: return appendOperator("HF");
873895
case SymbolKind::BackDeploymentThunk: return appendOperator("Twb");
874896
case SymbolKind::BackDeploymentFallback: return appendOperator("TwB");
897+
case SymbolKind::HasSymbolQuery: return appendOperator("TwS");
875898
}
876899
}
877900

lib/Demangling/Demangler.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ bool swift::Demangle::isFunctionAttr(Node::Kind kind) {
145145
case Node::Kind::AccessibleFunctionRecord:
146146
case Node::Kind::BackDeploymentThunk:
147147
case Node::Kind::BackDeploymentFallback:
148+
case Node::Kind::HasSymbolQuery:
148149
return true;
149150
default:
150151
return false;
@@ -2675,6 +2676,7 @@ NodePointer Demangler::demangleThunkOrSpecialization() {
26752676
switch (nextChar()) {
26762677
case 'b': return createNode(Node::Kind::BackDeploymentThunk);
26772678
case 'B': return createNode(Node::Kind::BackDeploymentFallback);
2679+
case 'S': return createNode(Node::Kind::HasSymbolQuery);
26782680
default:
26792681
return nullptr;
26802682
}

lib/Demangling/NodePrinter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,7 @@ class NodePrinter {
604604
case Node::Kind::UniqueExtendedExistentialTypeShapeSymbolicReference:
605605
case Node::Kind::NonUniqueExtendedExistentialTypeShapeSymbolicReference:
606606
case Node::Kind::SymbolicExtendedExistentialType:
607+
case Node::Kind::HasSymbolQuery:
607608
return false;
608609
}
609610
printer_unreachable("bad node kind");
@@ -3046,6 +3047,9 @@ NodePointer NodePrinter::print(NodePointer Node, unsigned depth,
30463047

30473048
return nullptr;
30483049
}
3050+
case Node::Kind::HasSymbolQuery:
3051+
Printer << "#_hasSymbol query for ";
3052+
return nullptr;
30493053
}
30503054

30513055
printer_unreachable("bad node kind!");

lib/Demangling/OldRemangler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2854,3 +2854,8 @@ ManglingError Remangler::mangleBackDeploymentFallback(Node *node,
28542854
Buffer << "TwB";
28552855
return ManglingError::Success;
28562856
}
2857+
2858+
ManglingError Remangler::mangleHasSymbolQuery(Node *node, unsigned depth) {
2859+
Buffer << "TwS";
2860+
return ManglingError::Success;
2861+
}

lib/Demangling/Remangler.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,6 +1669,7 @@ ManglingError Remangler::mangleGlobal(Node *node, unsigned depth) {
16691669
case Node::Kind::AccessibleFunctionRecord:
16701670
case Node::Kind::BackDeploymentThunk:
16711671
case Node::Kind::BackDeploymentFallback:
1672+
case Node::Kind::HasSymbolQuery:
16721673
mangleInReverseOrder = true;
16731674
break;
16741675
default:
@@ -3503,6 +3504,11 @@ ManglingError Remangler::mangleExtendedExistentialTypeShape(Node *node,
35033504
return ManglingError::Success;
35043505
}
35053506

3507+
ManglingError Remangler::mangleHasSymbolQuery(Node *node, unsigned depth) {
3508+
Buffer << "TwS";
3509+
return ManglingError::Success;
3510+
}
3511+
35063512
ManglingError Remangler::mangleSymbolicExtendedExistentialType(Node *node,
35073513
unsigned int depth) {
35083514
RETURN_IF_ERROR(mangle(node->getChild(0), depth+1));

test/Demangle/Inputs/manglings.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,3 +439,5 @@ $sxIeghHr_xs5Error_pIegHrzo_s8SendableRzs5NeverORs_r0_lTRTQ0_ ---> {T:} (1) awai
439439
$sxIeghHr_xs5Error_pIegHrzo_s8SendableRzs5NeverORs_r0_lTRTY0_ ---> {T:} (1) suspend resume partial function for reabstraction thunk helper <A, B where A: Swift.Sendable, B == Swift.Never> from @escaping @callee_guaranteed @Sendable @async () -> (@out A) to @escaping @callee_guaranteed @async () -> (@out A, @error @owned Swift.Error)
440440
$sxIeghHr_xs5Error_pIegHrzo_s8SendableRzs5NeverORs_r0_lTRTY_ ---> {T:} (0) suspend resume partial function for reabstraction thunk helper <A, B where A: Swift.Sendable, B == Swift.Never> from @escaping @callee_guaranteed @Sendable @async () -> (@out A) to @escaping @callee_guaranteed @async () -> (@out A, @error @owned Swift.Error)
441441
$sxIeghHr_xs5Error_pIegHrzo_s8SendableRzs5NeverORs_r0_lTRTQ12_ ---> {T:} (13) await resume partial function for reabstraction thunk helper <A, B where A: Swift.Sendable, B == Swift.Never> from @escaping @callee_guaranteed @Sendable @async () -> (@out A) to @escaping @callee_guaranteed @async () -> (@out A, @error @owned Swift.Error)
442+
$s7Library3fooyyFTwS ---> #_hasSymbol query for Library.foo() -> ()
443+
$s7Library5KlassCTwS ---> #_hasSymbol query for Library.Klass

0 commit comments

Comments
 (0)