Commit Graph

2771 Commits

Author SHA1 Message Date
Chris Lattner
40d5448bde simplify some code in constraints::matchCallArguments, NFC.
Swift SVN r21125
2014-08-09 00:17:44 +00:00
Joe Pamer
b13083b774 Provide better fixits for optionals-as-booleans (rdar://problem/17833968)
We now provide fixits for if-expressions, point out the actual conditional expression (as opposed to the surrounding expression),
support unary '!' applications and avoid printing type variables in the diagnostic.

Swift SVN r20992
2014-08-04 00:58:25 +00:00
Doug Gregor
60b92937e8 Use the dynamic casting infrastructure for casts that bridge from Objective-C.
A checked cast such as "x as String" or "x as? [String]", where x is of
class or Objective-C existential type, is now handled as a normal
checked cast rather than a Sema-generated call to the corresponding
witness. This eliminates a pile of hairy code from constraint
application and takes a step toward <rdar://problem/17408934>.

The part of the switch_objc.swift test I removed wasn't testing
anything useful; that's what <rdar://problem/17408934> is about.



Swift SVN r20970
2014-08-03 16:39:28 +00:00
Doug Gregor
79d5c69d5a Remove CheckedCastKind::ArrayDowncastBridged. Nobody F'ing Cares about it now.
Swift SVN r20730
2014-07-30 04:26:16 +00:00
Joe Pamer
1fec0afbd0 Disallow value-to-optional conversions between argument and parameter types when resolving overloads for operators applied to nil literal operands.
This is a targeted fix to address rdar://problem/16848110 ("Disallow non-optionals to be compared to nil") and its associated dupes.

Swift SVN r20716
2014-07-29 23:24:36 +00:00
Joe Groff
cd799f6797 Sema: Coerce structural lvalues when binding to non-lvalue type variables.
Modify TypeBase::getRValueType to structurally convert lvalues embedded in tuple and paren types. Inside the constraint solver, coerce types to rvalues based on the structural 'isLValueType' test rather than shallow 'is<LValueType>' checking. Fixes <rdar://problem/17507421>, but exposes an issue with call argument matching and lvalues <rdar://problem/17786730>.

Swift SVN r20442
2014-07-23 23:07:21 +00:00
Dave Abrahams
1438d617cd [stdlib] Rename ConstUnsafePointer=>UnsafePointer
Swift SVN r20318
2014-07-22 17:10:54 +00:00
Dave Abrahams
21669b3aee [stdlib] Add "Mutable" to [Autoreleasing]UnsafePointer
UnsafePointer becomes UnsafeMutablePointer
AutoreleasingUnsafePointer becomes AutoreleasingUnsafeMutablePointer

Swift SVN r20316
2014-07-22 16:56:23 +00:00
Joe Groff
8b05b42534 Sema: Lock in '!' lvalue support.
I'll reuse the EnableOptionalLValues option to stage in work on lvalue support for '?' and AnyObject lookup, but remove the conditionals on '!'.

Swift SVN r20270
2014-07-21 19:16:24 +00:00
Chris Lattner
bc481f0fe1 implement <rdar://problem/16859927> remove the underscore in "auto_closure"
autoclosure is one work, not two.



Swift SVN r20253
2014-07-21 15:23:50 +00:00
Jordan Rose
14196453cc Add a special diagnostic when a type has no accessible initializers.
Rather than just saying "'Foo' is not constructible with '()'", say
"'Foo' cannot be constructed because it has no accessible initializers",
which would help framework authors realize what they did wrong.

<rdar://problem/17717714>

Swift SVN r20232
2014-07-20 19:52:24 +00:00
Joe Groff
4155d52323 Sema: Preserve lvalue-ness through implicit forces of IUOs.
Swift SVN r20209
2014-07-19 17:11:21 +00:00
Joe Groff
ed88875794 Sema: Propagate lvalue-ness through the postfix ! operator.
Create a new "OptionalObject" constraint kind in the solver that relates an optional type to its payload type, preserving lvalue-ness, and use it to model ForceValueExpr under the optional-lvalues regime.

Swift SVN r20140
2014-07-18 04:37:00 +00:00
Joe Pamer
83d01d30a4 Allow for bridge conversions for conversions to CVarArgType, as opposed to only other bridge types. (rdar://problem/17687255)
The idea here is that for the bridge type, we'll up-convert to NSObject, which conforms to CVarArgType.

Swift SVN r20122
2014-07-17 23:32:53 +00:00
Joe Pamer
6a75d3d675 Now that the most problematic user conversions have been removed from the runtime (thanks, Doug!), we can remove the operator-specific user conversion handling code matchCallArguments. Doing so cleans things up a bit, and addresses rdar://problem/17540796, rdar://problem/17012694 and rdar://problem/16958107.
Swift SVN r19871
2014-07-12 00:41:27 +00:00
Doug Gregor
bd9ead4371 Remove -[no-]strict-keyword-arguments.
Swift SVN r19850
2014-07-11 16:58:35 +00:00
Doug Gregor
7decdc3e27 Eliminate the “verbatim” return bit from TypeChecker::getBridgedToObjC.
Nobody cares; NFC

Swift SVN r19758
2014-07-09 22:58:41 +00:00
Chris Lattner
02999cac51 Reinstate the @ on the @objc attribute. This is largely a revert of r19555 with a few tweaks.
Swift SVN r19706
2014-07-08 21:50:34 +00:00
Doug Gregor
0c31ff5681 Move bridging conversions into the type checker.
Previously, bridged value types and their corresponding Objective-C
classes allow inter-conversion via a number of user-defined conversion
functions in the Foundation module. Instead, make this a general
feature of the type checker so we can reason about it more
directly. Fixes <rdar://problem/16956098> and
<rdar://problem/17134986>, and eliminates 11 (half) of the
__conversion functions from the standard library and overlays.

A few notes:
  - The XCTest changes are because a String can no longer directly
  conform to CVarArg: this is a Good Thing (TM), because it should be
  ambiguous: did you mean to pass it as an NSString or a C string?
  - The Objective-C representations for the bridged collections are
  hard-coded in the type checker. This is unfortunate and can be
  remedied by adding another associated type to the
  _BridgedToObjectiveC protocol.

Swift SVN r19618
2014-07-07 18:04:18 +00:00
Jordan Rose
b892892871 Disallow use of TypeBase::getAs/isa/castAs with sugared types.
These methods all act on the desugared type, so the result would always be
false/null.

Also removes a few mistaken uses of getAs caught by this change.

Swift SVN r19585
2014-07-06 22:07:26 +00:00
Chris Lattner
7a56499d61 Start making @objc not start with an @ sign:
- Change the parser to accept "objc" without an @ sign as a contextual
   keyword, including the dance to handle the general parenthesized case.
 - Update all comments to refer to "objc" instead of "@objc".
 - Update all diagnostics accordingly.
 - Update all tests that fail due to the diagnostics change.
 - Switch the stdlib to use the new syntax.

This does not switch all tests to use the new syntax, nor does it warn about
the old syntax yet.  That will be forthcoming.  Also, this needs a bit of 
refactoring, which will be coming up.



Swift SVN r19555
2014-07-04 05:57:57 +00:00
Joe Groff
10fae3e228 Remove -enable-string-pointer-conversion staging flag.
Swift SVN r19524
2014-07-03 18:43:20 +00:00
Joe Groff
f9440d0cb7 Sema: Correctly resolve the metatype of '.member's found by optional unwrapping.
If the lookup was resolved by optional unwrapping, unwrap the metatype when we apply the solution so we don't try to create an invalid metatype conversion from T?.Type to T.Type. Fixes <rdar://problem/17542185>.

Swift SVN r19500
2014-07-03 03:00:46 +00:00
Joe Groff
3c539b7f24 Sema: Look through optional types for .member lookup.
When we see a '.member' expression in optional context, look for the member in the optional's object type if it isn't found in Optional itself. <rdar://problem/16125392>

Swift SVN r19469
2014-07-02 16:33:45 +00:00
Doug Gregor
eb8bd789d5 Only reflect NSString categories (outside of Foundation) on String.
This removes my bridging over-generalization <rdar://problem/17526544>.


Swift SVN r19430
2014-07-01 21:43:23 +00:00
Joe Groff
a796c76ae4 Sema: Allow string-to-pointer argument conversions.
Allow a String value to be implicitly converted to ConstUnsafePointer<{UInt8,Int8,Void}> by string-to-pointer conversion, when enabled by a staging flag.

Swift SVN r19366
2014-06-30 20:46:04 +00:00
Dave Abrahams
e35c581677 Revert "Sema: Allow string-to-pointer argument conversions."
This reverts commit r19349, which was printing garbage to the console
and breaking the Sema/availability.swift test

Swift SVN r19360
2014-06-30 19:57:20 +00:00
Joe Groff
a548fa3523 Sema: Allow string-to-pointer argument conversions.
Allow a String value to be implicitly converted to ConstUnsafePointer<{UInt8,Int8,Void}> by string-to-pointer conversion.

Swift SVN r19349
2014-06-30 18:44:11 +00:00
Joe Groff
fc392cc942 Sema: Strip out inout conversion constraint systems.
JoeP helped tweak things to ensure that pointer conversions are still
considered, but we no longer need the disjunction on InOutExprs to accommodate
user-defined inout conversions.

This causes some regressions in error reporting:

<rdar://problem/17489983> inout type mismatches complain about '@lvalue inout T'
<rdar://problem/17489894> inout not rejected as operand to assignment operator

Swift SVN r19306
2014-06-27 21:50:33 +00:00
Joe Groff
22f0e39ef2 Remove the -enable-pointer-conversions flag and dead code.
Swift SVN r19278
2014-06-26 23:56:59 +00:00
Joe Groff
ab1e99772a Sema: Disallow pointer conversions in operators.
We still don't want 'array1 == array2' to accidentally work via pointer comparison. However, we still admit pointer conversions when an inout is involved. 'pointer == &x' is desirable, and more importantly, explicit about what the user wants.

Swift SVN r19271
2014-06-26 23:06:32 +00:00
Joe Groff
fb7ef8c2a1 Sema: Allow inout-to-pointer conversions for pointers to arrays.
We need to admit a potential inout-to-pointer conversion even if the inout references an array, because we can have pointers to arrays. Add a short-circuit so that array-to-pointer conversions always beat inout-to-pointer conversions; both solutions could otherwise be considered valid for an UnsafePointer<Void>, and passing a pointer to the array reference rather than to the array data would be very bad.

Swift SVN r19270
2014-06-26 22:37:27 +00:00
Joe Groff
22288baf09 Sema: Tweak pointer conversion scoring to better favor no-conversion cases.
Patch by JoeP. This fixes cases where intermediate type variables introduced by generics or closures caused the type checker to favor UnsafePointer-to-ConstUnsafePointer conversions over no-conversion solutions.

Swift SVN r19198
2014-06-26 00:21:20 +00:00
Joe Groff
ab6b9cc4e3 Sema: Favor pointer parameter solutions that don't convert types.
Fixes ambiguity errors that arise from using pointer operators or constructors which could be satisfied multiple ways due to pointer conversions.

Swift SVN r19172
2014-06-25 18:23:30 +00:00
John McCall
385879beea Remove the CheckedCastKind from SIL dynamic casts.
It is straightforward and less redundant to recover this
information from the operand types.

Swift SVN r19056
2014-06-20 22:43:53 +00:00
Joe Groff
dba8a23d64 AST: Refactor get*UnsafePointerDecl() lookups onto the AST context.
These types are needed by enough of the stack now that it makes sense to centralize their lookup and caching onto the AST context like other core types.

Swift SVN r19029
2014-06-20 03:02:29 +00:00
Joe Groff
08a48565fb Sema: Introduce intrinsic pointer argument conversions.
Add primitive type-checker rules for pointer arguments. An UnsafePointer argument accepts:

- an UnsafePointer value of matching element type, or of any type if the argument is UnsafePointer<Void>,
- an inout parameter of matching element type, or of any type if the argument is UnsafePointer<Void>, or
- an inout Array parameter of matching element type, or of any type if the argument is UnsafePointer<Void>.

A ConstUnsafePointer argument accepts:

- an UnsafePointer, ConstUnsafePointer, or AutoreleasingUnsafePointer value of matching element type, or of any type if the argument is ConstUnsafePointer<Void>,
- an inout parameter of matching element type, or of any type if the argument is ConstUnsafePointer<Void>, or
- an inout or non-inout Array parameter of matching element type, or of any type if the argument is ConstUnsafePointer<Void>.

An AutoreleasingUnsafePointer argument accepts:

- an AutoreleasingUnsafePointer value of matching element type, or
- an inout parameter of matching element type.

This disrupts some error messages in unrelated tests, which is tracked by <rdar://problem/17380520>.

Swift SVN r19008
2014-06-19 18:03:10 +00:00
Doug Gregor
39e1b0886d Start using ConditionalCheckedCastExpr and ForcedCheckedCastExpr for collection downcasts.
NFC; just a cleanup.


Swift SVN r18979
2014-06-18 13:00:57 +00:00
Doug Gregor
1c06c309bc Automatically reflect non-Foundation categories of bridged Objective-C classes onto their bridged value types.
This makes categories of NSString, NSArray, and NSDictionary available
on String, Array, and Dictionary. Note that we only consider
categories not present in the Objective-C Foundation module, because
we want to manually map those APIs ourselves. Hence, no changes to the
NSStringAPI. Implements <rdar://problem/13653329>.


Swift SVN r18920
2014-06-16 09:07:00 +00:00
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