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

Container method to get routine by name #2762

Open
sergisiso opened this issue Oct 28, 2024 · 3 comments
Open

Container method to get routine by name #2762

sergisiso opened this issue Oct 28, 2024 · 3 comments

Comments

@sergisiso
Copy link
Collaborator

While doing #2739 some PSyKAl transformation scripts have:

invoke = psy.invokes.get("invoke_propagate_perturbation")
schedule invoke.schedule
# Modify schedule

With the new transformation signature this needs to be updated to:

for subroutine in psyir.walk(Routine):
    if subroutine.name == "invoke_propagate_perturbation":
        # Modify subroutine

Which I am not totally satisfied because it is more verbose, adds indentations, and even worst, it doesn't fail if the named routine does not exist. It would be good to add a generic Conatiner.get method to get routines by name or fail:

subroutine = psyir.children.get("invoke_propagate_perturbation")
# Modify subroutine

The first 'children' is unrelated, it is for going to the FileContainer to the Module also introduced in the mentioned PR.

Some alternatives are:

subroutine = psyir.children.routine("invoke_propagate_perturbation")
subroutine = psyir.children["invoke_propagate_perturbation"]
@sergisiso
Copy link
Collaborator Author

sergisiso commented Oct 29, 2024

Currently I can also do:

name = "invoke_propagate_perturbation"
subroutine = [x for x in psyir.children[0].children if x.name == name][0]

@arporter
Copy link
Member

Container currently has resolve_routine(name) and find_routine_psyir(name). Are these what you want (possibly with a nicer name for the last one)?

@sergisiso
Copy link
Collaborator Author

sergisiso commented Oct 29, 2024

Those methods implement all the 'language' knowledge regarding visibility, imports, interfaces, ... I was thinking something simpler, something akin to the tree semantic navigation methods that we have, so that we can navigate the tree by name when it makes sense.

E.g. "go to the lhs of the 3rd statement of the "mysub" routine in the first module" would be:
target = psyir[0]["mysub"][2].lhs

Note that in this example I navigate 2 container, one by index-order [0] and one by name ["mysub"]. But I am just traversing the tree, I am not interested in language logic here.

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

2 participants