mirror of
https://github.com/HigherOrderCO/Bend.git
synced 2024-10-05 15:57:08 +03:00
Fix 'free_vars' to be deterministic
Makes 'bend' desugar with imported types deterministic
This commit is contained in:
parent
3b91b0b72a
commit
2cc9e97453
@ -8,7 +8,6 @@ use interner::global::{GlobalPool, GlobalString};
|
||||
use itertools::Itertools;
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
collections::HashMap,
|
||||
hash::Hash,
|
||||
ops::{Deref, Range},
|
||||
};
|
||||
@ -819,8 +818,8 @@ impl Term {
|
||||
|
||||
/// Collects all the free variables that a term has
|
||||
/// and the number of times each var is used
|
||||
pub fn free_vars(&self) -> HashMap<Name, u64> {
|
||||
fn go_term(term: &Term, free_vars: &mut HashMap<Name, u64>) {
|
||||
pub fn free_vars(&self) -> IndexMap<Name, u64> {
|
||||
fn go_term(term: &Term, free_vars: &mut IndexMap<Name, u64>) {
|
||||
maybe_grow(|| {
|
||||
if let Term::Var { nam } = term {
|
||||
*free_vars.entry(nam.clone()).or_default() += 1;
|
||||
@ -831,7 +830,7 @@ impl Term {
|
||||
go_term(child, &mut new_scope);
|
||||
|
||||
for nam in binds.flatten() {
|
||||
new_scope.remove(nam);
|
||||
new_scope.shift_remove(nam);
|
||||
}
|
||||
|
||||
free_vars.extend(new_scope);
|
||||
|
@ -56,11 +56,11 @@ impl Term {
|
||||
// Gather the free variables
|
||||
// They will be implicitly captured by the new function
|
||||
let mut free_vars = step.free_vars();
|
||||
free_vars.remove(&Name::new(RECURSIVE_KW));
|
||||
free_vars.shift_remove(&Name::new(RECURSIVE_KW));
|
||||
free_vars.extend(base.free_vars());
|
||||
free_vars.extend(cond.free_vars());
|
||||
for bnd in bnd.iter().flatten() {
|
||||
free_vars.remove(bnd);
|
||||
free_vars.shift_remove(bnd);
|
||||
}
|
||||
let free_vars = free_vars.into_keys().collect::<Vec<_>>();
|
||||
|
||||
|
@ -412,7 +412,7 @@ pub fn lift_match_vars(match_term: &mut Term) -> &mut Term {
|
||||
for (binds, body) in arms {
|
||||
let mut arm_free_vars = body.free_vars();
|
||||
for bind in binds {
|
||||
arm_free_vars.remove(&bind);
|
||||
arm_free_vars.shift_remove(&bind);
|
||||
}
|
||||
free_vars.push(arm_free_vars.into_keys().collect());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user