-
Notifications
You must be signed in to change notification settings - Fork 550
Example of rustc interface #621
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
Example of rustc interface #621
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@georgewfraser Thanks!
Could you split this into 2 PRs? The first to add the rustc-driver-example.rs
and the second to add the link. That way the CI link check passes.
I'd like to create another directory and put |
cc @Zoxc |
@JohnTitor if you tell me what you want that directory to be named, I will set up 2 PRs, one with the example, one with the link. |
src/rustc-driver-example.rs
Outdated
let parse = queries.parse().unwrap().take(); | ||
println!("{:#?}", parse); | ||
// Analyze the program and inspect the types of definitions. | ||
queries.global_ctxt().unwrap().take().enter(|ctx| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ctx
should be named tcx
here to match the compiler convention.
src/rustc-driver-example.rs
Outdated
input_path: None, | ||
// Option<PathBuf> | ||
output_dir: None, | ||
// Option<PathBuf> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure listing the types is very helpful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you know nothing about the compiler internals (like me!) it's quite helpful for understanding what each of these options actually does.
@georgewfraser |
OK @mark-i-m this is just the .rs file now, once this is merged I will make a new PR with the changes to the .md file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
It's pretty hard to figure out how to use rustc_interface. This adds a simple "hello world" example of using rustc_interface to parse and typecheck a single file.
See discussion in https://internals.rust-lang.org/t/using-the-rustc-interface-crate/11982