Commit Graph

335 Commits

Author SHA1 Message Date
Hugh Bellamy
f001b7562b Use relatively new LLVM_FALLLTHROUGH instead of our own SWIFT_FALLTHROUGH 2017-02-12 10:47:03 +07:00
Hugh Bellamy
1d2aa8dcbd Cleanup uses of SWIFT_RUNTIME_EXPORT in implementation files (#7127) 2017-01-31 19:38:53 -08:00
Hugh Bellamy
d030ae4c94 Cleanup uses of SWIFT_RT_ENTRY_VISIBILITY (#7103) 2017-01-31 15:53:14 -08:00
Hugh Bellamy
818099ecbe Rename swift_unreachable to swift_runtime_unreachable 2017-01-26 15:31:34 +00:00
Hugh Bellamy
5a59971b95 Move Unreachable.h from include/Basic to include/Runtime 2017-01-26 15:31:33 +00:00
Hugh Bellamy
05a50fd978 Remove extern "C" from uses of SWIFT_RUNTIME_STDLIB_INTERFACE 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
30a88d38e6 [gardening] Fix recently introduced typos 2017-01-06 21:16:02 +01:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Saleem Abdulrasool
75533d9dac Merge pull request #6385 from hughbe/runtime
Fix building the runtime from Windows
2016-12-21 10:02:22 -08:00
Joe Groff
2e0cb9c0a2 Runtime: getDynamicType can't drill into existentials when producing a concrete metatype.
For a value of an opaque generic type `<T> x: T`, the language currently defines `type(of: x)` and `T.self` as both producing a type `T.Type`, and the result of substituting an existential type by `T == P` gives `P.Protocol`, so the `type(of:)` operation on `x` can only give the concrete protocol metatype when `x` is an existential in this case. The optimizer understood this rule, but the runtime did not, causing SR-3304.
2016-12-19 11:03:52 -08:00
Hugh Bellamy
7b66b579b1 Add various unreachable annotations to the runtime 2016-12-19 15:54:50 +00:00
practicalswift
38be6125e5 [gardening] C++ gardening: Terminate namespaces, fix argument names, ...
Changes:
* Terminate all namespaces with the correct closing comment.
* Make sure argument names in comments match the corresponding parameter name.
* Remove redundant get() calls on smart pointers.
* Prefer using "override" or "final" instead of "virtual". Remove "virtual" where appropriate.
2016-12-17 00:32:42 +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
Saleem Abdulrasool
5217db0d73 runtime: clean up unused variable warning
classType is unused without ObjC interop.  Simplify the code a bit by increasing
the scope covered by the SWIFT_OBJC_INTEROP.  It also silences the warning.
2016-12-11 21:42:23 -08:00
Erik Eckstein
9f8b68ae11 Mangling: use macros instead of hard-coded swift symbol names.
This makes it easier to switch between the old and new mangling scheme.
2016-12-02 15:55:30 -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
Slava Pestov
4e4d281aa7 stdlib: Rework swift_typeName() to use _swift_buildDemanglingForMetadata()
Previously we had two separate mechanisms to turn a metatype
into a string. The swift_typeName() function was used to print
the metatype in a human-readable fashion, whereas the
_swift_buildDemanglingForMetadata() was used when naming
generated generic Objective-C classes.

Unify them, since what swift_typeName() does is redundant;
instead of going directly from the metatype to a human-readable
string, we can get the mangling, and print that using the
demangler.

This fixes some issues with unnecessary parenthesis when
printing function types, and also allows Objective-C classes
to be instantiated with nested generic types as parameters.
2016-11-18 00:39:14 -08:00
Joe Groff
2b4cba8499 Runtime: Call Set/Dictionary casting hooks in the stdlib with the correct calling convention.
We neglected to pass down the Hashable witness table parameters, leading to Heisenbugs because we would call into invalid witness pointers occasionally when loading the Hashable conformance from corrupted metadata. Fixes rdar://problem/28022201.
2016-10-12 12:16:40 -07:00
Doug Gregor
2942b850ad Merge pull request #4898 from DougGregor/tuple-casting
Runtime/standard library: fix tuple printing, reflection, and casting
2016-09-21 10:09:03 -07:00
Doug Gregor
c9ebcc592e [Runtime] Generalize dynamic casting between tuple types.
This allows dynamic casting to succeed between tuple types with
different element types, converting each element in turn. Fixes
rdar://problem/19892202.
2016-09-21 09:00:23 -07:00
swift-ci
81ee414f7a Merge pull request #4894 from DougGregor/tuple-casting 2016-09-20 21:04:34 -07:00
Doug Gregor
87908c8a1b [Runtime] Handle tuple/tuple dynamic casts that add/remove labels.
Introduce narrow support for tuple/tuple dynamic casts that merely add
or remove labels, but require the element types to match exactly. This
gets us back to allowing the same correct dynamic casts as in Swift
3.0, when labels were completely ignored.
2016-09-20 17:05:07 -07:00
Doug Gregor
1a8189814a [Runtime] Include tuple labels when printing the runtime name of a type.
When we started recording labels within the metadata for a tuple type,
we failed to print those labels when rendering the type name from
metadata.
2016-09-20 13:47:34 -07:00
Joe Groff
1a52e3f2c2 SR-0140: Bridge Optionals to nonnull ObjC objects by bridging their payload, or using a sentinel.
id-as-Any lets you pass Optional to an ObjC API that takes `nonnull id`, and also lets you bridge containers of `Optional` to `NSArray` etc. When this occurs, we can unwrap the value and bridge it so that inhabited optionals still pass into ObjC in the expected way, but we need something to represent `none` other than the `nil` pointer. Cocoa provides `NSNull` as the canonical "null for containers" object, which is the least bad of many possible answers. If we happen to have the rare nested optional `T??`, there is no precedented analog for these in Cocoa, so just generate a unique sentinel object to preserve the `nil`-ness depth so we at least don't lose information round-tripping across the ObjC-Swift bridge.

Making Optional conform to _ObjectiveCBridgeable is more or less enough to make this all work, though there are a few additional edge case things that need to be fixed up. We don't want to accept `AnyObject??` as an @objc-compatible type, so special-case Optional in `getForeignRepresentable`.

Implements SR-0140 (rdar://problem/27905315).
2016-09-20 13:04:09 -07:00
Greg Parker
cd9a8afd5d Revert "SR-0140: Bridge Optionals to nonnull ObjC objects by bridging their payload, or using a sentinel." (#4820) 2016-09-15 18:18:07 -07:00
Joe Groff
cfa9cd9a08 SR-0140: Bridge Optionals to nonnull ObjC objects by bridging their payload, or using a sentinel.
id-as-Any lets you pass Optional to an ObjC API that takes `nonnull id`, and also lets you bridge containers of `Optional` to `NSArray` etc. When this occurs, we can unwrap the value and bridge it so that inhabited optionals still pass into ObjC in the expected way, but we need something to represent `none` other than the `nil` pointer. Cocoa provides `NSNull` as the canonical "null for containers" object, which is the least bad of many possible answers. If we happen to have the rare nested optional `T??`, there is no precedented analog for these in Cocoa, so just generate a unique sentinel object to preserve the `nil`-ness depth so we at least don't lose information round-tripping across the ObjC-Swift bridge.

Making Optional conform to _ObjectiveCBridgeable is more or less enough to make this all work, though there are a few additional edge case things that need to be fixed up. We don't want to accept `AnyObject??` as an @objc-compatible type, so special-case Optional in `getForeignRepresentable`.

Implements SR-0140 (rdar://problem/27905315).
2016-09-14 15:50:13 -07:00
Dmitri Gribenko
dfb4f56e55 runtime: rename _TMps8Hashable to HashableProtocolDescriptor 2016-08-31 09:53:39 -07:00
John McCall
219d093ef4 Fix the cast optimizer to handle CF/NS bridging correctly,
and fix the dynamic cast runtime to handle class + enum casts
to AnyHashable correctly.
2016-08-23 07:22:28 -07:00
John McCall
b937bdf717 Dynamic casts to AnyObject should succeed for an arbitrary source
type because we can always make a SwiftValue.

rdar://26268575
2016-08-19 10:36:18 -07:00
Joe Groff
f998c624e6 Runtime: Add a convenient -[_SwiftValue _swiftTypeName] method for debugging.
This makes it a bit easier to diagnose unexpected boxing problems in the debugger, by allowing `po [value _swiftTypeName]` to work, instead of forcing users to know how to call `swift_getTypeName` from lldb themselves.
2016-08-15 13:53:59 -07:00
Dmitri Gribenko
783fafa36a runtime: rename SwiftValue to _SwiftValue (it is a private class) 2016-08-10 15:45:16 -07:00
Dmitri Gribenko
e6f23fb7d3 runtime: move two AnyHashable-related entrypoints to SwiftHashableSupport.h 2016-08-09 00:49:20 -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
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
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
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
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
d206bb5aa1 Runtime: Let structural types be cast out of boxed AnyObjects too. 2016-07-28 12:52:46 -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
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
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