Commit Graph

242 Commits

Author SHA1 Message Date
Slava Pestov
c1339240cd RequirementMachine: Add flags to enable and disable merged associated types
On by default, no change from current behavior. I'm going to try turning
this off (and hopefully ripping it out entirely) once I fix a few bugs.
2021-12-08 21:32:42 -05:00
Slava Pestov
cfd8dbf272 Merge pull request #40465 from slavapestov/rqm-protocol-minimization-fixes
RequirementMachine: Protocol requirement signature minimization fixes
2021-12-08 17:19:21 -05:00
Zoe Carver
a46a3c525a Merge pull request #39605 from zoecarver/cxx-interop-import-as-class
[cxx-interop] Implement foreign reference types.
2021-12-08 19:33:50 +00:00
zoecarver
fc3b3a1d71 [cxx-interop] Implement foreign reference types.
This is an expiremental feature to allow an attribute, `import_as_ref`, to import a C++ record as a non-reference-counted reference type in Swift.
2021-12-08 15:35:18 +00:00
Slava Pestov
b999cea0f7 RequirementMachine: Try to minimize away concrete conformances first 2021-12-08 00:53:35 -05:00
Slava Pestov
96bdef9f50 RequirementMachine: Move generating conformances algorithm into its own class 2021-12-08 00:53:35 -05:00
Slava Pestov
86c15ad5c1 RequirementMachine: Generating conformances can reason about concrete conformances now 2021-12-08 00:53:35 -05:00
Slava Pestov
0686cd5aef RequirementMachine: Better assertions for generating conformances 2021-12-08 00:53:35 -05:00
Slava Pestov
2f2249cef1 RequirementMachine: Fix various RewriteSteps to work when re-contextualized
When a rewrite rule is replaced with a path containing ::Adjust, ::Decompose,
::ConcreteConformance or ::SuperclassConformance rewrite steps, the steps
will get a non-zero EndOffset if the original rule appears in a step with a
non-zero EndOffset.

For this reason, these steps must work with a non-zero EndOffset, which
primarily means computing correct offsets into the term being manipulated.
2021-12-08 00:53:35 -05:00
Slava Pestov
044611dddc RequirementMachine: Another cycle-breaking hack for associated type inference 2021-12-08 00:53:35 -05:00
Slava Pestov
47f3341b40 RequirementMachine: Delete loops that don't have rules in empty context
When a rule is replaced by a rewrite path, if the rule is in context
then every step of the replacement step is necessarily always in context.

The only way new rules in empty context can be introduced by a
replacement is if the original rewrite step being replaced had no
context.

Therefore, loops that do not contain rules in empty context will
never provide any additional information during homotopy reduction.
2021-12-08 00:53:35 -05:00
Slava Pestov
1bf6102f1e RequirementMachine: Don't bother normalizing loops 2021-12-08 00:53:35 -05:00
Slava Pestov
0e2fd5ad06 RequirementMachine: Don't call getExistentialLayout() from desugarConformanceRequirement() 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
26293c4695 RequirementMachine: Factor out Symbol::withConcreteSubstitutions() 2021-12-07 15:31:47 -05:00
Slava Pestov
99b0be27c7 RequirementMachine: Dump histograms after deleting requirement machine instances 2021-12-07 15:31:47 -05:00
Slava Pestov
417b789069 RequirementMachine: Track maximum value stored in the histogram 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
36a7c4c032 RequirementMachine: Move some code around 2021-12-07 15:31:47 -05:00
Slava Pestov
d1cda342ed RequirementMachine: Property map construction introduces concrete conformance rules 2021-12-07 15:31:47 -05:00
Slava Pestov
2aab4bb773 RequirementMachine: Stub out logic for property map to record rewrite loops
For homotopy reduction to properly deal with new rules introduced
while bulding the property map, rewrite loops must be recorded
relating these to existing rules.
2021-12-07 15:31:45 -05:00
Slava Pestov
e9b50f00f2 RequirementMachine: Record property rule IDs in property bags
For homotopy reduction to properly deal with rewrite rules
introduced by property map construction, we need to keep
track of the original property rules when recording properties
in property bags.

For now, this doesn't even attempt to handle unification or
conflicts; we only record the first rule for each kind of
property on a fixed key.

This isn't actually used for anything yet, except a new
verify pass that runs after property map construction.
2021-12-06 23:04:46 -05:00
Slava Pestov
7427b68785 RequirementMachine: Introduce RewriteStep::ConcreteConformance and ::SuperclassConformance 2021-12-06 23:04:46 -05:00
Slava Pestov
e9b94c1bf1 RequirementMachine: Move some methods from RewriteStep to RewritePathEvaluator
This better encapsulates the evaluator state into a single struct.
2021-12-06 23:04:46 -05:00
Slava Pestov
d19b15b66c RequirementMachine: Introduce Symbol::Kind::ConcreteConformance 2021-12-06 23:04:46 -05:00
Saleem Abdulrasool
349af3707d Merge pull request #40305 from compnerd/semitruck
gardening: make c++98-compat-extra-semi an error
2021-11-30 08:18:36 -08:00
Slava Pestov
77d4a207f8 RequirementMachine: Implement requirement inference 2021-11-29 13:54:15 -05:00
Slava Pestov
291ddd7a31 RequirementMachine: Plumb through the ModuleDecl used for requirement inference 2021-11-29 13:54:15 -05:00
Saleem Abdulrasool
910fbee14e gardening: make c++98-compat-extra-semi an error
This cleans up 90 instances of this warning and reduces the build spew
when building on Linux.  This helps identify actual issues when
building which can get lost in the stream of warning messages.  It also
helps restore the ability to build the compiler with gcc.
2021-11-27 11:40:17 -08:00
Slava Pestov
af9ea678ed RequirementMachine: Implement InferredGenericSignatureRequest 2021-11-19 17:06:00 -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
f0899e3acb RequirementMachine: Make some entry points in RequirementLowering.cpp public 2021-11-19 15:48:07 -05:00
Slava Pestov
28c1178c4f RequirementMachine: Introduce TypeAliasRequirementsRequest
This is a verbatim copy of the GenericSignatureBuilder's somewhat
questionable (but necessary for source compatibility) logic where
protocol typealiases with the same name as some other associated
type imply a same-type requirement.

The related diagnostics are there too, but only emitted when
-requirement-machine-protocol-signatures=on; in 'verify' mode,
the GSB will emit the same diagnostics.
2021-11-19 15:48:01 -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
Slava Pestov
df8ce67539 RequirementMachine: Refactor requirement lowering 2021-11-12 14:30:46 -05:00
Slava Pestov
67535303b6 RequirementMachine: Move implementation of StructuralRequirementsRequest and ProtocolDependenciesRequest to RequirementLowering.cpp 2021-11-12 14:30:46 -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
24bdecdca5 AST: Remove ASTContext::getOrCreateRequirementMachine() in favor of getRewriteContext() 2021-11-11 22:39:20 -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
796123eebd RequirementMachine: Avoid some expensive invariant checks in noassert builds 2021-11-11 22:39:20 -05:00
Slava Pestov
2dd14afc5e RequirementMachine: Minor comment fixes 2021-11-10 23:02:02 -05:00
Slava Pestov
2c4cfdcb1f RequirementMachine: Generating conformances prefers to delete non-explicit rules
This is a heuristic to ensure that conformance requirements remain in
their original protocol if possible, when the protocol is part of a
connected component consisting of multiple protocols.
2021-11-10 00:18:57 -05:00
Slava Pestov
dcefd70d11 RequirementMachine: Homotopy reduction propagates Rule::isExplicit() bit
If a rewrite loop contains two rules in empty context and one of them
is explicit, propagate the explicit bit to the other rule if the original
rule was found to be redundant.

This means that if we begin with an unresolved rule like

    [P].X.[Q] => [P].X [explicit]

And then completion added the resolved rule

    [P:X].[Q] => [P:X]

Then the new rule will become explicit once the original rule becomes
redundant.
2021-11-10 00:18:57 -05:00
Slava Pestov
8ab1c1f32e RequirementMachine: Remove one of the three homotopy reduction passes
This was a hack from before the change to minimize away the
least canonical rules first. Now, there's no reason to perform
a separate pass over rules containing unresolved name symbols.
2021-11-10 00:18:18 -05:00
Slava Pestov
15bf00148d RequirementMachine: Rename RewriteSystemCompletion.cpp to KnuthBendix.cpp 2021-11-10 00:18:18 -05:00
Slava Pestov
ecce9d2405 RequirementMachine: Narrower definition of Rule::isProtocolRefinementRule()
With this change the RequirementMachine's minimization behavior with
protocol refinement rules matches the GenericSignatureBuilder.

See https://github.com/apple/swift/pull/37466 for a full explanation
of what's going on here.
2021-11-10 00:18:18 -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