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.
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).
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.
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.
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.
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).
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.
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.
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.
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.
'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
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
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
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
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
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
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
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
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
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
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
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
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
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
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