Commit Graph

1659 Commits

Author SHA1 Message Date
Rintaro Ishizaki
cfeae64712 [AST] Add reference to original expression in MakeTemporarilyEscapableExpr
This is needed to restore original call expression in SanitizeExpr.
2018-08-10 18:19:53 +09:00
Pavel Yaskevich
6d64b1c8a5 [Diagnostics] Some diagnostics possible only when locator is resolved down to expression 2018-08-09 22:23:31 -07:00
Pavel Yaskevich
e2cde5acc2 [Diagnostics] Port 'missing optional unwrap' diagnostic to new abstraction 2018-08-09 17:47:06 -07:00
Pavel Yaskevich
d72c204bad [Diagnostics] Port member access on optional base diagnostic to new abstraction 2018-08-09 17:03:20 -07:00
Pavel Yaskevich
a564042fdc [Diagnostics] Port missing explicit conversion to new abstraction 2018-08-09 17:01:54 -07:00
Pavel Yaskevich
9f9904b65d [Diagnostics] Port missing & diagnostic to new abstraction 2018-08-09 13:57:57 -07:00
Pavel Yaskevich
f5aa0d9c75 [Diagnostics] Port missing force downcast diagnostic to new abstraction 2018-08-09 11:56:19 -07:00
Pavel Yaskevich
157dc719e0 [Diagnostics] Port implicitly escaping to type conversion diagnostics to new abstraction 2018-08-09 11:05:33 -07:00
Slava Pestov
8d4b8e31aa Sema: Remove ScalarToTuple conversion
This either became dead shortly after the removal of Swift 3
compatibility mode from the constraint solver, or even earlier.

Note that the code completion test change is actually correct
because (Any) -> () is not convertible to () -> () in the
language.
2018-08-08 10:18:52 -07:00
Slava Pestov
b581c63e6b AST: Remove TypeBase::getRValueObjectType()
This would look through one-element tuples, which is no longer necessary.
2018-08-08 10:18:52 -07:00
Joe Groff
cf664b2654 Merge pull request #18552 from jckarter/array-of-class-bridging
Sema: Apply metatype-to-object conversions even without restriction hints.
2018-08-08 09:43:24 -07:00
Joe Groff
0f085dc5ec Sema: Apply metatype-to-object conversions even without restriction hints.
In some cases, such as when pushing a collection conversion down to per-element conversions, we'll coerce a subtype metatype to AnyObject, as in:

```
func f(_: [AnyObject]) {}
f([NSString.self, NSObject.self]) // Type checks as [NSObject.Type] converted to [AnyObject]
```

and only record the restriction kinds used in the indirect steps NSString -> NSObject and NSObject.Type -> AnyObject without recording the jump from NSString.Type to AnyObject. coerceToType ought to apply this subtyping rule even without such a hint, though, since the restriction kind is intended only as an optimization. Fixes rdar://problem/42666956 .
2018-08-07 18:14:31 -07:00
Slava Pestov
528c632f8d Sema: Fix two unused variable warnings 2018-08-06 23:22:16 -07:00
Pavel Yaskevich
776485878f [ConstraintSystem] NFC: Move new diagnostics into separate files - Diagnostics.(h|cpp) 2018-08-06 13:08:47 -07:00
Pavel Yaskevich
d201e552e5 [Diagnostics] Move re-labeling diagnostic to use new abstraction 2018-08-04 16:52:45 -07:00
Pavel Yaskevich
5750b07daa [ConstraintSystem] Add new FailureDiagnostic abstraction
Aim of this new diagnostic abstraction is to encapsulate each
individual failure into its own class with some shared base.
Good example of this - diagnostics related to generic requirement
failures, where each kind (conformance, same-type etc.) has
some specific logic e.g. diagnostic message but the all share
the same traits like affected declaration/requirement.
2018-08-04 11:25:54 -07:00
Pavel Yaskevich
0f9f4e99ce [ConstraintSystem] NFC: Move getOverloadChoice{IfAvailable} to Solution
Since information comes from `Solution` anyway, it's good to have
that logic localized, but it's also useful for diagnostics based on
fixes attached to solutions.
2018-08-03 20:50:54 -07:00
Pavel Yaskevich
913f3710c6 Merge pull request #18484 from xedin/diag-req-failures-via-fixes
[ConstraintSystem] Diagnose missing conformance requirements via "fixes"
2018-08-03 19:23:06 -07:00
Pavel Yaskevich
e4da7a1167 [ConstraintSystem] Look through metatype of base while diagnosing conformance failures
Having `.Type` in `requires conformance` diagnostic is unnecessary.
2018-08-03 14:42:07 -07:00
Pavel Yaskevich
9d50122e75 [ConstraintSystem] NFC: Fix typo in FixKind::AddConformance name 2018-08-03 14:33:19 -07:00
gregomni
a37229e40a Omit recording conversion restrictions in a solution that apply can just as easily figure out itself from the shape of the types. 2018-08-03 11:02:04 -07:00
Pavel Yaskevich
6dfa8f21eb [ConstraintSystem] Try to dig out parameter position only if apply expr is available
While trying to diagnose missing conformances don't attempt
to lookup parameter position if the parent apply expression
is not available, which could happen when fixes are produced
as part of the sub-expression diagnostics.
2018-08-02 21:51:21 -07:00
Pavel Yaskevich
29e34e66e7 [ConstraintSystem] Diagnose missing conformance requirements via "fixes"
If fixes are allowed let solver record missing protocol conformance
requirements and assume that `conformsTo` constraint is successfully
solved, this helps to diagnose such errors without involving
heavy-weight expression based diagnostics.

Resolves: rdar://problem/40537858
2018-08-02 16:40:34 -07:00
gregomni
5faa8bf4d1 Don't offer force-unwrap of the base as a possible fixit for optional
member access if optional chaining is sure to be valid.
2018-07-27 13:56:24 -07:00
Doug Gregor
76eb767b97 [Type checker] Request nominal layout for the result types of function calls.
Once you’ve called a function and retrieved a result, IRGen will want
layout information for the result type. Make sure that the type checker
precomputes it.
2018-07-26 15:46:29 -07:00
Pavel Yaskevich
a9ebaef2e5 Merge pull request #18227 from xedin/diagnose-missing-labels-using-fixes
[ConstraintSystem] Use fixes to diagnose missing/extraneous/incorrect argument labels
2018-07-26 12:01:28 -07:00
Pavel Yaskevich
dfad872cea [ConstraintSystem] Attempt to apply fixes in AST walker order
This makes sure that the diagnostics appear in the stable order
which is closer to what users would expect e.g. evaluation
order, otherwise, because disjunctions are currently attempted
based on their size, ordering of error messages produced by
applying fixes is completely arbitrary.
2018-07-25 13:32:16 -07:00
Pavel Yaskevich
62eccd53ad [ConstraintSystem] Use fixes to diagnose missing argument labels
Let the solver disregard missing argument labels and record correct
ones, so such problem could be diagnosed later on iff there were no
other more serious failures.
2018-07-24 22:11:56 -07:00
Brent Royal-Gordon
0be713b5a0 [Sema] Add arg parens to two generated calls 2018-07-22 19:33:56 -07:00
Slava Pestov
e1da265873 Sema: Remove uses of AbstractFunctionDecl::getParameterLists() 2018-07-19 21:21:17 -07:00
Doug Gregor
b70466dc63 [Type Checker] Add a request kind for computing 'ValueDecl::isObjC()'.
Still a WIP
2018-07-18 14:50:39 -07:00
Pavel Yaskevich
aa9b3d8474 [TypeChecker] SE-0213: Implement literal init via coercion
Implementation is as follows: In `preCheckExpression` try to
detect if there is `T(literal)` call in the AST, replace it with
implicit `literal as T`, while trying to form type-checked AST,
after constraint solving, restore source information and drop
unnecessary coercion expression.

Resolves: rdar://problem/17088188
Resolves: rdar://problem/39120081
Resolves: rdar://problem/23672697
Resolves: rdar://problem/40379985
2018-07-17 12:08:59 -07:00
Pavel Yaskevich
10ddb04613 [ConstraintSystem] Add SuppressDiagnostics/AllowUnresolvedTypeVariables flags
Instead of mixing flags between type-checker and constraint solver, let's
move the ones which are useful in constraint system there. Doing
so allows for `solveForExpression` to be moved from `TypeChecker` to
`ConstraintSystem` which consolidates solver logic.

It also allows to set these flags as part of constraint generation/solving,
which is sometimes important.
2018-07-15 23:23:45 -07:00
Mark Lacey
eb57e209e3 Merge pull request #17691 from rudkx/remove-swift-3-in-expr-typechecking
Remove support for -swift-version 3 from the expression type checker.
2018-07-14 19:03:56 -07:00
Doug Gregor
5db1901d57 [Type checker] Emit coalesce-or-force-unwrap Fix-Its for necessary unwraps more consistently.
Replace the last (and most obscure) use of the poor “use ‘?’ or ‘!’” diagnostic with the
new, more explanatory version that provides separate notes with Fix-Its for coalescing or
force-unwrapping the value.

Finishes rdar://problem/42081852.
2018-07-13 16:48:15 -07:00
Doug Gregor
e7eac0af22 [Type checker] Extend the diagnostics for unwrapping the base of a member access.
Introduce a new fix kind into the constraint solver to cover unwrapping the base
of a member access so we can refer to the a member of the unwrapped base.
Wire this fix kind to the just-added diagnostic that suggests either the
chaining ‘?’ or the force-unwrap ‘!’ via separate, descriptive Fix-Its.

Example:

error: value of optional type 'X?' must be unwrapped to refer to member 'f' of wrapped base type 'X'
  let _: Int = x.f()
               ^
note: chain the optional using '?' to access member 'f' only for non-'nil' base values
  let _: Int = x.f()
               ^
                ?
note: force-unwrap using '!' to abort execution if the optional value contains 'nil'
  let _: Int = x.f()
               ^
                !

Before this, we would sometimes get a Fix-It for just ‘?’ and sometimes get a Fix-It for the
coalescing ‘??’, neither of which is likely to be right.

More work on rdar://problem/42081852.
2018-07-13 16:26:03 -07:00
Doug Gregor
945c09b1cc [Type checker] Improve diagnostics when an optional value is not unwrapped.
When we determine that an optional value needs to be unwrapped to make
an expression type check, use notes to provide several different
Fix-It options (with descriptions) rather than always pushing users
toward '!'. Specifically, the errors + Fix-Its now looks like this:

    error: value of optional type 'X?' must be unwrapped to a value of
        type 'X'
      f(x)
        ^
    note: coalesce using '??' to provide a default when the optional
        value contains 'nil'
      f(x)
        ^
          ?? <#default value#>
    note: force-unwrap using '!' to abort execution if the optional
        value contains 'nil'
      f(x)
         ^
         !

Fixes rdar://problem/42081852.
2018-07-13 11:02:04 -07:00
Mark Lacey
a5a1a63ed6 Silence a couple release build warnings about unused variables. 2018-07-12 07:52:02 -07:00
Mark Lacey
efb173857a Merge branch 'master' into remove-swift-3-in-expr-typechecking 2018-07-11 23:49:44 -07:00
Mark Lacey
aa30cc5adc Merge branch 'master' into remove-swift-3-in-expr-typechecking 2018-07-11 20:55:32 -07:00
Pavel Yaskevich
88e5e1a004 Merge pull request #17811 from xedin/fix-load-with-paren-expr
[TypeChecker] Make sure that `LoadExpr` is always precedes parens/force-value
2018-07-11 17:08:37 -07:00
Slava Pestov
4fa4133134 Sema: Fix crash with UnresolvedType in coerceExistential()
Fixes <rdar://problem/34357545>.
2018-07-10 17:01:12 -07:00
Pavel Yaskevich
b1bd9b6d05 [TypeChecker] Make sure that load always emitted before parens/forcing
While trying to emit implicit load expression make sure that it's
done in a way where force/paren expression is always top level,
that leads to better fix-its and, in case of forcing, more compact
SIL by intermediate optional container.

Resolves: [SR-8150](https://bugs.swift.org/browse/SR-8150) / rdar://problem/41725207
2018-07-07 19:25:41 -07:00
Slava Pestov
cb4a248e6b Sema: Diagnose non-required class initializer calls on protocols with superclass contraint 2018-07-06 23:39:39 -07:00
Mark Lacey
28f759c8b0 Remove support for -swift-version 3 from the expression type checker.
This is the obvious stuff. There will probably be more fallout.
2018-07-06 16:10:08 -07:00
Slava Pestov
381483bd74 AST: Remove Expr's LValueAccessKind 2018-07-05 23:54:13 -07:00
Joe Groff
01dea286ee Merge pull request #17679 from jckarter/nested-collection-upcast-peephole
Sema: Clear the types of exprs changed by collection upcast peepholes.
2018-07-02 19:05:17 -07:00
Joe Groff
64c1737211 Sema: Clear the types of exprs changed by collection upcast peepholes.
`finish{Array,Dictionary}Expr` currently invoke `cs.cacheExprTypes` after building their semantic exprs, which in a nested collection expression, immediately undoes the type changes done by this peephole, leading to crashes due to inconsistencies in the AST later. rdar://problem/41040820
2018-07-02 15:00:30 -07:00
John McCall
9bee3cac5a Generalize storage implementations to support generalized accessors.
The storage kind has been replaced with three separate "impl kinds",
one for each of the basic access kinds (read, write, and read/write).
This makes it far easier to mix-and-match implementations of different
accessors, as well as subtleties like implementing both a setter
and an independent read/write operation.

AccessStrategy has become a bit more explicit about how exactly the
access should be implemented.  For example, the accessor-based kinds
now carry the exact accessor intended to be used.  Also, I've shifted
responsibilities slightly between AccessStrategy and AccessSemantics
so that AccessSemantics::Ordinary can be used except in the sorts of
semantic-bypasses that accessor synthesis wants.  This requires
knowing the correct DC of the access when computing the access strategy;
the upshot is that SILGenFunction now needs a DC.

Accessor synthesis has been reworked so that only the declarations are
built immediately; body synthesis can be safely delayed out of the main
decl-checking path.  This caused a large number of ramifications,
especially for lazy properties, and greatly inflated the size of this
patch.  That is... really regrettable.  The impetus for changing this
was necessity: I needed to rework accessor synthesis to end its reliance
on distinctions like Stored vs. StoredWithTrivialAccessors, and those
fixes were exposing serious re-entrancy problems, and fixing that... well.
Breaking the fixes apart at this point would be a serious endeavor.
2018-06-30 05:19:03 -04:00
John McCall
9e905125f8 Perform function conversions when converting between autoclosures.
This is correct because it's the apparent rule used by CSSimplify:
value-to-autoclosure conversion is considered if and only if the
input type is not an autoclosure function type.

The real solution to this problem is that @autoclosure should be tracked
as a bit on the parameter type instead of as a bit on function types.
Slava has a PR leading towards that (https://github.com/apple/swift/pull/10094),
but it causes a source-compatibility problem when forwarding autoclosures.
You really shouldn't be able to forward autoclosures, but that's an
issue for the core team to resolve, and in the meantime there's this bug.

Fixes rdar://41219750.
2018-06-19 18:57:50 -04:00