Commit Graph

402 Commits

Author SHA1 Message Date
Erik Eckstein
9e9748565a demangler: fix another crash caused by a malformed symbol
rdar://problem/39995560
2018-05-08 09:46:00 -07:00
Erik Eckstein
af53cc3fa0 demangler: don't crash for malformed builtin type sizes
rdar://problem/39995700
2018-05-07 12:31:39 -07:00
Michael Gottesman
afc98b34e9 [func-sig-opts] Add a new mangling for the guaranteed->owned transformation.
I followed the example of the owned->guaranteed transformation.

rdar://38196046
2018-04-26 16:36:41 -07:00
Joe Groff
08d5e064fb Demangler: Reserve space for more kinds of symbolic reference in the future.
Carve out the C0 control code space as symbolic reference introducers—U+0001 through U+0017 as relative symbolic references, and U+0018 through U+001F as absolute symbolic references (if we ever need them).
2018-04-05 10:20:10 -07:00
Slava Pestov
588448684b IRGen: Emit resilient witness tables 2018-03-29 14:03:58 -07:00
Slava Pestov
30a3e75fe9 IRGen: Fix dependent witness table linkage
Witness tables for conformances that require runtime instantiation
should not be public, because it is an error to directly reference
such a symbol from outside the module.

Use a different mangling for witness table patterns and give them
non-public linkage.
2018-03-28 20:58:14 -07:00
Slava Pestov
e7ac4f5af2 IRGen: Mangled name for protocol requirement array 2018-03-27 16:24:19 -07:00
Slava Pestov
c31620d302 IRGen: Mangle generic signature and type for outlined thunks 2018-03-26 19:39:26 -07:00
Slava Pestov
8d6b60f8f5 Mangling: Use WO namespace for outlined value operations to declutter W namespace 2018-03-26 19:39:25 -07:00
Erik Eckstein
f0ef4007b6 Demangler: support the final mangling prefix _$s
rdar://problem/37681432
2018-03-24 19:28:38 -07:00
swift-ci
29788f6245 Merge pull request #14963 from kitasuke/replace-of-builtin-string-with-constant 2018-03-24 18:56:17 -07:00
Arnold Schwaighofer
ce7608a7ce IRGen: Make resilient enum's tag indices resilient
This allows reordering enum cases resiliently.

rdar://24057946
2018-03-20 13:19:56 -07:00
Joe Groff
53792aa64e IRGen: Make outlined enum copy/destroy lazier and better mangled.
Emit enum copy/destroy methods only when codegen demands them; they previously got emitted immediately when TypeInfo is instantiated, which led to many functions getting emitted that were never used. Also, make it so that the symbol name includes the full type of the enum instance the outlined functions operate on, so it's more obvious what they'e being used for and they can be ODRed across translation units.
2018-03-11 11:04:41 -07:00
Sho Ikeda
74ba135008 Merge pull request #15040 from ikesyo/gardening-not-empty
[gardening] Use `!empty()` over `size() > 0`
2018-03-08 18:47:12 +09:00
Huon Wilson
e307e54098 [AST] Explicitly track things marked __owned. 2018-03-08 12:36:24 +11:00
Sho Ikeda
cea6c03eb2 [gardening] Use !empty() over size() > 0 2018-03-08 09:21:09 +09:00
John McCall
9a4540e84d Split the instantiation function into two phases.
The allocation phase is guaranteed to succeed and just puts enough
of the structure together to make things work.

The completion phase does any component metadata lookups that are
necessary (for the superclass, fields, etc.) and performs layout;
it can fail and require restart.

Next up is to support this in the runtime; then we can start the
process of making metadata accessors actually allow incomplete
metadata to be fetched.
2018-03-06 03:07:55 -05:00
Erik Eckstein
da322a26a8 demangler: fix crashes for malformed symbols 2018-03-05 14:40:19 -08:00
John McCall
dd99536d31 Move the metadata-pattern header into the type context descriptor.
This is yet another waypoint on the path towards the final
generic-metadata design.  The immediate goal is to make the
pattern a private implementation detail and to give the runtime
more visibility into the allocation and caching of generic types.
2018-02-26 12:10:24 -05:00
Joe Groff
4c2dde56a0 IRGen: Lower external key path components.
The key path pattern needs to include a reference to the external descriptor, along with hooks for lowering its type arguments and indices, if any. The runtime will need to instantiate and interpolate the external component when the key path object is instantiated.

While we're here, let's also reserve some more component header bytes for future expansion, since this is an ABI we're going to be living with for a while.
2018-02-23 19:03:15 -08:00
Joe Groff
eb316818c5 Demangler: Fill in places we need to handle symbolic references and OtherNominalTypes when demangling bound generic types. 2018-02-20 18:20:09 -08:00
Davide Italiano
fe43d0bc76 [Demangler] Add convenience functions to ask about types.
And use them in the reflection library (TypeRef). These were
private to `TypeRef.cpp` but can be moved to the demangler as
they can be of general use, and we can use them from lldb (which
has homemade versions of the functions as well). Bonus point,
it probably makes sense for these helpers to live in the demangler
anyway.

<rdar://problem/37710513>
2018-02-20 11:38:13 -08: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
Arnold Schwaighofer
d981bb1d96 Mangling: noescape functions will be trivial and no longer compatible with escape function types.
Mangle escapeness as part of the type.

Part of:
SR-5441
rdar://36116691
2018-02-06 08:51:43 -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
fdef6ef15f Merge pull request #13468 from jckarter/generic-requirement-details
Context descriptors
2018-01-30 06:49:16 -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
Huon Wilson
935c167fc4 [Demangler] Use StringRef APIs for clarity. NFC.
Also, remove the seemingly-unsafe "'const char*' always has length 4"
micro-optimization.
2018-01-30 10:12:29 +11:00
Jordan Rose
e63879dc48 [Mangling] Define "related entity" operators 'LA'...'LJ'
(and 'La'...'Lj')

Use this for the synthesized structs for error enums, as described in
the previous commit, instead of reusing the "private discriminator"
feature. I left some space in the APIs for "related entity kinds" that
are longer than a single character, but I don't actually expect to use
it any time soon. It's mostly just easier to deal with StringRef than
with a bare char.

Note that this doesn't perfectly round-trip to the old mangling; I had
it treat these nodes as private discriminators with a prefixed "$"
instead. We don't depend on that for anything, though.
2018-01-24 10:52:46 -08:00
Doug Gregor
bc866086d9 [Mangling] Add a mangling for protocol conformance descriptors. 2018-01-17 10:33:30 -08:00
Jordan Rose
4a73f0daef Merge pull request #13519 from jrose-apple/mangle-imports-using-c-name
Mangle imported declarations using their C names

rdar://problem/24688918
2018-01-10 18:12:17 -08:00
Doug Gregor
82140ca811 [Demangle] Add back isSwiftSymbol() entry point for null-terminated strings.
This particular API can be safely used with a null-terminated string,
and is used by some clients (e.g., LLDB), so add back a "const char *"
variant that safely accesses a null-terminated string.
2018-01-10 14:27:37 -08:00
swift-ci
ea489cead0 Merge pull request #13844 from DougGregor/runtime-protocol-name-lookup 2018-01-09 23:06:09 -08:00
Doug Gregor
466e77c87b [Demangler] Eliminate a few erroneous "const char *" -> StringRefs.
Likely causing the recent ASan failure.
2018-01-09 20:21:31 -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
Jordan Rose
18689fe223 [Mangling] Uniformly use "So" for imported decls.
...and repurpose "SC" for (C)lang-importer-synthesized decls, instead
of just decls that are C-like instead of ObjC-like. (See next commits.)
2018-01-09 17:55:23 -08:00
swift-ci
fc4d66d269 Merge pull request #13827 from DougGregor/type-decoder-protocol-composition 2018-01-09 15:39:45 -08:00
Doug Gregor
e28e856595 [Runtime] Use bare protocol mangling for protocol descriptors.
The mangled name of protocol descriptors was the “protocol composition”
type consisting of a single protocol, which is a little odd. Instead,
use a bare protocol reference (e.g., “6Module5ProtoP”) with the “$S”
prefer to be more in line with nominal type descriptor names while still
making it clear that this is a Swift (not an Objective-C) protocol.
2018-01-09 10:21:55 -08:00
Doug Gregor
5f2a6b82ce [Demangle] StringRef-ify entry points.
isMangledName() was passing the data() pointer to a routine that assumed
it was getting a null-terminated string. Define away this class of error
by using StringRef consistently.
2018-01-09 10:06:51 -08:00
John McCall
3c54c0edfc IRGen and basic optimizer support for coroutines. 2018-01-09 11:35:09 -05: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
e5b1c9d899 demangler: catch more cases where the demangler crashes on malformed symbols 2018-01-08 14:59:08 -08:00
Doug Gregor
613cbb4d15 [Demangler] Don’t crash on malformed inputs in popFunctionParamLabels(). 2018-01-07 23:12:35 -08:00
Pavel Yaskevich
4885fd4203 [Mangling/ABI] NFC: Fix Migrator tests to reflect label mangling changes 2017-12-18 15:45:50 -08:00
Pavel Yaskevich
6725c04bfd [Mangling/ABI] Don't produce empty labels marker for functions without parameters
If function type doesn't have any parameters, there is
no need to produce a redundant 'no labels' marker for
such case, which also saves some space in mangled name.
2017-12-18 15:44:24 -08:00
Pavel Yaskevich
34b83306bf [Demangler] Teach node printer to use LabelList for entities 2017-12-18 15:44:24 -08:00
Pavel Yaskevich
3b9b0bff2f [Demangler] Save number of parameters in ArgumentTuple node 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
Slava Pestov
4d21d127aa Mangler: Add mangling for class metadata base offset 2017-12-08 13:50:56 -08:00
Joe Shajrawi
d8289aa3ec Code size: destroy_addr outline 2017-11-17 16:10:27 -08:00