Commit Graph

26 Commits

Author SHA1 Message Date
Slava Pestov
cd118ea19b RequirementMachine: Don't filter out unavailable Sendable conformance if allowMissing=true
Fixes rdar://problem/94456989.
2022-06-22 00:48:59 -04:00
Slava Pestov
bd46bdaaaa AST: Narrow the filtering of unavailable conformances to Sendable only
Remove the allowUnavailable parameter to lookupConformance(), and instead
explicitly check the result for hasUnavailableConformance() in the places
where we used to pass 'false'.

Also, narrow down this check in those places to the Sendable protocol
only, fixing a regression with Hashable conformance synthesis.

Fixes rdar://problem/94460143.
2022-06-14 21:24:08 -04:00
Slava Pestov
9695b1957a RequirementMachine: Concrete contraction needs to substitute the parent type of a subject type sometimes
If you have generic parameters <T, U> and requirements of the form:

- T : P
- T == ConcreteType<U>
- T.[P]U : SomeClass
- T.[P]U : SomeProto

And furthermore SomeClass does not conform to SomeProto, we can't leave
`T.[P]U : SomeClass` unsubstituted; we still have to replace `T` with
`ConcreteType<U>` to transform the latter two requirements into:

- U : SomeClass
- U : SomeProto

"Concrete contraction" is easily the hackiest part of the Requirement
Machine; I need to come up with a more principled solution for the
problem that it solves sooner or later.

Fixes rdar://problem/94150249.
2022-06-08 00:40:30 -04:00
Doug Gregor
904a2ff64c Allow unavailable conformances to non-Sendaable protocols during contraction
Refusing to acknowledge unavailable conformances at this point in the
requirement machine doesn't allow us to make use of unavailable
conformances from unavailable contexts, something which code currently
depends on. Limit the new filtering behavior to `Sendable` conformances
where we need them, as a narrow fix for this regression. We'll revisit
the approach here later.

Fixes rdar://94154905.
2022-06-02 13:24:37 -07:00
Doug Gregor
c9c50b4ae0 [Requirement machine] Ignore unavailable conformances on superclass constraints.
When determining whether a superclass conforms to a particular protocol,
skip unavailable conformances. This way, we don't minimize away a
constraint that might only apply to subclasses of the specified
superclass.

Fixes rdar://91853658.
2022-05-27 13:09:15 -07:00
Slava Pestov
75f6682969 RequirementMachine: Enable concrete contraction for nested type parameters
Fixes rdar://problem/91594361.
2022-05-09 21:21:35 -04:00
Slava Pestov
e5782a188d RequirementMachine: Refactor concrete contraction
Clean up the different cases by passing a 'Position' enum to
substTypeParameter().

Also generalize it to work with arbitrary type parameters instead
of generic parameters only, but leave this code path disabled
for now.
2022-05-09 21:21:35 -04:00
Slava Pestov
9170378d25 RequirementMachine: Fix handling of Sendable conformances for superclass requirements
Don't set allowMissing to true when checking conformance of a superclass requirement
to a protocol, since this prevents us from being able to express something like
'T : C, T : Sendable' to mean 'T can be any subclass of C which is also Sendable'.

Fixes rdar://problem/91530343.
2022-04-11 14:52:32 -04:00
Doug Gregor
45c7d6f4b8 Allow missing Sendable conformances when type parametesr are made concrete.
Fixes rdar://91174106.
2022-04-08 15:42:33 -07:00
Slava Pestov
41c04c5f7b RequirementMachine: Add a comment explaining a recent change to concrete contraction 2022-04-04 12:41:57 -04:00
Slava Pestov
02bfb79935 RequirementMachine: Concrete contraction discards errors from inferred requirements 2022-04-01 23:55:19 -04:00
Slava Pestov
175d5860cf RequirementMachine: Don't substitute unsatisfied layout requirements in concrete contraction 2022-04-01 23:06:19 -04:00
Slava Pestov
d385b73cd6 RequirementMachine: Plumb source locations through concrete contraction 2022-04-01 22:33:03 -04:00
Slava Pestov
ac7efc1de7 Merge pull request #41935 from slavapestov/rqm-concrete-contraction-unrelated-alias
RequirementMachine: Another silly GenericSignatureBuilder compatibility hack for concrete contraction
2022-03-21 22:44:40 -04:00
Slava Pestov
9f9b81b156 RequirementMachine: Explicitly specify SmallVector size 2022-03-21 16:59:03 -04:00
Slava Pestov
dc82433c78 RequirementMachine: Another silly GenericSignatureBuilder compatibility hack for concrete contraction 2022-03-21 16:31:18 -04:00
Slava Pestov
b0a4efba54 RequirementMachine: Fix lookupConcreteNestedType() to cope with opaque archetypes 2022-03-17 17:45:52 -04:00
Slava Pestov
d90e8122aa RequirementMachine: Factor out duplicated lookupConcreteNestedType() utility 2022-03-16 13:26:37 -04:00
Slava Pestov
8176b61d60 RequirementMachine: Tweak debug output and add an assertion 2022-03-16 12:24:10 -04:00
Slava Pestov
64f049a3d8 RequirementMachine: Fix ConcreteContraction::substTypeParameter() for non-nominal base type
We can handle a non-nominal base type here as long as the DependentMemberType
we're substituting this into is resolved.
2022-03-03 14:05:02 -05:00
Slava Pestov
589c1a3c11 RequirementMachine: A couple of improvements to concrete contraction
- Allow duplicate concrete type and superclass requirements on the
  same generic parameter, as long as they're identical. This can
  arise if requirement inference infers a requirement which the
  user then explicitly re-states.

- If duplicate requirements are found that name different types, drop
  only that generic parameter from consideration without giving up
  entirely.

- If a generic parameter is subject to both a concrete type and a
  superclass requirement, proceed with the concrete type requirement
  since it is more specific instead of giving up.
2022-03-03 14:05:02 -05:00
Slava Pestov
0d094241d8 RequirementMachine: Fix rogue debug output when debug flag was disabled 2022-03-03 14:05:02 -05:00
Slava Pestov
bd5a437c39 Merge pull request #41615 from slavapestov/rqm-protocol-superclass-circular-conformance
RequirementMachine: Fix minimization when protocol is constrained to a class that conforms to the protocol
2022-03-02 12:17:12 -05:00
Slava Pestov
5281426569 RequirementMachine: Fix minimization when protocol is constrained to a class that conforms to the protocol
Consider this example:

    protocol P : C {}
    class C : P {}

    <T where T : P>

The GenericSignatureBuilder thinks the minimized signature is
<T where T : P>. The RequirementMachine would minimize it down to
<T where T : C>. The latter is more correct, since the conformance
here is concrete and no witness table needs to be passed in at
runtime, however for strict binary compatibility we need to produce
the same signature as the GenericSignatureBuilder.

Accomplish this by changing the minimal conformances algorithm to
detect "circular concrete conformance rules", which take the form

    [P].[concrete: C : Q]

Where Q : P. These rules are given special handling. Ordinarily a
protocol conformance rule is eliminated before a concrete conformance
rule; however concrete conformances derived from circular
conformances are considered to be redundant from the get-go,
preventing protocol conformances that can be written in terms of
such concrete conformances from themselves becoming redundant.

Fixes rdar://problem/89633532.
2022-03-02 03:13:41 -05:00
Slava Pestov
8570b5656c RequirementMachine: Fix compile error on Linux 2022-03-01 00:56:43 -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