Commit Graph

30 Commits

Author SHA1 Message Date
Anthony Latsis
af66096847 Gardening: Migrate test suite to GH issues: Interpreter 2022-09-01 06:35:57 +03:00
Doug Gregor
def86ce402 Revert "[irgen] Force emission of objc class refs for non-foreign clang objc classes whose metadata we use."
This reverts commit 8247525471. While
correct, it has uncovered several issues in existing code bases that
need to be sorted out before we can land it again.
Fixes rdar://problem/57846390.
2020-01-11 21:46:42 -08:00
Michael Gottesman
8247525471 [irgen] Force emission of objc class refs for non-foreign clang objc classes whose metadata we use.
Today in far more cases we are using mangled strings to look up metadata at
runtime. If we do this for an objc class but for whatever reason we do not have
any other references to the class, the static linker will fail to link in the
relevant framework. The reason why this happens is that autolinking is treated
by the static linker as a hint that a framework may be needed rather than as a
"one must link against the framework". If there aren't any undefined symbols
needed by the app from that framework, the linker just will ignore the hint. Of
course this then causes the class lookup to fail at runtime when we use our
mangled name to try to lookup the class.

I included an Interpreter test as well as IRGen tests to make sure that we do
not regress here in the future.

NOTE: The test modifications here are due to my moving the ObjCClasses framework
out of ./test/Interpreters/Inputs => test/Inputs since I am using it in the
IRGen test along side the interpreter test.

rdar://56136123
2019-11-21 16:03:54 -08:00
Arnold Schwaighofer
6eca97add6 Codesign test/Interpreter 2018-08-10 06:58:40 -07:00
Slava Pestov
fc91a58d82 IRGen: [ClassLayout] Better fix for SR-4687
We cannot use field offset globals if *any* field of a generic class
with Objective-C ancestry is dependent.

This is because the Swift runtime first performs layout starting
from a static instance start offset, and then asks the Objective-C
runtime to slide the offsets based on the dynamic superclass size.

So if the class has a field of generic type, the alignment of that
type can change the offsets of fields *before* it as well as after.

So we cannot assuem that any fields in such a class have the same
offset across instantiations at all.

The previous fix captured the intent of the above, but it only
kicked in if the immediate superclass of the class was imported
from Objective-C. But really we need to do this for any class with
Objective-C ancestry.

While fixing this, re-organize the code in ClassLayoutBuilder a
little bit to untangle the stored property iteration from the
interesting FieldAccess adjustments that take place after.
2018-08-07 04:26:43 -07:00
Dmitri Gribenko
984210aa53 tests: replace '// RUN: rm -rf' '// RUN: mkdir' pairs with '%empty-directory(...)'
These changes were made using a script.
2017-06-04 11:08:39 -07:00
Arnold Schwaighofer
579360faf1 IRGen: Don't use global offset variables if we have a dependent layout and an Objective-C super class
We can't use global offset variables if we are generic and layout
dependent on a generic parameter because the objective-c layout might
depend on the alignment of the generic stored property ('t' in the
example below).

class Foo<T> : NSFoobar {
  var x : AKlass = AKlass()
  var y : AKlass = AKlass()
  var t : T?
}

SR-4687
rdar://31813495
2017-05-26 13:15:58 -07:00
Slava Pestov
e272cf420e IRGen: Fix 'super.' calls to objc-dispatched static methods from generic classes
If a class has runtime-initialized metadata, we cannot just
reference its metaclass symbol statically, and instead we must
realize the metadata and load its isa pointer at runtime.

Fixes <rdar://problem/23715486>.
2017-05-18 20:16:29 -07:00
Slava Pestov
584316d5f2 Runtime: Fix breakage when generic subclasses directly inherit NSObject
Remove special-casing that makes NSObject fragile since
this messes up layout. The optimization probably has little
practical benefit anyway.

Fixes <https://bugs.swift.org/browse/SR-2586>.
2016-09-20 16:08:20 -07:00
practicalswift
fa7fbdb8b0 [gardening] Remove redundant nil-initialization of optional variable
From the Swift documentation:

"If you define an optional variable without providing a default value,
 the variable is automatically set to nil for you."
2016-09-18 07:40:07 +02:00
Dmitri Gribenko
d175b3b66d Migrate FileCheck to %FileCheck in tests 2016-08-10 23:52:02 -07:00
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