Commit Graph

58 Commits

Author SHA1 Message Date
Slava Pestov
6af7f95a5a We don't need to plumb a resilience expansion through mangling, NFC
I'm going to be adding deployment target info ResilienceExpansion
soon so removing unnecessary usages helps reduce the amount of
work there.
2016-01-07 08:15:26 -08:00
Nadav Rotem
695a78ca6f Remove an include file that snuck in by mistake.
The world is not ready for this yet.
2016-01-06 12:59:49 -08:00
Nadav Rotem
f182d39004 [Mangler] Move the body of the 'finalize' methods into the cpp files. 2016-01-06 12:06:45 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
practicalswift
32a32e6446 Fix typo introduced during the last 24h :-) 2015-12-30 00:14:11 +01:00
Nadav Rotem
77080e4ca2 [Mangler] Add methods for encoding already-mangled symbols.
This commit is related to the work of encoding mangled names more efficiently by
compressing them. This commit adds two new methods to the mangler that allows it
to identify requests to mangle strings that are already mangled.  Right now the
mangler does not do anything with this information.

This API is needed in all of the places in the compiler where we compose mangled
names. For example, when the optimizer is cloning functions it adds a prefix to
an existing name.

I verified that this change is correct by adding a compress/decompress methods
that add a prefix to the mangled names with assertions to catch compression of
already compressed symbols or decompression of non-compressed named.  I plan to
commit the verification code together with the compression implementation later
on.
2015-12-29 14:21:36 -08:00
Nadav Rotem
b76a58af40 [Mangler] Simplify the mangling into a stream. NFC.
This is a tiny cleanup that makes it easier to add the compression/decompression layers.
2015-12-29 14:21:36 -08:00
Nadav Rotem
07d4558c1c [Mangler] Change the Swift mangler into a symbol builder.
This commit changes the Swift mangler from a utility that writes tokens into a
stream into a name-builder that has two phases: "building a name", and "ready".
This clear separation is needed for the implementation of the compression layer.

Users of the mangler can continue to build the name using the mangleXXX methods,
but to access the results the users of the mangler need to call the finalize()
method. This method can write the result into a stream, like before, or return
an std::string.
2015-12-25 21:40:25 -08:00
Nadav Rotem
6fa6ca563e [Mangler] Rename some of the mangler methods. NFC. 2015-12-24 14:35:33 -08:00
Nadav Rotem
0d037ad917 [Mangler] pass the APInt as const-ref 2015-12-23 00:19:09 -08:00
Nadav Rotem
be505d255b [Mangler] Split the SIL Mangler from the AST mangler.
This commit adds a new interface that removes the need of the SIL mangler from
using the internal buffer of the AST mangler.
2015-12-22 16:37:57 -08:00
Joe Groff
2368ce774b Remove self types from mangling by default.
And include some supplementary mangling changes:

- Give the first generic param (depth=0, index=0) a single character mangling. Even after removing the self type from method declaration types, 'Self' still shows up very frequently in protocol requirement signatures.
- Fix the mangling of generic parameter counts to elide the count when there's only one parameter at the starting depth of the mangling.

Together these carve another 154KB out of a debug standard library. There's some awkwardness in demangled strings that I'll clean up in subsequent commits; since decl types now only mangle the number of generic params at their own depth, it's context-dependent what depths those represent, which we get wrong now. Currying markers are also wrong, but since free function currying is going away, we can mangle the partial application thunks in different ways.

Swift SVN r32896
2015-10-26 22:05:20 +00:00
Joe Groff
7e119d0d53 Optimize the mangling of associated types in generic signatures.
Canonical dependent member types are always based from a generic parameter, so we can use a more optimal mangling that assumes this. We can also introduce substitutions for AssociatedTypeDecls, and when a generic parameter in a signature is constrained by a single protocol, we can leave that protocol qualification out of the unsubstituted associated type mangling. These optimizations together shrink the standard library by 117KB, and bring the length of the longest Swift symbol in the stdlib down from 578 to 334 characters, shorter than the longest C++ symbol in the stdlib.

Swift SVN r32786
2015-10-20 17:52:07 +00:00
Joe Groff
42c71b7972 Don't mangle directness into type metadata symbols.
Anywhere we can't directly address type metadata in Swift, we've found we need a function call. Directness isn't useful here.

Swift SVN r32626
2015-10-12 17:22:40 +00:00
Joe Groff
436ff435ae Mangling: Conditionally eliminate self types and requirements from method symbol manglings.
When -disable-self-type-mangling is set, mangle the decl type of methods without the encoding of the self type or any generic requirements from the context, since these are implied by the context mangling and aren't needed to uniquely identify the method. Doing this saves 150KB in the standard library. Before:

$ ls -l lib/swift/macosx/libswiftCore.dylib 
-rwxr-xr-x  1 jgroff  staff  9358140 Oct  1 11:14 lib/swift/macosx/libswiftCore.dylib
$ nm lib/swift/macosx/libswiftCore.dylib | wc -c
 1475338

After:

$ ls -l lib/swift/macosx/libswiftCore.dylib 
-rwxr-xr-x  1 jgroff  staff  9204428 Oct  1 13:59 lib/swift/macosx/libswiftCore.dylib
$ nm lib/swift/macosx/libswiftCore.dylib | wc -c
 1421702

This is hidden behind a flag because it doesn't yet have de/remangling support, and because we'll need to make sure the debugger and other clients can recover declaration types reasonably without help from the mangling.

Swift SVN r32399
2015-10-02 03:23:26 +00:00
Joe Groff
43d620c7e0 IRGen: Export direct metadata symbols at the address point of the metadata object.
This is more resilient, since we want to be able to add more information behind the address point of type objects. The start of the metadata object is now an internal "full metadata" symbol.

Note that we can't do this for known opaque metadata from the C++ runtime, since clang doesn't have a good way to emit offset symbol aliases, so for non-nominal metadata objects we still emit an adjustment inline. We also aren't able to generate references to aliases within the same module due to an MC bug with alias refs on i386 and armv7 (rdar://problem/22450593).

Swift SVN r31523
2015-08-27 05:18:38 +00:00
Joe Groff
f705c561e3 Revert "IRGen: Export direct metadata symbols at the address point of the metadata object."
This reverts commit r31515. It causes an LLVM error on the release bots.

Swift SVN r31516
2015-08-27 01:44:56 +00:00
Joe Groff
8e2ce60f5b IRGen: Export direct metadata symbols at the address point of the metadata object.
This is more resilient, since we want to be able to add more information behind the address point of type objects, and also makes IR a lot less cluttered. The start of the metadata object is now an internal "full metadata" symbol.

Note that we can't do this for known opaque metadata from the C++ runtime, since clang doesn't have a good way to emit offset symbol aliases, so for non-nominal metadata objects we still emit an adjustment inline.

Swift SVN r31515
2015-08-27 01:34:22 +00:00
Xi Ge
85367420bd [CodeCompletion] Adjust archetype depth so that mangler is always consistent with type checker. rdar://21435993
Swift SVN r30709
2015-07-28 00:02:44 +00:00
Joe Groff
ab4e578aeb AST: More robustly grab a Module for ArchetypeBuilder to canonicalize generic signatures.
Use the Module from the associated decl instead of using getStdlibModule, which sometimes produces null for -parse-stdlib tests, and is probably wrong.

Swift SVN r28380
2015-05-09 22:20:47 +00:00
Doug Gregor
b8995b0aa3 Transform the Module class into ModuleDecl.
Modules occupy a weird space in the AST now: they can be treated like
types (Swift.Int), which is captured by ModuleType. They can be
treated like values for disambiguation (Swift.print), which is
captured by ModuleExpr. And we jump through hoops in various places to
store "either a module or a decl".

Start cleaning this up by transforming Module into ModuleDecl, a
TypeDecl that's implicitly created to describe a module. Subsequent
changes will start folding away the special cases (ModuleExpr ->
DeclRefExpr, name lookup results stop having a separate Module case,
etc.).

Note that the Module -> ModuleDecl typedef is there to limit the
changes needed. Much of this patch is actually dealing with the fact
that Module used to have Ctx and Name public members that now need to
be accessed via getASTContext() and getName(), respectively.

Swift SVN r28284
2015-05-07 21:10:50 +00:00
John McCall
9e24340567 The SILModule has a lookup table for global variables,
use it instead of scanning at O(n).

Also, put mangling code in the mangler where it belongs.

NFC.

Swift SVN r26974
2015-04-04 08:41:23 +00:00
Jordan Rose
c9eeed3e2d Remove staging option -enable-private-discriminators.
Private discriminators for everybody!

Swift SVN r25997
2015-03-11 23:07:44 +00:00
David Farler
51f8070abe Serialize local types
Local type declarations are saved in the source file during parsing,
now serialized as decls. Some of these may be defined in DeclContexts
which aren't Decls and previously weren't serialized. Create four new
record kinds:

* PatternBindingInitializer
* DefaultArgumentInitializer
* AbstractClosureExpr
* TopLevelCodeDecl

These new records are used to only preserve enough information for
remangling in the debugger, and parental context relationships.

Finally, provide a lookup API in the module to search by mangled name.
With the new remangling API, the debugging lifecycle for local types
should be complete.

The extra LOCAL_CONTEXT record will compressed back down in a
subsequent patch.

Swift SVN r24739
2015-01-27 01:49:54 +00:00
John McCall
dc4431ebff Split addressors into unsafe, owning, and pinning variants.
Change all the existing addressors to the unsafe variant.

Update the addressor mangling to include the variant.

The addressor and mutable-addressor may be any of the
variants, independent of the choice for the other.

SILGen and code synthesis for the new variants is still
untested.

Swift SVN r24387
2015-01-13 03:09:16 +00:00
Michael Gottesman
185d9aaafd [mangle] Add support for mangling constant propagated specializations and wire CapturePropagation to use it.
I also fixed a few bugs in the mangling that this exposed.

Swift SVN r23858
2014-12-11 03:22:07 +00:00
Michael Gottesman
4d48d2aaae [mangle] Add initial code for SIL specializations manglings and refactor Generic Specialization mangling code to there from the pass itself.
This is apart of creating the infrastructure for creating special manglings for
all of the passes that we specialize. The main motiviations for this
infrastructure is:

1. Create an easy method with examples on how to create these manglings.
2. Support multiple specializations. This is important once we allow for partial
specialization and can already occur if we perform function signature
optimizations on specialized functions.

The overall scheme is as follows:

_TTS<MANGLINGINFO>__<FUNCNAME>

Thus if we specialize twice, the first specialization will just be treated as
the function name for the second specialization.

<MANGLINGINFO> is defined as:

_<SPECIALIZATIONKINDID>_<SPECIALIZATIONUNIQUEINFO>

Where specialization kind is an enum that specifies the specific sort of
specialization we are performing and specialization unique info is enough
information to ensure that the identity of the function is appropriately
preserved.

Swift SVN r23801
2014-12-09 02:53:05 +00:00
Adrian Prantl
dd4032ee41 Modify the Mangler to recursively deal with sugared types.
Unless DWARFmangling is set all methods still expect a CanonicalType.

Fixes <rdar://problem/17042576> [6A214t] Debug information has wrong type for dispatch queue

Swift SVN r23226
2014-11-11 01:32:12 +00:00
Manman Ren
276af26e12 [Global Opt] adds GlobalGetter as one kind of SILDeclRef.
Also handles mangling, demangling, printing and parsing.

This is the first patch to use global getter for "let" globals.

rdar://16614767


Swift SVN r23106
2014-11-05 00:40:32 +00:00
Jordan Rose
42011d98c8 Constify the mangler. No functionality change.
Swift SVN r22924
2014-10-24 22:22:54 +00:00
Dave Abrahams
90a34d86fa Mangle names of globalinit_{token,func} like other private entities.
This allows making global addressors fragile (They use globalinit_{token,func} for initialization of globals).

It has no noticable performance impact on our benchmarks, but it removes an ugly hack which explicitly
prevented addressors from being fragile.

Swift SVN r22812
2014-10-17 06:02:22 +00:00
Dave Abrahams
e4588e4896 Revert "Mangle names of globalinit_{token,func} like other private entities."
This reverts r22795, because it broke my RelWithDebInfo,
SWIFT_OPTIMIZED=NO build.

Swift SVN r22802
2014-10-16 21:12:11 +00:00
Erik Eckstein
b5cfd00f74 Mangle names of globalinit_{token,func} like other private entities.
This allows making global addressors fragile (They use globalinit_{token,func} for initialization of globals).

It has no noticable performance impact on our benchmarks, but it removes an ugly hack which explicitly
prevented addressors from being fragile.



Swift SVN r22795
2014-10-16 08:24:18 +00:00
Jordan Rose
09664184be Move mangling logic for type metadata and field offset into Mangler.
...so that the debugger can use it too. We may end up needing to move more
things from LinkEntity to Mangler in this way, but this is the baseline for
what's needed to properly display private types.

The suffix "Full" here is intended to represent that the Swift prefix "_T"
is included already; if there's a better name for this I'd be glad to change
it.

rdar://problem/18353463

Swift SVN r22031
2014-09-17 19:27:11 +00:00
Jordan Rose
4b94208eca Use extension mangling for all members of cross-module extensions.
If an entity is declared in an extension, and the extension is declared in a
different module from the type it extends, we include the extension's module
name in the mangling in addition to the extended type. We were already doing
this for functions and subscripts because of rdar://problem/18057875, but
this extends it to all declarations.

This is necessary to handle
(1) debugging private members of cross-module extensions
(2) the same member being declared in two different modules, each of which
    extends a type in a third module

rdar://problem/14884749

Swift SVN r21846
2014-09-10 19:10:48 +00:00
Jordan Rose
adc25c8b9f Staging: Guard private discriminators under -enable-primary-discriminators.
...rather than let this series of out-of-tree commits get any bigger.

Swift SVN r21601
2014-08-30 00:17:23 +00:00
Manman Ren
2cb20d4e62 [Mangler] mangle the module where an extension is defined if necessary.
If a method is defined within an extension of a class or struct that is
defined in a different module, we mangle the module where the extension is
defined.

If we define function f in module A, and redefine it again in an extension in
module B, we use different mangling to prevent linking in the wrong
SILFunction.

rdar://18057875


Swift SVN r21488
2014-08-27 19:57:21 +00:00
Greg Parker
c5b71e9e42 Don't use punycode when mangling names for Objective-C metadata.
Swift SVN r20886
2014-08-01 05:19:28 +00:00
Doug Gregor
18c6f52b2a When mangling a type within an extension, pass down the extension’s generic parameters.
Swift SVN r20854
2014-07-31 21:59:27 +00:00
Argyrios Kyrtzidis
2c88bb3f59 [AST] Modify mangleObjCRuntimeName to allow getting the ObjC runtime name of a class or protocol
without needing a fully typechecked AST.

Part of rdar://16521245

Swift SVN r16503
2014-04-18 07:07:11 +00:00
Argyrios Kyrtzidis
bb4b57c053 [IDE] Introduce ide::printDeclUSR() which uses the mangler to provide a USR for a swift symbol.
Swift SVN r14279
2014-02-23 06:54:48 +00:00
John McCall
c7da19725a Allow the mangler to mangle accessor kinds and make
protocol conformance thunk generation handle accessors
correctly.

Swift SVN r14050
2014-02-18 21:53:10 +00:00
Joe Groff
30a3a9a0a0 SILGen: Hand down context generic params for reabstraction thunks independent from their type.
Pass the context generic params for a reabstraction thunk down to getOrCreateReabstractionThunk from the enclosing function, where it can either use them to define a new thunk or ignore them if it has an equivalent thunk already. Tweak the mangling of reabstraction thunks to use the generic signature with decontextualized "from" and "to" types instead of the generic param list.

Swift SVN r13763
2014-02-10 23:37:11 +00:00
Joe Groff
ab82fa1207 Mangle SILFunctionTypes from their interface types.
Make up manglings for generic signatures and their dependent GenericTypeParamTypes and DependentMemberTypes, as well as the generic signature of a GenericFunctionType or SILFunctionType. Use these to build the mangling for a SILFunctionType from its interface types.

Swift SVN r13537
2014-02-06 01:36:49 +00:00
Chris Lattner
d407bc8fc4 Teach the parser to add the didSet/willSet functions to the enclosing
type, so we emit them.  Add mangler (and demangler) support for these.
Enhance our testcase to check to make sure that stores within these
specifiers are direct, they don't cause recursive infinite loops.

John, I picked w/W for the mangling letters, let me know if this is ok.


Swift SVN r13050
2014-01-28 05:15:56 +00:00
John McCall
a1b469ed2f ExplosionKind -> ResilienceExpansion. NFC.
Swift SVN r12364
2014-01-16 00:25:29 +00:00
Doug Gregor
fc7dfb2fae Start emitting .cxx_construct methods for Objective-C-derived classes.
When we're using Objective-C's memory allocation, emit .cxx_construct
methods whenever we have instance variables with in-class
initializers. Presently, these methods are just empty stubs.

Swift SVN r12211
2014-01-12 04:31:52 +00:00
Doug Gregor
3524a79fa0 Emit .cxx_destruct for destruction of ivars in Objective-C-derived classes.
The Objective-C runtime executes the .cxx_destruct method after the
last -dealloc has executed when destroying an object, allowing the
instance variables to remain live even after the subclass's
destructor/-dealloc has executed, which is important for memory
safety. This fixes the majority of <rdar://problem/15136592>.

Note that IRGenModule::getAddrOfIVarDestroyer() contains  an egregious
hack to find the ivar destructor SIL function via a linear
search. We need a better way to find SIL functions that we know exist,
because LinkEntity does not suffice.

Swift SVN r12206
2014-01-12 00:17:42 +00:00
Doug Gregor
0ed1e6d7f5 Switch mangleDestructorEntity() tover to accepting a DestructorDecl. NFC
Swift SVN r12161
2014-01-10 23:11:06 +00:00
Adrian Prantl
946dc5678b Debug info: Provide an in interface for LLDB to mangle types and refactor
some code in IRGenDebugInfo along the way.
This is WIP for rdar://problem/15498877.

Swift SVN r12146
2014-01-10 22:35:53 +00:00