Skip to content

Fine-grained: Fix AST merge issues #4652

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 23 commits into from
Mar 1, 2018
Merged

Fine-grained: Fix AST merge issues #4652

merged 23 commits into from
Mar 1, 2018

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Feb 28, 2018

This fixes all but one AST merge checker test failures. The remaining
one seems tricky to fix so I'll leave it for later.

I decided not to add tests for things that can be caught using the
merge checker. We'll have to run the merge checker periodically
since it's not enabled by default in the test suite.

Also process overloaded and non-overloaded functions more
consistently in AST merge.
They can appear in UnboundType instances.
Not sure yet if this actually fixes any user-visible issues.
There were two issues:

* The `info` attribute of the corresponding `ClassDef`
  wasn't updated.

* `FuncDef` objects within the related `TypeInfo` weren't
  processed, since they are only accessible through a
  symbol table. Functions in normal classes are accessible
  by traversing the AST, in contrast.
This could at least leak memory. Not sure if this could
cause invalid type checking results.
The type map could contain stale references to AST nodes.
Not sure if this is necessary but it might be.
The relevant nodes won't be exposed externally.
@JukkaL JukkaL requested a review from msullivan February 28, 2018 14:38
Copy link
Collaborator

@msullivan msullivan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

What is the one remaining failure?

mypy/types.py Outdated
[arg, ...] in Callable[[arg, ...], ret]. This is not a real type
but a syntactic AST construct.
but a syntactic AST construct. UnboundTypes can also have TypeList
types before they are processed into Callable type.s
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo

@@ -1503,6 +1503,11 @@ def visit_type_type(self, t: TypeType) -> T:
def visit_forwardref_type(self, t: ForwardRef) -> T:
raise RuntimeError('Internal error: unresolved forward reference')

def visit_type_list(self, t: TypeList) -> T:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can other sorts of "synthetic" types show up in our traversal?

Would it be a better approach in the future to make the merger a synthetic type traverser?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm looks like we could be hitting other such types as well. Maybe making it a "synthetic type visitor" is the right thing to do. I'll consider making a follow-up PR about this.

On the other hand, we should perhaps only have one sort of type visitor. I don't really see the benefit of having two sorts of visitors.

@JukkaL
Copy link
Collaborator Author

JukkaL commented Mar 1, 2018

The remaining failure is testFineGrainedCallable.

@JukkaL JukkaL merged commit 7264ae5 into master Mar 1, 2018
@JukkaL JukkaL deleted the fg-merge-fixes branch March 1, 2018 15:36
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
This fixes all but one AST merge checker test failures. The remaining
one (testFineGrainedCallable) seems tricky to fix so I'll leave it for later.

I decided not to add tests for things that can be caught using the
merge checker. We'll have to run the merge checker periodically
since it's not enabled by default in the test suite.
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.

2 participants