Is it possible to parse the Rust source file into HIR?

Hi rustaceans :slight_smile:

Lately, I’ve been really interested in compilers and I’d love to learn more about them. I have come to learn through projects like MIRI that there are multiple IR in Rust!

Could any one please suggest me how to obtain this HIR from a crate or a source file?

You can write a lint plugin that uses the check_crate method to get access to the crate’s HIR.

Lint plugin documentation is here: https://doc.rust-lang.org/book/compiler-plugins.html#lint-plugins You’ll need a LateLintPass and not an EarlyLintPass (the latter is the AST, not the HIR)

1 Like

Also its important to note that the HIR is not at all stable & if so if you upgrade your version of Rust any code you write based on it might be broken.

Thanks a tone @anon19897381!! This little info has been absolutely wonderful :thumbsup:

Actually, I’m just trying to use HIR as the target code or a transcompiler - you reckon that MIR would be a better target?

There’s no guarantee of stability around either representation AFAIK. You’d have to pin to a particular version of Rust.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.