Commit Graph

2208 Commits

Author SHA1 Message Date
Luciano Almeida
1e4fa6a08d [Sema] Fix variable invalid optional chaining in if context diagnostic 2023-02-22 17:52:02 -03:00
Hamish Knight
c82189dc02 Merge pull request #63747 from hamishknight/oh-bool 2023-02-18 14:57:24 +00: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
L-j-h-c
913dcd62b8 [Gardening] fix typos across docs and codebase
fix typos across docs and codebase
2023-02-17 23:55:16 +09:00
Pavel Yaskevich
4b6b5109f4 Merge pull request #63694 from apple/revert-63140-two-way-args-in-result-builders
Revert "[CSSimplify] Don't enable `OneWayBindParam` for result builder transf…"
2023-02-16 09:40:11 -08:00
Pavel Yaskevich
fe5559fe53 Merge pull request #63677 from xedin/dont-delay-result-builder-conjunctions
[CSBindings] Solver result builder transformed closures as soon as all contextual information becomes available
2023-02-15 15:22:48 -08:00
Pavel Yaskevich
d464ac3c16 Revert "[CSSimplify] Don't enable OneWayBindParam for result builder transf…" 2023-02-15 14:41:57 -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
Pavel Yaskevich
5659d7e2d9 [CSSimplify] Don't enable OneWayBindParam for result builder transformed closures
This means two things:

- transformed closures behave just like regular multi-statement closures
- It's now possible to pass partially resolved parameter types into
  the closure which helps with diagnostics.
2023-02-14 11:55:00 -08:00
Hamish Knight
c87b1b8bef Merge pull request #63022 from hamishknight/express-yourself 2023-02-03 16:40:09 +00:00
Kavon Farvardin
83166e4009 prevent MO as AnyObject and friends from typechecking
where `MO` is a move-only type.

turns out it was being allowed because the cast is represented as a
disjunction in the constraint solver:

- `MO conv AnyObject`
- `MO bridge conv AnyObject`

I caught the first one but missed the second, which was unconditionally
being allowed.
2023-02-01 23:38:28 -08:00
Kavon Farvardin
0f93d7799a prevent MO types from matching with existentials in the solver
`matchExistentialTypes` ends up getting called in most cases,
to ensure the conversion is legal.
2023-02-01 23:38:28 -08:00
Kavon Farvardin
ab130883a3 Initial ban of move-only types from being used generically
Since values of generic type are currently assumed to always
support copying, we need to prevent move-only types from
being substituted for generic type parameters.

This approach leans on a `_Copyable` marker protocol to which
all generic type parameters implicitly must conform.

A few other changes in this initial implementation:

- Now every concrete type that can conform to Copyable will do so. This fixes issues with conforming to a protocol that requires Copyable.
- Narrowly ban writing a concrete type `[T]` when `T` is move-only.
2023-02-01 23:38:28 -08:00
Holly Borla
e41cdfbdd4 Merge pull request #63341 from hborla/generalize-macro-expansion-expr
[Macros] Generalize `MacroExpansionExpr` and use it for both freestanding and attached macros.
2023-02-01 11:04:39 -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
Holly Borla
9b5cf1d2ff [Diagnostics] Remove the MacroMissingArguments constraint fix and its
associated failure diagnostic.

This constraint fix is unused now that MacroExpansionExpr always has an
argument list, and goes through the AddMissingArguments constraint fix for
this error.
2023-01-31 17:45:31 -08:00
Ikko Eltociear Ashimine
f27399d78d [CSSimplify] Fix typo in CSSimplify.cpp
bellow -> below
2023-02-01 02:56:35 +09:00
Pavel Yaskevich
ccb35fe967 Merge pull request #63083 from xedin/rdar-104302974
[CSSimplify] Report unresolved base failure if leading-dot syntax bas…
2023-01-20 17:36:01 -08:00
Pavel Yaskevich
7b9cffd40a [CSSimplify] Fix should propagate contextual type into optional chain with leading-dot syntax
Member chains with leading-dot syntax can infer the base type
only from context, so optionality mismatch with the contextual
type should propagate object type down the chain.
2023-01-20 09:47:33 -08:00
Pavel Yaskevich
c7cde3aef0 Merge pull request #63004 from xedin/improve-tuple-matching-diag-in-result-builder-context
[CSSimplify] Allow conversions between tuple element type and a placeholder
2023-01-19 10:25:44 -08:00
Pavel Yaskevich
9308796c66 [CSSimplify] Report unresolved base failure if leading-dot syntax base is a placeholder
If base type of the leading-dot syntax expression has been determined
to be a placeholder, this could only mean that `.<name>` couldn't be
resolved in the current context.

Resolves: rdar://104302974
2023-01-18 16:11:28 -08:00
Luciano Almeida
e513d23c0b [Sema] Improving global actor function mismatch diagnostic 2023-01-13 20:47:23 -03:00
Pavel Yaskevich
1c076f0e2b [CSSimplify] Allow conversions between tuple element type and a placeholder
If a placeholder appears on one of the side of tuple element matching
conversion, consider that conversion to be solved, because the actual
error is related to the placeholder.
2023-01-12 18:16:43 -08:00
Holly Borla
2d893d23bf [GenericEnvironment] For opened pack element environments, only include element type
parameters whose originating packs are in a given shape equivalence class.
2023-01-08 12:59:08 -08:00
Holly Borla
319ae65636 [Diagnostics] Don't fail simplifyFixConstraint for tuples of pack expansion types. 2023-01-07 09:50:14 -08:00
Holly Borla
c363fa2510 [Diagnostics] Make same-shape requirement failure diagnostics less sensitive
to binding order.
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
Kavon Farvardin
d02314730c Merge pull request #62514 from LucianoPAlmeida/contextual-ambiguous
[CS] Increase the score for implicit global actor function conversion
2023-01-04 13:10:22 -08:00
Doug Gregor
0c5436211c Merge pull request #62768 from DougGregor/macro-omnibus 2023-01-03 07:13:16 -08:00
takeshi-komori
29bf82ebed [CSSimplify] Fix sub-pattern matching logic related closure and enum element (#62777)
* [CSSimplify] fix pattern matching logic which is as part of the enum element for closure

* add test

* Fixed logic to apply to N levels of nesting

* update tests that take into account N levels of nesting.

* fix indentation

* use dynamic variables and uppdate some logic

* Revert "use dynamic variables and uppdate some logic"

This reverts commit 279dc4fe6b.

* fix logic to only see pattern matches

* clean up unnecessary logic

Co-authored-by: Luciano Almeida <passos.luciano@outlook.com>

* Clean up unnecessary logic(2)

* remove dropping

* Fix documentation comments to match current context

* clean up unnecessary logic

* remove comments

Co-authored-by: Luciano Almeida <passos.luciano@outlook.com>
2023-01-03 01:18:38 -08:00
Doug Gregor
71ca9c86e6 [Macros] Diagnose when we forget to provide macro arguments.
Unlike functions, you can't curry macros; diagnose when one omits the
arguments in a macro expansion of a macro that has a parameter list.
2023-01-02 21:22:04 -08:00
Doug Gregor
806b5a8777 [Macros] Diagnose errors where a macro is used without the '#'. 2023-01-02 21:22:04 -08:00
Holly Borla
0d3504fba6 Merge pull request #62729 from hborla/pack-diagnostics
[CSDiagnostics] Add an error message for pack expansion expressions over packs that don't have the same shape.
2022-12-21 13:44:08 -05:00
Holly Borla
42ede18fb0 Merge pull request #62713 from hborla/open-pack-element-type-repr
[ConstraintSystem] Enable pack element type reprs in expressions.
2022-12-21 10:48:42 -05:00
Holly Borla
e966b4ef7d [CSDiagnostics] Add an error message for pack expansion expressions over
packs that don't have the same shape.
2022-12-21 08:25:10 -05:00
Holly Borla
2df72f6bcc [ConstraintSystem] Strip pack expansions off of pack reference types in
getUnopenedTypeOfReference.
2022-12-20 22:13:40 -05:00
Robert Widmann
2b27330519 Merge pull request #62676 from valeriyvan/CSSimplify-simplify-condition
[Refactoring] Simplify excessive conditional expression: (A && !B) || (!A && B) is equivalent to bool(A) != bool(B)
2022-12-19 12:55:23 -07:00
Valeriy Van
194ecff898 Simplify conditional expression: (A && !B) || (!A && B) is equivalent to bool(A) != bool(B) 2022-12-19 15:26:52 +02:00
Holly Borla
2be16b84c5 [CSSimplify] Delay matching tuple types with unresolved pack expansions followed
by an unlabeled element until pack type variables are resolved.
2022-12-15 17:00:33 -05:00
Holly Borla
ea68720e12 [CSBindings] Instead of breaking a PackElementOf constraint down into Bind
constraints, vend potential bindings through PotentialBindings::infer.

This allows for bidirectional binding inference from the pack type to the
element type and vice versa.
2022-12-14 20:45:51 -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
Luciano Almeida
187cf81d16 [CS] Increase the score for implicit global actor function conversion 2022-12-12 00:08:18 -03:00
Alex Hoppen
9a0a7722f9 [IDE] Disable a few code completion specific paths for solver-based CursorInfo
The lexer will be responsible for knowing whether we have a code completion token, everything else will also work for other IDE inspection features.

The changes start to really make sense once I rename CodeCompletion -> IDEInspection in a lot of places.
2022-12-10 12:12:21 +01:00
Pavel Yaskevich
7588434007 [CSSimplify] Account for tuple splat when resolving closure parameters
SE-0110 allows tuple slat between function types. The solver needs to
account for that when trying to infer parameter types from context
while resolving a closure in order to propagate types and speed up
type-checking.

Resolves: https://github.com/apple/swift/issues/62390
2022-12-05 00:28:52 -08:00
Slava Pestov
b122977671 AST: Record both LHS and RHS index in PackExpansionMatcher.cpp 2022-12-01 15:25:20 -05:00
Doug Gregor
64f2c8ef0c Address a few comments about the specialization arguments constraint. 2022-11-28 18:33:11 -08:00
Doug Gregor
8adee85cb6 [Macros] Add support for explicit generic arguments of macros.
Enable type checking support for explicitly specifying generic arguments to
a macro, e.g., `#stringify<Double>(1 + 2)`. To do so, introduce a new
kind of constraint that performs explicit argument matching against the
generic parameters of a macro only after the overload is chosen.
2022-11-28 18:32:43 -08:00
Pavel Yaskevich
c17d35dc3e Merge pull request #62146 from xedin/rdar-102085039
[AST] `getParameterAt` should check index before retrieving it
2022-11-28 10:01:51 -08:00
Erik Eckstein
ab1b343dad use new llvm::Optional API
`getValue` -> `value`
`getValueOr` -> `value_or`
`hasValue` -> `has_value`
`map` -> `transform`

The old API will be deprecated in the rebranch.
To avoid merge conflicts, use the new API already in the main branch.

rdar://102362022
2022-11-21 19:44:24 +01:00
Pavel Yaskevich
77fb90ee19 [Sema/SILGen] Add asserts to getParameterAt call sites that expect non-null parameter 2022-11-17 11:52:00 -08:00