Commit Graph

100 Commits

Author SHA1 Message Date
Doug Gregor
a2b2798de2 [ABI] Eliminate the now-unused protocol requirement array.
This is a holdover from the old protocol descriptor layout, which is no
longer useful.
2018-07-24 17:33:16 -07:00
John McCall
7a4aeed570 Implement generalized accessors using yield-once coroutines.
For now, the accessors have been underscored as `_read` and `_modify`.
I'll prepare an evolution proposal for this feature which should allow
us to remove the underscores or, y'know, rename them to `purple` and
`lettuce`.

`_read` accessors do not make any effort yet to avoid copying the
value being yielded.  I'll work on it in follow-up patches.

Opaque accesses to properties and subscripts defined with `_modify`
accessors will use an inefficient `materializeForSet` pattern that
materializes the value to a temporary instead of accessing it in-place.
That will be fixed by migrating to `modify` over `materializeForSet`,
which is next up after the `read` optimizations.

SIL ownership verification doesn't pass yet for the test cases here
because of a general fault in SILGen where borrows can outlive their
borrowed value due to being cleaned up on the general cleanup stack
when the borrowed value is cleaned up on the formal-access stack.
Michael, Andy, and I discussed various ways to fix this, but it seems
clear to me that it's not in any way specific to coroutine accesses.

rdar://35399664
2018-07-23 18:59:58 -04:00
Slava Pestov
330be4a38e SILOptimizer: Remove 'unique ID' from FSO mangling 2018-07-11 15:29:45 -07:00
Adrian Prantl
fdad9076f2 Revert "Add debug info support for inlined and specialized generic variables."
There is an assertion failure building the source compatibility suite that
needs to be investigated.

This reverts commit 91f6f34119.
2018-07-07 13:01:01 -07:00
Adrian Prantl
91f6f34119 Add debug info support for inlined and specialized generic variables.
This patch adds SIL-level debug info support for variables whose
static type is rewritten by an optimizer transformation. When a
function is (generic-)specialized or inlined, the static types of
inlined variables my change as they are remapped into the generic
environment of the inlined call site. With this patch all inlined
SILDebugScopes that point to functions with a generic signature are
recursively rewritten to point to clones of the original function with
new unique mangled names. The new mangled names consist of the old
mangled names plus the new substituions, similar (or exactly,
respectively) to how generic specialization is handled.

On libSwiftCore.dylib (x86_64), this yields a 17% increase in unique
source vars and a ~24% increase in variables with a debug location.

rdar://problem/28859432
rdar://problem/34526036
2018-07-06 22:06:48 -07:00
David Zarzycki
7d6c69609b [Mangling] NFC: Adopt reference storage type meta-programming macros 2018-06-30 06:44:34 -04:00
Doug Gregor
58c5b020cb [Mangling] Handle mangling involving bound generic "protocols".
When mangling a specialized use of a typealias in a protocol, we end up
with a "bound generic protocol" mangling, with the one substitution
replacing Self with some other type. Handle de-mangling and
re-mangling of such names.

Fixes rdar://problem/41549126.
2018-06-27 16:43:29 -07:00
Adrian Prantl
360b1687ac Remove support for the obsolete Qualified Archetype mangling from everywhere. 2018-06-21 16:15:17 -07:00
Doug Gregor
7952a19f31 [Mangling] Introduce known manglings for many more standard library types.
Since the mangling scheme and set of standard library types is effectively
fixed now, introduce known mangling substitutions for a number of new
standard library types, filling out the S[A-Za-z] space.

Reduces standard library binary size by ~195k.
2018-06-19 23:24:38 -07:00
Joe Groff
2d77d299c3 TypeDecoder: Be more forgiving of extra child nodes in demangled nominal types. 2018-05-18 11:09:42 -07:00
Raj Barik
e215abc3fa Add ExistentialToGeneric mangling and demangling code 2018-05-14 15:26:18 -07:00
Davide Italiano
f6659435ad [ASTMangler] Add support for mangling generic typealiases.
<rdar://problem/39915946>
2018-05-11 14:34:41 -07:00
Joe Groff
0d438c91c4 [Demangle to metadata] Support simple extension contexts.
Support demangling for types nested within some simple extension contexts.
Still does not support nested types within constrained extensions that
involve same-type constraints among generic parameters, nor
deeply-nested types in extensions. However, it fixes
rdar://problem/40071688.
2018-05-10 23:36:01 -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
Slava Pestov
902c0d3586 Runtime: Handle symbolic references inside other mangling nodes
Previously we could only handle symbolic references at the
top level, but this is insufficient; for example, you can
have a nested type X.Y where X is defined in the current
translation unit and Y is defined in an extension of X in
a different translation unit. In this case, X.Y mangles as
a tree where the child contains a symbolic reference to X.

Handle this by adding a new form of Demangle::mangleNode()
which takes a callback for resolving symbolic references.

Fixes <rdar://problem/39613190>.
2018-04-20 21:55:45 -07:00
Sho Ikeda
6115216390 Merge pull request #15591 from ikesyo/demangling-using-over-typedef
[gardening][Demangling] Replace `typedef` with `using`
2018-03-30 12:30:49 +09:00
Slava Pestov
588448684b IRGen: Emit resilient witness tables 2018-03-29 14:03:58 -07:00
Sho Ikeda
17b833a831 [gardening][Demangling] Replace typedef with using 2018-03-29 13:39:10 +09: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
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
98ee6a5d7d Runtime: Prefab metadata records for Any and AnyObject.
Metadata for these types gets demanded fairly frequently, and it's a decent code size savings not having to emit a runtime call to access them.
2018-03-10 10:15:42 -08:00
Huon Wilson
38029bab2a [ABI] Store a ValueOwnership directly, not a manual encoding of it. 2018-03-08 12:36:37 +11:00
Huon Wilson
e307e54098 [AST] Explicitly track things marked __owned. 2018-03-08 12:36:24 +11: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
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
Mike Ash
03476e919e Merge branch 'master' into remove-reflectionlegacy 2018-02-22 11:44:55 -05:00
Mike Ash
c250a844d0 [Runtime] Add a declaration for swift_demangle to the header file and export it.
rdar://problem/20356017
2018-02-21 17:22:09 -05: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
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
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
Doug Gregor
d0b73b85d0 [Type decoder] Generalize the canonicalization of nominal type decl references.
Various TypeDecoder clients will depend on having the "bare" nominal
type declaration demangled node for looking up nominal type descriptors,
so move the generic argument-stripping code into TypeDecoder.
2018-01-12 15:35:12 -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
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
swift-ci
fc4d66d269 Merge pull request #13827 from DougGregor/type-decoder-protocol-composition 2018-01-09 15:39:45 -08:00
Doug Gregor
61884f7702 [Type decoder] Rework the builder contract for protocols.
TypeDecoder's interface with its builders already treated protocols as
a type (due to their being mangled as "protocol composition containing
one type"), and intermixed protocols with superclasses when forming
compositions. This makes for some awkwardness when working with
protocol descriptors, which are very much a distinct entity from a
type.

Separate out the notion of a "protocol declaration" (now represented
by the builder-provided BuiltProtocolDecl type) from "a protocol
composition containing a single type", similarly to the way we handle
nominal type declarations. Teach remote mirrors and remote AST to
handle the new contract.
2018-01-09 10:46:31 -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
Doug Gregor
8c02083f4a [Type decoder] Check for correct # of children when decoding a type.
Prevents crashing on some invalid inputs.
2018-01-07 23:13:54 -08:00
Erik Eckstein
cd3d50a5d9 ABI: Change the mangling prefix from _T0 to $S 2018-01-06 13:55:59 -08:00
David Zarzycki
5bd9bed595 [Demangling] #include <vector> to make Linux (Fedora 27) build again 2018-01-06 09:06:21 -05:00