Commit Graph

63 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
Hamish Knight
edca7c85ad Adopt ABORT throughout the compiler
Convert a bunch of places where we're dumping to stderr and calling
`abort` over to using `ABORT` such that the message gets printed to
the pretty stack trace. This ensures it gets picked up by
CrashReporter.
2025-05-19 20:55:01 +01:00
Slava Pestov
91503710bc AST: Remove origType parameter from ProtocolConformanceRef::getTypeWitness() 2025-04-03 17:35:32 -04:00
Slava Pestov
afbd81a599 AST/Sema: Use ProtocolConformanceRef::getTypeWitness() 2024-09-19 14:18:33 -04:00
Slava Pestov
da0130d297 AST: Replace calls to substBaseType() with getAssociatedType() 2024-09-19 14:18:32 -04:00
Slava Pestov
08bb0017f5 AST: Add GenericSignatureImpl::getReducedTypeParameter()
This avoids a bit of indirection when the input is already known to be
a type parameter, and not just a type that contains type parameters.
2024-09-13 15:19:48 -04:00
Slava Pestov
be9d999e64 AST: Simplify GenericSignature::getLocalRequirements() 2024-09-13 15:19:48 -04:00
Holly Borla
eabaed8a62 [Requirement Machine] Use element symbols for concrete same-element requirements. 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
1901862afc AST: Remove LookUpConformanceInSignature 2024-07-06 12:05:46 -04: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
04d3d43c4a RequirementMachine: Better assertion when root type parameter is invalid
Previously getReducedType() would dump debug info if we had an invalid
dependent member type, but an invalid root type parameter would cause
a segfault. Fix this.
2024-05-02 13:40:43 -04:00
Slava Pestov
5f2c49bd0e RequirementMachine: Canonicalize protocol list in RequirementMachine::getLocalRequirements() 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
Hamish Knight
05615fa0e4 NFC: Rename TypeWalker's SkipChildren to SkipNode
For consistency with ASTWalker.
2024-02-05 15:27:25 +00:00
Slava Pestov
5dd8307e60 AST: Pass SubstOptions to DependentMemberType::substBaseType() 2023-12-07 18:00:50 -05:00
Slava Pestov
7dea282810 RequirementMachine: Better validation in RequirementMachine::getReducedShapeTerm() 2023-07-03 15:41:09 -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
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
a5cf7d3298 RequirementMachine: The reduced type of a PackExpansionType has a reduced *shape* for the count type
I don't have a test case for this but it was bound to
come up eventually.
2023-03-15 23:04:50 -04:00
Slava Pestov
75d25c6175 RequirementMachine: Ensure that isValidTypeParameter() checks the generic parameter type too 2023-03-13 19:04:15 -04:00
Holly Borla
cf38d55e3a [AST] Plumb reduced shape types through local requirements into pack archetypes. 2022-10-23 11:42:46 -07:00
Holly Borla
c4b946195e [AST] Replace the "type sequence" terminology with "parameter pack". 2022-10-10 16:28:13 -07:00
Holly Borla
be619c62c9 [RequirementMachine] Add a generic signature query that determines whether
two type parameter packs have the same shape.
2022-10-07 10:35:49 -07:00
Holly Borla
fab5b7d364 [RequirementMachine] Add a generic signature query that returns the
reduced shape of a given type parameter pack.
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
4a041c57d0 AST: Rename ConformanceAccessPath to ConformancePath 2022-08-09 13:34:27 -04:00
Slava Pestov
9d96ed940f AST: Rename 'canonical wrt. generic signature' to 'reduced'
We had two notions of canonical types, one is the structural property
where it doesn't contain sugared types, the other one where it does
not contain reducible type parameters with respect to a generic
signature.

Rename the second one to a 'reduced type'.
2022-08-09 12:46:31 -04:00
Slava Pestov
ad2f73af44 RequirementMachine: More comments 2022-03-29 12:10:33 -04:00
Slava Pestov
3cfbe037ee RequirementMachine: Simplify getTypeForSymbolRange() a bit 2022-03-29 00:43:41 -04:00
Slava Pestov
ff40f109ca RequirementMachine: Allow RequirementMachine::isConcreteType() and ::getCanonicalTypeInContext() to be used with protocol connected components 2022-03-22 15:02:06 -04:00
Slava Pestov
bf779d31a0 RequirementMachine: Allow query operations to be invoked on requirement machine instances for fresh signatures 2022-03-22 15:02:06 -04:00
Slava Pestov
b0a4efba54 RequirementMachine: Fix lookupConcreteNestedType() to cope with opaque archetypes 2022-03-17 17:45:52 -04:00
Slava Pestov
d90e8122aa RequirementMachine: Factor out duplicated lookupConcreteNestedType() utility 2022-03-16 13:26:37 -04:00
Slava Pestov
54c83ead9e RequirementMachine: Make some low-cost assertions unconditional 2022-03-11 17:28:01 -05:00
Slava Pestov
e717330d3b RequirementMachine: Minor optimization 2022-03-11 17:28:01 -05:00
Slava Pestov
ef1292e1ce RequirementMachine: Don't filter out redundant superclass conformances when building archetypes
This was a hack to maintain exact compatibility with the GSB's
results when constructing archetypes, but it no longer appears
to be necessary.
2022-02-17 19:40:58 -05:00
Slava Pestov
a1c03db381 AST: Generalize ProtocolDecl::getRequirementSignature() to a new RequirementSignature type
The RequirementSignature generalizes the old ArrayRef<Requirement>
which stores the minimal requirements that a conforming type's
witnesses must satisfy, to also record the protocol typealiases
defined in the protocol.
2022-02-13 00:24:23 -05:00
Slava Pestov
0d0bcb2ff1 RequirementMachine: Simplify the Symbol API for removal of merged associated types 2022-02-07 18:57:45 -05:00
Slava Pestov
fa30159130 RequirementMachine: Move term to type methods from RewriteContext to PropertyMap 2022-01-20 00:18:47 -05:00
Slava Pestov
0ffd11c558 RequirementMachine: New GenericSignature::isValidTypeInContext() query 2022-01-14 21:25:32 -08:00
Slava Pestov
c79a89b826 RequirementMachine: Improved isCanonicalTypeInContext()
We would bail out early if there was no property map entry for this key.
But this means if a term without properties was non-canonical, this
method would still return false.

On the other hand, it is possible for a DependentMemberType to be
canonical, even if its parent is not, in the case where the parent
is fixed to a concrete type.

To handle this properly, change the type walk to use a TypeWalker
directly instead of findIf(); this allows us to return
Action::SkipChildren upon encountering a DependentMemberType.

The primary use of isCanonicalTypeInContext() was from inside
GenericSignature::verify(). So the assertion there will become
stricter.
2021-12-16 21:41:38 -05:00
Slava Pestov
36a7c4c032 RequirementMachine: Move some code around 2021-12-07 15:31:47 -05:00
Slava Pestov
d19b15b66c RequirementMachine: Introduce Symbol::Kind::ConcreteConformance 2021-12-06 23:04:46 -05:00
Slava Pestov
0571b65cb8 RequirementMachine: Move protocol linear order from ProtocolGraph to RewriteContext 2021-10-21 19:00:10 -04:00
Slava Pestov
17e2d6a290 RequirementMachine: Avoid term->type->term round-trip in getConformanceAccessPath()
We would skip recording a conformance access path if the subject
type canonicalized to a concrete type, but this was incorrect.

The correct formulation is to use the _canonical anchor_ and not
the canonical type as the caching key; that is, we always want it
to be a type parameter, even if it is fixed to a concrete type,
because type parameters fixed to concrete types can appear in
the middle of conformance access paths, as the example in the
radar demonstrates.

Fixes rdar://problem/83687967.
2021-10-05 15:06:42 -04:00
Slava Pestov
871b4d143a RequirementMachine: Cosmetic fix for conformance path assert output 2021-10-01 00:57:35 -04:00
Slava Pestov
3f8ef30185 RequirementMachine: Preserve sugared generic params in getSuperclassBound() and getConcreteType()
This was manifesting as module interfaces printing generic parameters
as `τ_0_0` in some cases.

Note that the GSB has the same bug, so this test case will fail with
-requirement-machine=off. I don't plan on fixing the bug in the GSB
unless we need to.

Fixes rdar://problem/78977127.
2021-09-29 14:39:38 -04:00