Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Write a tool for helping debug rome_ir #2587

Closed
2 tasks done
Tracked by #2616
IWANABETHATGUY opened this issue May 16, 2022 · 5 comments
Closed
2 tasks done
Tracked by #2616

Write a tool for helping debug rome_ir #2587

IWANABETHATGUY opened this issue May 16, 2022 · 5 comments
Labels
A-Tooling Area: our own build, development, and release tooling good first issue Good for newcomers task A task, an action that needs to be performed

Comments

@IWANABETHATGUY
Copy link
Contributor

IWANABETHATGUY commented May 16, 2022

Description

Currently, suppose we want to debug why our formatter generate different result from prettier. We need to use rome_playground, copy it, write some corresponding rust code, debug the rust rome_ir code, and finally, get expected rust rome_ir code that matches prettier, then adjust rome_js_formatter until it generates expected result same as prettier.

I found that rome_ir has some relation with our crate rome_formatter, e.g.:
Assume we have rome_ir below:

List [
    SyntaxTokenSlice("test"),
    HardGroup(
        List [
            SyntaxTokenSlice("("),
            SyntaxTokenSlice(")"),
        ],
    ),
    SyntaxTokenSlice(";"),
    SyntaxTokenSlice(""),
    Line(Hard),
]

We could convert rome_ir above to rust code use rome_formatter:

fn main() {
    use rome_formatter::prelude::*;
    use rome_formatter::Formatted;
    let block = format_elements![
        token("test"),
        hard_group_elements(format_elements![token("("), token(")")]),
        token(";"),
        token(""),
        hard_line_break()
    ];
    println!(
        "{}",
        Formatted::new(block, PrinterOptions::default())
            .print()
            .as_code()
    );
}

Although, SyntaxTokenSlice should be more efficient than token, in this scenario performance is not a big deal.

We want to use some tool to help us convert rome_ir in the playground to rust code, I split this task to two steps:

  • Write a parser that could convert rome_ir to AST
  • Visit the Ast to generate the corresponding rust code
@IWANABETHATGUY IWANABETHATGUY added the task A task, an action that needs to be performed label May 16, 2022
@NicholasLYang NicholasLYang added the A-Tooling Area: our own build, development, and release tooling label May 26, 2022
@NicholasLYang
Copy link
Contributor

This is an interesting idea! It's essentially a decompilation tool. One idea I had was to allow people to write format IR directly using s-expressions or a simple DSL. It could potentially tie into this.

@ematipico ematipico added the good first issue Good for newcomers label May 27, 2022
@github-actions
Copy link

This issue is stale because it has been open 14 days with no activity.

@ematipico
Copy link
Contributor

One more option that could help us to achieve this is by using serde. Each data structure could implement a custom de-serialization function

@github-actions github-actions bot removed the S-Stale label Sep 20, 2022
@github-actions
Copy link

github-actions bot commented Nov 4, 2022

This issue is stale because it has been open 14 days with no activity.

@MichaReiser
Copy link
Contributor

I think the hard part isn't about writing the IR elements but getting the conditional logic right.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Tooling Area: our own build, development, and release tooling good first issue Good for newcomers task A task, an action that needs to be performed
Projects
Status: Done
Development

No branches or pull requests

4 participants