Commit Graph

859 Commits

Author SHA1 Message Date
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
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