-
Notifications
You must be signed in to change notification settings - Fork 39
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
feat(hir): expose hir from parsing context #210
base: main
Are you sure you want to change the base?
Conversation
grandizzy
commented
Feb 24, 2025
- access Hir from calling ParsingContext::parse_and_lower_to_hir
crates/sema/src/lib.rs
Outdated
@@ -25,6 +25,7 @@ mod ast_lowering; | |||
mod ast_passes; | |||
|
|||
mod parse; | |||
use crate::hir::{Arena, Hir}; |
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.
should maintain style of the other fns, using hir:: as a module instead of importing
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.
changed in 9c654cc
crates/sema/src/lib.rs
Outdated
@@ -100,6 +101,32 @@ pub fn parse_and_resolve(pcx: ParsingContext<'_>) -> Result<()> { | |||
Ok(()) | |||
} | |||
|
|||
/// Parses and lowers to HIR, recursing into imports. | |||
pub fn parse_and_lower_to_hir<'hir>( |
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.
I want to avoid any code dup here and also avoid using Hir directly, but instead through gcx; I think what we can do here is something like this
fn parse_and_resolve() {
let gcx = *parse_and_lower()?;
analysis(gcx)?;
Ok(())
}
fn parse_and_lower<'hir>(pcx: '_, hir_arena: 'hir) -> impl Deref<Target=Gcx<'hir>> {
// all the code currently in parse_and_resolve ...
GcxWrapper(...)
}
struct GcxWrapper(GlobalContext);
impl Deref for GcxWrapper {
// move the unsafe here
}
impl Drop for GcxWrapper {
// move from OnDrop closure
}
This way we can keep the drop impl and avoid a closure for using Gcx
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.
@DaniPopes would the approach in 9c654cc which doesn't introduce a new wrapper work?