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

AST/Type Specialization #1210

Open
andrew-johnson-4 opened this issue Feb 1, 2025 · 0 comments
Open

AST/Type Specialization #1210

andrew-johnson-4 opened this issue Feb 1, 2025 · 0 comments

Comments

@andrew-johnson-4
Copy link
Owner

This is the logical opposite of a macro

for x in y { z }

can be inefficient due to the iter -> Maybe<item> signature of the iterator. This leads to unnecessary creation of an intermediate Maybe object which can be quite expensive compared to a normal for loop. To fix this, some sort of AST transformation is necessary, but how should this be structured?

There could be some type of type directed rewrite rule here to optimize the AST in place.

let iter = y;
let continue-iter = true;
while continue-iter match &iter.next {
   Some(x) => z;
   None => continue-iter = false;
}

would be replaced with

let iter = y;
while non-zero(iter) match iter {
   LCons(x,rest) => (z; iter = rest;);
}

for lists. This operation needs to be aware of AST patterns or understand them enough to do transformations. This is a specialization from iter to List<_> for the for macro, however it can't really be done during preprocessing and should also be generalized for code patterns that don't use a macro.

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

1 participant