Commit Graph

19 Commits

Author SHA1 Message Date
Slava Pestov
90a172e63b IRGen: Always use swift_initClassMetadata_UniversalStrategy() even if the class does not have generically-sized fields
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.
2016-02-11 23:23:26 -08:00
Slava Pestov
32bd7705bf IRGen: Test emission of conformances for concrete subclasses of generic classes
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>.
2016-01-15 21:34:53 -08:00
Slava Pestov
800821f980 IRGen: Layout of root classes containing resiliently-sized fields
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.
2015-12-24 02:54:56 -08:00
Slava Pestov
1368db7872 IRGen: Fix layout of concrete subclasses of generic subclasses of imported Objective-C classes
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>.
2015-12-21 16:23:39 -08:00
Slava Pestov
02b6753e93 Sema: Diagnose overrides of an @objc declaration that cannot be @objc
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
2015-06-03 00:01:33 +00:00
Slava Pestov
ec6b6b586c IRGen: No longer refuses to emit @objc thunks for stuff in generic context
For example, overriding methods in a generic subclass of an @objc
class works.

Swift SVN r29261
2015-06-03 00:01:30 +00:00
Slava Pestov
0c88c13c0d IRGen: Brazenly nuke -enable-dynamic-value-type-layout flag
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
2015-06-03 00:01:29 +00:00
Slava Pestov
56dec64e5c IRGen: Trying to get dynamic layout for @objc working
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
2015-06-03 00:01:27 +00:00
Arnold Schwaighofer
f7771859d8 Rename the optimize_test feature to executable_test and document that feature.
Swift SVN r29213
2015-06-01 23:44:13 +00:00
Arnold Schwaighofer
3643c614a3 Run tests in optimize test modes
This runs all files that have a target-build-swift or target-run-stdlib-swift
RUN line in optimize test mode.

Swift SVN r29206
2015-06-01 21:23:31 +00:00
Ted Kremenek
eaa0f93710 Revert "IRGen: Trying to get dynamic layout for @objc working"
Speculatively reverting because the iOS bots are broken.

Swift SVN r29146
2015-05-29 14:11:28 +00:00
Ted Kremenek
dad92b0084 Revert "IRGen: Brazenly nuke -enable-dynamic-value-type-layout flag"
Speculatively reverting because the iOS bots are broken.

Swift SVN r29145
2015-05-29 14:11:25 +00:00
Ted Kremenek
aa7f47df9b Revert "IRGen: No longer refuses to emit @objc thunks for stuff in generic context"
Speculatively reverting because the iOS bots are broken.

Swift SVN r29144
2015-05-29 14:11:22 +00:00
Slava Pestov
2eac5bc755 IRGen: No longer refuses to emit @objc thunks for stuff in generic context
For example, overriding methods in a generic subclass of an @objc
class works.

Swift SVN r29139
2015-05-29 06:19:08 +00:00
Slava Pestov
9da369b5ba IRGen: Brazenly nuke -enable-dynamic-value-type-layout flag
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
2015-05-29 06:19:06 +00:00
Slava Pestov
83b789ea34 IRGen: Trying to get dynamic layout for @objc working
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
2015-05-29 06:19:04 +00:00
Greg Parker
15b99a26d9 Test: Add %target-clang substitution.
Swift SVN r28758
2015-05-19 06:08:36 +00:00
Dmitri Hrybenko
f46f16ae82 stdlib: implement new print() API
rdar://20775683

Swift SVN r28309
2015-05-08 01:37:59 +00:00
John McCall
b6bafa5d74 When instantiating a generic class, set up the
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
2015-02-25 23:35:25 +00:00