mirror of
https://github.com/HigherOrderCO/Bend.git
synced 2024-09-11 11:56:54 +03:00
Fix pruning of native hvm defs
This commit is contained in:
parent
8b5555c490
commit
9fc8a726af
@ -49,8 +49,19 @@ impl Ctx<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn rm_def(book: &mut Book, def_name: &Name) {
|
||||||
|
if book.defs.contains_key(def_name) {
|
||||||
|
book.defs.shift_remove(def_name);
|
||||||
|
} else if book.hvm_defs.contains_key(def_name) {
|
||||||
|
book.hvm_defs.shift_remove(def_name);
|
||||||
|
} else {
|
||||||
|
unreachable!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Remove unused definitions.
|
// Remove unused definitions.
|
||||||
for def in self.book.defs.keys().cloned().collect::<Vec<_>>() {
|
let names = self.book.defs.keys().cloned().chain(self.book.hvm_defs.keys().cloned()).collect::<Vec<_>>();
|
||||||
|
for def in names {
|
||||||
if let Some(use_) = used.get(&def) {
|
if let Some(use_) = used.get(&def) {
|
||||||
match use_ {
|
match use_ {
|
||||||
Used::Main => {
|
Used::Main => {
|
||||||
@ -60,7 +71,7 @@ impl Ctx<'_> {
|
|||||||
// Used by a non-builtin definition.
|
// Used by a non-builtin definition.
|
||||||
// Prune if `prune_all`, otherwise show a warning.
|
// Prune if `prune_all`, otherwise show a warning.
|
||||||
if prune_all {
|
if prune_all {
|
||||||
self.book.defs.shift_remove(&def);
|
rm_def(self.book, &def);
|
||||||
} else {
|
} else {
|
||||||
self.info.add_rule_warning("Definition is unused.", WarningType::UnusedDefinition, def);
|
self.info.add_rule_warning("Definition is unused.", WarningType::UnusedDefinition, def);
|
||||||
}
|
}
|
||||||
@ -69,7 +80,7 @@ impl Ctx<'_> {
|
|||||||
// Unused, but a user-defined constructor.
|
// Unused, but a user-defined constructor.
|
||||||
// Prune if `prune_all`, otherwise nothing.
|
// Prune if `prune_all`, otherwise nothing.
|
||||||
if prune_all {
|
if prune_all {
|
||||||
self.book.defs.shift_remove(&def);
|
rm_def(self.book, &def);
|
||||||
} else {
|
} else {
|
||||||
// Don't show warning if it's a user-defined constructor.
|
// Don't show warning if it's a user-defined constructor.
|
||||||
}
|
}
|
||||||
@ -77,7 +88,7 @@ impl Ctx<'_> {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Unused builtin, can always be pruned.
|
// Unused builtin, can always be pruned.
|
||||||
self.book.defs.shift_remove(&def);
|
rm_def(self.book, &def);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user