Commit Graph

122 Commits

Author SHA1 Message Date
Erik Eckstein
5e80555c9b demangler: put the demangler into a separate library
Previously it was part of swiftBasic.

The demangler library does not depend on llvm (except some header-only utilities like StringRef). Putting it into its own library makes sure that no llvm stuff will be linked into clients which use the demangler library.

This change also contains other refactoring, like moving demangler code into different files. This makes it easier to remove the old demangler from the runtime library when we switch to the new symbol mangling.

Also in this commit: remove some unused API functions from the demangler Context.

fixes rdar://problem/30503344
2017-03-09 13:42:43 -08:00
Joe Groff
294913e114 Fix _stdlib_getErrorDefaultUserInfo to have the signature the runtime expects.
The ABI mismatch here would cause a crash in cases when the Foundation overlay wasn't available, or its implementation of swift_Foundation_getErrorDefaultUserInfo wasn't dynamically resolvable, such as in a stripped statically linked binary. Fixes rdar://problem/29173132.
2017-03-08 14:56:02 -08:00
Joe Groff
0ec27bdecf Runtime: Bridging an Error to NSError requires only checking its domain.
The lazy population of the NSError fields is ordered such that the domain is written into the object last with acq/rel ordering, so another thread only needs to check the domain to see whether the initialization has already happened. (The initialization itself is idempotent, so we can optimistically perform the initialization and discard the results if we race.) Checking the user info is redundant, and is also wrong for real NSError objects, since [NSError errorWithDomain:d code:c userInfo:nil] will in fact plant nil in the userInfo field of the object, leading us to attempt to bridge an already-native NSError.
2017-03-08 13:10:23 -08:00
Arnold Schwaighofer
39fa2f0228 Use the swift calling convention for swift functions
Use the generic type lowering algorithm described in
"docs/CallingConvention.rst#physical-lowering" to map from IRGen's explosion
type to the type expected by the ABI.

Change IRGen to use the swift calling convention (swiftcc) for native swift
functions.

Use the 'swiftself' attribute on self parameters and for closures contexts.

Use the 'swifterror' parameter for swift error parameters.

Change functions in the runtime that are called as native swift functions to use
the swift calling convention.

rdar://19978563
2017-02-14 12:17:57 -08:00
Hugh Bellamy
a5a4880075 Remove extern "C" uses of SWIFT_RT_ENTRY_VISIBILITY 2017-01-22 18:32:17 +00:00
Hugh Bellamy
63cf2d561e Remove extern "C" from uses of SWIFT_RUNTIME_EXPORT 2017-01-22 18:32:17 +00:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Erik Eckstein
c34c0e4bbc Mangling: Don’t hardcode the mangling prefixes in symbols selected by SELECT_MANGLING 2016-12-14 16:39:00 -08:00
Erik Eckstein
c73ac007d1 Mangling: support new mangled symbols in ErrorObject.mm 2016-12-13 11:01:58 -08:00
Saleem Abdulrasool
c67a33fbc7 build: remove TARGET_SDKS from the runtime
The runtime and stubs are built for ALL targets, not specific ones.  This allows
us to configure when cross-compiling to Windows again.  Collapse the dual
addition of the swiftRuntime into a single build.  This unifies the runtime
build for the apple and non-Apple SDKs.  The difference here was the ObjC
interop sources.  In order to deal with that unification add a CPP macro to
indicate whether the interop sources should be included or not.
2016-12-03 17:02:44 -08:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
practicalswift
f44686d825 [gardening] Fix trailing whitespace in *.cfg.in, *.html, *.mm and *.sil files 2016-10-29 14:06:43 +02:00
Doug Gregor
73e2143213 [SE-0112] Provide default implementations for CustomNSError requirements.
Provide default implementations for all of the CustomNSError requirements:
  * errorDomain: default to the name of the enum type
  * errorCode: default to the same thing "_code" gets, e.g., the enum tag or
    raw value
  * errorUserInfo: default to empty

This makes it significantly easier to customize just one aspect of the
NSError view of an error type, e.g., just the user-info dictionary,
without having to write boilerplate for the others. This was actually
part of SE-0112, but I missed it in the original implementation and we
thought it was an amendment.

Fixes rdar://problem/23511842.
2016-09-02 10:33:15 -07:00
Dmitri Gribenko
dfb4f56e55 runtime: rename _TMps8Hashable to HashableProtocolDescriptor 2016-08-31 09:53:39 -07:00
Dmitri Gribenko
b162f60070 runtime: make _SwiftNativeNSError use the Hashable conformance, if available
If the Swift error wrapped in a _SwiftNativeNSError box conforms to
Hashable, the box now uses the Swift's conformance to Hashable.

Part of rdar://problem/27574348.
2016-08-09 00:49:20 -07:00
Doug Gregor
360ed82872 Reinstate cod epart of "Eliminate race in swift_bridgeErrorToNSError.""
This partially reverts commit
47f01ee98d. In other words, I'm bring
back the changes to the Swift runtime that should eliminate the data
race in swift_bridgeErrorToNSError, but leaving the actual test
disabled while we do more investigation.
2016-08-03 23:53:31 -07:00
Doug Gregor
47f01ee98d Revert "Eliminate race in swift_bridgeErrorToNSError."
This reverts commit e07e88706d. The
crash came back, so there's obviously more I need to investigate here:

  https://ci.swift.org/job/swift-PR-osx-smoke-test/881/testReport/junit/Swift(macosx-x86_64)/stdlib/ErrorProtocol_swift/
2016-08-03 23:48:33 -07:00
Doug Gregor
e07e88706d Eliminate race in swift_bridgeErrorToNSError.
Huge thanks to John for noting that 'consume' didn't provide the
guarantees we wanted, and to Michael G. for getting a TSan build up
and running to identify/verify this race.

It's possible that this is overlay strict, and that we only need to
look at the domain to ensure that the code and userInfo are
visible. However, TSan seems to prefix the form in this patch, so
we'll be more conservative for now.

Fixes rdar://problem/27541751.
2016-08-03 15:21:15 -07:00
Joe Groff
bc8433f186 Runtime: Implement an opaque 'SwiftValue' ObjC class to hold bridged values.
If there's no better mapping for a Swift value into an Objective-C object for bridging purposes, we can fall back to boxing the value in a class. This class doesn't have any public interface beyond being `NSObject`-conforming in Objective-C, but is recognized by the Swift runtime so that it can be dynamically cast back to the boxed type.
2016-07-15 15:56:25 -07:00
Doug Gregor
823c24b355 [SE-0112] Rename ErrorProtocol to Error.
This is bullet (5) of the proposed solution in SE-0112, and the last
major piece to be implemented.
2016-07-12 10:53:52 -07:00
Doug Gregor
b0f9317765 [SE-0112] Add error protocols LocalizedError, RecoverableError, CustomNSError
An error type can conform to one or more of these new protocols to
customize its behavior and representation. From an implementation
standpoint, the protocol conformances are used to fill in the
user-info dictionary in NSError to interoperate with the Cocoa
error-handling system.

There are a few outstanding problems with this implementation,
although it is fully functional:
  * Population of the userInfo dictionary is currently eager; we
  should use user info providers on platforms where they are
  available.
  * At present, the Swift dynamic casting machinery is unable to unbox a
  _SwiftNativeNSError when trying to cast from it to (e.g.) an
  existential, which makes it impossible to retrieve the
  RecoverableError from the NSError. Instead, just capture the original
  error---hey, they're supposed to be value types anyway!---and use that
  to implement the entry points for the informal
  NSErrorRecoveryAttempting protocol.

This is part (1) of the proposal solution.
2016-07-12 10:53:52 -07:00
Joe Groff
4ce8645501 Wanton microoptimization for -[_SwiftNativeNSError classForCoder]
We have a static cache var for [NSError class], so save an objc_msgSend here
2016-05-09 11:18:34 -07:00
Joe Groff
f7455a8409 Runtime: Archive _SwiftNativeNSErrors as NSErrors.
_SwiftNativeNSError is a runtime-private subclass, and NSError's inherited NSCoding implementation doesn't handle the Swift payload of bridged errors. We can't really archive arbitrary Swift values anyway yet, so just archive bridged NSError subclasses as regular NSErrors. Fixes rdar://problem/23051728.
2016-05-06 14:31:16 -07:00
Joe Groff
233a2bad9e Runtime: Fix _SwiftNativeNSError's copyWithZone:.
The default implementation from NSObject doesn't know how to copy the Swift error payload, and the object's immutable anyway, so we just need to retain and return the object we already have.
2016-05-06 11:44:23 -07:00
John McCall
50d58b2732 Add a lot of calling-convention annotations to the standard library / runtime.
The general rule here is that something needs to be SWIFT_CC(swift)
if it's just declared in Swift code using _silgen_name, as opposed to
importing something via a header.

Of course, SWIFT_CC(swift) expands to nothing by default for now, and
I haven't made an effort yet to add the indirect-result / context
parameter ABI attributes.  This is just a best-effort first pass.

I also took the opportunity to shift a few files to just implement
their shims header and to demote a few things to be private stdlib
interfaces.
2016-05-04 10:31:23 -07: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
f51e708a8f Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-01-04 12:25:25 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Max Moiseev
200be71583 Merge remote-tracking branch 'origin' into swift-3-api-guidelines 2015-12-23 10:28:04 -08:00
Joe Groff
e1589a0a3a Runtime: Implement convertNSErrorToErrorType and v.v. in Swift.
These are compiler hooks that belong in the Foundation overlay; they don't need to be in the core runtime.
2015-12-22 14:41:23 -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
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
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
c6b6d346bd Move the SwiftNativeNSXXXBase classes and stubs to SwiftStubs.
Move the ObjC internal declarations to a public runtime header so they can be shared, and rename _swift_deallocClassInstance to the more descriptive name swift_rootObjCDealloc (and make it only available with ObjC interop).
2015-11-13 08:37:12 -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
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
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
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
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
John McCall
62fd20393c Make _swift_allocNilObjCError public so that it can actually
be found by the runtime.

Fixes rdar://21184674, at least as long as your application
links against the Foundation overlay.

Swift SVN r29460
2015-06-17 22:17:49 +00:00
Joe Groff
5cdc9f3fd1 Runtime/stdlib: Slightly better implementations of errorInMain and unexpectedError.
Implement these backstops in the stdlib instead of the runtime, where we can at least interpolate the error value and give a slightly more informative error. Could still be improved by handing the source location down from the point of the crash instead of using the location from the stdlib source. Somewhat addresses rdar://problem/20807523.

Swift SVN r29401
2015-06-16 18:57:09 +00:00
Ted Kremenek
9f9bb725cf Rename '_ErrorType' to 'ErrorType'.
Swift SVN r28293
2015-05-07 21:59:29 +00:00