Commit Graph

121 Commits

Author SHA1 Message Date
Slava Pestov
d19b15b66c RequirementMachine: Introduce Symbol::Kind::ConcreteConformance 2021-12-06 23:04:46 -05:00
Slava Pestov
42c0a28ad7 RequirementMachine: Add RequirementMachine::initWithWrittenRequirements() 2021-11-19 15:48:28 -05:00
Slava Pestov
1c78b0466b RequirementMachine: Clean up the RequirementMachine::initWith*() methods a bit 2021-11-19 15:48:15 -05:00
Slava Pestov
ff5d0e1d63 RequirementMachine: Split off RuleBuilder into a new RequirementLowering.cpp file 2021-11-12 14:30:46 -05:00
Slava Pestov
d164fb8010 RequirementMachine: Rename RewriteSystemBuilder to RuleBuilder 2021-11-12 14:30:46 -05:00
Slava Pestov
2666449aa6 RequirementMachine: Implement AbstractGenericSignatureRequestRQM 2021-11-12 00:32:43 -05:00
Slava Pestov
952dafad72 RequirementMachine: Preliminary refactoring in preparation for computing top-level generic signatures 2021-11-11 22:39:20 -05:00
Slava Pestov
a4e848f598 RequirementMachine: New way of modeling layout requirement implied by superclass requirement
A superclass requirement implies a layout requirement. We don't
want the layout requirement to be present in the minimal
signature, so instead of adding a pair of requirements:

    T.[superclass: C<X, Y>] => T
    T.[layout: _NativeClass] => T

Add this pair of requirements:

    T.[superclass: C<X, Y>] => T
    [superclass: C<X, Y>].[layout: _NativeClass] => [superclass: C<X, Y>] [permanent]

Completion then derives the rule as a consequence:

    T.[layout: _NativeClass] => T

Since this rule is a consequence of the other two rules, homotopy
reduction will mark it redundant.
2021-11-10 00:18:18 -05:00
Slava Pestov
b7711454a2 RequirementMachine: Rename RewriteSystemBuilder::AssociatedTypeRules => PermanentRules 2021-11-10 00:18:18 -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
5ac83e2819 RequirementMachine: Move buildPropertyMap() from RewriteSystem to PropertyMap
Now that the property map stores a reference to the RewriteSystem,
defining the buildPropertyMap() method on PropertyMap feels cleaner,
and allows more of the property map's internals to be private.
2021-11-01 22:51:26 -04:00
Slava Pestov
1057b56395 RequirementMachine: Rename HomotopyGenerator to RewriteLoop
Also, stop talking about 2-cells and 3-cells.
2021-10-27 01:28:24 -04:00
Slava Pestov
5689d046d4 RequirementMachine: Always add a rule for the trivial [P].[P] => [P] conformance
Completion adds this rule when a same-type requirement equates the Self of P
with some other type parameter conforming to P; one example is something like this:

  protocol P {
    associatedtype T : P where T.T == Self
  }

The initial rewrite system looks like this:

  (1) [P].T => [P:T]
  (2) [P:T].[P] => [P:T]
  (3) [P:T].[P:T] => [P]

Rules (2) and (3) overlap on the term

  [P:T].[P:T].[P]

Simplifying the overlapped term with rule (2) produces

  [P:T].[P:T]

Which further reduces to

  [P]

Simplifying the overlapped term with rule (3) produces

  [P].[P]

So we get a new rule

  [P].[P] => [P]

This is not a "real" conformance rule, and homotopy reduction wastes work
unraveling it in rewrite loops where this rule occurs. Instead, it's better
to introduce it as a permanent rule that is not subject to homotopy reduction
for every protocol.
2021-10-27 00:34:04 -04:00
Slava Pestov
e0a33445ac RequirementMachine: Fold what remains of ProtocolGraph into RewriteSystemBuilder 2021-10-21 19:00:41 -04:00
Slava Pestov
0571b65cb8 RequirementMachine: Move protocol linear order from ProtocolGraph to RewriteContext 2021-10-21 19:00:10 -04:00
Slava Pestov
6441b8bd73 RequirementMachine: Extract some verification logic out of minimizeRewriteSystem() 2021-10-14 15:03:08 -04:00
Slava Pestov
4d5e641b4e RequirementMachine: Store the rewrite system in the property map 2021-10-10 00:20:19 -04:00
Slava Pestov
286e91d447 RequirementMachine: Temporarily disable associated type merging when minimizing protocol signatures
Also while plumbing this through, don't record homotopy generators
unless we're minimizing a protocol signature, since they're not
used for anything else yet.
2021-10-09 19:11:14 -04:00
Slava Pestov
85dfbcdedb RequirementMachine: Move some code from RequirementMachine.cpp to RequirementMachineRequests.cpp 2021-10-09 19:11:14 -04:00
Slava Pestov
a4c2ad43ab RequirementMachine: Use ProtocolDecl::getProtocolDependencies()
When using the requirement machine to build protocol signatures,
we can't get the protocol's dependencies by looking at the
conformance requirements in it's requirement signature, because
we haven't computed the requirement signature yet.

Instead, get the dependencies via the recently-added
getStructuralRequirements() request.
2021-10-08 19:38:48 -04:00
Slava Pestov
b8177995df RequirementMachine: Sort requirements and canonicalize same-type requirements 2021-10-08 14:28:27 -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
760efcafd8 RequirementMachine: When building a requirement signature system, remember the protocols 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
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
5f3d781ed3 RequirementMachine: Homotopy reduction tweaks
- Skip permanent rules (there's no point, we'll add them back next time)
- Skip conformance rules (these will be handled separately)
- Delete 3-cells that are entirely "in-context" (but don't quote me on
  this one, I'm not quite yet convinced it's correct, but it feels right)
2021-09-27 19:03:34 -04:00
Slava Pestov
7ad0c3cc79 RequirementMachine: Add a mode allowing unresolved name symbols in rewrite rules 2021-09-27 19:03:26 -04:00
Slava Pestov
99dab70840 RequirementMachine: Mark associated type introduction rules permanent 2021-09-24 08:59:51 -04:00
Slava Pestov
c6403e65e1 RequirementMachine: RewriteStep stores both whiskers 2021-09-24 08:59:50 -04:00
Slava Pestov
b317a5c5ee RequirementMachine: Verify homotopy generators 2021-09-24 08:59:50 -04:00
Slava Pestov
463d591496 RequirementMachine: Verify that generic parameter symbols are valid within the current signature 2021-08-26 02:07:18 -04:00
Slava Pestov
e29b081939 RequirementMachine: Dump conformance access paths 2021-08-26 02:07:18 -04:00
Slava Pestov
fe2f42bc72 RequirementMachine: Rename -debug-requirement-machine flag to -dump-requirement-machine 2021-08-19 22:14:58 -04:00
Slava Pestov
0602a2ede3 RequirementMachine: Simplify right hand sides on each iteration of completion 2021-08-13 16:34:32 -04:00
Slava Pestov
2fc6ec551b RequirementMachine: Use trie for left hand side simplification
In a confluent rewrite system, if the left hand side of a rule
X => Y can be reduced by some other rule X' => Y', then it is
permissible to delete the original rule X => Y altogether.

Confluence means that rewrite rules can be applied in any
order, so it is always valid to apply X' => Y' first, thus
X => Y is obsolete.

This was previously done in the completion procedure via a
quadratic algorithm that attempted to reduce each existing
rule via the newly-added rule obtained by resolving a critical
pair. Instead, we can do this in the post-processing pass
where we reduce right hand sides using a trie to speed up
the lookup.

This increases the amount of work performed by the
completion procedure, but eliminates the quadratic algorithm,
saving time overall.
2021-08-07 01:51:31 -04:00
Slava Pestov
f39a0a888f RequirementMachine: Use the correct predicate to determine if a class uses Objective-C reference counting
Also, introduce the layout requirement implied by a superclass requirement
when lowering requirements, instead of when building the property map.

Right now this is functionally equivalent, but if we ever start to
test properties by checking for joinability of T with T.[p] instead of
looking at the property map entry of T, this new formulation is the
right one.
2021-08-04 01:24:00 -04:00
Slava Pestov
2d636955c6 RequirementMachine: Collapse RequirementMachine::Implementation down into RequirementMachine 2021-07-23 17:21:58 -04:00
Slava Pestov
27cf1cc4c2 RequirementMachine: Merge RequirementMachineImpl.h into RequirementMachine.h 2021-07-23 17:21:58 -04:00
Slava Pestov
379359c08e RequirementMachine: Move RequirementMachine.h to lib/AST/RequirementMachine 2021-07-23 17:21:57 -04:00
Slava Pestov
d3db1b6753 RequirementMachine: EquivalenceClassMap => PropertyMap
EquivalenceClass is now PropertyBag.
2021-07-23 17:21:57 -04:00
Slava Pestov
cfb1595ec5 RequirementMachine: Rename Atom => Symbol 2021-07-23 15:58:50 -04:00
Robert Widmann
1329f3cfbd [NFC] Lift getGenericEnvironment() into GenericSignature 2021-07-22 23:33:02 -07:00
Robert Widmann
d86551de67 Lift Requirement and Parameter Accessors up to GenericSignature
Start treating the null {Can}GenericSignature as a regular signature
with no requirements and no parameters. This not only makes for a much
safer abstraction, but allows us to simplify a lot of the clients of
GenericSignature that would previously have to check for null before
using the abstraction.
2021-07-22 23:27:05 -07:00
Slava Pestov
02db632488 RequirementMachine: Re-use a single global RewriteContext 2021-07-17 00:05:05 -04:00
Slava Pestov
b718663719 RequirementMachine: Tri-state enable flag, and move queries to GenericSignatureQueries.cpp
The -enable-requirement-machine and -disable-requirement-machine flags are now
replaced by a new flag -requirement-machine={on,off,verify}.
2021-07-17 00:05:05 -04:00
Slava Pestov
08edd56686 RequirementMachine: Drop protocols that the superclass conforms to when building an archetype 2021-07-17 00:05:05 -04:00
Slava Pestov
3e47d94b6c RequirementMachine: Implement GenericSignature::getLocalRequirements() query 2021-07-17 00:05:05 -04:00
Slava Pestov
4184ebd0a8 RequirementMachine: Split off RewriteContext.{h,cpp} from RewriteSystem.{h,cpp} 2021-07-14 00:16:06 -04:00