Skip to content

(towards #3124) Make the loop variable as child of Loop instead of an attribute#3473

Open
sergisiso wants to merge 10 commits into
masterfrom
loop_variable_as_child
Open

(towards #3124) Make the loop variable as child of Loop instead of an attribute#3473
sergisiso wants to merge 10 commits into
masterfrom
loop_variable_as_child

Conversation

@sergisiso

Copy link
Copy Markdown
Collaborator

No description provided.

@codecov

codecov Bot commented Jun 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (4216b9a) to head (aa0df55).

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #3473   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          395       395           
  Lines        55199     55212   +13     
=========================================
+ Hits         55199     55212   +13     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sergisiso sergisiso requested review from LonelyCat124 and arporter and removed request for arporter June 30, 2026 14:53
@sergisiso sergisiso self-assigned this Jun 30, 2026
@sergisiso

Copy link
Copy Markdown
Collaborator Author

@arporter @LonelyCat124 This is ready for review. Switching to in-tree loop references has been relatively painless, with the only oddity being the lfric null loops (which are loops that are not loops?) and have a dummy symbol as they don't exist after lowering anyway.

@LonelyCat124 LonelyCat124 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I had a very quick scan through and it looks to make sense. There's a leftover print statement and this opens up one other issue that wasn't previously addressed in the definition use chains.

Can you create a test using loop.variable.next_accesses() and check what the behaviour is? Once we know that I'll have a more detailed look through.

assert isinstance(dag, graphviz.Digraph)

result = my_file.read()
print(result)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

delete.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done

@sergisiso

Copy link
Copy Markdown
Collaborator Author

Can you create a test using loop.variable.next_accesses() and check what the behaviour is?

@LonelyCat124 loop.variable won't have a next_access() method because it points to the symbol self._children[0].symbol but next_access is a reference method. I kept it this way to keep all the existing loop.variable code unmodified (but I was considering adding a variable_reference or similar for the typical syntactic navigation methods that we offer).

Is this what you wanted to check or do you mean a test with loop.children[0].next_access()?

@LonelyCat124

LonelyCat124 commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

Is this what you wanted to check or do you mean a test with loop.children[0].next_access()?

@sergisiso I guess a test with loop.children[0].next_accesses() if .variable isn't the Reference (i didn't check that detail yet).

@sergisiso

Copy link
Copy Markdown
Collaborator Author

@LonelyCat124 I added the suggested check in references_test.py. Ready for another look

@LonelyCat124 LonelyCat124 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@sergisiso A few more changes
I think a variable_reference (or some better name) getter (rather than children[0]) is probably worthwhile to avoid random potential accesses to children[0].

Also I think Reference.is_write should be updated for these new References also?

if self.variable.name != "null":
var_accesses.add_access(Signature(self.variable.name),
AccessType.WRITE, self)
# This re

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This comment is unfinished.

- the second one represents the loop lower bound,
- the third one represents the loop upper bound,
- the forth one represents the step value
- and the fith one is always a PSyIR Schedule node containing the

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

fith/fifth

if len(self.children) < 4:
if len(self.children) < 5:
raise InternalError(
f"Loop is incomplete. It should have exactly 4 "

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Error message is out of date.

assert b.next_accesses()[0] == b

# Check the next_access of the loop variable
assert loop.children[0].next_accesses() == [loop.loop_body.children[0].rhs]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for this - can you add a test what happens if we have:

do i = 1, 100
   a(1) = a(1) + 1
end do

I'm not sure what will happen with the next_access for i and want to make sure it makes sense and we understand it.

Also in definition_use_chains_forward_dependence_test.py line 664 we have a test that returns a Loop (instead of its variable). Perhaps the best thing to do is to create an issue "Definition use chains return a Loop instead of the Loops' variable reference" (or similar) and we add a TODO to all the tests that return these loops (and maybe a note in the DUC docs with the TODO also?) since there is now a reference that could be pointed at.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants