Commit Graph

873 Commits

Author SHA1 Message Date
Slava Pestov
40b585f441 RequirementMachine: Use RewriteStep::AbstractTypeWitness in nested type concretization 2021-12-17 10:04:52 -05:00
Slava Pestov
2bca132380 RequirementMachine: Introduce RewriteStep::AbstractTypeWitness 2021-12-17 10:04:52 -05:00
Slava Pestov
4c83fe851d RequirementMachine: Generalize ConcreteTypeWitness to TypeWitness 2021-12-17 10:04:52 -05:00
Slava Pestov
b1a3d2c6af RequirementMachine: Preserve rewrite path for simplifying substitutions 2021-12-17 10:04:52 -05:00
Slava Pestov
317743a487 RequirementMachine: Rename GeneratingConformances => MinimalConformances 2021-12-17 10:04:52 -05:00
Slava Pestov
d72500db0d RequirementMachine: Cache result of RewriteLoop::findRulesAppearingOnceInEmptyContext() 2021-12-17 10:04:51 -05:00
Slava Pestov
4cc7589f7b RequirementMachine: Symbols and Terms should have PointerLikeTypeTraits 2021-12-17 10:04:51 -05:00
Slava Pestov
22816b0b41 RequirementMachine: Skip more work in concretizeNestedTypesFromConcreteParent() 2021-12-17 10:04:51 -05: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
1747951eb7 RequirementMachine: Drop requirements containing ErrorTypes 2021-12-14 02:17:07 -05:00
Slava Pestov
71194c2c46 RequirementMachine: Use RewriteStep::SameTypeWitness in nested type concretization 2021-12-14 02:16:47 -05:00
Slava Pestov
7708c75184 RequirementMachine: Introduce RewriteStep::SameTypeWitness 2021-12-14 02:16:46 -05:00
Slava Pestov
5a2b19393c RequirementMachine: Refactor PropertyMap::computeConstraintTermForTypeWitness() 2021-12-14 02:16:46 -05:00
Slava Pestov
8e3f35075f RequirementMachine: Make the rewrite path optional with RewriteSystem::simplifySubstitution() 2021-12-14 02:16:46 -05:00
Slava Pestov
17664c0c59 RequirementMachine: Use RewriteStep::ConcreteTypeWitness in nested type concretization 2021-12-14 02:16:46 -05:00
Slava Pestov
654953cbac RequirementMachine: Introduce RewriteStep::ConcreteTypeWitness 2021-12-14 02:16:46 -05:00
Slava Pestov
c6441c0d89 RequirementMachine: Add machinery for recording concrete type witnesses 2021-12-14 02:16:46 -05:00
Slava Pestov
56fb3cc937 RequirementMachine: Refactor nested type concretization a bit 2021-12-13 18:48:48 -05:00
Slava Pestov
d25b0db75c RequirementMachine: Fold recordConcreteConformanceRules() into concretizeNestedTypesFromConcreteParent() 2021-12-13 18:48:48 -05:00
Slava Pestov
d07812e479 RequirementMachine: Factor out PropertyMap::concretizeTypeWitnessInConformance() 2021-12-13 18:48:48 -05:00
Slava Pestov
7a56ab8c18 RequirementMachine: Mark conflicting rules
This isn't quite right, because we really want the longer (more
specific) of the two rules to be conflicting, not the most-recently
added rule.
2021-12-13 18:48:23 -05:00
Slava Pestov
5ac43b14d2 RequirementMachine: Fully canonicalize substitutions in concrete type rules
Previously we did this when adding new concrete type rules,
but we don't have a complete rewrite system at that point yet,
so there was no guarantee concrete substitution terms would
be canonical.

Now, perform simplification in a post-pass after completion,
at the same time as simplifying rule right hand sides.

Rewrite loops are recorded relating the original rule with the
simplified substitutions.
2021-12-13 18:48:23 -05:00
Slava Pestov
e86fe2706a RequirementMachine: Allow simplified rules to appear in rewrite paths 2021-12-13 18:48:23 -05:00
Slava Pestov
1d5fdc3e62 RequirementMachine: Implement linear order on concrete type symbols with the same concrete type 2021-12-13 16:51:51 -05:00
Slava Pestov
49274ccd64 RequirementMachine: Forgot to set ProtocolComponent::InProgress to true 2021-12-10 17:31:41 -05:00
Slava Pestov
74616dbda5 RequirementMachine: Fix concrete conformances with inherited protocols 2021-12-10 17:31:41 -05:00
Slava Pestov
42e20509e8 RequirementMachine: Better debug output for generating conformances algorithm 2021-12-10 17:31:41 -05:00
Slava Pestov
7f7bf2fa97 RequirementMachine: Fix subtle bug in Knuth-Bendix algorithm
Filter out trivial overlaps where a rule overlaps entirely with
itself before looking at CheckedOverlaps. Otherwise, we'll miss
overlaps where a rule overlaps with itself at a non-zero
position.
2021-12-10 00:49:46 -05:00
Slava Pestov
3138020e5d RequirementMachine: Diagnose non-confluent rewrite systems instead of asserting
We assert when building a rewrite system for an existing generic
signature, or in AbstractGenericSignatureRequest, where there is no
source location.

In RequirementSignatureRequest and InferredGenericSignatureRequest
we now produce a diagnostic.
2021-12-10 00:49:46 -05:00
Slava Pestov
360fbc67bc RequirementMachine: Fix silly mistake in requirement inference
getFirstTypeRepr() asserts unless the RequirementRepr is a SameType
requirement. For type requirements we need to call getSubjectTypeRepr().
2021-12-10 00:49:46 -05:00
Slava Pestov
d7b5dfc644 RequirementMachine: Don't keep protocol requirement machines around 2021-12-10 00:49:45 -05:00
Slava Pestov
c1339240cd RequirementMachine: Add flags to enable and disable merged associated types
On by default, no change from current behavior. I'm going to try turning
this off (and hopefully ripping it out entirely) once I fix a few bugs.
2021-12-08 21:32:42 -05:00
Slava Pestov
cfd8dbf272 Merge pull request #40465 from slavapestov/rqm-protocol-minimization-fixes
RequirementMachine: Protocol requirement signature minimization fixes
2021-12-08 17:19:21 -05:00
Zoe Carver
a46a3c525a Merge pull request #39605 from zoecarver/cxx-interop-import-as-class
[cxx-interop] Implement foreign reference types.
2021-12-08 19:33:50 +00:00
zoecarver
fc3b3a1d71 [cxx-interop] Implement foreign reference types.
This is an expiremental feature to allow an attribute, `import_as_ref`, to import a C++ record as a non-reference-counted reference type in Swift.
2021-12-08 15:35:18 +00:00
Slava Pestov
b999cea0f7 RequirementMachine: Try to minimize away concrete conformances first 2021-12-08 00:53:35 -05:00
Slava Pestov
96bdef9f50 RequirementMachine: Move generating conformances algorithm into its own class 2021-12-08 00:53:35 -05:00
Slava Pestov
86c15ad5c1 RequirementMachine: Generating conformances can reason about concrete conformances now 2021-12-08 00:53:35 -05:00
Slava Pestov
0686cd5aef RequirementMachine: Better assertions for generating conformances 2021-12-08 00:53:35 -05:00
Slava Pestov
2f2249cef1 RequirementMachine: Fix various RewriteSteps to work when re-contextualized
When a rewrite rule is replaced with a path containing ::Adjust, ::Decompose,
::ConcreteConformance or ::SuperclassConformance rewrite steps, the steps
will get a non-zero EndOffset if the original rule appears in a step with a
non-zero EndOffset.

For this reason, these steps must work with a non-zero EndOffset, which
primarily means computing correct offsets into the term being manipulated.
2021-12-08 00:53:35 -05:00
Slava Pestov
044611dddc RequirementMachine: Another cycle-breaking hack for associated type inference 2021-12-08 00:53:35 -05:00
Slava Pestov
47f3341b40 RequirementMachine: Delete loops that don't have rules in empty context
When a rule is replaced by a rewrite path, if the rule is in context
then every step of the replacement step is necessarily always in context.

The only way new rules in empty context can be introduced by a
replacement is if the original rewrite step being replaced had no
context.

Therefore, loops that do not contain rules in empty context will
never provide any additional information during homotopy reduction.
2021-12-08 00:53:35 -05:00
Slava Pestov
1bf6102f1e RequirementMachine: Don't bother normalizing loops 2021-12-08 00:53:35 -05:00
Slava Pestov
0e2fd5ad06 RequirementMachine: Don't call getExistentialLayout() from desugarConformanceRequirement() 2021-12-08 00:53:35 -05:00
Slava Pestov
34cbfd23a5 RequirementMachine: Don't assert if a rewrite system has unresolved rules
This is a source-level error, not an invariant violation. Instead, plumb
a new hadError() flag, which in the future will assert if no diagnostic
was produced.
2021-12-08 00:53:34 -05:00
Slava Pestov
26293c4695 RequirementMachine: Factor out Symbol::withConcreteSubstitutions() 2021-12-07 15:31:47 -05:00
Slava Pestov
99b0be27c7 RequirementMachine: Dump histograms after deleting requirement machine instances 2021-12-07 15:31:47 -05:00
Slava Pestov
417b789069 RequirementMachine: Track maximum value stored in the histogram 2021-12-07 15:31:47 -05:00
Slava Pestov
8e7a9b0f9f RequirementMachine: Add a couple of histograms 2021-12-07 15:31:47 -05:00
Slava Pestov
36a7c4c032 RequirementMachine: Move some code around 2021-12-07 15:31:47 -05:00