Commit Graph

335 Commits

Author SHA1 Message Date
Joe Groff
15c9d2b130 Runtime: Remove unused once_flag. 2015-12-31 16:36:51 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Joe Groff
583f5bdb6f Runtime: Rename class property lookup functions with consistent naming scheme.
Getting a superclass, instance extents, and whether a class is native-refcounted are all useful type API. De-underscore these functions and give them a consistent `swift[_objc]_class*` naming scheme.
2015-12-23 15:04:27 -08:00
Joe Groff
fe4782ef05 Runtime: Rename swift_isClassOrObjCExistential to -Type.
To conform with the other 'is*Type' queries.
2015-12-23 13:34:47 -08:00
Max Moiseev
200be71583 Merge remote-tracking branch 'origin' into swift-3-api-guidelines 2015-12-23 10:28:04 -08:00
Joe Groff
a3354c70ed Runtime: Remove extern "C" from non-API helper function. 2015-12-23 09:17:08 -08:00
Joe Groff
4b461684e3 Remove unused _swift_isClass function. 2015-12-23 09:17:08 -08:00
Slava Pestov
096ea38ae1 Runtime: Factor out "class has formal superclass" logic, NFC 2015-12-22 15:30:17 -08:00
Max Moiseev
d610fa0d1c Merge remote-tracking branch 'origin' into swift-3-api-guidelines 2015-12-10 10:29:52 -08:00
Dmitri Gribenko
feacbc4433 Rename ErrorType to ErrorProtocol 2015-12-09 17:12:19 -08:00
Andrew Trick
35cb1afab8 Fix dynamic runtime casts of Optionals.
Fixes <rdar://23122310> Runtime dynamic casts...

This makes runtime dynamic casts consistent with language rules, and
consequently makes specialization of generic code consistent with an
equivalent nongeneric implementation.

The runtime now supports casts from Optional<T> to U. Naturally the
cast fails on nil source, but otherwise succeeds if T is convertible to
U.

When casting T to Optional<U> the runtime succeeds whenever T is
convertible to U and simply wraps the result in an Optional.

To greatly simplify the runtime, I am assuming that
target-type-specific runtime cast entry points
(e.g. swift_dynamicCastClass) are never invoked with an optional
source. This assumption is valid for the following reasons. At the
language level optionals must be unwrapped before downcasting (via
as[?!]), so we only need to worry about SIL and IR lowering.  This
implementation assumes (with asserts) that:

- SIL promotion from an address cast to a value casts should only happen
  when the source is nonoptional. Handling optional unwrapping in SIL
  would be too complicated because we need to check for Optional's own
  conformances. (I added a test case to ensure this promotion does not
  happen). This is not an issue for unchecked_ref_cast, which
  implicitly unwraps optionals, so we can promote those!

- IRGen lowers unchecked_ref_cast (Builtin.castReference) directly to
  a bitcast (will be caught by asserts).

- IRGen continues to emit the generic dynamicCast entry point for
  address-casts (will be caught by asserts).
2015-12-09 16:12:30 -08:00
Andrew Trick
a8a49afd9e Add Builtin.isOptional.
There was previously no way to detect a type that is nominally
Optional at runtime. The standard library, namely OutputStream, needs
to handle Optionals specially in order to cirumvent conversion to the
Optional's wrapped type. This should be done with conditional
conformance, but until that feature is available, Builtin.isOptional
will serve as a useful crutch.
2015-12-09 16:06:42 -08:00
Andrew Trick
a98de1ba1c Add an Optional metadata kind for runtime casts.
Reuses the enum metadata layout and builder because most of the logic is
also required for Optional (generic arg and payload). We may want to
optimize this at some point (Optional doesn't have a Parent), but I
don't see much opportunity.

Note that with this approach there will be no change in metadata layout.
Changing the kind still breaks the ABI of course.

Also leaves the MirrorData summary string as "(Enum Value)". We should
consider changing it.
2015-12-09 15:01:33 -08:00
Doug Coleman
86d99cea9b Fix eight Linux warnings.
Fix spurious docs warning that @in and @in_guaranteed should be ``fn``.

Add ``#ifdef SWIFT_OBJC_INTEROP`` to silence a -Wunused-function
on linux since that function is only used from within that #ifdef
elsewhere.

Fix three -Wunused-function warnings on linux.

Fix two -Wunreachable-code warnings on linux dealing with
SWIFT_HAVE_WORKING_STD_REGEX.
2015-12-07 15:29:41 -08:00
Landon Fuller
0f6380ef4d Match the Linux approach of assuming only the 4K NULL page is reserved. 2015-12-04 12:26:14 -07:00
Joe Groff
5e5cdc6be3 Runtime: Use 'once' instead of static local variable initialization.
The C++ ABI for static locals is a bit heavy compared to dispatch_once; doing this saves more than 1KB in runtime code size. Dispatch_once/call_once is also more likely to be hot because it's also used by Swift and ObjC code.

Alas, llvm::get_execution_seed() from llvm/ADT/Hashing.h still inflicts one static local initialization on us we can't override (without forking Hashing.h, anyway).
2015-11-30 12:08:12 -08:00
Joe Groff
fbd2e4d872 Rename @asmname to @_silgen_name.
This reflects the fact that the attribute's only for compiler-internal use, and isn't really equivalent to C's asm attribute, since it doesn't change the calling convention to be C-compatible.
2015-11-17 14:13:48 -08:00
Joe Groff
0fc6dc8e3b Runtime: Rename swift_stdlib_getDemangledTypeName to swift_getTypeName and decouple it from String.
Getting the name of a type seems like reasonable core runtime functionality, and something the runtime can cache on its side too. Have the function return a pointer to a raw string in memory owned by the runtime, and have it be wrappen in a Swift.String on the standard library side.
2015-11-17 08:37:50 -08:00
Greg Parker
e09027ca04 Fix the error message when a cast to a protocol type fails.
rdar://22936612
2015-11-17 01:08:31 -08:00
Joe Groff
dc26310f34 Runtime: Avoid instantiating call_once on Darwin by using cross-platform Lazy definitions. 2015-11-16 13:05:19 -08:00
Joe Groff
4abd79d1d0 Remove unnecessary #include. 2015-11-13 19:15:17 -08:00
Joe Groff
69a206229d Runtime: Start splitting out stubs only needed by the standard library.
Set up a separate libSwiftStubs.a archive for C++ stub functionality that's needed by the standard library but not part of the core runtime interface. Seed it with the Stubs.cpp and LibcShims.cpp files, which consist only of stubs, though a few stubs are still strewn across the runtime code base.
2015-11-11 17:28:57 -08:00
Joe Groff
f716bb2c3e Runtime: Let allocError take an initial value.
This will let us eventually do tagged pointer optimization for small error values. We don't take advantage of this in IRGen yet, but we can take advantage of it in the dynamic cast code in a few places, so it gets exercised, and doing this now will let us backward-deploy the optimization when we do implement it in the future.
2015-11-02 19:07:20 -08:00
Michael Gottesman
654ca4e0c5 Move Lazy.h from stdlib/public/runtime => include/swift/Basic
I am going to use this in a unittest for BlotMapVector.
2015-11-02 09:22:30 -08:00
Joe Groff
0cd5aa8c7c Change mangling for the Swift module from 'Ss' to 's'.
'Ss' appears in manglings tens of thousands of times in the standard library and is also incredibly frequent in other modules. This alone is enough to shrink the standard library by 59KB.

Swift SVN r32409
2015-10-02 22:39:44 +00:00
Xin Tong
dca508bfbb This is part of a series of commits to remove reference forwarding for
some of the ARC entry points. rdar://22724641. After this commit,
swift_retain_noresult will be completely replaced by swift_retain.
LLVMARCOpts pass is modified NOT to rewrite swift_retain to
swift_retain_noresult which forward no reference.

Swift SVN r32082
2015-09-18 21:56:50 +00:00
Michael Gottesman
121ef3ef9f Revert the series of commits for removing the return value from swift_retain_noresult.
I asked that the patches were split up so I could do post commit review.

This reverts commit r32059.
This reverts commit r32058.
This reverts commit r32056.
This reverts commit r32055.

Swift SVN r32060
2015-09-18 02:31:24 +00:00
Xin Tong
4e46dacc3d Completely replace swift_retain_noresult with swift_retain. this is part of a series of commits
to remove reference forwarding for some of the ARC entry points. rdar://22724641. After this
commit, swift_retain_noresult will be completely replaced by swift_retain and LLVMARCOpts.cpp
will no longer canonicalize swift_retain to swift_retain_noresult as now swift_retain returns no
reference.

Swift SVN r32058
2015-09-18 01:51:17 +00:00
Joe Groff
dd97410f94 IRGen: Check class constraint when casting metatypes to AnyObject.Type.
Fixes rdar://problem/22643781.

Swift SVN r31971
2015-09-15 21:40:15 +00:00
Joe Groff
fd820f53e6 Runtime: Factor out _dynamicCastToFunction.
NFC

Swift SVN r31895
2015-09-11 16:47:07 +00:00
Joe Groff
57ba78e4c5 Runtime: Fix goto-fail-ism in function casts.
'break' in a for loop breaks out of the loop, not the switch. Oops. Fixes rdar://problem/22576226.

Swift SVN r31888
2015-09-11 05:01:38 +00:00
Joe Groff
0bf684c30d Runtime: Fix leak in failure path for dynamicCastClassToValueViaObjCBridgeable.
Caught by the leaks runner on DollarReduce perf test. Fixes rdar://problem/22646089.

Swift SVN r31873
2015-09-11 00:05:25 +00:00
Joe Groff
3ff48d95c4 Runtime: Fix memory leak when swift_dynamicCast does a copy_on_success bridging cast.
In the course of preparing the bridging object to be bridged to a Swift value, we forwarded the cast flags to _dynamicCastUnknownClass unaltered, which caused a leak for copy-on-success casts since it introduced an extra retain. Fix this by simplifying _dynamicCastUnknownClass to have no retain/release behavior of its own. Fixes rdar://problem/22587077.

Swift SVN r31841
2015-09-10 00:51:10 +00:00
Joe Groff
773eadb9f2 IRGen/Runtime: Populate the runtime protocol conformance table with relative references.
By using relative references, either directly to symbols internal to the current TU, or to the GOT entry for external symbols, we avoid unnecessary runtime relocations, and we save space on 64-bit platforms, since a single image is still <2GB in size. For the 64-bit standard library, this trades 26KB of fake-const data in __DATA,__swift1_proto for 13KB of true-const data in __TEXT,__swift2_proto. Implements rdar://problem/22334380.

Swift SVN r31555
2015-08-28 18:07:22 +00:00
Roman Levenstein
0b5157b104 Reduce the amount of memory required for caching protocol conformances.
The reason for this patch:
- Currently, when we invoke swift_conformsToProtocol for the first time, we load ALL protocol conformances into conformances cache (to avoid rescanning the conformances section next time), which consumes about 50-70KB of memory even per minimal Swift application (e.g. hello-world app). While it may seem not so much, if you think about apps running on watchOS or writing daemons in Swift (and we have about 120 of those running on iOS), it is a lot of memory.
- In reality, only a couple of those conformances are used by applications, which means that most of the loaded conformances are useless and just consume the memory.

The implemented solution:
- Load only the conformances which were queried by calling swift_conformsToProtocol. Don’t try to load any other conformances, when not asked to do so.
- Use std::vector instead of std::deqeue for SectionsToScan. This shaves off another 4KB of memory, because std::deque reserves at least 4KB by default.

This patch does not seem to produce any detectable performance hit on our benchmark suite.

With these changes, the minimal "hello world" application consumes only 9.8KB, whereas before it used to consume 60KB.

rdar://22331482

Swift SVN r31310
2015-08-18 21:35:37 +00:00
David Farler
9e4d52c9cb Reinstate watchOS and other SDK overlays to build against the public SDKs.
Un-revert the below commits with the following addition:
add declarations for posix_spawn related APIs to SwiftPrivateDarwinExtras.
posix_spawn-related APIs aren't available in the public SDKs, so force past
the availability by creating our own stubs in the internal DarwinExtras
library.

r31244, r31245

CMake: build all platforms except watchOS using the public SDK

Covers rdar://problem/21145996.
A step towards rdar://problem/21099318.

Switch SDK overlays to use the public SDK

I had to cut the dependency on CrashReporterClient.h and reimplement
some of that code inline in the Swift runtime.  This shoud be OK (even
though not very clean), since the layout of CrashReporter sections is
ABI.

rdar://21099318

Swift SVN r31252
2015-08-14 22:09:49 +00:00
Dmitri Hrybenko
c75fc00cec Revert "CMake: build all platforms except watchOS using the public SDK"
This reverts commit r31244.  It broke the buildbot.

Swift SVN r31247
2015-08-14 18:56:15 +00:00
Dmitri Hrybenko
dd38372fb7 CMake: build all platforms except watchOS using the public SDK
Covers rdar://problem/21145996.
A step towards rdar://problem/21099318.

Swift SVN r31244
2015-08-14 17:26:04 +00:00
Mish Awadah
10bdef0936 Revert "CMake: build all platforms except watchOS using the public SDK"
This reverts commit cd3f1ba7d1ee2397817e1a165209fdeab8a1c004.

Reverting this b/c it is breaking buildbots with the following:
CMake Error at CMakeLists.txt:522 (message):
  CrashReporterClient library is required, but it was not found

Swift SVN r31047
2015-08-06 06:12:23 +00:00
Dmitri Hrybenko
271acdfcab CMake: build all platforms except watchOS using the public SDK
Covers rdar://problem/21145996.
A step towards rdar://problem/21099318.

Swift SVN r31041
2015-08-06 04:28:05 +00:00
Joe Groff
c3d4ced4a6 Runtime: Don't try to trim the nonexistent mangling prefix from protocol descriptors defined in ObjC.
Fixes rdar://problem/21887583.

Swift SVN r30409
2015-07-20 18:05:33 +00:00
Joe Groff
db0fea590e stdlib: Use unqualified names in 'print'.
Leave the qualification off of enum cases and type names when 'print'-ing them, but keep them on 'debugPrint'. (At least, at the outermost level; since ad-hoc printing of structs and tuples uses debugPrint, we'll still get qualification at depth, which kind of sucks but needs more invasive state management in print to make possible.) Implements rdar://problem/21788604.

Swift SVN r30166
2015-07-13 21:42:11 +00:00
Joe Groff
482c82c4f1 Runtime: Don't rewrap an NSError when trying to dynamic cast to NSError.
Fixes rdar://problem/21610394.

Swift SVN r30015
2015-07-09 04:32:09 +00:00
Devin Coughlin
007dfe15bf Runtime: Allow protocol extensions for weakly-linked Objective-C classes
Change ProtocolConformanceRecord::getCanonicalTypeMetadata() to return null if
the class metadata in the protocol conformance record is null. This fixes a
runtime crash in swift_conformsToProtocol when there is a protocol extension of
a missing weakly-linked class.

rdar://problem/21541766

Swift SVN r30012
2015-07-09 03:36:57 +00:00
Joe Groff
ab1f459a40 Runtime/stdlib: Non-verbatim bridging of metatypes.
Metatypes can't directly conform to _ObjectiveCBridgeable, but we can pretend they do by making a struct with the same ABI conform and returning that conformance when we call findBridgeWitness on a metatype. Fixes rdar://problem/16238475.

Swift SVN r29999
2015-07-08 23:23:55 +00:00
Joe Groff
c749f51bcb Don't include class metatypes in the "canBeClass" bucket.
The stdlib uses this condition to recognize types that represent classes without representation changing, which isn't true for metatypes. They will natively be pointers to the Swift type metadata instead of the ObjC class object, so a conversion step is necessary. This doesn't directly fix container bridging, but it prevents the runtime from trying to bridge verbatim metatypes without first changing them to ObjC representation.

Swift SVN r29998
2015-07-08 23:23:49 +00:00
Joe Groff
177575510d Runtime: Additional fix for casting class types to existential metatypes.
Tested in following commit.

Swift SVN r29961
2015-07-08 05:03:25 +00:00
Joe Groff
6760567659 Runtime: Handle casting from class types to class metatypes.
Implement casting support for taking an AnyObject and conditionally converting it to a T.Type for some class type. Fix some memory management bugs too, where we used swift_release to release an object not known to have Swift refcounting. This mostly fixes rdar://problem/16238475, though the SIL optimizer still improperly folds away attempted casts from NSObject to a class metatype, and I haven't yet validated bridging support for NSArray<Class>*.

Swift SVN r29956
2015-07-08 03:39:55 +00:00
Joe Groff
8ec59e5c11 Runtime: Implementation for generic typed boxes.
Provide new swift_{alloc,dealloc,project}Box2 entry points that allocate, project, and deallocate typed boxes using runtime-instantiated metadata. Give these a new metadata kind, so that external tools recognize the difference and can interpret the metadata appropriately.

Swift SVN r29714
2015-06-26 00:06:17 +00:00
Joe Groff
a8edb34623 Runtime: Allow for "throws" variance in dynamic casts.
Fixes rdar://problem/21300246.

Swift SVN r29363
2015-06-10 20:27:28 +00:00