Commit Graph

311 Commits

Author SHA1 Message Date
Doug Gregor
9c530f1d93 [Runtime] Add witness-table parameters to _ObjectiveCBridgeable witnesses.
The witness-table parameters got added to all witnesses as part of the
resilience work, but the hardcoded witness table in the runtime's
dynamic-casting infrastructure didn't get updated. Nothing seems to be
relying on these right now, so we cannot actually *test* it, but I've
verified that the types line up.
2016-03-18 16:30:53 -07:00
Doug Gregor
67dad6041c [Runtime] Use the _ObjectiveCBridgeable._ObjectiveCType type witness directly.
This lets us eliminate the _getObjectiveCType() value witness, which
was working around the lack of proper type witness metadata in witness
tables. Boilerplate -= 1.
2016-03-18 16:11:38 -07:00
Max Moiseev
cf4bafe9e3 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-03-03 13:22:03 -08:00
Roman Levenstein
99fd8b6080 Rename some macros based on the PR review comments.
- use  the SWIFT prefix for all macros
- make names of some macros shorter
2016-02-25 05:31:00 -08:00
Roman Levenstein
de3b850ce8 Use more descriptive names for calling conventions.
Rename RuntimeCC into DefaultCC
Rename RuntimeCC1 into RegisterPreservingCC
Remove RuntimeCC0 because it was identical to DefaultCC.
2016-02-25 05:31:00 -08:00
Roman Levenstein
68b6181642 Annotate runtime functions using the newly introduced annotations from runtime/Config.h.
This makes sure that runtime functions use proper calling conventions, get the required visibility, etc.

We annotate the most popular runtime functions in terms of how often they are invoked from Swift code.
- Almost all variants of retain/release functions are annotated to use the new calling convention.
- Some popular non-reference counting functions like swift_getGenericMetadata or swift_dynamicCast are annotated as well.

The set of runtime functions annotated to use the new calling convention should exactly match the definitions in RuntimeFunctions.def!
2016-02-25 05:30:59 -08:00
Dmitri Gribenko
3d3d4540e1 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-20 14:37:49 -08:00
Dmitri Gribenko
7e88bd7b2f stdlib: remove dead code 2016-02-20 02:30:46 -08:00
Dmitri Gribenko
65d840c0ae stdlib: lowercase cases in Optional and ImplicitlyUnwrappedOptional 2016-02-18 00:40:33 -08:00
Max Moiseev
3a3984877a Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-15 15:43:34 -08:00
Joe Groff
f7291b21ec Runtime: Build with -fvisibility=hidden.
...and explicitly mark symbols we export, either for use by executables or for runtime-stdlib interaction. Until the stdlib supports resilience we have to allow programs to link to these SPI symbols.
2016-02-08 08:06:02 -08:00
Max Moiseev
61c837209b Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-04 16:13:39 -08:00
Harlan Haskins
b55d8d9c3c [Runtime] Add backtrace reporting on fatalError in debug builds 2016-01-29 13:42:06 -08:00
Max Moiseev
08e1e4a043 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-01-11 16:51:11 -08:00
Greg Parker
35448a1179 Merge pull request #861 from jder/fix-fail-cast-overrelease
[SR-392][Runtime] Avoid overrelease when failing cast to protocol
2016-01-09 08:40:45 -08:00
Greg Parker
8ee8adb36e [stdlib] Move protocol conformance checking and caching into its own file. 2016-01-09 01:00:31 -08:00
Slava Pestov
b45cec0dff Runtime: Fix a warning 2016-01-08 19:21:23 -08:00
Jesse Rusak
30224016c5 [SR-392][Runtime] Avoid overrelease when failing cast to protocol
Fixes a regression introduced in e09027ca which causes us to release
the wrong value when a cast fails.
2016-01-08 19:02:37 -05:00
Andrew Trick
9cf84c24ca Fix a leak when interpolating optional references.
The runtime support for casting optionals introduced in 35cb1afa
resulted in a redundant retain.

Fixes SR-459: Weakened optionals don't zero...
rdar://24057977.
2016-01-08 13:51:02 -08:00
Greg Parker
f91dd6fa60 Merge pull request #857 from jder/fix-existential-cast-leak
[SR-426][Runtime] Use _fail to ensure src is deallocated in cast
2016-01-08 01:44:35 -08:00
Doug Gregor
1a38e0ad3b Merge branch 'master' into swift-3-api-guidelines 2016-01-06 15:32:55 -08:00
Greg Parker
3f6356110b Remove a stale comment.
This comment should have been removed by d0be84e.
2016-01-04 23:12:52 -08:00
Max Moiseev
f51e708a8f Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-01-04 12:25:25 -08:00
Jesse Rusak
2aaa4846e8 [SR-426][Runtime] Use _fail to ensure src is deallocated in cast
This case was previously ignoring the DestroyOnFailure flag, so
we had a leak if a cast to an existential metatype failed for
certain types (tuples, structs, etc).
2016-01-03 15:07:34 -05:00
Chris Lattner
a30ae2bf55 Merge pull request #836 from zachpanz88/new-year
Update copyright date
2015-12-31 19:36:14 -08:00
Joe Groff
d0be84e1f3 Runtime: Refactor conformance cache initialization to include installation of the dyld callbacks.
This more cleanly groups together the initialization steps needed to warm up the conformance cache, so redundant work doesn't need to be done by other interested parties (such as the type-by-name lookup @lhoward's working on).
2015-12-31 17:11:17 -08:00
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