1
1
mirror of https://github.com/oxalica/nil.git synced 2024-11-23 03:57:06 +03:00

Update la-arena and add capacity hints

This commit is contained in:
oxalica 2023-02-03 03:45:17 +08:00
parent 97de111137
commit 6b2eb7b9eb
5 changed files with 31 additions and 25 deletions

28
Cargo.lock generated
View File

@ -101,15 +101,15 @@ dependencies = [
[[package]]
name = "dissimilar"
version = "1.0.5"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd5f0c7e4bd266b8ab2550e6238d2e74977c23c15536ac7be45e9c95e2e3fbbb"
checksum = "210ec60ae7d710bed8683e333e9d2855a8a56a3e9892b38bad3bb0d4d29b0d5e"
[[package]]
name = "either"
version = "1.8.0"
version = "1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797"
checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91"
[[package]]
name = "expect-test"
@ -211,9 +211,9 @@ checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440"
[[package]]
name = "la-arena"
version = "0.2.1"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d43db9f547ba2787bdeac81ef97ccc80784f385b3b39b4d50344270629a2bee3"
checksum = "1dabfe0d01e15fde0eba33b9de62475c59e681a47ce4ffe0534af2577a3f8524"
[[package]]
name = "lazy_static"
@ -434,9 +434,9 @@ checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116"
[[package]]
name = "proc-macro2"
version = "1.0.49"
version = "1.0.50"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57a8eca9f9c4ffde41714334dee777596264c7825420f521abc92b5b5deb63a5"
checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2"
dependencies = [
"unicode-ident",
]
@ -476,9 +476,9 @@ dependencies = [
[[package]]
name = "regex"
version = "1.7.0"
version = "1.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a"
checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733"
dependencies = [
"regex-syntax",
]
@ -763,9 +763,9 @@ dependencies = [
[[package]]
name = "unicode-bidi"
version = "0.3.8"
version = "0.3.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992"
checksum = "d54675592c1dbefd78cbd98db9bacd89886e1ca50692a0692baefffdeb92dd58"
[[package]]
name = "unicode-ident"
@ -784,9 +784,9 @@ dependencies = [
[[package]]
name = "unicode-segmentation"
version = "1.10.0"
version = "1.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fdbf052a0783de01e944a6ce7a8cb939e295b1e7be835a1112c3b9a7f047a5a"
checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36"
[[package]]
name = "unicode-width"

View File

@ -11,7 +11,7 @@ builtin = { path = "../builtin" }
either = "1.8.0"
indexmap = "1.9.1"
itertools = "0.10.5"
la-arena = "0.2.1"
la-arena = "0.3.0"
nix-interop = { path = "../nix-interop" }
ordered-float = "3.4.0"
salsa = "0.17.0-pre.2"

View File

@ -78,11 +78,14 @@ pub(crate) fn liveness_check_query(
// Unused let-bindings are eagerly collected into this.
let mut unused_defs = Vec::new();
let name_cnt = module.names.len();
let expr_cnt = module.exprs.len();
// For rec-attrset check.
let mut visited_defs: ArenaMap<NameId, ()> = ArenaMap::default();
let mut visited_defs = ArenaMap::<NameId, ()>::with_capacity(name_cnt);
// For traversal of let-in bindings.
let mut visited_def_rhs = ArenaMap::default();
let mut visited_withs = ArenaMap::default();
let mut visited_def_rhs = ArenaMap::with_capacity(expr_cnt);
let mut visited_withs = ArenaMap::with_capacity(expr_cnt);
let mut stack = vec![module.entry_expr];
while !stack.is_empty() {

View File

@ -25,7 +25,10 @@ impl ops::Index<ScopeId> for ModuleScopes {
impl ModuleScopes {
pub(crate) fn module_scopes_query(db: &dyn DefDatabase, file_id: FileId) -> Arc<Self> {
let module = db.module(file_id);
let mut this = Self::default();
let mut this = Self {
scopes: Arena::new(),
scope_by_expr: ArenaMap::with_capacity(module.exprs.len()),
};
let root_scope = this.scopes.alloc(ScopeData {
parent: None,
kind: ScopeKind::Definitions(Default::default()),
@ -278,10 +281,9 @@ impl NameReference {
for (expr, resolved) in name_res.iter() {
match resolved {
ResolveResult::Builtin(_) => {}
&ResolveResult::Definition(name) => match this.def_refs.get_mut(name) {
Some(refs) => refs.push(expr),
None => this.def_refs.insert(name, vec![expr]),
},
&ResolveResult::Definition(name) => {
this.def_refs.entry(name).or_default().push(expr)
}
ResolveResult::WithExprs(withs) => withs
.iter()
.for_each(|&with_expr| this.with_refs.entry(with_expr).or_default().push(expr)),

View File

@ -464,8 +464,9 @@ impl<'db> InferCtx<'db> {
let mut i = Collector::new(&mut self.table);
let name_cnt = self.module.names().len();
let mut name_ty_map = ArenaMap::default();
let mut expr_ty_map = ArenaMap::default();
let expr_cnt = self.module.exprs().len();
let mut name_ty_map = ArenaMap::with_capacity(name_cnt);
let mut expr_ty_map = ArenaMap::with_capacity(expr_cnt);
for (name, _) in self.module.names() {
let ty = TyVar(u32::from(name.into_raw()));
name_ty_map.insert(name, i.collect(ty));