Commit Graph

873 Commits

Author SHA1 Message Date
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
ae44028117 RequirementMachine: Allow the property map to record induced rules directly
It doesn't actually do this yet, but the idea is to look at the
total rule count before and after, instead of just looking at the
induced rules array (which I will delete in the next commit).
2022-01-25 00:35:11 -05:00
Slava Pestov
10e4ffdfbd RequirementMachine: Track known protocols in the rewrite system
Conditional requirement inference needs to be able to add rewrite rules
from the requirement signatures of hitherto-unseen protocols, so to
help with that, extract out the RuleBuilder's ProtocolMap and move it
into the RewriteSystem.
2022-01-25 00:35:03 -05:00
Slava Pestov
96122834fb RequirementMachine: getRuleForRequirement() supports relative terms 2022-01-25 00:32:25 -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
b27c15686c RequirementMachine: Add assertion to RewriteSystem::isInMinimizationDomain() 2022-01-25 00:32:25 -05:00
Slava Pestov
f480eeaf53 RequirementMachine: Factor out getRuleForRequirement() from RuleBuilder::addRequirement() 2022-01-25 00:32:25 -05:00
Slava Pestov
f3b8bedf1f RequirementMachine: Fix assertion failure when conflicting rules are also redundant
We can end up with two redundant concrete type rules on the same
term, but we would crash in homotopy reduction because the rules
were incomparable due to the concrete type symbol at the end.

If one of them is conflicting though, we don't really care about
the homotopy reduction order, so skip the check if the other
rule was already marked conflicting.
2022-01-25 00:32:25 -05:00
Slava Pestov
7a5758ea43 RequirementMachine: Fix missing space in debug output 2022-01-25 00:32:25 -05:00
Slava Pestov
a2f2ffd1c2 RequirementMachine: Remove obsolete comment 2022-01-25 00:32:25 -05:00
Slava Pestov
275af8d0fd RequirementMachine: getTypeForSymbolRange() maps canonical terms to canonical types
Previously this would only be true with merged associated types,
but I want to get rid of those.
2022-01-20 14:18:25 -05:00
Slava Pestov
8468c14dbc RequirementMachine: Add overload of PropertyMap::lookUpProperties() that takes a pair of iterators 2022-01-20 12:48:48 -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
86f17a71e2 RequirementMachine: Move term to type conversion to a new file InterfaceType.cpp 2022-01-19 23:43:48 -05:00
Slava Pestov
0ffd11c558 RequirementMachine: New GenericSignature::isValidTypeInContext() query 2022-01-14 21:25:32 -08:00
Slava Pestov
da30258f49 RequirementMachine: Remove RewriteSystem::TypeWitness 2022-01-13 19:14:52 -05:00
Slava Pestov
bdbf50e1e3 RequirementMachine: Replace RewriteStep::SameTypeWitness with a relation 2022-01-13 19:14:52 -05:00
Slava Pestov
6064671abd RequirementMachine: Replace RewriteStep::ConcreteTypeWitness with relations 2022-01-13 18:01:15 -05:00
Slava Pestov
84e2a627ec RequirementMachine: Replace RewriteStep::AbstractTypeWitness with relations 2022-01-13 00:02:31 -05:00
Slava Pestov
abb85fb3ca RequirementMachine: Replace RewriteStep::{Superclass,Concrete}Conformance with relations 2022-01-13 00:02:31 -05:00
Slava Pestov
3d2492fe56 RequirementMachine: Rename RewriteStep::ApplyRewriteRule to RewriteStep::Rule 2022-01-13 00:02:31 -05:00
Slava Pestov
f06f59a18a RequirementMachine: Generalize relations so they look more like rules 2022-01-13 00:02:31 -05:00
Slava Pestov
220d4882fd RequirementMachine: Move some code to a new PropertyRelations.cpp file 2022-01-13 00:02:31 -05:00
Slava Pestov
a7091d9b0d RequirementMachine: Fix terminology in debug message 2022-01-13 00:02:31 -05:00
Slava Pestov
f674ca95bd RequirementMachine: Remove the older 'concrete type in domain' hack 2022-01-11 21:43:56 -05:00
Slava Pestov
378231cb97 RequirementMachine: A better trick to tie off type witness recursion
This will replace the 'concrete type in domain' hack. Instead of
finding some other type parameter with the same concrete type and a
compatible starting symbol, this finds a prefix of the original
term. This allows the induced same-type requirement to be described
with a rewrite path.
2022-01-11 21:43:55 -05:00
Slava Pestov
a3c230e436 RequirementMachine: PropertyBag::{getConcreteType,getSuperclassBound}() should return CanType 2022-01-11 21:43:55 -05:00
Slava Pestov
56450af673 RequirementMachine: Record identity conformances in the property map 2022-01-11 21:43:55 -05:00
Slava Pestov
746f4a5a8f RequirementMachine: Throw out rewrite loops not part of the minimization domain
When minimizing a generic signature, we only care about loops
where the basepoint is a generic parameter symbol.

When minimizing protocol requirement signatures in a connected
component, we only care about loops where the basepoint is a
protocol symbol or associated type symbol whose protocol is
part of the connected component.

All other loops can be discarded since they do not encode
redundancies that are relevant to us.
2022-01-05 23:59:46 -05:00
Slava Pestov
25cae6f479 RequirementMachine: Ignore requirements with ErrorTypes for GSB compatibility 2022-01-05 22:41:03 -05:00
Slava Pestov
9bb497c866 RequirementMachine: Concrete class requirements imply superclass requirements 2022-01-05 22:41:03 -05:00
Slava Pestov
be772cc74b RequirementMachine: Layout requirement implied by superclass is now handled in the property map 2022-01-05 22:41:03 -05:00
Slava Pestov
2737989f8f RequirementMachine: Fix 'relations' where one rule is a suffix of the other 2022-01-05 22:41:03 -05:00
Slava Pestov
5ced0f8c2e RequirementMachine: Avoid some wasted work when re-building the property map 2022-01-05 22:41:03 -05:00
Slava Pestov
380dba1a9f RequirementMachine: Fold PropertyBag::addProperty() into PropertyMap::addProperty() 2022-01-05 22:41:03 -05:00
Slava Pestov
66cf913d68 RequirementMachine: Minimization understands 'relations' among layout requirements
A superclass requirement 'T : C' implies a layout requirement
'T : AnyObject' (if the class is @objc) or 'T : _NativeObject'
(if the class is not @objc).

In the latter case, there might already be a 'T : AnyObject'
requirement, in which case the type parameter 'T' is subject
to two layout requirements:

    T : AnyObject
    T : _NativeObject

The second requirement implies the first however. To encode this
in the world of rewrite loops, we the notion of a 'relation'
between property symbols, and a 'Relation' rewrite step.

Here, the relation is that _NativeObject < AnyObject. Once this
relation is recorded, the Relation rewrite step will transform

    T.[layout: _NativeObject].[layout: AnyObject]

into

    T.[layout: _NativeObject]

and vice versa.

This rewrite step allows us to construct a rewrite loop which
makes the first rewrite rule redundant via the second.
2022-01-04 22:35:58 -05:00
Slava Pestov
7148aea7ed RequirementMachine: Rename RewriteStep::RuleID to RewriteStep::Arg
It's used to store more than just the rule ID. However, add a
getRuleID() method that also asserts that Kind is ApplyRewriteRule
for readability.
2022-01-04 22:35:58 -05:00
Slava Pestov
8bf1bc283c RequirementMachine: Rename A/B stack to primary/secondary stack 2022-01-04 22:35:58 -05:00
Slava Pestov
b42402bd6f Merge pull request #40646 from slavapestov/rqm-more-validation-test-fixes
RequirementMachine: More fixes for validation tests with -requirement-machine-protocol-signatures=verify
2021-12-21 08:34:57 -05:00
Slava Pestov
c5df7870b4 RequirementMachine: Fix for redundant protocol refinement via concrete type requirements 2021-12-20 17:59:31 -05:00
Slava Pestov
f50c7c94df RequirementMachine: Tweak TypeAliasRequirementsRequest to match GSB on highly-invalid code 2021-12-20 17:59:31 -05:00
Slava Pestov
5c11f36354 RequirementMachine: Mark rules as conflicting more aggressively 2021-12-20 17:59:31 -05:00
Slava Pestov
f4ff260ee7 RequirementMachine: Subtle fix for minimal conformances algorithm
We don't need to be able to recover the parent type of a conformance
rule if the rule itself is redundant.
2021-12-20 17:59:31 -05:00
Slava Pestov
8a222b50fd RequirementMachine: Better debug output from minimal conformances algorithm 2021-12-20 17:59:31 -05:00
Saleem Abdulrasool
d5174b28df AST: make RequirementMachine/PropertyUnification.cpp build on VS2022
Using the qualified name is subtly different from scoping the function.
Use the latter, which correctly places the function into the namespace,
to enable building with VS2022.
2021-12-19 15:37:24 -08:00
Slava Pestov
82a494e31b RequirementMachine: Go back to doing three passes in homotopy reduction
First pass:
- Eliminate rules with unresolved name symbols in LHS
- Eliminate simplified non-conformance rules

Second pass:
- Eliminate non-minimal conformance rules

Third pass:
- Eliminate all other non-conformance rules

If you have a concrete requirement with a non-canonical substitution, like

    A : P, A == G<B.T>

We add an induced rule for the abstract type witness,

    A.T == B.T

This rule has a rewrite path in terms of the previous two rules, but we
want to try to eliminate the other two rules first.

This new ordering ensures we eliminate the simplified rule A == G<B.T> and
compute minimal conformances before we get around to considering A.T == B.T,
which can no longer be eliminated by that point.

If we eliminate A.T == B.T first, we end up with simplified concrete
type and concrete conformance rules which cannot be eliminated:

    A.[concrete: G<B.T>] => A
    A.[concrete: G<B.T> : P] => A

This changes the minimized signature in an incompatible way in two test cases.

In Generics/rdar83308672.swift, the signature becomes equivalent to what the
GSB used to output.

In Generics/sr10532.swift, the GSB would output an invalid signature anyway,
so it doesn't matter.
2021-12-17 10:04:52 -05:00
Slava Pestov
3c9344cc80 RequirementMachine: Improved verifyMinimizedRules() 2021-12-17 10:04:52 -05:00