Commit Graph

8 Commits

Author SHA1 Message Date
Becca Royal-Gordon
ba1ec90419 Generate IR for @_objcImpls
This commit begins to generate correct metadata for @_objcImplementation extensions:

• Swift-specific metadata and symbols are not generated.
• For main-class @_objcImpls, we visit the class to emit metadata, but visit the extension’s members.
• Includes both IR tests and executable tests, including coverage of same-module @objc subclasses, different-module @objc subclasses, and clang subclasses.

The test cases do not yet cover stored properties.
2022-10-18 17:21:56 -07:00
John McCall
bad16fd105 Do dynamic layout of generic/resilient default actors properly.
Since these types have an implicit stored property, this requires
adding an abstraction over fields to IRGen, at least throughout
the class code.  In some ways I think this significantly improves
the code, especially in how we approach missing members.

Fixes rdar://72202671.
2020-12-15 20:10:46 -05:00
Arnold Schwaighofer
7f20d937e9 IRGen: Correctly compute instanceStart for a Swift class that starts with an empty field and is followed by a resilient field
We used to crash for classes that have an empty and a resilient field
during intialization if the object was in the shared cache.

  class CrashInInit {
    var empty = EmptyStruct()
    var resilient = ResilientThing()
  }

What happened was that for such a class we we would compute a
instanceStart of 0. The shared cache builder would then slide the value
of the constant ivar offset for the empty field from 0 to 16. However,
the field offset for empty fields is assumed to be zero and the runtime
does not compute a different value for the empty field and so the field
offset for the empty field remains 0. The runtime then trys to reconcile
the field offset (0) and the ivar offset (16) trying to write to the ivar
offset. However, the ivar offset is marked as constant and so we
crashed.
This can be avoided by correctly computing the instanceStart for such a
class to be 16 such that the shared cache builder does not update the
value of the empty field.

rdar://rdar://58458169
2020-01-15 06:18:41 -08:00
John McCall
7f55a4a4f0 Always give known-empty class properties a zero offset in the static layout.
Field offset vectors are always filled out with either zero or the static layout's offset, depending on the metadata initialization strategy.  This change means that the static layout's offset will only be non-zero for properties with a statically-known layout.  Existing runtimes doing dynamic class layout assign class properties a zero offset if the field offset vector entry is zero and the property is zero-sized.  So this effectively brings the compiler into accord with the runtime (for all newly-compiled Swift code, which will eventually be all Swift code because the current public releases of Swift 5 are not yet considered ABI-stable) and guarantees a zero value for the offset everywhere.

Since the runtime will agree with the compiler about the zero value of the offset, the compiler can continue to emit such offset variables as constant.  The exception to this rule is if the class has non-fragile ObjC ancestry, in which case the ObjC runtime (which is not aware of this special rule for empty fields) will attempt to slide it along with everything else.

Fixes rdar://48031465, in which the `FixedClassMetadataBuilder` for a class with a legacy-fixed layout was writing a non-zero offset for an empty field into the field offset vector, causing the runtime to not apply the special case and thus to compute a non-zero offset, which it then attempted to copy into the global field offset variable, which the compiler had emitted as a true-constant zero.
2019-02-20 00:53:11 -05:00
Slava Pestov
eec0fcdf49 IRGen: When available, use ClassMetadataStrategy::Update even if we don't have legacy type info
If we know our deployment target has a new Objective-C runtime, we can
emit fixed metadata for classes with resilient types even if those
types do not appear in the YAML legacy type info.

Fixes <rdar://problem/47649465>.
2019-02-18 22:39:13 -05:00
Slava Pestov
9a6126b148 IRGen: Move fine-grained flags from ClassLayoutBuilder to ClassLayout
Another refactoring in preparation for adding the new type of class
metadata emitted when deploying to a target with a new Objective-C
runtime.

Progress on <rdar://problem/47649465>.
2019-02-18 22:39:13 -05: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
Slava Pestov
f594d5bfbf IRGen: Split off ClassLayout implementation into its own file 2018-08-07 05:34:29 -07:00