Instead of a wholly separate lazyness mechanism for foreign metadata where
the first call to getAddrOfForeignTypeMetadataCandidate() would emit the
metadata, emit it using the lazy metadata mechanism.
This eliminates some code duplication. It also ensures that foreign
metadata is only emitted once per SIL module, and not once per LLVM
module, avoiding duplicate copies that must be ODR'd away in multi-threaded
mode.
This fixes the test case from <rdar://problem/49710077>.
The old logic was confusing. The LazyTypeGlobals map would contain
entries for all referenced types, even those without lazy metadata.
And for a type with lazy metadata, the IsLazy field would begin
with a value of false -- unless it was imported.
When a non-imported type was finally visited in the AST, we would
try to "enable" lazyness for it, which meant queueing up any
metadata that had been requested prior, or immediately emitting
the metadata otherwise.
Instead, let's add a separate map that caches whether a type has
lazy metadata or not. The first time we ask for the metadata of a
type, consult this map. If the type has lazy metadata according to
the map, queue up metadata emission for the type. Otherwise, emit
metadata eagerly when the type is visited in the AST.
In LLDB expressions, references to private metadata accessors may be
emitted and need to be bound to symbols available in the attached
program, even if these symbols are only supposed to have private
visibility within the program.
Also rdar://problem/48018240
COFF has a section name limit which was being exceeded. Correct the
section name to what was expected (the tests are lenient and would
accept the ELF name as well). Furthermore, ensure that the section is
emitted into the B group so that it can be collated and markers
inserted.
When emitting metadata for a Swift-defined @objc protocol that has
provided a specific Objective-C name (e.g., via @objc(renamed)),
mangle such protocols using their Objective-C names so they can be
found at runtime.
Only do this for metadata, because doing it anywhere else would cause
an ABI break. Fixes rdar://problem/47877748.
Sorting of DeclContext-local protocols and conformances shouldn't ever
be necessary, because the underlying data structures that produce
these lists should be deterministic. Sorting can hide any
non-determinism, so stop doing it and we can address the underlying
nondeterminism.
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.
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.
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.
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.
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.
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.
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.
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).
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.