Commit Graph

1945 Commits

Author SHA1 Message Date
Pavel Yaskevich
2fa4fbb7a9 Merge pull request #30646 from xedin/rdar-60225883
[CSApply] Support dynamic member lookup as component of key path dyna…
2020-03-26 09:33:12 -07:00
Pavel Yaskevich
95be170e46 [CSApply] Support dynamic member lookup as component of key path dynamic member lookup
Previously solution application only supported references to
key path dynamic member lookup as components but it should support both kinds.

Resolves: rdar://problem/60225883
Resolves: [SR-12313](https://bugs.swift.org/browse/SR-12313)
2020-03-25 15:21:52 -07:00
Pavel Yaskevich
4b3d075fb7 [ConstraintSystem] Produce fallback diagnostic on mismatch between fixes/holes
If score indicates that a solution should have at least one fix
but it doesn't let's attempt to produce a fallback diagnostic inline.
2020-03-24 16:51:44 -07:00
Pavel Yaskevich
da2023c9a0 [ConstraintSystem] Score solutions based on number of holes
Introduce `SK_Hole` which is used to count a number of "holes" in
a given solution. It is used to distinguish solutions with fewer holes.

Also it makes it possible to check whether a solution has holes but
no fixes, which is an issue and such solution shouldn't be applied
to AST.
2020-03-24 16:51:44 -07:00
Pavel Yaskevich
786bad422a [ConstraintSystem] Avoid applying invalid solution with fixes
If solution score indicates that there should be a fix but
none where recorded fail solution application and produce
a fallback diagnostic to pin-point a problem.

Resolves: rdar://problem/60663007
2020-03-24 16:51:44 -07:00
Hamish Knight
c74a7512f7 [CS] NFC: Remove OverloadChoiceKind::BaseType
This doesn't appear to be used any more.
2020-03-22 22:51:58 -07:00
Doug Gregor
06196e09c0 Merge pull request #30496 from DougGregor/contextual-pattern-binding-decl
[Constraint system] Use the PatternBindingDecl context when possible.
2020-03-19 13:21:50 -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
Slava Pestov
f6187e520a Sema: Don't devirtualize partially applied operator references 2020-03-18 19:23:18 -04:00
Slava Pestov
c543838854 Sema: Rewrite partial applications into closures
When a method is called with fewer than two parameter lists,
transform it into a fully-applied call by wrapping it in a
closure.

Eg,

Foo.bar => { self in { args... self.bar(args...) } }
foo.bar => { self in { args... self.bar(args...) } }(self)

super.bar => { args... in super.bar(args...) }

With this change, SILGen only ever sees fully-applied calls,
which will allow ripping out some code.

This new way of doing curry thunks fixes a long-standing bug
where unbound references to protocol methods did not work.

This is because such a reference must open the existential
*inside* the closure, after 'self' has been applied, whereas
the old SILGen implementation of curry thunks really wanted
the type of the method reference to match the opened type of
the method.

A follow-up cleanup will remove the SILGen curry thunk
implementation.

Fixes rdar://21289579 and https://bugs.swift.org/browse/SR-75.
2020-03-18 09:29:22 -04:00
Pavel Yaskevich
2dd74706c9 Merge pull request #30411 from xedin/diags-to-use-solution-instead-of-cs
[Diagnostics] Switch `FailureDiagnostic` to use a solution
2020-03-13 20:20:58 -07:00
Pavel Yaskevich
3ab8710329 [Diagnostics] Cleanup use of constraint system by ConstraintFix/FailureDiagnostic 2020-03-13 15:02:10 -07:00
Pavel Yaskevich
1fc0ea6b0e [CSFix] Allow diagnose to accept a solution to diagnose
Instead of always applying solution back to constraint system
before diagnostics, let's pass solution directly to `ConstaintFix::diagnose`
method to be used by `FailureDiagnostic` which paves a way for
stateless diagnostics.
2020-03-12 11:41:36 -07:00
Pavel Yaskevich
7c1df6ad51 [ConstraintSystem] Remove getType(Expr*) accessor from Solution
It's obsolete and has been superseded by `getType(TypedNode)`.
2020-03-12 10:28:18 -07:00
Hamish Knight
b62c9b6b01 [CS] Use getParameterType for KeyPath as function
Previously we were using `getPlainType` to match
the parameter type against the key path's base
type. This gave us the external parameter type,
which would be the element type for a variadic
parameter.  However the code we generate expects
the internal parameter type, which is provided by
`getParameterType`.

Resolves rdar://problem/59445486.
2020-03-11 17:21:28 -07:00
Robert Widmann
0a28307c41 [CS] Use The Full Opened Type When Forming Subscripts
The "opened type" of a subscript reference has all references to Self
immediately substituted out, which destroys the link between Self and
the opened existential type we form for the "fully opened type". This
means, in general, we cannot use this type when rewriting subscript
applies, or we'll miss closing opened existentials.

Use the "fully opened type" everywhere except the AnyObject subscript
path. Then, add an assertion that AnyObject subscripts never involve
opened archetypes that we would have to close.

Resolves SR-11748, rdar://57092093
2020-03-04 17:23:15 -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
Slava Pestov
9452c60b3b Sema: Remove CSApply's getNaturalArgumentCount() in favor of getNumCurryLevels() 2020-02-26 23:10:07 -05:00
Slava Pestov
90ee606de7 Sema: Refactor CSApply in preparation for curry thunks 2020-02-26 23:10:07 -05:00
Doug Gregor
031f5a4888 Merge pull request #30065 from DougGregor/function-builders-if-case-fixes
[Constraint system] Cleanups for function builders support for if let/if case let
2020-02-26 10:38:15 -08:00
Doug Gregor
c58e0aa169 [Constraint system] Make sure we set expression types on StmtCondition. 2020-02-25 22:43:21 -08:00
Doug Gregor
141f3e7f07 [Constraint system] Expand SolutionApplicationTarget to StmtConditions.
Handle StmtCondition as part of SolutionApplicationTarget, so we can
generate constraints from it and rewrite directly as part of a solution,
rather than open-coding the operation in the function builder transform.
2020-02-25 13:47:26 -08:00
Joe Groff
cf0e09d9c5 Preserve conformances for upper bound constraints when lowering SILFunctionTypes 2020-02-24 12:14:21 -08:00
Joe Groff
9c9bf567f7 SIL: Preserve upper bound constraints for substitutions into nominal types.
When extracting substitutions during type lowering, we can't discard protocol constraints
in positions where the substitution is for a nominal type's generic arguments, since associated
types on that protocol may affect the nominal type's ABI.
2020-02-24 12:14:21 -08:00
Pavel Yaskevich
8af4f2ddb3 Merge pull request #29493 from LucianoPAlmeida/SR-11421-checked-cast-diag
[SR-11421][Diagnostics] Tailored diagnostic for checked downcast with literals
2020-02-19 17:29:30 -08:00
Hamish Knight
1a9764e6d7 [CS] Remove SubExpressionDiagnostics option 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
8722530943 [CSDiag] NFC: Move diagnoseDeprecatedConditionalConformanceOuterAccess to CSApply 2020-02-17 16:09:11 -08:00
Pavel Yaskevich
48f24b02d6 Merge pull request #29866 from xedin/rdar-57356196
[CSApply] Always use `String` type for ObjC interop key path
2020-02-17 10:50:31 -08:00
Pavel Yaskevich
ae79b0d0bd [CSApply] Always use String type for ObjC interop key path
If it's possible to build an Objective-C key path for key path
expression make sure that its implicitly generated string literal
expression has a `String` type.

Resolves: rdar://problem/57356196
2020-02-15 00:04:09 -08:00
Robert Widmann
a9e871a0b1 [Sema] Warn About Tuple Shuffles
Emit a warning that tuple shuffling is deprecated across the board. In
the future, we should try to unshuffle these expressions where we can,
but that's a diagnostic improvement for another day.

See also https://forums.swift.org/t/deprecating-tuple-shuffles-round-2/16884/30
2020-02-13 17:29:03 -08:00
Doug Gregor
d4cd5e0ebc Merge pull request #29801 from DougGregor/constraint-solver-rewrite-target
[Constraint system] Factor out application to a SolutionApplicationTarget
2020-02-12 20:24:41 -08:00
Luciano Almeida
968a37d221 [Diagnostics] Tailored diagnostic message for conditional downcast involving literals that can be statically coerced 2020-02-13 01:04:15 -03:00
Doug Gregor
7f9029071d [Constraint system] Adopt rewriteTarget for function builder transform.
When applying a function builder to a closure to produce the final,
type-checked closure, use the new rewriteTarget() so it’s performed on
a per-target basis. Use this to eliminate some duplicating in the handling
of return types.
2020-02-12 17:51:47 -08:00
Doug Gregor
efd357e7c7 [Constraint system] Factor out application to a SolutionApplicationTarget.
Pull out the core operation of rewriting a given SolutionApplicationTarget
into into a method on the ExprWalker that does the overall rewrite, so it
can be called multiple times within application.
2020-02-12 17:51:47 -08:00
Doug Gregor
8b5a639769 Merge pull request #29778 from DougGregor/more-sinking
[Constraint system] Sink optional “some” pattern handling into constrain generation
2020-02-11 20:13:38 -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
151fc79264 Merge pull request #29770 from DougGregor/builder-transform-node-types
[Constraint solver] Fix handling of node types for function builder application
2020-02-11 17:21:16 -08:00
marcrasi
565b0e17fd change "new" to "malloc" because it gets "free"d later (#29767) 2020-02-11 16:03:32 -08:00
Doug Gregor
3508dfb0ea [Constraint system] Use hash table lookup appropriately.
It’s pointlessly inefficient to do an O(n) scan through a hash table to match
keys!
2020-02-11 15:14:44 -08:00
Doug Gregor
f5b9517552 [Constraint system] Simplify and improve handling of node tyoes.
Rather than having separate dense maps for the type mappings of each
node type (expression, type location, variable declaration, pattern) that
a TypedNode can be, have a single such map. Sometimes we end up
setting a particular node's type more than once, so cope with that
by restoring the prior type.
2020-02-11 15:14:44 -08:00
Doug Gregor
a1932f10e5 [Constraint solver] Sink remaining logic from typeCheckBinding.
Move the remaining logic of typeCheckBinding, which consists of applying
the solution to the pattern, down into the normal solution application
path. typeCheckBinding() is now a thin shell over the normal
typeCheckExpression() convenience function.
2020-02-10 22:01:37 -08:00
Doug Gregor
364770e658 [Constraint system] Remove typeCheckBinding’s ExprTypeCheckListener.
Sink the solution-application code from typeCheckBinding’s
ExprTypeCheckListener subclass into normal solution application, allowing
us to eliminate this subclass entirely. Down to one…
2020-02-10 22:01:37 -08:00
Doug Gregor
c1c7112110 Remove some unused code and fix a test 2020-02-10 22:01:37 -08:00
Doug Gregor
4d1de7fd3d [Constraint solver] Sink down initialization pattern constraint generation.
Sink the constraint generation for initialization patterns, including all
of the logic for property wrappers, from the high-level entry point
`typeCheckBinding` down into the lower-level constraint generation for
solution application targets.
2020-02-10 22:01:37 -08:00