This function points the ivar offsets at per-metadata field offsets
before passing off the class to the Objective-C runtime, ensuring
we don't slide the global ivar offsets multiple times.
The swift_initializeSuperclass() function does not do this ivar
cloning, so it cannot be used for generic classes even if they do
not have generically-sized fields.
An alternative would be to refactor the runtime to clone ivar offset
vectors in swift_initializeSuperclass(), but this doesn't seem to be
worth it for now.
This was fixed by Luke Howard as part of some other changes in the
following patch:
<b5880f386b>
After rebasing my fix, I noticed most of it disappeared.
However, it's still worth checking in the tests.
Fixes <rdar://problem/24183374>.
Now that all the machinery is in place, the ClassMetadataBuilder
can (more accurately) query the ClassLayout instead of trying to
re-derive whether the field offset vector is dependent, etc.
Apart from performing dynamic layout for resiliently-sized fields
in concrete classes, this also lets us *skip* dynamic layout
if we have a generic class without any dependent fields.
I haven't tested subclassing with resilient field layout yet, but
getting that working is the next step and should not be too much
work.
Also, swift_initClassMetadata_UniversalStrategy() only stores
the computed field offsets in the field offset globals when the
Objective-C runtime is available, because it gets the offset
pointers from the Objective-C class rodata. On Linux, we will
need to emit code to copy from the field offset vector into
field offset globals in IRGen. This is pretty easy, but I'll do
it in a follow-up patch so for now the new execution test is
XFAIL'd on Linux.
class B<T> : NSFoo {}
class A : B<Int> {}
IRGen computes the ivar layout starting from offset zero, since
the size of the 'NSFoo' is unknown and we rely on the Objective-C
runtime to slide the ivar offsets.
The instantiated metadata for B<Int> would contain a field offset
vector with the correct offsets, because of how
swift_initClassMetadata_UniversalStrategy() works.
However, A's metadata is emitted statically, and this includes a
copy of the field offset vector from the superclass. A's metadata
was initialized by swift_initializeSuperclass(), which did not
copy the field offset vector over from A<Int>. And since the
Objective-C runtime only slides the immediate ivars of a class,
the field offsets corresponding to A<Int>'s fields in B's type
metadata were never slid, resulting in problems when an instance
of B was passed to a function operating on an A<T> generically.
Fixes <rdar://problem/23200051>.
Now that generic subclasses of @objc classes are supported, dust off
Doug Gregor's fix for <rdar://problem/20385288>. It is now an error
to override an @objc declaration with something that cannot be
represented as @objc.
For example, the override of foo() here will not compile unless
it is explicitly marked @nonobjc:
func foo(i: Int) {}
...
override func foo(i: Int?) {}
Note that I updated IRGen to delete some logic for figuring out when
to emit @objc metadata. We can now rely on Sema to correctly set
isObjC(), instead of checking overrides ourselves. This was wrong
anyway, now that we can have @nonobjc overrides of @objc methods,
and vice versa.
Swift SVN r29263
The last remaining case was apparently @objc generic classes, which
seem to work now.
Also nuke the IRGen/unimplemented_objc_generic_class.swift test,
this is now implemented and we have other tests that test this
functionality.
Swift SVN r29260
It looks like John and Joe already did a good part of this. The previous
patch to enable polymorphic @objc_method signatures takes us further, and
I think this patch fills in the rest.
Fixes <rdar://problem/18505295>, <rdar://problem/20700287>.
Swift SVN r29259
The last remaining case was apparently @objc generic classes, which
seem to work now.
Also nuke the IRGen/unimplemented_objc_generic_class.swift test,
this is now implemented and we have other tests that test this
functionality.
Swift SVN r29138
It looks like John and Joe already did a good part of this. The previous
patch to enable polymorphic @objc_method signatures takes us further, and
I think this patch fills in the rest.
Fixes <rdar://problem/18505295>, <rdar://problem/20700287>.
Swift SVN r29137
correct preconditions for ObjC layout, and write the
computed offsets back to global ivar offset variables
when present.
Swift will use the global variables for accesses to
ivars when it can show that their offsets are
non-dependent.
Fixes a major problem with generic subclasses of ObjC
classes whose dynamic layout does not match the layout
in their @interface.
rdar://19583881
Swift SVN r25536