Skip to content
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

Foundation for fine-grained incremental checking #2838

Merged
merged 45 commits into from
Apr 5, 2017
Merged

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Feb 9, 2017

Currently fine-grained incremental checking can only be run through unit tests -- there's no interactive way to use it. It only supports a small Python subset, and it doesn't support all kinds of modifications.

mypy/server/update.py is the main entry point and has more documentation.

@@ -0,0 +1,495 @@
-- Test cases for AST merge (user for fine-grained incremental checking)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The important thing here is that we test that identities of certain nodes are preserved across merge. <id> suffixes represent object identities (somewhat similar to id(x)), and they only make sense within a single test case. Two things within a single test case that share an id have the same identity, and two things with different ids have different identities.

@JukkaL
Copy link
Collaborator Author

JukkaL commented Feb 9, 2017

The travis failures look strange. I'll investigate them tomorrow.

* If one of the types is not valid for whatever reason, they are
considered different.

* Sometimes require types to be structurally identical, even if the
Copy link
Member

Choose a reason for hiding this comment

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

typo "if the are" -> "if they are"

@@ -0,0 +1,49 @@
"""Strip AST from from semantic and type information."""
Copy link
Member

Choose a reason for hiding this comment

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

typo: "from from" -> "from"

@JukkaL
Copy link
Collaborator Author

JukkaL commented Mar 2, 2017

Rebased and squashed most commits to help rebasing. Still trying to get a passing travis build.

self.pass_num += 1
todo = self.deferred_nodes
if not todo:
todo = self.deferred_nodes
Copy link
Member

Choose a reason for hiding this comment

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

Hm, what if todo and self.deferred_nodes are both non-empty?

mypy/checker.py Outdated
@@ -568,7 +584,7 @@ def is_implicit_any(t: Type) -> bool:
for i in range(len(typ.arg_types)):
arg_type = typ.arg_types[i]

ref_type = self.scope.active_class()
ref_type = self.scope.active_self_type() # type: Type
Copy link
Member

Choose a reason for hiding this comment

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

Optional[Type]

mypy/checker.py Outdated

def __init__(self, module: MypyFile) -> None:
self.stack = [module]

def top_function(self) -> Optional[FuncItem]:
def top_function(self) -> Optional[FuncDef]:
for e in reversed(self.stack):
if isinstance(e, FuncItem):
Copy link
Member

Choose a reason for hiding this comment

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

FuncDef

self.pop_target_component()

def push_target_component(self, name: str) -> None:
if self.target and not self.function_or_member[-1]:
Copy link
Member

Choose a reason for hiding this comment

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

Can you explain the relationship between target and function_and_member?

def refresh_top_level(self, file_node: MypyFile) -> None:
"""Reanalyze a stale module top-level in fine-grained incremental mode."""
for d in file_node.defs:
if not isinstance(d, (FuncItem, ClassDef)):
Copy link
Member

Choose a reason for hiding this comment

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

TODO: analyze class bodies?

class B(C): pass
[file m.py.2]
class C: pass
class B: pass
Copy link
Member

Choose a reason for hiding this comment

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

Preserve C.g.

mypy/semanal.py Outdated
defn.defs.accept(self)

@contextmanager
def analyze_class_body(self, defn: ClassDef) -> Iterator[None]:
Copy link
Member

Choose a reason for hiding this comment

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

Better name??

JukkaL added 22 commits April 3, 2017 15:18
* Add AST diff
* Add fine-grained dependency generation
* Add AST merge for merging old and new ASTs for a module
* Update AST dump to show various object identities
* Add various tests
In fine-grained incremental mode keep reporting errors for targets
with errors even if the targets weren't explicitly triggered during
successive iterations. We currently repeatedly type check these
targets. Alternatively, we could perhaps just keep generating the
errors without actually re-type-checking the targets, but there's a
risk that it will be hard to always do this correctly, so we are
starting with this simple-minded approach which is good enough
for now.
* Use up-to-date type maps instead of the global type map which will
  get out of sync.

* Update dependencies of reprocessed targets.
Also change order of processing stale nodes in fine-grained
incremental to be more similar to normal mode.
A class target covers the entire class body and all definitions
within it.
@@ -71,6 +71,9 @@ def run_case(self, testcase: DataDrivenTestCase) -> None:
a.append('==')
a.extend(new_messages)

# Normalize paths in test output (for Windows).
a = [line.replace('\\', '/') for line in a]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess this doesn't really matter as much, but I am always hesitant to use unix forward slash on Windows, I think it is okay here as long as it is internal and the file itself is never written to disk, but to avoid bugs I always favor the platform specific separator. Just a thought.

@JukkaL JukkaL changed the title [WIP] Fine-grained incremental checking Foundation for fine-grained incremental checking Apr 5, 2017
@gvanrossum gvanrossum merged commit 737434b into master Apr 5, 2017
@gvanrossum gvanrossum deleted the fine-grained branch April 5, 2017 15:20
@pkch pkch mentioned this pull request Apr 13, 2017
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.

4 participants