rip out unneeded tracking of symbol variable mapping

This commit is contained in:
Folkert 2020-10-17 21:55:37 +02:00
parent 607799b96e
commit cfb2064868

View file

@ -123,7 +123,6 @@ impl Pools {
struct State { struct State {
env: Env, env: Env,
mark: Mark, mark: Mark,
vars_by_symbol: MutMap<Symbol, Variable>,
} }
pub fn run( pub fn run(
@ -136,10 +135,9 @@ pub fn run(
let state = State { let state = State {
env: env.clone(), env: env.clone(),
mark: Mark::NONE.next(), mark: Mark::NONE.next(),
vars_by_symbol: MutMap::default(),
}; };
let rank = Rank::toplevel(); let rank = Rank::toplevel();
let mut state = solve( let state = solve(
env, env,
state, state,
rank, rank,
@ -150,10 +148,6 @@ pub fn run(
constraint, constraint,
); );
// by default, state.vars_by_symbol only gives back top-level symbols and their variable
// for closure size inference, we need all of the symbols, we do that here
state.env.vars_by_symbol.extend(state.vars_by_symbol);
(Solved(subs), state.env) (Solved(subs), state.env)
} }
@ -168,10 +162,9 @@ pub fn run_in_place(
let state = State { let state = State {
env: env.clone(), env: env.clone(),
mark: Mark::NONE.next(), mark: Mark::NONE.next(),
vars_by_symbol: MutMap::default(),
}; };
let rank = Rank::toplevel(); let rank = Rank::toplevel();
let mut state = solve( let state = solve(
env, env,
state, state,
rank, rank,
@ -182,17 +175,13 @@ pub fn run_in_place(
constraint, constraint,
); );
// by default, state.vars_by_symbol only gives back top-level symbols and their variable
// for closure size inference, we need all of the symbols, we do that here
state.env.vars_by_symbol.extend(state.vars_by_symbol);
state.env state.env
} }
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
fn solve( fn solve(
env: &Env, env: &Env,
mut state: State, state: State,
rank: Rank, rank: Rank,
pools: &mut Pools, pools: &mut Pools,
problems: &mut Vec<TypeError>, problems: &mut Vec<TypeError>,
@ -201,22 +190,13 @@ fn solve(
constraint: &Constraint, constraint: &Constraint,
) -> State { ) -> State {
match constraint { match constraint {
True => { True => state,
state
.vars_by_symbol
.extend(env.vars_by_symbol.iter().map(|(x, y)| (*x, *y)));
state
}
SaveTheEnvironment => { SaveTheEnvironment => {
// NOTE deviation: elm only copies the env into the state on SaveTheEnvironment // NOTE deviation: elm only copies the env into the state on SaveTheEnvironment
let mut copy = state; let mut copy = state;
copy.env = env.clone(); copy.env = env.clone();
copy.vars_by_symbol
.extend(env.vars_by_symbol.iter().map(|(x, y)| (*x, *y)));
copy copy
} }
Eq(typ, expectation, category, region) => { Eq(typ, expectation, category, region) => {
@ -403,7 +383,7 @@ fn solve(
) )
} }
ret_con if let_con.rigid_vars.is_empty() && let_con.flex_vars.is_empty() => { ret_con if let_con.rigid_vars.is_empty() && let_con.flex_vars.is_empty() => {
let mut state = solve( let state = solve(
env, env,
state, state,
rank, rank,
@ -436,10 +416,6 @@ fn solve(
} }
} }
state
.vars_by_symbol
.extend(new_env.vars_by_symbol.iter().map(|(x, y)| (*x, *y)));
let new_state = solve( let new_state = solve(
&new_env, &new_env,
state, state,
@ -498,10 +474,6 @@ fn solve(
); );
} }
state
.vars_by_symbol
.extend(new_env.vars_by_symbol.iter().map(|(x, y)| (*x, *y)));
// run solver in next pool // run solver in next pool
// Solve the assignments' constraints first. // Solve the assignments' constraints first.
@ -589,7 +561,6 @@ fn solve(
let temp_state = State { let temp_state = State {
env: new_state.env, env: new_state.env,
mark: final_mark, mark: final_mark,
vars_by_symbol: new_state.vars_by_symbol,
}; };
// Now solve the body, using the new vars_by_symbol which includes // Now solve the body, using the new vars_by_symbol which includes