Skip to content

Commit 4c09fa6

Browse files
committed
Mangling: add a specialization mangling for changing the function type representation of a function
1 parent ab2345a commit 4c09fa6

File tree

8 files changed

+37
-2
lines changed

8 files changed

+37
-2
lines changed

docs/ABI/Mangling.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1350,7 +1350,7 @@ Some kinds need arguments, which precede ``Tf``.
13501350
spec-arg ::= identifier
13511351
spec-arg ::= type
13521352

1353-
SPEC-INFO ::= FRAGILE? ASYNC-REMOVED? PASSID
1353+
SPEC-INFO ::= FRAGILE? (ASYNC-REMOVED|REPR-CHANGED)? PASSID
13541354

13551355
PASSID ::= '0' // AllocBoxToStack,
13561356
PASSID ::= '1' // ClosureSpecializer,
@@ -1361,10 +1361,12 @@ Some kinds need arguments, which precede ``Tf``.
13611361
PASSID ::= '6' // MoveDiagnosticInOutToOut,
13621362
PASSID ::= '7' // AsyncDemotion,
13631363
PASSID ::= '8' // PackSpecialization,
1364+
PASSID ::= '9' // EmbeddedWitnessCallSpecialization
13641365

13651366
FRAGILE ::= 'q'
13661367

13671368
ASYNC-REMOVED ::= 'a' // async effect removed
1369+
REPR-CHANGED ::= 'r' // function type representation changed
13681370

13691371
ARG-SPEC-KIND ::= 'n' // Unmodified argument
13701372
ARG-SPEC-KIND ::= 'c' // Consumes n 'type' arguments which are closed over types in argument order

include/swift/Demangling/Demangle.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ enum class SpecializationPass : uint8_t {
165165
MoveDiagnosticInOutToOut,
166166
AsyncDemotion,
167167
PackSpecialization,
168-
LAST = PackSpecialization
168+
EmbeddedWitnessCallSpecialization,
169+
LAST = EmbeddedWitnessCallSpecialization
169170
};
170171

171172
constexpr uint8_t MAX_SPECIALIZATION_PASS = 10;

include/swift/Demangling/DemangleNodes.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,8 @@ NODE(OutlinedEnumProjectDataForLoad)
399399
NODE(OutlinedEnumGetTag)
400400
// Added in Swift 5.9 + 1
401401
NODE(AsyncRemoved)
402+
// Added in Swift 6.3 + 1
403+
NODE(RepresentationChanged)
402404

403405
// Added in Swift 5.TBD
404406
NODE(ObjectiveCProtocolSymbolicReference)

lib/Demangling/Demangler.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3377,6 +3377,8 @@ NodePointer Demangler::demangleGenericSpecializationWithDroppedArguments() {
33773377
NodePointer Demangler::demangleFunctionSpecialization() {
33783378
NodePointer Spec = demangleSpecAttributes(
33793379
Node::Kind::FunctionSignatureSpecialization);
3380+
if (Spec && Spec->getFirstChild()->getKind() == Node::Kind::RepresentationChanged)
3381+
return Spec;
33803382
while (Spec && !nextIf('_')) {
33813383
Spec = addChild(Spec, demangleFuncSpecParam(Node::Kind::FunctionSignatureSpecializationParam));
33823384
}
@@ -3619,6 +3621,7 @@ NodePointer Demangler::addFuncSpecParamNumber(NodePointer Param,
36193621
NodePointer Demangler::demangleSpecAttributes(Node::Kind SpecKind) {
36203622
bool isSerialized = nextIf('q');
36213623
bool asyncRemoved = nextIf('a');
3624+
bool representationChanged = nextIf('r');
36223625

36233626
int PassID = (int)nextChar() - '0';
36243627
if (PassID < 0 || PassID >= MAX_SPECIALIZATION_PASS) {
@@ -3635,6 +3638,10 @@ NodePointer Demangler::demangleSpecAttributes(Node::Kind SpecKind) {
36353638
SpecNd->addChild(createNode(Node::Kind::AsyncRemoved),
36363639
*this);
36373640

3641+
if (representationChanged)
3642+
SpecNd->addChild(createNode(Node::Kind::RepresentationChanged),
3643+
*this);
3644+
36383645
SpecNd->addChild(createNode(Node::Kind::SpecializationPassID, PassID),
36393646
*this);
36403647
return SpecNd;

lib/Demangling/NodePrinter.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ bool NodePrinter::isSimpleType(NodePointer Node) {
487487
case Node::Kind::ReadAccessor:
488488
case Node::Kind::Read2Accessor:
489489
case Node::Kind::RelatedEntityDeclName:
490+
case Node::Kind::RepresentationChanged:
490491
case Node::Kind::RetroactiveConformance:
491492
case Node::Kind::Setter:
492493
case Node::Kind::Shared:
@@ -1331,6 +1332,10 @@ void NodePrinter::printSpecializationPrefix(NodePointer node,
13311332
}
13321333
return;
13331334
}
1335+
if (node->getFirstChild()->getKind() == Node::Kind::RepresentationChanged) {
1336+
Printer << "representation changed of ";
1337+
return;
1338+
}
13341339
Printer << Description << " <";
13351340
const char *Separator = "";
13361341
int argNum = 0;
@@ -1429,6 +1434,10 @@ NodePointer NodePrinter::print(NodePointer Node, unsigned depth,
14291434
Printer << "async demotion of ";
14301435
print(Node->getChild(0), depth + 1);
14311436
return nullptr;
1437+
case Node::Kind::RepresentationChanged:
1438+
Printer << "representation changed of ";
1439+
print(Node->getChild(0), depth + 1);
1440+
return nullptr;
14321441
case Node::Kind::CurryThunk:
14331442
Printer << "curry thunk of ";
14341443
print(Node->getChild(0), depth + 1);

lib/Demangling/OldRemangler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,11 @@ ManglingError Remangler::mangleAsyncRemoved(Node *node, unsigned depth) {
451451
return ManglingError::Success;
452452
}
453453

454+
ManglingError Remangler::mangleRepresentationChanged(Node *node, unsigned depth) {
455+
Buffer << "r";
456+
return ManglingError::Success;
457+
}
458+
454459
ManglingError Remangler::mangleDroppedArgument(Node *node, unsigned depth) {
455460
Buffer << "t" << node->getIndex();
456461
return ManglingError::Success;

lib/Demangling/Remangler.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,6 +1518,9 @@ ManglingError Remangler::mangleFunctionSignatureSpecialization(Node *node,
15181518
Buffer << "Tf";
15191519
bool returnValMangled = false;
15201520
for (NodePointer Child : *node) {
1521+
if (Child->getKind() == Node::Kind::RepresentationChanged) {
1522+
returnValMangled = true;
1523+
}
15211524
if (Child->getKind() == Node::Kind::FunctionSignatureSpecializationReturn) {
15221525
Buffer << '_';
15231526
returnValMangled = true;
@@ -3193,6 +3196,11 @@ ManglingError Remangler::mangleAsyncRemoved(Node *node, unsigned depth) {
31933196
return ManglingError::Success;
31943197
}
31953198

3199+
ManglingError Remangler::mangleRepresentationChanged(Node *node, unsigned depth) {
3200+
Buffer << 'r';
3201+
return ManglingError::Success;
3202+
}
3203+
31963204
ManglingError Remangler::mangleDroppedArgument(Node *node, unsigned depth) {
31973205
Buffer << "t";
31983206
int n = node->getIndex();

test/Demangle/Inputs/manglings.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ $s27distributed_actor_accessors7MyActorC7simple2ySSSiFTETFHF ---> accessible fun
442442
$s1A3bar1aySSYt_tF ---> A.bar(a: _const Swift.String) -> ()
443443
$s1t1fyyFSiAA3StrVcs7KeyPathCyADSiGcfu_SiADcfu0_33_556644b740b1b333fecb81e55a7cce98ADSiTf3npk_n ---> function signature specialization <Arg[1] = [Constant Propagated KeyPath : _556644b740b1b333fecb81e55a7cce98<t.Str,Swift.Int>]> of implicit closure #2 (t.Str) -> Swift.Int in implicit closure #1 (Swift.KeyPath<t.Str, Swift.Int>) -> (t.Str) -> Swift.Int in t.f() -> ()
444444
$s3foo4main1SVs5Int32VSbTf3npSSi3Si0_n ---> function signature specialization <Arg[1] = [Constant Propagated Struct : main.S][Constant Propagated Struct : Swift.Int32][Constant Propagated Integer : 3][Constant Propagated Struct : Swift.Bool][Constant Propagated Integer : 0]> of foo
445+
$e4test4BaseCyxGAA1PA2aEP3fooyyFTWTfr9 ---> representation changed of protocol witness for test.P.foo() -> () in conformance test.Base<A> : test.P in test
445446
$s21back_deploy_attribute0A12DeployedFuncyyFTwb ---> back deployment thunk for back_deploy_attribute.backDeployedFunc() -> ()
446447
$s21back_deploy_attribute0A12DeployedFuncyyFTwB ---> back deployment fallback for back_deploy_attribute.backDeployedFunc() -> ()
447448
$s4test3fooyyAA1P_px1TRts_XPlF ---> test.foo<A>(any test.P<Self.T == A>) -> ()

0 commit comments

Comments
 (0)