Commit Graph

132 Commits

Author SHA1 Message Date
Doug Gregor
dd8c668aa8 Import NSDictionary as Dictionary<NSObject, AnyObject>
Fixes <rdar://problem/16870626>.


Swift SVN r18907
2014-06-15 10:44:23 +00:00
Doug Gregor
5bb6969af3 Type checker support for dictionary downcasting.
This is the semantic-analysis portion of <rdar://problem/16847470>.


Swift SVN r18900
2014-06-14 18:27:38 +00:00
Doug Gregor
47fbf0d166 Extend dictionary upcast support for handle mixed bridging/upcasting.
This allows dictionary upcasting where the key is bridged and the
value is not, or vice-versa. Finishes <rdar://problem/17289296>.


Swift SVN r18895
2014-06-14 15:48:12 +00:00
Doug Gregor
33ecf5888d For now, only allow bridged upcasting of dictionaries when the destination’s key and value have object representation.
Tights up the semantics of <rdar://problem/17289296> slightly.

Swift SVN r18888
2014-06-14 04:34:47 +00:00
Doug Gregor
0f1f518a17 Type checker: allow dictionary upcasts, including bridging upcasts.
This is the type checker portion of <rdar://problem/17114737>.

Swift SVN r18887
2014-06-14 04:34:44 +00:00
Nadav Rotem
2a7b156427 Handle CheckedCastKind::Identical in a few places that I missed.
Swift SVN r18868
2014-06-13 16:35:21 +00:00
Doug Gregor
1789c4ccbc Collapse CollectionBridgedConversionExpr into CollectionUpcastConversionExpr.
Semantically, these expressions handle the same thing: an upcast of a
collection when the underlying element types of the source are
subtypes of or can be bridged to subtypes of the destination. This
reduces some branching in the type checker and eliminates duplication
in SILGen.

Swift SVN r18865
2014-06-13 16:32:47 +00:00
Joe Groff
ca42a7b377 Turn on metatype-to-object conversions.
Swift SVN r18850
2014-06-13 01:01:38 +00:00
Doug Gregor
5ca3882b06 Rename array upcast/bridge expressions to "collection".
This is staging for dictionary bridging upcasts.


Swift SVN r18840
2014-06-12 21:41:55 +00:00
Joe Groff
cf9e0d2624 Sema: Introduce metatype-to-object conversions.
Allow class metatypes (including class-constrained existential metatypes) to be treated as subtypes of AnyObject, and single-@objc protocol metatypes to be treated as subtypes of the Protocol class from objc. No codegen support yet, so this is hidden behind a frontend flag for now.

Swift SVN r18810
2014-06-11 23:06:23 +00:00
Joe Pamer
1914df72f3 Begin making locators non-optional for constraints.
One difficulty in generating reasonable diagnostic data for type check failures has been the fact that many constraints had been synthesized without regard for where they were rooted in the program source. The result of this was that even though we would store failure information for specific constraints, we wouldn't emit it for lack of a source location. By making location data a non-optional component of constraints, we can begin diagnosing type check errors closer to their point of failure.

Swift SVN r18751
2014-06-09 17:49:46 +00:00
Doug Gregor
fb2f72ab48 Eliminate type checker support for forced contextual downcasting via "expr!".
We removed this feature when we changed casting syntax, but left it in
the type checker to help migrate code via a Fix-It. We no longer need
it.



Swift SVN r18729
2014-06-06 05:10:15 +00:00
Doug Gregor
fb93d14aec Generalize downcasting through an Objective-C class to a bridged value type.
Rather than only allowing downcasting from AnyObject, allow it for any
class or Objective-C existential type, e.g., "NSArray() as
Int[]". While here, reduce our reliance on implicit conversions when
checking bridging. This is most of <rdar://problem/16972956>, but 'is'
still doesn't work properly in these cases.


Swift SVN r18693
2014-06-02 15:44:48 +00:00
Doug Gregor
c1de0bf27f Suggest "as T" rather than "!" for implicit downcast fixes <rdar://problem/17029454>.
Swift SVN r18626
2014-05-25 19:48:44 +00:00
Joe Pamer
1c53181667 Again, fix two problems with implicit conversions:
- rdar://problem/16776273, wherein conversions between nil and .None were permitted
due to an implicit conversion between nil and COpaquePointer.
- rdar://problem/16877526, where we needed to add new equality overloads to handle
conversions between nil and .None given the supression of user conversions.

(Some minor tweaks this time around for better interoperability with AnyObject.)

Swift SVN r18498
2014-05-21 18:56:35 +00:00
Joe Pamer
1d34a88477 Revert "Fix two problems with implicit conversions: - rdar://problem/16776273, wherein conversions between nil and .None were permitted due to an implicit conversion between nil and COpaquePointer. - rdar://problem/16877526, where we needed to add new equality overloads to handle conversions between nil and .None given the supression of user conversions. (Thanks to Ted for the overloads and test.)"
This reverts commit r18473.

Swift SVN r18477
2014-05-21 00:28:46 +00:00
Joe Pamer
f469d8f1f6 Fix two problems with implicit conversions:
- rdar://problem/16776273, wherein conversions between nil and .None were permitted
due to an implicit conversion between nil and COpaquePointer.
- rdar://problem/16877526, where we needed to add new equality overloads to handle
conversions between nil and .None given the supression of user conversions.
(Thanks to Ted for the overloads and test.)

Swift SVN r18473
2014-05-20 23:53:34 +00:00
Doug Gregor
1cb05e5b0b When force-casting AnyObject to a contextual type, bridge through Objective-C.
Previously, we were relying on user-defined conversions to perform the
final bridging from the Objective-C class type (e.g., NSString) to its
Swift value type (String). That works for NSString <-> String, but not
for arbitrary arrays. Use the bridgeFromObjectiveC() witness instead,
so we can handle:

  let obj: AnyObject = ...
  let strArr: String[] = obj!

Fixes <rdar://problem/16952771>.

Swift SVN r18422
2014-05-19 15:32:06 +00:00
Doug Gregor
2cea48a91d Unify ArrayDowncastExpr handling with ConditionalCheckedCastExpr handling.
The latter has some brilliant code to deal with differing levels of
optionality, binding inner optionals etc. Unifying these code paths
makes array downcasts work when the source has (possibly
implicitly-wrapped) optional type, e.g.,

var arrImplicitOpt: AnyObject[]! = nsarr
if let strArr = arrImplicitOpt as String[] {
  println("String array contains \(strArr)")
} else {
  println("Not a string array")
}

Another part of <rdar://problem/16952771> and the array-bridging story.


Swift SVN r18392
2014-05-19 05:14:39 +00:00
Doug Gregor
e7ad745be0 Support downcasting from AnyObject to a bridged value type.
This allows us to cast "through" a bridged class type in an "as" case,
e.g.,

  if let str = obj as String { ... }

where obj is an AnyObject (or optional/implicitly unwrapped optional
thereof). In such cases, we perform a checked cast to the
corresponding class type (NSString in this case) and then convert the
(optional!) result down to the value type.

Addresses the main part of <rdar://problem/15288553>, but we still
have trouble with "is" with optionals, and the #if false'd out
testcase incorrectly fails due to <rdar://problem/16953860>.

Swift SVN r18347
2014-05-18 20:30:39 +00:00
Doug Gregor
97977a2bb4 Zap some dead code.
Swift SVN r18346
2014-05-18 20:30:34 +00:00
Doug Gregor
0aba627a86 Reinstate "Drive a wedge between array upcasts and array bridged
upcasts." 
Reinstate "Restrict the array-bridged conversion to non-verbatim
bridging." 
Reinstate "[stdlib] Fix T[].bridgeFromObjectiveC" 
Reinstate "[stdlib] Fix T[].bridgeFromObjectiveC" 
Reinstate "[stdlib] Move _arrayBridgedDownCast to Foundation"
 Reinstate "Replace "can" with "cannot" in a message." 
Reinstate "Implement support for non-verbatim T[] -> AnyObject[]
upcasts."  

This reinstates commit r18291. 
This reinstates commit r18290. 
This reinstates commit r18288. 
This reinstates commit r18287. 
This reinstates commit r18286. 
This reinstates commit r18293. 
This reinstates commit r18283.

John fixed the issue in r18294.


Swift SVN r18299
2014-05-18 03:36:09 +00:00
Michael Gottesman
263dca4b47 Revert "Drive a wedge between array upcasts and array bridged upcasts."
Revert "Restrict the array-bridged conversion to non-verbatim bridging."
Revert "[stdlib] Fix T[].bridgeFromObjectiveC"
Revert "[stdlib] Fix T[].bridgeFromObjectiveC"
Revert "[stdlib] Move _arrayBridgedDownCast to Foundation"
Revert "Replace "can" with "cannot" in a message."
Revert "Implement support for non-verbatim T[] -> AnyObject[] upcasts."

This reverts commit r18291.
This reverts commit r18290.
This reverts commit r18288.
This reverts commit r18287.
This reverts commit r18286.
This reverts commit r18293.
This reverts commit r18283.

Sorry for the number of reverts, but I needed to do this many to get a clean
revert to r18283.

Swift SVN r18296
2014-05-18 02:42:56 +00:00
Doug Gregor
3a8a652370 Drive a wedge between array upcasts and array bridged upcasts.
Previously, we were relying on overly-general subtyping to determine
when we could perform an array upcast, which pushed some non-verbatim
bridging through that path. Instead, restrict array upcasts to classes
and ObjC existentials, and use bridging casts for the other cases.

Swift SVN r18291
2014-05-18 00:42:01 +00:00
Doug Gregor
937504bc5e Restrict the array-bridged conversion to non-verbatim bridging.
This allows, e.g., String[] -> NSString[] and String[] -> NSObject[]. Part of <rdar://problem/16952238>.

Swift SVN r18290
2014-05-18 00:42:00 +00:00
Doug Gregor
8215dff6c3 A trailing closure means that a keyword argument can be omitted, not wrong.
Fixes the type checker issue reported in <rdar://problem/16909180>.

Swift SVN r18260
2014-05-17 17:59:17 +00:00
Joe Pamer
b10a2bf48a Fix regression in implicit conversions of implicitly unwrapped optional AnyObject types to their contextual types. (rdar://problem/16922332)
Swift SVN r18203
2014-05-16 18:13:35 +00:00
Joe Pamer
50ef69c745 Allow for implicit forcing of enumerated unchecked optional values. (rdar://problem/16265970, rdar://problem/16569776, rdar://problem/16931457)
Swift SVN r18145
2014-05-16 00:06:39 +00:00
Joe Pamer
a74c44a6e4 Fix two crashing bugs related to checked downcasts - rdar://problem/16093456 and rdar://problem/16892211.
Swift SVN r18118
2014-05-15 18:36:44 +00:00
John McCall
fc57ea2cf8 Add __conversion as a known identifier.
Swift SVN r18068
2014-05-14 08:19:20 +00:00
Doug Gregor
80a85d3670 Improve handling of repeated keyword arguments missing at the call site.
Fixes <rdar://problem/16900465>.

Swift SVN r18043
2014-05-14 00:20:04 +00:00
Joe Pamer
5d95457efc Disallow operator overloads that require implicit conversions for all arguments (rdar://problem/16785445)
Swift SVN r18019
2014-05-13 20:09:50 +00:00
Joe Pamer
1e5b9116d4 More array casting work:
- Continue adding support for checked downcasts of array types (rdar://problem/16535104)
- Fix non-bridged array conversions post-r17868
- Fix rdar://problem/16773693
- Add tests for NSArray coercions to and from Array<T>

Swift SVN r17957
2014-05-12 20:49:42 +00:00
Doug Gregor
9c03b4f924 Miscellaneous cleanups for array bridging in the type checker.
Use protocol conformance checks whenever we want to determine whether
a value type is bridged to an Objective-C class, which is simpler and
more robust. Clean up some of the type checker code around bridging,
using TypeBase::isEqual() to compare types and looking through type
sugar more regularly.

As part of this, move Array's conformance to
_ConditionallyBridgedToObjectiveC into the Foundation overlay. This
lets us use NSArray as the bridged type (which is clearer than using
CocoaArray), and follows what we're doing for dictionary bridging.


As part of this, move Array's bridged-to-


Swift SVN r17868
2014-05-11 05:13:24 +00:00
Joe Groff
d6957d0328 Make existential-to-concrete metatype casts work.
This mostly falls out from the metatype cast infrastructure, but we need to generalize some Sema and SILGen code to accept AnyMetatypeType. Concrete-to-existential metatypes will need more runtime checking that isn't implemented, so raise a 'not implemented' error on those for now.

Swift SVN r17798
2014-05-09 20:57:55 +00:00
Doug Gregor
05a283a58c When dealing with argument tuple conversions, keep the parentheses around
This is fairly ugly, because we're halfway between a-function-type-takes-a-tuple and a-function-type-takes-a-set-of-parameters. However, it's another step toward -strict-keyword-arguments.

Swift SVN r17727
2014-05-08 23:20:47 +00:00
Joe Groff
1dce36edd2 Make 'T.self is U.Type' work.
Fix up all of type-checking, SILGen, IRGen, and the runtime to support checked casts of metatypes. <rdar://problem/16847453>

Swift SVN r17719
2014-05-08 22:55:14 +00:00
Joe Pamer
f3e6b31887 Fix a problem with the type checker trying to create user conversion expressions out of like-types. (rdar://problem/16837295)
Swift SVN r17669
2014-05-08 02:07:53 +00:00
Joe Pamer
709da29301 Implement checks for conditionally bridged types when performing a bridged conversion between array types. (rdar://problem/16540403)
Swift SVN r17660
2014-05-08 00:58:30 +00:00
Doug Gregor
36cbcccbe9 Generalize constraint application under -strict-keyword-arguments.
Introduce a new locator kind for argument/parameter comparisons that
tracks both the argument and the parameter, which we will eventually
use in diagnostics more regularly. For now, this helps us smooth over
scalar-to-tuple/tuple-to-tuple/tuple-to-scalar nonsense when dealing
with calls.

Fix a pile of fallout from this change.

Swift SVN r17648
2014-05-07 22:36:49 +00:00
Doug Gregor
3bd0d6976f Reimplement constraint application for strict keyword arguments.
Swift SVN r17647
2014-05-07 22:36:47 +00:00
Joe Pamer
2eedc06d66 Begin adding plumbing for the type checker to accept "forward" bridged array conversions. (rdar://problem/16540403)
Swift SVN r17640
2014-05-07 19:45:37 +00:00
Doug Gregor
8802bbc8eb Factor out the argument/parameter matching of matchCallArguments(). NFC
We're going to want to re-use the argument/parameter matching of
matchCallArguments() elsewhere, so separate it from the constraint system.

Swift SVN r17626
2014-05-07 13:09:50 +00:00
Doug Gregor
41a6c97d97 Generalize call argument/parameter patching to work on tuple type element arrays.
This is a small step toward subsuming scalar-to-tuple and
tuple-to-scalar conversions.

Swift SVN r17623
2014-05-07 12:23:57 +00:00
Joe Pamer
edb4946f66 Begin updating type checking of array upcasts to conform with the new spec.
Also, call through DaveA's new entry point for upcasts on Array<T>.

Swift SVN r17564
2014-05-06 21:32:22 +00:00
Joe Pamer
d22ffa8cb8 Re-lazify the addition of equatable conformances to imported enum types. (rdar://problem/16808612)
Rather than force conformances to Equatable to be added to all imported enumeration types outright, change them back to being lazily added. We can then handle situations where new overloads of '==' are introduced during constraint generation by re-writing the relevant overload disjunction constraint to include the newly forced declarations as bind options.

Swift SVN r17557
2014-05-06 19:56:29 +00:00
Jordan Rose
3e917be738 Use full DeclNames for dynamic lookup of calls.
Previously, we were just using the base name, which resulted in massive
inefficiency when dealing with Clang (we basically had to check every
selector in the system to see if it had the same first selector piece).
I've hacked ConstraintSystem a bit to carry a map from UnresolvedDotExpr
to the ApplyExpr that consumes it, so that we can use the full DeclName
and look up methods by full selector.

Now that dynamic lookup is fast, re-enable it for the
Foundation_bridge.swift test. (r17520 actually provided most of the benefit.)

This does break selector lookup on AnyObject when doing selector splitting,
and slightly regresses diagnostics when you try to call a method on AnyObject
and forget a parameter name.

<rdar://problem/16808651>. Part of the Playground performance efforts.

Swift SVN r17524
2014-05-06 02:35:08 +00:00
Doug Gregor
26a3594481 Keyword arguments: handle scalar-to-tuple conversions better.
Swift SVN r17503
2014-05-05 23:58:19 +00:00
Joe Pamer
11441abc4b Rather than special-case NSString conversions in the type checker, utilize the _BridgedToObjectiveC protocol conformance on the type being converted if available. This will allow us to more broadly accommodate bridged conversions between types.
Swift SVN r17482
2014-05-05 19:40:03 +00:00
Doug Gregor
254e5741fd Strict keyword arguments: allow trailing closures in scalar-to-tuple conversions.
Swift SVN r17449
2014-05-05 15:42:16 +00:00