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

Have a way to parse SSA #6475

Closed
asterite opened this issue Nov 7, 2024 · 0 comments · Fixed by #6489
Closed

Have a way to parse SSA #6475

asterite opened this issue Nov 7, 2024 · 0 comments · Fixed by #6489
Assignees
Labels
enhancement New feature or request

Comments

@asterite
Copy link
Collaborator

asterite commented Nov 7, 2024

Problem

Right now we have some tests for SSA, but they have this form:

// fn main f0 {
//   b0(v0: u16):
//     v1 = cast v0 as u32
//     v2 = cast v0 as u32
//     constrain v1 v2
// }
//
// After constructing this IR, we run constant folding which should replace the second cast
// with a reference to the results to the first. This then allows us to optimize away
// the constrain instruction as both inputs are known to be equal.
//
// The first cast instruction is retained and will be removed in the dead instruction elimination pass.
let main_id = Id::test_new(0);

// Compiling main
let mut builder = FunctionBuilder::new("main".into(), main_id);
let v0 = builder.add_parameter(Type::unsigned(16));

let v1 = builder.insert_cast(v0, Type::unsigned(32));
let v2 = builder.insert_cast(v0, Type::unsigned(32));
builder.insert_constrain(v1, v2, None);

let mut ssa = builder.finish();
let main = ssa.main_mut();
let instructions = main.dfg[main.entry_block()].instructions();
assert_eq!(instructions.len(), 3);

Essentially, we have a comment for the SSA function we are testing, then code that programmatically creates this.

This works, but:

  • it's a slow process, or at least slower than being able to translate the comment to the SSA code
  • the code that generates the code could potentially be not generating the code it's supposed to generate, or the two could fall out of sync (or we might need to maintain both so that they are in sync)

So, we could introduce some way to go from SSA code into an Ssa object:

let src = "
    fn main f0 {
    b0(v0: u16):
        v1 = cast v0 as u32
        v2 = cast v0 as u32
        constrain v1 v2
    }
    ";
let ssa = Ssa::from_str(src).unwrap();

Happy Case

There's a way to go from SSA source code to an Ssa object.

Workaround

None

Workaround Description

No response

Additional Context

No response

Project Impact

None

Blocker Context

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

@asterite asterite added the enhancement New feature or request label Nov 7, 2024
@asterite asterite self-assigned this Nov 7, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Nov 7, 2024
@TomAFrench TomAFrench moved this from 📋 Backlog to 🏗 In progress in Noir Nov 8, 2024
@asterite asterite mentioned this issue Nov 8, 2024
5 tasks
@github-project-automation github-project-automation bot moved this from 🏗 In progress to ✅ Done in Noir Nov 12, 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