Fine-grained: Support NewType and reset subtype caches#4656
Merged
Conversation
NewType work highlighted an issue with subtype caches with stale information leaking, and this fixes that issue as well. We reset the subtype cache in two places: * When calculating the MRO; we reset caches of all base classes as well. * When merging a new version of a TypeInfo, which may have a different MRO; we reset all caches of base classes in the old MRO, as they might no longer be supertypes.
msullivan
approved these changes
Mar 1, 2018
Collaborator
msullivan
left a comment
There was a problem hiding this comment.
One question, but looks good
| self.is_enum = self._calculate_is_enum() | ||
| # The property of falling back to Any is inherited. | ||
| self.fallback_to_any = any(baseinfo.fallback_to_any for baseinfo in self.mro) | ||
| self.reset_subtype_cache() |
Collaborator
There was a problem hiding this comment.
I don't fully understand why this is necessary (though it certainly isn't /wrong/). Adding a new subclass shouldn't invalidate any of the caches, since they store only positive information?
Collaborator
Author
There was a problem hiding this comment.
I think that some changes in generic base classes may require this. Say, originally the base class was C[A] and after update it is C[B]. This would change the subtype relation even though the MRO is unchanged. If we are doing a refresh of the class there would be no AST merge so without this the subtype cache would not get emptied.
carljm
added a commit
to carljm/mypy
that referenced
this pull request
Mar 6, 2018
* master: New files shouldn't trigger a coarse-grained rebuild in fg cache mode (python#4669) Bump version to 0.580-dev Update revision history for 0.570 (python#4662) Fine-grained: Fix crashes when refreshing synthetic types (python#4667) Fine-grained: Support NewType and reset subtype caches (python#4656) Fine-grained: Detect changes in additional TypeInfo attributes (python#4659) Fine-grained: Apply semantic analyzer patch callbacks (python#4658) Optimize fine-grained update by using Graph as the cache (python#4622) Cleanup check_reverse_op_method (python#4017) Fine-grained: Fix AST merge issues (python#4652) Optionally check that we don't have duplicate nodes after AST merge (python#4647)
yedpodtrzitko
pushed a commit
to kiwicom/mypy
that referenced
this pull request
Mar 15, 2018
NewType work highlighted an issue with subtype caches with stale information leaking, and this fixes that issue as well. We reset the subtype cache in two places: * When calculating the MRO; we reset caches of all base classes as well. * When merging a new version of a TypeInfo, which may have a different MRO; we reset all caches of base classes in the old MRO, as they might no longer be supertypes.
This file contains hidden or 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
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.
NewType work highlighted an issue with subtype caches with stale
information leaking, and this fixes that issue as well. We reset the
subtype cache in two places:
When calculating the MRO; we reset caches of all base classes as
well.
When merging a new version of a TypeInfo, which may have a
different MRO; we reset all caches of base classes in the old
MRO, as they might no longer be supertypes.