Commit Graph

49 Commits

Author SHA1 Message Date
Pavel Yaskevich
fecc887024 Merge pull request #40438 from xedin/rdar-85843677
[PreCheck] Don't use value declared in closure as outer candidate if …
2021-12-07 12:14:58 -08:00
Pavel Yaskevich
f642c3efc8 [PreCheck] Don't use value declared in closure as outer candidate if it's validated
With multi-statement closure inference enabled "outer candidates"
hack needs to be careful with its use of `isInvalid()` because some
of the declarations lookup finds might be coming from a multi-statement
closure that being type-checked, such declarations have to be avoided
as candidates, otherwise calling `isInvalid` on them results in a circular
type-checking.

Resolves: rdar://85843677
2021-12-06 16:47:56 -08:00
Pavel Yaskevich
dcf80e62d0 [PreCheck] Avoid patterns that appear in closures when multi-statement inference is enabled
Scope down previous check to avoid walking into patterns that appear
in multi-statement closures if the inference is enabled.
2021-12-03 10:56:55 -08:00
Pavel Yaskevich
0e6e058e7c [TypeChecker] Fix constraint solver to respect LeaveClosureBodyUnchecked flag 2021-12-03 10:54:07 -08:00
Pavel Yaskevich
bc54bc6bb7 Revert "[TypeChecker] SE-0326: Enable multi-statement closure inference by default" 2021-11-29 17:26:08 -08:00
Anthony Latsis
e48f4830dd TypeResolution: Replace more 'forContextual' uses with 'resolveContextualType' 2021-11-19 16:44:03 +03:00
Pavel Yaskevich
63f355fde0 Merge pull request #39989 from xedin/more-diag-improvements-for-multi-stmt-closures
[TypeChecker] SE-0326: Enable multi-statement closure inference by default
2021-11-17 10:14:58 -08:00
Pavel Yaskevich
8dddc89127 [PreCheck] Avoid patterns that appear in closures when multi-statement inference is enabled
Scope down previous check to avoid walking into patterns that appear
in multi-statement closures if the inference is enabled.
2021-11-15 16:42:05 -08:00
Pavel Yaskevich
83033198c3 [TypeChecker] Fix constraint solver to respect LeaveClosureBodyUnchecked flag 2021-11-15 16:42:05 -08:00
Hamish Knight
15098e22bd [AST] Rename resolveComponents -> setComponents
The naming here has bothered me for a little while
now, it just sets the components, it doesn't
resolve anything.
2021-11-15 12:25:17 +00:00
Robert Widmann
22ad19f64b Revert "[Sema] Diagnose and reject top-level placeholders"
This reverts commit f6b6bff6de.
2021-11-03 10:29:14 -07:00
Pavel Yaskevich
f074305e87 [PreCheck] Allow pre-check to walk into patterns when multi-statement inference is disabled
This restores original pre-check behavior and is important for diagnostics
like `'_' can only appear in a pattern or on the left side of an assignment`.
2021-10-08 12:29:34 -07:00
Pavel Yaskevich
01040809a5 [PreCheck] Don't walk into any declaration besides PatternBindingDecl
All other declarations encountered in a body of a multi-statement
closure are handled during solution application via calling
`TypeChecker::typeCheckDecl` that would run its own pre-check.
2021-10-08 10:08:03 -07:00
Pavel Yaskevich
c712d07928 [PreCheck] Don't attempt to pre-check patterns
Patterns found in different statements of a multi-statement closure
are going to be resolved while closure is type-checked.
2021-10-08 10:08:02 -07:00
Hamish Knight
3e28bbbd2c Update for review feedback
- Remove OriginalArguments in favor of storing the
pre-rewritten argument list, which simplifies things
nicely
- Adopt llvm::indexed_accessor_iterator
2021-09-01 18:40:29 +01:00
Hamish Knight
8c2b88abc0 [CS] Adopt ArgumentList
- Explicitly limit favoring logic to only handle
unary args, this seems to have always been the
case, but needs to be handled explicitly now that
argument lists aren't exprs
- Update the ConstraintLocator simplification to
handle argument lists
- Store a mapping of locators to argument lists
in the constraint system
- Abstract more logic into a getArgumentLocator
method which retrieves an argument-to-param locator
from an argument anchor expr
2021-09-01 18:40:25 +01:00
Hamish Knight
89276c077f [CS] Tighten up check for unresolved member chain
With the removal of TupleExpr and ParenExpr argument
lists, it's no longer sufficient to check whether
a given parent expr has a possible chain sub-expr,
as it might be a child that's unrelated to the chain
under consideration. For example, for a chain that's
an argument to a function call, we don't want to
walk up and consider the call expr to be an extension
of the chain just because it has a function expr.

Tighten up the check by comparing whether the given
sub-expr of a possible chain parent matches the
current expr in the chain.
2021-09-01 18:40:24 +01:00
Hamish Knight
8be85c09b9 [Sema] Have isValidTypeExprParent consider its child
With the introduction of the ArgumentList type,
argument expressions will be direct decedents of
call expressions, without an intermediate TupleExpr.
As such, we need to tweak isValidTypeExprParent to
consider the child expression such that `T(x)` is
permissible, but `x(T)` is not.

Change isValidTypeExprParent to take a child expr
parameter, and update its use in MiscDiagnostics
and PreCheckExpr. For PreCheckExpr, switch from a
stack to walking the parent directly, as a
stack-based approach would be a bit more fiddly in
this case, and walking the parents shouldn't be
expensive.

This should be NFC, I'm splitting it off from the
ArgumentList refactoring to make the rebasing there
a little more straightforward.
2021-08-27 12:38:33 +01:00
Frederick Kellison-Linn
f6b6bff6de [Sema] Diagnose and reject top-level placeholders 2021-08-19 14:53:34 -04:00
Frederick Kellison-Linn
42b04279f0 [Sema] Rework TypeExpr folding for placeholders 2021-08-19 14:53:33 -04:00
Frederick Kellison-Linn
c305cb01a8 [Sema] Re-enable placeholder type parsing and folding 2021-08-19 14:53:21 -04:00
Robert Widmann
808220510e [NFC] Remove Unused Module Parameter to Conformance Lookup
It's been quite a long time since this unused parameter was introduced.
The intent is to produce the module as a root for the search - that is,
computing the set of conformances visible from that module, not the set
of conformances inside of that module. Callers have since been providing
all manner of module-scoped contexts to it.

Let's just get rid of it. When we want to teach protocol conformance
lookup to do this, we can revert this commit as a starting point and try
again.
2021-08-04 14:43:31 -07:00
Alex Hoppen
d64b8ecea6 [CodeCompletion] Migrate key path completion to be solver based
This commit essentially consistes of the following steps:
- Add a new code completion key path component that represents the code completion token inside a key path. Previously, the key path would have an invalid component at the end if it contained a code completion token.
- When type checking the key path, model the code completion token’s result type by a new type variable that is unrelated to the previous components (because the code completion token might resolve to anything).
- Since the code completion token is now properly modelled in the constraint system, we can use the solver based code completion implementation and inspect any solution determined by the constraint solver. The base type for code completion is now the result type of the key path component that preceeds the code completion component.

This resolves bugs where code completion was not working correctly if the key path’s type had a generic base or result type. It’s also nice to have moved another completion type over to the solver-based implementation.

Resolves rdar://78779234 [SR-14685] and rdar://78779335 [SR-14703]
2021-06-25 23:19:35 +02:00
Hamish Knight
46fa6e5721 [AST] Improve BinaryExpr
Abstract away the TupleExpr gunk and expose
`getLHS` and `getRHS` accessors. This is in
preparation for completely expunging the use
of TupleExpr as an argument list.
2021-05-19 14:48:01 +01:00
Pavel Yaskevich
2898b50b7f Revert "Revert "[TypeChecker] PreCheck: Don't strip away tuple/paren from subscripts …"" 2021-05-04 11:19:33 -07:00
Pavel Yaskevich
b12d57afac Revert "[TypeChecker] PreCheck: Don't strip away tuple/paren from subscripts …" 2021-05-03 11:55:25 -07:00
Pavel Yaskevich
a21f323c16 Merge pull request #36946 from xedin/rdar-61749633
[TypeChecker] PreCheck: Don't strip away tuple/paren from subscripts …
2021-04-26 12:19:55 -07:00
Frederick Kellison-Linn
237b73d7b2 [Sema] Fix stale reference passed to PlaceholderType::get 2021-04-16 23:00:12 -04:00
Pavel Yaskevich
593bbab880 [TypeChecker] PreCheck: Don't strip away tuple/paren from subscripts and ObjC literals
`PreCheckExpression` already skips calls, make sure that invalid subscripts,
dynamic subscript, ObjC literals preserve paren/tuple for an index/argument.

Resolves: rdar://61749633
2021-04-16 11:40:19 -07:00
Pavel Yaskevich
84857b6374 [PreCheck] Remove closure parameter validation
This is no longer necessary since parameter type would be validated
during constraint generation.
2021-03-25 14:34:24 -07:00
Slava Pestov
58dbf60d18 Merge pull request #36441 from slavapestov/ban-defer-forward-reference
Sema: Ban forward references of captured values from 'defer' body
2021-03-16 17:26:28 -04:00
Slava Pestov
b6381d4549 Sema: Ban forward references of captured values from 'defer' body
While 'defer' is implemented as a local function, it doesn't
behave as one. In particular, since SILGen runs it after
destroying all local bindings that appear after the 'defer'
definition, the body of a 'defer' cannot forward reference
captured bindings the way that local functions can.

Note that I had to remove a SILGen test case for an older,
related issue. The new diagnostic in Sema catches these cases
earlier.

Fixes rdar://problem/75088379.
2021-03-15 17:17:30 -04:00
Pavel Yaskevich
2e0bda57e9 Merge pull request #35933 from mininny/add-diagnostics-for-invalid-power-operator
[Diagnostics] Add diagnostic when using nonexistent '**' operator
2021-03-15 00:34:02 -07:00
Minhyuk Kim
56f4a7bb7c Add unexisting_power_operator diagnostic when using unexisting ** operator in swift 2021-03-14 21:17:16 +09:00
Holly Borla
6a8232e184 [PreCheckExpr] Strip $ prefixes out from compound decl names for unqualified
lookup in TypeChecker::resolveDeclRefExpr.
2021-02-25 18:35:13 -08:00
Frederick Kellison-Linn
1819d33f57 Disable PlaceholderType parsing 2021-02-16 22:59:19 -05:00
Frederick Kellison-Linn
be2aeb513b [Sema] Rework DiscardAssignmentExpr checking wrt SequenceExpr folding
Now that we're checking DiscardAssignmentExprs in PreCheckExpr, we have to be careful to make sure we don't diagnose anything until after SequenceExprs have been folded, since the relevant AssignExprs won't even have a "right hand side" and "left hand side" until after folding.
2021-02-16 22:59:19 -05:00
Frederick Kellison-Linn
e4ea1678dc Rename HoleType to PlaceholderType
HoleType basically served the same purpose as PlaceholderType. This commit unifies the two.
2021-02-16 22:59:19 -05:00
Frederick Kellison-Linn
40122dfecd [Sema] Add support for folding placeholders into TypeExprs
Move markAcceptableDiscardExprs into PreCheckExpr so that we can perform this analysis before we convert expressions like `_? = <value>` into `_ = <value>` since `_?` is now an expression with meaning, and we only want to perform this transformation when `_?` is on the LHS of an assignment
2021-02-16 22:59:19 -05:00
Frederick Kellison-Linn
e508fb3733 [Sema] Introduce placeholder handler to TypeResolver
For now, don't do anything useful in clients. Specifying a placeholder type is still an error
2021-02-16 22:59:18 -05:00
Slava Pestov
01b3965459 Sema: Add a timer for preCheckExpression() 2020-12-15 23:43:04 -05:00
Pavel Yaskevich
607f49dc2e [TypeChecker] Find outermost paren or tuple while checking invalid inout use
Unwrap `InOutExpr` from all parens until the outermost paren or a tuple
to correctly diagnose calls like `foo(((&bar)))` or `foo(x: (&bar))`,
 and suggest a fix-it with moves `&` outside parens.

Resolves: rdar://problem/71356981
2020-11-19 13:31:10 -08:00
Slava Pestov
5808d9beb9 Parse: Remove parse-time name lookup 2020-11-16 22:39:44 -05:00
Slava Pestov
641a257f73 Sema: Don't diagnose forward references to debugger variables in pre-checking 2020-11-16 22:39:43 -05:00
Slava Pestov
2a678f29db Sema: Remove TypeResolutionFlags::AllowUnavailable{,Protocol} 2020-10-14 23:42:44 -04:00
Pavel Yaskevich
461eafff54 [ConstraintSystem] NFC: Move ConstraintSystem.h to include/swift/Sema 2020-10-08 10:45:47 -07:00
Slava Pestov
554e0f97e6 AST: Find local property wrappers in ASTScope::lookupLocalDecls()
Two fixes here:

- The ASTScopeDeclConsumerForLocalLookup needs to visit auxiliary variables
- preCheckExpression() should call ASTScope::lookupLocalDecls() even when
  parser lookup is enabled, since otherwise we won't be able to find
  auxiliary decls in the current DeclContext.
2020-10-02 14:40:11 -04:00
Slava Pestov
06fc9c5a5e Sema: Simulate old name lookup behavior when parser lookup is off
Before performing an UnqualifiedLookup with Flags::IncludeOuterResults
turned on, call ASTScope::lookupSingleLocalDecl() to find local
bindings that precede the current source location.

If this fails, we perform an unqualified lookup to try to find
forward references to captures, type members, and top-level
declarations.
2020-10-01 23:50:16 -04:00
Slava Pestov
d576b4e926 Sema: Move preCheckExpression() into its own file 2020-10-01 17:24:44 -04:00