Commit Graph

23 Commits

Author SHA1 Message Date
Alejandro Alonso
6f83e3c28f Fix type parsing when preceeded by '-' 2024-09-11 10:28:44 -07:00
Alejandro Alonso
7cd424812f Move some value checking to desugaring 2024-09-04 15:13:46 -07:00
Alejandro Alonso
f4f60f4344 Remove Value requirement Add GenericTypeParamKind 2024-09-04 15:13:43 -07:00
Alejandro Alonso
3e9c4633ca Add some new diagnostics and tests 2024-09-04 15:13:27 -07:00
Slava Pestov
273c4b2b1a RequirementMachine: Convert to new assertions 2024-06-22 08:53:22 -04:00
Kavon Farvardin
30983530b6 NCGenerics: introduce SuppressedAssociatedTypes
The model for associated types hasn't been fully worked-out for
noncopyable generics, but there is some support already that is being
used by the stdlib for an internal-only (and rather cursed) protocol
`_Pointer` to support `UnsafePointer`, etc.

This patch gates the existing experimental support for associated types
behind a feature flag. This flag doesn't emit feature-guards in
interfaces, since support for it is tied closely to NoncopyableGenerics
and has been there from its early days.
2024-04-02 16:53:36 -07:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Slava Pestov
dcca5ced0f RequirementMachine: Remove -warn-redundant-requirements flag 2024-02-02 14:57:19 -05:00
Kavon Farvardin
63b3e7624d [NCGenerics] fold InverseType into PCT
We already need to track the inverses separate from the members in a
ProtocolCompositionType, since inverses aren't real types. Thus, the
only purpose being served by InverseType is to be eliminated by
RequirementLowering when it appears in a conformance requirement.

Instead, we introduce separate type InverseRequirement just to keep
track of which inverses we encounter to facilitate cancelling-out
defaults and ensuring that the inverses are respected after running
the RequirementMachine.
2023-12-07 22:14:23 -08:00
Kavon Farvardin
2e66b69953 [Sema] prevent inverse-constraints on outer params
Since there is no propagation of inverse constraints in the requirement
machine, we need to fully desugar these requirements at the point of
defining a generic parameter. That desugaring involves determining which
default conformance requirements need to be applied to a generic
parameter, accounting for inverses.

But, nested generic contexts in scope of those expanded generic
parameters can still write constraints on that outer parameter. For
example, this method's where clause can have its own constraints on `T`:

```
struct S<T> {
 func f() where T: ~Copyable {}
}
```

But, the generic signature of `S` already has a `T: Copyable` that was
expanded. The method `f` will always see a `T` that conforms to
`Copyable`, so it's impossible for `f` to claim that it applies for
`T`'s that lack Copyable.

Put another way, it's not valid for this method `f`, whose generic
signature is based on its parent's `S`, to weaken or remove requirements
 from parent's signature. Only positive requirements can be
 added to them.
2023-10-27 15:01:10 -07:00
Kavon Farvardin
bb341e7928 [NoncopyableGenerics] fix isNoncopyable for packs
We're not yet going to allow noncopyable types into packs, so this
change prevents the use of `~Copyable` on an `each T` generic parameter.
 It also fixes how we query for whether a `repeat X` parameter is
 copyable.
2023-10-27 15:01:10 -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
Holly Borla
74cc62735b [RequirementMachine] Diagnose same-element requirements.
The rewrite rules are not quite right yet for same-element requirements, so
let's ban them for now.
2023-03-06 21:32:30 -08:00
Holly Borla
38a2c8218b [Requirement] Rename RequirementKind::SameCount to SameShape. 2022-10-06 20:48:40 -07:00
Holly Borla
ae5ebba2c1 [RequirementMachine] Add same-length requirement inference for pack
expansion types.
2022-10-06 20:38:30 -07:00
Slava Pestov
9339443e79 RequirementMachine: Diagnose recursive requirements
Note the test cases in abstract_type_witnesses used to pass but are now
rejected. This is fine, because doing anything more complicated used to
crash, and the GSB would crash or misbehave with these examples.
2022-08-11 14:12:06 -04:00
Slava Pestov
f901cc72b4 RequirementMachine: Move diagnostics code into a new Diagnostics.cpp 2022-05-10 01:49:56 -04:00
Holly Borla
a4230a6061 [RequirementMachine] Simplify computing and emitting conflict diagnostics.
Instead of computing different combinations of conflicting requirement kinds,
emit the same error message for all of them.
2022-03-29 18:27:45 -07:00
Holly Borla
964c11a4d0 [RequirementMachine] Consolidate the various RequirementError::Kind cases
that represent conflict diagnostics.
2022-03-29 18:27:45 -07:00
Holly Borla
caee699560 [RequirementMachine] Mention the type parameter that is the subject of
two conflicting requirements in diagnostics where possible.
2022-03-29 18:27:45 -07:00
Holly Borla
e512e7a824 [RequirementMachine] Add a RequirementError for diagnosing a conflicting
same-type requirement.
2022-03-29 18:23:53 -07:00
Holly Borla
a992917f1c [NFC][RequirementMachine] Rename some of the RequirementError::Kind cases,
add documentation for each case, and move RequirementError to
lib/AST/RequirementMachine/Diagnostics.h.
2022-02-16 13:11:57 -08:00