Skip to content

Handle loops in analysis of assigned vars #925

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 5 commits into from
Jul 27, 2023
Merged

Handle loops in analysis of assigned vars #925

merged 5 commits into from
Jul 27, 2023

Conversation

gramalingam
Copy link
Collaborator

The analysis function "assigned_vars" was not handling loops. Fix this.

Should fix issue #879

See also PR #909

@codecov
Copy link

codecov bot commented Jul 26, 2023

Codecov Report

Merging #925 (45e9a3d) into main (d77f001) will decrease coverage by 0.07%.
The diff coverage is 66.66%.

@@            Coverage Diff             @@
##             main     #925      +/-   ##
==========================================
- Coverage   76.91%   76.85%   -0.07%     
==========================================
  Files         112      112              
  Lines       13669    13723      +54     
  Branches     1397     1405       +8     
==========================================
+ Hits        10514    10547      +33     
- Misses       2804     2826      +22     
+ Partials      351      350       -1     
Files Changed Coverage Δ
onnxscript/analysis_test.py 53.84% <42.50%> (-4.41%) ⬇️
onnxscript/analysis.py 88.59% <100.00%> (+1.69%) ⬆️
onnxscript/converter.py 80.97% <100.00%> (ø)
onnxscript/converter_test.py 84.48% <100.00%> (+0.33%) ⬆️

if isinstance(stmt, ast.Break):
return set()
if ast_utils.is_print_call(stmt):
return set()
if isinstance(stmt, list):
return assigned_in_block(stmt)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we test this too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is tested by every test for this function, since parse_tree.body is a list of statements. In fact, this extension exists primarily for enabling the unit tests.

Copy link
Collaborator

Choose a reason for hiding this comment

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

hmm strange.
image

coverage shows only this line is not tested

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let me print some things here to see

Copy link
Collaborator

Choose a reason for hiding this comment

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

Duplicate of line 77?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch, thanks!

Comment on lines +1105 to +1109
live_defs = list(
stmt.live_out.intersection(analysis.assigned_vars(stmt, self.message))
)
else:
live_defs = list(analysis.defs(stmt))
live_defs = list(analysis.assigned_vars(stmt, self.message))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would be good to explain this logic with a comment?

Copy link
Collaborator Author

@gramalingam gramalingam Jul 27, 2023

Choose a reason for hiding this comment

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

Good question. I didn't add it, and it seems questionable to me. I need to check it out, I suspect it was added in some case where the liveness analysis had not run for some reason. but the fix should probably be something else.

Copy link
Collaborator

@justinchuby justinchuby left a comment

Choose a reason for hiding this comment

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

LGTM w/ duplicated logic removed

@gramalingam gramalingam merged commit 4e7e421 into main Jul 27, 2023
@gramalingam gramalingam deleted the rama/if_loop branch July 27, 2023 21:54
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