Commit Graph

1305 Commits

Author SHA1 Message Date
Chris Willmore
589a46f9ba Merge pull request #858 from jder/vararg-tuple-conversion-for-args-only
[SR-433][Sema] Don't produce vararg tuples outside of arglists
2016-01-05 17:39:17 -08:00
Max Moiseev
f51e708a8f Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-01-04 12:25:25 -08:00
Jesse Rusak
63faeac77c [SR-433][Sema] Don't produce vararg tuples outside of arglists
Previously, we could produce such a tuple shuffle for non-arg
tuples, which would trigger an assert in SILGen.
2016-01-02 15:37:42 -05:00
Chris Lattner
a30ae2bf55 Merge pull request #836 from zachpanz88/new-year
Update copyright date
2015-12-31 19:36:14 -08:00
Chris Lattner
7daaa22d93 Completely reimplement/redesign the AST representation of parameters.
Parameters (to methods, initializers, accessors, subscripts, etc) have always been represented
as Pattern's (of a particular sort), stemming from an early design direction that was abandoned.
Being built on top of patterns leads to patterns being overly complicated (e.g. tuple patterns
have to have varargs and default parameters) and make working on parameter lists complicated
and error prone.  This might have been ok in 2015, but there is no way we can live like this in
2016.

Instead of using Patterns, carve out a new ParameterList and Parameter type to represent all the
parameter specific stuff.  This simplifies many things and allows a lot of simplifications.
Unfortunately, I wasn't able to do this very incrementally, so this is a huge patch.  The good
news is that it erases a ton of code, and the technical debt that went with it.  Ignoring test
suite changes, we have:
   77 files changed, 2359 insertions(+), 3221 deletions(-)

This patch also makes a bunch of wierd things dead, but I'll sweep those out in follow-on
patches.

Fixes <rdar://problem/22846558> No code completions in Foo( when Foo has error type
Fixes <rdar://problem/24026538> Slight regression in generated header, which I filed to go with 3a23d75.

Fixes an overloading bug involving default arguments and curried functions (see the diff to
Constraints/diagnostics.swift, which we now correctly accept).

Fixes cases where problems with parameters would get emitted multiple times, e.g. in the
test/Parse/subscripting.swift testcase.

The source range for ParamDecl now includes its type, which permutes some of the IDE / SourceModel tests
(for the better, I think).

Eliminates the bogus "type annotation missing in pattern" error message when a type isn't
specified for a parameter (see test/decl/func/functions.swift).

This now consistently parenthesizes argument lists in function types, which leads to many diffs in the
SILGen tests among others.

This does break the "sibling indentation" test in SourceKit/CodeFormat/indent-sibling.swift, and
I haven't been able to figure it out.  Given that this is experimental functionality anyway,
I'm just XFAILing the test for now.  i'll look at it separately from this mongo diff.
2015-12-31 19:24:46 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
practicalswift
fa0b339a21 Fix typos. 2015-12-26 17:51:59 +01: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
Maxim Moiseev
ca932fca5a CVarArgType => CVarArg 2015-12-16 15:52:01 -08:00
Max Moiseev
806be29941 Merge remote-tracking branch 'origin' into swift-3-api-guidelines 2015-12-14 12:05:35 -08:00
practicalswift
ba64df92e3 Fix typo: coerceable → coercible 2015-12-14 00:11:23 +01:00
Chris Willmore
e169d04dcf Sema: Have all fixes go through recordFix(). NFC.
This removes duplicated code and avoids issues like 18741539 where a fix
is recorded but the solution's score is not increased.
2015-12-11 15:25:55 -08:00
Max Moiseev
786e1ea2b1 Merge remote-tracking branch 'origin' into swift-3-api-guidelines 2015-12-11 15:19:02 -08:00
Chris Willmore
c99c02b5a6 Transform EditorPlaceholderExpr into trap if executed in playground
mode (take 2)

Allow untyped placeholder to take arbitrary type, but default to Void.
Add _undefined<T>() function, which is like fatalError() but has
arbitrary return type. In playground mode, merely warn about outstanding
placeholders instead of erroring out, and transform placeholders into
calls to _undefined(). This way, code with outstanding placeholders will
only crash when it attempts to evaluate such placeholders.

When generating constraints for an iterated sequence of type T, emit

    T convertible to $T1
    $T1 conforms to SequenceType

instead of

    T convertible to SequenceType

This ensures that an untyped placeholder in for-each sequence position
doesn't get inferred to have type SequenceType. (The conversion is still
necessary because the sequence may have IUO type.) The new constraint
system precipitates changes in CSSimplify and CSDiag, and ends up fixing
18741539 along the way.

(NOTE: There is a small regression in diagnosis of issues like the
following:

    class C {}
    class D: C {}
    func f(a: [C]!) { for _: D in a {} }

It complains that [C]! doesn't conform to SequenceType when it should be
complaining that C is not convertible to D.)

<rdar://problem/21167372>

(Originally Swift SVN r31481)
2015-12-10 22:05:16 -08:00
Maxim Moiseev
2c95bb6d51 BooleanType => Boolean 2015-12-10 14:56:32 -08:00
Max Moiseev
d610fa0d1c Merge remote-tracking branch 'origin' into swift-3-api-guidelines 2015-12-10 10:29:52 -08:00
Dmitri Gribenko
feacbc4433 Rename ErrorType to ErrorProtocol 2015-12-09 17:12:19 -08:00
Justas Brazauskas
043c518b27 Fix typos 2015-12-09 17:54:54 +02:00
Chris Lattner
15862749a3 Completely eliminate the MissingArgument/ExtraArguments Failure kinds, as they
are now unused.  Failure is down to just 4 kinds, so it is closer to going away.
NFC.
2015-12-07 23:14:19 -08:00
Chris Lattner
80abe99ea3 remove the OutOfOrderArgument failure mode now that CSDiag subsumes it. 2015-11-15 23:15:23 -08:00
Chris Willmore
da15fbf4ce [Sema] Error on generic arg lists with different lengths
Don't assert that generic arg lists have the same lengths. We don't
currently allow nested generics, but we try to type-check anyway, and
one of the effects is sticking the generic params for both the outer and
inner classes on the inner type. Instead, just error out.

<rdar://problem/21967211>
2015-11-10 18:08:29 -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
Doug Gregor
2d5d3d240c Omit needless words: use the actual mapped names for builtin C types.
This provides better fidelity between omit-needless-words acting on
Clang types vs. acting on Swift types.

Swift SVN r32383
2015-10-01 22:37:40 +00:00
Chris Willmore
49e5130103 Allow inout closure param type to be inferred from context or usage.
Introduce a new constraint kind, BindParam, which relates the type of a
function parameter to the type of a reference to it from within the
function body. If the param type is an inout type, the ref type is an
lvalue type with the same underlying object type; otherwise the two
types must be the same. This prevents DeclRefExprs from being inferred
to have inout type in some cases.

<rdar://problem/15998821> Fail to infer types for closure that takes an inout argument

Swift SVN r32183
2015-09-23 18:46:12 +00:00
Chris Lattner
f8c6e46e03 remove the Failure::IsNotOptional failure mode, as CSDiags does a better job
of providing contextual diagnostics (e.g. producing the warning in 
Constraints/dynamic_lookup.swift).  This drops a specific diagnostic about
force casting the result of as! which was added in the Swift 1.2 timeframe
to explain the change in cast semantics.  Now that as! has been around for
a long time, it is more confusing than helpful.



Swift SVN r31887
2015-09-11 04:40:13 +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
ce7bcc3bea One second thought: keep the interface to computeTupleShuffle consistent:
change its implementation to take a list of TupleTypeElt for both the
from/to tuple type, but provider a convenience wrapper that takes the
from/to tuple type as TupleType's.


Swift SVN r31733
2015-09-06 22:23:25 +00:00
Chris Lattner
17c3ebbd49 remove a function that is dead after r31728
Swift SVN r31732
2015-09-06 22:17:45 +00:00
Chris Lattner
21acbd42a0 refactor constraints::computeTupleShuffle() to take its first tuple as
an exploded list of elements, which is more convenient for at least one
caller.  NFC.



Swift SVN r31731
2015-09-06 22:17:22 +00:00
Chris Lattner
bab9b62c87 reimplement the "function produces expected type 'XYZ'; did you mean to call it with '()'?"
fixit hint in CSDiags instead of being a FixKind.  This resolves a number of issues with
it, particularly that it didn't actually check to see if the function in question takes
a () argument or not.  

This fixes:
<rdar://problem/21692808> QoI: Incorrect 'add ()' fixit with trailing closure

among other issues.



Swift SVN r31728
2015-09-06 20:41:21 +00:00
Chris Lattner
9f01aa2b3f revert the fix to rdar://22298549, it is causing a crash on the
testcase in rdar://21692808


Swift SVN r31727
2015-09-06 20:18:25 +00:00
Chris Lattner
44b35a85f8 remove a bunch more Failure conditions that CSDiags ignores.
Swift SVN r31718
2015-09-05 21:53:08 +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
877fa0bf84 remove some dead "Failure" cases that CSDiags already ignores because it handles them
better in its expression-driven system.


Swift SVN r31716
2015-09-05 21:09:02 +00:00
Chris Lattner
659dde32ab simplify some code, NFC.
Swift SVN r31619
2015-09-02 05:11:56 +00:00
Chris Lattner
66a3e8ba14 Fix <rdar://problem/22344208> QoI: Warning for unused capture list variable should be customized
Where before we produced an invalid and misleading diagnostic, produce a correct one.


Swift SVN r31599
2015-09-01 06:12:39 +00:00
Chris Lattner
18107bf5c9 fix <rdar://problem/22298549> QoI: Unwanted trailing closure produces weird error
Swift SVN r31598
2015-09-01 04:56:06 +00:00
Chris Willmore
337b52fb1e Use AST function representation info instead of dropping down to SIL.
Swift SVN r31596
2015-09-01 03:27:23 +00:00
Chris Willmore
1c3b391fd3 Don't allow function types that differ in SIL representation to be matched by SameType constraint.
<rdar://problem/22181714> Crash when typing "signal"

Swift SVN r31594
2015-09-01 01:46:59 +00:00
Chris Lattner
1e5c13aa58 refactor the interface to performMemberLookup to pass in the components
of the constraint that it needs, not a constraint itself.  NFC.


Swift SVN r31585
2015-08-30 20:58:21 +00:00
Chris Willmore
32bcecb2a2 Use Defaultable constraint instead of disjunction for last-resort type.
NFC.

Swift SVN r31393
2015-08-21 21:27:46 +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
f6ce68a45a remove ConstraintKind::Conjunction, it is unused and unnecessary - after
all, the whole system is a conjunction!


Swift SVN r31284
2015-08-18 00:47:28 +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
Joe Pamer
cd492d96b5 Fix a type checker crash when the object type of a ForceValueExpr is an 'Any'.
This allows us to remove the workaround generic overloads for "print" without sacrificing good diagnostics for its unavailable overloads. (rdar://problem/21499048, rdar://problem/21582758, rdar://problem/22126141)

Swift SVN r31169
2015-08-12 15:59:31 +00:00
Chris Lattner
a899872d91 Reapply r31105, with some fixes to invalid unconstrained generics. These fixes correct
the regressions that r31105 introduced in the validation tests, as well as fixing a number
of other validation tests as well.

Introduce a new UnresolvedType to the type system, and have CSDiags start to use it
as a way to get more type information out of incorrect subexpressions.  UnresolvedType
generally just propagates around the type system like a type variable:
 - it magically conforms to all protocols
 - it CSGens as an unconstrained type variable.
 - it ASTPrints as _, just like a type variable.

The major difference is that UnresolvedType can be used outside the context of a
ConstraintSystem, which is useful for CSGen since it sets up several of them to 
diagnose subexpressions w.r.t. their types.

For now, our use of this is extremely limited: when a closureexpr has no contextual
type available and its parameters are invalid, we wipe them out with UnresolvedType
(instead of the previous nulltype dance) to get ambiguities later on.

We also introduce a new FreeTypeVariableBinding::UnresolvedType approach for
constraint solving (and use this only in one place in CSDiags so far, to resolve
the callee of a CallExpr) which solves a system and rewrites any leftover type 
variables as UnresolvedTypes.  This allows us to get more precise information out,
for example, diagnosing:

 func r22162441(lines: [String]) {
   lines.map { line in line.fooBar() }
 }

with: value of type 'String' has no member 'fooBar'
instead of: type of expression is ambiguous without more context

This improves a number of other diagnostics as well, but is just the infrastructural
stepping stone for greater things.





Swift SVN r31130
2015-08-11 06:06:05 +00:00
Chris Lattner
2204dbcbfd revert r31105, it causes some regressions on validation tests.
Swift SVN r31107
2015-08-10 15:01:22 +00:00
Chris Lattner
de79b60c89 Introduce a new UnresolvedType to the type system, and have CSDiags start to use it
as a way to get more type information out of incorrect subexpressions.  UnresolvedType
generally just propagates around the type system like a type variable:
 - it magically conforms to all protocols
 - it CSGens as an unconstrained type variable.
 - it ASTPrints as _, just like a type variable.

The major difference is that UnresolvedType can be used outside the context of a
ConstraintSystem, which is useful for CSGen since it sets up several of them to 
diagnose subexpressions w.r.t. their types.

For now, our use of this is extremely limited: when a closureexpr has no contextual
type available and its parameters are invalid, we wipe them out with UnresolvedType
(instead of the previous nulltype dance) to get ambiguities later on.

We also introduce a new FreeTypeVariableBinding::UnresolvedType approach for
constraint solving (and use this only in one place in CSDiags so far, to resolve
the callee of a CallExpr) which solves a system and rewrites any leftover type 
variables as UnresolvedTypes.  This allows us to get more precise information out,
for example, diagnosing:

 func r22162441(lines: [String]) {
   lines.map { line in line.fooBar() }
 }

with: value of type 'String' has no member 'fooBar'
instead of: type of expression is ambiguous without more context

This improves a number of other diagnostics as well, but is just the infrastructural
stepping stone for greater things.



Swift SVN r31105
2015-08-10 06:18:27 +00:00
Joe Pamer
828eb68e72 Commit DaveA's API changes to 'print', along with the compiler changes necessary to support them.
There's still work left to do. In terms of next steps, there's still rdar://problem/22126141, which covers removing the 'workaround' overloads for print (that prevent bogus overload resolution failures), as well as providing a decent diagnostic when users invoke print with 'appendNewline'.

Swift SVN r30976
2015-08-04 01:57:11 +00:00