Commit Graph

2333 Commits

Author SHA1 Message Date
Holly Borla
75c1b6e199 Merge pull request #64166 from hborla/parameter-pack-substitution 2023-03-07 06:39:50 -08:00
Hamish Knight
43f0694fa3 Merge pull request #64149 from hamishknight/more-nfc-changes 2023-03-07 10:49:54 +00:00
John McCall
db4b16e3dd [WIP] Always use PackTypes as the substitutions for type parameter packs
This simplifies the representation and allows clients to handle fewer
cases.  It also removes an ambiguity in the representation which could
lead us to have two canonical types for the same type.

This is definitely not working yet, but I'm not making progress on
it quickly enough to unblock what we need to unblock; it'll have to
be fixed in parallel.
2023-03-06 17:08:35 -08:00
Holly Borla
b0211233a9 Merge pull request #64146 from hborla/shape-of-assertion
[ConstraintSystem] Don't propagate errors for invalid `DeclRef`s in the pattern of a pack expansion.
2023-03-06 14:23:13 -08:00
Hamish Knight
2976edbe20 [CS] Rename SolutionApplicationTarget -> SyntacticElementTarget 2023-03-06 20:54:06 +00:00
Holly Borla
721b846e16 [ConstraintSystem] Don't propagate errors for invalid DeclRefs in the pattern
of a pack expansion.
2023-03-06 10:51:43 -08: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
Holly Borla
8012e45109 [Diagnostics] Diagnose pack element expressions containing a non-pack subexpression. 2023-03-05 00:11:54 -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
Holly Borla
e063f02a42 [ConstraintSystem] Handle invalid pack element bindings during PackElementOf
simplification.
2023-03-04 19:43:43 -08:00
Joe Groff
5ef0c4eaad Merge pull request #64058 from jckarter/minimize-abi-effect-of-parameter-modifiers-b
Only mangle `borrowing`/`consuming` when they would change ABI.
2023-03-03 07:01:50 -08:00
Joe Groff
5345e982e9 Only mangle borrowing/consuming when they would change ABI.
`__shared` and `__owned` would always get mangled, even when they don't have any effect
on ABI, making it unnecessarily ABI-breaking to apply them to existing API to make
calling conventions explicit. Avoid this issue by only mangling them in cases where they
change the ABI from the default.
2023-03-02 21:33:29 -08:00
Holly Borla
ad3a385cd2 [Sema] Eliminate single-element tuples after parameter pack substitution. 2023-03-02 19:37:52 -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
Holly Borla
b78b6b9a77 Merge pull request #63991 from hborla/materialize-pack-from-tuple
[ConstraintSystem] Implement type checking for converting a tuple to a pack using the `.element` syntax.
2023-03-01 16:19:33 -08:00
Hamish Knight
f6f5e89bcd Merge pull request #63996 from hamishknight/nfc-pattern-changes 2023-03-01 21:27:34 +00:00
Hamish Knight
9b8bc6033c [AST] NFC: Refactor ExprPattern construction
Introduce 3 separate factory constructors, and
remove the ability to specify the match expr and
var, as those should be synthesized on-demand.
2023-03-01 15:53:41 +00:00
Holly Borla
509188630b [ConstraintSystem] Implement type checking for converting a tuple to a
pack using the `.element` syntax.
2023-02-28 22:56:59 -08:00
Kavon Farvardin
f41ed5926b implement the forget statement
Currently, this is staged in as `_forget`,
as part of SE-390. It can only be used on
`self` for a move-only type within a consuming
method or accessor. There are other rules, see
Sema for the details.

A `forget self` really just consumes self and
performs memberwise destruction of its data.
Thus, the current expansion of this statement
just reuses what we inject into the end of a
deinit.

Parsing of `forget` is "contextual".
By contextual I mean that we do lookahead to
the next token and see if it's identifier-like.
If so, then we parse it as the `forget` statement.
Otherwise, we parse it as though "forget" is an
identifier as part of some expression.

This way, we won't introduce a source break for
people who wrote code that calls a forget
function.

This should make it seamless to change it from
`_forget` to `forget` in the future.

resolves rdar://105795731
2023-02-28 21:15:17 -08:00
Alex Hoppen
0ed6deea9b Merge pull request #63712 from ahoppen/ahoppen/completion-misc
[CodeCompletion] Collection of minor changes to prepare migrating remaining completion kinds to solver-based
2023-02-28 16:02:58 +01: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
Pavel Yaskevich
dd353b948b Merge pull request #63794 from xedin/rdar-105348781
[CSSimplify] Make "force optional unwrap" fix less aggressive
2023-02-24 10:47:23 -08:00
Alex Hoppen
46f5119113 [CodeCompletion] Don’t crash if constructors in member lookup have an error type 2023-02-22 22:33:42 +01:00
Luciano Almeida
1e4fa6a08d [Sema] Fix variable invalid optional chaining in if context diagnostic 2023-02-22 17:52:02 -03:00
Pavel Yaskevich
084543566e [CSSimplify] Make "force optional unwrap" fix less aggressive
Don't attempt the fix until sub-expression is resolved
if chain is not using leading-dot syntax. This is better
than attempting to propagate type information down
optional chain which is hard to diagnose.

Resolves: rdar://105348781
2023-02-20 16:24:11 -08: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