Commit Graph

918 Commits

Author SHA1 Message Date
Joe Groff
6ad01d63f6 Sema: Feed argument label and constraint locator info from key path subscript components into getCalleeDeclAndArgs.
Fixes SR-5189 | rdar://problem/32713662.
2017-07-10 14:55:08 -07:00
Robert Widmann
abd5aa8e6d Rename some X-Value-related entities
* Rename coerceToMaterializableValue to coerceToRValue

* Rename isLValueType to hasLValueType to better match the
intended semantics of the member.
2017-06-14 13:18:45 -07:00
John McCall
b542c75cb1 Use abstract implicit-conversion expressions for bridging cases instead of
expanding the conversion calls in Sema.
2017-06-11 01:39:51 -04:00
Mark Lacey
d1a0b35447 [Constraint solver] More type map changes.
A few more changes to use the side map for expression types in the
constraint solver. Still not enabled.
2017-06-02 08:13:57 -07:00
Mark Lacey
fb5ac6df02 [Constraint solver] Fix an issue with rewriting OpenExistentialExpr.
If we fail when doing a coercion while generating an OpenExistentialExpr
when applying a solution during type checking, make sure that the opaque
value on that OpenExistentialExpr is cleared.

We do not visit these during normal AST walks because they normally
appear in the subexpression held by the OpenExistentialExpr. In this
case, however, we replace that subexpression with an ErrorExpr which
means we will not visit the opaque value at all, so certain operations,
like setting the type on the opaque value, will never happen, and we can
run into problems later by code that assumes the type is set.

It seems reasonable to just clear these out in cases like this since
they are not reachable by any normal means.
2017-06-01 20:18:29 -07:00
Pavel Yaskevich
c94fe94d5d [Diagnostics] Add a fix-it for optional to raw representable type conversion
Situations where there is a contextual RawRepresentable type is
used incorrectly would produce `<Type>(rawValue: )` fix-it only
in cases where neither or both sides of the expression are optional.
Let's fix that by adding a fix-it for optional to contextual raw
value type conversion.

Resolves: rdar://problem/32431736
2017-05-31 13:58:17 -07:00
Slava Pestov
1b254a9843 Sema: Kill off old modeling of generic arguments 2017-05-24 20:39:10 -07:00
Slava Pestov
7ec163a83a Parse: Simplify parsing of generic types
Now that preCheckExpression() can handle more cases, we can
eliminate a special case where sometimes we would make
DeclRefExprs instead of TypeExprs for references to generic
types.
2017-05-23 02:10:03 -07:00
Slava Pestov
0c474eb681 Sema: Move some code from preCheckExpression() pass to static methods on TypeExpr
This is just an NFC refactoring to simplify the pre-check
pass a little bit.
2017-05-21 18:16:36 -07:00
practicalswift
492f5cd35a [gardening] Remove redundant repetition of type names (DRY): RepeatedTypeName foo = dyn_cast<RepeatedTypeName>(bar)
Replace `NameOfType foo = dyn_cast<NameOfType>(bar)` with DRY version `auto foo = dyn_cast<NameOfType>(bar)`.

The DRY auto version is by far the dominant form already used in the repo, so this PR merely brings the exceptional cases (redundant repetition form) in line with the dominant form (auto form).

See the [C++ Core Guidelines](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#es11-use-auto-to-avoid-redundant-repetition-of-type-names) for a general discussion on why to use `auto` to avoid redundant repetition of type names.
2017-05-05 09:45:53 +02:00
Huon Wilson
07c5ab8fb2 Implement \ syntax for Swift key paths.
This introduces a few unfortunate things because the syntax is awkward.
In particular, the period and following token in \.[a], \.? and \.! are
token sequences that don't appear anywhere else in Swift, and so need
special handling. This is somewhat compounded by \foo.bar.baz possibly
being \(foo).bar.baz or \(foo.bar).baz (parens around the type), and,
furthermore, needing to distinguish \Foo?.bar from \Foo.?bar.

rdar://problem/31724243
2017-05-01 16:06:15 -07: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
Slava Pestov
b9494b0798 AST: Add an assertion to MemberRefExpr constructor 2017-04-10 17:04:34 -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
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
Slava Pestov
5d39fe9314 AST: Fix a comment typo 2017-03-26 00:00:54 -07: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
Slava Pestov
162b2d252e AST: Include gardening to minimize dependencies on Expr.h
A lot of files transitively include Expr.h, because it was
included from SILInstruction.h, SILLocation.h and SILDeclRef.h.

However in reality most of these files don't do anything
with Exprs, especially not anything in IRGen or the SILOptimizer.

Now we're down to 171 files in the frontend which depend on
Expr.h, which is still a lot but much better than before.
2017-03-12 22:26:56 -07:00
swift-ci
6ee6378e5d Merge pull request #8029 from rudkx/more-cs-typemap 2017-03-10 18:42:47 -08:00
Mark Lacey
b592260cdd [Constraint solver] More updates for using the constraint solver type map. 2017-03-10 18:16:09 -08:00
Alex Hoppen
1b7055db5a [Gardening] Change calls of getName().isOperator() to isOperator() 2017-03-10 09:06:20 +00:00
Joe Groff
6752266798 Merge pull request #7534 from jckarter/covariant-self-init-delegation
Sema: Type-check initializer delegation as a covariant expression.
2017-02-17 17:32:03 -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
Joe Groff
eae044c07d Sema: Type-check initializer delegation as a covariant expression.
If a convenience initializer in a subclass delegated to an inherited initializer from its base, we would end up type-checking the reference to the base class constructor as returning the base type, leading to type mismatches in the result AST and downstream crashes. We can wrap up the synthesized OtherConstructorRefExpr in a CovariantFunctionConversionExpr, which will trick the type checker into propagating the covariant result that gets rebound to `self` on return, avoiding this problem. (For now, I'm avoiding making the constructor decl formally have a Self return type, since that exposes a bunch of downstream breakage in code paths that only expect FuncDecls to be covariant, and also affects the mangling of constructors, causing a bunch of test case thrash we really don't want to inflict on the 3.1 branch.)
2017-02-16 13:19:11 -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
Slava Pestov
81d46a3084 Sema: Follow-on fix for <https://github.com/apple/swift/pull/6267>
Fixes <https://bugs.swift.org/browse/SR-3656>.
2017-01-17 23:06:16 -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
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
practicalswift
38be6125e5 [gardening] C++ gardening: Terminate namespaces, fix argument names, ...
Changes:
* Terminate all namespaces with the correct closing comment.
* Make sure argument names in comments match the corresponding parameter name.
* Remove redundant get() calls on smart pointers.
* Prefer using "override" or "final" instead of "virtual". Remove "virtual" where appropriate.
2016-12-17 00:32:42 +01: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
56fc0d12d6 Fix -DNDEBUG build. 2016-12-13 11:30:20 -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
Michael Gottesman
1af1cbfb76 [gardening] Add a bunch of end namespace comments found by clang-tidy. 2016-12-06 19:22:52 -08:00
Rintaro Ishizaki
4250f2c598 [AST] CompositionTypeRepr is not 'isSimple()'
We can't simply append '.self' for this.
2016-11-29 15:28:48 +09: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
91e3c67493 Updated TupleExpr's getSourceRange to inspect child elements source ranges 2016-10-16 13:30:43 -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
Doug Gregor
50341da32b Use "TypeBase::hasError()" rather than "is<ErrorType>()" where needed.
In most places where we were checking "is<ErrorType>()", we now mean
"any error occurred". The few exceptions are in associated type
inference, code completion, and expression diagnostics, where we might
still work with partial errors.
2016-10-07 10:58:23 -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
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
John McCall
a6e1e87585 Add implicit conversions and casts from T:Hashable <-> AnyHashable.
rdar://27615802
2016-08-04 23:13:27 -07:00
Doug Gregor
a9536906ff [SE-0111] Drop argument labels on references to function values.
When referencing a function in the type checker, drop argument labels
when we don't need them to type-check an immediate call to that
function. This provides the semantic behavior of SE-0111, e.g.,
references to functions as values produce unlabeled function types,
without the representational change of actually dropping argument
labels from the type system.

At the moment, this only works for bare references to functions. It
still needs to be pushed through more of the type checker and more AST
nodes to work in the general case.

Keep this work behind the frontend flag
-suppress-argument-labels-in-types for now.
2016-07-28 15:40:11 -07:00
Doug Gregor
8c7e75afa0 [AST] Eliminate OverloadedMemberRefExpr.
This expression kind was introduced in exactly one place, and only
with one member. That place can use MemberRefExpr instead.
2016-07-28 14:44:23 -07:00
Doug Gregor
e4d8f486a8 Simplify AST for string literals to not depend on implicit tuple splat.
String literal expressions, as well as the magic literals #file and
tuple value that is then fed into one or two call expressions. For
string literals, that tuple value was implicitly splatted, breaking
AST invariants.

Instead, keep string literals and these magic literals that produce a
string as a single expression node, but store the declarations that
will be used to transform the raw literal into the complete
literal. SILGen will form the appropriate calls. This representation
is far simpler---the AST no longer has a bunch of implicit nodes---and
doesn't break AST invariants.
2016-07-27 12:30:22 -07:00