mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 16:21:11 +00:00
remove unused variables from let/letrec
This commit is contained in:
parent
e82c670747
commit
7be41d8c09
9 changed files with 74 additions and 130 deletions
|
@ -561,7 +561,7 @@ fn to_num_checked(symbol: Symbol, var_store: &mut VarStore, lowlevel: LowLevel)
|
|||
annotation: None,
|
||||
};
|
||||
|
||||
let body = LetNonRec(Box::new(def), Box::new(no_region(cont)), ret_var);
|
||||
let body = LetNonRec(Box::new(def), Box::new(no_region(cont)));
|
||||
|
||||
defn(
|
||||
symbol,
|
||||
|
@ -858,7 +858,7 @@ fn num_overflow_checked(symbol: Symbol, var_store: &mut VarStore, lowlevel: LowL
|
|||
annotation: None,
|
||||
};
|
||||
|
||||
let body = LetNonRec(Box::new(def), Box::new(no_region(cont)), ret_var);
|
||||
let body = LetNonRec(Box::new(def), Box::new(no_region(cont)));
|
||||
|
||||
defn(
|
||||
symbol,
|
||||
|
@ -1662,7 +1662,7 @@ fn str_to_num(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
|||
annotation: None,
|
||||
};
|
||||
|
||||
let body = LetNonRec(Box::new(def), Box::new(no_region(cont)), ret_var);
|
||||
let body = LetNonRec(Box::new(def), Box::new(no_region(cont)));
|
||||
|
||||
defn(
|
||||
symbol,
|
||||
|
@ -1898,7 +1898,7 @@ fn str_from_utf8(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
|||
),
|
||||
};
|
||||
|
||||
let body = LetNonRec(Box::new(def), Box::new(no_region(cont)), ret_var);
|
||||
let body = LetNonRec(Box::new(def), Box::new(no_region(cont)));
|
||||
|
||||
defn(
|
||||
symbol,
|
||||
|
@ -2003,7 +2003,7 @@ fn str_from_utf8_range(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
|||
),
|
||||
};
|
||||
|
||||
let roc_result = LetNonRec(Box::new(def), Box::new(no_region(cont)), ret_var);
|
||||
let roc_result = LetNonRec(Box::new(def), Box::new(no_region(cont)));
|
||||
|
||||
// Only do the business with the let if we're in bounds!
|
||||
|
||||
|
@ -3759,11 +3759,7 @@ fn list_find(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
|||
final_else: Box::new(no_region(make_err)),
|
||||
};
|
||||
|
||||
let body = LetNonRec(
|
||||
Box::new(find_result_def),
|
||||
Box::new(no_region(inspect)),
|
||||
t_ret,
|
||||
);
|
||||
let body = LetNonRec(Box::new(find_result_def), Box::new(no_region(inspect)));
|
||||
|
||||
defn(
|
||||
symbol,
|
||||
|
@ -3933,7 +3929,7 @@ fn dict_get(symbol: Symbol, var_store: &mut VarStore) -> Def {
|
|||
final_else: Box::new(no_region(make_err)),
|
||||
};
|
||||
|
||||
let body = LetNonRec(Box::new(def), Box::new(no_region(inspect)), ret_var);
|
||||
let body = LetNonRec(Box::new(def), Box::new(no_region(inspect)));
|
||||
|
||||
defn(
|
||||
symbol,
|
||||
|
|
|
@ -1277,19 +1277,17 @@ pub fn can_defs_with_return<'a>(
|
|||
for declaration in declarations.into_iter().rev() {
|
||||
loc_expr = Loc {
|
||||
region: Region::zero(),
|
||||
value: decl_to_let(var_store, declaration, loc_expr),
|
||||
value: decl_to_let(declaration, loc_expr),
|
||||
};
|
||||
}
|
||||
|
||||
(loc_expr.value, output)
|
||||
}
|
||||
|
||||
fn decl_to_let(var_store: &mut VarStore, decl: Declaration, loc_ret: Loc<Expr>) -> Expr {
|
||||
fn decl_to_let(decl: Declaration, loc_ret: Loc<Expr>) -> Expr {
|
||||
match decl {
|
||||
Declaration::Declare(def) => {
|
||||
Expr::LetNonRec(Box::new(def), Box::new(loc_ret), var_store.fresh())
|
||||
}
|
||||
Declaration::DeclareRec(defs) => Expr::LetRec(defs, Box::new(loc_ret), var_store.fresh()),
|
||||
Declaration::Declare(def) => Expr::LetNonRec(Box::new(def), Box::new(loc_ret)),
|
||||
Declaration::DeclareRec(defs) => Expr::LetRec(defs, Box::new(loc_ret)),
|
||||
Declaration::InvalidCycle(entries) => {
|
||||
Expr::RuntimeError(RuntimeError::CircularDef(entries))
|
||||
}
|
||||
|
|
|
@ -661,7 +661,7 @@ fn force_effect(
|
|||
Loc::at_zero(call)
|
||||
};
|
||||
|
||||
Expr::LetNonRec(Box::new(def), Box::new(force_thunk_call), var_store.fresh())
|
||||
Expr::LetNonRec(Box::new(def), Box::new(force_thunk_call))
|
||||
}
|
||||
|
||||
fn build_effect_forever(
|
||||
|
@ -917,9 +917,7 @@ fn build_effect_forever_inner_body(
|
|||
Box::new(Loc::at_zero(Expr::LetNonRec(
|
||||
Box::new(force_thunk1),
|
||||
Box::new(force_thunk2),
|
||||
var_store.fresh(),
|
||||
))),
|
||||
var_store.fresh(),
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -1246,7 +1244,6 @@ fn build_effect_loop_inner_body(
|
|||
Expr::LetNonRec(
|
||||
Box::new(thunk_from_effect),
|
||||
Box::new(Loc::at_zero(match_on_force_thunk1)),
|
||||
var_store.fresh(),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -106,8 +106,8 @@ pub enum Expr {
|
|||
},
|
||||
|
||||
// Let
|
||||
LetRec(Vec<Def>, Box<Loc<Expr>>, Variable),
|
||||
LetNonRec(Box<Def>, Box<Loc<Expr>>, Variable),
|
||||
LetRec(Vec<Def>, Box<Loc<Expr>>),
|
||||
LetNonRec(Box<Def>, Box<Loc<Expr>>),
|
||||
|
||||
/// This is *only* for calling functions, not for tag application.
|
||||
/// The Tag variant contains any applied values inside it.
|
||||
|
@ -214,8 +214,8 @@ impl Expr {
|
|||
&Self::Var(sym) => Category::Lookup(sym),
|
||||
Self::When { .. } => Category::When,
|
||||
Self::If { .. } => Category::If,
|
||||
Self::LetRec(_, expr, _) => expr.value.category(),
|
||||
Self::LetNonRec(_, expr, _) => expr.value.category(),
|
||||
Self::LetRec(_, expr) => expr.value.category(),
|
||||
Self::LetNonRec(_, expr) => expr.value.category(),
|
||||
&Self::Call(_, _, called_via) => Category::CallResult(None, called_via),
|
||||
&Self::RunLowLevel { op, .. } => Category::LowLevelOpResult(op),
|
||||
Self::ForeignCall { .. } => Category::ForeignCall,
|
||||
|
@ -1477,7 +1477,7 @@ pub fn inline_calls(var_store: &mut VarStore, scope: &mut Scope, expr: Expr) ->
|
|||
Expect(Box::new(loc_condition), Box::new(loc_expr))
|
||||
}
|
||||
|
||||
LetRec(defs, loc_expr, var) => {
|
||||
LetRec(defs, loc_expr) => {
|
||||
let mut new_defs = Vec::with_capacity(defs.len());
|
||||
|
||||
for def in defs {
|
||||
|
@ -1498,10 +1498,10 @@ pub fn inline_calls(var_store: &mut VarStore, scope: &mut Scope, expr: Expr) ->
|
|||
value: inline_calls(var_store, scope, loc_expr.value),
|
||||
};
|
||||
|
||||
LetRec(new_defs, Box::new(loc_expr), var)
|
||||
LetRec(new_defs, Box::new(loc_expr))
|
||||
}
|
||||
|
||||
LetNonRec(def, loc_expr, var) => {
|
||||
LetNonRec(def, loc_expr) => {
|
||||
let def = Def {
|
||||
loc_pattern: def.loc_pattern,
|
||||
loc_expr: Loc {
|
||||
|
@ -1518,7 +1518,7 @@ pub fn inline_calls(var_store: &mut VarStore, scope: &mut Scope, expr: Expr) ->
|
|||
value: inline_calls(var_store, scope, loc_expr.value),
|
||||
};
|
||||
|
||||
LetNonRec(Box::new(def), Box::new(loc_expr), var)
|
||||
LetNonRec(Box::new(def), Box::new(loc_expr))
|
||||
}
|
||||
|
||||
Closure(ClosureData {
|
||||
|
@ -1672,11 +1672,7 @@ pub fn inline_calls(var_store: &mut VarStore, scope: &mut Scope, expr: Expr) ->
|
|||
|
||||
loc_answer = Loc {
|
||||
region: Region::zero(),
|
||||
value: LetNonRec(
|
||||
Box::new(def),
|
||||
Box::new(loc_answer),
|
||||
var_store.fresh(),
|
||||
),
|
||||
value: LetNonRec(Box::new(def), Box::new(loc_answer)),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -660,12 +660,12 @@ fn fix_values_captured_in_closure_expr(
|
|||
use crate::expr::Expr::*;
|
||||
|
||||
match expr {
|
||||
LetNonRec(def, loc_expr, _) => {
|
||||
LetNonRec(def, loc_expr) => {
|
||||
// LetNonRec(Box<Def>, Box<Located<Expr>>, Variable, Aliases),
|
||||
fix_values_captured_in_closure_def(def, no_capture_symbols);
|
||||
fix_values_captured_in_closure_expr(&mut loc_expr.value, no_capture_symbols);
|
||||
}
|
||||
LetRec(defs, loc_expr, _) => {
|
||||
LetRec(defs, loc_expr) => {
|
||||
// LetRec(Vec<Def>, Box<Located<Expr>>, Variable, Aliases),
|
||||
fix_values_captured_in_closure_defs(defs, no_capture_symbols);
|
||||
fix_values_captured_in_closure_expr(&mut loc_expr.value, no_capture_symbols);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue