Commit Graph

1334 Commits

Author SHA1 Message Date
Doug Gregor
d436b5d341 Constraint solver: look through type variables after unwrapping optionals.
When simplifying a checked-cast constraint, look through type
variables after unwrapping optionals or looking through
metatypes. Otherwise, we won't find obvious solutions. Fixes
rdar://problem/18330319.

Swift SVN r22086
2014-09-18 18:02:00 +00:00
Doug Gregor
8cf718f9f6 Don't allow a generic parameter with a non-@objc protocol requirement to bind to an existential.
We don't properly open up the existential to make this work, which
leads to an IRGen crash. Reject the uses of generics that would cause
such a crash rdar://problem/17491663.


Swift SVN r21946
2014-09-15 17:36:26 +00:00
Doug Gregor
713ba3edd8 CF <-> NS bridging is a subtype. Fixes rdar://problem/18297881
Swift SVN r21922
2014-09-12 20:57:53 +00:00
Doug Gregor
43b6ed364a Thread constraint locators through opening of generic types.
Locators that refer to opened type parameters now carry information
about the source location where we needed to open the type, so that
(for example) we can trace an opened type parameter back to the
location it was opened. As part of this, eliminate the "rootExpr"
fallback, because we're threading constraint locators everywhere.

This is infrastructural, and should be NFC.

Swift SVN r21919
2014-09-12 20:27:19 +00:00
Doug Gregor
9f4ddfe2e1 Don't allow an implicit conversion from NSNumber to one of its bridged value types.
Eliminate the implicit conversion from NSNumber to one of its bridged
value types (Int, Float, Double, Bool, etc.). One can use "as" to
perform the conversion instead. This eliminates a class of
accepts-dubious that involve lossy conversions from NSNumber to Int.

Our eventual arc is to eliminate all of these conversions. This is a
small, high-value step along that path rdar://problem/18269449.

Swift SVN r21879
2014-09-11 17:12:02 +00:00
Doug Gregor
16d8294814 Don't allow bridging conversions when we're processing favored constraints.
This is another instance where we choose a favored constraint that
only type checks because we're bridging through NSNumber, causing
awful problems. Fixes rdar://problem/17962491.


Swift SVN r21445
2014-08-25 22:16:58 +00:00
Doug Gregor
397f4a9888 Remove user-defined conversions from the type checker.
Nobody is using this crufty old feature now, so remove it and the
complexity that goes along with it.

Swift SVN r21379
2014-08-21 21:59:49 +00:00
Doug Gregor
17716524c5 Handle CF <-> Objective-C toll-free-bridged conversions in the type checker.
Introduce an attribute that describes when a given CF type is
toll-free-bridged to an Objective-C class, and which class that
is. Use that information in the type checker to provide the CF <->
Objective-C toll-free-bridged conversions directly, rather than using
the user-defined conversion machinery.

Swift SVN r21376
2014-08-21 21:36:05 +00:00
Doug Gregor
0777d6dd6f Remove the assumption that constructing a T always produces a T.
With failable initializers, it will be able to produce a T? or T!.


Swift SVN r21294
2014-08-19 21:01:10 +00:00
Doug Gregor
42dc448e7e Reflect failability of an initializer in the optionality of its result type.
Don't verify this for the Optional and ImplicitlyUnwrappedOptional types.


Swift SVN r21293
2014-08-19 20:42:06 +00:00
Doug Gregor
c06e22d406 Revert r21291; it's breaking the standard library build.
Swift SVN r21292
2014-08-19 20:37:05 +00:00
Joe Pamer
1bdf86437f Do not penalize optional-to-optional conversions when processing the associated value-to-optional conversions. Doing so can result in incorrect ambiguity errors when applying optional-typed arguments to function overload sets with optional and non-optional parameter types. (Hitlisted: rdar://problem/18028526)
Swift SVN r21264
2014-08-18 22:30:07 +00:00
Doug Gregor
86b59b1294 Add a score kind for value-to-optional bindings, and ban them during partial ordering.
This is the semantic change we need to eliminate ambiguities when
introducing the new ?? overload. There is a minor regression here with
curried method references, which is covered by <rdar://problem/18006008>.


Swift SVN r21173
2014-08-13 16:19:56 +00:00
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