Commit Graph

1147 Commits

Author SHA1 Message Date
Pavel Yaskevich
d673ed0989 Merge pull request #30519 from xedin/rdar-52204414
[ConstraintSystem] Don't allow explicit closure result to be implicitly converted to `Void`
2020-03-20 09:36:17 -07:00
Pavel Yaskevich
4876996b8c Merge pull request #30510 from HassanElDesouky/SR-12309-FollowUp
[CSGen] Diagnose `nil` with any number of parentheses
2020-03-20 00:13:50 -07:00
Robert Widmann
21cfcfef2c Merge pull request #30505 from CodaFi/ligated-legacy
[NFC] Remove the Legacy Semantic Queries Bit
2020-03-19 13:45:27 -07:00
Hassan El Desouky
5ff6fe20a9 Remove incorrect comment 2020-03-19 22:31:01 +02:00
Hassan El Desouky
a72ea640e6 Handle nil with any number of parentheses 2020-03-19 21:41:22 +02:00
Robert Widmann
6d60d01420 [NFC] Remove the Legacy Semantic Queries Bit
Clients that wish to avoid semantic requests should decline to register
those requests.
2020-03-19 11:04:12 -07:00
Doug Gregor
f2e581c7fc [Type checker] Look through reference storage types for typed patterns.
Fixes a regression caused by properly setting the context for checking
the type in a typed pattern.
2020-03-19 11:01:56 -07:00
Doug Gregor
3abea6be65 [Constraint system] Use the PatternBindingDecl context when possible.
Make sure that we're resolving types and patterns using the
PatternBindingDecl context, both for the type resolver context and the
contextual pattern used for pattern resolution.

Fixes a regression with implicitly-unwrapped options reported as
SR-11998 / rdar://problem/58455441.
2020-03-18 21:09:06 -07:00
Pavel Yaskevich
c72940f2c7 [ConstraintSystem] Default multi-statement closure result to Void only after resolving
Let's remove a side-effect from `ConstraintGenerator::inferClosureType`
and default result type to `Void` for multi-statement closures after
closure has been resolved.
2020-03-18 17:48:56 -07:00
Pavel Yaskevich
2d6170b847 [TypeChecker] Requestify check to determine if closure has explicit result
Determine whether closure body has any explicit `return`
statements which could produce a non-void result.
2020-03-18 17:06:15 -07:00
Robert Widmann
70b6bbcb13 Remove swift::createTypeChecker
Replace it with the "legacy semantic queries" bit. The remaining client
of this bit is SourceKit, which appears to require this bit be set
conditionally so certain semantic property wrapper requests return
a sentinel value.

We should migrate these requests to a syntactic interface as soon as
possible.

rdar://60516325
2020-03-16 19:20:22 -07:00
Robert Widmann
c3c490efb0 Remove the ability to reference instances of TypeChecker 2020-03-16 19:19:02 -07:00
HassanElDesouky
e747dc25b1 Resolve issues 2020-03-14 08:02:23 +02:00
HassanElDesouky
8d5a33ee89 Move to visitNilLiteralExpr 2020-03-14 07:39:44 +02:00
HassanElDesouky
ceb3f3842f [SR-12309] Add more tests 2020-03-14 03:06:10 +02:00
HassanElDesouky
8195cce1d3 [SR-12309] Cannot force unwrap 'nil' 2020-03-14 01:28:28 +02:00
Pavel Yaskevich
f1f3b60713 [CSGen] Clarify locators for some of the patterns
- optional object type of `.some` pattern ends with `OptionalPayload`
- type of sub-pattern used in a cast points to underlying sub-pattern declaration
- Enum element:
  - parent type locator ends with `ParentType`
  - member lookup constraint locator ends at `Member`
2020-03-10 13:56:32 -07:00
Doug Gregor
1a981f917c [Constraint system] Clean up constraints associated with patterns.
Wherever we have constraints that involve pattern matching, use the
PatternMatch locator element. Additionally, don't use the TupleElement
locator element for tuple patterns, because it violates assumptions used
for diagnostics.

The new test was crashing; now it has a terrible diagnostic for which I
need to think harder about a fix.
2020-03-05 23:06:21 -08:00
Doug Gregor
8191aa4924 Merge pull request #30174 from DougGregor/function-builder-switch
[Constraint system] Implement switch support for function builders.
2020-03-03 12:34:08 -08:00
Doug Gregor
4b43573693 [Constraint system] Implement switch support for function builders.
Implement support for switch statements within function builders. Cases can
perform arbitrary pattern matches, e.g.,

    tuplify(true) { c in
      "testSwitchCombined"
      switch e {
      case .a:
        "a"
      case .b(let i, _?), .b(let i, nil):
        i + 17
      }
    }

subject to the normal rules of switch statements. Cases within function
builders cannot, however, include “fallthrough” statements, because those
(like “break” and “continue”) are control flow.

The translation of performed for `switch` statements is similar to that of
`if` statements, using `buildEither(first:)` and `buildEither(second:)` on
the function builder type.

This is the bulk of switch support, tracked by rdar://problem/50426203.
2020-03-02 17:25:25 -08:00
Doug Gregor
13b200ddd5 [Constraint system] Generalize saved ASTNode -> solution target mapping.
We are currently only using the “solution targets” map for statement
conditions, but we will need it for more entities soon. Start generalizing
now.
2020-03-02 08:43:55 -08:00
Holly Borla
87bb7755c2 Merge pull request #30101 from hborla/dynamic-replacement-type-erasure
[Sema] Implement type erasure for dynamic replacement.
2020-02-28 09:37:33 -08:00
Holly Borla
3cdc30ffeb [Sema] Support type erasure for dynamic replacement in function
builders.
2020-02-27 09:01:16 -08:00
Holly Borla
96d7434fd0 [Sema] Implement type erasure for dynamic replacement when the
dynamically replaceable function returns an opaque type.
2020-02-25 19:53:25 -08:00
Doug Gregor
6ad4b252ef [Constraint system] Address review comments on if patterns in function builders 2020-02-25 14:06:05 -08:00
Doug Gregor
4830c48960 [Constraint system] Support if let / if case in function builders.
Use the generalized constraint generation and binding for patterns to
introduce support for if-let and if-case in function builders, handling
arbitrary patterns.

Part of function builder generalization, rdar://problem/50426203.
2020-02-25 09:44:06 -08:00
Doug Gregor
3f2f79a699 [Constraint system] Fold pattern variable binding into constraint gen.
Rather than re-walk the pattern to create type bindings for the variables
that show up in the pattern, assign types to each of the variables as part
of constraint generation for the pattern. Only do this in contexts
where we will need the types, e.g., function builders.
2020-02-25 08:51:56 -08:00
Doug Gregor
d607d3a068 [Constraint system] Custom diagnostics for failed pattern matches.
Extend the constraint system’s diagnostics with specific handling for
matching an enum element pattern that has a subpattern (i.e., to capture
associated values) against an enum case that does not have any associated
value. This brings diagnostics for the new code path on par with the existing
diagnostics of coercePatternToType.
2020-02-24 00:48:15 -08:00
Doug Gregor
dcf7ddeb3a [Constraint system] Generate constraints for EnumElement patterns.
Generate a complete set of constraints for EnumElement patterns, e.g.,

    case let .something(x, y)

Most of the complication here comes from the implicit injection of optionals,
e.g., this case can be matched to an optional of the enum type of which
`something` is a member. To effect this change, introduce a locator for
pattern matching and use it to permit implicit unwrapping during member
lookup without triggering an error.

Note also labels are dropped completely when performing the match,
because labels can be added or removed when pattern matching. Label
conflict are currently diagnosed as part of coercePatternToType, which
suffices so long as overloading cases based on argument labels is not
permitted.

The primary observable change from this commit is in diagnostics: rather
than diagnostics being triggered by `TypeChecker::coercePatternToType`,
diagnostics for matching failures here go through the diagnostics machinery
of the constraint solver. This is currently a regression, because
there are no custom diagnostics for pattern match failures within the
constraint system. This regression will be addressed in a subsequent
commit; for now, leave those tests failing.
2020-02-24 00:48:15 -08:00
Doug Gregor
08bfba79df [Constraint system] Add conversion constraint for typed patterns.
For typed patterns, the sub pattern type must be convertible to the type
provided to the pattern.
2020-02-24 00:48:15 -08:00
Doug Gregor
bea9d06a8b [Constraint system] Set the type on all patterns, not just top-level ones. 2020-02-24 00:48:15 -08:00
Doug Gregor
244a8232dd [Constraint system] Maintain paren type sugar for patterns. 2020-02-24 00:48:15 -08:00
Doug Gregor
7bef5405ec [Constraint system] “is” pattern match should open the type 2020-02-24 00:48:15 -08:00
Doug Gregor
8fb05af641 [Constraint solver] Give Bool patterns Bool type. 2020-02-24 00:48:14 -08:00
Doug Gregor
232f20f58d [Constraint solver] Generate constraints for “is” patterns.
Generate a checked-cast constraint for an “is” pattern, which otherwise
doesn’t change the type. This is hard to validate because checked-cast
constraints never actually fail.
2020-02-24 00:48:14 -08:00
Doug Gregor
ee90374a8f [Constraint system] Finish an unfinished comment. 2020-02-24 00:48:14 -08:00
Doug Gregor
be8b9e5ef4 [Constraint solver] Always produce optional types for '?' patterns. 2020-02-24 00:48:14 -08:00
Doug Gregor
d81161aa47 Merge pull request #29851 from DougGregor/remove-performance-hacks
[Constraint solver] Remove performance hacks for pattern type computation
2020-02-23 22:46:50 -10:00
Pavel Yaskevich
71753f3ca6 [ConstraintSystem] Rank contextually unavailable overloads lower than other choices (#29921)
Currently constraint solver is only capable of detecting universally unavailable
overloads but that's insufficient because it's still possible to pick a contextually
unavailable overload choice which could be better than e.g. generic overload, or
one with defaulted arguments, marked as disfavored etc.

Let's introduce `ConstraintSystem::isDeclUnavailable` which supports both universal
and contextual unavailability and allow constraint solver to rank all unavailable
overload choices lower than any other possible choice(s).

Resolves: rdar://problem/59056638
2020-02-19 13:13:53 -05:00
Hamish Knight
857e523deb [CS] Remove unused function
In addition to a member it set on SanitizeExpr.
Unfortunately it will take a bit more effort to
kill SanitizeExpr entirely.
2020-02-19 07:43:59 -08:00
Hamish Knight
1a9764e6d7 [CS] Remove SubExpressionDiagnostics option 2020-02-19 07:43:59 -08:00
Hamish Knight
ed1d372887 [CS] Remove DiagnosedExprs 2020-02-19 07:43:59 -08:00
Pavel Yaskevich
2dccdbfabf [ConstraintSystem] NFC: Remove workarounds related to (now deprecated) CSDiag 2020-02-18 10:13:09 -08:00
Pavel Yaskevich
81c3f62638 [CSGen] Validate presence of _MaxBuiltinFloatType before generating constraints for float literals 2020-02-17 16:09:11 -08:00
Pavel Yaskevich
3edefea8d3 [ConstraintSystem] Don't attempt to solve closures with error expressions inside
Problem(s) which caused `ErrorExpr` to be added to AST should be
diagnosed already and solver wouldn't be able to produce a viable
solution in such case anyway.
2020-02-17 16:09:11 -08:00
Pavel Yaskevich
e17df6bcdf [CSGen] Don't try to infer closure types with destructured parameters
If one of the parameters represents a destructured tuple
e.g. `{ (x: Int, (y: Int, z: Int)) in ... }` let's fail
inference and not attempt to solve the constraint system because:

a. Destructuring has already been diagnosed by the parser;
b. Body of the closure would have error expressions for
   each incorrect parameter reference and solver wouldn't
   be able to produce any viable solutions.
2020-02-17 16:09:11 -08:00
Doug Gregor
72d29cfcab [Constraint solver] Remove performance hacks for pattern type computation.
We shouldn't need these.
2020-02-13 13:28:36 -08:00
Doug Gregor
5e28c7c886 [Constraint System] Move bindVariablesInPattern into the constraint system.
This general notion of wiring up the types of variables that occur
within a pattern to the types in the produced pattern type is useful
outside of function builders, too.
2020-02-13 10:51:26 -08:00
Doug Gregor
a308a7e53c [Constraint system] Sink down debug logging.
This way we’ll see constraints whenever they’re generated, and remove some
of the expression-centric nature of the top-level solve() and solveImpl().
2020-02-11 17:33:08 -08:00
Doug Gregor
bddee5cff2 [Constraint system] Move shrinking back into typeCheckExpression()
We only want this at the top level, not during the middle of constraint
generation.
2020-02-11 17:24:38 -08:00