Commit Graph

672 Commits

Author SHA1 Message Date
Hamish Knight
fdc9817471 Merge pull request #64174 from hamishknight/pattern-requests 2023-03-08 10:52:40 +00:00
Hamish Knight
54c2fbf6f3 [CS] NFC: Add Solution::getTargetFor 2023-03-07 15:16:34 +00:00
Holly Borla
75c1b6e199 Merge pull request #64166 from hborla/parameter-pack-substitution 2023-03-07 06:39:50 -08:00
Holly Borla
e7f82bc6e7 [ConstraintSystem] Record both the UUID and the shape class for opened pack
element environments.

This allows the constraint system to ensure that for a given pack expansion locator,
the given shape class is always the same when requesting the element environment.
If the shape class differs, it means there's a same-shape requirement failure, which
will be diagnosed via the ShapeOf constraint simplification.
2023-03-06 21:22:35 -08:00
Hamish Knight
2976edbe20 [CS] Rename SolutionApplicationTarget -> SyntacticElementTarget 2023-03-06 20:54:06 +00:00
Hamish Knight
cbea535cc8 [CS] Cleanup an unused parameter in CSApply 2023-03-06 20:54:05 +00:00
Hamish Knight
570b9f31df [CS] Split out SolutionApplicationTarget.h
Some clients such as code completion ought to be
able to reference this without pulling in the
entirety of ConstraintSystem.h.
2023-03-06 20:54:03 +00:00
Pavel Yaskevich
342e5f6725 Merge pull request #64036 from xedin/rdar-106054263
[CSSimplify] Detect and diagnose generic argument mismatches individually
2023-03-06 10:18:09 -08:00
Pavel Yaskevich
b7745b04bd [CSSimplify] Detect and diagnose generic argument mismatches individually
Generic arguments types are not always resolved enough to enable
aggregated mismatch fixes, which means that the solver should be
able to handle standalone generic argument matching constraints
and create a fix per mismatch location to coalesce them during
diagnostics.

Resolves: rdar://106054263
2023-03-04 21:57:53 -08:00
Mishal Shah
e256b56545 Merge branch 'main' into rebranch 2023-03-02 18:25:09 -08:00
Pavel Yaskevich
1dd6d349d1 [ConstraintSystem] NFC: Pass down matcher flags to repairFailures 2023-03-02 11:02:30 -08:00
Andrew Trick
f1ff6958a3 Merge pull request #63825 from atrick/diagnose-implicit-raw-bitwise
Warn on implicit pointer conversion from nontrivial inout values.
2023-03-02 10:57:30 -08:00
Ben Barham
59afba5bf9 Manually merge branch 'main' into rebranch 2023-03-01 14:13:50 -08:00
Hamish Knight
3a7b5586ed [CS] NFC: Introduce SolutionApplicationTarget::isForInitialization 2023-03-01 15:53:40 +00:00
Doug Gregor
200f2340d9 [Macros] Be deliberate about walking macro arguments vs. expansions
Provide ASTWalker with a customization point to specify whether to
check macro arguments (which are type checked but never emitted), the
macro expansion (which is the result of applying the macro and is
actually emitted into the source), or both. Provide answers for the
~115 different ASTWalker visitors throughout the code base.

Fixes rdar://104042945, which concerns checking of effects in
macro arguments---which we shouldn't do.
2023-02-28 17:48:23 -08:00
Andrew Trick
185e6fabd5 Add TypeBase::isArrayType helper API.
This is also needed in SIL diagnostics, not just Sema diagnostics,
because implicit Array conversion generates special SIL patterns.
2023-02-27 21:51:17 -08:00
swift-ci
7c9fd4dc12 Merge remote-tracking branch 'origin/main' into rebranch 2023-02-18 06:58:04 -08:00
Hamish Knight
eac3fb4506 [CS] NFC: Default the allowFreeTypeVariables parameter
All but one client wants to set this to anything
other than `FreeTypeVariableBinding::Disallow`.
2023-02-17 20:58:46 +00:00
swift-ci
6b227723c8 Merge remote-tracking branch 'origin/main' into rebranch 2023-02-16 04:53:57 -08:00
Slava Pestov
7d1f7f62e6 Merge pull request #63704 from slavapestov/pack-element-type-repr-fixes
A couple of PackElementTypeRepr fixes
2023-02-16 07:51:29 -05:00
Slava Pestov
e0c341d0ac AST: Rename PackReferenceTypeRepr => PackElementTypeRepr 2023-02-15 22:37:07 -05:00
swift-ci
f5f3acff89 Merge remote-tracking branch 'origin/main' into rebranch 2023-02-15 15:33:54 -08:00
Pavel Yaskevich
a815de7586 [Sema] NFC: Add accessor to determine whether a type variable represents an opaque type 2023-02-14 16:43:53 -08:00
Pavel Yaskevich
f27369d93a [BuilderTransform] Add contextual type to transformation information
This information would be used to decide whether conjunction that
represents transformed closure should be delayed or not.
2023-02-14 16:30:42 -08:00
swift-ci
197114cb22 Merge remote-tracking branch 'origin/main' into rebranch 2023-02-03 08:55:08 -08:00
Hamish Knight
c87b1b8bef Merge pull request #63022 from hamishknight/express-yourself 2023-02-03 16:40:09 +00:00
swift-ci
853bcf6b49 Merge remote-tracking branch 'origin/main' into rebranch 2023-02-01 23:13:19 -08:00
Hamish Knight
a40f1abaff Introduce if/switch expressions
Introduce SingleValueStmtExpr, which allows the
embedding of a statement in an expression context.
This then allows us to parse and type-check `if`
and `switch` statements as expressions, gated
behind the `IfSwitchExpression` experimental
feature for now. In the future,
SingleValueStmtExpr could also be used for e.g
`do` expressions.

For now, only single expression branches are
supported for producing a value from an
`if`/`switch` expression, and each branch is
type-checked independently. A multi-statement
branch may only appear if it ends with a `throw`,
and it may not `break`, `continue`, or `return`.

The placement of `if`/`switch` expressions is also
currently limited by a syntactic use diagnostic.
Currently they're only allowed in bindings,
assignments, throws, and returns. But this could
be lifted in the future if desired.
2023-02-01 15:30:18 +00:00
Alex Hoppen
2c5b193892 [Sema] Type check multi-statement closures inside result builders 2023-02-01 10:29:56 +01:00
swift-ci
6e6d419476 Merge remote-tracking branch 'origin/main' into rebranch 2023-01-26 13:34:34 -08:00
Hamish Knight
76da268b4b [CS] Debug: Print ASTNode for contextual type
If we don't have an associated TypeRepr for a
contextual type in the constraint system, dump the
ASTNode that it's for instead.

Before:

```
Contextual Type: $T2
```

After:

```
Contextual Type: $T2 at DeclRef@/Users/hamish/src/swift-test-arena/swift-test-arena/main.swift:1493:21
```
2023-01-26 17:21:49 +00:00
swift-ci
a32e3d57f4 Merge remote-tracking branch 'origin/main' into rebranch 2023-01-09 01:34:36 -08:00
Doug Gregor
97ee7024cf Merge pull request #62917 from DougGregor/macro-expansion-diags 2023-01-09 01:29:58 -08:00
Erik Eckstein
712fd7922b Merge remote-tracking branch 'origin/main' into rebranch 2023-01-09 08:48:47 +01:00
Doug Gregor
c06216c36d [Macros] Disable macro expansion within the definition of macros.
... and once we do that, ensure that `#externalMacro` can only be
expanded as the definition of another macro.
2023-01-08 22:43:07 -08:00
Holly Borla
715de13dbf [Sema] Key opened pack element generic on the shape class of the expansion. 2023-01-07 15:07:51 -08:00
Holly Borla
6e28f996ce [ConstraintSystem] Create opened pack element generic environments lazily
in the constraint system.
2023-01-07 09:50:14 -08:00
Holly Borla
b01fc1a7a7 [ConstraintSystem] Pack element type variables can bind to noescape. 2023-01-07 09:50:14 -08:00
Kavon Farvardin
3f6a0ccb90 Allow a global-actor to be dropped for some non-async functions.
It's ok to drop the global-actor qualifier `@G` from a function's type if:

- the cast is happening in a context isolated to global-actor `G`
- the function value will not be `@Sendable`
- the function value is not `async`

It's primarily safe to drop the attribute because we're already in the
same isolation domain. So it's OK to simply drop the global-actor
if we prevent the value from later leaving that isolation domain.
This means we no longer need to warn about code like this:

```
@MainActor func doIt(_ x: [Int], _ f: @MainActor (Int) -> ()) {
  x.forEach(f)
// warning: converting function value of type '@MainActor (Int) -> ()' to '(Int) throws -> Void' loses global actor 'MainActor'
}
```

NOTE: this implementation is a bit gross in that the constraint solver
might emit false warnings about casts it introduced that are actually
safe. This is mainly because closure isolation is only fully determined
after constraint solving. See the FIXME's for more details.

resolves rdar://94462333
2023-01-05 17:54:00 -08:00
Pavel Yaskevich
2e25c2fc80 Merge pull request #62791 from xedin/rdar-103739206
[Diagnostics] Relax contextual type presence from assertion to a check
2023-01-04 09:47:19 -08:00
swift-ci
1a625f2706 Merge remote-tracking branch 'origin/main' into rebranch 2023-01-03 01:13:18 -08:00
Pavel Yaskevich
eaf0532a04 [Diagnostics] Relax contextual type presence from assertion to a check
In some situations `getContextualType` for a contextual type
locator is going to return then empty type. This happens because
e.g. optional-some patterns and patterns with incorrect type don't
have a contextual type for initialization expression but use
a conversion with contextual locator nevertheless to indicate
the purpose. This doesn't affect non-ambiguity diagnostics
because mismatches carry both `from` and `to` types.

Resolves: rdar://problem/103739206
2023-01-02 21:11:07 -08:00
Alex Hoppen
3c90c892e9 [CodeCompletion] Drop ForCodeCompletion constraint system option for syntactic elements that don't contain completion token 2022-12-21 12:17:56 -08:00
swift-ci
06a400d795 Merge remote-tracking branch 'origin/main' into rebranch 2022-12-21 07:53:50 -08:00
Holly Borla
58953567b3 [CSGen] Use PackExpansionExpr::getExpandedPacks to generate ShapeOf constraints
rather than relying on PackElementExprs collected by preCheck.

This handles pack element expressions and pack element type reprs, and enforces that
all packs expanded by a given pack expansion expression all have the same shape.

Once the parser creates PackExpansionExpr directly (based on a dedicated syntax instead
of postfix '...'), the code in preCheck for identifying and creating pack expansions
can simply be deleted.
2022-12-20 22:34:16 -05:00
Holly Borla
a2346db445 [ConstraintSystem] Add a getAsTypeRepr helper method for casting ASTNodes. 2022-12-20 21:28:16 -05:00
Holly Borla
334efb9975 [ConstraintSystem] Always pass in a direct instance of OpenPackElementType instead
of assigning it to std::function_ref.

std::function_ref does not own the function reference, so assigning an OpenPackElementType
to a local function_ref lead to stale constraint system references when invoking
operator () later on.
2022-12-20 15:44:42 -05:00
Holly Borla
27aa3651e8 [ConstraintSystem] Open pack element types using a PackElementOf constraint
when resolving pack reference type reprs inside pack expansion expressions.
2022-12-20 11:36:58 -05:00
swift-ci
446f63fdc1 Merge remote-tracking branch 'origin/main' into rebranch 2022-12-13 07:53:58 -08:00
Alex Hoppen
fe2ae72ad2 [IDE] Rename CodeCompletion to IDEInspection in cases where the code path no longer exclusively applies to code completion
The code completio infrastructure is also being used for cursor info now, so it should no longer be called code completion.

rdar://103251187
2022-12-13 11:41:05 +01:00