mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 21:43:37 +00:00
Normalize data
No need to store derivable info
This commit is contained in:
parent
e918b1f2b3
commit
b8f62095d6
1 changed files with 9 additions and 14 deletions
|
@ -17,7 +17,6 @@ impl_arena_id!(ScopeId);
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub struct ExprScopes {
|
pub struct ExprScopes {
|
||||||
pub(crate) body: Arc<Body>,
|
|
||||||
scopes: Arena<ScopeId, ScopeData>,
|
scopes: Arena<ScopeId, ScopeData>,
|
||||||
scope_by_expr: FxHashMap<ExprId, ScopeId>,
|
scope_by_expr: FxHashMap<ExprId, ScopeId>,
|
||||||
}
|
}
|
||||||
|
@ -47,19 +46,16 @@ pub(crate) struct ScopeData {
|
||||||
impl ExprScopes {
|
impl ExprScopes {
|
||||||
pub(crate) fn expr_scopes_query(db: &impl HirDatabase, def: DefWithBody) -> Arc<ExprScopes> {
|
pub(crate) fn expr_scopes_query(db: &impl HirDatabase, def: DefWithBody) -> Arc<ExprScopes> {
|
||||||
let body = db.body(def);
|
let body = db.body(def);
|
||||||
let res = ExprScopes::new(body);
|
let res = ExprScopes::new(&*body);
|
||||||
Arc::new(res)
|
Arc::new(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new(body: Arc<Body>) -> ExprScopes {
|
fn new(body: &Body) -> ExprScopes {
|
||||||
let mut scopes = ExprScopes {
|
let mut scopes =
|
||||||
body: body.clone(),
|
ExprScopes { scopes: Arena::default(), scope_by_expr: FxHashMap::default() };
|
||||||
scopes: Arena::default(),
|
|
||||||
scope_by_expr: FxHashMap::default(),
|
|
||||||
};
|
|
||||||
let root = scopes.root_scope();
|
let root = scopes.root_scope();
|
||||||
scopes.add_params_bindings(root, body.params());
|
scopes.add_params_bindings(body, root, body.params());
|
||||||
compute_expr_scopes(body.body_expr(), &body, &mut scopes, root);
|
compute_expr_scopes(body.body_expr(), body, &mut scopes, root);
|
||||||
scopes
|
scopes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,9 +95,8 @@ impl ExprScopes {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_params_bindings(&mut self, scope: ScopeId, params: &[PatId]) {
|
fn add_params_bindings(&mut self, body: &Body, scope: ScopeId, params: &[PatId]) {
|
||||||
let body = Arc::clone(&self.body);
|
params.iter().for_each(|pat| self.add_bindings(body, scope, *pat));
|
||||||
params.iter().for_each(|pat| self.add_bindings(&body, scope, *pat));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_scope(&mut self, node: ExprId, scope: ScopeId) {
|
fn set_scope(&mut self, node: ExprId, scope: ScopeId) {
|
||||||
|
@ -151,7 +146,7 @@ fn compute_expr_scopes(expr: ExprId, body: &Body, scopes: &mut ExprScopes, scope
|
||||||
}
|
}
|
||||||
Expr::Lambda { args, body: body_expr, .. } => {
|
Expr::Lambda { args, body: body_expr, .. } => {
|
||||||
let scope = scopes.new_scope(scope);
|
let scope = scopes.new_scope(scope);
|
||||||
scopes.add_params_bindings(scope, &args);
|
scopes.add_params_bindings(body, scope, &args);
|
||||||
compute_expr_scopes(*body_expr, body, scopes, scope);
|
compute_expr_scopes(*body_expr, body, scopes, scope);
|
||||||
}
|
}
|
||||||
Expr::Match { expr, arms } => {
|
Expr::Match { expr, arms } => {
|
||||||
|
|
Loading…
Reference in a new issue