-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Define type filtering through an intersection operation #10781
Merged
straight-shoota
merged 8 commits into
crystal-lang:master
from
HertzDevil:refactor/restrict-type3
Jul 25, 2021
Merged
Define type filtering through an intersection operation #10781
straight-shoota
merged 8 commits into
crystal-lang:master
from
HertzDevil:refactor/restrict-type3
Jul 25, 2021
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
straight-shoota
approved these changes
Jun 18, 2021
asterite
approved these changes
Jun 18, 2021
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if we are in a PR freeze already, but otherwise feel free to merge this.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Refactors type filtering operations (used for
is_a?
andas
) into a new internal methodCrystal::Type.common_descendent
, a dual tocommon_ancestor
, in a similar vein as #10527. This is a prerequisite for eventually implementing #2404.The first commit mostly copies the type-versus-type portion of
Type#restrict
tocommon_descendent
, subsequent commits are further refactors. There is a slight performance boost here because the new intersection no longer needs aMatchContext
object (the context is never needed unless AST node restrictions are involved, e.g. to accessself
or bind free variables). Since type restrictions must behave like AST node restrictions for the time being, the old logic in restrictions.cr remains intact.The new method uses
#implements?
where the restriction code would use#restriction_of?
, and once again the context object is unneeded here. There is exactly one spec that fails due to this change, and I have confirmed that it would be fixed by #10779.This PR is purely a refactor; it does not make type filtering commutative yet, and it is relatively apparent where commutativity fails. It is up to a second PR to turn this method into a commutative greatest common descendent operation.