Commit Graph

394 Commits

Author SHA1 Message Date
John McCall
5553224fd4 Support the explicit representation of self-conformances.
Big, but actually NFC because we're never actually creating them.
2018-11-15 16:42:03 -05:00
Arnold Schwaighofer
152e8db8bb IRGen and runtime implementation for dynamic replacements 2018-11-06 09:58:36 -08:00
Arnold Schwaighofer
ebbe3aed1c IRGen: Add implementation for dynamically replaceable functions
A dynamically replaceable function calls through a global variable that
holds the function pointer.

struct ChainEntry {
   void *(funPtr)();
   struct ChainEntry *next;
}

ChainEntry dynamicallyReplaceableVar;

void dynamicallyReplaceableFunction() {
  dynamicallyReplaceableVar.funPtr()
}

dynamic replacements will be chainable so the global variable also
functions as the root entry in the chain of replacements.

A dynamic replacement functions can call the previous implementation by
going through its chain entry.

ChainEntry chainEntryOf_dynamic_replacement_for_foo;

void dynamic_replacement_for_foo() {
   // call the previous (original) implementation.
   chainEntryOf_dynamic_replacement_for_foo.funPtr();
}
2018-11-06 09:53:21 -08:00
Doug Gregor
5e232de4b8 [Mangling] Mangle retroactive conformances using the new conformance mangling
Change the retroactive conformance mangling to use the new
any-protocol-conformance mangling, which maintains more information about
concrete conformances. Specifically, it maintains conformance information
for conditional requirements. It also uses the protocol-conformance-ref
production that will eventually allow symbolic references to protocol
conformance descriptors.

While here, extend the “is retroactive” check during mangling to look for
retroactive conformances in the conditional requirements of a conformance.
The immediate conformance might not be retroactive, but its specialization
might depend on a retroactive conformance. Mangle these as “retroactive”, so
we can correctly reconstruct the exact type.
2018-11-02 22:35:34 -07: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
John McCall
cf511445e2 Basic support for Builtin.IntegerLiteral. 2018-10-31 18:42:34 -04:00
Doug Gregor
c3b806b230 Merge pull request #20097 from DougGregor/protocol-symbolic-reference
[Mangling] Mangle protocol symbolic references in any-generic-type production.
2018-10-27 00:52:43 -07:00
Doug Gregor
dafaabecd6 [Mangling] Mangle protocol symbolic references in any-generic-type production.
We were strangely excluding protocols from being symbolically referenced
in the any-generic-type production, which meant that we could not resolve
(e.g.) associated type references to private protocols at runtime. Allow
protocol symbolic references in this position, and cope with it in the
demangler.

Fixes the rest of rdar://problem/44977236.
2018-10-26 18:10:07 -07:00
Slava Pestov
4cecc268dc IRGen: Emit Objective-C metadata update callbacks 2018-10-26 16:54:23 -04: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
Erik Eckstein
f24e09e9fb demangler: fix a crash for an invalid symbol
SR-8930
rdar://problem/45216653
2018-10-15 14:52:15 -07:00
Erik Eckstein
37d27b1a41 demangler: fix demangling of InlinedGenericFunction nodes 2018-10-15 14:47:20 -07:00
Doug Gregor
ea9f0eaf8c [Mangling] Mangle protocol names in assoc-type-paths.
The mangling of associated type paths was only adding the names of
associated types, and not their enclosing protocols. This led to mangling
collisions that could lead to corrupted metadata. In the standard
library, for example, the generic requirements for the 
Unicode _ParsingIterator in the standard library ended up encoding an 
access to Sequence.Element rather than IteratorProtocol.Element due
to the mangling conflict.

Part of SR-7553 / rdar://problem/39769906.
2018-09-21 23:44:46 -07:00
Doug Gregor
32fd274f5e Merge pull request #19391 from DougGregor/assoc-conformance-default-witnesses
[ABI] Associated conformance defaults
2018-09-19 13:15:46 -07:00
Davide Italiano
e4d9813b40 [Demangler] Adjust the implementation of isObjCSymbol().
Pointed out by Jordan.
2018-09-18 13:48:51 -07:00
Davide Italiano
dbe5ee77b8 [Demangler] Implement isObjCSymbol().
This function can be queried to find out whether the passed
mangled name is an Objective-C symbol. This will be used
in the debugger to replace an hardcoded check that would
break if the mangling prefix changed.

<rdar://problem/44467875>
2018-09-18 11:32:16 -07:00
Doug Gregor
b71bef1e42 [ABI] Mangling for default associated conformance accessors.
Default associated conformance accessors will be used in default
witness tables to fill in associated conformances for defaulted
associated types. Add (de|re|)mangling support for them and make them
linking entities in IRGen.
2018-09-17 22:45:15 -07:00
Doug Gregor
4549fcd673 [ABI] Add associated conformance descriptors.
Associated conformance descriptors are aliases that refer to associated
conformance requirements within a protocol descriptor’s list of
requirements. They will be used to provide protocol resilience against
the addition of new associated conformance requirements (which only makes 
sense for newly-introduced, defaulted associated types).
2018-09-17 16:32:29 -07:00
Doug Gregor
2ef9363bd1 [ABI] Add default associated type witnesses to resilient protocols.
When an associated type witness has a default, record that as part of
the protocol and emit a default associated type metadata accessor into the
default witness table. This allows a defaulted associated type to be
added to a protocol resiliently.

This is another part of rdar://problem/44167982, but it’s still very
limiting because the new associated type cannot have any conformances.
2018-09-15 22:04:46 -07:00
Doug Gregor
bbe56b284a [ABI] Add protocol requirements base descriptor.
Introduce an alias that refers one element prior to the start of a
protocol descriptor’s protocol requirements. This can be subtracted from
an associated type descriptor address to determine the offset of the
associated type accessor within a corresponding witness table. The code
generation for the latter is not yet implemented.
2018-09-14 20:59:03 -07:00
Doug Gregor
9873d52814 [ABI] Emit associated type descriptors referencing each requirement.
Emit associated type descriptors (as aliases) to reference each associated
type requirement within a resilient protocol.
2018-09-14 20:59:03 -07:00
Saleem Abdulrasool
9105eb31f1 Demangling: use assert over llvm_unreachable
Avoid a dependency on LLVMSupport at runtime through the `llvm_unreachable`.
This would pull in `llvm_unreachable_internal` in debug builds, which requires a
runtime dependency on LLVMSupport which increases the size of the binary
considerably.
2018-09-11 22:10:08 -07:00
Erik Eckstein
882f844ff0 demangler: Support mangling typealiases in functions in generic nominals.
For example:

public struct Mystruct<T> {
  func testit<U>(x: T, u: U) {
    typealias Myalias = AnyObject
  }
}

In this case the Myalias has a generic function as context.
2018-09-11 08:33:16 -07:00
Slava Pestov
2990271686 IRGen: Add mangling for method lookup functions 2018-09-07 21:50:58 -07:00
Robert Widmann
65916262a6 Merge pull request #19135 from CodaFi/no-substitute-for-the-real-deal
[NFC] Drop unused pending substitutions vector
2018-09-06 11:34:31 -04:00
Erik Eckstein
dc31ff920d demangler: Fix a few crashes with malformed symbols
SR-8483
SR-8576
SR-8577
2018-09-05 15:49:52 -07:00
Robert Widmann
14d770e551 [NFC] Drop unused pending substitutions vector 2018-09-05 11:47:38 -04:00
Slava Pestov
dad44cdd4a IRGen: Introduce 'method descriptor' mangling 2018-08-31 00:20:38 -06:00
Slava Pestov
8be09fef74 IRGen/Runtime: Rename "InPlaceMetadata" to "SingletonMetadata"
It's not actually "in-place" for resilient classes, which have a
pattern with an allocation function.
2018-08-24 00:52:36 -07:00
Adrian Prantl
58475ef1ad 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-31 16:59:56 -07:00
John McCall
dc052e6364 Resolve metadata cycles through non-generic value types with resilient layout.
The central thrust of this patch is to get these metadata initializations
off of `swift_once` and onto the metadata-request system where we can
properly detect and resolve dependencies.  We do this by first introducing
runtime support for resolving metadata requests for "in-place"
initializations (committed previously) and then teaching IRGen to actually
generate code to use them (this patch).

A non-trivial amount of this patch is just renaming and refactoring some of
existing infrastructure that was being used for in-place initializations to
try to avoid unnecessary confusion.

The remaining cases that are still using `swift_once` resolution of
metadata initialization are:

- non-generic classes that can't statically fill their superclass or
  have resilient internal layout

- foreign type metadata

Classes require more work because I'd like to switch at least the
resilient-superclass case over to using a pattern much more like what
we do with generic class instantiation.  That is, I'd like in-place
initialization to be reserved for classes that actually don't need
relocation.

Foreign metadata should also be updated to the request/dependency scheme
before we declare ABI stability.  I'm not sure why foreign metadata
would ever require a type to be resolved, but let's assume it's possible.

Fixes part of SR-7876.
2018-07-25 15:21:55 -04:00
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
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
f232af5535 [Mangling] Allow standard substitutions in protocol mangling.
Protocol name mangling didn’t always go through a path that allowed the use
of standard substitutions. Enable standard substitutions for protocol name
manglings where they make sense.

Removes ~277k from the standard library binary size.
2018-06-19 23:24:38 -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
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