mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
Remove owner from Body
This commit is contained in:
parent
6149ee30ef
commit
fe00db72b9
@ -22,8 +22,6 @@ pub use hir_def::expr::{
|
||||
/// The body of an item (function, const etc.).
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub struct Body {
|
||||
/// The def of the item this body belongs to
|
||||
owner: DefWithBody,
|
||||
exprs: Arena<ExprId, Expr>,
|
||||
pats: Arena<PatId, Pat>,
|
||||
/// The patterns for the function's parameters. While the parameter types are
|
||||
@ -86,7 +84,7 @@ impl Body {
|
||||
}
|
||||
};
|
||||
|
||||
let (body, source_map) = lower::lower(db, def.resolver(db), file_id, def, params, body);
|
||||
let (body, source_map) = lower::lower(db, def.resolver(db), file_id, params, body);
|
||||
(Arc::new(body), Arc::new(source_map))
|
||||
}
|
||||
|
||||
@ -102,10 +100,6 @@ impl Body {
|
||||
self.body_expr
|
||||
}
|
||||
|
||||
pub fn owner(&self) -> DefWithBody {
|
||||
self.owner
|
||||
}
|
||||
|
||||
pub fn exprs(&self) -> impl Iterator<Item = (ExprId, &Expr)> {
|
||||
self.exprs.iter()
|
||||
}
|
||||
@ -117,21 +111,21 @@ impl Body {
|
||||
|
||||
// needs arbitrary_self_types to be a method... or maybe move to the def?
|
||||
pub(crate) fn resolver_for_expr(
|
||||
body: Arc<Body>,
|
||||
db: &impl HirDatabase,
|
||||
owner: DefWithBody,
|
||||
expr_id: ExprId,
|
||||
) -> Resolver {
|
||||
let scopes = db.expr_scopes(body.owner);
|
||||
resolver_for_scope(body, db, scopes.scope_for(expr_id))
|
||||
let scopes = db.expr_scopes(owner);
|
||||
resolver_for_scope(db, owner, scopes.scope_for(expr_id))
|
||||
}
|
||||
|
||||
pub(crate) fn resolver_for_scope(
|
||||
body: Arc<Body>,
|
||||
db: &impl HirDatabase,
|
||||
owner: DefWithBody,
|
||||
scope_id: Option<scope::ScopeId>,
|
||||
) -> Resolver {
|
||||
let mut r = body.owner.resolver(db);
|
||||
let scopes = db.expr_scopes(body.owner);
|
||||
let mut r = owner.resolver(db);
|
||||
let scopes = db.expr_scopes(owner);
|
||||
let scope_chain = scopes.scope_chain(scope_id).collect::<Vec<_>>();
|
||||
for scope in scope_chain.into_iter().rev() {
|
||||
r = r.push_expr_scope(Arc::clone(&scopes), scope);
|
||||
|
@ -20,8 +20,8 @@ use ra_syntax::{
|
||||
use test_utils::tested_by;
|
||||
|
||||
use crate::{
|
||||
db::HirDatabase, AstId, DefWithBody, Either, HirFileId, MacroCallLoc, MacroFileKind,
|
||||
Mutability, Path, Resolver, Source,
|
||||
db::HirDatabase, AstId, Either, HirFileId, MacroCallLoc, MacroFileKind, Mutability, Path,
|
||||
Resolver, Source,
|
||||
};
|
||||
|
||||
use super::{
|
||||
@ -33,7 +33,6 @@ pub(super) fn lower(
|
||||
db: &impl HirDatabase,
|
||||
resolver: Resolver,
|
||||
file_id: HirFileId,
|
||||
owner: DefWithBody,
|
||||
params: Option<ast::ParamList>,
|
||||
body: Option<ast::Expr>,
|
||||
) -> (Body, BodySourceMap) {
|
||||
@ -44,7 +43,6 @@ pub(super) fn lower(
|
||||
current_file_id: file_id,
|
||||
source_map: BodySourceMap::default(),
|
||||
body: Body {
|
||||
owner,
|
||||
exprs: Arena::default(),
|
||||
pats: Arena::default(),
|
||||
params: Vec::new(),
|
||||
|
@ -150,7 +150,7 @@ impl SourceAnalyzer {
|
||||
None => scope_for(&scopes, &source_map, &node),
|
||||
Some(offset) => scope_for_offset(&scopes, &source_map, file_id.into(), offset),
|
||||
};
|
||||
let resolver = expr::resolver_for_scope(def.body(db), db, scope);
|
||||
let resolver = expr::resolver_for_scope(db, def, scope);
|
||||
SourceAnalyzer {
|
||||
resolver,
|
||||
body_owner: Some(def),
|
||||
|
@ -43,7 +43,7 @@ use crate::{
|
||||
expr::{BindingAnnotation, Body, ExprId, PatId},
|
||||
resolve::{Resolver, TypeNs},
|
||||
ty::infer::diagnostics::InferenceDiagnostic,
|
||||
Adt, AssocItem, ConstData, DefWithBody, FnData, Function, HasBody, Path, StructField,
|
||||
Adt, AssocItem, ConstData, DefWithBody, FnData, Function, Path, StructField,
|
||||
};
|
||||
|
||||
macro_rules! ty_app {
|
||||
@ -64,9 +64,8 @@ mod coerce;
|
||||
/// The entry point of type inference.
|
||||
pub fn infer_query(db: &impl HirDatabase, def: DefWithBody) -> Arc<InferenceResult> {
|
||||
let _p = profile("infer_query");
|
||||
let body = def.body(db);
|
||||
let resolver = def.resolver(db);
|
||||
let mut ctx = InferenceContext::new(db, body, resolver);
|
||||
let mut ctx = InferenceContext::new(db, def, resolver);
|
||||
|
||||
match def {
|
||||
DefWithBody::Const(ref c) => ctx.collect_const(&c.data(db)),
|
||||
@ -187,6 +186,7 @@ impl Index<PatId> for InferenceResult {
|
||||
#[derive(Clone, Debug)]
|
||||
struct InferenceContext<'a, D: HirDatabase> {
|
||||
db: &'a D,
|
||||
owner: DefWithBody,
|
||||
body: Arc<Body>,
|
||||
resolver: Resolver,
|
||||
var_unification_table: InPlaceUnificationTable<TypeVarId>,
|
||||
@ -204,7 +204,7 @@ struct InferenceContext<'a, D: HirDatabase> {
|
||||
}
|
||||
|
||||
impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
||||
fn new(db: &'a D, body: Arc<Body>, resolver: Resolver) -> Self {
|
||||
fn new(db: &'a D, owner: DefWithBody, resolver: Resolver) -> Self {
|
||||
InferenceContext {
|
||||
result: InferenceResult::default(),
|
||||
var_unification_table: InPlaceUnificationTable::new(),
|
||||
@ -213,7 +213,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
||||
trait_env: lower::trait_env(db, &resolver),
|
||||
coerce_unsized_map: Self::init_coerce_unsized_map(db, &resolver),
|
||||
db,
|
||||
body,
|
||||
owner,
|
||||
body: db.body(owner),
|
||||
resolver,
|
||||
}
|
||||
}
|
||||
|
@ -130,10 +130,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
||||
TypeCtor::FnPtr { num_args: sig_tys.len() as u16 - 1 },
|
||||
Substs(sig_tys.into()),
|
||||
);
|
||||
let closure_ty = Ty::apply_one(
|
||||
TypeCtor::Closure { def: self.body.owner(), expr: tgt_expr },
|
||||
sig_ty,
|
||||
);
|
||||
let closure_ty =
|
||||
Ty::apply_one(TypeCtor::Closure { def: self.owner, expr: tgt_expr }, sig_ty);
|
||||
|
||||
// Eagerly try to relate the closure type with the expected
|
||||
// type, otherwise we often won't have enough information to
|
||||
@ -184,7 +182,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
||||
}
|
||||
Expr::Path(p) => {
|
||||
// FIXME this could be more efficient...
|
||||
let resolver = expr::resolver_for_expr(self.body.clone(), self.db, tgt_expr);
|
||||
let resolver = expr::resolver_for_expr(self.db, self.owner, tgt_expr);
|
||||
self.infer_path(&resolver, p, tgt_expr.into()).unwrap_or(Ty::Unknown)
|
||||
}
|
||||
Expr::Continue => Ty::simple(TypeCtor::Never),
|
||||
|
Loading…
Reference in New Issue
Block a user