Commit Graph

212 Commits

Author SHA1 Message Date
Chris Willmore
68dd563fbf <rdar://problem/18311362> TLF: Eliminate implicit bridging conversions
Require 'as' when converting from Objective-C type to native type (but
continue to allow implicit conversion from native to Objective-C). This
conversion constraint is called ExplicitConversion; all implicit
conversions are covered by the existing Conversion constraint. Update
standard library and tests to match.

Swift SVN r24496
2015-01-18 00:07:45 +00:00
Doug Gregor
376c39bc74 Add test for rdar://problem/17855378
Swift SVN r24356
2015-01-10 05:48:43 +00:00
Chris Lattner
3578c7fde0 Teach the type checker about subtype relationships of noescape, and use this
to allow passing off a no-escape formal parameter to the argument of a 
noescape parameter call.



Swift SVN r24126
2014-12-23 22:18:09 +00:00
Chris Willmore
36d0f187ec Sema, SILGen, ClangImporter: Add special support for Set<T>
Add the following functionality to the Swift compiler:

* covariant subtyping of Set
* upcasting, downcasting of Set
* automatic bridging between Set and NSSet, including
    * NSSet params/return values in ObjC are imported as Set<NSObject>
    * Set params/return values in Swift are visible to ObjC as NSSet

<rdar://problem/18853078> Implement Set<T> up and downcasting

Swift SVN r23751
2014-12-06 02:52:33 +00:00
Jordan Rose
f0582e27b9 Testing whether a type is bridged to ObjC isn't always a public use.
Push the "in expression" flag up through TypeChecker::getBridgedToObjC and
TypeChecker::getDynamicBridgedThroughObjCClass.

Swift SVN r23701
2014-12-05 00:23:29 +00:00
Jordan Rose
2b0fbcbe80 Looking up conformances for a type isn't always a public use of the type.
Specifically, it's not when
- the conformance is being used within a function body (test included)
- the conformance is being used for or within a private type (test included)
- the conformance is being used to generate a diagnostic string

We're still a bit imprecise in some places (checking ObjC bridging), but
in general this means less of an issue for checking literals.

Swift SVN r23700
2014-12-05 00:23:24 +00:00
Jordan Rose
470706eb61 Dependencies: Push isKnownPrivate up to TypeChecker::lookupConstructor.
Some initializer lookups are known to be private dependencies.

Swift SVN r23632
2014-12-03 02:55:59 +00:00
Jordan Rose
e97764fbd8 Dependencies: Type lookups are private in constraint systems within functions.
This is the start of distinguishing qualified lookups within function bodies
from qualified lookups in a function signature. Both of these use the
function itself as the decl context, so we need to distinguish them manually.

This particular commit doesn't change much because expressions don't often
use TypeMember constraints. But it does help with for-loops!

Swift SVN r23484
2014-11-20 20:58:19 +00:00
Joe Groff
2405002991 Sema: Remove the subtype constraint introduced for checked casts.
This prevented metatype casts and other kinds of cast that could be allowed from being accepted. Keep the subtype constraint if we're casting between generic class types with open type variables, because it can provide context to deduce type arguments in this case. This causes a regression in test/Constraints/members.swift that uses 'as' as a coercion, but we're planning to disambiguate cast/coercion syntax soon, which should fix that issue.

Swift SVN r23303
2014-11-13 17:08:04 +00:00
David Farler
c453eb4c48 Add Set type.
<rdar://problem/14661754> TLF: [data-structure] Set<T> data type + Bridging from NSSet

Swift SVN r23262
2014-11-12 07:07:00 +00:00
Joe Groff
53deeebe39 Sema: Relax existential-to-concrete type checking.
There's no reason to constrain casting to or from a generic or existential, since their types may be dynamically equal even if we don't have static knowledge that they are. First step here is to remove the subtype constraint we used to introduce for existential-to-concrete casts.

Swift SVN r23148
2014-11-07 01:17:48 +00:00
Joe Groff
5e682924f6 AST: Drop insignificant CheckedCastKinds.
We'd like to kill this enum off eventually, since the runtime inevitably needs to be able to handle arbitrary checked casts in opaque contexts, and SILGen and IRGen can deal with picking more optimal runtime entry points for specific casts. Only the container bridging kinds are still depended on anymore, and even those ought to eventually be handlable by the runtime in 'x as T' situations. NFC yet.

Swift SVN r23127
2014-11-06 04:05:05 +00:00
Chris Willmore
22f2452909 Only allow labeled parameters with function type to claim trailing closures, as opposed to any unlabeled argument.
For real this time. Added some additional tests.

rdar://problem/18778670

Swift SVN r23094
2014-11-04 03:40:08 +00:00
Chris Willmore
da2e3c4c73 Revert "Only allow labeled parameters with function type to claim trailing closures, as opposed to any unlabeled argument."
The commit broke the PerfTestSuite build:

/Users/buildslave/jenkins/sharedspace/swift-release-asserts/swift/src/tools/swift/benchmark/PerfTestSuite/SingleSource/DollarChain.swift:30:14:
error: missing argument label 'function:' in call
       $.tap(beatle, {$0.name = "Beatle"}).color = "Blue"

This reverts commit r23090.

Swift SVN r23093
2014-11-04 02:19:10 +00:00
Chris Willmore
f64bdb3021 Only allow labeled parameters with function type to claim trailing closures, as opposed to any unlabeled argument.
rdar://problem/18778670

Swift SVN r23090
2014-11-03 22:22:48 +00:00
Devin Coughlin
0aa115c09b Add diagnostics for potentially unavailable initializers.
This patch adds diagnostics for initializers that are potentially unavailable.
It does not treat such initializers as optionals, even when
EnableExperimentalUnavailableAsOptional is true -- there is some tricky
interaction with failable initializers that still needs to be worked out.



Swift SVN r22548
2014-10-06 19:50:08 +00:00
Devin Coughlin
59814bd140 Add type checking for potentially unavailable method references.
This commit modifies Sema to add type checking for potentially unavailable
method references. We now record the reason for method unavailability when
recording a potential overload choice during member constraint simplification
and either diagnose or lift to an optional type during CSApply. This commit also
generalizes UnavailableToOptionalExpr to take an arbitrary subexpression.

This commit does not address potentially unavailable properties, initializers,
or dynamic member references.


Swift SVN r22508
2014-10-03 23:23:13 +00:00
Jordan Rose
042569a3be Optional: Replace uses of Nothing with None.
llvm::Optional (like Swift.Optional!) uses None as its placeholder value,
not Nothing.

Swift SVN r22476
2014-10-02 18:51:42 +00:00
Jordan Rose
e999f40628 Replace "optVal = Nothing" with "optVal.reset()" for Optional<ArrayRef<T>>.
In preparation for the switch to llvm::Optional, which is constructible from
the same dummy llvm::NoneType as llvm::ArrayRef, making the assignment
ambiguous.

Swift SVN r22473
2014-10-02 18:51:37 +00:00
Devin Coughlin
2e8d4bc718 Add handling of potentially unavailable overloaded global functions to Sema.
This commit also factors out some common checking and diagnostic code; it
additionally moves diagnostic emission for unavailable references from CSGen to
CSApply.


Swift SVN r22447
2014-10-01 23:52:08 +00:00
Doug Gregor
8cca0ae85d Solver: eliminate construction constraints. We never need to retain them.
Swift SVN r22432
2014-10-01 18:25:49 +00:00
John McCall
8c303ef7a6 Representational changes towards get-and-mutableAddress
properties.

The main design change here is that, rather than having
purportedly orthogonal storage kinds and has-addressor
bits, I've merged them into an exhaustive enum of the
possibilities.  I've also split the observing storage kind
into stored-observing and inherited-observing cases, which
is possible to do in the parser because the latter are
always marked 'override' and the former aren't.  This
should lead to much better consideration for inheriting
observers, which were otherwise very easy to forget about.
It also gives us much better recovery when override checking
fails before we can identify the overridden declaration;
previously, we would end up spuriously considering the
override to be a stored property despite the user's
clearly expressed intent.

Swift SVN r22381
2014-09-30 08:39:38 +00:00
Devin Coughlin
3749a98763 Record the reason a declaration is potentially unavailable.
This commit adds tracking of the reason a declaration reference is potentially
unavailable to the UnavailableToOptionalExpr AST node and to OverloadChoice. We
will use this reason during SILGen to emit the appropriate run-time check and
during typechecking to provide more helpful diagnostics.

To keep OverloadChoice as small as possible, we encode the reason as an index
into a vector of reasons stored in a given instance of ConstraintSystem (this is
the same approach that Fix takes).

This commit adds Sema/OverloadChoice.cpp (for the parts of OverloadChoice that
now rely on ConstraintSystem) and AST/Availability.h (to bring in
availability-related structures without TypeRefinementContext).


Swift SVN r22377
2014-09-30 01:53:59 +00:00
Dmitri Hrybenko
d396134832 Portability: use std::make_tuple instead of relying on a libc++
extension (an implicit constructor in std::tuple)

Swift SVN r22339
2014-09-28 18:44:34 +00:00
John McCall
1b3771c10b Fix a pair of bugs with rvalue addressed subscripting.
Swift SVN r22258
2014-09-24 09:07:30 +00:00
Devin Coughlin
b727b6d932 Treat potentially unavailable global variable references as optional.
This patch adds the ability (-enable-experimental-unavailable-as-optional) to
treat potentially unavailable declarations as if they had optional types. For
the moment, this is only implemented for global variables.

The high-level approach is to (1) record the potential unavailability of a
declaration reference in the overload choice during constraint generation; (2)
treat the declaration as if it had an optional type during overload resolution
(this is similar to how optional protocol members are treated); and (3) add an
implicit conversion (UnavailableToOptionalExpr) during constraint application
to represent the run-time availability check and optional injection.

This patch does not implement SILGen for UnavailableToOptionalExpr.


Swift SVN r22245
2014-09-24 00:07:46 +00:00
Doug Gregor
55afb33c94 Associate argument labels with the callee in the solver.
When performing name lookup for a declaration that is being called,
use the argument labels at the call site to filter out those
declarations with incompatible argument labels.


Swift SVN r22176
2014-09-22 20:08:01 +00:00
Doug Gregor
5c5cc998a1 Provide Fix-Its for the RawRepresentable interface change.
Calls to fromRaw are replaced with uses of the new failable
initializer init(rawValue:). Similarly, calls to toRaw are replaced
with uses of the rawValue property. Fixes rdar://problem/18357647.


Swift SVN r22164
2014-09-21 23:10:07 +00:00
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