Skip to content

Commit 1667c5f

Browse files
committed
mangling: take the constness of function parameters into mangling
Taking constness of parameters into mangling allows us to support overloads of functions vary on the constness of specific parameters. rdar://87954644
1 parent 359ee9b commit 1667c5f

File tree

9 files changed

+40
-1
lines changed

9 files changed

+40
-1
lines changed

docs/ABI/Mangling.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ Types
621621
type-list ::= empty-list
622622

623623
// FIXME: Consider replacing 'h' with a two-char code
624-
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
624+
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
625625

626626
METATYPE-REPR ::= 't' // Thin metatype representation
627627
METATYPE-REPR ::= 'T' // Thick metatype representation

include/swift/Demangling/DemangleNodes.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ NODE(AsyncSuspendResumePartialFunction)
328328

329329
// Added in Swift 5.6
330330
NODE(AccessibleFunctionRecord)
331+
NODE(CompileTimeConst)
331332

332333
// Added in Swift 5.7
333334
NODE(OpaqueReturnTypeIndexed)

lib/AST/ASTMangler.cpp

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

2686+
if (flags.isCompileTimeConst())
2687+
appendOperator("Yt");
2688+
26862689
if (!name.empty())
26872690
appendIdentifier(name.str());
26882691
if (flags.isVariadic())

lib/Demangling/Demangler.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,9 @@ NodePointer Demangler::demangleTypeAnnotation() {
777777
case 'k':
778778
return createType(
779779
createWithChild(Node::Kind::NoDerivative, popTypeAndGetChild()));
780+
case 't':
781+
return createType(
782+
createWithChild(Node::Kind::CompileTimeConst, popTypeAndGetChild()));
780783
default:
781784
return nullptr;
782785
}

lib/Demangling/NodePrinter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ class NodePrinter {
421421
case Node::Kind::InfixOperator:
422422
case Node::Kind::Initializer:
423423
case Node::Kind::Isolated:
424+
case Node::Kind::CompileTimeConst:
424425
case Node::Kind::PropertyWrapperBackingInitializer:
425426
case Node::Kind::PropertyWrapperInitFromProjectedValue:
426427
case Node::Kind::KeyPathGetterThunkHelper:
@@ -1463,6 +1464,10 @@ NodePointer NodePrinter::print(NodePointer Node, unsigned depth,
14631464
Printer << "isolated ";
14641465
print(Node->getChild(0), depth + 1);
14651466
return nullptr;
1467+
case Node::Kind::CompileTimeConst:
1468+
Printer << "_const ";
1469+
print(Node->getChild(0), depth + 1);
1470+
return nullptr;
14661471
case Node::Kind::Shared:
14671472
Printer << "__shared ";
14681473
print(Node->getChild(0), depth + 1);

lib/Demangling/OldRemangler.cpp

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

1826+
ManglingError Remangler::mangleCompileTimeConst(Node *node, unsigned depth) {
1827+
Buffer << "Yt";
1828+
return mangleSingleChildNode(node, depth + 1); // type
1829+
}
1830+
18261831
ManglingError Remangler::mangleNoDerivative(Node *node, unsigned depth) {
18271832
Buffer << 'k';
18281833
return mangleSingleChildNode(node, depth + 1); // type

lib/Demangling/Remangler.cpp

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

1972+
ManglingError Remangler::mangleCompileTimeConst(Node *node, unsigned depth) {
1973+
RETURN_IF_ERROR(mangleSingleChildNode(node, depth + 1));
1974+
Buffer << "Yt";
1975+
return ManglingError::Success;
1976+
}
1977+
19721978
ManglingError Remangler::mangleShared(Node *node, unsigned depth) {
19731979
RETURN_IF_ERROR(mangleSingleChildNode(node, depth + 1));
19741980
Buffer << 'h';

test/Demangle/Inputs/manglings.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,3 +423,4 @@ $s6Foobar7Vector2VAASdRszlE10simdMatrix5scale6rotate9translateSo0C10_double3x3aA
423423
$s17distributed_thunk2DAC1fyyFTE ---> distributed thunk for distributed_thunk.DA.f() -> ()
424424
$s16distributed_test1XC7computeyS2iFTF ---> distributed accessor for distributed_test.X.compute(Swift.Int) -> Swift.Int
425425
$s27distributed_actor_accessors7MyActorC7simple2ySSSiFTETFHF ---> accessible function runtime record for distributed accessor for distributed thunk for distributed_actor_accessors.MyActor.simple2(Swift.Int) -> Swift.String
426+
$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)