Skip to content

Commit 0cd5aa8

Browse files
committed
Change mangling for the Swift module from 'Ss' to 's'.
'Ss' appears in manglings tens of thousands of times in the standard library and is also incredibly frequent in other modules. This alone is enough to shrink the standard library by 59KB. Swift SVN r32409
1 parent 394b948 commit 0cd5aa8

File tree

180 files changed

+969
-930
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

180 files changed

+969
-930
lines changed

docs/ABI.rst

+17-6
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ Globals
765765
entity ::= static? entity-kind context entity-name
766766
entity-kind ::= 'F' // function (ctor, accessor, etc.)
767767
entity-kind ::= 'v' // variable (let/var)
768-
entity-kind ::= 's' // subscript itself (not the individual accessors)
768+
entity-kind ::= 'i' // subscript ('i'ndex) itself (not the individual accessors)
769769
entity-kind ::= 'I' // initializer
770770
entity-name ::= decl-name type // named declaration
771771
entity-name ::= 'A' index // default argument generator
@@ -796,15 +796,15 @@ Globals
796796
addressor-kind ::= 'p' // pinning addressor (native owner)
797797

798798
An ``entity`` starts with a ``nominal-type-kind`` (``[COPV]``), a
799-
substitution (``[S]``) of a nominal type, or an ``entity-kind``
800-
(``[FIsv]``).
799+
substitution (``[Ss]``) of a nominal type, or an ``entity-kind``
800+
(``[FIiv]``).
801801

802802
An ``entity-name`` starts with ``[AaCcDggis]`` or a ``decl-name``.
803803
A ``decl-name`` starts with ``[LP]`` or an ``identifier`` (``[0-9oX]``).
804804

805805
A ``context`` starts with either an ``entity``, an ``extension`` (which starts
806-
with ``[E]``), or a ``module``, which might be an ``identifier`` (``[0-9oX]``)
807-
or a substitution of a module (``[S]``).
806+
with ``[Ee]``), or a ``module``, which might be an ``identifier`` (``[0-9oX]``)
807+
or a substitution of a module (``[Ss]``).
808808

809809
A global mangling starts with an ``entity`` or ``[MTWw]``.
810810

@@ -1137,22 +1137,33 @@ if it mangled again.) The result type will mangle using the substitution for
11371137
``zim.zang``, ``CS0_zoo`` (and acquire substitution ``S3_``). The full
11381138
function type thus mangles as ``fTCC3zim4zang4zungCS1_CS_7zippity_CS0_zoo``.
11391139

1140+
::
1141+
1142+
substitution ::= 's'
1143+
1144+
The special substitution ``s`` is used for the ``Swift`` standard library
1145+
module.
1146+
11401147
Predefined Substitutions
11411148
~~~~~~~~~~~~~~~~~~~~~~~~
11421149

11431150
::
11441151

1152+
known-module ::= 's' // Swift
11451153
known-module ::= 'SC' // C
11461154
known-module ::= 'So' // Objective-C
1147-
known-module ::= 'Ss' // Swift
11481155
known-nominal-type ::= 'Sa' // Swift.Array
11491156
known-nominal-type ::= 'Sb' // Swift.Bool
11501157
known-nominal-type ::= 'Sc' // Swift.UnicodeScalar
11511158
known-nominal-type ::= 'Sd' // Swift.Float64
11521159
known-nominal-type ::= 'Sf' // Swift.Float32
11531160
known-nominal-type ::= 'Si' // Swift.Int
1161+
known-nominal-type ::= 'SP' // Swift.UnsafePointer
1162+
known-nominal-type ::= 'Sp' // Swift.UnsafeMutablePointer
11541163
known-nominal-type ::= 'SQ' // Swift.ImplicitlyUnwrappedOptional
11551164
known-nominal-type ::= 'Sq' // Swift.Optional
1165+
known-nominal-type ::= 'SR' // Swift.UnsafeBufferPointer
1166+
known-nominal-type ::= 'Sr' // Swift.UnsafeMutableBufferPointer
11561167
known-nominal-type ::= 'SS' // Swift.String
11571168
known-nominal-type ::= 'Su' // Swift.UInt
11581169

docs/DebuggingTheCompiler.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -257,4 +257,4 @@ function in the current frame::
257257
Address: CollectionType3[0x0000000100004db0] (CollectionType3.__TEXT.__text + 16000)
258258
Summary: CollectionType3`ext.CollectionType3.CollectionType3.MutableCollectionType2<A where A: CollectionType3.MutableCollectionType2>.(subscript.materializeForSet : (Swift.Range<A.Index>) -> Swift.MutableSlice<A>).(closure #1)
259259
Module: file = "/Volumes/Files/work/solon/build/build-swift/validation-test-macosx-x86_64/stdlib/Output/CollectionType.swift.gyb.tmp/CollectionType3", arch = "x86_64"
260-
Symbol: id = {0x0000008c}, range = [0x0000000100004db0-0x00000001000056f0), name="ext.CollectionType3.CollectionType3.MutableCollectionType2<A where A: CollectionType3.MutableCollectionType2>.(subscript.materializeForSet : (Swift.Range<A.Index>) -> Swift.MutableSlice<A>).(closure #1)", mangled="_TFFeRq_15CollectionType322MutableCollectionType2_S_S0_m9subscriptFGVSs5Rangeqq_Ss16MutableIndexable5Index_GVSs12MutableSliceq__U_FTBpRBBRQPS0_MS4__T_"
260+
Symbol: id = {0x0000008c}, range = [0x0000000100004db0-0x00000001000056f0), name="ext.CollectionType3.CollectionType3.MutableCollectionType2<A where A: CollectionType3.MutableCollectionType2>.(subscript.materializeForSet : (Swift.Range<A.Index>) -> Swift.MutableSlice<A>).(closure #1)", mangled="_TFFeRq_15CollectionType322MutableCollectionType2_S_S0_m9subscriptFGVs5Rangeqq_s16MutableIndexable5Index_GVs12MutableSliceq__U_FTBpRBBRQPS0_MS4__T_"

docs/SIL.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ Here is an example of a ``.sil`` file::
162162
sil @_T5norms11taxicabNormfT1aV5norms5Point_Sd : $(Point) -> Double {
163163
bb0(%0 : $Point):
164164
// func Swift.+(Double, Double) -> Double
165-
%1 = function_ref @_TSsoi1pfTSdSd_Sd
165+
%1 = function_ref @_Tsoi1pfTSdSd_Sd
166166
%2 = struct_extract %0 : $Point, #Point.x
167167
%3 = struct_extract %0 : $Point, #Point.y
168168
%4 = apply %1(%2, %3) : $(Double, Double) -> Double

lib/AST/Mangle.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,9 @@ void Mangler::mangleModule(const Module *module) {
315315

316316
// Try the special 'swift' substitution.
317317
// context ::= known-module
318-
// known-module ::= 'Ss'
318+
// known-module ::= 's'
319319
if (module->isStdlibModule()) {
320-
Buffer << "Ss";
320+
Buffer << "s";
321321
return;
322322
}
323323

@@ -1686,7 +1686,7 @@ void Mangler::mangleEntity(const ValueDecl *decl,
16861686
if (isa<VarDecl>(decl)) {
16871687
Buffer << 'v';
16881688
} else if (isa<SubscriptDecl>(decl)) {
1689-
Buffer << 's';
1689+
Buffer << 'i';
16901690
} else if (isa<GenericTypeParamDecl>(decl)) {
16911691
shouldBindParent = BindGenerics::None;
16921692
Buffer << 't';

lib/Basic/Demangle.cpp

+32-4
Original file line numberDiff line numberDiff line change
@@ -1002,8 +1002,6 @@ class Demangler {
10021002
return NodeFactory::create(Node::Kind::Module, MANGLING_MODULE_OBJC);
10031003
if (Mangled.nextIf('C'))
10041004
return NodeFactory::create(Node::Kind::Module, MANGLING_MODULE_C);
1005-
if (Mangled.nextIf('s'))
1006-
return NodeFactory::create(Node::Kind::Module, STDLIB_NAME);
10071005
if (Mangled.nextIf('a'))
10081006
return createSwiftType(Node::Kind::Structure, "Array");
10091007
if (Mangled.nextIf('b'))
@@ -1016,10 +1014,18 @@ class Demangler {
10161014
return createSwiftType(Node::Kind::Structure, "Float");
10171015
if (Mangled.nextIf('i'))
10181016
return createSwiftType(Node::Kind::Structure, "Int");
1017+
if (Mangled.nextIf('P'))
1018+
return createSwiftType(Node::Kind::Structure, "UnsafePointer");
1019+
if (Mangled.nextIf('p'))
1020+
return createSwiftType(Node::Kind::Structure, "UnsafeMutablePointer");
10191021
if (Mangled.nextIf('q'))
10201022
return createSwiftType(Node::Kind::Enum, "Optional");
10211023
if (Mangled.nextIf('Q'))
10221024
return createSwiftType(Node::Kind::Enum, "ImplicitlyUnwrappedOptional");
1025+
if (Mangled.nextIf('R'))
1026+
return createSwiftType(Node::Kind::Structure, "UnsafeBufferPointer");
1027+
if (Mangled.nextIf('r'))
1028+
return createSwiftType(Node::Kind::Structure, "UnsafeMutableBufferPointer");
10231029
if (Mangled.nextIf('S'))
10241030
return createSwiftType(Node::Kind::Structure, "String");
10251031
if (Mangled.nextIf('u'))
@@ -1033,6 +1039,9 @@ class Demangler {
10331039
}
10341040

10351041
NodePointer demangleModule() {
1042+
if (Mangled.nextIf('s')) {
1043+
return NodeFactory::create(Node::Kind::Module, STDLIB_NAME);
1044+
}
10361045
if (Mangled.nextIf('S')) {
10371046
NodePointer module = demangleSubstitutionIndex();
10381047
if (!module)
@@ -1095,6 +1104,19 @@ class Demangler {
10951104
return proto;
10961105
}
10971106

1107+
if (Mangled.nextIf('s')) {
1108+
NodePointer stdlib = NodeFactory::create(Node::Kind::Module, STDLIB_NAME);
1109+
1110+
NodePointer name = demangleDeclName();
1111+
if (!name) return nullptr;
1112+
1113+
auto proto = NodeFactory::create(Node::Kind::Protocol);
1114+
proto->addChild(std::move(stdlib));
1115+
proto->addChild(std::move(name));
1116+
Substitutions.push_back(proto);
1117+
return proto;
1118+
}
1119+
10981120
return demangleDeclarationName(Node::Kind::Protocol);
10991121
}
11001122

@@ -1148,6 +1170,8 @@ class Demangler {
11481170
}
11491171
if (Mangled.nextIf('S'))
11501172
return demangleSubstitutionIndex();
1173+
if (Mangled.nextIf('s'))
1174+
return NodeFactory::create(Node::Kind::Module, STDLIB_NAME);
11511175
if (isStartOfEntity(Mangled.peek()))
11521176
return demangleEntity();
11531177
return demangleModule();
@@ -1198,7 +1222,7 @@ class Demangler {
11981222
entityBasicKind = Node::Kind::Variable;
11991223
} else if (Mangled.nextIf('I')) {
12001224
entityBasicKind = Node::Kind::Initializer;
1201-
} else if (Mangled.nextIf('s')) {
1225+
} else if (Mangled.nextIf('i')) {
12021226
entityBasicKind = Node::Kind::Subscript;
12031227
} else {
12041228
return demangleNominalType();
@@ -1356,7 +1380,7 @@ class Demangler {
13561380
if (!Mangled)
13571381
return nullptr;
13581382
char c = Mangled.peek();
1359-
if (c != '_' && c != 'S'
1383+
if (c != '_' && c != 'S' && c != 's'
13601384
&& (nodeKind == Node::Kind::AssociatedType || c != 'U')
13611385
&& !isStartOfIdentifier(c))
13621386
break;
@@ -1589,6 +1613,10 @@ class Demangler {
15891613
else
15901614
return makeAssociatedType(sub);
15911615
}
1616+
if (Mangled.nextIf('s')) {
1617+
NodePointer stdlib = NodeFactory::create(Node::Kind::Module, STDLIB_NAME);
1618+
return makeAssociatedType(stdlib);
1619+
}
15921620
if (Mangled.nextIf('d')) {
15931621
Node::IndexType depth, index;
15941622
if (!demangleIndex(depth))

lib/Basic/Remangle.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ bool Remangler::trySubstitution(Node *node, SubstitutionEntry &entry) {
351351
SUCCESS_IF_IS(node->getChild(1)->getText(), EXPECTED, SUBSTITUTION)
352352

353353
case Node::Kind::Module:
354-
SUCCESS_IF_TEXT_IS(STDLIB_NAME, "Ss");
354+
SUCCESS_IF_TEXT_IS(STDLIB_NAME, "s");
355355
SUCCESS_IF_TEXT_IS(MANGLING_MODULE_OBJC, "So");
356356
SUCCESS_IF_TEXT_IS(MANGLING_MODULE_C, "SC");
357357
break;
@@ -734,7 +734,7 @@ void Remangler::mangleVariable(Node *node, EntityContext &ctx) {
734734
}
735735

736736
void Remangler::mangleSubscript(Node *node, EntityContext &ctx) {
737-
mangleNamedAndTypedEntity(node, 's', "", ctx);
737+
mangleNamedAndTypedEntity(node, 'i', "", ctx);
738738
}
739739

740740
void Remangler::mangleInitializer(Node *node, EntityContext &ctx) {

lib/SILAnalysis/ARC/ARCAnalysis.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ mayGuaranteedUseValue(SILInstruction *User, SILValue Ptr, AliasAnalysis *AA) {
588588

589589
static bool ignoreableApplyInstInUnreachableBlock(ApplyInst *AI) {
590590
const char *fatalName =
591-
"_TFSs18_fatalErrorMessageFTVSs12StaticStringS_S_Su_T_";
591+
"_TFs18_fatalErrorMessageFTVs12StaticStringS_S_Su_T_";
592592
auto *FRI = dyn_cast<FunctionRefInst>(AI->getCallee());
593593

594594
// We use endswith here since if we specialize fatal error we will always

lib/SILAnalysis/CFG.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static bool isSafeNonExitTerminator(TermInst *TI) {
3636

3737
static bool isTrapNoReturnFunction(ApplyInst *AI) {
3838
const char *fatalName =
39-
"_TFSs18_fatalErrorMessageFTVSs12StaticStringS_S_Su_T_";
39+
"_TFs18_fatalErrorMessageFTVs12StaticStringS_S_Su_T_";
4040
auto *FRI = dyn_cast<FunctionRefInst>(AI->getCallee());
4141

4242
// We use endswith here since if we specialize fatal error we will always

lib/SwiftDemangle/MangleHack.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ _swift_mangleSimpleClass(const char *module, const char *class_) {
2929
size_t classLength = strlen(class_);
3030
char *value = nullptr;
3131
if (strcmp(module, swift::STDLIB_NAME) == 0) {
32-
int result = asprintf(&value, "_TtCSs%zu%s", classLength, class_);
32+
int result = asprintf(&value, "_TtCs%zu%s", classLength, class_);
3333
assert(result > 0);
3434
(void)result;
3535
} else {
@@ -48,7 +48,7 @@ _swift_mangleSimpleProtocol(const char *module, const char *protocol) {
4848
size_t protocolLength = strlen(protocol);
4949
char *value = nullptr;
5050
if (strcmp(module, swift::STDLIB_NAME) == 0) {
51-
int result = asprintf(&value, "_TtPSs%zu%s_", protocolLength, protocol);
51+
int result = asprintf(&value, "_TtPs%zu%s_", protocolLength, protocol);
5252
assert(result > 0);
5353
(void)result;
5454
} else {

stdlib/public/runtime/Casting.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -1401,10 +1401,10 @@ static bool _dynamicCastUnknownClassIndirect(OpaqueValue *dest,
14011401
}
14021402

14031403
#if SWIFT_OBJC_INTEROP
1404-
extern "C" const ProtocolDescriptor _TMpSs9ErrorType;
1404+
extern "C" const ProtocolDescriptor _TMps9ErrorType;
14051405

14061406
static const WitnessTable *findErrorTypeWitness(const Metadata *srcType) {
1407-
return swift_conformsToProtocol(srcType, &_TMpSs9ErrorType);
1407+
return swift_conformsToProtocol(srcType, &_TMps9ErrorType);
14081408
}
14091409

14101410
static const Metadata *getNSErrorTypeMetadata() {
@@ -2659,12 +2659,12 @@ swift::swift_conformsToProtocol(const Metadata *type,
26592659
// The return type is incorrect. It is only important that it is
26602660
// passed using 'sret'.
26612661
extern "C" OpaqueExistentialContainer
2662-
_TFSs24_injectValueIntoOptionalU__FQ_GSqQ__(OpaqueValue *value,
2662+
_TFs24_injectValueIntoOptionalU__FQ_GSqQ__(OpaqueValue *value,
26632663
const Metadata *T);
26642664
// The return type is incorrect. It is only important that it is
26652665
// passed using 'sret'.
26662666
extern "C" OpaqueExistentialContainer
2667-
_TFSs26_injectNothingIntoOptionalU__FT_GSqQ__(const Metadata *T);
2667+
_TFs26_injectNothingIntoOptionalU__FT_GSqQ__(const Metadata *T);
26682668

26692669
static inline bool swift_isClassOrObjCExistentialImpl(const Metadata *T) {
26702670
auto kind = T->getKind();
@@ -2726,7 +2726,7 @@ struct _ObjectiveCBridgeableWitnessTable {
27262726

27272727
} // unnamed namespace
27282728

2729-
extern "C" const ProtocolDescriptor _TMpSs21_ObjectiveCBridgeable;
2729+
extern "C" const ProtocolDescriptor _TMps21_ObjectiveCBridgeable;
27302730

27312731
/// Dynamic cast from a value type that conforms to the _ObjectiveCBridgeable
27322732
/// protocol to a class type, first by bridging the value to its Objective-C
@@ -2906,11 +2906,11 @@ static bool _dynamicCastClassToValueViaObjCBridgeable(
29062906
//===----------------------------------------------------------------------===//
29072907

29082908
extern "C" const _ObjectiveCBridgeableWitnessTable
2909-
_TWPVSs19_BridgeableMetatypeSs21_ObjectiveCBridgeableSs;
2909+
_TWPVs19_BridgeableMetatypes21_ObjectiveCBridgeables;
29102910

29112911
static const _ObjectiveCBridgeableWitnessTable *
29122912
findBridgeWitness(const Metadata *T) {
2913-
auto w = swift_conformsToProtocol(T, &_TMpSs21_ObjectiveCBridgeable);
2913+
auto w = swift_conformsToProtocol(T, &_TMps21_ObjectiveCBridgeable);
29142914
if (LLVM_LIKELY(w))
29152915
return reinterpret_cast<const _ObjectiveCBridgeableWitnessTable *>(w);
29162916
// Class and ObjC existential metatypes can be bridged, but metatypes can't
@@ -2920,14 +2920,14 @@ findBridgeWitness(const Metadata *T) {
29202920
case MetadataKind::Metatype: {
29212921
auto metaTy = static_cast<const MetatypeMetadata *>(T);
29222922
if (metaTy->InstanceType->isAnyClass())
2923-
return &_TWPVSs19_BridgeableMetatypeSs21_ObjectiveCBridgeableSs;
2923+
return &_TWPVs19_BridgeableMetatypes21_ObjectiveCBridgeables;
29242924
break;
29252925
}
29262926
case MetadataKind::ExistentialMetatype: {
29272927
auto existentialMetaTy =
29282928
static_cast<const ExistentialMetatypeMetadata *>(T);
29292929
if (existentialMetaTy->isObjC())
2930-
return &_TWPVSs19_BridgeableMetatypeSs21_ObjectiveCBridgeableSs;
2930+
return &_TWPVs19_BridgeableMetatypes21_ObjectiveCBridgeables;
29312931
break;
29322932
}
29332933

stdlib/public/runtime/ErrorObject.mm

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ static Class getSwiftNativeNSErrorClass() {
171171
// Swift source.
172172

173173
static auto TheWitnessTable = dlsym(RTLD_DEFAULT,
174-
"_TWPCSo7CFErrorSs9ErrorType10Foundation");
174+
"_TWPCSo7CFErrors9ErrorType10Foundation");
175175
assert(TheWitnessTable &&
176176
"Foundation overlay not loaded, or CFError: ErrorType conformance "
177177
"not available");

stdlib/public/runtime/GlobalObjects.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
namespace swift {
2222

2323
// _direct type metadata for Swift._EmptyArrayStorage
24-
extern "C" ClassMetadata _TMdCSs18_EmptyArrayStorage;
24+
extern "C" ClassMetadata _TMdCs18_EmptyArrayStorage;
2525

2626
extern "C" _SwiftEmptyArrayStorage _swiftEmptyArrayStorage = {
2727
// HeapObject header;
2828
{
29-
&_TMdCSs18_EmptyArrayStorage, // is-a pointer
29+
&_TMdCs18_EmptyArrayStorage, // is-a pointer
3030
},
3131

3232
// _SwiftArrayBodyStorage body;

0 commit comments

Comments
 (0)