From a7cf176a2e4ba2a4c07128072d731b5b485ebcd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabrielle=20Guimar=C3=A3es=20de=20Oliveira?= Date: Sun, 19 May 2024 21:47:06 -0300 Subject: [PATCH] feat(sol-hir): remove old code --- sol-hir/src/fmt.rs | 26 ++--- sol-hir/src/reference.rs | 8 +- sol-hir/src/source.rs | 234 +++++---------------------------------- 3 files changed, 46 insertions(+), 222 deletions(-) diff --git a/sol-hir/src/fmt.rs b/sol-hir/src/fmt.rs index 821d6e3..7a43739 100644 --- a/sol-hir/src/fmt.rs +++ b/sol-hir/src/fmt.rs @@ -359,7 +359,7 @@ mod impls { impl HirFormatter for stmt::Block { fn hir_fmt(&self, db: &dyn HirDb, f: &mut Formatter, scope: &Scope) -> std::fmt::Result { code_block(db, scope, f, |db, f, scope| { - for statement in self.statements(db) { + for statement in self.statements.iter() { statement.hir_fmt(db, f, scope)?; } Ok(()) @@ -420,14 +420,14 @@ mod impls { impl HirFormatter for pattern::ConstructorPattern { fn hir_fmt(&self, db: &dyn HirDb, f: &mut Formatter, scope: &Scope) -> std::fmt::Result { - let arguments = self.arguments(db); + let arguments = self.arguments.clone(); if arguments.is_empty() { - self.name(db).hir_fmt(db, f, scope)?; + self.name.clone().hir_fmt(db, f, scope)?; write!(f, " ")?; scope.punctuated(db, f, arguments, ", ") } else { write!(f, "(")?; - self.name(db).hir_fmt(db, f, scope)?; + self.name.hir_fmt(db, f, scope)?; write!(f, " ")?; scope.punctuated(db, f, arguments, ", ")?; write!(f, ")") @@ -515,13 +515,13 @@ mod impls { impl HirFormatter for expr::CallExpr { fn hir_fmt(&self, db: &dyn HirDb, f: &mut Formatter, scope: &Scope) -> std::fmt::Result { write!(f, "(")?; - self.callee(db).hir_fmt(db, f, scope)?; - let arguments = self.arguments(db); + self.callee.hir_fmt(db, f, scope)?; + let arguments = self.arguments.clone(); if !arguments.is_empty() { write!(f, " ")?; scope.punctuated(db, f, arguments, " ")?; } - if let Some(block) = self.do_notation(db) { + if let Some(block) = self.do_notation.clone() { write!(f, " ")?; block.hir_fmt(db, f, scope)?; } @@ -535,18 +535,18 @@ mod impls { fn hir_fmt(&self, db: &dyn HirDb, f: &mut Formatter, scope: &Scope) -> std::fmt::Result { write!(f, "λ")?; write!(f, " ")?; - scope.punctuated(db, f, self.parameters(db), ", ")?; + scope.punctuated(db, f, self.parameters.clone(), ", ")?; write!(f, ".")?; write!(f, " ")?; - self.value(db).hir_fmt(db, f, scope) + self.value.hir_fmt(db, f, scope) } } impl HirFormatter for expr::AnnExpr { fn hir_fmt(&self, db: &dyn HirDb, f: &mut Formatter, scope: &Scope) -> std::fmt::Result { - self.value(db).hir_fmt(db, f, scope)?; + self.value.hir_fmt(db, f, scope)?; write!(f, " : ")?; - self.type_rep(db).hir_fmt(db, f, scope) + self.type_rep.hir_fmt(db, f, scope) } } @@ -562,11 +562,11 @@ mod impls { fn hir_fmt(&self, db: &dyn HirDb, f: &mut Formatter, scope: &Scope) -> std::fmt::Result { write!(f, "match")?; write!(f, " ")?; - self.scrutinee(db).hir_fmt(db, f, scope)?; + self.scrutinee.hir_fmt(db, f, scope)?; write!(f, " ")?; write!(f, "{{")?; code_block(db, scope, f, |db, f, scope| { - scope.unlined(db, f, self.clauses(db), ", ") + scope.unlined(db, f, self.clauses.clone(), ", ") })?; write!(f, "}}") } diff --git a/sol-hir/src/reference.rs b/sol-hir/src/reference.rs index 075f393..c7e89af 100644 --- a/sol-hir/src/reference.rs +++ b/sol-hir/src/reference.rs @@ -142,8 +142,8 @@ impl<'db, U: Checkable> HirListener for ReferenceWalker<'db, U> { } fn enter_block(&mut self, block: stmt::Block) { - self.enter_scope(self.db, block.location(self.db), block.scope(self.db)); - self.stack.push(block.scope(self.db)); + self.enter_scope(self.db, block.location(self.db), block.scope.clone()); + self.stack.push(block.scope.clone()); } fn exit_block(&mut self, _: stmt::Block) { @@ -151,8 +151,8 @@ impl<'db, U: Checkable> HirListener for ReferenceWalker<'db, U> { } fn enter_abs_expr(&mut self, abs_expr: expr::AbsExpr) { - self.enter_scope(self.db, abs_expr.location(self.db), abs_expr.scope(self.db)); - self.stack.push(abs_expr.scope(self.db)); + self.enter_scope(self.db, abs_expr.location(self.db), abs_expr.scope.clone()); + self.stack.push(abs_expr.scope.clone()); } fn exit_abs_expr(&mut self, _: expr::AbsExpr) { diff --git a/sol-hir/src/source.rs b/sol-hir/src/source.rs index f35298b..0410ed5 100644 --- a/sol-hir/src/source.rs +++ b/sol-hir/src/source.rs @@ -1306,40 +1306,13 @@ pub mod pattern { impl walking::Walker for ConstructorPattern { fn accept(self, db: &dyn crate::HirDb, listener: &mut T) { listener.enter_constructor_pattern(self.clone()); - self.name(db).accept(db, listener); - self.arguments(db).accept(db, listener); + self.name.clone().accept(db, listener); + self.arguments.clone().accept(db, listener); self.location(db).accept(db, listener); listener.exit_constructor_pattern(self); } } - impl ConstructorPattern { - pub fn new( - _: &dyn crate::HirDb, - name: Constructor, - arguments: Vec, - location: Location, - ) -> ConstructorPattern { - ConstructorPattern { - name, - arguments, - location, - } - } - - pub fn name(&self, _db: &dyn crate::HirDb) -> Constructor { - self.name.clone() - } - - pub fn arguments(&self, _db: &dyn crate::HirDb) -> Vec { - self.arguments.clone() - } - - pub fn location(&self, _db: &dyn crate::HirDb) -> Location { - self.location.clone() - } - } - impl HirElement for ConstructorPattern { fn location(&self, _: &dyn crate::HirDb) -> Location { self.location.clone() @@ -1696,7 +1669,7 @@ pub mod stmt { impl walking::Walker for Block { fn accept(self, db: &dyn crate::HirDb, listener: &mut T) { listener.enter_block(self.clone()); - self.statements(db).accept(db, listener); + self.statements.clone().accept(db, listener); self.location(db).accept(db, listener); listener.exit_block(self); } @@ -1706,35 +1679,12 @@ pub mod stmt { fn default_with_db(db: &dyn crate::HirDb) -> Self { let scope = Scope::new_ref(ScopeKind::Block); - Self::new(db, vec![], Location::call_site(db), scope) - } - } - - impl Block { - pub fn new( - _: &dyn crate::HirDb, - statements: Vec, - location: Location, - scope: Arc, - ) -> Self { Self { - statements, - location, + statements: vec![], + location: Location::call_site(db), scope, } } - - pub fn statements(&self, _: &dyn crate::HirDb) -> Vec { - self.statements.clone() - } - - pub fn scope(&self, _db: &dyn crate::HirDb) -> Arc { - self.scope.clone() - } - - pub fn location(&self, _db: &dyn crate::HirDb) -> Location { - self.location.clone() - } } impl HirElement for Block { @@ -1905,46 +1855,13 @@ pub mod expr { impl walking::Walker for AbsExpr { fn accept(self, db: &dyn crate::HirDb, listener: &mut T) { listener.enter_abs_expr(self.clone()); - self.parameters(db).accept(db, listener); - self.value(db).accept(db, listener); + self.parameters.clone().accept(db, listener); + self.value.clone().accept(db, listener); self.location(db).accept(db, listener); listener.exit_abs_expr(self); } } - impl AbsExpr { - pub fn new( - _: &dyn crate::HirDb, - parameters: Vec, - value: expr::Expr, - location: Location, - scope: Arc, - ) -> Self { - Self { - parameters, - value: Box::new(value), - location, - scope, - } - } - - pub fn parameters(&self, _db: &dyn crate::HirDb) -> Vec { - self.parameters.clone() - } - - pub fn value(&self, _db: &dyn crate::HirDb) -> Expr { - (*self.value).clone() - } - - pub fn location(&self, _db: &dyn crate::HirDb) -> Location { - self.location.clone() - } - - pub fn scope(&self, _db: &dyn crate::HirDb) -> Arc { - self.scope.clone() - } - } - impl salsa::DebugWithDb<>::DynDb> for AbsExpr { fn fmt(&self, f: &mut Formatter<'_>, _: &dyn crate::HirDb, _: bool) -> std::fmt::Result { Debug::fmt(self, f) @@ -1971,40 +1888,13 @@ pub mod expr { impl walking::Walker for AnnExpr { fn accept(self, db: &dyn crate::HirDb, listener: &mut T) { listener.enter_ann_expr(self.clone()); - self.value(db).accept(db, listener); - self.type_rep(db).accept(db, listener); + self.value.clone().accept(db, listener); + self.type_rep.clone().accept(db, listener); self.location(db).accept(db, listener); listener.exit_ann_expr(self); } } - impl AnnExpr { - pub fn new( - _: &dyn crate::HirDb, - value: expr::Expr, - type_rep: type_rep::TypeRep, - location: Location, - ) -> Self { - Self { - value: Box::new(value), - type_rep, - location, - } - } - - pub fn value(&self, _db: &dyn crate::HirDb) -> Expr { - (*self.value).clone() - } - - pub fn type_rep(&self, _db: &dyn crate::HirDb) -> type_rep::TypeRep { - self.type_rep.clone() - } - - pub fn location(&self, _db: &dyn crate::HirDb) -> Location { - self.location.clone() - } - } - impl HirElement for AnnExpr { fn location(&self, _: &dyn crate::HirDb) -> Location { self.location.clone() @@ -2061,42 +1951,13 @@ pub mod expr { impl walking::Walker for MatchExpr { fn accept(self, db: &dyn crate::HirDb, listener: &mut T) { listener.enter_match_expr(self.clone()); - self.scrutinee(db).accept(db, listener); - self.clauses(db).accept(db, listener); + self.scrutinee.clone().accept(db, listener); + self.clauses.clone().accept(db, listener); self.location(db).accept(db, listener); listener.exit_match_expr(self); } } - impl MatchExpr { - pub fn new( - _: &dyn crate::HirDb, - kind: MatchKind, - scrutinee: expr::Expr, - clauses: Vec, - location: Location, - ) -> Self { - Self { - kind, - scrutinee: Box::new(scrutinee), - clauses, - location, - } - } - - pub fn scrutinee(&self, _db: &dyn crate::HirDb) -> Expr { - (*self.scrutinee).clone() - } - - pub fn clauses(&self, _db: &dyn crate::HirDb) -> Vec { - self.clauses.clone() - } - - pub fn location(&self, _db: &dyn crate::HirDb) -> Location { - self.location.clone() - } - } - impl HirElement for MatchExpr { fn location(&self, _: &dyn crate::HirDb) -> Location { self.location.clone() @@ -2130,49 +1991,14 @@ pub mod expr { impl walking::Walker for CallExpr { fn accept(self, db: &dyn crate::HirDb, listener: &mut T) { listener.enter_call_expr(self.clone()); - self.callee(db).accept(db, listener); - self.arguments(db).accept(db, listener); - self.do_notation(db).accept(db, listener); + self.callee.clone().accept(db, listener); + self.arguments.clone().accept(db, listener); + self.do_notation.clone().accept(db, listener); self.location(db).accept(db, listener); listener.exit_call_expr(self); } } - impl CallExpr { - pub fn new( - _: &dyn crate::HirDb, - kind: CallKind, - callee: Callee, - arguments: Vec, - do_notation: Option, - location: Location, - ) -> Self { - Self { - kind, - callee, - arguments, - do_notation, - location, - } - } - - pub fn callee(&self, _db: &dyn crate::HirDb) -> Callee { - self.callee.clone() - } - - pub fn arguments(&self, _db: &dyn crate::HirDb) -> Vec { - self.arguments.clone() - } - - pub fn do_notation(&self, _db: &dyn crate::HirDb) -> Option { - self.do_notation.clone() - } - - pub fn location(&self, _db: &dyn crate::HirDb) -> Location { - self.location.clone() - } - } - impl HirElement for CallExpr { fn location(&self, _: &dyn crate::HirDb) -> Location { self.location.clone() @@ -2250,28 +2076,26 @@ pub mod expr { impl Expr { /// Creates a unit expression. It's used to create a unit expression, that is just like a /// `()` value. - pub fn call_unit_expr(location: Location, db: &dyn crate::HirDb) -> Self { - Self::Call(CallExpr::new( - db, - /* kind = */ CallKind::Prefix, - /* callee = */ Callee::Unit, - /* arguments = */ vec![], - /* do_notation = */ None, - /* location = */ location, - )) + pub fn call_unit_expr(location: Location) -> Self { + Self::Call(CallExpr { + kind: CallKind::Prefix, + callee: Callee::Unit, + arguments: vec![], + do_notation: None, + location, + }) } /// Creates a block do-notation expression. It's used to create a block expression, that is /// just like a `do { }` value. pub fn block(db: &dyn crate::HirDb, do_notation: stmt::Block) -> Self { - Self::Call(CallExpr::new( - db, - /* kind = */ CallKind::Prefix, - /* callee = */ Callee::Do, - /* arguments = */ vec![], - /* do_notation = */ Some(do_notation.clone()), - /* location = */ do_notation.location(db), - )) + Self::Call(CallExpr { + kind: CallKind::Prefix, + callee: Callee::Do, + arguments: vec![], + do_notation: Some(do_notation.clone()), + location: do_notation.location(db), + }) } /// Upgrades this expression to a type representation. This is useful for error recovery and