Commit Graph

1583 Commits

Author SHA1 Message Date
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
Doug Gregor
8283a67648 Revert "Revert "Reimplement function builders as statement transformations."" 2020-01-21 10:07:20 -08:00
Doug Gregor
86c13d3c74 Revert "Reimplement function builders as statement transformations." 2020-01-17 15:52:49 -08:00
Doug Gregor
9853926cb2 [Function builders] Make sure we contextualize closures with builders applied.
We used to get this contextualization "for free" because closures that
had function builders applied to them would get translated into
single-expression closures. Now, we need to check for this explicitly.
2020-01-16 13:19:21 -08:00
Doug Gregor
3a51d5b9b2 [WIP] Reimplement function builders as statement transformations. 2020-01-16 13:18:33 -08:00
Pavel Yaskevich
cf2cad0cd5 [ConstraintSystem] Add more information retrieval callbacks to getCalleeLocator
`getCalleeLocator` has to be able to:

- Retrieve type for given expression via `getType`;
- Simplify given type via `simplifyType`; and
- Retrieve a selected overload choice for a given locator via `getOverloadFor`.
2020-01-14 00:09:33 -08:00
Pavel Yaskevich
8f68a68c70 [ConstraintSystem] Augment getCalleeLocator with getType callback
This is necessary for ambiguity diagnostics because none of the
solutions are applied back to the constraint system which means
that `getCalleeLocator` needs an ability to query information
from different sources e.g. constraint system and/or solution.
2020-01-14 00:09:32 -08:00
Doug Gregor
142b3ad538 [Constraint system] Minor fixes / test updates for function builders. 2020-01-09 16:33:13 -08:00
Doug Gregor
5b320992ea [Constraint solver] Use a constraint system to apply all function builders.
When type checking the body of a function declaration that has a function
builder on it (e.g., `@ViewBuilder var body: some View { ... }`), create a
constraint system that is responsible for constraint generation and
application, sending function declarations through the same code paths
used by closures.
2020-01-09 14:38:45 -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
Doug Gregor
9be16b2185 [Type checker] Move conformance resolution during application into Solution.
While this doesn't completely use the solution's set of known conformances,
it moves the logic for handling the lookup into the right place.
2020-01-02 13:06:09 -08:00
Slava Pestov
af07642c8f Sema: Remove TypeCheckExprFlags::SkipMultiStmtClosures
Fold this into TypeCheckExprFlags::SubExpressionDiagnostics, which
is itself going away soon, hopefully!
2019-12-19 23:51:53 -05:00
Hamish Knight
40d11716f7 [CS] Use custom locator element for callAsFunction
Introduce a `ImplicitCallAsFunction` locator path
element to represent an implicit member reference
to `callAsFunction`. Then adjust CSApply a little
to check whether it's finishing an apply for a
callable type, and if so build the implicit member
access.
2019-12-18 11:43:45 -08:00
Hamish Knight
ee5ce77c7f [CS] Push callee resolution into finishApply
Instead of passing the resolved callee, pass the
callee locator. This avoids every caller having
to resolve the callee themselves.
2019-12-18 11:43:44 -08:00
Robert Widmann
7dd429b67f [NFC] Refactor buildSubscript a bit
Have callers resolve the SelectedOverload instead of the callee.  Then make the error paths more apparent, and flush Optional<SelectedOverload> wherever it can be found.
2019-12-16 11:31:14 -08:00
Robert Widmann
1534b3659d [NFC] Const-qualify SelectedOverload's members 2019-12-16 11:28:54 -08:00
Doug Gregor
9f85ce33b7 Merge pull request #28796 from DougGregor/leave-optimization-to-the-optimizers
[Constraint application] Stop optimizing casts in the AST.
2019-12-14 19:48:19 -08:00
Doug Gregor
cb69e00b83 [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-12-14 16:03:15 -08:00
Doug Gregor
f9eb34a5fa [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-12-14 16:03:15 -08:00
Slava Pestov
594044a049 Sema: Clean up handling of protocol operators with concrete operands
In this case we would "devirtualize" the protocol requirement call
by building the AST to model a direct reference to the witness.

Previously this was done by recursively calling typeCheckExpression(),
but the only thing this did was recover the correct substitutions
for the call.

Instead, we can just build the right SubstitutionMap directly.
Unfortunately, while we serialize enough information in the AST
to devirtualize calls at the SIL level, we do not for AST Exprs.

This is because SIL devirtualization builds a reference to the
witness thunk signature, which is an intermediate step between
the protocol requirement and the witness. I get around this by
deriving the substitutions from walking in parallel over the
interface type of the witness, together with the inferred type
of the call expression.
2019-12-14 01:02:33 -05:00
Slava Pestov
7626f9de4f AST: Small cleanups
- Allow AbstractClosureExpr to be created with null body
- Split up ParameterList::CloneFlags::Inherited
2019-12-13 15:39:47 -05:00
Slava Pestov
db357d95a9 Sema: Remove unused 'locator' parameter in a few places 2019-12-13 15:39:47 -05:00
Brent Royal-Gordon
7543a89cc4 Merge pull request #27683 from brentdax/i-understood-that-reference
[NFC] Distinguish references to names from declarations of those names by type
2019-12-11 10:50:57 -08:00
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