Commit Graph

2 Commits

Author SHA1 Message Date
Slava Pestov
a05f6c80f6 IRGen: Use metadata accessors for types with resilient layout
If a struct has fixed layout but contains fields which are opaque,
or if the struct itself is opaque, use a metadata accessor function
instead of loading the metadata directly.

Let's say that A and B are two structs defined in the same module,
and B has a fixed size. This patch adds support for these two cases:

1) Fixed-layout struct A contains resilient struct B
2) Resilient struct A contains resilient struct B

In case 1),

a) Inside X: A is fixed-size and has constant metadata
 i) Direct metadata access can be performed on A and B
 ii) Direct field access can be performed on A and B
d) Outside X: B has an opaque layout
 i) Metadata accessor must be called for A and B
 ii) Fields of A do not have constant offsets, instead the offsets
     must be loaded from type metadata

Case 2) is the same as above except ii) does not apply, since fields
of resilient structs are manipulated via accessors.

Eventually, we will use metadata accessor functions for all public
struct and enum types.
2015-11-16 10:37:14 -08:00
Slava Pestov
19458cef2c IRGen: Preliminary resilient struct support
Add a new ResilientStructTypeInfo. This is a singleton since
all resilient structs have opaque payloads and are accessed
through value witness tables.

With this in place, flesh out IRGenModule::isResilient() and
use the new singleton to convert resilient structs.

Note that the old isResilient() was hard-coded to report that
all Clang-imported classes are "resilient". Now that this has
been unified with NominalTypeDecl::hasFixedLayout(), we will
report Clang-imported classes are "resilient" at the SIL level.
This should not introduce any semantic differences at this
point.

Unlike SIL, where currently resilient types are always resilient
even when used from the same module, IRGen is able to perform
direct manipulation of resilient structs from the current
module, since IRGen's type lowering has a resilience scope
plumbed through.

Note that we do not yet support laying out structs and classes
containing resilient fields -- this will come in a future patch.
2015-11-13 13:20:50 -08:00