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

NodeCountMapper doesn't count nodes inside functions #513

Open
majosm opened this issue Jul 3, 2024 · 0 comments
Open

NodeCountMapper doesn't count nodes inside functions #513

majosm opened this issue Jul 3, 2024 · 0 comments

Comments

@majosm
Copy link
Collaborator

majosm commented Jul 3, 2024

Comparing my concatenation changes with main reminded me that NodeCountMapper doesn't currently accumulate node counts from functions into the overall count. It should be given a map_function_definition method that does something similar to CallSiteCountMapper:

@memoize_method
def map_function_definition(self, /, expr: FunctionDefinition,
*args: Any, **kwargs: Any) -> None:
if not self.visit(expr):
return
new_mapper = self.clone_for_callee(expr)
for subexpr in expr.returns.values():
new_mapper(subexpr, *args, **kwargs)
self.count += new_mapper.count
self.post_visit(expr, *args, **kwargs)

I wonder if the default map_function_definition implementation in CachedWalkMapper should be disabled, to avoid bugs like this? Maybe a default implementation could be provided in a separate method, e.g. _basic_map_function_definition, for convenience in mappers that don't need special behavior.

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

No branches or pull requests

1 participant