Commit Graph

50 Commits

Author SHA1 Message Date
Slava Pestov
d212041dfb RequirementMachine: Fold RewriteSystem::processConflicts() into recordConflict() and add debug output 2022-04-01 01:05:54 -04:00
Slava Pestov
ad2f73af44 RequirementMachine: More comments 2022-03-29 12:10:33 -04:00
Slava Pestov
a631d8aa3a RequirementMachine: Write some comments 2022-03-28 22:16:09 -04:00
Slava Pestov
132334cda9 RequirementMachine: Add debugging flag to disable re-using requirement machines 2022-03-27 11:54:28 -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
af443bee0a RequirementMachine: Implement RewriteContext::getRequirementMachine(ProtocolDecl *) 2022-03-16 00:58:30 -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
a154641288 [RequirementMachine] Propagate explicit requirement IDs from redundant
rules in a separate pass after homotopy reduction.

RewriteSystem::propagateExplicitBits was too eager in propagating
IDs from explicit rules within rewrite loops, which resulted in bogus
redundancy warnings when the canonical form of an explicit rule was
given a different requirement ID. Instead, propagate requirement IDs
after homotopy reduction when redundant rules are computed and rewrite
loops are simplified.
2022-03-09 12:14:58 -08: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
Slava Pestov
a3ab5f4cd4 RequirementMachine: Remove no-longer used DebugFlags::Merge 2022-02-23 00:17:56 -05:00
Slava Pestov
991fe1dbd8 RequirementMachine: Preserve replacement paths for redundant rules 2022-02-16 16:28:08 -05:00
Slava Pestov
50f84cb4bf RequirementMachine: Tweak debug output 2022-02-09 00:26:04 -05:00
Slava Pestov
0d0bcb2ff1 RequirementMachine: Simplify the Symbol API for removal of merged associated types 2022-02-07 18:57:45 -05:00
Slava Pestov
b138c7602d RequirementMachine: Add DebugFlags::PropertyMap 2022-02-04 22:47:49 -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
86f17a71e2 RequirementMachine: Move term to type conversion to a new file InterfaceType.cpp 2022-01-19 23:43:48 -05:00
Slava Pestov
a7091d9b0d RequirementMachine: Fix terminology in debug message 2022-01-13 00:02:31 -05:00
Slava Pestov
317743a487 RequirementMachine: Rename GeneratingConformances => MinimalConformances 2021-12-17 10:04:52 -05:00
Slava Pestov
49274ccd64 RequirementMachine: Forgot to set ProtocolComponent::InProgress to true 2021-12-10 17:31:41 -05:00
Slava Pestov
d7b5dfc644 RequirementMachine: Don't keep protocol requirement machines around 2021-12-10 00:49:45 -05:00
Slava Pestov
044611dddc RequirementMachine: Another cycle-breaking hack for associated type inference 2021-12-08 00:53:35 -05:00
Slava Pestov
99b0be27c7 RequirementMachine: Dump histograms after deleting requirement machine instances 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
d19b15b66c RequirementMachine: Introduce Symbol::Kind::ConcreteConformance 2021-12-06 23:04:46 -05:00
Robert Widmann
22405cefea Plumb the "Is Type Sequence" Bit Through the Surface AST 2021-11-08 13:48:30 -08:00
Slava Pestov
0571b65cb8 RequirementMachine: Move protocol linear order from ProtocolGraph to RewriteContext 2021-10-21 19:00:10 -04:00
Slava Pestov
56439726ab RequirementMachine: Move some code from PropertyMap.cpp to RewriteContext.cpp 2021-10-14 15:03:26 -04:00
Slava Pestov
a5e680015a Merge pull request #39646 from slavapestov/fix-rqm-reference-invalidation
RequirementMachine: Fix reference invalidation bug
2021-10-08 18:30:35 -04:00
Slava Pestov
566971dbc2 RequirementMachine: Add some comments and assertions around state transitions 2021-10-08 14:28:27 -04:00
Slava Pestov
526feebb8d RequirementMachine: Fix reference invalidation bug
After forming a reference to an entry in a DenseMap, we have to be
careful not touch the reference after calling any code which might
re-entrantly invalidate the reference by mutating the DenseMap.

Fixes rdar://problem/83891298.
2021-10-07 22:38:01 -04:00
Slava Pestov
62de909801 RequirementMachine: Some comments 2021-10-06 00:20:18 -04:00
Slava Pestov
03dfa60edd RequirementMachine: Initial implementation of requirement minimization 2021-10-06 00:11:21 -04:00
Slava Pestov
c3270742dc RequirementMachine: Compute strongly connected components from the protocol dependency graph 2021-10-05 21:30:57 -04:00
Slava Pestov
a0f4484127 RequirementMachine: Don't forget to delete requirement machines when freeing the RewriteContext 2021-09-28 13:52:33 -04:00
Slava Pestov
46063d3925 Merge pull request #39476 from slavapestov/rqm-avoid-hashtable-lookup
AST: GenericSignatures point directly to their RequirementMachine
2021-09-28 00:18:03 -04:00
Slava Pestov
47ab4a9f28 AST: GenericSignatures point directly to their RequirementMachine
This avoids a hashtable lookup when performing queries.
2021-09-27 21:36:45 -04:00
Slava Pestov
64d1931e15 RequirementMachine: Sketch out "generating conformances" algorithm 2021-09-27 19:04:16 -04:00
Slava Pestov
c6403e65e1 RequirementMachine: RewriteStep stores both whiskers 2021-09-24 08:59:50 -04:00
Slava Pestov
e4f6128990 RequirementMachine: Don't simplify terms inside concrete substitutions when adding a rule
The effect of doing this is difficult to represent with homotopy generators,
so let's just not bother.
2021-09-24 08:59:50 -04:00
Slava Pestov
399a600e32 RequirementMachine: Add -debug-requirement-machine= flag to control debug output 2021-08-20 01:29:22 -04:00
Slava Pestov
eec233507b RequirementMachine: Cache the mapping from associated type symbols to associated type declarations 2021-08-13 17:27:49 -04:00
Slava Pestov
47fc3d87ad RequirementMachine: Speed up PropertyMap lookups with a suffix trie
Whereas term simplification uses a prefix trie with shortest matching,
the PropertyMap uses a suffix trie with longest matching.
2021-08-06 14:17:20 -04:00
Slava Pestov
156fa2cc04 RequirementMachine: Speed up term simplification with a prefix trie
Previously RewriteSystem::simplify() would attempt to apply every
rewrite rule at every position in the original term, which was
obviously a source of overhead.

The trie itself is somewhat unoptimized; for example, with a bit of
effort it could merge a node with its only child, if nodes stored
a range of elements to compare rather than a single element.
2021-08-05 21:42:50 -04:00
Slava Pestov
ed966e7337 RequirementMachine: Add histograms for symbol kinds and term length 2021-08-05 21:42:50 -04:00
Slava Pestov
cfb1595ec5 RequirementMachine: Rename Atom => Symbol 2021-07-23 15:58:50 -04:00
Slava Pestov
4184ebd0a8 RequirementMachine: Split off RewriteContext.{h,cpp} from RewriteSystem.{h,cpp} 2021-07-14 00:16:06 -04:00