Commit Graph

81 Commits

Author SHA1 Message Date
Erik Eckstein
8404c73dba Demangler: support stack allocation for the Demangler's allocator
The demangler can be initialized with a preallocated memory on the stack. Only in case of an overflow, the bump pointer allocator mallocs new memory.
Also, support that a new instance of a demangler can "borrow" the free memory from an existing demangler. This is useful because in the runtime the demangler is invoked recursively. With this feature, all the nested demanglers can share a single stack allocated space.
2019-02-15 09:29:49 -08:00
Erik Eckstein
b04ebcfacf Demangler: improve debug logging.
Log allocated memory and indent according to the nesting level
2019-02-15 09:29:49 -08:00
Erik Eckstein
58f2d373d4 Demangler: Reduce sizeof(Node) from 48 bytes to 24 bytes
This is done by disallowing nodes with children to also have index or text payloads.
In some cases those payloads were not needed anyway, because the information can be derived later.
In other cases the fix was to insert an additional child node with the index/text payload.

Also, implement single or double children as "inline" children, which avoids needing a separate node vector for children.

All this reduces the needed size for node trees by over 2x.
2019-02-15 09:29:49 -08:00
Doug Gregor
21e5a7e8a2 [Metadata reader] Save/restore symbolic reference resolver
… rather than clearing it out completely. This is better hygiene, although it
doesn’t matter right now.
2019-01-27 21:58:09 -08:00
Jordan Rose
0ca4d557f4 [Mangling] Split up protocol-conformance-ref further
New(er) grammar:

    // same module as conforming type, or non-unique
    protocol-conformance-ref ::= protocol 'HP'
    // same module as protocol
    protocol-conformance-ref ::= protocol 'Hp'
    // retroactive
    protocol-conformance-ref ::= protocol module

We don't make use of this distinction anywhere yet, but we could in
the future.
2018-12-20 14:00:06 -08:00
Doug Gregor
510b64fcd5 [Mangling] Give protocol-conformance-ref an operator.
Due to some unfortunate refactoring, protocol-conformance-ref is a
nonterminal in the mangling grammar that doesn't have its own
operator:

```
protocol-conformance-ref ::= protocol module?
```

Both "module" and "protocol" can be an "identifier", which introduces
a mangling collision. Address the mangling collision by using the
operator "HP".

Fixes rdar://problem/46735592.
2018-12-17 18:11:47 -08:00
Doug Gregor
1efe2bca21 [Mangling] Introduce mangling for protocol conformances.
Introduce complete mangling for references to protocol conformances:

* Mangle requirements of conditional conformances when present.
* Mangle conformance access paths for generic environment-dependent
  conformances.
* Abstract protocol conformance references so we can introduce
  symbolic references for them.
2018-11-02 22:35:34 -07:00
Doug Gregor
5b41ac16db [ABI] Introduce indirect symbolic references to context descriptors.
Extending the mangling of symbolic references to also include indirect
symbolic references. This allows mangled names to refer to context
descriptors (both type and protocol) not in the current source file.

For now, only permit indirect symbolic references within the current module,
because remote mirrors (among other things) is unable to handle relocations.

Co-authored-by: Joe Groff <jgroff@apple.com>
2018-10-23 16:06:42 -07:00
Robert Widmann
14d770e551 [NFC] Drop unused pending substitutions vector 2018-09-05 11:47:38 -04:00
Slava Pestov
330be4a38e SILOptimizer: Remove 'unique ID' from FSO mangling 2018-07-11 15:29:45 -07:00
Sho Ikeda
17b833a831 [gardening][Demangling] Replace typedef with using 2018-03-29 13:39:10 +09:00
Joe Groff
953dddd5d3 IRGen/Runtime: Allow mangled type refs to embed "symbolic references" to type context descriptors.
This makes resolving mangled names to nominal types in the same module more efficient, and for eventual secrecy improvements, also allows types in the same module to be referenced from mangled typerefs without encoding any source-level name information about them.
2018-02-10 10:43:47 -08:00
Doug Gregor
28c489c16d [ABI] Mangle retroactive conformances as part of bound generic types.
A "retroactive" protocol conformance is a conformance that is provided
by a module that is neither the module that defines the protocol nor
the module that defines the conforming type. It is possible for such
conformances to conflict at runtime, if defined in different modules
that were not both visible to the compiler at the same time.

When mangling a bound generic type, also mangle retroactive protocol
conformances that were needed to satisfy the generic requirements of
the generic type. This prevents name collisions between (e.g.) types
formed using retroactive conformances from different modules. The
impact on the size of the mangling is expected to be relatively small,
because most conformances are not retroactive.

Fixes the ABI part of rdar://problem/14375889.
2018-01-31 09:53:38 -08:00
Joe Groff
a7a3b17597 Replace nominal type descriptors with a hierarchy of context descriptors.
This new format more efficiently represents existing information, while
more accurately encoding important information about nested generic
contexts with same-type and layout constraints that need to be evaluated
at runtime. It's also designed with an eye to forward- and
backward-compatible expansion for ABI stability with future Swift
versions.
2018-01-29 16:19:25 -08:00
Jordan Rose
38e2cfe1e2 Mangle imported declarations using their C names.
This makes them consistent no matter what shenanigans are pulled by
the importer, particularly NS_ENUM vs. NS_OPTIONS and NS_SWIFT_NAME.

The 'NSErrorDomain' API note /nearly/ works with this, but the
synthesized error struct is still mangled as a Swift declaration,
which means it's not rename-stable. See follow-up commits.

The main place where this still falls down is NS_STRING_ENUM: when
this is applied, a typedef is imported as a unique struct, but without
it it's just a typealias for the underlying type. There's also still a
problem with synthesized conformances, which have a module mangled
into the witness table symbol even though that symbol is linkonce_odr.

rdar://problem/31616162
2018-01-09 17:55:24 -08:00
Pavel Yaskevich
25f59f06f2 [Mangler] Support functions with old parameter label mangling scheme
Make function mangling backward compatible based on the prefix
of the mangled symbol, which is used to distinguish between names
with old/new parameter label mangling schemes.

Resolves: rdar://problem/36357120
2018-01-08 18:04:07 -08:00
Erik Eckstein
cd3d50a5d9 ABI: Change the mangling prefix from _T0 to $S 2018-01-06 13:55:59 -08:00
Pavel Yaskevich
34b83306bf [Demangler] Teach node printer to use LabelList for entities 2017-12-18 15:44:24 -08:00
Pavel Yaskevich
10c385d1b7 [Mangling/ABI] Add special LabelList to store parameter labels
Instead of mangling parameter labels as part of the function type
move them to the end of the function name instead, to match the
language semantics.
2017-12-18 15:44:24 -08:00
Alex Hoppen
1c7e289b96 [Mangling] Adjust subscript mangling to not include "subscript"
Change the mangling of accessors to have a variable or subscript node
as their only child node, while subscript nodes no longer contain a decl
name.
2017-09-10 19:44:07 +02:00
Arnold Schwaighofer
48bd2bba76 Mangling changes for outlined Objective-C method calls
rdar://33387700
2017-09-06 08:37:30 -07:00
Erik Eckstein
ecd177fa17 Demangler: handle suffixes in the form '.<n>'.
Demangle such suffixes as "unmangled suffix"
IRGen still uses '.<n>' to disambiguate partial apply thunks and outlined copy functions.

rdar://problem/32934962
2017-06-26 15:19:20 -07:00
Erik Eckstein
6a478caf7d demangling: Drop the support of "unmangled suffix"
Either the demangling completely succeeds or it fails. Don't demangle to something like: [...] with unmangled suffix "..."

This avoids getting really stupid demangled names for symbols which are actually not swift symbols.
2017-05-24 17:00:20 -07:00
practicalswift
7eb7d5b109 [gardening] Fix 100 typos. 2017-04-18 17:01:42 +02:00
Jordan Rose
2d84981fc2 Improve the mangling of typealiases.
- Allow them to use substitutions.
- Consistently use 'a' as a mangling operator.
- For generic typealiases, include the alias as context for any generic
  parameters.

Typealiases don't show up in symbol names, which always refer to
canonical types, but they are mangled for debug info and for USRs
(unique identifiers used by SourceKit), so it's good to get this
right.
2017-04-17 11:31:15 -07:00
Slava Pestov
0d0dc207c0 AST: Mangling for primitive AnyObject
A protocol composition with an explicit 'AnyObject' member is
now mangled as <protocol list> 'Xl'. For subclass existentials,
I changed the mangling from <protocol list> <class> 'XE' to
<protocol list> <class> 'Xl'.

Not used for anything just yet.
2017-04-13 21:17:07 -07:00
Erik Eckstein
7dd2828d27 Demangler: add a debug dump function to print the internal state of the demangler.
Useful for debugging the demangler.
2017-04-06 16:07:13 -07:00
practicalswift
19558c9ed7 [gardening] Fix typo 2017-04-03 09:21:09 +02:00
practicalswift
00ba5dc248 [gardening] Fix typos 2017-04-02 16:23:45 +02:00
Erik Eckstein
4d36b7f42e Remove an unused function in the old demangler 2017-03-17 16:10:36 -07:00
Erik Eckstein
5e80555c9b demangler: put the demangler into a separate library
Previously it was part of swiftBasic.

The demangler library does not depend on llvm (except some header-only utilities like StringRef). Putting it into its own library makes sure that no llvm stuff will be linked into clients which use the demangler library.

This change also contains other refactoring, like moving demangler code into different files. This makes it easier to remove the old demangler from the runtime library when we switch to the new symbol mangling.

Also in this commit: remove some unused API functions from the demangler Context.

fixes rdar://problem/30503344
2017-03-09 13:42:43 -08:00