Commit Graph

998 Commits

Author SHA1 Message Date
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
Slava Pestov
ef05accd31 Sema: Remove even more vestigial TypeChecker usages 2019-11-19 17:40:00 -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
Doug Gregor
6273941034 [Constraint solver] Centralize solution-application logic somewhat.
In anticipation of eliminating this solution-application logic, centralize
to application of solutions back to the constraint system for the purpose
of applying the solution to update ASTs.
2019-11-15 20:33:57 -08:00
Doug Gregor
c63076e3a1 [Constraint system] Apply fixes without relying on a root expression.
When applying the set of fixes introduced by a solution, don't rely on
a walk from the "root" expression of the constraint system to
attribute the fixes to expressions. Rather, collect the fixes and emit
diagnostics in source order of the expressions that pertain to.
2019-11-15 20:33:57 -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
Doug Gregor
9b9aa2377d [Constraint solver] Lazily populate the expression depth/index map. 2019-11-14 15:29:40 -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
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
Robert Widmann
48805b1d44 Give ASTContext TypeCheckerOptions
Strip TypeChecker of all of this state.
2019-11-12 09:56:01 -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
535150c7c6 Move preCheckExpression to ConstraintSystem 2019-11-10 13:48:03 -08:00
Robert Widmann
7bad9aacc3 Drop the TypeChecker out of ConstraintSystem 2019-11-10 13:26:47 -08:00
Doug Gregor
51cb333363 [Constraint system] Fall back to baseCS when looking for an expression's parent 2019-11-08 22:47:27 -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
Robert Widmann
41ab235797 [CS] Remove some TypeChecker uses 2019-11-07 12:41:37 -08:00
Doug Gregor
1cd5152f86 Move ConstraintSystem::setExprTypes() over to Solution
It belongs on Solutionn, which should contain all of the information
needed to perform the operation. Simplify the implementation slightly
while doing this, eliminating some dead code.
2019-11-06 08:50:53 -08:00
Robert Widmann
53f2974e27 [NFC] Remove unnecessary TypeCheckers from sequence folding 2019-11-05 20:30:40 -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
e97314cb5c [ConstraintSystem] Never choose the potential binding for a hole
in the constraint system over a different binding or disjunction.

In other words, we will only choose to bind a hole to `Any` if there
are no other bindings and no disjunctions.
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
Pavel Yaskevich
2dddfcb190 Merge pull request #28013 from xedin/trailing-closures-not-so-trailing
[Diagnostics] Port invalid trailing closure use diagnostics
2019-11-01 15:38:20 -07:00
Pavel Yaskevich
6bddac33d5 [ConstraintSystem] Allow to check presence of fix by kind and locator 2019-10-31 20:54:00 -07: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
Brent Royal-Gordon
ffbe53e290 [NFC] Eliminate const_casts in constraint system dumpers 2019-10-31 18:41:11 -07:00
Brent Royal-Gordon
99faa033fc [NFC] Standardize dump() methods in frontend
By convention, most structs and classes in the Swift compiler include a `dump()` method which prints debugging information. This method is meant to be called only from the debugger, but this means they’re often unused and may be eliminated from optimized binaries. On the other hand, some parts of the compiler call `dump()` methods directly despite them being intended as a pure debugging aid. clang supports attributes which can be used to avoid these problems, but they’re used very inconsistently across the compiler.

This commit adds `SWIFT_DEBUG_DUMP` and `SWIFT_DEBUG_DUMPER(<name>(<params>))` macros to declare `dump()` methods with the appropriate set of attributes and adopts this macro throughout the frontend. It does not pervasively adopt this macro in SILGen, SILOptimizer, or IRGen; these components use `dump()` methods in a different way where they’re frequently called from debugging code. Nor does it adopt it in runtime components like swiftRuntime and swiftReflection, because I’m a bit worried about size.

Despite the large number of files and lines affected, this change is NFC.
2019-10-31 18:37:42 -07:00
Robert Widmann
929332e12a Make isAvailabilitySafeForConformance a utility 2019-10-30 12:55:42 -07:00
Robert Widmann
972e755e9b Give ConstraintSystem's outlet to the ASTContext
Make it less tempting to ask for the type checker embedded into
ConstraintSystem by using the accessor to the ASTContext.
2019-10-30 12:55:42 -07:00
Hamish Knight
a5e375a770 Cache resolved concrete decl refs in ExprRewriter
This ensures we don't have to compute the substitutions
multiple times when, for example, rewriting an
apply of generic function.
2019-10-22 12:36:59 -07:00
Hamish Knight
9d80a82939 Make resolveLocatorToDecl simpler and more robust
Rather than attempting to pull out a concrete decl
ref from the rewritten function expr, retrieve the
callee from the solution using a callee locator
computed before the apply is rewritten, and then
pass this callee down through `finishApply` and
`coerceCallArguments`.

Resolves SR-11648.
2019-10-22 11:54:04 -07:00
Hamish Knight
e4e5b5e94a Allow getCalleeLocator to not look through applies
Some clients may only want a callee locator for an
immediate decl reference such as `x.foo`, but not
for `x.foo()`.
2019-10-22 11:54:04 -07:00
Hamish Knight
e3df69a2b5 Add Solution::resolveConcreteDeclRef
This is a convenience member for computing the
contextual substitutions for a decl reference at
a given locator.
2019-10-22 11:54:03 -07:00
Hamish Knight
37c42f6203 [Sema] NFC: Remove an unnecessary parameter 2019-10-21 13:44:15 -07:00
Pavel Yaskevich
8d3409bddf [ConstraintSystem] Allow argument matcher to continue in presence of missing/extra arguments
This makes it possible to find all of the problems related to a given
set of arguments and fix/score each overload candidate correctly.
2019-10-16 10:19:26 -07:00
Pavel Yaskevich
1b302b98d3 [ConstraintSystem] Record a fix for extraneous arguments after matcher is done 2019-10-16 10:19:26 -07:00
Pavel Yaskevich
e33a3402cb [ConstraintSystem] Make contextual function type available for matchCallArguments
Helps diagnostics to avoid digging this type out from locator.
2019-10-16 10:19:25 -07:00
Pavel Yaskevich
22813d96cf [ConstraintSystem] Extend MatchCallArgumentListener::extraArguments to return all extraneous arguments 2019-10-16 10:19:25 -07:00
Hamish Knight
fc020bb3f4 [CS] Add ConstraintSystem::addFixConstraint
This lets us add a constraint to the system with an associated fix.
Unlike `addUnsolvedConstraint`, this will attempt to immediately
simplify the constraint, producing an unsolved constraint if necessary.
2019-10-15 10:12:48 -07:00