Commit Graph

1350 Commits

Author SHA1 Message Date
Doug Gregor
602b38e444 [IRGen] Centralize alignment/default type information in LinkEntity.
Simplify calls to getAddrOfLLVMVariableOrGOTEquivalent() and
getAddrOfLLVMVariable() by moving the computation of the alignment and
default type into LinkEntity.

Co-authored-by: Joe Groff <jgroff@apple.com>
2018-10-23 09:57:03 -07:00
Slava Pestov
ebe19ca69e IRGen: Use getSelfTypeInContext() in one spot 2018-10-15 20:34:08 -07:00
Doug Gregor
6e0d1d3222 Merge pull request #19719 from DougGregor/superclass-mangled-name
[ABI] Use mangled superclass names from class context descriptors.
2018-10-04 19:58:46 -07:00
Slava Pestov
c969abdf1d IRGen: Remove some unused and used-once functions
A few utility methods would bypass computing the TypeInfo for a tuple,
but they were only used in assertions or used in places where I can't
imagine tuples coming up often enough for it to matter.
2018-10-04 20:01:23 -04:00
Doug Gregor
2b44e8578f [ABI] Use mangled superclass names from class context descriptors.
Rather than rely on the metadata initialization function to compute and
fill in the superclass, use the mangled superclass name to construct the
superclass metadata.
2018-10-04 15:43:24 -07:00
Doug Gregor
a24729afb8 [ABI] Add a mangled superclass type to class context descriptors.
This allows us to recover the complete superclass type from metadata.
Currently unused, but we want to stub out the space in the ABI.
2018-10-03 20:55:17 -07:00
Doug Gregor
a4778e1c0c [ABI] Only emit resilient superclass descriptor references in class metadata.
The superclass descriptor reference in class context descriptors is only used
for metadata bound computations when the superclass is resilient. Only
include the superclass descriptor reference when the class has a resilient
superclass, using a trailing record. It’s a tiny space savings for
classes that don’t have resilient superclasses.
2018-10-03 20:05:28 -07:00
Doug Gregor
df7744e484 Merge pull request #19480 from DougGregor/mangled-assoc-type-witness
[ABI] Use mangled names for associated type witnesses.
2018-10-01 06:57:45 -07:00
Doug Gregor
4444ff9294 [IRGen] Mark protocol conformance descriptors as true const. 2018-09-28 23:53:18 -07:00
Doug Gregor
65c0c842ed [ABI] Rework the tagging of default associated type witnesses.
Encode default associated type witnesses using a sentinel prefix byte
(0xFF) in the mangled name rather than as a second low bit on the
reference. Align all of the mangled names used for type references to
2 bytes (so we get that low bit regardless) and separate the symbol
names for default associated type witnesses vs. other kinds of
metadata or reflection metadata.
2018-09-28 23:38:38 -07:00
Slava Pestov
ce770cdf4e AST: Introduce GenericSignature::forEachParam()
This replaces the inefficient pattern:

  for (auto param : sig->getGenericParams()) {
    if (sig->isCanonicalTypeInContext(param)) {
      ...
    } else {
      ...
    }
  }
2018-09-27 21:28:36 -07:00
Doug Gregor
441fee071a [Witness tables] Use a discriminator bit for default associated type witnesses
Indicate whether a particular associated type witness is a default (whose
mangled name is relative to the protocol) vs. being supplied as part of the
conformance (whose mangled name is relative to the conforming type). The
use of pointer identity to distinguish these cases can fail due to the
coalescing of these linker symbols.
2018-09-27 13:26:31 -07:00
Doug Gregor
b531b3923f [ABI] Use mangled names for associated type witnesses.
Rather than storing associated type metadata access functions in
witness tables, initially store a pointer to a mangled type name.
On first access, demangle that type name and replace the witness
table entry with the resulting type metadata.

This reduces the code size of protocol conformances, because we no
longer need to create associated type metadata access functions for
every associated type, and the mangled names are much smaller (and
sharable). The same code size improvements apply to defaulted
associated types for resilient protocols, although those are more
rare. Witness tables themselves are slightly smaller, because we
don’t need separate private entries in them to act as caches.

On the caller side, associated type metadata is always produced via
a call to swift_getAssociatedTypeWitness(), which handles the demangling
and caching behavior.

In all, this reduces the size of the standard library by ~70k. There
are additional code-size wins that are possible with follow-on work:

* We can stop emitting type metadata access functions for non-resilient
types that have constant metadata (like `Int`), because they’re only
currently used as associated type metadata access functions.
* We can stop emitting separate associated type reflection metadata,
because the reflection infrastructure can use these mangled names
directly.
2018-09-26 23:19:33 -07:00
Slava Pestov
4da47823a5 Runtime/IRGen: Add new initialization pattern for classes with backward deployment layout
If a class has a backward deployment layout:

- We still want to emit it using the FixedClassMetadataBuilder.

- We still want it to appear in the objc_classes section, and get an
  OBJC_CLASS_$_ symbol if its @objc.

- However, we want to use the singleton metadata initialization pattern
  in the metadata accessor.

- We want to emit metadata for all field types, and call the
  swift_updateClassMetadata() function to initialize the class
  metadata.

For now, this function just performs the idempotent initialization of
invoking a static method on the class, causing it to be realized with
the Objective-C runtime.
2018-09-23 21:26:46 -07:00
Slava Pestov
a7f668c89c IRGen: Clean up class metadata emission 2018-09-23 21:26:46 -07:00
Doug Gregor
fb62977c2b [IRGen] Emit default associated conformance witnesses.
For a resilient protocol that has defaulted associated types, emit
default associated conformance witnesses that compute associated
conformances based on that default witness.

This completes the implementation of resilience protocols that
add new, defaulted associated types, rdar://problem/44167982.
2018-09-19 10:56:20 -07:00
Doug Gregor
d076e41f32 [IRGen] Put associated conformance accessors in resilient witness table
For a resilient conformance, emit the associated conformance accessor
functions into the resilient witness table (keyed on the associated
conformance descriptor) rather than in the fixed part of the witness
table. This is another part of resilience for associated conformances,
and a step toward defaults for associated conformances.
2018-09-17 21:58:56 -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
4ed973329a [SIL] Unify default witness table entries with witness table entries.
SILWitnessTable::Entry already contains a superset of what was supported
by SILDefaultWitnessTable::Entry, the latter of which only had “no entry”
and “method” states. Make SILDefaultWitnessTable::Entry an alias for
SILWitnessTable::Entry, and unify all of the parsing/printing/
(de)serialization logic.
2018-09-15 22:04:46 -07:00
Doug Gregor
350391db9d [ABI] Use associated type descriptors for generic parameter references.
Generic parameter references, which occur in generic requirement
metadata, were hardcoding associated type indices. Instead, use
relative references to associated type descriptors and perform the
index calculation at runtime.

Associated types can now be reordered resiliently (without relying on 
sorting), which is the first main step toward rdar://problem/44167982.
2018-09-14 20:59:03 -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
swift-ci
cc329fee03 Merge pull request #19141 from aschwaighofer/remove_constant_string_literal 2018-09-10 15:51:47 -07:00
Slava Pestov
9347a072e5 IRGen: Emit method lookup function 2018-09-07 21:50:58 -07:00
Arnold Schwaighofer
73df12c09f Remove dead constant_string_literal
constant_string_literal was added to support a one word representation
of String that never materialized.
2018-09-05 12:13:57 -07:00
Slava Pestov
870c58e017 IRGen: Change method descriptor layout to be consistent with protocol requirements
Both now have a flags field followed by the implementation.
2018-09-04 14:46:34 -07:00
Slava Pestov
b7449d5621 IRGen/Runtime: Method override descriptors 2018-09-04 14:46:34 -07:00
Slava Pestov
44c4497ac5 IRGen/Runtime: Protocol requirement descriptors don't need to reference the dispatch thunk 2018-08-31 00:16:22 -07:00
Slava Pestov
771eacb4df IRGen: Emit method descriptors 2018-08-31 00:20:39 -06:00
Slava Pestov
b3060d8836 IRGen: Emit dispatch thunks while emitting nominal type descriptor 2018-08-31 00:20:38 -06:00
John McCall
b80618fc80 Replace materializeForSet with the modify coroutine.
Most of this patch is just removing special cases for materializeForSet
or other fairly mechanical replacements.  Unfortunately, the rest is
still a fairly big change, and not one that can be easily split apart
because of the quite reasonable reliance on metaprogramming throughout
the compiler.  And, of course, there are a bunch of test updates that
have to be sync'ed with the actual change to code-generation.

This is SR-7134.
2018-08-27 03:24:43 -04: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
Slava Pestov
ed5bb3490b IRGen: Fold {Fixed,InPlace}ClassMemberBuilder into {Fixed,InPlace}ClassMetadataBuilder
With all the other refactoring, these are only used from one place and
keeping them separate is not necessary.
2018-08-24 00:52:36 -07:00
Slava Pestov
03cb6d1ff4 IRGen/Runtime: Use a true-const pattern to initialize non-generic resilient class metadata
Previously we would emit class metadata for classes with resilient
ancestry, and relocate it at runtime once the correct size was known.

However most of the fields were blank, so it makes more sense to
construct the metadata from scratch, and store the few bits that we
do need in a true-const pattern where we can use relative pointers.
2018-08-23 23:40:08 -07:00
Slava Pestov
120be251db IRGen: Metadata patterns are always true-const
They were, already, but remove the isConstant parameter to
getAddrOfTypeMetadataPattern(), and just assert that its true for
patterns in defineTypeMetadata() instead.

Also, metadata patterns are i8*, not i8**. In fact they don't contain any
absolute pointers at all.

Should be NFC other than the LLVM type change.
2018-08-23 23:40:08 -07:00
Slava Pestov
d56234416d IRGen: Another small cleanup for class metadata emission 2018-08-23 23:40:08 -07:00
Slava Pestov
4a23d3cc6c IRGen: Rename emitInitializeMetadata() to emitInitializeValueMetadata()
Small cleanup suggested by John in review.
2018-08-23 23:40:08 -07:00
Slava Pestov
d7a9a2a010 IRGen: Remove unused 'isIndirect' parameter to defineTypeMetadata() 2018-08-21 22:29:16 -07:00
Slava Pestov
d93ca3f3d5 IRGen: Merge ConcreteClassMetadataBuilderBase into ClassMetadataBuilderBase
ClassMetadataBuilderBase only has one subclass now, so fold it in.
2018-08-21 22:29:16 -07:00
Slava Pestov
c7f6078153 IRGen: GenericMetadataBuilderBase doesn't need a superclass
It's confusing to have the generic and concrete type metadata
builders share a common base class, when most of the base class
is not used for the generic case.
2018-08-21 22:29:12 -07:00
Slava Pestov
8972f36807 IRGen: Make some metadata builder methods into top level static functions 2018-08-21 21:51:53 -07:00
Slava Pestov
97af8a7c68 IRGen: Concrete type metadata does not have generic parameters or requirements 2018-08-21 20:40:47 -07:00
Slava Pestov
6150e34508 Runtime/IRGen: Two-phase metadata initialization for resilient classes
Similar to the non-resilient case, except we also emit a 'relocation
function'. The class descriptor now contains this relocation function
if the class has resilient ancestry, and the relocation function
calls the runtime's swift_relocateClassMetadata() entry point.

The metadata completion function calls swift_initClassMetadata() and
does layout, just like the non-resilient case.

Fixes <rdar://problem/40810002>.
2018-08-20 16:26:47 -07:00
Slava Pestov
50a037d8ed Runtime: Set the superclass in swift_initClassMetadata()
Now that we don't need the superclass before calling
swift_relocateClassMetadata(), it seems simpler to set it
here instead of doing it in various places in IRGen.
2018-08-20 16:23:07 -07:00
Slava Pestov
3256ee43c0 Runtime: swift_relocateClassMetadata() calculates metadata bounds from the class descriptor
Using the superclass metadata here no longer makes sense with two-phase
init, in case the superclass metadata depends on the class being
instantiated.

It would also be nice to rework the resilient class metadata 'pattern'
to be its own data structure that's true const, instead of just the
prefix of a real class metadata, but for now let's keep the existing
crappy design.
2018-08-20 16:23:07 -07:00
Slava Pestov
a86a71de1e Runtime/IRGen: Two-phase metadata initialization for non-resilient classes
Note that this patch also consolidates the recursive metadata tests
into one place while adding an execution test.
2018-08-20 16:23:07 -07:00
Slava Pestov
1fbdf035ce IRGen: Teach emitDirectTypeMetadataAccessFunctionBody() about "idempotent" class initialization
This is the simplest case, and not very interesting.
2018-08-20 16:23:07 -07:00
Slava Pestov
24a9a5156c IRGen: In-place initialization for classes with generic ancestry and resiliently-sized fields
If a class has generic ancestry or resiliently-sized fields, but is
itself not generic and does not have resilient ancestry, we must
perform runtime metadata initialization, but we can initialize
the metadata in-place.

As with generic classes or classes with resilient ancestry, we
copy generic requirements and field offset vectors from the
superclass. We also calculate the layout of the class's direct
fields at runtime.

Unlike the fully resilient case, we don't copy vtable entries
from the superclass, or install the direct class's vtable
entries from the type context descriptor. Instead, we statically
emit the vtable as with fixed-size class metadata.

Both the in-place and resilient case call the same runtime
entry point to initialize class metadata; the new HasStaticVTable
flag in ClassLayoutFlags is used to select between the two
behaviors concerning the vtable.
2018-08-20 16:22:35 -07:00
Slava Pestov
98b5eafcca IRGen: Split up doesClassMetadataRequireDynamicInitialization() into two predicates
- doesClassMetadataRequireRelocation() -- returns true if we must
  allocate new metadata at runtime and fill it in, because the class
  has multiple instantiations (generic case) or because the total size
  of the metadata is not known at compile time (resilient ancestry).

- doesClassMetadataRequireInitialization() -- weaker condition than
  the above. It's true if the metadata must be relocated, but it is
  also true if the metadata has otherwise fixed size but must be
  filled in dynamically. This occurs if the class has generic
  ancestry but is itself not generic, or if the class has
  resiliently-sized fields, or missing members.

For now, we don't actually care about the distinciton anywhere,
because we cannot do in-place initialization of class metadata yet.
2018-08-20 14:24:19 -07:00