Skip to content

Commit

Permalink
refactor(sol-hir-lowering): remove unused declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
aripiprazole committed Mar 4, 2024
1 parent 305ad1f commit e034b7e
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 337 deletions.
2 changes: 1 addition & 1 deletion sol-eval/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub fn hir_eval(
ClassDecl(_) => todo!(),
InstanceDecl(_) => todo!(),
TraitDecl(_) => todo!(),
DataDecl(_) => todo!(),
Inductive(_) => todo!(),
TypeDecl(_) => todo!(),
}
}
Expand Down
323 changes: 7 additions & 316 deletions sol-hir-lowering/src/lib.rs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions sol-hir/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ mod impls {
}
}

impl HirFormatter for top_level::DataDecl {
impl HirFormatter for top_level::Inductive {
fn hir_fmt(&self, db: &dyn HirDb, f: &mut Formatter, scope: &Scope) -> std::fmt::Result {
format_decl(self, "data", db, scope, f, |db, f, scope| {
// Write the classes' methods wi
Expand Down Expand Up @@ -396,7 +396,7 @@ mod impls {
ClassDecl(class_decl) => class_decl.hir_fmt(db, f, scope),
InstanceDecl(instance_decl) => instance_decl.hir_fmt(db, f, scope),
TraitDecl(trait_decl) => trait_decl.hir_fmt(db, f, scope),
DataDecl(decl_decl) => decl_decl.hir_fmt(db, f, scope),
Inductive(decl_decl) => decl_decl.hir_fmt(db, f, scope),
TypeDecl(type_decl) => type_decl.hir_fmt(db, f, scope),
}
}
Expand Down
2 changes: 1 addition & 1 deletion sol-hir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub struct Jar(
source::top_level::ClassDecl,
source::top_level::InstanceDecl,
source::top_level::TraitDecl,
source::top_level::DataDecl,
source::top_level::Inductive,
source::top_level::TypeDecl,
source::top_level::Constructor,
source::top_level::BindingGroup,
Expand Down
4 changes: 2 additions & 2 deletions sol-hir/src/reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ impl<'db, U: Checkable> HirListener for ReferenceWalker<'db, U> {
}
}

fn enter_data_top_level(&mut self, decl: top_level::DataDecl) {
fn enter_data_top_level(&mut self, decl: top_level::Inductive) {
self.enter_scope(self.db, decl.location(self.db), decl.scope(self.db));
self.stack.push(decl.scope(self.db));
}

fn exit_data_top_level(&mut self, _: top_level::DataDecl) {
fn exit_data_top_level(&mut self, _: top_level::Inductive) {
self.stack.pop();
}

Expand Down
23 changes: 11 additions & 12 deletions sol-hir/src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1189,20 +1189,19 @@ pub mod top_level {
}

#[salsa::tracked]
pub struct DataDecl {
pub struct Inductive {
pub attributes: HashSet<declaration::Attribute, FxBuildHasher>,
pub docs: Vec<declaration::DocString>,
pub visibility: Spanned<declaration::Vis>,
pub name: Definition,
pub parameters: Vec<declaration::Parameter>,
pub return_type: type_rep::TypeRep,
pub variants: Vec<Constructor>,
pub methods: Vec<BindingGroup>,
pub location: Location,
pub scope: Arc<Scope>,
}

impl walking::Walker for DataDecl {
impl walking::Walker for Inductive {
fn accept<T: HirListener>(self, db: &dyn crate::HirDb, listener: &mut T) {
listener.enter_data_top_level(self);
self.attributes(db).accept(db, listener);
Expand All @@ -1218,7 +1217,7 @@ pub mod top_level {
}
}

impl declaration::Declaration for DataDecl {
impl declaration::Declaration for Inductive {
fn attributes(
&self,
db: &dyn crate::HirDb,
Expand Down Expand Up @@ -1251,7 +1250,7 @@ pub mod top_level {
}
}

impl HirElement for DataDecl {
impl HirElement for Inductive {
fn location(&self, db: &dyn crate::HirDb) -> Location {
Self::location(*self, db)
}
Expand Down Expand Up @@ -1347,7 +1346,7 @@ pub mod top_level {
ClassDecl(ClassDecl),
InstanceDecl(InstanceDecl),
TraitDecl(TraitDecl),
DataDecl(DataDecl),
Inductive(Inductive),
TypeDecl(TypeDecl),
}

Expand All @@ -1361,7 +1360,7 @@ pub mod top_level {
TopLevel::ClassDecl(class_decl) => class_decl.debug_all(db).fmt(f),
TopLevel::InstanceDecl(instance_decl) => instance_decl.debug_all(db).fmt(f),
TopLevel::TraitDecl(trait_decl) => trait_decl.debug_all(db).fmt(f),
TopLevel::DataDecl(data_decl) => data_decl.debug_all(db).fmt(f),
TopLevel::Inductive(data_decl) => data_decl.debug_all(db).fmt(f),
TopLevel::TypeDecl(type_decl) => type_decl.debug_all(db).fmt(f),
}
}
Expand All @@ -1381,7 +1380,7 @@ pub mod top_level {
TopLevel::ClassDecl(class_decl) => class_decl.accept(db, listener),
TopLevel::InstanceDecl(instance_decl) => instance_decl.accept(db, listener),
TopLevel::TraitDecl(trait_decl) => trait_decl.accept(db, listener),
TopLevel::DataDecl(data_decl) => data_decl.accept(db, listener),
TopLevel::Inductive(data_decl) => data_decl.accept(db, listener),
TopLevel::TypeDecl(type_decl) => type_decl.accept(db, listener),
}
}
Expand All @@ -1397,7 +1396,7 @@ pub mod top_level {
Self::ClassDecl(downcast) => downcast.location(db),
Self::InstanceDecl(downcast) => downcast.location(db),
Self::TraitDecl(downcast) => downcast.location(db),
Self::DataDecl(downcast) => downcast.location(db),
Self::Inductive(downcast) => downcast.location(db),
Self::TypeDecl(downcast) => downcast.location(db),
}
}
Expand All @@ -1412,7 +1411,7 @@ pub mod top_level {
ClassDecl(ClassDecl),
TraitDecl(TraitDecl),
InstanceDecl(InstanceDecl),
DataDecl(DataDecl),
DataDecl(Inductive),
TypeDecl(TypeDecl),
}

Expand Down Expand Up @@ -1442,7 +1441,7 @@ pub mod top_level {
DeclDescriptor::ClassDecl(downcast) => Self::ClassDecl(downcast),
DeclDescriptor::InstanceDecl(downcast) => Self::InstanceDecl(downcast),
DeclDescriptor::TraitDecl(downcast) => Self::TraitDecl(downcast),
DeclDescriptor::DataDecl(downcast) => Self::DataDecl(downcast),
DeclDescriptor::DataDecl(downcast) => Self::Inductive(downcast),
DeclDescriptor::TypeDecl(downcast) => Self::TypeDecl(downcast),
})
}
Expand All @@ -1462,7 +1461,7 @@ pub mod top_level {
TopLevel::ClassDecl(downcast) => Self::ClassDecl(downcast),
TopLevel::InstanceDecl(downcast) => Self::InstanceDecl(downcast),
TopLevel::TraitDecl(downcast) => Self::TraitDecl(downcast),
TopLevel::DataDecl(downcast) => Self::DataDecl(downcast),
TopLevel::Inductive(downcast) => Self::DataDecl(downcast),
TopLevel::TypeDecl(downcast) => Self::TypeDecl(downcast),
})
}
Expand Down
4 changes: 2 additions & 2 deletions sol-hir/src/walking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub trait HirListener {
fn enter_type_top_level(&mut self, type_: top_level::TypeDecl) {}
fn enter_instance_top_level(&mut self, trait_: top_level::InstanceDecl) {}
fn enter_trait_top_level(&mut self, trait_: top_level::TraitDecl) {}
fn enter_data_top_level(&mut self, data: top_level::DataDecl) {}
fn enter_data_top_level(&mut self, data: top_level::Inductive) {}

// SECTION: type_rep
fn exit_arrow_type_rep(&mut self, arrow: type_rep::ArrowTypeRep) {}
Expand Down Expand Up @@ -149,5 +149,5 @@ pub trait HirListener {
fn exit_type_top_level(&mut self, class: top_level::TypeDecl) {}
fn exit_instance_top_level(&mut self, trait_: top_level::InstanceDecl) {}
fn exit_trait_top_level(&mut self, trait_: top_level::TraitDecl) {}
fn exit_data_top_level(&mut self, data: top_level::DataDecl) {}
fn exit_data_top_level(&mut self, data: top_level::Inductive) {}
}
2 changes: 1 addition & 1 deletion sol-js/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub fn transform_top_level(
TopLevel::ClassDecl(_) => bail!("class declarations are not supported"),
TopLevel::InstanceDecl(_) => bail!("instance declarations are not supported"),
TopLevel::TraitDecl(_) => bail!("trait declarations are not supported"),
TopLevel::DataDecl(_) => bail!("data declarations are not supported"),
TopLevel::Inductive(_) => bail!("data declarations are not supported"),
TopLevel::TypeDecl(_) => bail!("type declarations are not supported"),
}
}
Expand Down

0 comments on commit e034b7e

Please sign in to comment.