Commit Graph

733 Commits

Author SHA1 Message Date
Varun Gandhi
8021795672 [AST] Setup AST and SIL to accomodate Clang function types.
We still don't store compute or store the type anywhere; we will do so in
later commits.
2019-11-22 12:42:08 -08:00
Pavel Yaskevich
f7ee402d2f Merge pull request #28400 from xedin/rdar-57201781
[ConstraintSystem] Introduce notion of constraint system phase
2019-11-21 13:17:34 -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
Robert Widmann
827d319cf6 Merge pull request #28386 from CodaFi/more-factors-at-play
[NFC] Refactor Overload Resolution a Bit
2019-11-20 15:56:04 -08:00
Robert Widmann
c11ffb5e19 Factor out the part of resolveOverload that fiddles with constraint system 2019-11-20 11:36:59 -08:00
Robert Widmann
d772338398 Refactor resolveOverloadForDeclWithSpecialTypeCheckingSemantics
Have it function more like getTypeOfMemberReference and clean up its caller a bit
2019-11-20 11:36:35 -08:00
Slava Pestov
636fc0f17e Sema: Compute captures when contextualizing closures 2019-11-19 17:18:07 -05:00
Slava Pestov
0bb323b75c Sema: Move buildAutoClosureExpr() from TypeChecker to ConstraintSystem 2019-11-19 14:02:21 -05: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
Doug Gregor
78e360a67d [Constraint solver] Drop unused Expr* from diagnoseAmbiguity().
We've made this unnecessary.
2019-11-15 21:09:27 -08:00
Slava Pestov
9826aaa9ed Merge pull request #28275 from slavapestov/check-where-clause-non-generic-type
Check generic requirements of parent context when realizing non-generic types
2019-11-15 08:46:04 -05: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
abf41e73a8 [Constraint system] Look for parent/depth info in base constraint system.
Look first in the base constraint system for this information, so it
only gets built once in the normal case.
2019-11-14 20:35:07 -08:00
Doug Gregor
24b47b5673 [Constraint solver] Sink Expr::getPreorderIndexMap() into its client. 2019-11-14 20:33:00 -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
Doug Gregor
9b9aa2377d [Constraint solver] Lazily populate the expression depth/index map. 2019-11-14 15:29:40 -08:00
Slava Pestov
54155fe290 Sema: Check generic requirements of parent context when realizing non-generic types
When realizing a type like Foo<A>.Bar, we have to account for the
possibility that Bar is defined in a constrained extension of Foo,
and has generic requirements beyond those that Foo itself places
on 'A'.

Previously we only handled this for types referenced from the
constraint system as part of openUnboundGenericType(), so we were
allowing invalid types through in type context.

Add the right checking to applyGenericArguments() to close the
hole. Note that the old code path still exists in the constraint
solver; it is used for member accesses on metatype bases only.

Fixes <https://bugs.swift.org/browse/SR-10466>.
2019-11-14 18:26:43 -05:00
Doug Gregor
01f203a54d [Constraint system] Sink Expr::getDepthMap() into its one client.
NFC. It'll be easier to refactor this when it's not an API on Expr.
2019-11-14 15:02:58 -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
Doug Gregor
670ff7def1 [Constrant system] Drop expression from diagnoseAmbiguityWithFixes.
It's unused now.
2019-11-13 17:23:27 -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
Robert Widmann
d890b8ad41 Remove some save-and-restores
An awful pattern we use throughout the compiler is to save and restore global flags just for little things.  In this case, it was just to turn on some extra options in AST printing for type variables. The kicker is that the ASTDumper doesn't even respect this flag. Add this as a PrintOption and remove the offending save-and-restores.

This doesn't quite get them all: we appear to have productized this pattern in the REPL.
2019-11-13 07:37:12 -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
Doug Gregor
23edd22824 Merge pull request #28221 from DougGregor/reduce-depth-maps
Reduce usage of expression depth maps
2019-11-12 20:43:14 -08:00
swift-ci
39fb55b616 Merge pull request #28156 from marcrasi/diff-fn-ty-ast-bits 2019-11-12 17:28:47 -08:00
Doug Gregor
99555dc951 [Constraint system] Add ConstraintSystem::getExprDepth() and use it for cleanup.
Rather than passing around or create depth maps at a few places in the
constraint solver, introduce getExprDepth() and use it consistently.
2019-11-12 15:42:17 -08:00
Marc Rasi
6413f4341a [AutoDiff upstream] AST bits for @differentiable fn ty 2019-11-12 15:19:03 -08:00
Hamish Knight
cd3ada5abb getInterfaceType() always returns a type (#28210)
getInterfaceType() always returns a type
2019-11-12 13:24:05 -08:00
Robert Widmann
48805b1d44 Give ASTContext TypeCheckerOptions
Strip TypeChecker of all of this state.
2019-11-12 09:56:01 -08:00
Hamish Knight
ed77b86c24 getInterfaceType() always returns a type 2019-11-12 07:50:29 -08:00
Robert Widmann
efb6117bd8 [NFC] Remove Diagnostic State From TypeChecker
Push this map into ConstraintSystem and have the search and retrieval chain up the linked list of base constraint systems.
2019-11-10 22:05:32 -08:00
Robert Widmann
7bad9aacc3 Drop the TypeChecker out of ConstraintSystem 2019-11-10 13:26:47 -08:00
Doug Gregor
bc926f7eb7 [Constraint system] Drop the root expression from FailureDiagnostic.
We're not using it for anything, now.
2019-11-08 22:38:49 -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
Robert Widmann
e6dbfa393a Move Utilities back to TypeChecker 2019-11-06 15:20:46 -08:00
Robert Widmann
3cf7b5451e Remove references to TypeChecker in the constraint system 2019-11-06 15:08:59 -08:00
Robert Widmann
a840af35cd Move getSelfForInitDelegationInConstructor to ASTContext 2019-11-06 15:08:59 -08:00
Pavel Yaskevich
6d02fb7815 Merge pull request #28057 from xedin/assign-diags
[Diagnostics] Port the rest of assignment diagnostics to the new framework
2019-11-06 00:11:08 -08:00
Robert Widmann
e804d6ed9a Make TypeChecker::getDefaultType a utility 2019-11-05 20:31:15 -08:00
Robert Widmann
fba3c1d0cb Make building and manipulating checked DeclRefs a utility 2019-11-05 20:30:40 -08:00
Robert Widmann
392df03466 [NFC] Drop unnecessary TypeCheckers from Sema 2019-11-05 20:30:40 -08:00
Pavel Yaskevich
30440d8235 [Diagnostics] Properly diagnose assignment mismatch in ambiguity cases 2019-11-05 12:38:13 -08:00
Holly Borla
33b9d4c446 [Diagnostics] Change FailureDiagnostic::resolveType to replace
holes with generic parameters directly when possible.
2019-11-05 09:17:53 -08:00
Holly Borla
4fd1377c81 [ConstraintSystem] With the new approach for holes, hole propagation happens
automatically.

This commit also renames `ConstraintSystem::recordHole/isHole` to
`recordPotentialHole` and `isPotentialHole` to make it clear that
we don't know for sure whether a type variable is a hole until it's
bound to unresolved.
2019-11-05 09:15:13 -08:00
Holly Borla
e63f259f4f [ConstraintSystem] Bind holes to UnresolvedType instead of Any. 2019-11-05 09:15:13 -08:00
Holly Borla
9093dfcd20 [ConstraintSystem] Move hole propagation to addTypeVariableConstraintsToWorkList
where we are already gathering constraints.
2019-11-05 09:15:13 -08:00
Holly Borla
3bc2269f4f [ConstraintSystem] Allow generic parameters and holes to default to
`Any` in `getPotentialBindings` rather than `ComponentStep::take`.
2019-11-05 09:15:13 -08:00
Holly Borla
561e527848 [ConstraintSystem] Extend the ExplicitlySpecifyGenericArguments fix to cover
all cases of missing generic parameters.

In `ComponentStep::take` when there are no bindings or disjunctions, use hole
propagation to default remaining free type variables that aren't for generic
parameters and continue solving. Rather than using a defaultable constraint for
holes, assign a fixed type directly when we have no bindings to try.
2019-11-05 09:15:13 -08:00
Hamish Knight
7077a68b83 [Sema] Diagnose unsound pointer conversions
Diagnose ephemeral conversions that are passed to @_nonEphemeral
parameters. Currently, this defaults to a warning with a frontend flag
to upgrade to an error. Hopefully this will become an error by default
in a future language version.
2019-11-03 08:42:25 -08:00
Brent Royal-Gordon
17169fc1fe Merge pull request #27950 from brentdax/dumpster-fire
[NFC] Standardize dump() methods in frontend
2019-10-31 20:36:26 -07:00