Commit Graph

3150 Commits

Author SHA1 Message Date
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
Joe Groff
50af58b62a Merge pull request #4030 from jckarter/27671131
Runtime: Fix undersized allocation for out-of-line optional cast result.
2016-08-05 09:44:11 -07:00
John McCall
a6e1e87585 Add implicit conversions and casts from T:Hashable <-> AnyHashable.
rdar://27615802
2016-08-04 23:13:27 -07:00
Joe Groff
2508c46051 Runtime: Fix undersized allocation for out-of-line optional cast result.
We accounted for the size difference between T and T? in the inline case, but not the out-of-line case. rdar://problem/27671131
2016-08-04 16:59:51 -07:00
Joe Groff
b8c66b218a Merge pull request #4020 from jckarter/metatype-universal-bridging
Runtime: Handle universal bridging of class metatypes.
2016-08-04 15:18:29 -07:00
Joe Groff
c3fed97431 Runtime: Handle Protocol objects through universal bridging too. 2016-08-04 15:03:14 -07:00
Joe Groff
f6ea4fe766 Runtime: Handle universal bridging of class metatypes.
Class metatypes bridge to their `Class` objects in Objective-C.
2016-08-04 14:17:11 -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
e83fb64917 [Runtime] Extract an embedded NSError when dynamic casting to an Error existential.
SILGen already attempts to extract an embedded NSError when
type-erasing to an Error existential; make the runtime do the same
thing dynamically.

Huge thanks to Joe Groff who noticed that I missed this path.
2016-08-03 23:22:30 -07:00
Michael Gottesman
a0fca3a8f0 Merge pull request #3965 from gottesmm/support_per_host_cmake_and_tsan_of_runtime_via_buildscript
Support per host cmake and tsan of runtime via buildscript
2016-08-03 21:48:24 -07:00
Michael Gottesman
06a70d3942 [cmake] Add cmake support for only applying tsan to the swift stdlib/runtime. 2016-08-03 17:53:57 -07:00
Doug Gregor
4b8b7bb878 [NSError bridging] Rename runtime entry points for _getErrorEmbeddedNSError.
This clarifies the 'Indirect' case. Thanks, Dmitri!
2016-08-03 15:59:01 -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
Doug Gregor
d2195318d2 [NSError bridging] Use embedded NSError when erasing types to Error existentials.
Imported Cocoa error types are represented by structs wrapping an
NSError. The conversion from these structs to Error would end up
boxing the structs in _SwiftNativeNSError, losing identity and leading
to a wrapping loop.

Instead, extract the embedded NSError if there is one. In the Swift
runtime, do this as part of the dynamic cast to NSError, using a (new,
defaulted) requirement in the Error type so we can avoid an extra
runtime lookup of the protocol. In SILGEn, do this by looking for the
_BridgedStoredNSError protocol conformance when erasing to an Error
type. Fixes SR-1562 / rdar://problem/26370984.
2016-08-03 09:20:04 -07:00
Joe Groff
77df2865e9 Merge pull request #3829 from jckarter/cast-structural-type-from-boxed-anyobject
Runtime: Let structural types be cast out of boxed AnyObjects too.
2016-07-28 14:04:45 -07:00
Joe Groff
d206bb5aa1 Runtime: Let structural types be cast out of boxed AnyObjects too. 2016-07-28 12:52:46 -07:00
Dmitri Gribenko
561ac46679 stdlib: move a function from runtime to stubs
This function is not needed in the runtime.
2016-07-28 01:19:31 -07:00
Roman Levenstein
880be3be4f Remove unsafeAddress(of:)
rdar://problem/18589289
2016-07-26 19:57:26 -07:00
Dmitri Gribenko
53c424409d stdlib: add AnyHashable
Implements SE-0131 "Add AnyHashable to the standard library".
2016-07-26 03:10:52 -07:00
Joe Groff
b1fb1fa3ea Runtime: Handle bridging from ObjC objects to Any or boxed types. 2016-07-25 06:01:21 -07:00
Joe Groff
32b50c624d stdlib: Remove _isBridgedToObjectiveC from _ObjectiveCBridgeable.
All generic bridgeable types can bridge for all their instantiations now. Removing this ferrets out some now-unnecessary traps that check for unbridgeable parameter types.
2016-07-25 06:01:21 -07:00
practicalswift
a87d170b81 [gardening] Improve consistency in header formatting. 2016-07-24 21:36:25 +02:00
John McCall
892c903b1b Fix embarrassing copy/paste error and enable Dave's test. 2016-07-23 12:14:44 -07:00
John McCall
232a314a9f Teach the dynamic-cast machinery how to cast collection element types. 2016-07-23 10:30:10 -07:00
Luke Larson
74e0498015 Revert "Update master to build with Xcode 8 beta 3, OS X 10.12, iOS 10, tvOS 10, and watchOS 3 SDKs."
This reverts commit 62d1fa760c.
2016-07-19 15:18:17 -07:00
Mishal Shah
62d1fa760c Update master to build with Xcode 8 beta 3, OS X 10.12, iOS 10, tvOS 10, and watchOS 3 SDKs. 2016-07-19 22:31:34 +02:00
Joe
67dccb283e [SE-0095] Code feedback changes; Any is parsed as a keyword
- Any is made into a keyword which is always resolved into a TypeExpr,
allowing the removal of the type system code to find TheAnyType before
an unconstrained lookup.
- Types called `Any` can be declared, they are looked up as any other
identifier is
- Renaming/redefining behaviour of source loc methods on
ProtocolCompositionTypeRepr. Added a createEmptyComposition static
method too.
- Code highlighting treats Any as a type
- simplifyTypeExpr also does not rely on source to get operator name.
- Any is now handled properly in canParseType() which was causing
generic param lists containing ‘Any’ to fail
- The import objc id as Any work has been relying on getting a decl for
the Any type. I fix up the clang importer to use Context.TheAnyType
(instead of getAnyDecl()->getDeclaredType()). When importing the id
typedef, we create a typealias to Any and declare it unavaliable.
2016-07-19 12:01:37 -07:00
Joe
3938d5682a [SE-0095] [Runtime], [Demangler], & AST printer updated to new composition syntax
- All parts of the compiler now use ‘P1 & P2’ syntax
- The demangler and AST printer wrap the composition in parens if it is
in a metatype lookup
- IRGen mangles compositions differently
    - “protocol<>” is now “swift.Any”
    - “protocol<_TP1P,_TP1Q>” is now “_TP1P&_TP1Q”
- Tests cases are updated and added to test the new syntax and mangling
2016-07-19 12:01:37 -07:00
Joe Groff
9cba38537e Runtime: Forward SwiftValue -description and -debugDescription to the boxed value.
Following the example of SwiftObject, use swift_getSummary to get the description string for a Swift value as the description of a boxed SwiftValue.
2016-07-18 12:21:54 -07:00
Joe Groff
e25c751693 Merge pull request #3538 from jckarter/id-as-any-swiftvalue-box
Runtime: Implement an opaque 'SwiftValue' ObjC class to hold bridged values.
2016-07-18 09:05:37 -07:00
Dmitri Gribenko
1edf5326a1 runtime: remove workaround for Clang 3.5
All supported OSes have Clang 3.6+.
2016-07-15 21:44:01 -06: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
Robert Widmann
dc88e51321 Nuke entry-point-based process args
Provides a new fallback for Process arguments for those instances where we do
not own main (e.g. Frameworks, Objective-C owns main.m or main.c, etc.). This
includes a number of platform-specific specializations of argument grabbing
logic and a new thread-safe interface to Process.unsafeArgv.

main()  | _NSGetArgc/_NSGetArgv    | /proc/self/cmdline     | __argc/__argv
--------|--------------------------|------------------------|---------------
Scripts | OS X, iOS, tvOS, watchOS | Linux, FreeBSD, Cygwin | Windows

For interpreted Swift where we must filter out the arguments we now do so by
loading the standard library and calling into new SPI to override the arguments
that would have been grabbed by the runtime. This implementation completely
subsumes the use of the entry point  '_stdlib_didEnterMain' and it will be
removed in a future commit.
2016-07-14 01:06:19 -07:00
Joe Groff
02640fc1bc Runtime: Look through existentials when bridging to id. 2016-07-12 19:21:13 -07:00
Slava Pestov
67f7e773dd Runtime: Add preliminary _swift_bridgeUnknownToObject() entry point. 2016-07-12 13:49:39 -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
John McCall
8d1ea1c001 Fix foreign type metadata creation to not call the initializer
under the lock.

Unfortunately, unit-testing this is gratuitously difficult
because of C++ problems.  (Fixed in C++17, apparently.)  Will
be tested by a future patch which creates a nested foreign
type.
2016-07-08 15:21:34 -07:00
Saleem Abdulrasool
3d174c372a stdlib: be more DLL friendly on Windows
When the standard library is built dynamically on COFF targets, the public
interfaces must be decorated in order to generate a proper DLL which can be
confused by the dependent libraries.  When the exported interface is used, it
must be indirectly addressed.  This can be done manually in code or the MS
extension of `__declspec(dllimport)` may be used to indicate to the compiler
that this symbol be addressed indirectly.  This permits building more pieces of
the standard library dynamically on Windows.
2016-07-06 17:51:31 -07:00
Dmitri Gribenko
ef557a11ff runtime: rename 'getReflectableConformance()' to 'unwrapExistential()' 2016-07-05 14:13:54 -07:00
Dmitri Gribenko
a4fb03f1eb runtime: simplify getReflectableConformance() 2016-07-05 14:13:23 -07:00
Dmitri Gribenko
acac328eaa stdlib: remove _Reflectable 2016-07-05 14:13:23 -07:00
Roman Levenstein
40b8fd58fe Remove copy constructors and assignment operators from RelativeDirectPointerImpl.
There were places were RelativeDirectPointers were copied using bitwise copies, which is semantically wrong. This patch makes sure it cannot happen anymore.
2016-06-29 17:20:12 -07:00
Arnold Schwaighofer
8cae9874e3 Fix the assert 2016-06-27 15:29:32 -07:00
Arnold Schwaighofer
542a8b410a Fast-path dynamicCast from a class instance in an existential container to AnyObject
rdar://26981164
2016-06-27 13:29:09 -07:00
Saleem Abdulrasool
d9ba70a595 runtime: tweak the compilation
Always include all the sources as we cannot include object libraries to be
subsumed.  This allows us to conditionally build the swift runtime for foreign
hosts simultaneously (e.g. cross compile for Linux and Windows simultaneously).
2016-06-22 21:38:15 -07:00
Saleem Abdulrasool
d771054c7b build: use the new object format property
Simplify the ELF checks based on review comments from Dimitri Gribenko.
2016-06-22 09:37:56 -07:00
Saleem Abdulrasool
bbb82d4fe4 build: build the section_magic libraries for ELFish targets
Build the section_magic libraries for all the ELFish SDKs that have been
configured.  This allows us to build for SDKs which dont match the object format
at the same time (e.g. Linux and Windows).
2016-06-21 23:01:52 -07:00
William Dillon
244b448bcd Fixed stack execution for arm 2016-06-20 18:01:28 +00:00