Commit Graph

731 Commits

Author SHA1 Message Date
Doug Gregor
d752f414d3 [Constraint solver] Rework solveImpl(Expr*) to return SolutionResult.
SolutionResult better captures what can happen when solving a constraint
system for the given expression occurs than the ad hoc SolutionKind return
& small vector of Solution results. Also, try to make this logic less
convoluted.
2020-01-26 12:05:43 -08:00
Doug Gregor
5063cb5b79 [Constraint solver] Factor out adding a contextual conversion constraint. 2020-01-26 12:05:43 -08:00
Doug Gregor
f7744bd8b2 [Constraint solver] Make DeclContext explicit. NFC 2020-01-26 12:05:43 -08:00
swift_jenkins
1c3fcc6301 Merge remote-tracking branch 'origin/master' into master-next 2020-01-24 12:58:09 -08:00
swift-ci
01ceb5301e Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-24 12:43:37 -08:00
Doug Gregor
27cd8d2afb [Constraint system] Save contextual types into each Solution
We’ll want to pull these back out for diagnostic purposes.
2020-01-24 10:17:59 -08:00
Mike Ash
1c2034c8df Merge branch 'master' into master-next 2020-01-24 12:45:15 -05:00
Mike Ash
cd2b54f74e Merge branch 'master' into master-rebranch 2020-01-24 11:30:32 -05:00
Doug Gregor
83cb35139a [Constraint solver] Allow contextual types for multiple expressions.
Generalize the representation of contextual types so we can store
contextual types for more than one expression. Allow these to be
added/rolled back in solver scopes. Nothing uses this functionality
yet.
2020-01-23 13:56:36 -08:00
Doug Gregor
133439dcbb [Constraint solver] Request contextual type information per expression.
When requesting information about the contextual type of a constraint
system, do so using a given expression rather than treating it like
the global state that it is.
2020-01-23 11:46:17 -08:00
swift-ci
a48309f8b1 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-21 12:03:41 -08:00
swift_jenkins
3f59fa22c0 Merge remote-tracking branch 'origin/master' into master-next 2020-01-21 11:57:23 -08:00
Doug Gregor
8283a67648 Revert "Revert "Reimplement function builders as statement transformations."" 2020-01-21 10:07:20 -08:00
swift-ci
677787741d Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-21 09:23:10 -08:00
swift_jenkins
9e553c0215 Merge remote-tracking branch 'origin/master' into master-next 2020-01-21 09:17:31 -08:00
Doug Gregor
86c13d3c74 Revert "Reimplement function builders as statement transformations." 2020-01-17 15:52:49 -08:00
swift_jenkins
06de3e6377 Merge remote-tracking branch 'origin/master' into master-next 2020-01-17 10:57:41 -08:00
swift-ci
3a0eb0760f Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-17 10:44:12 -08:00
Doug Gregor
3a51d5b9b2 [WIP] Reimplement function builders as statement transformations. 2020-01-16 13:18:33 -08:00
Erik Eckstein
1b312a85bd Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-16 10:39:20 +01:00
swift_jenkins
9bcad62da7 Merge remote-tracking branch 'origin/master' into master-next 2020-01-16 00:37:48 -08:00
Doug Gregor
3651defcfa [Solver] When LLVM stats are disabled, don't adjust their values.
Fixes rdar://58549337
2020-01-14 22:12:43 -08:00
Pavel Yaskevich
66db166922 [ConstraintSystem] Introduce new DefaultClosureType constraint
This constraint connects type variable representing a closure
expression to its inferred type and behaves just like regular
`Defaultable` constraint expect for type inference where it's
used only if there are no contextual bindings available.
2020-01-14 00:09:32 -08:00
Pavel Yaskevich
92556e8f0d [ConstraintSystem] Introduce a mapping from closures to their inferred types
In preparation to change type-checking behavior of closures
we need to introduce a special mapping from closure expressions
to their inferred types (based on parameters/result and body).
2020-01-14 00:09:32 -08:00
Shoaib Meenai
f2310cff37 [Statistic] Adjust for LLVM r374490
Use appropriate member functions instead of accessing Value directly.
2020-01-09 23:07:20 -08:00
Arnold Schwaighofer
43c24be5cd Merge remote-tracking branch 'upstream/master' into master-next 2020-01-08 06:41:34 -08:00
Doug Gregor
fffe1291fa [Constraint system] Generalize record of transformed function builders. 2020-01-06 11:39:11 -08:00
Doug Gregor
dfda7aca7f [Constraint solver] Generalize "target" of solution application.
Chip away at the expression-centric nature of the constraint system by
generalizing the "target" of solution application from a single
expression to a a "SolutionApplicationTarget", which can be an
expression or a function body. The latter will be used for applying
function builders to an entire function body.
2020-01-06 11:31:06 -08:00
swift_jenkins
add386ded3 Merge remote-tracking branch 'origin/master' into master-next 2020-01-02 15:59:15 -08:00
Doug Gregor
bbcaf8c669 [Type checker] Introduce value witness constraints.
Introduce a new kind of constraint, the "value witness" constraint,
which captures a reference to a witness for a specific protocol
conformance. It otherwise acts like a more restricted form of a "value
member" constraint, where the specific member is known (as a
ValueDecl*) in advance.

The constraint is effectively dependent on the protocol
conformance itself; if that conformance fails, mark the type variables
in the resolved member type as "holes", so that the conformance
failure does not cascade.

Note that the resolved overload for this constraint always refers to
the requirement, rather than the witness, so we will end up recording
witness-method references in the AST rather than concrete references,
and leave it up to the optimizers to perform devirtualization. This is
demonstrated by the SIL changes needed in tests, and is part of the
wider resilience issue with conformances described by
rdar://problem/22708391.
2020-01-02 12:06:23 -08:00
Joe Groff
fb34044408 Merge remote-tracking branch 'origin/master' into master-next 2019-12-10 12:46:41 -08:00
Hamish Knight
a97328dcbf [CS] Use a MapVector to cache resolved overloads
Rather than maintaining a linked list of overload
choices, which must be linearly searched each time
we need to lookup an overload at a given callee
locator, use a MapVector which can be rolled back
at the end of a scope.

Remove ResolvedOverloadSetListItem in favor of
using SelectedOverload, which avoids the need to
convert between them when moving from
ConstraintSystem to Solution.
2019-12-05 14:47:52 -08:00
Pavel Yaskevich
addc2b06ab [ConstraintSystem] Introduce notion of constraint system phase
Some constraint transformations require knowledge about what state
constraint system is currently in e.g. `constraint generation`,
`solving` or `diagnostics` to make a decision whether simplication
is possible. Notable example is `keypath dynamic member lookup`
which requires a presence of `applicable fn` constraint to retrieve
some contextual information.

Currently presence or absence of solver state is used to determine
whether constraint system is in `constraint generation` or `solving`
phase, but it's incorrect in case of `diagnoseFailureForExpr` which
tries to simplify leftover "active" constraints before it can attempt
type-check based diagnostics.

To make this more robust let's introduce (maybe temporarily until
type-check based diagnostics are completely obsoleted) a proper
notion of "phase" to constraint system so it is always clear what
transitions are allowed and what state constraint system is
currently in.

Resolves: rdar://problem/57201781
2019-11-20 18:34:51 -08:00
swift_jenkins
9811735f9e Merge remote-tracking branch 'origin/master' into master-next 2019-11-18 19:00:01 -08:00
Doug Gregor
e06fb4bed3 [Constraint system] Capture "salvage" result in a self-contained data structure
Rework the interface to ConstraintSystem::salvage() to (a) not require
an existing set of solutions, which it overwrites anyway, (b) not
depend on having a single expression as input, and (c) be clear with
its client about whether the operation has already emitted a
diagnostic vs. the client being expected to produce a diagnostic.
2019-11-18 16:34:01 -08:00
swift_jenkins
b9f998ffa4 Merge remote-tracking branch 'origin/master' into master-next 2019-11-15 15:56:48 -08:00
Doug Gregor
0b6ef0d4d1 Merge pull request #28276 from DougGregor/constraint-solver-expr-ctor
[Constraint solver] Remove expression from the constructor.
2019-11-14 22:48:07 -08:00
Doug Gregor
2d915f60ab [Constraint solver] Remove expression from the constructor.
Rather than setting up the constraint solver with a single expression
(that gets recorded for parents/depths), record each expression that
goes through constraint generation.
2019-11-14 15:41:38 -08:00
Holly Borla
5bb50068ac Merge pull request #28243 from hborla/missing-generic-args-refactoring
[ConstraintSystem] Missing generic args/hole refactoring
2019-11-14 13:48:40 -08:00
Holly Borla
c0312b9c0e [ConstraintSystem] Record holes in the constraint system using a new flag in
`TypeVariableOptions` rather than using a separate data structure in the
constraint system.
2019-11-13 15:46:36 -08:00
swift-ci
436cbabb3d Merge remote-tracking branch 'origin/master' into master-next 2019-11-13 11:50:27 -08:00
Robert Widmann
417c82f42d Strip TypeChecker of its ASTContext
If you can get a TypeChecker at this point, you had one all along.

Its constructor and destructor are now defaultable.
2019-11-13 09:44:02 -08:00
swift-ci
5fc1d17bf9 Merge remote-tracking branch 'origin/master' into master-next 2019-11-13 09:10:56 -08:00
Robert Widmann
f4d333d066 Sink a bunch of semantic options into TypeCheckerOptions
Sink
- DebugConstraintSolver
- DebugConstraintSolverAttempt
- DebugConstraintSolverOnLines
- DebugGenericSignatures
- DebugForbidTypecheckPrefix
- SolverMemoryThreshold
- SolverBindingThreshold
- SolverShrinkUnsolvedThreshold
- SolverDisableShrink
- EnableOperatorDesignatedTypes
- DisableConstraintSolverPerformanceHacks
- SolverEnableOperatorDesignatedTypes
2019-11-12 22:39:49 -08:00
swift-ci
8ad621275f Merge remote-tracking branch 'origin/master' into master-next 2019-11-10 17:10:41 -08:00
Robert Widmann
7bad9aacc3 Drop the TypeChecker out of ConstraintSystem 2019-11-10 13:26:47 -08:00
swift-ci
6adca0b0ab Merge remote-tracking branch 'origin/master' into master-next 2019-11-09 08:09:11 -08:00
Doug Gregor
7ff75da27c [Constraint system] Drop unnecessary Expr* parameter from core solve.
This parameter was unused anyway.
2019-11-08 21:26:04 -08:00
Doug Gregor
9204d7cee4 [Constraint systme] Rename solve() -> solveImpl().
solve() is a bit too overloaded, so rename the version that does the
core "evaluate all of the steps to produce a set of solutions"
functionality to solveImpl().
2019-11-08 21:26:04 -08:00
swift-ci
db522a95db Merge remote-tracking branch 'origin/master' into master-next 2019-11-07 18:09:06 -08:00