Commit Graph

2553 Commits

Author SHA1 Message Date
Pavel Yaskevich
b9b21fc597 [CSSimplify] Detect and diagnose attempts to specialize types with invalid number of arguments 2023-06-27 17:24:39 -07:00
Pavel Yaskevich
cd057bba27 [CSFix] Add a fix to detect type specialization arity mismatches
The situations where number of parameters and arguments didn't match.
2023-06-27 17:24:39 -07:00
Pavel Yaskevich
2bbda09043 [CSSimplify] Detect and diagnose attempts to specialize non-generic types/aliases 2023-06-27 17:24:38 -07:00
Pavel Yaskevich
ab2f47b92f [CSFix] Add a fix to detect invalid specialization of non-generic types 2023-06-27 17:24:38 -07:00
Pavel Yaskevich
42f80fbe43 [CSSimplify] Teach specialization constraint to look through non-generic typealiases
If type alias declaration doesn't add new generic parameters
refer to its underlying type to find them.
2023-06-27 17:24:20 -07:00
Evan Wilde
250082df25 [NFC] Reformat all the LLVMs
Reformatting everything now that we have `llvm` namespaces. I've
separated this from the main commit to help manage merge-conflicts and
for making it a bit easier to read the mega-patch.
2023-06-27 09:03:52 -07:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
swift-ci
44ab03a90b Merge pull request #66871 from kavon/generics-error-noncopyable
Be more specific than "noncopyable type T can't be used with generics yet"
2023-06-26 18:32:26 -07:00
Kavon Farvardin
c40985dfb3 describe how generic parameters implicitly require Copyable 2023-06-26 16:55:06 -07:00
Pavel Yaskevich
3122440842 Merge pull request #66766 from amritpan/key-path-backward-diag
[ConstraintSystem] Fix keyPath diagnostic error for value convert to contextual types
2023-06-26 08:52:18 -07:00
Kavon Farvardin
66bf3c03fc describe illegal casts to existentials 2023-06-23 20:15:01 -07:00
Amritpan Kaur
dda0f50034 Switch types for keypath diagnostics where
where contextual type and value types capabilities do not match.
2023-06-21 20:49:44 -07:00
Pavel Yaskevich
5e30445495 [CSSimplify] Add special handling if specialized type comes from TypeExpr
Add a special case for `TypeExpr` due to i.e. context specialization,
in such cases there is nothing for the solver to "open" so we need
to form opened type map manually.

Resolves: rdar://111059036
2023-06-20 21:58:04 -07:00
Pavel Yaskevich
199616a49b Merge pull request #66708 from xedin/generalize-default-closure-type-constraint
[ConstraintSystem] Use fallback type constraint to default pack expansion
2023-06-19 00:47:18 -07:00
Pavel Yaskevich
2ee646f47b [ConstraintSystem] NFC: Generalize DefaultClosureType constraint
This constraint is useful in more places than closures because
it gives a way to provide a "fallback type" without it having
effect on inference.
2023-06-16 11:15:15 -07:00
Hamish Knight
f10d0df62f Merge pull request #66593 from hamishknight/pattern-error 2023-06-16 18:06:47 +01:00
Holly Borla
612a2e79fa Merge pull request #66657 from hborla/variadic-macro-specialization
[ConstraintSystem] Use an explicit generic argument constraint for `UnresolvedSpecializeExpr`.
2023-06-15 09:35:25 -07:00
Holly Borla
d357315661 [ConstraintSystem] Handle typealiases in ExplicitGenericArguments
constraint simplification.
2023-06-15 00:27:18 -07:00
Holly Borla
eb858d938e [ConstraintSystem] Use an explicit generic argument constraint for
UnresolvedSpecializeExpr.

The eager generic argument matching code in CSGen for unresolved
specializations was incorrect because it didn't account for parameter
packs. Fortunately, a constraint to delay explicit generic argument
matching already exists for macros. Use it here.
2023-06-14 18:24:58 -07:00
Pavel Yaskevich
2b8a39724c Merge pull request #66513 from xedin/init-accessor-diagnostics
[Sema/SIL] Improve diagnostics related to init accessors
2023-06-14 09:57:08 -07:00
Pavel Yaskevich
3c924be2a0 [CSFix] InitAccessors: Add a fix that tracks invalid member references within init accessors 2023-06-13 10:58:50 -07:00
Pavel Yaskevich
935142ff49 [ConstraintSystem] InitAccessors: Detect invalid references to members within init accessors
Only properties that are listed in 'initializes' and 'accesses'
attributes could be referenced within init accessor. Detect any
and all invalid member references in the solver.
2023-06-13 10:58:50 -07:00
Hamish Knight
c6dd3ad839 [CS] Diagnose UnresolvedPatternExprs as part of constraint solving
Instead of diagnosing in CSApply, let's create a
fix and diagnose in the solver instead.
Additionally, make sure we assign ErrorTypes to
any VarDecls bound by the invalid pattern, which
fixes a crash.

rdar://110638279
2023-06-13 12:14:25 +01:00
Holly Borla
cd752cca22 [NameLookup] Plumb source location arguments through all name lookup APIs.
This source location will be used to determine whether to add a name lookup
option to exclude macro expansions when the name lookup request is constructed.
Currently, the source location argument is unused.
2023-06-11 23:09:47 -07:00
swift-ci
c74fd074c6 Merge pull request #64280 from hamishknight/platypus
[CS] Allow ExprPatterns to be type-checked in the solver
2023-06-06 20:21:45 -07:00
Hamish Knight
b43d351197 [CS] Improve diagnostics a bit for pattern mismatch
There's still plenty of more work to do here for
pattern diagnostics, including introducing a
bunch of new locator elements, and handling things
like argument list mismatches. This at least lets
us fall back to a generic mismatch diagnostic.
2023-06-07 00:35:02 +01:00
Hamish Knight
23dbf6f106 [CS] Reverse the type order in a couple of pattern equality constraints
Order them such that if they were changed to
conversions, they would be sound. This shouldn't
make a difference, but unfortunately it turns out
pattern equality is not symmetric. As such, tweak
the pattern equality logic to account for the
reversed types. This allows us to remove a special
case from function matching.
2023-06-07 00:35:00 +01:00
Hamish Knight
f3b16fd7ad [CS] Fix a couple of constraints in getTypeForPattern
The TypedPattern and IsPattern constraints were
incorrectly written, with conversions propagating
out of the patterns, when really conversions
ought to propagate into patterns. In any case, it
seems like we really want equality here. Fix the
constraints to use equality, and have the cast
constraint operate on the external pattern type
instead of the subpattern type.
2023-06-07 00:35:00 +01:00
Slava Pestov
6eb112e3b6 AST: Factor out duplication between PackTypeParameterCollector and PackTypeVariableCollector 2023-06-06 14:18:37 -04:00
Luciano Almeida
1d90de16c7 Merge pull request #66208 from LucianoPAlmeida/diag-ternary
[Sema] Increase impact of ternary then branch aiming better diagnostics
2023-05-31 01:24:43 -03:00
Luciano Almeida
fef908efac [Sema] Increase impact of ternary then branch aiming better diagnostics 2023-05-30 20:55:50 -03:00
Sophia Poirier
93864f6c15 [Variadic Generics] drop requirement of .element for tuple expansion rdar://107160966 2023-05-30 11:37:55 -04:00
Slava Pestov
b2bc2c72ec AST: Introduce PackElementType 2023-05-25 11:17:30 -04:00
Pavel Yaskevich
acf64e3c15 Merge pull request #66080 from xedin/rdar-109586440
[ConstraintSystem] Some more variadic generic fixes
2023-05-24 14:49:09 -07:00
Pavel Yaskevich
fe6cfe2d85 [CSDiagnostics] Diagnose conformance failures related to pack expansion patterns 2023-05-23 09:47:48 -07:00
Pavel Yaskevich
3b1f392d0a Merge pull request #65785 from angela-laar/fix-covariant-erasure-for-constrained-existentials
Fix covariant erasure for constrained existentials
2023-05-18 16:58:45 -07:00
Pavel Yaskevich
a987861d1c Merge pull request #65806 from xedin/rdar-108977234
[CSSimplify] Detect and diagnose conformance failures related to AnyHashable conversion
2023-05-16 09:56:41 -07:00
Pavel Yaskevich
fdf6d62ece Merge pull request #65830 from xedin/rdar-108904190
[CSSimplify] Allow converting pack expansion types and tuples with pack expansions to Void for closure result
2023-05-16 09:56:27 -07:00
Pavel Yaskevich
96cbc01822 Merge pull request #65861 from xedin/rdar-109160060
[CSSimplify] Allow conversions between tuples with pack expansions and `Any`
2023-05-15 16:20:50 -07:00
Pavel Yaskevich
dc4ee4b61a [CSSimplify] Allow converting tuple with pack expansions to Void for closure result
Maintains existing rule where single-expression closure is allowed
to convert to contextual function type with `Void` result.
2023-05-15 16:20:01 -07:00
Pavel Yaskevich
effa261266 [CSSimplify] Move invalid pack expansion check to enable closure result conversion
Checking for pack expansion type mismatch impedes non-Void-to-Void
conversion allowed for single-expression closures.

Resolves: rdar://108904190
2023-05-15 16:19:59 -07:00
Pavel Yaskevich
406b7a62c7 Merge pull request #65718 from xedin/diagnose-missing-each-in-expr-context
[ConstraintSystem] Detect and diagnose missing 'each' and provide a fix-it
2023-05-15 16:18:55 -07:00
Angela Laar
5c818b3fd4 [Constraint System] Fix covariant erasure for constrained existentials
Constrained existentials should be type erased to an upper bound that is dependent on other type parameters.
2023-05-15 16:17:59 -07:00
Pavel Yaskevich
181d2d1371 [CSSimplify] Allow conversions between tuples with pack expansions and Any
Don't attempt to wrap `Any` into a single-element tuple to match
against a tuple with pack expansions, this conversion would be
handled by existential promotion if it's allowed, otherwise it
would produce an error.

Resolves: rdar://109160060
2023-05-11 10:05:15 -07:00
Kavon Farvardin
3e4bc82aa8 rename _forget to discard; deprecate _forget
SE-390 concluded with choosing the keyword discard rather than forget for
the statement that disables the deinit of a noncopyable type. This commit
adds parsing support for `discard self` and adds a deprecation warning for
`_forget self`.

rdar://108859077
2023-05-08 21:42:19 -07:00
Pavel Yaskevich
5f8e3eb6f6 [CSSimplify] Detect and diagnose conformance failures related to AnyHashable conversion
Failure of an argument to AnyHashable parameter to conform to Hashable
protocol should be detected in `simplifyConformsToConstraint` and fixed
there.

Doing so requires impact assessment adjustment because regular conformance
requirements have default impact of 1, this is going to have argument
impact of 2 not avoid clashing with other failures.
2023-05-08 16:16:30 -07:00
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
Kavon Farvardin
f667c867c9 Merge pull request #65673 from kavon/copyable-constraint-performance
Fix a performance issue when answering "is this tuple Copyable"?
2023-05-05 11:14:44 -07:00
Kavon Farvardin
f15dadeee7 Merge pull request #65668 from kavon/noncopyable-metatypes-redo
Noncopyable metatypes redo
2023-05-04 16:42:06 -07:00
Kavon Farvardin
ce04b84489 Fix a performance issue when answering "is this tuple Copyable"?
If we don't split up the tuple into individual constraints,
we end up spending more time querying whether a tuple is
Copyable in `lookupConformance`, because it will naively
check the types of all elements of the tuple recursively
with `lookupConformance`.

This is inefficient because if we know some of the elements
of the tuple are fixed types, we don't need to keep checking
those again. For example, if we have `($T, Int, $U)`, and
then try a binding for `$T`, we might ask again if the whole
tuple conforms. Leading to `lookupConformance` to check
whether `Int` (and all other elements of the tuple) conforms
to Copyable, when we either already know that, or can't
answer it yet because it's still a type variable.

By splitting up a Copyable constraint on a tuple into
invidivual  constraints on each of its type elements,
we can avoid this redundant work by `lookupConformance`.

While today we could short-cut this even further to say
that _all_ tuples are Copyable, since we emit an error if
a noncopyable type appears in one, that won't be true in
the near future. This is the nicer solution we'll want to
keep around long-term.

After discussing this with Pavel, we don't think there's a
good way to add a regression test for this, because the
performance issue primarily comes up in specific example
programs that aren't amenable to scale tests.

resolves rdar://107536402
2023-05-04 14:53:48 -07:00