Fork of daniellemaywood.uk/gleam — Wasm codegen work
2

Configure Feed

Select the types of activity you want to include in your feed.

use immutable hash map and carry less data around

+31 -20
+1 -1
compiler-core/src/analyse.rs
··· 561 561 name_location: location, 562 562 .. 563 563 } => { 564 - let _ = environment.ignored_names.insert(name.clone(), *location); 564 + let _ = environment.discarded_names.insert(name.clone(), *location); 565 565 } 566 566 } 567 567
+3 -4
compiler-core/src/error.rs
··· 12 12 use crate::type_::{FieldAccessUsage, error::PatternMatchKind}; 13 13 use crate::{ast::BinOp, parse::error::ParseErrorType, type_::Type}; 14 14 use crate::{bit_array, diagnostic::Level, javascript, type_::UnifyErrorSituation}; 15 - use ecow::{EcoString, eco_format}; 15 + use ecow::EcoString; 16 16 use itertools::Itertools; 17 17 use pubgrub::Package; 18 18 use pubgrub::{DerivationTree, VersionSet}; ··· 2388 2388 TypeError::UnknownVariable { 2389 2389 location, 2390 2390 variables, 2391 - ignored_variables, 2391 + discarded_location, 2392 2392 name, 2393 2393 type_with_name_in_scope, 2394 2394 } => { ··· 2404 2404 } 2405 2405 }; 2406 2406 2407 - let ignored_variable = ignored_variables.get(&eco_format!("_{name}")); 2408 - let location = if let Some(ignored_location) = ignored_variable { 2407 + let location = if let Some(ignored_location) = discarded_location { 2409 2408 Location { 2410 2409 label: Label { 2411 2410 text: None,
+7 -7
compiler-core/src/type_/environment.rs
··· 58 58 59 59 // The names of all the ignored variables and arguments in scope: 60 60 // `let _var = 10` `pub fn main(_var) { todo }`. 61 - pub ignored_names: HashMap<EcoString, SrcSpan>, 61 + pub discarded_names: im::HashMap<EcoString, SrcSpan>, 62 62 63 63 /// Types defined in the current module (or the prelude) 64 64 pub module_types: HashMap<EcoString, TypeConstructor>, ··· 137 137 unqualified_imported_types: HashMap::new(), 138 138 accessors: prelude.accessors.clone(), 139 139 scope: prelude.values.clone().into(), 140 - ignored_names: HashMap::new(), 140 + discarded_names: im::HashMap::new(), 141 141 importable_modules, 142 142 current_module, 143 143 local_variable_usages: vec![HashMap::new()], ··· 153 153 #[derive(Debug)] 154 154 pub struct ScopeResetData { 155 155 local_values: im::HashMap<EcoString, ValueConstructor>, 156 - ignored_names: HashMap<EcoString, SrcSpan>, 156 + discarded_names: im::HashMap<EcoString, SrcSpan>, 157 157 } 158 158 159 159 impl Environment<'_> { ··· 176 176 177 177 pub fn open_new_scope(&mut self) -> ScopeResetData { 178 178 let local_values = self.scope.clone(); 179 - let ignored_names = self.ignored_names.clone(); 179 + let discarded_names = self.discarded_names.clone(); 180 180 self.local_variable_usages.push(HashMap::new()); 181 181 ScopeResetData { 182 182 local_values, 183 - ignored_names, 183 + discarded_names, 184 184 } 185 185 } 186 186 ··· 192 192 ) { 193 193 let ScopeResetData { 194 194 local_values, 195 - ignored_names, 195 + discarded_names, 196 196 } = data; 197 197 198 198 let unused = self ··· 208 208 self.handle_unused_variables(unused, problems); 209 209 } 210 210 self.scope = local_values; 211 - self.ignored_names = ignored_names; 211 + self.discarded_names = discarded_names; 212 212 } 213 213 214 214 pub fn next_uid(&mut self) -> u64 {
+5 -3
compiler-core/src/type_/error.rs
··· 14 14 use num_bigint::BigInt; 15 15 #[cfg(test)] 16 16 use pretty_assertions::assert_eq; 17 - use std::{collections::HashMap, sync::Arc}; 17 + use std::sync::Arc; 18 18 19 19 /// Errors and warnings discovered when compiling a module. 20 20 /// ··· 167 167 location: SrcSpan, 168 168 name: EcoString, 169 169 variables: Vec<EcoString>, 170 - ignored_variables: HashMap<EcoString, SrcSpan>, 170 + /// If there's a discarded variable with the same name in the same scope 171 + /// this will contain its location. 172 + discarded_location: Option<SrcSpan>, 171 173 type_with_name_in_scope: bool, 172 174 }, 173 175 ··· 1298 1300 location, 1299 1301 name, 1300 1302 variables, 1301 - ignored_variables: HashMap::new(), 1303 + discarded_location: None, 1302 1304 type_with_name_in_scope, 1303 1305 }, 1304 1306
+7 -2
compiler-core/src/type_/expression.rs
··· 18 18 parse::PatternPosition, 19 19 reference::ReferenceKind, 20 20 }; 21 + use ecow::eco_format; 21 22 use hexpm::version::{LowestVersion, Version}; 22 23 use im::hashmap; 23 24 use itertools::Itertools; ··· 1013 1014 ArgNames::Discard { name, .. } | ArgNames::LabelledDiscard { name, .. } => { 1014 1015 let _ = self 1015 1016 .environment 1016 - .ignored_names 1017 + .discarded_names 1017 1018 .insert(name.clone(), location); 1018 1019 } 1019 1020 } ··· 3479 3480 location: *location, 3480 3481 name: name.clone(), 3481 3482 variables: self.environment.local_value_names(), 3482 - ignored_variables: self.environment.ignored_names.clone(), 3483 + discarded_location: self 3484 + .environment 3485 + .discarded_names 3486 + .get(&eco_format!("_{name}")) 3487 + .cloned(), 3483 3488 type_with_name_in_scope: self 3484 3489 .environment 3485 3490 .module_types
+8 -3
compiler-core/src/type_/pattern.rs
··· 1 + use ecow::eco_format; 1 2 use hexpm::version::{LowestVersion, Version}; 2 3 use im::hashmap; 3 4 use itertools::Itertools; ··· 588 589 self.check_name_case(location, &name, Named::Discard); 589 590 let _ = self 590 591 .environment 591 - .ignored_names 592 + .discarded_names 592 593 .insert(name.clone(), location); 593 594 Pattern::Discard { 594 595 type_, ··· 635 636 location, 636 637 name: name.clone(), 637 638 variables: self.environment.local_value_names(), 638 - ignored_variables: self.environment.ignored_names.clone(), 639 + discarded_location: self 640 + .environment 641 + .discarded_names 642 + .get(&eco_format!("_{name}")) 643 + .cloned(), 639 644 type_with_name_in_scope: self 640 645 .environment 641 646 .module_types ··· 703 708 AssignName::Discard(right) => { 704 709 let _ = self 705 710 .environment 706 - .ignored_names 711 + .discarded_names 707 712 .insert(right.clone(), right_location); 708 713 self.check_name_case(right_location, right, Named::Discard); 709 714 }