Commit Graph

737 Commits

Author SHA1 Message Date
John McCall
7bb263161a Fix a semantic bug in CSApply's optional-to-optional application.
Implicit conversions from T?? to U?? would map nil to some(nil) instead of nil.
2017-04-26 17:24:17 -04:00
John McCall
e6d52d8808 LValueToPointerExpr is dead code. RIP LValueToPointerExpr. 2017-04-25 03:01:16 -04:00
Joe Groff
595e0e4ede Merge branch 'master' into keypaths 2017-04-19 18:38:24 -07:00
Graydon Hoare
3a79d83233 Forward declare TypeRepr in TypeLoc.h, adjust other code to compensate. 2017-04-18 11:12:53 -07:00
Arnold Schwaighofer
4d60ec333b AST/SILGen support for constant string literals
rdar://30545013
2017-04-11 11:41:43 -07:00
Joe Groff
964dc0e174 Sema: (wip) Overload resolution for keypath subscripts.
TODO: Some diagnostic regressions:
test-macosx-x86_64/Compatibility/tuple_arguments.swift
test-macosx-x86_64/Constraints/diagnostics.swift
test-macosx-x86_64/Constraints/tuple_arguments.swift
test-macosx-x86_64/expr/unary/keypath/keypath.swift
test-macosx-x86_64/expr/unary/selector/selector.swift
2017-04-09 16:38:02 -07:00
Joe Groff
fc23781906 Sema: First pass at type-checking Swift key paths.
TODO:

- Select the KeyPath subclass corresponding to the write capability of the key path components
- Figure out an issue with unresolved solutions being chosen with contextually-typed keypaths
- Diagnostic QoI
2017-04-04 11:31:15 -07:00
Joe Groff
e3046d6f75 Parsing for native keypaths.
Use `#keyPath2` as a stand-in for the final syntax.
2017-04-04 11:31:15 -07:00
Joe Groff
a5ca6ccd61 Restructure KeyPathExpr to allow more kinds of components.
Expand the representation in anticipation of more kinds of components. NFC intended yet.
2017-04-04 11:31:15 -07:00
Joe Groff
eb5d006e40 Rename ObjCKeyPathExpr -> KeyPathExpr.
We can use the same general shape of expression for native key paths.
2017-04-04 11:31:15 -07:00
Dave
e3b458dff4 Fixed a typo (#8217)
Changed "Retrieve the expression that direct represents the callee." to "Retrieve the expression that directly represents the callee.", on line 3835
2017-03-20 21:35:32 -04:00
Mark Lacey
abfd19c5b1 [Constraint solver] Update LiteralExpr::shallowClone to set types in type map.
It was getting types from the type map, but not setting them in it.
2017-03-15 00:16:54 -07:00
Hugh Bellamy
fdf2282031 Remove now unecessary MSVC trailing objects workaround 2017-03-06 09:58:01 +07:00
David Farler
c343298b8f [Syntax] Implement return-statement and integer-literal-expr
A return statement needs something to return, so implement
integer-literal-expression too. This necessarily also forced
UnknownExprSyntax, UnknownStmtSyntax, and UnknownDeclSyntax,
which are stand-in token buckets for when we don't know
how to transform/migrate an AST.

This commit also contains the core function for caching
SyntaxData children. This is highly tricky code, with some
detailed comments in SyntaxData.{h,cpp}. The gist is that
we have to atomically swap in a SyntaxData pointer into the
child field, so we can maintain pointer identity of SyntaxData
nodes, while still being able to cache them internally.

To prove that this works, there is a multithreaded test that
checks that two threads can ask for a child that hasn't been
cached yet without crashing or violating pointer identity.

https://bugs.swift.org/browse/SR-4010
2017-02-22 18:45:29 -08:00
David Farler
7ee42994c8 Start the Syntax library and optional full token lexing
Add an option to the lexer to go back and get a list of "full"
tokens, which include their leading and trailing trivia, which
we can index into from SourceLocs in the current AST.

This starts the Syntax sublibrary, which will support structured
editing APIs. Some skeleton support and basic implementations are
in place for types and generics in the grammar. Yes, it's slightly
redundant with what we have right now. lib/AST conflates syntax
and semantics in the same place(s); this is a first step in changing
that to separate the two concepts for clarity and also to get closer
to incremental parsing and type-checking. The goal is to eventually
extract all of the syntactic information from lib/AST and change that
to be more of a semantic/symbolic model.

Stub out a Semantics manager. This ought to eventually be used as a hub
for encapsulating lazily computed semantic information for syntax nodes.
For the time being, it can serve as a temporary place for mapping from
Syntax nodes to semantically full lib/AST nodes.

This is still in a molten state - don't get too close, wear appropriate
proximity suits, etc.
2017-02-17 12:57:04 -08:00
Jacob Bandes-Storch
f2d426f285 [AST] CaptureListExpr's body is always a ClosureExpr (#7326) 2017-02-08 20:25:39 -08:00
Mark Lacey
ef442daa8a More progress on constraint system type map.
Another pile of changes to use a side map for types in the constraint
solver and only write them directly into expressions once we have a
known good solution that we want to apply.

Still incomplete, we continue to write the types into expressions along
the way at the moment.
2017-02-05 17:37:03 -07:00
Maxwell Swadling
e713c4271d Fall back to the AssignExprs startLoc when the EqualLoc is invalid
SIL Location diagnostics point at the getLoc, so when the EqualLoc is invalid we get no loc, while the startLoc is a fine alternative for these types of diagnostics.
2017-01-25 15:09:52 +11:00
Rintaro Ishizaki
6305529fe5 [Parse] Add back TrailingSemiLoc to Expr, Stmt, and Decl 2017-01-23 13:18:11 +09:00
Hugh Bellamy
b5a49109ab Merge pull request #6854 from hughbe/overload-token-hack
Introduce and use SWIFT_TRAILING_OBJECTS_OVERLOAD_TOKEN to simplify MSVC hacks
2017-01-17 22:10:50 +00:00
Hugh Bellamy
9580d5b044 Introduce and use SWIFT_TRAILING_OBJECTS_OVERLOAD_TOKEN to simplify MSVC hacks 2017-01-17 20:45:59 +00:00
Rintaro Ishizaki
2f1a3e1617 [AST] Remove unused property 'TrailingSemiLoc' from Stmt and Expr 2017-01-17 17:17:03 +09:00
Joe Groff
c03371afc1 Sema: NSValue-to-value-type casts are failable and should be checked.
In Swift 4 mode, no longer consider e.g. 'nsNumber as Int' or 'nsValue as NSRange' to be valid coercions. This would break compatibility with Swift 3, so in Swift 3 mode, accept the coercion, but *also* accept a checked cast without a warning, and raise a migration warning about the unchecked coercion.
2017-01-13 13:51:27 -08:00
Hugh Bellamy
7a5ef4bdd1 Support building swift/AST with MSVC on Windows 2017-01-09 09:05:06 +00:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Mark Lacey
ed328af079 Add explicit type operands to two Exprs only created during type checking.
We need to use the types stored in the constraint system's type map when
creating these.
2017-01-04 16:21:29 -08:00
Mark Lacey
36b07395bc Add type accessor arguments to expression APIs that access types.
These are used from within constraint system code, and for those uses we
need to be reading from the constraint system type map.

Add the parallel constraint system interfaces that call into the
Expr interfaces with the appropriate accessors.
2017-01-04 14:25:38 -08:00
Joe Groff
0c9297862f Sema: Handle type-checking for withoutActuallyEscaping.
withoutActuallyEscaping has a signature like `<T..., U, V, W> (@nonescaping (T...) throws<U> -> V, (@escaping (T...) throws<U> -> V) -> W) -> W, but our type system for functions unfortunately isn't quite that expressive yet, so we need to special-case it. Set up the necessary type system when resolving an overload set to reference withoutActuallyEscaping, and if a type check succeeds, build a MakeTemporarilyEscapableExpr to represent it in the type-checked AST.
2016-12-22 17:51:26 -08:00
Doug Gregor
fa47d57b4e [AST] Remove CheckedCastKind::BridgeFromObjectiveC.
It's not handled any differently from ValueCast, so simplify it away.
2016-12-21 13:46:14 -08:00
Doug Gregor
e97ab635ea [Constraint solver] Separate bridging conversions from other conversions.
Previously, bridging conversions were handled as a form of "explicit
conversion" that was treated along the same path as normal
conversions in matchTypes(). Historically, this made some
sense---bridging was just another form of conversion---however, Swift
now separates out bridging into a different kind of conversion that is
available only via an explicit "as". This change accomplishes a few
things:

* Improves type inference around "as" coercions. We were incorrectly
  inferring type variables of the "x" in "x as T" in cases where a
  bridging conversion was expected, which cause some type inference
  failures (e.g., the SR-3319 regression).

* Detangles checking for bridging conversions from other conversions,
  so it's easier to isolate when we're applying a bridging
  conversion.

* Explicitly handle optionals when dealing with bridging conversions,
  addressing a number of problems with incorrect diagnostics, e.g.,
  complains about "unrelated type" cast failures that would succeed at
  runtime.

Addresses rdar://problem/29496775 / SR-3319 / SR-2365.
2016-12-21 13:46:14 -08:00
Mark Lacey
e3636ac2d1 Use llvm::function_ref rather than std::function.
Thanks to Jordan for the suggestion!
2016-12-14 12:49:02 -08:00
Mark Lacey
59ce1ff73c Add a function parameter to Expr::propagateLValueAccessKind.
This parameter implements getType() for the given expression, making
it possible to use this from within the constraint system, which now
has it's own side map for types of expressions.
2016-12-12 23:55:25 -08:00
Argyrios Kyrtzidis
fc678740db [code-completion] Avoid a tentantive parse when in code-completion mode and make sure CodeCompletionExpr has a token range.
The tentantive parse is used for diagnostic purposes but can cause code-completion to delay the same decl twice.
The range of CodeCompletionExpr was previously character range which invalidated invariants of the AST.

Fixes:
	validation-test/IDE/crashers_fixed/084-swift-parser-consumedecl.swift
	validation-test/IDE/crashers_fixed/104-swift-gettypeofcompletioncontextexpr.swift
2016-12-05 17:09:49 -08:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Maxwell Swadling
d77d0764f7 Fixed a bug in AssignExpr that caused it to create invalid source ranges 2016-10-16 17:41:58 -07:00
Maxwell Swadling
339e40fb02 Fixed an assert caused when a TupleExpr that didn't have a valid SourceRange had a valid SourceLoc for the first element but not for the last 2016-10-08 23:31:01 -07:00
Slava Pestov
e97df4a285 Sema: Implicit conversion for single-expression closures of Never type
This fixes a usability regression with the removal of @noreturn
in Swift 3. Previously, it was legal to write this:

let callback: () -> Int = { fatalError() }

Now that the special @noreturn attribute has been replaced with
a Never type, the above fails to typecheck, because the expression
now has type 'Never', and we expect a value of type 'Int'.

Getting around this behavior requires ugly workarounds to force the
parser to treat the body as a statement rather than an expression;
for example,

let callback: () -> Int = { _ = (); fatalError() }

This patch generalized single-expression closures to allow
the 'Never to T' conversion. Note that this is rather narrow
in scope -- it only applies to closure *literals*, single-expression
ones at that, not arbitrary function *values*.

In fact, it is not really a conversion at all, but more of a
desugaring rule for single-expression closures. They can now be
summarized as follows:

- If the closure literal has contextual return type T and
  the expression has Never type, the closure desugars as
  { _ = <expr> }, with no ReturnStmt.

- If the closure literal has contextual return type T for some
  non-void type T, the closure desugars as { return <expr> };
  the expression type must be convertible to T.

- If the closure literal has contextual return type Void, and
  the expression has some non-Void type T, the closure
  desugars as { _ = <expr>; return () }.

Fixes <rdar://problem/28269358> and <https://bugs.swift.org/browse/SR-2661>.
2016-09-22 23:40:25 -07:00
practicalswift
3a4ee89034 [gardening] Use consistent formatting. 2016-09-17 12:12:49 +02:00
Jordan Rose
4ec661d9b7 Fix the SourceRange of an AssignExpr with an implicit source.
Fixed by Maxwell Swadling, unit test by me.
2016-09-14 19:55:08 -07:00
Rintaro Ishizaki
339387e95b [AST] Remove DefaultValueExpr type (#4713)
The last instantiation of this type was removed in 68bcb0d2af
2016-09-12 16:50:02 +09:00
Doug Gregor
78b007f178 Always create a DefaultArgumentInitializer for a parameter with a default argument.
As with pattern binding initializer contexts, we were trying to
optimize away these contexts, leading to an unpredictable AST.
2016-09-02 13:51:00 -07:00
Pavel Yaskevich
8e04a84239 [Type checker] Introduce directional path consistency algorithm
DPC algorithm tries to solve individual sub-expressions and combine
resolved types as a way to reduce pre-existing OSR domains. Solving
is done bottom-up so each consecutive sub-expression tightens
possible solution domain even further.
2016-08-24 18:40:28 -07:00
Mishal Shah
a84704f4b5 Revert "[Type checker] Introduce directional path consistency algorithm" 2016-08-24 17:53:12 -07:00
Pavel Yaskevich
de51b01195 [Type checker] Introduce directional path consistency algorithm
DPC algoritm tries to solve individual sub-expressions and combine
resolved types as a way to reduce pre-existing OSR domains. Solving
is done bottom-up so each consecutive sub-expression tightens
possible solution domain even further.
2016-08-24 14:38:46 -07:00
Doug Gregor
f99904ac66 Eliminate the useless flag -enable-experimental-collection-casts.
This eliminates a pile of now-dead code in:
  * The type checker, where we no longer have special cases for bridging conversions
  * The expression ASTs, where we no longer need to distinguish bridging collection up/down casts
  * SILGen, which no longer uses

Still to come is the removal of the
_(set|dictionary)Bridge(From|To)ObjectiveC(Conditional)? entrypoints
from the standard library. They're still used by some tests.
2016-08-19 21:17:10 -07:00
Argyrios Kyrtzidis
9bd3e48b21 [AST] Fix the source range for InterpolatedStringLiteralExpr.
This allows fixits to be correctly applied when wrapping such an expression.
2016-08-10 15:22:03 -07:00
John McCall
a6e1e87585 Add implicit conversions and casts from T:Hashable <-> AnyHashable.
rdar://27615802
2016-08-04 23:13:27 -07:00
Chris Lattner
8c2d0c5a28 minor fix to a setter, NFC. 2016-08-03 16:55:17 -07:00
Chris Lattner
1d21b4e4e1 Add a bit and some diagnostics logic to help with the ongoing id-as-any project.
This is NFC because nothing sets the bit yet, it is just to aid an ongoing
investigation.
2016-08-03 16:45:01 -07:00
Robert Widmann
80fb5c1c5a Remove usage of getMetatypeLoc() 2016-07-29 16:59:14 -07:00