Browse Source

Remove size of typed_ast::Expression from 416 byte to 224 byte

David Peter 1 year ago
parent
commit
3a767fd344
2 changed files with 9 additions and 8 deletions
  1. 1 1
      numbat/src/typechecker/mod.rs
  2. 8 7
      numbat/src/typed_ast.rs

+ 1 - 1
numbat/src/typechecker/mod.rs

@@ -96,7 +96,7 @@ impl TypeChecker {
                         // if we see a struct name here, it's safe to assume it
                         // isn't accidentally clashing with a dimension, we
                         // check that earlier.
-                        return Ok(Type::Struct(info.clone()));
+                        return Ok(Type::Struct(Box::new(info.clone())));
                     }
                 }
 

+ 8 - 7
numbat/src/typed_ast.rs

@@ -283,7 +283,7 @@ pub enum Type {
     String,
     DateTime,
     Fn(Vec<Type>, Box<Type>),
-    Struct(StructInfo),
+    Struct(Box<StructInfo>),
     List(Box<Type>),
 }
 
@@ -306,7 +306,8 @@ impl std::fmt::Display for Type {
                     ps = param_types.iter().map(|p| p.to_string()).join(", ")
                 )
             }
-            Type::Struct(StructInfo { name, fields, .. }) => {
+            Type::Struct(info) => {
+                let StructInfo { name, fields, .. } = &**info;
                 write!(
                     f,
                     "{name} {{{}}}",
@@ -348,7 +349,7 @@ impl PrettyPrint for Type {
                     + return_type.pretty_print()
                     + m::operator("]")
             }
-            Type::Struct(StructInfo { name, .. }) => m::type_identifier(name),
+            Type::Struct(info) => m::type_identifier(&info.name),
             Type::List(element_type) => {
                 m::type_identifier("List")
                     + m::operator("<")
@@ -400,9 +401,9 @@ impl Type {
                 vars.dedup();
                 vars
             }
-            Type::Struct(StructInfo { fields, .. }) => {
+            Type::Struct(info) => {
                 let mut vars = vec![];
-                for (_, (_, t)) in fields {
+                for (_, (_, t)) in &info.fields {
                     vars.extend(t.type_variables(including_type_parameters));
                 }
                 vars
@@ -750,7 +751,7 @@ impl Expression {
             Expression::Boolean(_, _) => Type::Boolean,
             Expression::Condition(_, _, then_, _) => then_.get_type(),
             Expression::String(_, _) => Type::String,
-            Expression::InstantiateStruct(_, _, info_) => Type::Struct(info_.clone()),
+            Expression::InstantiateStruct(_, _, info_) => Type::Struct(Box::new(info_.clone())),
             Expression::AccessField(_, _, _, _, _struct_type, field_type) => {
                 field_type.unsafe_as_concrete()
             }
@@ -775,7 +776,7 @@ impl Expression {
             Expression::Condition(_, _, then_, _) => then_.get_type_scheme(),
             Expression::String(_, _) => TypeScheme::make_quantified(Type::String),
             Expression::InstantiateStruct(_, _, info_) => {
-                TypeScheme::make_quantified(Type::Struct(info_.clone()))
+                TypeScheme::make_quantified(Type::Struct(Box::new(info_.clone())))
             }
             Expression::AccessField(_, _, _, _, _struct_type, field_type) => field_type.clone(),
             Expression::List(_, _, inner) => match inner {