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

Create Functor Ast to control interleaving #4954

Closed
Tracked by #4594
jfecher opened this issue May 1, 2024 · 1 comment
Closed
Tracked by #4594

Create Functor Ast to control interleaving #4954

jfecher opened this issue May 1, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@jfecher
Copy link
Contributor

jfecher commented May 1, 2024

Problem

Implementing #4953 is a difficult task since it requires fundamentally changing the compiler's architecture.

Most notably, passes can accidentally break the lock-step constraint by recursing on an expression themselves as in:

fn type_check(expr: Expr) {
    match expr {
        Expr::Add(a, b) => {
            let a_type = type_check(a); // breaks lock-step! 
            let b_type = type_check(b); // we're now several nodes out of sync with other passes!
        }
        ...
    }
}

In this case, breaking lock step in the type checker would mean it is type checking nodes which haven't been name resolved yet, and would likely error as a result.

Happy Case

We can add a Functor version of the Ast with all recursive Expression/Statement nodes replaced with a generic T argument. This is similar to the technique used in "recursion schemes" for reusable recursive helper functions, although Rust does not have the expressitivity to represent the normal Ast as a Fixed version of the Functor version (if this means nothing to you, feel free to ignore this remark). For us, this just means it needs to be a separate enum from the normal Ast.

Project Impact

None

Impact Context

No response

Workaround

None

Workaround Description

No response

Additional Context

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

@jfecher jfecher added the enhancement New feature or request label May 1, 2024
@jfecher
Copy link
Contributor Author

jfecher commented Jun 7, 2024

Instead of trying to interleave our existing passes, it was easier to write an elaborator to interleave them from scratch instead (adapting existing code where possible).

@jfecher jfecher closed this as completed Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant