Commit Graph

87 Commits

Author SHA1 Message Date
Kathy Gray
e25cfc6d23 Expand support for PackExpansion type in requirements maching
Types where pack expansion required nested subsitution could cause the compiler to crash rather than properly expanding the pack. Both for populated types and infinityly expanding types which should generate an error.
This expands the support for these to generate more errors and populated types, and correspondingly expands the test suite
2025-10-10 17:46:22 +01: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
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
1b99dd2451 RequirementMachine: Tweak RewriteSystem::recordConflict() heuristic again 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
70c9f8a47e RequirementMachine: Leave behind conflicting requirements in the minimized signature
Requirement lowering only expects that it won't see two requirements
of the same kind (except for conformance requirements). So only mark
those as conflicting.

This addresses a crash-on-invalid and improves diagnostics for
move-only generics, because a conflict won't drop the copyability
of a generic parameter and expose a move-only-naive user to
confusing error messages.

Fixes #61031.
Fixes #63997.
Fixes rdar://problem/111991454.
2024-02-15 14:32:31 -05:00
Slava Pestov
747b060389 RequirementMachine: Correct desugaring of same-type requirements with pack expansion on both sides 2023-07-25 02:47:45 -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
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
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
4204e20508 RequirementMachine: Allow 'any C & P' to satisfy a superclass requirement 'C' if 'P' is an @objc protocol
The GenericSignatureBuilder did not actually allow this, but it's conflict
detection was imperfect so it did not flag the example in the radar;
variations on this code were rejected by the GenericSignatureBuilder.

Since the Requirement Machine finds all conflicts correctly, relax the
logic here to make this example work.

Fixes rdar://problem/91637621.
2022-04-12 16:43:56 -04:00
Slava Pestov
06b181a099 RequirementMachine: Don't record duplicate conflicts in PropertyMap::checkConcreteTypeRequirements() 2022-04-01 22:38:42 -04:00
Slava Pestov
a8190d81da RequirementMachine: Don't record duplicate superclass conflicts 2022-04-01 01:05:54 -04:00
Slava Pestov
d212041dfb RequirementMachine: Fold RewriteSystem::processConflicts() into recordConflict() and add debug output 2022-04-01 01:05:54 -04:00
Slava Pestov
a631d8aa3a RequirementMachine: Write some comments 2022-03-28 22:16:09 -04:00
Slava Pestov
a8a281d637 RequirementMachine: Use recordConflict() for superclass conflicts
Instead of calling markConflicting() directly, use the existing
recordConflict() utility.
2022-03-14 12:33:18 -04:00
Slava Pestov
a69ac78482 RequirementMachine: Rework PropertyMap::recordConflict() for GSB compatibility
We want to prefer explicit rules when an explicit rule and non-explicit
rule conflict. Since the explicit bit hasn't been computed yet when
building the property map, save conflicting rule pairs in a side table,
and then process them later in homotopy reduction.

The side table will also be useful for diagnostics later.
2022-02-17 19:40:58 -05:00
Slava Pestov
93727490df RequirementMachine: Remove old PropertyMap::unifyConcreteTypes() 2022-02-17 19:40:58 -05:00
Slava Pestov
b90dae1f15 RequirementMachine: Unify every pair of superclass requirements that apply to a term 2022-02-17 19:40:58 -05:00
Slava Pestov
2f16ca38e5 RequirementMachine: Unify every pair of concrete type rules that apply to a term
Instead of keeping track of the best one so far, and unifying subsequent rules
against it.

This allows us to record more identities, fixing a regression from an earlier
change where we were unable to eliminate an obviously-redundant rule.
2022-02-17 19:40:58 -05:00
Slava Pestov
991fe1dbd8 RequirementMachine: Preserve replacement paths for redundant rules 2022-02-16 16:28:08 -05:00
Slava Pestov
f32b545283 RequirementMachine: Move RewriteSystem::processTypeDifference() and friends from PropertyUnification.cpp to RewriteSystem.cpp 2022-02-15 04:02:46 -05:00
Slava Pestov
12ba9bf1ab RequirementMachine: Move processTypeDifference() method and friends from PropertyMap to RewriteSystem 2022-02-15 04:02:46 -05:00
Slava Pestov
c6119acb8f RequirementMachine: Generalize concrete unification a bit to allow sharing code with concrete simplification 2022-02-15 04:02:46 -05:00
Slava Pestov
e445335eb3 RequirementMachine: Record rewrite loops during superclass unification
This is the second half of rdar://problem/88134910.

Also addresses rdar://problem/25065503.
2022-02-09 22:44:06 -05:00
Slava Pestov
94b55bd408 RequirementMachine: Factor out PropertyMap::unifyConcreteTypes() from ::addConcreteTypeProperty() 2022-02-09 16:49:24 -05:00
Slava Pestov
868e48cb7a RequirementMachine: Mark rules as simplified in PropertyMap::addConcreteTypeProperty() 2022-02-07 08:20:59 -05:00
Slava Pestov
9e234a09c6 RequirementMachine: Record rewrite loop relating concrete type rules in processTypeDifference()
We can't actually rely on concretelySimplifyLeftHandSideSubstitutions()
to do this for us, because the less-simplified rule (the LHS rule)
might only apply to a suffix of the base term.
2022-02-07 08:20:59 -05:00
Slava Pestov
5bb80286e9 RequirementMachine: Factor out a utility for building a rewrite path unifying to concrete type rules 2022-02-07 08:20:59 -05:00
Slava Pestov
70876171e6 RequirementMachine: Build rewrite paths for concrete unification induced rules 2022-02-07 08:20:59 -05:00
Slava Pestov
9ee702026f RequirementMachine: Factor out TypeDifference::getOriginalSubstitution() 2022-02-07 08:20:59 -05:00
Slava Pestov
60db9174e6 RequirementMachine: Factor out PropertyMap::processTypeDifference() 2022-02-07 08:20:59 -05:00
Slava Pestov
00d226fd2f RequirementMachine: Store the base term in the TypeDifference 2022-02-07 08:20:59 -05:00
Slava Pestov
b0dd114fdd RequirementMachine: Add a FIXME comment 2022-02-07 08:20:59 -05:00
Slava Pestov
d8aa79c5e5 RequirementMachine: Rename RewriteStep::AdjustConcreteType to ::PrefixSubstitutions 2022-02-07 08:20:58 -05:00
Slava Pestov
73296edc63 RequirementMachine: Less indirect TypeDifference representation 2022-02-07 08:20:58 -05:00
Slava Pestov
e19ee4d1a1 RequirementMachine: Refactor PropertyMap::addConcreteTypeProperty() to use computeTypeDifference()
This doesn't record rewrite loops from most concrete unifications just yet,
only handling a case where two concrete types were identical except for an
adjustment.
2022-02-07 08:20:58 -05:00
Slava Pestov
0c777e7534 RequirementMachine: Split up PropertyMap::addProperty() 2022-02-07 08:20:58 -05:00
Slava Pestov
e12cdd3773 RequirementMachine: Split off nested type concretization from PropertyUnification.cpp to ConcreteTypeWitness.cpp 2022-02-04 22:47:49 -05:00
Slava Pestov
4f3d05f502 RequirementMachine: Remove Symbol::getSuperclass() 2022-02-04 22:47:19 -05:00
Slava Pestov
eb9f12109e RequirementMachine: Conditional requirement inference
If a type parameter is subject to both a conformance requirement
and a concrete type requirement, the concrete type might conform
conditionally.

In this case, introduce new requirements to satisfy the conditional
conformance.

Since this can add new hitherto-unseen protocols to the rewrite
system, restrict this feature to top-level generic signatures, and
not protocol requirement signatures. Allowing this to occur in
protocol requirement signatures would change the connectivity of
the protocol dependency graph (and hence the connected components)
during completion, which would be a major complication in the
design. The GSB already enforces this restriction.

I changed the existing conditional_requirement_inference.swift test
to run with -requirement-machine-inferred-signatures=verify. Since
one of the test cases there triggers an unrelated bug in the
Requirement Machine, I split it off into a new file named
conditional_requirement_inference_2.swift which still runs with
the GSB. Once the bug is fixed I'll merge the files again.
2022-01-25 00:35:16 -05:00
Slava Pestov
75dfab00b9 RequirementMachine: Eliminate layout requirement implied by concrete type requirement
A type parameter subject to an AnyObject requirement might also be subject
to a concrete type requirement. There are two cases to handle here:

- If the concrete type is a class, the layout requirement is redundant.
- If the concrete type is not a class, we have a conflict.

There is an existing test that's good enough; I just changed it to
run with -requirement-machine-inferred-signatures=verify.
2022-01-25 00:35:11 -05:00
Slava Pestov
41e3292015 RequirementMachine: Remove 'induced rules' mechanism from the property map 2022-01-25 00:35:11 -05:00
Slava Pestov
0b3d6ea028 RequirementMachine: Property map adds new rules directly 2022-01-25 00:35:11 -05:00
Slava Pestov
c46c7773ed RequirementMachine: Rename remapConcreteSubstitutionSchema() to getRelativeSubstitutionSchemaFromType() 2022-01-25 00:32:25 -05:00
Slava Pestov
01ba790ccf RequirementMachine: Move remapConcreteSubstitutionSchema() to RewriteContext 2022-01-25 00:32:25 -05:00
Slava Pestov
bdbf50e1e3 RequirementMachine: Replace RewriteStep::SameTypeWitness with a relation 2022-01-13 19:14:52 -05:00