Remove SourceMap

This commit is contained in:
Giacomo Stevanato 2021-09-25 19:06:04 +02:00
parent fe2b1615de
commit 72bb49467d
2 changed files with 11 additions and 34 deletions

View file

@ -90,13 +90,6 @@ pub enum WherePredicateTypeTarget {
TypeParam(LocalTypeParamId), TypeParam(LocalTypeParamId),
} }
#[derive(Default)]
pub(crate) struct SourceMap {
pub(crate) type_params: ArenaMap<LocalTypeParamId, Either<ast::TypeParam, ast::Trait>>,
lifetime_params: ArenaMap<LocalLifetimeParamId, ast::LifetimeParam>,
const_params: ArenaMap<LocalConstParamId, ast::ConstParam>,
}
impl GenericParams { impl GenericParams {
pub(crate) fn generic_params_query( pub(crate) fn generic_params_query(
db: &dyn DefDatabase, db: &dyn DefDatabase,
@ -153,14 +146,9 @@ impl GenericParams {
} }
} }
pub(crate) fn fill( pub(crate) fn fill(&mut self, lower_ctx: &LowerCtx, node: &dyn HasGenericParams) {
&mut self,
lower_ctx: &LowerCtx,
sm: &mut SourceMap,
node: &dyn HasGenericParams,
) {
if let Some(params) = node.generic_param_list() { if let Some(params) = node.generic_param_list() {
self.fill_params(lower_ctx, sm, params) self.fill_params(lower_ctx, params)
} }
if let Some(where_clause) = node.where_clause() { if let Some(where_clause) = node.where_clause() {
self.fill_where_predicates(lower_ctx, where_clause); self.fill_where_predicates(lower_ctx, where_clause);
@ -180,12 +168,7 @@ impl GenericParams {
} }
} }
fn fill_params( fn fill_params(&mut self, lower_ctx: &LowerCtx, params: ast::GenericParamList) {
&mut self,
lower_ctx: &LowerCtx,
sm: &mut SourceMap,
params: ast::GenericParamList,
) {
for type_param in params.type_params() { for type_param in params.type_params() {
let name = type_param.name().map_or_else(Name::missing, |it| it.as_name()); let name = type_param.name().map_or_else(Name::missing, |it| it.as_name());
// FIXME: Use `Path::from_src` // FIXME: Use `Path::from_src`
@ -196,9 +179,7 @@ impl GenericParams {
default, default,
provenance: TypeParamProvenance::TypeParamList, provenance: TypeParamProvenance::TypeParamList,
}; };
let param_id = self.types.alloc(param); self.types.alloc(param);
sm.type_params.insert(param_id, Either::Left(type_param.clone()));
let type_ref = TypeRef::Path(name.into()); let type_ref = TypeRef::Path(name.into());
self.fill_bounds(lower_ctx, &type_param, Either::Left(type_ref)); self.fill_bounds(lower_ctx, &type_param, Either::Left(type_ref));
} }
@ -206,8 +187,7 @@ impl GenericParams {
let name = let name =
lifetime_param.lifetime().map_or_else(Name::missing, |lt| Name::new_lifetime(&lt)); lifetime_param.lifetime().map_or_else(Name::missing, |lt| Name::new_lifetime(&lt));
let param = LifetimeParamData { name: name.clone() }; let param = LifetimeParamData { name: name.clone() };
let param_id = self.lifetimes.alloc(param); self.lifetimes.alloc(param);
sm.lifetime_params.insert(param_id, lifetime_param.clone());
let lifetime_ref = LifetimeRef::new_name(name); let lifetime_ref = LifetimeRef::new_name(name);
self.fill_bounds(lower_ctx, &lifetime_param, Either::Right(lifetime_ref)); self.fill_bounds(lower_ctx, &lifetime_param, Either::Right(lifetime_ref));
} }
@ -215,8 +195,7 @@ impl GenericParams {
let name = const_param.name().map_or_else(Name::missing, |it| it.as_name()); let name = const_param.name().map_or_else(Name::missing, |it| it.as_name());
let ty = const_param.ty().map_or(TypeRef::Error, |it| TypeRef::from_ast(lower_ctx, it)); let ty = const_param.ty().map_or(TypeRef::Error, |it| TypeRef::from_ast(lower_ctx, it));
let param = ConstParamData { name, ty: Interned::new(ty) }; let param = ConstParamData { name, ty: Interned::new(ty) };
let param_id = self.consts.alloc(param); self.consts.alloc(param);
sm.const_params.insert(param_id, const_param.clone());
} }
} }

View file

@ -662,11 +662,10 @@ impl<'a> Ctx<'a> {
owner: GenericsOwner<'_>, owner: GenericsOwner<'_>,
node: &impl ast::HasGenericParams, node: &impl ast::HasGenericParams,
) -> Interned<GenericParams> { ) -> Interned<GenericParams> {
let mut sm = &mut Default::default();
let mut generics = GenericParams::default(); let mut generics = GenericParams::default();
match owner { match owner {
GenericsOwner::Function(func) => { GenericsOwner::Function(func) => {
generics.fill(&self.body_ctx, sm, node); generics.fill(&self.body_ctx, node);
// lower `impl Trait` in arguments // lower `impl Trait` in arguments
for id in func.params.clone() { for id in func.params.clone() {
if let Param::Normal(ty) = &self.data().params[id] { if let Param::Normal(ty) = &self.data().params[id] {
@ -678,27 +677,26 @@ impl<'a> Ctx<'a> {
| GenericsOwner::Enum | GenericsOwner::Enum
| GenericsOwner::Union | GenericsOwner::Union
| GenericsOwner::TypeAlias => { | GenericsOwner::TypeAlias => {
generics.fill(&self.body_ctx, sm, node); generics.fill(&self.body_ctx, node);
} }
GenericsOwner::Trait(trait_def) => { GenericsOwner::Trait(trait_def) => {
// traits get the Self type as an implicit first type parameter // traits get the Self type as an implicit first type parameter
let self_param_id = generics.types.alloc(TypeParamData { generics.types.alloc(TypeParamData {
name: Some(name![Self]), name: Some(name![Self]),
default: None, default: None,
provenance: TypeParamProvenance::TraitSelf, provenance: TypeParamProvenance::TraitSelf,
}); });
sm.type_params.insert(self_param_id, Either::Right(trait_def.clone()));
// add super traits as bounds on Self // add super traits as bounds on Self
// i.e., trait Foo: Bar is equivalent to trait Foo where Self: Bar // i.e., trait Foo: Bar is equivalent to trait Foo where Self: Bar
let self_param = TypeRef::Path(name![Self].into()); let self_param = TypeRef::Path(name![Self].into());
generics.fill_bounds(&self.body_ctx, trait_def, Either::Left(self_param)); generics.fill_bounds(&self.body_ctx, trait_def, Either::Left(self_param));
generics.fill(&self.body_ctx, &mut sm, node); generics.fill(&self.body_ctx, node);
} }
GenericsOwner::Impl => { GenericsOwner::Impl => {
// Note that we don't add `Self` here: in `impl`s, `Self` is not a // Note that we don't add `Self` here: in `impl`s, `Self` is not a
// type-parameter, but rather is a type-alias for impl's target // type-parameter, but rather is a type-alias for impl's target
// type, so this is handled by the resolver. // type, so this is handled by the resolver.
generics.fill(&self.body_ctx, &mut sm, node); generics.fill(&self.body_ctx, node);
} }
} }