Commit Graph

24 Commits

Author SHA1 Message Date
Kathy Gray
fcb7d76e74 RequirementMachine: Adding shape abstractions
Adding abstractions to check terms for shape symbol and remove the shape
symbol from the end of the sequence of symbols, rather than manually
manipulating the end() sequence externally.
2025-10-31 17:29:45 +00:00
Slava Pestov
244d2afea3 RequirementMachine: New way of propagating failure when building rewrite system for protocol
If we failed to construct a rewrite system for a protocol, either because
the Knuth-Bendix algorithm failed or because of a request cycle while
resolving requirements, we would end up in a situation where the resulting
rewrite system didn't include all conformance requirements and associated
types, so name lookup would find declarations whose interface types are
not valid type parameters.

Fix this by propagating failure better and just doing nothing in
getReducedTypeParameter().

Fixes rdar://147277543.
2025-10-04 09:17:46 -04:00
Slava Pestov
fbe3d71b19 RequirementMachine: Small cleanup 2024-09-14 23:33:11 -04:00
Sima Nerush
1ba38c54f2 [Requirement Machine] When forming requirements from same-element rewrite rules, swap the sides depending on which one is longer once the [element] symbol is dropped.
This change fixes the "out-of-order" type parameters error in `GenericSignature::verify`
2024-07-15 10:19:32 -07:00
Holly Borla
2ea4586580 [Requirement Machine] Implement same-element requirements. 2024-07-15 10:19:32 -07:00
Slava Pestov
273c4b2b1a RequirementMachine: Convert to new assertions 2024-06-22 08:53:22 -04:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Slava Pestov
cfa557e5d1 RequirementMachine: Refactor RequirementBuilder a bit 2024-02-29 18:13:28 -05: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
1dc4c4699f RequirementMachine: Fix warning in noassert build 2023-08-15 13:51:27 -04:00
Slava Pestov
8afff61699 AST: Replace TypeArrayView<GenericTypeParamType> with ArrayRef<GenericTypeParamType *>
This basically undoes 3da6fe9c0d, which in hindsight was wrong.

There were no other usages of TypeArrayView anywhere else except for
GenericSignature::getGenericParams(), and it was almost never what
you want, so callers had to convert back and forth to an ArrayRef.
Remove it.
2023-06-29 19:23:44 -04: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
Slava Pestov
d4136e981b RequirementMachine: Fix unused variable warning 2022-10-16 21:37:25 -04:00
Holly Borla
313138c7db [NFC][RequirementMachine] Minor syntax change for MutableTerm initialization. 2022-10-06 20:48:40 -07:00
Holly Borla
38a2c8218b [Requirement] Rename RequirementKind::SameCount to SameShape. 2022-10-06 20:48:40 -07:00
Holly Borla
60f80006fc [RequirementMachine] Generalize connected components to process same
shape requirements.
2022-10-06 20:38:31 -07:00
Holly Borla
f4bfce6448 [RequirementMachine] Map same-shape requriements to rewrite rules.
A same-shape requirement 'length(T...) == length(U...)' becomes a rewrite
rule 'T.[shape] => U.[shape]'. Reduced shape rules will drop the [shape]
term from each side of the rule, and create a same-shape requirement
between the two type parameter packs.
2022-10-06 20:38:31 -07:00
Holly Borla
0f13eda26c [RequirementMachine] Add a new symbol kind for the shape of a parameter
pack.
2022-10-06 20:38:30 -07:00
Slava Pestov
42407bba3b RequirementMachine: Convert recursive requirements into ErrorTypes 2022-08-11 14:10:01 -04:00
Slava Pestov
3432a1f20c RequirementMachine: Don't filter out ErrorType as aggressively 2022-08-11 14:10:01 -04:00
Slava Pestov
ad2f73af44 RequirementMachine: More comments 2022-03-29 12:10:33 -04:00
Slava Pestov
05aeeff386 RequirementMachine: Reconstitute sugar in trivial cases
The Requirement Machine operates on canonical types internally and erases
sugared types appearing in generic requirements as a result.

For trivial cases like Array<T> vs [T], we can use the existing
TypeBase::reconstituteSugar() utility to produce a more aesthetically-pleasing
generic signature.
2022-03-14 12:33:18 -04:00
Slava Pestov
3576318fc7 RequirementMachine: Refactor construction of requirements from rules
The final step in minimization is building Requirements and
ProtocolTypeAliases from the minimal Rules in the RewriteSystem.

Move this to a new file and refactor it a bit to handle
Requirements and ProtocolTypeAliases more consistently.
2022-03-14 12:33:18 -04:00