Commit Graph

375 Commits

Author SHA1 Message Date
Joe Groff
e152c4d7a4 Sema: Disallow partial applications of payloaded enum case constructors.
Fixes <rdar://problem/16304750>, which was frequently taking down SourceKit on partially-entered enum constructions.

Swift SVN r20459
2014-07-24 02:39:56 +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
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
Joe Pamer
da59d305c9 Greatly improve type checker performance when inferring types for certain binary
expression applications

(rdar://problem/15933674, rdar://problem/17365394 and many, many dupes.)

When solving for the type of a binOp expression, factor the operand expression
types into account when collating overloads for the operator being applied.
This allows the type checker to now infer types for some binary operations with
hundreds of nested components, whereas previously we could only handle a handful.
(E.g., "1+2+3+4+5+6" previously sent the compiler into a tailspin.)

Specifically, if one of the operands is a literal, favor operator overloads
whose operand, result or contextual types are the default type of the literal
convertible conformance of the the argument literal type.

By doing so we can prevent exponential behavior in the solver and massively
reduce the complexity of many commonly found constraint systems. At the same
time, we'll still defer to "better" overloads if the default one cannot be
applied. (When adding an Int8 to an Int, for example.)

This obviously doesn't solve all of our performance problems (there are more
changes coming), but there are couple of nice side-effects:
- By tracking literal/convertible protocol conformance info within type
variables, I can potentially eliminate many instances of "$T0" and the
like from our diagnostics.
- Favored constraints are placed at the front of the overload resolution
disjunction, so if a system fails to produce a solution they'll be the
first to be mined for a cause. This helps preserve user intent, and leads
to better diagnostics being produced in some cases.

Swift SVN r19848
2014-07-11 16:24:42 +00:00
Joe Groff
ba15e5c835 Warn when a trailing closure is separated from its call site by more than one line.
Swift SVN r19325
2014-06-28 18:51:28 +00:00
Joe Groff
88f2632a44 Allow trailing closures with a line break before '{'.
Swift SVN r19322
2014-06-28 05:12:48 +00:00
Dave Abrahams
b7a8fc7d4c Revert "Allow trailing closures with a line break before '{'."
This reverts r19315, which broke my build:

-- Testing: 1 tests, 1 threads --
FAIL: Swift :: Interpreter/arrays.swift (1 of 1)
******************** TEST 'Swift :: Interpreter/arrays.swift' FAILED ********************
Script:
--
rm -rf /Users/dave/build/swift/Ninja-RelWithDebInfo/swift/test/Interpreter/Output/arrays.swift.tmp && mkdir -p /Users/dave/build/swift/Ninja-RelWithDebInfo/swift/test/Interpreter/Output/arrays.swift.tmp && xcrun -sdk macosx10.10 /Users/dave/build/swift/Ninja-RelWithDebInfo/swift/bin/swift -target x86_64-apple-macosx10.9 -resource-dir '/Users/dave/build/swift/Ninja-RelWithDebInfo/swift/lib/swift' -module-cache-path /Users/dave/build/swift/Ninja-RelWithDebInfo/swift/swift-module-cache -module-cache-path /Users/dave/build/swift/Ninja-RelWithDebInfo/swift/test/Interpreter/Output/arrays.swift.tmp/clang-module-cache /Users/dave/src/s/swift/test/Interpreter/arrays.swift -o /Users/dave/build/swift/Ninja-RelWithDebInfo/swift/test/Interpreter/Output/arrays.swift.tmp/a.out &&  /Users/dave/build/swift/Ninja-RelWithDebInfo/swift/test/Interpreter/Output/arrays.swift.tmp/a.out | FileCheck /Users/dave/src/s/swift/test/Interpreter/arrays.swift
--
Exit Code: 1

Command Output (stderr):
--
/Users/dave/src/s/swift/test/Interpreter/arrays.swift:54:1: error: invalid use of '()' to call a value of non-function type '()'
println()
^

Swift SVN r19317
2014-06-28 01:51:45 +00:00
Joe Groff
0c9fc15ae1 Allow trailing closures with a line break before '{'.
Swift SVN r19315
2014-06-28 00:36:45 +00:00
Joe Pamer
a314db950e Remove another point of non-determinism while tracking failed constraints, and use this as an opportunity to improve certain diagnostics. (rdar://problem/16808495)
Swift SVN r19244
2014-06-26 19:48:48 +00:00
Doug Gregor
9210cd5ff4 Replace T[] array syntax with [T] in the test suite
Swift SVN r19192
2014-06-25 23:39:24 +00:00
Chris Lattner
70076cf958 switch the testsuite to use the ..< operator instead of ..
Swift SVN r19003
2014-06-19 17:18:23 +00:00
Jordan Rose
bb5b2f4a70 [Parse] Allow shadowing the variable a closure expr is being assigned to.
Do this by only warning on self-referential uses of a variable when there's
not another binding found in the local scope. This probably still restricts
some reasonable edge cases, but it at least allows shadowing the variable
with a local name.

<rdar://problem/17087232>

Swift SVN r18771
2014-06-10 01:14:29 +00:00
Joe Pamer
ef75f7283a Take first steps towards eliminating un-substituted type variables from our diagnostic output.
Swift SVN r18750
2014-06-09 17:49:43 +00:00
Chris Lattner
183b7e3790 fix <rdar://problem/16955318> Observed variable in a closure triggers an assertion
Swift SVN r18419
2014-05-19 14:37:38 +00:00
Ted Kremenek
9eea282719 Switch range operators ".." and "...".
- 1..3 now means 1,2
- 1...3 now means 1,2,3

Implements <rdar://problem/16839891>

Swift SVN r18066
2014-05-14 07:36:00 +00:00
Chris Lattner
bca1634958 fix rdar://16889886 - Assert when trying to weak capture a property of self in a lazy closure
also improve error recovery.


Swift SVN r18008
2014-05-13 16:45:15 +00:00
Ted Kremenek
fad874708e Adjust test cases.
Swift SVN r17964
2014-05-12 22:01:52 +00:00
Chris Lattner
d05205ba8b move trailing closure tests into the expr/closures directory instead of being
in its own test dir.  NFC.


Swift SVN r15017
2014-03-14 00:30:43 +00:00
Joe Pamer
81690590c4 When type checking a closure expression, don't bail if a semantic error is encountered when validating the closure's parameter list. At best, this means we won't be able to point out any potential errors in the return-type annotation. At worst, it could leave us with a malformed closure type.
Swift SVN r14529
2014-02-28 19:21:24 +00:00
Joe Pamer
c9bd295533 When contextualizing closure expressions wrapped in auto closures, ensure that the inner closure's parent context is properly adjusted to reflect the auto closure's newly adjusted parent context.
Swift SVN r14482
2014-02-27 22:29:35 +00:00
Doug Gregor
faf1c45d14 Shuffle the files in the testsuite a bit to try to reflect language structure.
There's a lot more work to do here, but start to categorize tests
along the lines of what a specification might look like, with
directories (chapters) for basic concepts, declarations, expressions,
statements, etc.


Swift SVN r9958
2013-11-05 15:12:57 +00:00
Doug Gregor
63ff23147f Implement another new closure syntax.
In this syntax, the closure signature (when present) is placed within
the braces and the 'in' keyword separates it from the body of the
closure, e.g.,

      magic(42, { (x : Int, y : Int) -> Bool in
        print("Comparing \(x) to \(y).\n")
        return y < x
      })

When types are omitted from the parameter list, one can also drop the
parentheses, e.g.,

      magic(42, { x, y -> Bool in
        print("Comparing \(x) to \(y).\n")
        return y < x
      })

The parsing is inefficient and recovers poorly (in part because 'in'
is a contextual keyword rather than a real keyword), but it should
handle the full grammar. A number of tests, along with the whitepaper
and related rational documents, still need to be updated. Still, this
is the core of <rdar://problem/14004323>.



Swift SVN r6105
2013-07-10 01:15:15 +00:00
Doug Gregor
fab984aeae Test and improve parser error recovery for closures.
Swift SVN r5203
2013-05-17 16:39:20 +00:00
Doug Gregor
6e64ca66f0 Treat '|' as a delimiter while parsing the signature of a closure.
'|' is part of the character set for operators, but within the
signature of a closure we need to treat the first non-nested '|' as
the closing delimiter for the closure parameter list. For example,

  { |x = 1| 2 + x}

parses with the default value of '1' for x, with the body 2 + x. If
the '|' operator is needed in the default value, it can be wrapped in
parentheses:

  { |x = (1|2)| x }

Note that we have problems with both name binding and type checking
for default values in closures (<rdar://problem/13372694>), so they
aren't actually enabled. However, this allows us to parse them and
recover better in their presence.



Swift SVN r5202
2013-05-17 16:02:44 +00:00
Doug Gregor
ce3fe3ae92 Implement Ruby-inspired closure syntax.
This commit implements closure syntax that places the (optional)
parameter list in pipes within the curly braces of a closure. This
syntax "slides" well from very simple closures with anonymous
arguments, e.g.,

  sort(array, {$1 > $0})

to naming the arguments

  sort(array, {|x, y| x > y})

to adding a return type and/or parameter types

  sort(array, {|x : String, y : String| -> Bool x > y})

and with multiple statements in the body:

  sort(array, {|x, y|
    print("Comparing \(x) and \(y)\n")
    return x > y
  })

When the body contains only a single expression, that expression
participates in type inference with its enclosing expression, which
allows one to type-check, e.g.,

  map(strings, {|x| x.toUpper()})

without context. If one has multiple statements, however, one will
need to provide additional type information either with context

  strings = map(strings, {
    return $0.toUpper()
  })

or via annotations

  map(strings, {|x| -> String 
    return x.toUpper()
  }

because we don't perform inter-statement type inference.

The new closure expressions are only available with the new type
checker, where they completely displace the existing { $0 + $1 }
anonymous closures. 'func' expressions remain unchanged.

The tiny test changes (in SIL output and the constraint-checker test)
are due to the PipeClosureExpr AST storing anonymous closure arguments
($0, $1, etc.) within a pattern in the AST. It's far cleaner to
implement this way.

The testing here is still fairly light. In particular, we need better
testing of parser recovery, name lookup for closures with local types,
more deduction scenarios, and multi-statement closures (which don't
get exercised beyond the unit tests).



Swift SVN r5169
2013-05-14 05:17:10 +00:00