Skip to content

Three more associated type inference fixes #71539

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 11, 2024

Conversation

slavapestov
Copy link
Contributor

@slavapestov slavapestov commented Feb 11, 2024

Fixes rdar://problem/122584912, rdar://problem/122574126, rdar://problem/122586992, rdar://problem/122588328 (I count four fixes, not three, but whatever).

A minimal Sequence conformance only needs to define an Iterator type,
with the Element type witness inferred from the Element of the iterator.

This trick didn't always work if the conforming type conformed to other
protocols with declared same-type requirements involving Self.Element.

Refine the heuristic introduced in 23599b6
to prefer abstract type witnesses in the current protocol, even if there
is a shorter one in another protocol.

Fixes rdar://problem/122574126, rdar://problem/122588328.
This is part of the -disable-experimental-associated-type-inference
code path for abstract type witnesses, but I want to use it in
another place.

- Look in local conformances only, instead of all protocols.
  Philosophically, we want associated type inference to reason
  about each nominal type declaration or extension as a single
  unit.

- Look for an abstract witness in any protocol that declares an
  associated type of the same name, not just a protocol that
  inherits from the associated type's protocol.
If a protocol fixes an associated type of another protocol via a
concrete same-type requirement, we should make use of this fact
immediately when building the associated type inference constraint
system.

Previously we only introduced fixed type bindings at the end, and
only in the 'abstract type witness' inference path, which we
reach if a type witness cannot be resolved by looking at value
witnesses alone.

This meant that associated type inference would find valid or
ambiguous solutions which would then be contradicted by the
ensureRequirementsAreSatisfied() check.

Longer term, what I want to do is actually build the type witness
system upfront, and also teach the constraint solver here about
merging equivalence classes, so that we can split them again when
backtracking. This will combine the best of both approaches.

Fixes rdar://problem/122586992.
@slavapestov slavapestov force-pushed the assoc-type-regression-fixes-2 branch from 73b191b to 23ef893 Compare February 11, 2024 04:56
@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

@slavapestov slavapestov merged commit eb1bdee into swiftlang:main Feb 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant