-
Notifications
You must be signed in to change notification settings - Fork 18
IL Traversals #212
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
base: main
Are you sure you want to change the base?
IL Traversals #212
Conversation
|
@nomeata what do you think? This should help with the creation of the passes I think, especially since the traversal functions can be called at any point of the AST. |
|
I’m all for it. I wonder how general these will have to be – in particular when a traversal needs to pass a locally updated env around. But even something that helps in 80% of passes is useful. Or maybe your vision is to re-start a new traversal locally when updating some local environment? |
| in | ||
| f typ @ traverse_list | ||
|
|
||
| and collect_exp c e = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The collect functions could use an identity transform with a local mutable ref to collect the list, to avoid some duplication here. Not sure if it is worth it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think at that point you could just use iter.ml couldn't you? edit: Ah I see what you mean, but either way it would functionally the same to iter.ml, which I think we wouldn't want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly most of these traversals (except transform) could be done by iter.ml, but at least it provides more flexibility on whether we want to do a more functional approach to the traversals.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, right. I do think we should have these traversals, just saying that they could be implemented themselves using iter maybe? No big deal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough! I will probably do that as it will reduce the duplication by a good amount.
I would say my vision was more to re-start the traversal locally, as I think a general traversal with local updates would start to get very messy. |
|
Ended up merging the exists, forall, and collect into 1 generic traversal where you have to supply the default value and compose function. Simplified Sub, SubExpansion, Totalize, aliasDemut, and Uncaseremoval with this new approach |
… functions can decide to stop the traversal.
After writing many passes, I think it makes sense to attempt to refactor them to avoid duplicate logic with the traversals. Inspired by AL's IL_walk.ml, it has been extended to be more general and have the following traversals:
Each traversal has a record type that dictates the custom functions that can be modified to make the specific traversal you need. This can be extended to however many custom functions are needed. This can also be extended to have the custom functions return a bool to indicate whether to stop traversal at the specific branch of the AST.
Currently a draft to first see if the idea is worth it.
(Also, would probably want to merge collect, exists, and forall into a more generic traversal)