Commit Graph

311 Commits

Author SHA1 Message Date
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
Joe Groff
80caa5a67c Runtime: Fix assertion failure in Casting tests.
Swift SVN r29327
2015-06-06 00:01:28 +00:00
Joe Groff
9a33c50f04 Runtime: Look through artificial subclasses when generating metatype names.
Fixes rdar://problem/20307995.

Swift SVN r29325
2015-06-05 23:37:33 +00:00
Joe Groff
86b4cf91ec whitespace
Swift SVN r29157
2015-05-30 00:41:45 +00:00
Joe Groff
c45dccb335 Runtime: Handle dynamic casts from ErrorType classes to NSError.
Move the check for NSError earlier so that it covers class cases, and put a check in _dynamicCastFromExistential to avoid the identical-class fast path when NSError's involved. Fixes rdar://problem/21116814.

Swift SVN r29130
2015-05-29 02:31:54 +00:00
Enrico Granata
8a5726d966 Revert 28997
The consensus is against this change and we're going for a much more targeted fix in PlaygroundLogger only



Swift SVN r28999
2015-05-24 23:16:57 +00:00
Enrico Granata
05a038e818 Make it so that the runtime demangler does not print the Swift standard library module name
This changes things like Swift.Dictionary<Swift.Int, Swift.AnyObject> to Dictionary<Int, AnyObject>

It has been suggested that playgrounds would benefit from not showing the fully qualified name.
Playgrounds use the runtime demangler to obtain type names, and honestly, I do not see enough value in those qualifiers being printed out to justify hackery in PlaygroundLogger or separate demangling logic



Swift SVN r28997
2015-05-24 22:25:12 +00:00
Ted Kremenek
9f9bb725cf Rename '_ErrorType' to 'ErrorType'.
Swift SVN r28293
2015-05-07 21:59:29 +00:00
Joe Groff
9b4dc24721 Runtime: (Almost) cleanse of global constructors and destructors.
Configure the runtime to build with -Wglobal-constructors, and Lazy-fy almost everything that gets flagged. (I gave "swift_isaMask" a pass since that's almost definitely hot enough to warrant a static initialization.) Make some improvements to the Lazy wrapper, using aligned_storage to ensure that it's trivially constructed and destructed.

Swift SVN r28199
2015-05-06 04:59:56 +00:00
Enrico Granata
3386d89af4 When demangling as string type names that come from module names of the form __lldb_expr_<something> in a Swift program, hide the module
The __lldb_expr modules are special as in they are autogenerated by LLDB and meant to not be user-accessible, so showing them adds visual noise for no user benefit

I am open to the notion of adding a flag to swift-demangle to the same effect, but that seems much lower priority



Swift SVN r28195
2015-05-06 02:49:08 +00:00
Dave Abrahams
c5b64b3503 [stdlib] Fix another bug in _getSuperclass
When passed an existential, there is no class object and we should
return nullptr.

Swift SVN r28159
2015-05-05 06:47:54 +00:00
Dave Abrahams
6f4e1bb309 [stdlib] Fixes for _getSuperclass
This internal function is used by mirrors and thus must work correctly

Swift SVN r28154
2015-05-05 05:40:20 +00:00
Joe Groff
00f7520888 IRGen/Runtime: Combine the separate per-convention function metadata caches into one.
We have enough flag bits on function types now to warrant stashing an extra word in the metadata key alongside the arguments and results, so add one, and pack the number of arguments, function convention, and 'throws' bit in there. This lets us merge the separate metadata caches for thick/thin/block/C functions into one, saving a bit of runtime memory, and simplifying a bunch of repetitive code in the runtime and IRGen.

This also fixes a subtle bug we had where the runtime getFunctionTypeMetadata function expected the result argument to be passed in the arguments array, but IRGen was passing it as a separate argument, which would have caused function type metadata to fail to be uniqued by result type.

Swift SVN r27651
2015-04-23 22:58:11 +00:00
Joe Groff
c4ec47ddea IRGen/Runtime: Metadata for @convention(c) function types.
For now, C&P a new metadata cache for C function pointers, like we do for blocks and thin types.

Swift SVN r27595
2015-04-22 18:06:23 +00:00
Joe Groff
86157d533e Runtime: Reenable metatype casting code when ObjC interop is disabled.
Fixes rdar://problem/20583365, and incidentally gets test/Interpreter/layout_reabstraction.swift to work without ObjC interop as well.

Swift SVN r27557
2015-04-22 03:49:12 +00:00
Joe Groff
4c4069d9e9 Runtime: Use 'nullptr' instead of 'nil'.
'nil' is only defined if the ObjC runtime is imported.

Swift SVN r27545
2015-04-22 00:45:07 +00:00
Joe Groff
79ee6f21c4 Runtime: Recognize class and @objc existential metatypes as class instances in swift_isClassOrObjCExistential.
Fixes rdar://problem/20131232.

Swift SVN r27534
2015-04-21 18:24:10 +00:00
Dave Abrahams
7cd1429f59 [stdlib] Add _getSuperclass(AnyClass)
We'll need this to handle class mirrors properly

Swift SVN r27500
2015-04-20 21:58:24 +00:00
Joe Groff
fcf535d682 Runtime: Implement ObjC-free metatype dynamic casts.
Swift SVN r27414
2015-04-17 05:30:35 +00:00
Joe Groff
1b2fcd1852 IRGen/Runtime: AnyObject never has a witness table, even if it isn't @objc.
@objc protocols aren't supported with an ObjC runtime, but we still want values of AnyObject type to be word-sized. Handle this by turning the binary "needsWitnessTable" condition into a "dispatch strategy" enum, so we can recognize the condition "has no methods, so neither swift nor objc dispatch" as distinct from either swift or ObjC protocol representations. Assign this dispatch strategy when we lower AnyObject. Should be NFC for the ObjC-enabled build.

(It would also be beneficial for the ObjC-runtime-enabled version of Swift if AnyObject weren't an @objc protocol; that would mean we could give it a canonical protocol descriptor in the standard library, among other things. There are fairly deep assumptions in Sema that AnyObject is @objc, though, and it's not worth disturbing those assumptions right now.)

Reapplying with updates to the runtime unit tests.

Swift SVN r27341
2015-04-16 00:24:51 +00:00
Joe Groff
af6e1933f0 Revert "IRGen/Runtime: AnyObject never has a witness table, even if it isn't @objc."
This reverts commit r27338. Runtime unit tests need to be updated.

Swift SVN r27340
2015-04-16 00:13:52 +00:00
Joe Groff
2b93411ba7 IRGen/Runtime: AnyObject never has a witness table, even if it isn't @objc.
@objc protocols aren't supported with an ObjC runtime, but we still want values of AnyObject type to be word-sized. Handle this by turning the binary "needsWitnessTable" condition into a "dispatch strategy" enum, so we can recognize the condition "has no methods, so neither swift nor objc dispatch" as distinct from either swift or ObjC protocol representations. Assign this dispatch strategy when we lower AnyObject. Should be NFC for the ObjC-enabled build.

(It would also be beneficial for the ObjC-runtime-enabled version of Swift if AnyObject weren't an @objc protocol; that would mean we could give it a canonical protocol descriptor in the standard library, among other things. There are fairly deep assumptions in Sema that AnyObject is @objc, though, and it's not worth disturbing those assumptions right now.)

Swift SVN r27338
2015-04-15 23:53:25 +00:00
Joe Groff
225a0ebd70 Runtime: Non-ObjC-interoperable version of ErrorObject implementation.
This gets the runtime building again with ObjC interop disabled, though the standard library still has issues.

Swift SVN r27326
2015-04-15 20:27:24 +00:00
Joe Groff
c0a2994564 AST: Start printing function types with @convention instead of old attributes.
And update tests to match.

Swift SVN r27262
2015-04-13 22:51:34 +00:00
Greg Parker
69757f2b60 Fix 32-bit build after r27225.
On 32-bit, swift_allocBox() returns something that implicitly 
converts to BoxPair; it doesn't return a BoxPair directly.


Swift SVN r27226
2015-04-11 01:20:18 +00:00