Commit Graph

114 Commits

Author SHA1 Message Date
Slava Pestov
a631d8aa3a RequirementMachine: Write some comments 2022-03-28 22:16:09 -04:00
Slava Pestov
4d097da73c RequirementMachine: Re-use requirement machines constructed by minimization for queries
Fixes rdar://problem/88135641.
2022-03-26 00:56:41 -04:00
Slava Pestov
af99ac55de RequirementMachine: Add -debug-requirement-machine=timers 2022-03-26 00:56:41 -04:00
Slava Pestov
3fe4aaae5a RequirementMachine: Fix subtle bug in isRecursivelyConstructingRequirementMachine()
I don't have a reduced test case. It was possible for computing the requirement
signatures of a connected component to have finished, and yet for the
ProtocolDecl::hasComputedRequirementSignature() method to return false, if
we had evaluated a RequirementSignatureRequestRQM but not the top-level
RequirementSignatureRequest.

Instead, track whether we've computed the signatures for a component directly.

I don't have a reduced test case. It would arise with associated type inference,
which uses this predicate to break nasty cycles.
2022-03-24 23:45:32 -04:00
Slava Pestov
441fa1679a RequirementMachine: Splitting concrete equivalence classes in protocol requirement signatures 2022-03-22 15:02:06 -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
4446f2afcf RequirementMachine: Move some code out of RuleBuilder and into RequirementSignatureRequest 2022-03-22 15:02:06 -04:00
Slava Pestov
466d6a9468 RequirementMachine: Refactor shouldSplitConcreteEquivalenceClasses() and splitConcreteEquivalenceClasses() a bit
Note that this changes the behavior of a test slightly when the
-disable-concrete-contraction flag is used. This is because we're
not using the Requirement Machine that minimized the signature
and not the Requirement Machine built from the minimized
signature; the former includes a concrete conformance rule.

The isConcreteType() query returns true on the former when
given the generic parameter τ_0_0.

Since -disable-concrete-contraction is only meant for debugging,
I'm just removing that line from the test.
2022-03-22 15:02:06 -04:00
Slava Pestov
11b45ca269 RequirementMachine: splitConcreteEquivalenceClass() uses getConcreteType() instead of getCanonicalTypeInContext() 2022-03-22 15:02:06 -04:00
Slava Pestov
24b6624275 RequirementMachine: Move some code around in RequirementMachineRequests.cpp 2022-03-22 15:02:06 -04:00
Slava Pestov
9ccdd15d58 RequirementMachine: Add upper bound on number of attempts at splitting concrete equivalence classes 2022-03-22 15:02:06 -04:00
Slava Pestov
4069434100 RequirementMachine: Preserve sugar when splitting concrete equivalence classes
Instead of kicking off an AbstractGenericSignatureRequest recursively,
handle the rebuilding in a loop in {Abstract,Inferred}GenericSignatureRequest.

This also avoids an unnecessary call to verify() when rebuilding.
2022-03-22 15:02:06 -04:00
Slava Pestov
2206b1c54d RequirementMachine: Split up equivalence classes with inferred concrete type
I'll clean this up, comment it and generalize it to work with protocol requirement
signatures soon. Landing this now to unblock the Linux corelibs-foundation build.

Fixes rdar://problem/89791117.
2022-03-18 01:29:22 -04:00
Slava Pestov
f3bcc52e6c RequirementMachine: Rename RequirementMachine::initWithProtocols() 2022-03-15 18:34:54 -04:00
Slava Pestov
2ee5aeefee RequirementMachine: InferredGenericSignatureRequest returns parent generic signature if completion fails 2022-03-14 12:33:18 -04:00
Slava Pestov
f5b3d19703 RequirementMachine: Replace hadError() with getErrors() returning an OptionSet
This gives us more fine-grained information which will be plumbed
through the various requests.
2022-03-14 12:33:18 -04:00
Slava Pestov
1578ab578a RequirementMachine: Refactor requests to not be downstream of the GenericSignatureBuilder
This will make it easier to remove the GenericSignatureBuilder (which
still won't happen for a little while).
2022-03-14 12:33:18 -04:00
Slava Pestov
05aeeff386 RequirementMachine: Reconstitute sugar in trivial cases
The Requirement Machine operates on canonical types internally and erases
sugared types appearing in generic requirements as a result.

For trivial cases like Array<T> vs [T], we can use the existing
TypeBase::reconstituteSugar() utility to produce a more aesthetically-pleasing
generic signature.
2022-03-14 12:33:18 -04:00
Slava Pestov
3576318fc7 RequirementMachine: Refactor construction of requirements from rules
The final step in minimization is building Requirements and
ProtocolTypeAliases from the minimal Rules in the RewriteSystem.

Move this to a new file and refactor it a bit to handle
Requirements and ProtocolTypeAliases more consistently.
2022-03-14 12:33:18 -04:00
Holly Borla
7ce6504b93 [RequirementMachine] Avoid passing the requirement error vector through
initialization of the rewrite system.

Instead, the rewrite system can determine trivially redundant requirements
by finding structural requirements with no associated rewrite rules.
2022-03-10 13:13:50 -08:00
Holly Borla
4b55c30fad [RequirementMachine] Instead of recording redundant requirements and other
diagnostics in the rewrite system, pass down the 'errors' vector from the
top-level requests.
2022-03-09 18:18:43 -08:00
Holly Borla
be30d76732 [RequirementMachine] Diagnose redundant requirements found during minimization
of the rewrite system.
2022-03-09 12:14:58 -08:00
Holly Borla
b18e815436 [RequirementMachine] Preserve structural requirements during rule construction,
and diagnose trivially redundant rules in the rewrite system.
2022-03-09 12:14:58 -08:00
Slava Pestov
9c2d540e69 RequirementMachine: Check invariants using GenericSignature::verify()
Previously only the GenericSignatureBuilder would call this; to ensure
we get the same test coverage when the Requirement Machine is 'on' as
'verify', also call this from the Requirement Machine.

For now, we can't call this from RequirementSignatureRequestRQM due
to circularity issues; that will have to wait until this request is
folded into RequirementSignatureRequest.
2022-03-03 14:05:02 -05:00
Slava Pestov
8e09ba8b45 RequirementMachine: Introduce 'concrete contraction' pre-processing pass before building rewrite system
See the comment at the top of ConcreteContraction.cpp for a detailed explanation.

This can be turned off with the -disable-requirement-machine-concrete-contraction
pass, mostly meant for testing. A few tests now run with this pass both enabled
and disabled, to exercise code paths which are otherwise trivially avoided by
concrete contraction.

Fixes rdar://problem/88135912.
2022-02-25 11:48:38 -05:00
Slava Pestov
ae1ef6d50d RequirementMachine: Eliminate RequirementMachine::initWithAbstractRequirements() 2022-02-23 00:20:57 -05:00
Holly Borla
1dddd9c047 [RequirementMachine] Move gating emitting diagnostics on the requirement
macine flags to callers.

Callers gate this decision on different flags; InferredGenericSignatureRequestRQM
needs RequirementMachineInferredSignatures to be enabled, and the other
callsites need RequirementMachineProtocolSignatures to be enabled.
2022-02-16 13:11:57 -08:00
Holly Borla
3837b4def4 [RequirementMachine] Diagnose early redundant requirements. 2022-02-16 13:11:57 -08:00
Holly Borla
3c2b588037 [RequirementMachine] Plumb the requirement errors vector through desugarRequirement. 2022-02-16 13:11:57 -08:00
Holly Borla
a74717ab69 [RequirementMachine] Diagnose non-protocol, non-class conformance/subtype
constraints in the requirement machine.
2022-02-16 13:11:56 -08: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
fa65fd0e05 RequirementMachine: Plumb protocol typealiases through minimization
Now that we can detect protocol typealias rules, collect and keep
track of them so that they can be recorded in protocol requirement
signatures.

For now, this is all NFC since nothing introduces such rules into
the rewrite system, except for invalid requirements which are
diagnosed anyway.
2022-02-13 00:24:23 -05:00
Slava Pestov
d4a4540494 RequirementMachine: Fix name lookups for the internal 'where' clause of a GenericParamList
These come up in SIL and in the experimental named opaque result types
implementation. Pass the correct DeclContext here, instead of using
the ModuleDecl.
2022-02-10 17:23:54 -05:00
Slava Pestov
2d066dd7ed RequirementMachine: Do a better job of filtering out invalid superclass and concrete type requirements
In the long run it doesn't really matter if we leave them in there, but for now
matching the GenericSignatureBuilder's behavior makes the tests pass with
-requirement-machine-inferred-signatures=verify.
2022-02-10 17:23:54 -05:00
Slava Pestov
50f84cb4bf RequirementMachine: Tweak debug output 2022-02-09 00:26:04 -05:00
Slava Pestov
37be2d5dd7 RequirementMachine: Emit a diagnostic note with the offending rewrite rule if completion failed
This surfaces an implementation detail, but it might be better
than nothing.
2022-02-07 08:20:59 -05:00
Slava Pestov
634ca55764 RequirementMachine: Rework completion limits a bit
- Rename StepLimit to MaxRuleCount, DepthLimit to MaxRuleLength
- Rename command line flags to -requirement-machine-max-rule-{count,length}=
- Check limits outside of PropertyMap::buildPropertyMap()
- Simplify the logic in RequirementMachine::computeCompletion()
2022-02-07 08:20:59 -05:00
Slava Pestov
4f3d05f502 RequirementMachine: Remove Symbol::getSuperclass() 2022-02-04 22:47:19 -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
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
317743a487 RequirementMachine: Rename GeneratingConformances => MinimalConformances 2021-12-17 10:04:52 -05:00
Slava Pestov
1747951eb7 RequirementMachine: Drop requirements containing ErrorTypes 2021-12-14 02:17:07 -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
d7b5dfc644 RequirementMachine: Don't keep protocol requirement machines around 2021-12-10 00:49:45 -05:00
Slava Pestov
86c15ad5c1 RequirementMachine: Generating conformances can reason about concrete conformances now 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
d19b15b66c RequirementMachine: Introduce Symbol::Kind::ConcreteConformance 2021-12-06 23:04:46 -05:00
Slava Pestov
291ddd7a31 RequirementMachine: Plumb through the ModuleDecl used for requirement inference 2021-11-29 13:54:15 -05:00
Slava Pestov
af9ea678ed RequirementMachine: Implement InferredGenericSignatureRequest 2021-11-19 17:06:00 -05:00
Slava Pestov
a208abc54c RequirementMachine: Desugar requirements in AbstractGenericSignatureRequest
The requirements passed to this request may have been substituted,
meaning the subject type might be a concrete type and not a type
parameter.

Also, the right hand side of conformance requirements here might be
a protocol composition.

Desugaring converts these kinds of requirements into "proper"
requirements where the subject type is always a type parameter,
which is what the RuleBuilder expects.
2021-11-12 14:30:46 -05:00