Commit Graph

1583 Commits

Author SHA1 Message Date
Varun Gandhi
99b72992ba [NFC] Add some useful crash information in CSApply. 2019-11-22 12:42:38 -08:00
Varun Gandhi
196f358dec [AST] Add ClangTypeConverter, computing C types for FunctionTypes.
Note: The change in ASTBuilder::createFunctionType is functionally minor,
but we need the FunctionType::Params computed _before_ the ExtInfo, so we
need to shuffle a bunch of code around.
2019-11-22 12:42:36 -08:00
Hamish Knight
25cfa13a95 [CS] Remove isDynamic param from buildMemberRef
Callers were either just passing
choice.getKind() == OverloadChoiceKind::DeclViaDynamic
or passing false. Inline the check into the function
and assert for callers that don't expect a decl
from dynamic lookup.
2019-11-21 16:21:57 -08:00
Doug Gregor
7f50537933 Revert "[Constraint application] Stop optimizing casts in the AST." 2019-11-21 09:19:04 -08:00
Doug Gregor
8d0612da97 [Constraint application] Stop optimizing casts in the AST.
Constraint application was rewriting conditional casts (as?) and
forced casts (as!) into coercions (as) at the AST level when it
determined that there was a coercion. Stop doing that: it's the
optimizer's job to remove such casts.
2019-11-20 16:36:29 -08:00
Doug Gregor
d379de8830 [Constraint solver] Switch coercion to be solution-based.
Rather than spinning up a new constraint system when performing an "as"
coercion, perform the coercion with the known solution, because we
already did all of the work to figure out how to perform the coercion.
2019-11-20 16:36:29 -08:00
Hamish Knight
7e788b8ab9 [AST] Remove CallerDefaultArgumentExpr
Now that we use DefaultArgumentExpr for both kinds
of default arguments, this is no longer needed.
2019-11-20 15:07:33 -08:00
Hamish Knight
c667d2b361 Use DefaultArgumentExpr for caller-side defaults
This commit changes how we represent caller-side
default arguments within the AST. Instead of
directly inserting them into the call-site, use
a DefaultArgumentExpr to refer to them indirectly.

The main goal of this change is to make it such
that the expression type-checker no longer cares
about the difference between caller-side and
callee-side default arguments. In particular, it
no longer cares about whether a caller-side
default argument is well-formed when type-checking
an apply. This is important because any
conversions introduced by the default argument
shouldn't affect the score of the resulting
solution.

Instead, caller-side defaults are now lazily
type-checked when we want to emit them in SILGen.
This is done through introducing a request, and
adjusting the logic in SILGen to be more lenient
with ErrorExprs. Caller-side defaults in primary
files are still also currently checked as a part
of the declaration by `checkDefaultArguments`.

Resolves SR-11085.
Resolves rdar://problem/56144412.
2019-11-20 15:07:32 -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
Slava Pestov
7c145fb7be Merge pull request #27951 from zoecarver/key-path-default-arg
Fix KeyPath with default arg
2019-11-19 00:04:51 -05:00
Doug Gregor
6096b43957 Merge pull request #28345 from DougGregor/cs-fewer-root-exprs
[Constraint solver] Reduce reliance on the "root" expression further
2019-11-18 18:50:59 -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
Doug Gregor
85a5df09a2 Merge pull request #28292 from DougGregor/apply-fixes-without-root
[Constraint system] Apply fixes without relying on a root expression.
2019-11-18 15:06:19 -08:00
Bruno Rocha
4d85c8bcd1 Index optional is pattern 2019-11-18 13:09:39 -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
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
Holly Borla
ea1a46c84d [ConstraintFix] Rather than creating a coalesced fix right before
diagnosing failures in applySolutionFixes, coalesce fixes and
diagnose failures in one method on ConstraintFix.

This eliminates the need for the `DefaultGenericArgument` fix (which
was renamed from `ExplicitlySpecifyGenericArguments`) to have an
array of missing parameters, which was only used when the fixes were
coalesced. Instead, the coalesced arguments are used to create the
`MissingGenericArgumentsFailure` diagnostic directly.
2019-11-13 14:15:40 -08:00
zoecarver
853dfbefa0 Copy labels and conformances 2019-11-12 13:34:01 -08:00
zoecarver
27ffff100e Use range-based for-loop 2019-11-11 19:37:16 -08:00
Holly Borla
7f2d4c0a99 [CSApply] When applying constraint fixes for a solution, only coalesce
fixes of the same kind.
2019-11-11 10:08:25 -08:00
zoecarver
18f918b5dd Regenerate labels in CSApply instead of keeping two sizes 2019-11-10 20:19:34 -08:00
Robert Widmann
1000c9d19e Remove some ancillary TypeCheckers 2019-11-10 14:29:05 -08:00
Robert Widmann
ecb7b8c749 Make convertToType a utility 2019-11-10 13:39:34 -08:00
Robert Widmann
32e68468f4 Remove TypeChecker from parameter default checking 2019-11-10 13:34:43 -08:00
Robert Widmann
7bad9aacc3 Drop the TypeChecker out of ConstraintSystem 2019-11-10 13:26:47 -08:00
Robert Widmann
63896c1fc5 Make more high-level type checking endpoints utility 2019-11-10 13:03:46 -08:00
Robert Widmann
d21424b58b Make typeCheckExpression a utility 2019-11-10 12:40:09 -08:00
Robert Widmann
4bf902549f Merge pull request #28152 from hamishknight/decontextualize
Make TypeChecker's Context and Diags fields private
2019-11-09 15:00: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
Hamish Knight
643ef80486 Remove external uses of TypeChecker's Context field 2019-11-08 10:59:20 -08:00
Robert Widmann
41ab235797 [CS] Remove some TypeChecker uses 2019-11-07 12:41:37 -08:00
Hamish Knight
fb55c032f8 diagnoseUnownedImmediateDeallocation doesn't need a TypeChecker 2019-11-07 12:41:37 -08:00
Hamish Knight
cb0c9adc46 Use getXXXType over getXXXDecl in a bunch of places 2019-11-07 08:26:08 -08:00
Robert Widmann
e6dbfa393a Move Utilities back to TypeChecker 2019-11-06 15:20:46 -08:00
Robert Widmann
e5599ef25d Make coerceParameterListToType a utility 2019-11-06 15:08:59 -08:00
Robert Widmann
36987e0491 Drop references to the type checker in CSApply 2019-11-06 15:08:59 -08:00
Robert Widmann
59db7832b0 Make coerceToRValue a utility 2019-11-06 15:08:59 -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
Doug Gregor
39af1d0c55 [Constraint solver] Drop Expr* from finalization.
We don't need to pass an expression into rewriter finalization; the update
of expression types can be handled per-expression.
2019-11-06 08:39:47 -08:00
Robert Widmann
6c6035eca2 Drop TypeCheckers out of TypeCheckStmt 2019-11-05 22:52:28 -08:00
Robert Widmann
e804d6ed9a Make TypeChecker::getDefaultType a utility 2019-11-05 20:31:15 -08:00
Robert Widmann
392df03466 [NFC] Drop unnecessary TypeCheckers from Sema 2019-11-05 20:30:40 -08:00
Holly Borla
e840d52258 [Diagnostics] Allow fixes with the same locator to be coalesced before
application rather than throwing away subsequent fixes.

The "primary fix" decides whether or not to coalesce fixes that have
the same locator.
2019-11-05 09:15:13 -08:00
Robert Widmann
8a69f886ad Merge pull request #27955 from AnthonyLatsis/bracestmt_cleanup
NFC: Solidify and tidy up the BraceStmt interface
2019-10-31 13:48:40 -07:00
Robert Widmann
4996858c4d Re-implement isInvalid for ValueDecls 2019-10-30 15:09:14 -07:00
Robert Widmann
118f68b1be Make getProtocol and getLiteralProtocol static utilities 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
Robert Widmann
da2b063af9 Make calls to lookupMember actually look static 2019-10-30 12:55:42 -07:00
Robert Widmann
bcf03aa019 Make getDeclTypeCheckingSemantics a utility 2019-10-30 12:55:10 -07:00