Skip to content

Commit 7ae6737

Browse files
authored
mangling: take the constness of function parameters into mangling (#40988)
Taking constness of parameters into mangling allows us to support overloads of functions vary on the constness of specific parameters. rdar://87954644
1 parent 729f152 commit 7ae6737

File tree

9 files changed

+42
-1
lines changed

9 files changed

+42
-1
lines changed

docs/ABI/Mangling.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ Types
619619
type-list ::= empty-list
620620

621621
// FIXME: Consider replacing 'h' with a two-char code
622-
list-type ::= type identifier? 'Yk'? 'z'? 'h'? 'n'? 'Yi'? 'd'? // type with optional label, '@noDerivative', inout convention, shared convention, owned convention, actor 'isolated', and variadic specifier
622+
list-type ::= type identifier? 'Yk'? 'z'? 'h'? 'n'? 'Yi'? 'd'? 'Yt'? // type with optional label, '@noDerivative', inout convention, shared convention, owned convention, actor 'isolated', variadic specifier, and compile-time constant
623623

624624
METATYPE-REPR ::= 't' // Thin metatype representation
625625
METATYPE-REPR ::= 'T' // Thick metatype representation

include/swift/Demangling/DemangleNodes.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,5 +325,8 @@ NODE(IndexSubset)
325325
NODE(AsyncAwaitResumePartialFunction)
326326
NODE(AsyncSuspendResumePartialFunction)
327327

328+
// Added in Swift 5.6
329+
NODE(CompileTimeConst)
330+
328331
#undef CONTEXT_NODE
329332
#undef NODE

lib/AST/ASTMangler.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2654,6 +2654,9 @@ void ASTMangler::appendTypeListElement(Identifier name, Type elementType,
26542654
if (flags.isIsolated())
26552655
appendOperator("Yi");
26562656

2657+
if (flags.isCompileTimeConst())
2658+
appendOperator("Yt");
2659+
26572660
if (!name.empty())
26582661
appendIdentifier(name.str());
26592662
if (flags.isVariadic())

lib/Demangling/Demangler.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,9 @@ NodePointer Demangler::demangleTypeAnnotation() {
763763
case 'k':
764764
return createType(
765765
createWithChild(Node::Kind::NoDerivative, popTypeAndGetChild()));
766+
case 't':
767+
return createType(
768+
createWithChild(Node::Kind::CompileTimeConst, popTypeAndGetChild()));
766769
default:
767770
return nullptr;
768771
}

lib/Demangling/NodePrinter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ class NodePrinter {
419419
case Node::Kind::InfixOperator:
420420
case Node::Kind::Initializer:
421421
case Node::Kind::Isolated:
422+
case Node::Kind::CompileTimeConst:
422423
case Node::Kind::PropertyWrapperBackingInitializer:
423424
case Node::Kind::PropertyWrapperInitFromProjectedValue:
424425
case Node::Kind::KeyPathGetterThunkHelper:
@@ -1457,6 +1458,10 @@ NodePointer NodePrinter::print(NodePointer Node, unsigned depth,
14571458
Printer << "isolated ";
14581459
print(Node->getChild(0), depth + 1);
14591460
return nullptr;
1461+
case Node::Kind::CompileTimeConst:
1462+
Printer << "_const ";
1463+
print(Node->getChild(0), depth + 1);
1464+
return nullptr;
14601465
case Node::Kind::Shared:
14611466
Printer << "__shared ";
14621467
print(Node->getChild(0), depth + 1);

lib/Demangling/OldRemangler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,6 +1817,11 @@ ManglingError Remangler::mangleIsolated(Node *node, unsigned depth) {
18171817
return mangleSingleChildNode(node, depth + 1); // type
18181818
}
18191819

1820+
ManglingError Remangler::mangleCompileTimeConst(Node *node, unsigned depth) {
1821+
Buffer << "Yt";
1822+
return mangleSingleChildNode(node, depth + 1); // type
1823+
}
1824+
18201825
ManglingError Remangler::mangleNoDerivative(Node *node, unsigned depth) {
18211826
Buffer << 'k';
18221827
return mangleSingleChildNode(node, depth + 1); // type

lib/Demangling/Remangler.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1963,6 +1963,12 @@ ManglingError Remangler::mangleIsolated(Node *node, unsigned depth) {
19631963
return ManglingError::Success;
19641964
}
19651965

1966+
ManglingError Remangler::mangleCompileTimeConst(Node *node, unsigned depth) {
1967+
RETURN_IF_ERROR(mangleSingleChildNode(node, depth + 1));
1968+
Buffer << "Yt";
1969+
return ManglingError::Success;
1970+
}
1971+
19661972
ManglingError Remangler::mangleShared(Node *node, unsigned depth) {
19671973
RETURN_IF_ERROR(mangleSingleChildNode(node, depth + 1));
19681974
Buffer << 'h';

test/Demangle/Inputs/manglings.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,3 +421,4 @@ $s13__lldb_expr_110$10016c2d8yXZ1B10$10016c2e0LLC ---> __lldb_expr_1.(unknown co
421421
$s__TJO ---> $s__TJO
422422
$s6Foobar7Vector2VAASdRszlE10simdMatrix5scale6rotate9translateSo0C10_double3x3aACySdG_SdAJtFZ0D4TypeL_aySd__GD ---> MatrixType #1 in static (extension in Foobar):Foobar.Vector2<Swift.Double><A where A == Swift.Double>.simdMatrix(scale: Foobar.Vector2<Swift.Double>, rotate: Swift.Double, translate: Foobar.Vector2<Swift.Double>) -> __C.simd_double3x3
423423
$s17distributed_thunk2DAC1fyyFTE ---> distributed thunk for distributed_thunk.DA.f() -> ()
424+
$s1A3bar1aySSYt_tF ---> A.bar(a: _const Swift.String) -> ()

test/SILGen/const_param.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %target-swift-emit-silgen -parse-as-library %s -module-name A | %FileCheck %s
2+
3+
func foo(_ a: _const Int) {}
4+
func bar(a: _const String) {}
5+
6+
// CHECK: @$s1A3fooyySiYtF
7+
// CHECK: @$s1A3bar1aySSYt_tF
8+
9+
// RUN: %swift-demangle s1A3fooyySiYtF | %FileCheck %s -check-prefix=CHECK-FOO
10+
11+
// CHECK-FOO: A.foo(_const Swift.Int) -> ()
12+
13+
// RUN: %swift-demangle s1A3bar1aySSYt_tF | %FileCheck %s -check-prefix=CHECK-BAR
14+
15+
// CHECK-BAR: A.bar(a: _const Swift.String) -> ()

0 commit comments

Comments
 (0)