Commit Graph

164 Commits

Author SHA1 Message Date
Pavel Yaskevich
31e0a52be4 [CSFix] Add a skeleton of a fix for missing each in value pack reference 2023-05-08 13:30:51 -07:00
Hamish Knight
91209d4226 [CS] NFC: Factor out AllowAssociatedValueMismatch
This seems better suited as its own fix, rather
than as part of ContextualMismatch.
2023-05-04 14:53:57 +01:00
Pavel Yaskevich
d8c8a39cc5 [CSFix] Add a fix to allow value pack expansions without pack references
Situations like `repeat x` where `x` is `Int` where pack expansion
expression doesn't have any pack references.
2023-05-02 09:32:19 -07:00
Pavel Yaskevich
b9ef2cabe4 [CSFix] Add a skeleton of a fix for argument destructuring to match pack expansion 2023-05-02 09:32:19 -07:00
Holly Borla
da3079de05 [ConstraintSystem] Diagnose pack expansion expressions in non-variadic contexts. 2023-03-21 21:58:05 -07:00
Pavel Yaskevich
230dfcc30c Merge pull request #64490 from xedin/rdar-102412006
[CSFix] Diagnose an invalid member reference in ambiguous contexts
2023-03-21 14:39:59 -07:00
Holly Borla
cb19fc3a71 [ConstraintSystem] Enforce TVO_CanBindToPack, and diagnose pack references outside
of pack expansion expressions.
2023-03-20 20:13:48 -07:00
Pavel Yaskevich
d7a41c2aff [CSFix] Diagnose an invalid member reference in ambiguous contexts
For example @objc lookup could find multiple instance members
on `AnyObject`. It should be allowed to diagnose issues with
that as non-ambiguous if all fixes have the same kind/base type.

Resolves: rdar://102412006
2023-03-20 15:15:55 -07:00
Pavel Yaskevich
8b63ce8273 Merge pull request #64143 from xedin/ambiguity-diag-improvements
[ConstraintSystem] A couple of improvements to ambiguity diagnostics
2023-03-07 11:57:51 -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
Pavel Yaskevich
6c5186f1ca [CSFix] Diagnose missing base type unwrap in ambiguous contexts 2023-03-06 10:17:51 -08:00
Holly Borla
d11c65a884 [CSFix] Move 'const' qualifier in MustBeCopyable and AllowInvalidPackElement to
match other constraint fixes.
2023-03-05 10:13:32 -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
059891771f [CSFix] Implement coalescing for generic argument mismatch fixes 2023-03-04 21:57:47 -08:00
Pavel Yaskevich
cf8abc9eb9 Merge pull request #64017 from xedin/add-castTo-to-ConstraintFix
[CSFix] NFC: Add a way to cast one fix to the other (to complement `g…
2023-03-02 00:31:26 -08:00
Pavel Yaskevich
2dbc406ad2 [CSFix] NFC: Add a way to cast one fix to the other (to complement getAs)
And to make sure that `classof` is consistent add `const` to some
of the fixes that didn't specify it for the argument.
2023-03-01 17:19:04 -08:00
Pavel Yaskevich
bb1da5e599 [CSFix] Diagnose extraneous force unwraps in ambiguous context 2023-02-24 23:48:03 -08:00
Kavon Farvardin
b7f4344888 make MustBeCopyable::diagnoseForAmbiguity robust
Previous implementation blindly took the first solution
and tried to diagnose, but that's not a safe assumption.

It's possible that among the solution-fix pairs, one
of `noncopyableTy`'s within the fix differs from the
others. Things probably can go wrong because the solution
doesn't correspond to that type.

Also, in that case we'd be emitting a diagnostic that
may not make any sense. In such cases, now we decline
to emit a diagnostic.

Thanks Pavel for catching this.
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
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
Pavel Yaskevich
9b688e9ca6 [CSFix] Move diagnoseForAmbiguity to RequirementFix
The logic is common for all types of fixes that represent
a requirement failure.
2023-01-26 15:55:50 -08:00
Pavel Yaskevich
edb6ef0d9a [CSFix] NFC: Add a common base class for all requirement failures 2023-01-26 15:55:50 -08:00
Pavel Yaskevich
a5bcf13ea9 Merge pull request #63031 from xedin/diag-inaccessible-member-in-ambiguous-context
[CSFix] Diagnose use of inaccessible members in ambiguous contexts
2023-01-16 15:10:57 -08:00
Luciano Almeida
e513d23c0b [Sema] Improving global actor function mismatch diagnostic 2023-01-13 20:47:23 -03:00
Pavel Yaskevich
d43d2ccb8e [CSFix] Diagnose use of inaccessible members in ambiguous contexts 2023-01-13 09:39:02 -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
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
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
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
Slava Pestov
bb045423b3 Sema: Add diagnostics for ShapeOf constraint 2022-10-25 13:20:38 -04:00
Pavel Yaskevich
61a850dfc3 [CSFix] Improve missing .rawValue fix in ambiguity conditions 2022-08-03 15:50:33 -07:00
Pavel Yaskevich
ac89df5c12 [CSFix] Generalize a fix for unresolved pattern decl
The fix should support both named (i.e. `test(a)` and "any" patterns
i.e. `test(_)`.
2022-08-03 15:50:33 -07:00
Alex Hoppen
f623440f01 [CS] Disfavor solutions that were unable to infer the variable type inside a named pattern
We need this to resolve a test failure in optional.swift.
2022-07-20 09:47:16 +02:00
Alex Hoppen
e14fa7291f [CS] Don’t fail constraint generation for ErrorExpr or if type fails to resolve
Instead of failing constraint generation by returning `nullptr` for an `ErrorExpr` or returning a null type when a type fails to be resolved, return a fresh type variable. This allows the constraint solver to continue further and produce more meaningful diagnostics.

Most importantly, it allows us to produce a solution where previously constraint generation for a syntactic element had failed, which is required to type check multi-statement closures in result builders inside the constraint system.
2022-07-20 09:46:12 +02:00
Doug Gregor
db14ab140f Sink concurrency constraint fix behavior logic into "attempt" functions.
This is a cleaner pattern for the solver, thanks Pavel!
2022-07-08 13:33:14 -07:00
Doug Gregor
8a8efcb663 Drop ConstraintFix::diagfixBehavior() in favor of public const fixBehavior. 2022-07-08 13:25:00 -07:00
Doug Gregor
7436fb365a Rename CSFix::affectsSolutionScore() to impact(). 2022-07-08 13:03:12 -07:00
Doug Gregor
de7b840661 Replace CSFix::canApplySolution() with isFatal(). 2022-07-08 13:03:12 -07:00
Doug Gregor
3368dd4b6b Make the error for missing existential erasure coercions configurable. 2022-07-08 12:25:09 -07:00
Doug Gregor
2e3aa67c02 [Constraint solver] Treat downgraded errors as "disfavored overloads".
This allows us to still maintain them in the score kind, but not treat
them as being as severe as an error requiring a fix.
2022-07-07 18:12:56 -07:00
Doug Gregor
c564698625 [Constraint solver] Improve modeling of fix behavior.
Rather than re-using `DiagnosticBehavior` to describe how a fix should
act, introduce `FixBehavior` to cover the differences between (e.g.)
always-as-awarning and downgrade-to-warning. While here, split the
`isWarning` predicate into two different predicates:

* `canApplySolution`: Whether we can still apply a solution when it
contains this particular fix.
* `affectsSolutionScore`: Whether

These two predicates are currently tied together, because that's the
existing behavior, but we don't necessarily want them to stay that way.
2022-07-07 12:17:11 -07:00
Doug Gregor
218a3f79e0 [Constraint solver] Downgrade/ignore concurrency issues more generally.
Instead of the `warning` Boolean threaded through the solver's
diagnostics, thread `DiagnosticBehavior` to be used as the behavior
limit. Use this for concurrency checking (specifically dropped
`@Sendable` and dropped global actors) so the solver gets more control
over these diagnostics.

This change restores the diagnostics to a usable state after the prior
change, which introduced extra noise. The only change from existing
beavior is that dropping a global actor from a function type is now
always a warning in Swift < 6. This is partly intentional, because
there are some places where dropping the global actor is well-formed.
2022-07-01 11:45:44 -07:00
Pavel Yaskevich
7ba07ae3ba Merge pull request #59210 from xedin/conflicting-patterns-in-case
[Diagnostics] Diagnose conflicting pattern variables
2022-06-14 11:30:34 -07:00
Luciano Almeida
c6f00fae98 [Sema] Allow TreatArrayLiteralAsDictionary fix to handle literals with more than one element 2022-06-05 22:36:35 -03:00
Pavel Yaskevich
f15a0b16cb [CSFix] Detect conflicting pattern variables
The fix indentifies the conflicting variables and the expected
"join" type e.g. `case .a(let x), .b(let x)` where `a(Int)` and
`b(String)`.
2022-06-03 16:31:27 -07:00
Pavel Yaskevich
773ea6b10c [TypeChecker] Require a coercion if result of protocol member access would loose information
Accessing members on the protocol could result in existential opening and subsequence
result erasure, which requires explicit coercion if there is any loss of generic requirements.
2022-05-25 16:07:06 -07:00
Pavel Yaskevich
fc1ed430b9 [CSFix] Implement missing existential coercion fix 2022-05-25 16:07:05 -07:00
Pavel Yaskevich
8306724d81 [CSFix] Add a skeleton fix to require explicit existential coercion 2022-05-25 16:07:05 -07:00