Commit Graph

1549 Commits

Author SHA1 Message Date
Saleem Abdulrasool
b700aed019 IRGen: followup for SVN r352827
This adjusts the previous change for the IRGen API changes in SVN r352827.  We
sometimes may get back a BitCastInst for the function type coercion.  Ensure
that we strip the pointer casts before performing the cast which may otherwise
fail with an assertions build.  We need to now perform a cast for the
existential boxed constructor and destructor calls to account for the missing
bitcast on a reused function.  This actually makes the IR a bit clearer as the
two parameters are being cast instead when necessary.
2019-02-14 09:27:48 -08:00
Bob Wilson
a43ee93445 Merge pull request #22353 from compnerd/r352827
Adjust for SVN r352827
2019-02-09 16:42:18 -08:00
swift-ci
89b29e1cda Merge remote-tracking branch 'origin/master' into master-next 2019-02-05 08:29:37 -08:00
Saleem Abdulrasool
6a1072d825 Adjust for SVN r352827
Update for `getOrInsertFunction` API in LLVM.
2019-02-04 12:48:46 -08:00
Saleem Abdulrasool
846a64b538 IRGen: give non_abi WeakODR linkage
Mark the non_abi functions as weak_odr.  This is needed on Windows
where the default argument generators are emitted as non-ABI functions.
These can be emitted multiple times and need to be coalesced by the
linker - that is be COMDATed as per WeakODR semantics as multiple
definitions are a hard error with PE/COFF.  Use WeakODR rather than
LinkOnceODR as we want to ensure that the symbol is preserved even if
unreferenced.
2019-01-31 17:53:50 -08:00
swift-ci
9416f1973d Merge remote-tracking branch 'origin/master' into master-next 2019-01-18 14:32:40 -08:00
Robert Widmann
c5b7230d22 [NFC] Upgrade EnumElementDecl to a DeclContext
Pure plumbing for the sake of default arguments.
2019-01-16 18:39:30 -05:00
swift-ci
6c6c3f6cbc Merge remote-tracking branch 'origin/master' into master-next 2019-01-16 11:30:02 -08:00
Slava Pestov
5182104e47 Merge pull request #21883 from slavapestov/default-witness-thunks-multithreaded-again
IRGen: Ensure that default witness thunks are emitted in the same thread as the protocol descriptor
2019-01-16 14:26:27 -05:00
swift-ci
16b7ebb1c0 Merge remote-tracking branch 'origin/master' into master-next 2019-01-16 10:10:05 -08:00
Slava Pestov
77e5b44560 IRGen: Ensure that default witness thunks are emitted in the same thread as the protocol descriptor
Protocol descriptors for resilient protocols relatively-reference
default witness thunks, so when using -num-threads N with N > 1,
we must ensure the default witness thunk is emitted in the same
LLVM module.
2019-01-15 21:42:24 -05:00
swift-ci
c7caa89c53 Merge remote-tracking branch 'origin/master' into master-next 2019-01-14 23:10:01 -08:00
Slava Pestov
152fab22a1 Revert "IRGen: Ensure that default witness thunks are emitted in the same thread as the protocol descriptor" 2019-01-15 01:05:06 -05:00
Saleem Abdulrasool
0c3f772767 IRGen: ensure that declarations are not COMDATed
Unfortunately, declarations cannot be marked with their COMDAT groups.
This fixes multithreaded IRGen where we would emit declarations for the
global initializers with COMDATs causing the IR Verifier to object.  The
existing test cases cover this scenario.
2019-01-14 16:52:35 -08:00
swift-ci
3fc7a5d887 Merge remote-tracking branch 'origin/master' into master-next 2019-01-14 15:11:06 -08:00
Slava Pestov
50465688f8 IRGen: Ensure that default witness thunks are emitted in the same thread as the protocol descriptor
Protocol descriptors for resilient protocols relatively-reference
default witness thunks, so when using -num-threads N with N > 1,
we must ensure the default witness thunk is emitted in the same
LLVM module.
2019-01-14 16:26:07 -05:00
Saleem Abdulrasool
aba8de7345 IRGen: adjust for SVN r351020
Update for SVN r351020, which removed TypeBuilder from LLVM.  This was not
actually used for constructing types anymore, so simply remove the header.
2019-01-14 08:49:03 -08:00
Saleem Abdulrasool
7f005414dd Merge pull request #21639 from compnerd/tinkering-linkering
ApplyIRLinkage cleanups
2019-01-04 15:26:11 -08:00
Saleem Abdulrasool
d3efed2943 IRGen: use ApplyIRLinkage more aggressively (NFC)
Use `ApplyIRLinkage` rather than manually applying the DLLStorage.  This
makes it much more apparent as to the desired semantic linkage desired.
2019-01-04 10:39:03 -08:00
Daniel Dunbar
8980213f7c Merge pull request #20687 from ddunbar/swasm-allow-wasm-object-format
[Swift+WASM] Allow Wasm object format.
2019-01-04 08:34:43 -08:00
Slava Pestov
4d4c194760 IRGen: Clean up and fix lazy metadata emission for reflection
We were wastefully emitting an accessor if a field had a type, for
example if my field type was (() -> (X, Array<Y>>) we would force
the emission of a function to construct (() -> (X, Array<Y>)) even
though all we care about is the type metadata for X and Y.

Conversely, we would skip the field type if it contained an
archetype, even if it otherwise contained metadata that we need
to force to emit, for instance something like (T, X) where T is
a generic parameter and X is a nominal type.

A final side effect is we no longer try to emit type metadata for
one-element tuples when emitting enum payload metadata, which is
something I want to assert against.
2018-12-15 00:05:48 -05:00
Jordan Rose
b060166dc7 Merge pull request #20559 from jrose-apple/sub-rosa
[IRGen] Generate proper type descriptors for ObjC subscript accessors

https://bugs.swift.org/browse/SR-8356
2018-12-10 11:58:50 -08:00
Saleem Abdulrasool
f067cb7250 IRGen: address TODO for COMDATing
Enable COMDATing in `createFunction`.  This is particularly important
for the emission of the GetEnumTagSinglePayload.  The function emission
is marked as linkonce ODR but does not get COMDAT'ed currently, breaking
emission on PE/COFF targets like Windows.
2018-12-08 22:48:56 -08:00
Jordan Rose
f6abffcaba [IRGen] Stop registering protocol property accessors twice in JIT mode
We visited them twice, which led to registering them twice. Add a test
for this feature so that we don't regress on this or on the use of
non-extended types in the future (see previous commits).
2018-12-08 22:43:34 -08:00
Jordan Rose
c34fe93f98 [IRGen] Generate proper type descriptors for ObjC subscript accessors
https://bugs.swift.org/browse/SR-8356
rdar://problem/42284266
2018-12-08 14:20:49 -08:00
Jordan Rose
4abb570025 [IRGen] Stop using "extended" type encodings where not supported
These are only used in two places in the Apple Objective-C runtime:

- A protocol's "extended method types" list
- Block type descriptors

We were using them when dynamically registering a protocol with the
Objective-C runtime, but that's just expecting "normal" types; the
"extended method types" list is never present in such a protocol.
2018-12-08 14:20:49 -08:00
Slava Pestov
aa747dcd81 Remove property behaviors 2018-12-07 20:38:33 -05:00
Doug Gregor
50b5044abb [IRGen] Don't emit relative references to Objective-C class references.
Objective-C class references (which show up in the __objc_classrefs
section) are always coalesced by the linker. When we relatively
address them (which occurs in protocol conformance records), the
linker may compute the relative offset *before* coalescing, leading to
an incorrect result. The net effect is a protocol conformance record
that applies to the wrong Objective-C class, causing all sorts of
runtime mayhem.

Switch relatively-addressed Objective-C classes over to using the
Objective-C runtime name of the class. It's a less efficient encoding
(since we need to go through objc_lookUpClass), but it avoids the
linker bug.

Fixes rdar://problem/46428085 by working around the linker bug.
2018-12-06 17:05:52 -08:00
Doug Gregor
f18aa80ba1 [IRGen] Foreign metadata is lazy metadata, always.
Treat foreign metadata as lazy metadata, emitted when needed.
Fixes SR-9397 / rdar://problem/46423275.
2018-12-04 11:29:16 -08:00
Doug Gregor
2c5ecb477a Merge pull request #20858 from DougGregor/mangled-base-protocol-witnesses
[ABI] Use mangled names for base protocol witnesses.
2018-12-04 11:28:27 -08:00
Doug Gregor
e6620b055d [Mangling] Separate out base conformance descriptors.
Separate the mangling of base conformance descriptors from that of
associated conformance descriptors, and simplify it.
2018-12-04 00:13:54 -08:00
Slava Pestov
4289f76064 AST: Introduce ClassDecl::hasResilientMetadata() 2018-11-29 23:20:02 -05:00
Slava Pestov
e1e22edb16 Merge pull request #20699 from slavapestov/overly-lazy-witness-table-emission
IRGen: Force emission of lazy witness table when conformance descriptor is referenced
2018-11-22 13:51:12 -05:00
Slava Pestov
4496a03a56 IRGen: Force emission of lazy witness table when conformance descriptor is referenced
Otherwise with the new resilient witness table emission pattern, we might miss
conformances for refined protocols, since the witness table itself is never
referenced, only the conformance descriptor is.

Fixes <rdar://problem/46133018>.
2018-11-21 22:25:50 -05:00
Saleem Abdulrasool
967b47f88c IRGen: adjust the replacemnts section for Windows
Group the section for the replacements on PE/COFF.  The group is needed
to ensure that we are able to order the marker for the start and stop
properly.  Without the grouping there is no way to guarantee the
ordering.
2018-11-21 18:41:02 -08:00
Daniel Dunbar
1efee0c27a [Swift+WASM] Allow Wasm object format.
- This currently does nothing more than adopt the ELF conventions, but for the
   Wasm object file format.
2018-11-20 15:22:26 -07:00
Doug Gregor
17699d4e33 [Metadata] Emit complete context descriptors for parents of anonymous contexts
When a (file)private entity occurs inside a generic context, we still need
information about the genericity of the enclosing context to demangle
to metadata. Emit complete context descriptors for parents of anonymous
contexts.

Fixes rdar://problem/46109026.
2018-11-16 21:34:32 -08:00
John McCall
ff6d031482 Allow TypeReference to refer to protocol descriptors.
We should also allow references via manglings just to cover the
general case if we need it, but this is useful on its own so that
we can emit a reference to any natively-declared Swift type.
2018-11-16 00:39:10 -05:00
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
Saleem Abdulrasool
2117c46097 IRGen: add a constant for common linkages
Swift uses LinkOnceODR with Internal linkage and normal Internal linkage quite
frequently.  Define a constant for this.
2018-11-13 09:56:24 -08:00
Arnold Schwaighofer
fb7b223ba2 Add support to modify chaining behavior of dynamic replacements
Default to not chain dynamic replacements: Only one replacement and the
original implementation are active.
2018-11-09 13:17:09 -08:00
Slava Pestov
50f68839a9 IRGen: Fix keypath pattern emission regression in multi-threaded mode
We were emitting relative references to entities that might be in
another translation unit. Use a GOT entry or thunk where appropriate.

Fixes <rdar://problem/45901706>.
2018-11-09 00:44:29 -05:00
Doug Gregor
5758cdcfcc [ABI] Eliminate the special structure for generic parameter references.
TargetGenericParamRef is a specialized structure used to describe the
subject of a generic requirement, e.g., the “T.Assoc” in “T.Assoc: P”.
Replace it with a mangled name, for several reasons:

1) Mangled type names are also fairly concise, can often be shared, and
are a well-tested path
2) Mangled type names can express any type, which might be useful in the
future
3) This structure doesn’t accommodate specifically stating where the
conformances come from (to extract associated type witnesses). Neither
can mangled names, but we’d like to do that work in only one place.

This change exposed an existing bug where we improperly calculated the
generic parameter counts for extensions of nested generic types. Fix that
bug here (which broke an execution test).
2018-11-08 13:58:17 -08:00
Arnold Schwaighofer
f1b53eb5c1 Add artificial debug information to dispatch thunk. 2018-11-06 09:58:36 -08: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
Saleem Abdulrasool
24b86d8967 Merge pull request #20059 from compnerd/comdat-helpers
IRGen: ensure that helper functions are COMDAT'ed
2018-11-06 08:53:31 -08:00
Joe Groff
65a4531467 IRGen/Runtime: Make key path pattern format true-const.
Use relative references instead of pointers so that the pattern can be true-const. Instead of trying
to instantiate a constant key path literal in-place, point to a cache variable that we can store
a pointer to the shared instance into when instantiated. Now that the pattern format has diverged
significantly from the instance format, simplify and refactor the instantiation code using a walker
for the pattern format instead of trying to reuse the code for working with instantiated instances.
rdar://problem/42674576
2018-11-05 12:30:49 -08:00
Saleem Abdulrasool
86e5b2574c IRGen: introduce new IRLinkage applicator
In order to handle LinkOnceODR semantics correctly across various object
formats, introduce a new helper ApplyIRLinkage.  This abstracts the need
to create a COMDAT group and set it on the GlobalValue.  Adjust all
sites where we set the IR linkage attributes to use this mechanism
instead to avoid having to track down symbols not being added to a
COMDAT group.
2018-11-04 10:13:50 -08:00
Slava Pestov
4cecc268dc IRGen: Emit Objective-C metadata update callbacks 2018-10-26 16:54:23 -04:00