Skip to content

[RequirementMachine] Substitution simplification records projections #41381

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

Conversation

slavapestov
Copy link
Contributor

@slavapestov slavapestov commented Feb 15, 2022

The Requirement Machine had three components that did similar things:

  • The simplifyLeftHandSideSubstitutions() pass ran during completion, simplifying rules like T.[concrete: G<Y>] => T down to T.[concrete: G<X>] => T, given Y => X
  • The concretelySimplifyLeftHandSideSubstitutions() pass ran after property map construction, simplifying rules like T.[concrete: G<X>] => T down to T.[concrete: G<Int>] => T, given X.[concrete: Int] => X
  • The PropertyMap::unifyConcreteTypes() operation would compute the meet of concrete type terms, so for example given T.[concrete: G<X>] => T and T.[concrete: G<Y>] => T, it would record an induced rule Y => X.

There were two problems here:

  • The first two passes are almost identical; the difference is that the second one can also replace subterms of a concrete type with concrete types, whereas the first one only rewrites type parameters appearing in substitutions to other type parameters. This PR refactors concretelySimplifyLeftHandSideSubstitutions() so that it can work without a PropertyMap, in which case it operates like the old simplifyLeftHandSideSubstitutions(), allowing simplifyLeftHandSideSubstitutions() to be removed entirely.
  • All three passes would record a loop that would derive the concrete type rules from each other using the induced rules on the substitutions, but only the last one would record rewrite loops expressing the induced rules in terms of the concrete type rules. This meant that in some cases, we would be unable to eliminate the induced rule.

Additionally, this PR fixes a couple of unrelated issues where Sema would emit duplicate diagnostics when resolving TypeReprs; in particular, this would manifest when running tests with -requirement-machine-inferred-signatures=verify, which resolves each TypeRepr appearing in a where clause twice (once for the GSB and once for the RequirementMachine).

When emitting a diagnostic, mark the TypeRepr as invalid and
return an ErrorType to ensure that the diagnostic is not
emitted again, and to muffle downstream diagnostics.
…Substitutions()

Now that the PropertyMap to the concrete simplification version is optional,
we can just pass nullptr here to get the old behavior where type terms are
simplified to canonical anchors and no concrete simplification is performed.
The inverted form no longer has to replace substitutions; we use
the inverted form of DecomposeConcrete for that. So just assert
that the substitutions are equal.
…riends from PropertyUnification.cpp to RewriteSystem.cpp
- Prefer rewrite loops not involving Decompose
- Prefer more deeply nested concrete types
@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test macOS

@slavapestov slavapestov marked this pull request as ready for review February 15, 2022 16:59
@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test macOS

1 similar comment
@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test macOS

@slavapestov slavapestov changed the title RequirementMachine: Substitution simplification records projections [RequirementMachine] Substitution simplification records projections Feb 16, 2022
@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test macOS

1 similar comment
@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test macOS

@slavapestov
Copy link
Contributor Author

swiftlang/llvm-project#3952
@swift-ci Please smoke test macOS

@slavapestov slavapestov merged commit 1665c57 into swiftlang:main Feb 16, 2022
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