Commit Graph

160 Commits

Author SHA1 Message Date
Slava Pestov
cca936e790 RequirementMachine: Don't consider protocol typealiases with UnboundGenericType
These are stealth generic typealiases and should not participate in the
rewrite system.
2022-03-21 12:19:29 -04:00
Slava Pestov
1e731d3a18 RequirementMachine: Don't assert on abstract conformance in desugarConformanceRequirement() 2022-03-17 17:45:52 -04:00
Slava Pestov
ef1636a462 RequirementMachine: Split off RuleBuilder.{cpp,h} from RequirementLowering.{cpp,h} 2022-03-16 12:24:20 -04:00
Slava Pestov
7c006190dd RequirementMachine: Fold getRuleForRequirement() into RuleBuilder::addRequirement() 2022-03-16 12:24:20 -04:00
Slava Pestov
652de97cfd RequirementMachine: Introduce RuleBuilder::initWithConditionalRequirements() 2022-03-16 12:24:20 -04:00
Slava Pestov
8176b61d60 RequirementMachine: Tweak debug output and add an assertion 2022-03-16 12:24:10 -04:00
Slava Pestov
d7f84454c4 RequirementMachine: Filter duplicates in ProtocolDependenciesRequest 2022-03-16 00:58:30 -04:00
Slava Pestov
653977a51c RequirementMachine: Rule sharing
All the pieces are now in place so that the RuleBuilder can assemble
a confluent rewrite system for downstream protocol dependencies,
instead of building rules from protocol requirement signatures.
2022-03-16 00:58:30 -04:00
Slava Pestov
aaf84ac6c2 RequirementMachine: Implement RequirementMachine::initWithProtocolSignatureRequirements() 2022-03-15 18:34:54 -04:00
Slava Pestov
564f626f62 RequirementMachine: Rename some RuleBuilder methods for clarity 2022-03-15 18:34:54 -04:00
Slava Pestov
1d8dd94501 RequirementMachine: Refactor RuleBuilder in preparation for rule sharing 2022-03-15 18:34:54 -04:00
Slava Pestov
6a74ad7065 RequirementMachine: Drop GSB compatibility hack involving ErrorTypes
Another hack we can remove now that 'verify' mode skips checking if
there was a conflict.
2022-03-14 12:33:18 -04:00
Slava Pestov
a61f67a0e8 RequirementMachine: Hack to allow protocol typealiases to appear in associated type inheritance clauses
If you have something like

    protocol P {
      typealias A = C

      associatedtype T : A
    }

    class C {}

Then ::Structural resolution of 'A' in the inheritance clause will
produce a DependentMemberType 'Self.A'. Check for this case and
attempt ::Interface resolution to get the correct underlying type.

Fixes rdar://problem/90219229.
2022-03-14 12:33:18 -04: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
Holly Borla
80a2eee2bf [Diagnostics] Remove a few special cases of printing 'any' for specific
error messages.
2022-03-05 14:26:45 -08:00
Slava Pestov
c75337c986 RequirementMachine: Remove lookupMemberType() in favor of existing substBaseType() 2022-02-18 22:24:25 -05:00
Slava Pestov
d7f8f2067a Sema: Generalize ProtocolDecl::getPrimaryAssociatedType() to ProtocolDecl::getPrimaryAssociatedTypes() 2022-02-18 22:24:25 -05:00
Slava Pestov
7e5d6f4cb0 AST: Rework ParameterizedProtocolTypes to store multiple argument types
For now, this is NFC since we still assume one argument elsewhere.
2022-02-18 18:22:20 -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
04a91fe61d [RequirementMachine] Suppress requirement diagnostics when one of the
types already has an error.
2022-02-16 13:11:57 -08:00
Holly Borla
d5814ae3e5 [RequirementMachine] Only emit a redundancy warning for layout constraints
if the type is constrained to a class layout, and add a few more test cases
for type requirement conflicts.
2022-02-16 13:11:57 -08:00
Holly Borla
a992917f1c [NFC][RequirementMachine] Rename some of the RequirementError::Kind cases,
add documentation for each case, and move RequirementError to
lib/AST/RequirementMachine/Diagnostics.h.
2022-02-16 13:11:57 -08:00
Holly Borla
1f1125098b [NFC][RequirementMachine] Add documentation for diagnoseRequirementErrors. 2022-02-16 13:11:57 -08:00
Holly Borla
e6dc7e69c1 [RequirementMachine] Emit diagnostics for structural requirements in protocol
and typealias requirement signatures.
2022-02-16 13:11:57 -08:00
Holly Borla
ec45d960d8 [RequirementMachine] Always store an invalid requirement in RequirementError. 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
203734bea4 [RequirementMachine] Diagnose conformance, layout, and superclass constraints
on non-type-parameters in the requirement machine.
2022-02-16 13:11:57 -08:00
Holly Borla
e4cba889c2 [RequirementMachine] Diagnose concrete same-type mismatches, such as
`where String == Int`.
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
4a06e21bf9 RequirementMachine: Introduce rules for protocol typealiases from requirement signatures
When building a rewrite system for a generic signature or protocol,
we would add requirements from the requirement signature of every
protocol dependency. Now, also add protocol typealias rules as well.
2022-02-13 00:24:23 -05: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
c58d9d8974 Sema: StructuralRequirementsRequest collects protocol typealiases
Introduces rewrite rules for typealiases defined inside the protocol
itself.

Typealiases defined in protocol extensions do not participate
in the rewrite system, except for when they have the same name as
an associated type, as per the weird rule codified in the
TypeAliasRequirementsRequest for GSB compatibility.
2022-02-13 00:24:23 -05:00
Slava Pestov
d64fb39514 RequirementMachine: Introduce conditional requirements in desugaring 2022-02-10 17:23:54 -05:00
Slava Pestov
48ca87ddeb RequirementMachine: Handle type parameters in @_differentiable requirement inference 2022-02-10 17:23:54 -05:00
Slava Pestov
915ae67974 RequirementMachine: Factor out lookupMemberType() utility in RequirementLowering.cpp 2022-02-10 17:23:54 -05:00
Slava Pestov
0177f75473 AST: TypeBase::isConstraintType() answers true for ParameterizedProtocolType also 2022-02-03 13:27:24 -05:00
Slava Pestov
aa67c8bf8a Parametrized => parameterized 2022-02-03 13:27:24 -05:00
Slava Pestov
7dc36c3092 Merge pull request #40714 from slavapestov/parametrized-protocol-type
Parametrized protocol types
2022-01-26 11:44:29 -05:00
Slava Pestov
a416116094 RequirementMachine: Desugar ParametrizedProtocolType 2022-01-26 00:11:38 -05:00
Slava Pestov
7393c9c84f RequirementMachine: Remove unsound cycle-breaking hack 2022-01-25 21:28:52 -05:00
Slava Pestov
96122834fb RequirementMachine: getRuleForRequirement() supports relative terms 2022-01-25 00:32:25 -05:00
Slava Pestov
f480eeaf53 RequirementMachine: Factor out getRuleForRequirement() from RuleBuilder::addRequirement() 2022-01-25 00:32:25 -05:00
Slava Pestov
a2f2ffd1c2 RequirementMachine: Remove obsolete comment 2022-01-25 00:32:25 -05:00
Slava Pestov
56450af673 RequirementMachine: Record identity conformances in the property map 2022-01-11 21:43:55 -05:00
Slava Pestov
25cae6f479 RequirementMachine: Ignore requirements with ErrorTypes for GSB compatibility 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
f50c7c94df RequirementMachine: Tweak TypeAliasRequirementsRequest to match GSB on highly-invalid code 2021-12-20 17:59:31 -05:00
Slava Pestov
360fbc67bc RequirementMachine: Fix silly mistake in requirement inference
getFirstTypeRepr() asserts unless the RequirementRepr is a SameType
requirement. For type requirements we need to call getSubjectTypeRepr().
2021-12-10 00:49:46 -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