Commit Graph

34 Commits

Author SHA1 Message Date
Mike Ash
c0486723fe [Test] Remove class_getImageName-static test.
This test checks the behavior of class_getImageName before the runtime's hook is installed with objc_setHook_getImageName. Foundation now triggers installation of that hook very early, causing the test to fail. Reliably avoiding this is difficult, and the test is redundant with the ObjC runtime's tests, so just remove it.

rdar://132478164
2024-07-25 11:09:38 -04:00
Michael Spencer
b2640e15e4 [test] Rename all module.map files to module.modulemap
`module.map` as a module map name has been discouraged since 2014, and
Clang will soon warn on its usage. This patch renames all instances of
`module.map` in the Swift tests to `module.modulemap` in preparation
for this change to Clang.

rdar://106123303
2023-08-21 15:58:59 -07:00
Saleem Abdulrasool
88e13060ab test: repair Interpreter/SDK/interpreter_with_options on ASi
Remove the target specific binary and instead compile a test binary on
the fly.  Because this test is restricted to macOS platforms, we know
that we assume that we will have a compatible Objective-C runtime at our
disposal.  Use that to create a stub library for testing
`NSClassFromString`.

This allows this test to execute on ARM64.
2020-08-07 14:29:35 -07:00
David Smith
8e09cd2119 Merge pull request #25864 from Catfish-Man/no-objc-complications-once-more-into-the-breach
Update fast dealloc to use new-style interposing and support objc weak refs
2020-01-22 17:21:34 -08:00
David Smith
f36a4db856 Update fast dealloc to use new-style interposing and support objc weak refs 2020-01-22 13:55:27 -08: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
Slava Pestov
6d5ff209d0 IRGen: Implement support for __attribute__((ns_consumed)) block parameters
Fixes <rdar://problem/48792177>.
2019-12-02 18:41:27 -05: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
Mike Ash
597dcd8f3f [Stdlib][Frontend][CMake] Remove SWIFT_DARWIN_ENABLE_STABLE_ABI_BIT option, make it permanently on. 2019-03-13 09:31:50 -04:00
Jordan Rose
425c190086 Restore initializing entry points for @objc convenience initializers (#21815)
This undoes some of Joe's work in 8665342 to add a guarantee: if an
@objc convenience initializer only calls other @objc initializers that
eventually call a designated initializer, it won't result in an extra
allocation. While Objective-C /allows/ returning a different object
from an initializer than the allocation you were given, doing so
doesn't play well with some very hairy implementation details of
compiled nib files (or NSCoding archives with cyclic references in
general).

This guarantee only applies to
(1) calling `self.init`
(2) where the delegated-to initializer is @objc
because convenience initializers must do dynamic dispatch when they
delegate, and Swift only stores allocating entry points for
initializers in a class's vtable. To dynamically find an initializing
entry point, ObjC dispatch must be used instead.

(It's worth noting that this patch does NOT check that the calling
initializer is a convenience initializer when deciding whether to use
ObjC dispatch for `self.init`. If we ever add peer delegation to
designated initializers, which is totally a valid feature, that should
use static dispatch and therefore should not go through objc_msgSend.)

This change doesn't /always/ result in fewer allocations; if the
delegated-to initializer ends up returning a different object after
all, the original allocation was wasted. Objective-C has the same
problem (one of the reasons why factory methods exist for things like
NSNumber and NSArray).

We do still get most of the benefits of Joe's original change. In
particular, vtables only ever contain allocating initializer entry
points, never the initializing ones, and never /both/ (which was a
thing that could happen with 'required' before).

rdar://problem/46823518
2019-01-14 13:06:50 -08:00
Greg Parker
7200e109d7 [runtime] Add tests of pre-stable ABI objects with the stable ABI runtime (#21403)
* [test] Fix objc_old_swift when objc/objc-internal.h is not in the SDK.
2018-12-20 18:32:03 -08:00
Slava Pestov
eb8aa7fce0 Update missing member tests to use Swift 4/5 instead of 3/4 2018-08-02 02:10:17 -07:00
Jordan Rose
3ed3774e07 Override ObjC's class_getImageName to handle Swift classes
This not only restores the correct behavior for classes with generic
ancestry, but also handles actual generic classes as well. (This is
the function that backs Foundation's Bundle.init(for: AnyClass)
initializer.)

https://bugs.swift.org/browse/SR-1917
rdar://problem/33450609&40367300
2018-07-12 15:48:58 -07:00
Christopher Rogers
6da2b9202a [SR-7263] Ensure use-after-free possible in test 2018-05-11 12:33:14 +09:00
Christopher Rogers
eea57a0373 [SR-7263] Ensure caller alive after optimization 2018-05-10 20:07:27 +09:00
Jordan Rose
520d6b9b91 Make NS_TYPED_ENUMS ObjectiveCBridgeable when they wrap an object (#15270)
This allows them to be used in generic arguments for NSArray et al.
We already do this for the ones that wrap bridged values (like
NSString/String), but failed to do it for objects that /weren't/
bridged to Swift values (class instances and protocol compositions),
or for Error-which-is-special.

In addition to this being a sensible thing to do, /not/ doing this led
to IRGen getting very confused (i.e. crashing) when we imported a
Objective-C protocol that actually used an NS_TYPED_ENUM in this way.

(We actually shouldn't be using Swift's IRGen logic to emit protocol
descriptors for imported protocols at all, because it's possible we
weren't able to import all the requirements. But that's a separate
issue.)

https://bugs.swift.org/browse/SR-6844
2018-03-15 16:17:38 -07:00
Joe Groff
39dfe07354 IRGen: Treat class layout for classes from other modules a bit more opaquely.
We would miscompile in mixed-language-version projects when a Swift class was compiled for one language version, while using Objective-C-imported types that are only available to that version, and then imported into a Swift module with a different language version that wasn't able to see all of the properties because of incompatible imported types. This manifested in a number of ways:

- We assumed we could re-derive the constant field offsets of the class's ivars from the layout, which is wrong if properties are missing, causing accesses to final properties or subclass properties to go to the wrong offsets.
- We assumed we could re-derive the instance size and alignment of a class instance in total, causing code to allocate the wrong amount of memory.
- We neglected to account for the space that stored properties take up in the field offset vector of the class object, causing us to load vtable entries for following subclass methods from the wrong offsets.

Eventually, resilience should reduce our exposure to these kinds of problems. As an incremental step in the right direction, when we look at a class from another module in IRGen, treat it as always variably-sized, so we don't try to hardcode offsets, size, or alignment of its instances. When we import a class, and we're unable to import a stored property, leave behind a new kind of MissingMemberDecl that records the number of field offset vector slots it will take up, so that we lay out subclass objects and compute vtable offsets correctly. Fixes rdar://problem/35330067.

A side effect of this is that the RemoteAST library is no longer able to provide fixed field offsets for class ivars. This doesn't appear to impact the lldb test suite, and they will ultimately need to use more abstract access patterns to get ivar offsets from resilient classes (if they aren't already), so I just removed the RemoteAST test cases that tested for class field offsets for now.
2017-11-17 14:38:08 -08:00
Jordan Rose
85ccbb4990 [ClangImporter] Bridging can happen even without full bridgeability
Partially reverts f4f8349 (from July!) which caused us to start
importing global blocks with unbridged parameters, breaking source
compatibility. I'm still investigating whether there's an actual hole
in the logic; see next few commits.

rdar://problem/34913634
2017-11-02 14:40:39 -07:00
Saleem Abdulrasool
bdb7901a1c test: modernise nullability attributes (NFC)
Use the modern spelling for the nullability attributes in the test mock
headers.  Currently, this was relying on the predefined macros from
clang to work.  However, those are only available on Darwin targets.
This is needed to make the mock environments more portable.
2017-11-01 23:27:33 -07:00
Erik Eckstein
488c43c825 runtime: add a runtime function _swift_checkClassAndWarnForKeyedArchiving
This function checks if a mangled class name is going to be written into an NSArchive.
If yes, a warning should be printed and the return value should indicate that.

TODO: print the actual warning

rdar://problem/32414508
2017-06-07 17:02:00 -07:00
Erik Eckstein
ddecb6444b Add a test to check the archive compatibility between swift versions.
Check that we can read an archive which was produced with the swift 3.1 compiler
2017-05-03 10:52:55 -07:00
Mishal Shah
23b646eed2 Update master to build with Xcode 8 beta 2, OS X 10.12, iOS 10, tvOS 10, and watchOS 3 SDKs 2016-07-06 10:48:45 -07:00
Mishal Shah
87b7bcfd3e Update master to build with Xcode 8 beta 1, OS X 10.12, iOS 10, tvOS 10, and watchOS 3 SDKs. 2016-06-14 14:53:55 -07:00
Jordan Rose
4968da94bf [test] Switch a test from NSLog to fputs.
NSLog does additional things like writing to the system log; this test
doesn't need that.
2016-05-12 16:18:11 -07:00
Jordan Rose
55b20d42d7 [test] Test invoking the ObjC entry point of a throwing method.
This previously blew up if the Objective-C client passed NULL for the
error parameter, but started working after the pointer nullability
change. Why? John had /already written and committed/ code to handle
NULL assuming pointer nullability was explicit, and that code was
/correct as is/.
2016-04-11 20:06:40 -07:00
Doug Gregor
def2846a45 Add an executable test for objc_runtime_visible classes + dynamic casting. 2016-04-04 09:52:14 -07:00
Max Moiseev
3a3984877a Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-15 15:43:34 -08:00
Dmitri Hrybenko
f46f16ae82 stdlib: implement new print() API
rdar://20775683

Swift SVN r28309
2015-05-08 01:37:59 +00:00
Jordan Rose
8247c2d357 If imported calls return nil for 'NSArray * __nonnull', pretend it was [].
...and similar for NSDictionary and NSSet.

For APIs that don't have a reason to distinguish "empty" and "absent" cases,
we encourage standardizing on "empty" and marking the result as non-optional
(or in Objective-C, __nonnull). However, there are system APIs whose
implementations currently do return nil rather than an empty collection
instance. In these cases, we recommend /changing/ the API to return the
appropriate "empty" value instead.

However, this can cause problems for backwards-deployment: while the API is
truly non-optional on system vN, a program may encounter a nil return value
if run on system vN-1. Objective-C can generally deal with this (especially
if the only thing you do is ask for the count or try to iterate over the
collection) but Swift can't. Therefore, we've decided to "play nice" and
accept nil return values for the collection types (NSArray, NSDictionary,
and NSSet) and implicitly treat them as "empty" values if they are the
result of an imported function or method.

Note that the current implementation has a hole regarding subscript getters,
since we still make an AST-level thunk for these in the Clang importer.
We can probably get rid of those these days, but I didn't want to touch
them at this point. It seems unlikely that there will be a subscript that
(a) is for a collection type, and (b) mistakenly returned nil in the past
rather than an empty collection.

There's another hole where an ObjC client calls one of these mistakenly-nil-
returning methods and then immediately hands the result off by calling a
Swift method. However, we have to draw the line somewhere.

(We're actually going to do this for strings as well; coming soon.)

rdar://problem/19734621

Swift SVN r26479
2015-03-24 03:36:45 +00:00
Joe Groff
6bdedc769f Clang importer: Don't delay the protocol conformances of imported enums.
Fixes rdar://problem/19924834, which exposes a case where delayed protocols cause an imported enum's Equatabe protocol conformance to get instantiated too late, if the enum is imported by one file that doesn't use the Equatable conformance, and a subsequent file in the same invocation then uses the conformance. Jordan notes that delaying these conformances is no longer desirable, now that we dynamically detect conformances.

Swift SVN r25741
2015-03-04 04:48:59 +00:00
Jordan Rose
14a2909cab Pass -L, -l, and -framework to REPL and interpret mode jobs.
...and then honor them.

While here, make -l a little more flexible (see interpret_with_options test).

rdar://problem/17830826, which unblocks the LLDB feature for the same.

Swift SVN r24033
2014-12-19 17:33:03 +00:00
Joe Groff
dfac9181dd Runtime: Add ObjC weak referencing support to SwiftObject.
We were missing -_tryRetain, -_isDeallocating, -allowsWeakReference and -retainWeakReference implementations on SwiftObject, so forming an ObjC weak reference to a pure Swift object always failed and produced a nil reference. Fixes rdar://problem/18637774.

This can be reapplied now that we properly call objc_destructInstance on deallocation.

Swift SVN r23070
2014-11-02 21:03:21 +00:00
Greg Parker
330752b749 Revert r22710 and r22711 implementing ObjC weak ref methods on SwiftObject.
This is still incomplete and needs more work. rdar://18637774.


Swift SVN r22717
2014-10-14 01:33:29 +00:00
Joe Groff
82f6260c64 Runtime: Add ObjC weak referencing support to SwiftObject.
We were missing -_tryRetain, -_isDeallocating, -allowsWeakReference and -retainWeakReference implementations on SwiftObject, so forming an ObjC weak reference to a pure Swift object always failed and produced a nil reference. Fixes rdar://problem/18637774.

Swift SVN r22710
2014-10-13 22:12:39 +00:00