Commit Graph

1659 Commits

Author SHA1 Message Date
Brent Royal-Gordon
6a8598a99c [NFC] Remove DeclNameRef staging calls 2019-12-11 00:55:18 -08:00
Brent Royal-Gordon
addbe3e5ed [NFC] Thread DeclNameRef through most of the compiler
This huge commit contains as many of the mechanical changes as possible.
2019-12-11 00:55:18 -08:00
Hamish Knight
58884002d8 [CS] Don't adjust opened types of @dynamicMemberLookup overloads
Rather than adjusting the opened types for choices
referring to `subscript(dynamicMember:)` down to
the result type, only use the result type to
bind the overload type variable. This avoids the
need for a couple of special cases in CSApply.

To facilitate this change, add
`ConstraintSystem::bindOverload`, which deals with
adding the necessary constraints to bind the
overload's type variable. The eventual goal here
is to remove `adjustTypeOfOverloadReference`, with
adjustments to the opened type being moved to
`getTypeOfMemberReference`, and the adding of
constraints being moved to `bindOverloadType`.
2019-12-10 18:02:14 -08:00
Hamish Knight
5d7fb487eb [CS] Remove a couple of dead types 2019-12-09 15:27:57 -08:00
Hamish Knight
e2fbe3a020 [CS] Pass SelectedOverload in a couple of places
Rather than passing separate parameters for the
choice, openedType, and openedFullType, just pass
the selected overload.
2019-12-09 15:27:57 -08:00
Hamish Knight
bfdc2c701b [CS] Change openedType -> openedFullType in a couple of cases
This helps avoid confusion with SelectedOverload's
`openedType` member.
2019-12-09 07:53:52 -08:00
Hamish Knight
aa3e2d510c [CS] Stop passing FunctionRefKind in a couple of places
We can retrieve it from the passed OverloadChoice.
2019-12-09 07:53:52 -08:00
Brent Royal-Gordon
e1e7a3fe75 Merge pull request #25656 from brentdax/file-name-basis
Shorten #file and add #filePath (behind an experimental flag)
2019-12-06 21:34:58 -08:00
Hamish Knight
8a83440ce1 [CS] Resolve callees for callAsFunction ".member" exprs
Apply the same checks as ApplyExprs to
UnresolvedMemberExprs in getCalleeLocator to
resolve callees in cases where they're used with
`callAsFunction` in addition to a weird edge case
where we currently allow them with constructor
calls, e.g:

```
struct S {
  static let s = S.self
}

let x: S = .s()
```

Arguably we should be representing ".member()"
expressions with an UnresolvedMemberExpr + CallExpr,
which would avoid the need to apply these special
cases, and reject the above syntax for not using
an explicit ".init". Doing so will likely require
a bit of hacking in CSGen though.

Resolves SR-11909.
2019-12-06 11:21:37 -08:00
Brent Royal-Gordon
63ec1cf5af Introduce a separate #filePath, remove -pound-file
This makes the path behavior more first-class. The feature is now hidden behind an experimental flag, -enable-experimental-concise-pound-file.
2019-12-04 16:35:13 -08:00
Hamish Knight
e5ea69c0fc [CS] Fix key path dynamic member IUOs (#28562)
[CS] Fix key path dynamic member IUOs
2019-12-04 10:57:43 -08:00
Varun Gandhi
e7be41d0cb Merge pull request #27479 from varungandhi-apple/vg-track-clang-function-types
Track Clang function types in the AST
2019-12-04 08:47:35 -08:00
Hamish Knight
d328b1b32a [CS] Correctly set key path component types
Previously we missed caching component types in
one case, and cached the wrong type in another.
Make both cases use cacheExprTypes to cache the
correct component types.
2019-12-04 08:43:06 -08:00
Hamish Knight
ef6a240372 [CS] Fix key path dynamic member IUOs
Previously we were only handling IUO unwrapping in
visitKeyPathExpr, but not for callers that were
building their own property and subscript
components such as dynamic member lookup.

Move the IUO unwrapping logic into
buildKeyPath[Property/Subscript]Component,
and adjust their signatures to allow them to
append multiple components. Also add
buildKeyPathOptionalForceComponent to allow more
convenient adding of an optional force component.

Resolves SR-11893.
2019-12-04 08:43:06 -08:00
Hamish Knight
c1849ba621 [CS] Refactor visitKeyPathExpr a little
Rather than setting `baseTy` for each component,
just set it for the last component in the
iteration. In addition, remove the `component`
variable, which no longer serves a purpose.
Finally, cache all the component types at the end
of the loop.
2019-12-04 08:43:06 -08:00
Hamish Knight
92a6302dcc [CS] Don't throw away unresolved key path components
When originally implemented (a5ca6ccd61),
we used to append the set `component` to
`resolvedComponents`, however that appears to have
been refactored away at some point, leaving a couple
of dead assignments. Restore the old behaviour by
just appending the components.
2019-12-04 08:43:05 -08:00
Slava Pestov
3aa70827e0 Merge pull request #28465 from zoecarver/feature/variadic-args-key-path-subscript
Fix variadic args in key path subscript
2019-12-02 21:35:53 -05:00
Hamish Knight
aa8d7ba833 [CS] Apply all finishApply's transforms to callAsFunction
Rather than coercing the call arguments ourselves,
just build the finished member reference for the
callAsFunction method, and let finishApply do the
rest. This allows us to deal with transformations
such as IUO unwraps.

Resolves SR-11881.
2019-12-02 15:29:21 -08:00
Hamish Knight
19e199e567 Use DefaultArgumentExpr for caller-side defaults (#28279)
Use DefaultArgumentExpr for caller-side defaults
2019-12-02 13:57:17 -08:00
Hamish Knight
53ed83c245 [CS] Coerce dynamic member strings to their param type (#28512)
[CS] Coerce dynamic member strings to their param type
2019-12-02 11:31:31 -08:00
Hamish Knight
e599c8b848 [CS] NFC: Remove unused variable 2019-11-30 14:47:29 -08:00
Hamish Knight
78bcb2e9ae [CS] Coerce dynamic member strings to their param type
Move `buildDynamicMemberLookupIndexExpr` into
ExprRewriter, and pass the string literal through
`handleStringLiteralExpr` to properly handle its
coercion to the parameter type.
2019-11-30 14:47:10 -08:00
Hamish Knight
a014f15e75 [CS] Enforce that withPathElement is called on an lvalue
Locator builders keep a pointer to their underlying
locator, so it's not generally sound to extend an
rvalue locator builder.

This commit enforces that withPathElement is called
on an lvalue, and adds a couple more overloads of
getConstraintLocator to make it more convenient to
extend locators with multiple elements.
2019-11-27 17:13:50 -08:00
zoecarver
c19f3cefec Remove silgen changes and use getParameterType in CSApply 2019-11-26 00:07:31 -08:00
zoecarver
d7f6e4a1b1 Cleanup 2019-11-23 21:50:34 -08:00
zoecarver
758bce9382 Fix variadic arguments in keypath subscripts 2019-11-23 21:43:13 -08:00
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