Commit Graph

357 Commits

Author SHA1 Message Date
Andrew Trick
182bb7f812 Revert "Merge pull request #1058 from austinzheng/az-port-mirror"
This pull request broke the following tests on several build configurations
(eg --preset=buildbot,tools=RA,stdlib=DA)

    1_stdlib/Reflection.swift
    1_stdlib/ReflectionHashing.swift
    1_stdlib/UnsafePointer.swift.gyb

This reverts commit c223a3bf06, reversing
changes made to 5c2bb09b09.
2016-01-27 10:43:08 -08:00
Austin Zheng
10d5b23c30 [SR-88] Reinstate mirror migration commit
Changes:
- Reverted commit reverting original SR-88 commit
- Removed mirror children helper collections and related code
- Rewrote some tests to keep them working properly
- Wrote two more tests for the three pointer APIs to ensure no crashes if created using a value > Int64.max

This reverts commit 8917eb0e5a.
2016-01-26 19:28:32 -08:00
Chris Lattner
995506a5e2 Improve the generic "expression...is ambiguous without more context" error in a few ways:
- Improve the specific cases of nil and empty collection literals.
- Improve cases of contextual member lookup where the result type of the looked up member disagrees with context.
- Add some fixme's to the testsuite for cases of this diagnostic that should be diagnosed in other ways.
2016-01-22 22:58:26 -08:00
Mark Lacey
8917eb0e5a Revert "[Runtime][StdLib] Migrate mirrors to use CustomReflectable API, rewrite dump()"
This reverts commit 9798dfd4aa because it
broke the stdlib build.
2016-01-22 08:41:07 -08:00
Austin Zheng
9798dfd4aa [Runtime][StdLib] Migrate mirrors to use CustomReflectable API, rewrite dump()
Jira: SR-88
Changes:
- Removed stdlib type conformances to _Reflectable
- Conformed stdlib types to CustomReflectable, CustomPlaygroundQuickLookable
- Rewrote dump() function to not use _reflect()
- CGRect, CGPoint, CGSize now conform to CustomDebugStringConvertible
- Rewrote unit tests for compatibility with new API
2016-01-21 09:44:15 -08:00
Chris Willmore
983a674e0c Make use of curried function declaration syntax an error.
<rdar://problem/23111018>
2016-01-20 21:57:38 -08:00
Doug Gregor
7d70b704e4 Merge commit '5e11e3f7287427d386636a169c4065c0373931a8' into swift-3-api-guidelines 2016-01-19 23:18:20 -08:00
Chris Lattner
e30cd939d9 Fix rdar://20395243 QoI: type variable reconstruction failing for tuple types
ASTPrinter of type variables was trying to dig an original type out of the
locator and archetype that opened the type variable in the first place.  This
was prone to failure and never helped, so just always print type vars as _.

The affected diagnostics always come out better and this saves a word of storage
for each type variable.
2016-01-11 22:20:19 -08:00
Chris Lattner
13d96b3eeb Spell out these diagnostics more, they are embarassing, but we should fix that not hide it. 2016-01-11 20:45:11 -08:00
Chris Lattner
8d81349fe1 fix rdar://24029542 "Postfix '.' is reserved" error message" isn't helpful
This adds some heuristics so we can emit a fixit to remove extraneous
whitespace after a . and diagnose the case where a member just hasn't
been written yet better.  This also improves handling of tok::unknown
throughout the parser a bit.

This is a re-commit of ff4ea54 with an update for a SourceKit test.
2016-01-11 15:11:20 -08:00
Erik Eckstein
acc243a002 Revert "fix rdar://24029542 "Postfix '.' is reserved" error message" isn't helpful"
It's probably the cause for the fail of SourceKit/SyntaxMapData/syntaxmap-edit-del.swift

This reverts commit ff4ea54614.
2016-01-11 10:43:39 -08:00
Chris Lattner
ff4ea54614 fix rdar://24029542 "Postfix '.' is reserved" error message" isn't helpful
This adds some heuristics so we can emit a fixit to remove extraneous
whitespace after a . and diagnose the case where a member just hasn't
been written yet better.  This also improves handling of tok::unknown
throughout the parser a bit.
2016-01-10 15:28:03 -08:00
Max Moiseev
200be71583 Merge remote-tracking branch 'origin' into swift-3-api-guidelines 2015-12-23 10:28:04 -08:00
Chris Lattner
443af4ad91 In the deprecation warnings for ++/-- on index types, emit a fixit hint to rewrite into
the correct call to .successor() or .predecessor().

This wraps up <rdar://problem/23708702> Emit deprecation warnings for ++/-- in Swift 2.2
2015-12-22 21:04:48 -08:00
Chris Lattner
6a63c77fce Produce fixit hints for deprecated ++/--, rewriting them into (e.g.) += 1.
This handles the case when we have int/fp uses that ignore the result of
the expression.  Index types are coming next.
2015-12-22 15:40:35 -08:00
Max Moiseev
a7339e67ac Merge remote-tracking branch 'origin' into swift-3-api-guidelines 2015-12-22 11:36:07 -08:00
Chris Lattner
be53728691 Mark the ++ and -- operators in the standard library as deprecated for Swift 2.2,
to be removed in Swift 3.0.  I plan to improve the QoI of this deprecation in a
subsequent commit.
2015-12-21 22:10:25 -08:00
Doug Gregor
a97ab6dd14 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2015-12-18 10:15:47 -08:00
Chris Willmore
18938ac2ef Fix single-arg-for-tuple-param check
In matchTypes(), we check whether a type variable representing an
argument could potentially be bound to a single param in a TupleType
rather than the whole TupleType, but this check has been pretty
heuristic and ad hoc so far. Replace with an explicit check to see if
it's possible for exactly one of the parameters in the tuple type can be
bound to a single unlabeled argument.

<rdar://problem/22913570>
2015-12-17 16:58:39 -08:00
Max Moiseev
786e1ea2b1 Merge remote-tracking branch 'origin' into swift-3-api-guidelines 2015-12-11 15:19:02 -08:00
Maxim Moiseev
2c95bb6d51 BooleanType => Boolean 2015-12-10 14:56:32 -08:00
Frederick Kellison-Linn
0bfba2972e Fix lexer to properly handle single quote strings
Lexer now suggests escaping unescaped double quotes and unescaping escaped single quotes in single quote strings..
2015-12-09 20:09:04 -05:00
Chris Lattner
aad3cf9e10 Factor out structural error diagnostics out to a helper method (allowing
the code to be actually readable since it unnests it greatly), and call it
both before and after argument type validation.  This allows us to capture
many more structural errors than before, leading to much better diagnostics
in a lot of cases.  This also fixes the specific regressions introduced by
96a1e96.
2015-12-07 23:48:29 -08:00
Chris Lattner
96a1e96dea Improve printing of "too few" or "too many" arguments in generic or
overloaded argument list mismatches.  We printed them in simple cases
due to "Failure" detecting them in trivial situations.  Instead of
doing that, let CSDiags do it, which allows us to pick things out of
overload sets and handle the more complex cases well.

This is a progression across the board except for a couple of cases
where we now produce "cannot convert value of type 'whatever' to
expected argument type '(arglist)'", this is a known issue that I'll
fix in a subsequent commit.
2015-12-07 23:09:08 -08:00
Chris Lattner
25e310c46f Add a testcase for a fixed issue, remove a fixme that has been fixed. NFC. 2015-11-17 21:09:25 -08:00
Chris Lattner
4b8ccacf63 Fix <rdar://problem/22243469> QoI: Poor error message with throws, default arguments, & overloads
and probably others.

When we're type-checking a failed ApplyExpr that has an overload set that
prevents getting a specific type to feed into the initial typechecking of
the argument list, ranking can often narrow down the list of candidates
further, to the point where there is only one candidate left or where all
candidates agree that one argument is wrong.

In this case, re-type-check the subexpr with the expected type.  In the case of
rdar://problem/22243469 we now produce:

t.swift:6:11: error: invalid conversion from throwing function of type '() throws -> ()' to non-throwing function type '() -> Void'
  process {
          ^

instead of:

t.swift:6:3: error: cannot invoke 'process' with an argument list of type '(() throws -> ())'
  process {
  ^
t.swift:6:3: note: overloads for 'process' exist with these partially matching parameter lists: (UInt, fn: () -> Void)
  process {
  ^

Which is a heck of a lot less specific.  Similarly, in the testcase from rdar://23550816, instead
of producing:

  takeTwoFuncsWithDefaults { $0 + 1 }
error: cannot invoke 'takeTwoFuncsWithDefaults' with an argument list of type '((Int -> Int)?)'
note: expected an argument list of type '(f1: (Int -> Int)?, f2: (String -> String)?)'

we now produce:
error: cannot convert value of type '_ -> Int' to expected argument type '(String -> String)?'

which is a lot closer to what we want to complain about.
2015-11-17 20:27:47 -08:00
Chris Lattner
85501b436e Remove some weird hacks that added special case behavior for operators. This
code had the effect of squishing the note that printed the overload candidate
set for the operators in question.  While these are not generally helpful given
how many overloads we have of (e.g.) the + operator, it doesn't do us any good
to have special cases like this, because methods can have tons of overloads as
well.
2015-11-15 21:24:57 -08:00
Chris Lattner
2f04cb13f1 Fix <rdar://problem/23550816> QoI: Poor diagnostic in argument list of "print" (varargs related)
When passing a contextual type to a call, if we have a scalar element
initializing a varargs parameter list, we need to use the varargs element type
contextually.  Fixing this improves some confusing diagnostics.
2015-11-15 15:13:21 -08:00
Chris Willmore
a79c1c9bf4 Don't allow conversion from inout argument to Any parameter.
<rdar://problem/23249098>
2015-11-03 19:00:46 -08:00
David Farler
93b6962478 Warn when using 'var' bindings in function parameters
These will no longer be allowed in a future Swift release.

rdar://problem/23172698
2015-11-03 17:24:20 -08:00
Chris Willmore
30af42fda9 Add warning that curried function decl syntax is going away.
<rdar://problem/23111018>
2015-11-02 15:45:11 -08:00
Chris Willmore
6d7d45a0a4 When clearing type data for failure diagnosis, reset the lvalue access kind too.
That way, re-typechecking doesn't complain about the lvalue access kind
bit already having been set.

<rdar://problem/23185177> Compiler crashes in Assertion failed: ((AllowOverwrite || !E->hasLValueAccessKind()) && "l-value access kind has already been set"), function visit

Swift SVN r32854
2015-10-24 00:44:23 +00:00
Chris Willmore
4b8a5cf894 Lex single-quote string literals but emit an error if they're encountered.
Emit a fix-it replacing them with double-quote string literals.

<rdar://problem/21950709> QoI: Parse single-quoted literals like double-quoted literals

Swift SVN r31973
2015-09-15 22:24:18 +00:00
Chris Lattner
96eaa14f3b Fix an arbitrary restriction where we would not propagate the result type of
call expression onto a callee when it was a binary expression.  Doing this
requires improving the diagnostics for when the contextual result type is
incompatible with all candidates, but that is general goodness all around.

This fixes:
<rdar://problem/22333090> QoI: Propagate contextual information in a call to operands

and improves a number of diagnostics where the problem is that an operator
is used in a context that expects a type that it cannot produce.



Swift SVN r31891
2015-09-11 06:12:05 +00:00
Chris Lattner
72c5c3e4fe Two changes:
- Enhance the branch new argument label overload diagnostic to just
   print the argument labels that are the problem, instead of printing
   the types inferred at the argument context.  This can lead to confusion
   particularly when an argument label is missing.  For example before:

error: argument labels '(Int)' do not match any available overloads
note: overloads for 'TestOverloadSets.init' exist with these partially matching parameter lists: (a: Z0), (value: Int), (value: Double)

after:

error: argument labels '(_:)' do not match any available overloads
note: overloads for 'TestOverloadSets.init' exist with these partially matching parameter lists: (a: Z0), (value: Int), (value: Double)


Second, fix <rdar://problem/22451001> QoI: incorrect diagnostic when argument to print has the wrong type
by specifically diagnosing the problem when you pass in an argument to a nullary function.  Before:

error: cannot convert value of type 'Int' to expected argument type '()'

after:
error: argument passed to call that takes no arguments
print(r22451001(5))
                ^




Swift SVN r31795
2015-09-09 00:26:37 +00:00
Chris Lattner
e7a86e00b9 Finish up the last bit of work I plan on
<rdar://problem/22333281> QoI: improve diagnostic when contextual type of closure disagrees with arguments

In the common case where someone doesn't care about the argument 
list to a closure, we now generate a tailored error message with a 
fixit to introduce the necessary "_,_ in " nonsense at the start 
of the closure.  IMO ideally we wouldn't require this, but until we
fix that type checker issue, we should at least give people the
obvious fix.


Swift SVN r31720
2015-09-05 22:37:55 +00:00
Chris Lattner
86b47b8186 remove the TupleSizeMismatch failure mode and diagnose the problem in the mainline
expr diagnosis stuff, giving us much better diagnostics on the cases in
expr/closure/closures.swift.  This is part #2 of resolving
<rdar://problem/22333281> QoI: improve diagnostic when contextual type of closure disagrees with arguments



Swift SVN r31717
2015-09-05 21:38:06 +00:00
Chris Lattner
6619cf76dd Improve the diagnostics generated when the contextual type for a closure
specifies some # of arguments but the closureexpr itself disagrees.  This is 
step #1 to resolving
<rdar://problem/22333281> QoI: improve diagnostic when contextual type of closure disagrees with arguments



Swift SVN r31715
2015-09-05 21:02:18 +00:00
Chris Willmore
a17ebe2f16 Add check to simplifyLocator for TupleElement.
When simplifying tuple element locator, be careful about possibly
accessing non-existent elements of TupleExpr anchor.

<rdar://problem/22426860> CrashTracer: [USER] swift at …mous_namespace::ConstraintGenerator::getTypeForPattern + 698

Swift SVN r31629
2015-09-02 08:50:59 +00:00
Chris Lattner
712d3447ce improve some diagnostics around inout expr.
Swift SVN r31415
2015-08-22 22:29:14 +00:00
Chris Lattner
3a03435a1e Now that we have various infrastructure improvements in place, we can
remove some unprincipled code from typeCheckChildIndependently that was
special casing some expr nodes.


Swift SVN r31407
2015-08-22 06:06:14 +00:00
Chris Lattner
6358c3049d Now that we consistently propagate contextual type information when it
is available, use it to start producing useful diagnostics for contextually
typed member references.


Swift SVN r31362
2015-08-20 17:07:15 +00:00
Chris Willmore
032f7532f7 Don't bind unlabeled type variable to single labeled argument.
<rdar://problem/22348394> Compiler crash on invoking function with labeled defaulted param with non-labeled argument

Swift SVN r31355
2015-08-19 22:57:29 +00:00
Chris Lattner
248727780f Now that enough yaks are cleanly shaven, completely reimplement how
we process contextual constraints when producing diagnostic.  Formerly,
we would aggressively drop contextual type information on the floor under
the idea that it would reduce constraints on the system and make it more
likely to be solvable.  However, this also has the downside of introducing
ambiguity into the system, and some expr nodes (notably closures) cannot
usually be solved without that contextual information.

In the new model, expr diagnostics are expected to handle the fact that
contextual information may be present, and bail out without diagnosing an
error if that is the case.  This gets us more information into closures,
allowing more specific return type information, e.g. in the case in
test/expr/closure/closures.swift.

This approach also produces more correct diagnostics in a bunch of other
cases as well, e.g.:

-  var c = [:]  // expected-error {{type '[_ : _]' does not conform to protocol 'DictionaryLiteralConvertible'}} 
+  var c = [:]  // expected-error {{expression type '[_ : _]' is ambiguous without more context}}

and the examples in test/stmt/foreach.swift, test/expr/cast/as_coerce.swift,
test/expr/cast/array_iteration.swift, etc.

That said, this another two steps forward, one back thing.  Because we
don't handle propagating sametype constraints from results of calls to their
arguments, we regress a couple of (admittedly weird) cases.  This is now 
tracked by:
<rdar://problem/22333090> QoI: Propagate contextual information in a call to operands

There is also the one-off narrow case tracked by:
<rdar://problem/22333281> QoI: improve diagnostic when contextual type of closure disagrees with arguments



Swift SVN r31319
2015-08-18 23:55:02 +00:00
Chris Lattner
8e758ba19f Make the "type of expression is ambiguous without more context" diagnostic more
specific when it fails, by printing a potentially partially resolved type for the
ambiguous expression in question, which it carries information.  This can at least
tell what the ambiguous parts of the resultant type *are* in some cases (e.g. in
the Constraints/array_literal.swift case).  That said, this diagnostic is still
admittedly not great.

This also exposes a couple of cases where we produce bogus diagnostics in general 
(expr/cast/as_coerce.swift).  The issue here is that these shouldn't be ambiguous 
at all, they are being misreported due to 22320758), which I'll fix separately.



Swift SVN r31292
2015-08-18 06:05:46 +00:00
Chris Willmore
265f91fead Allow string literals in string literal interpolation.
Teach skipToEndOfInterpolatedExpression() to match quote marks as well
as parentheses in the interpolated expression. This makes expressions
like "hello \(names["bob"])" possible.

Swift SVN r31283
2015-08-18 00:41:01 +00:00
Chris Willmore
86f64d3e26 Don't simplify argument tuple conversion constraint $T1 < (T2, ...) to
$T1 < T2 if there are other required params in the tuple.

<rdar://problem/22211854> wrong arg list crashing sourcekit

Swift SVN r31218
2015-08-13 18:28:25 +00:00
Chris Willmore
215eef9565 CSDiag: Set CTPurpose in right place when typechecking function argument independently.
<rdar://problem/22211854> wrong arg list crashing sourcekit

Swift SVN r31216
2015-08-13 17:46:34 +00:00
Chris Lattner
42d53dc414 Fix:
<rdar://problem/18397777> QoI: special case comparisons with nil
<rdar://problem/18042123> QoI: Fixit for "if !optional" should suggest "if optional == nil"



Swift SVN r31204
2015-08-13 04:36:43 +00:00
Jordan Rose
a26716290c When adding " != nil" to an optional in an 'if', we may need parens.
...such as with 'try?'.

rdar://problem/22259712

Swift SVN r31199
2015-08-13 03:08:15 +00:00