(Towards #3367) def use chain update for assignments.#3399
(Towards #3367) def use chain update for assignments.#3399LonelyCat124 wants to merge 30 commits intomasterfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3399 +/- ##
========================================
Coverage 99.96% 99.96%
========================================
Files 391 391
Lines 54583 54689 +106
========================================
+ Hits 54564 54670 +106
Misses 19 19 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
I resolved the last of the FIXMEs. I need to do some tests with loops and things where I check I get the same results for Assignment.next_accesses/previous_accesses that I would calling it for all of the References individually. |
|
Having an issue with this code: For the single reference case, it doesn't find b=1 for a forward check for the original |
…t shows some easy cases for forward accesses
|
Fixed the previous case, but immediately created another non-equivalent case where I do as the def use chains output for b when the full statement is input goes past the |
|
I fixed the above case going forwards, so things are looking like they're getting there. I suspect there will be issues going backwards that I'll need to match as well. |
|
NEMO ITs failing in the async runs. I need to manually look at whats happening - I think barriers are now being missed, which if there's not a simple solution to it might need a full DUC rewrite 😢 |
arporter
left a comment
There was a problem hiding this comment.
Thanks Aidan, that is extremely complex code! I've had a look through most of it except the tests so far. You'll see I'm a bit confused about the correct way of determining the "start point" and "end point". Apart from that, it's just minor things.
| self._start_point = self._reference_abs_pos | ||
| # Find the highest abs position, as all of these are | ||
| # contained in the same parent. | ||
| self._start_point = max(list(self._references_abs_pos.values())) |
There was a problem hiding this comment.
As in, we only start the search after the last of the provided references?
There was a problem hiding this comment.
Yes, I felt like for a next_accesses on a statement such as b = a + a we wouldn't want to return the second reference to a. I guess in theory with how the chains are currently setup for an example like b = a + a + a you could provide a list with only b and the first and last a references in which case we'd miss the middle a, but I think that isn't a real case so I'm not worried.
There was a problem hiding this comment.
That makes sense, thanks. Worth saying this (the first sentence) in a comment.
| self._stop_point = self._reference_abs_pos | ||
| # Find the max abs position, as all of these are | ||
| # contained in the same parent. | ||
| self._stop_point = min(list(self._references_abs_pos.values())) |
There was a problem hiding this comment.
You use min but say "max" in the comment :-)
There was a problem hiding this comment.
In fact, as with my comments on the start_point, is min correct?
There was a problem hiding this comment.
Updated the comment - I think min is correct as discussed in the previous comment, but I could be persuaded either way.
There was a problem hiding this comment.
Please add a comment as discussed on the previous comment.
|
@arporter Review comments addressed I think. I've tried to explain my reasoning for using max or min, but happy to change it if you disagree with what the result should be from the DUC. |
…into 3367_def_use_chain_update
|
I guess to also note this only improves the behaviour for Assignments, and the issue says statements, so I'm going to change this to towards 3367 and update the title and fix that later. |
arporter
left a comment
There was a problem hiding this comment.
Thanks very much Aidan. I've made it all the way through now and it just comments and tidying left to do :-)
(ITs were all green bar a signal 11 on the LFRic tests which I've just restarted.)
| ) | ||
| control_flow_nodes.append(None) | ||
| index = len(chains) | ||
| control_flow_nodes.insert(index, None) |
There was a problem hiding this comment.
I seem to be generally confused here. You get the length of chains and use that as the point at which to insert into control_flow_nodes - I don't think I'd fully understood that last time. Please add a comment to explain - this could also go some way to investigating whether (future) refactoring would help.
| ) | ||
| control_flow_nodes.append(None) | ||
| index = len(chains) | ||
| control_flow_nodes.insert(index, None) |
There was a problem hiding this comment.
I'm not advocating for a re-write of anything at this stage - or at least, not in this PR. You understand the code a lot better than I do so if you think it would simplify things then that would be great, otherwise, don't worry.
| self._start_point = self._reference_abs_pos | ||
| # Find the highest abs position, as all of these are | ||
| # contained in the same parent. | ||
| self._start_point = max(list(self._references_abs_pos.values())) |
There was a problem hiding this comment.
That makes sense, thanks. Worth saying this (the first sentence) in a comment.
| self._stop_point = self._reference_abs_pos | ||
| # Find the max abs position, as all of these are | ||
| # contained in the same parent. | ||
| self._stop_point = min(list(self._references_abs_pos.values())) |
There was a problem hiding this comment.
Please add a comment as discussed on the previous comment.
| sig = a_3.get_signature_and_indices()[0] | ||
| duc = DefinitionUseChain( | ||
| a_3, control_flow_region=[routine] | ||
| [a_3], control_flow_region=[routine] |
There was a problem hiding this comment.
You don't need to put a_3 in a list now.
|
|
||
| psyir = fortran_reader.psyir_from_source(code) | ||
| references = psyir.walk(Reference) | ||
| next_accesses = references[4].next_accesses() |
There was a problem hiding this comment.
Please add some comments to explain which bits of the code are being examined and found.
| '''Test the DUCs give the same results for multiple inputs as each of | ||
| the inputs individually. | ||
| ''' | ||
|
|
There was a problem hiding this comment.
It's a small thing but you could reduce duplication in the fixture by doing:
code = f"subroutine test\n{code}\nend subroutine test"| '''Test the DUCs give the same results for multiple inputs as each | ||
| of the inputs individually. | ||
| ''' | ||
| psyir = fortran_reader.psyir_from_source(code) |
| assign = psyir.walk(Assignment)[-1] | ||
|
|
||
| all_refs = assign.walk(Reference) | ||
| lhs_ref = all_refs[0] # First Reference is lhs a |
There was a problem hiding this comment.
Probably worth sanity-checking this in case of future changes, e.g. assert lhs_ref.symbol.name == "a" and same for rhs_ref.
| assign = psyir.walk(Assignment)[0] | ||
|
|
||
| all_refs = assign.walk(Reference) | ||
| lhs_ref = all_refs[0] # First Reference is lhs a |
There was a problem hiding this comment.
Pls add sanity checks that the refs are the ones you expect, e.g. assert lhs_ref.symbol.name == "a"
|
@arporter Ready for another look. |
I now have this at a stage that it can handle multiple inputs and behave somewhat sensibly. I haven't yet finished, as it currently requires inputs to be members of the same parent, but I think we want them to simply share an ancestor statement.
There are a few remaining FIXMEs for things that I don't know what they were preventing previously and didn't cause any previous test failures, but presumably were things I thought mattered previously (though I did also just find some code that didn't matter so...). I need to do more testing for multi-inputs, but I think I might do that through Statement.next_accesses or some similar option.