Rename Located -> Loc

This commit is contained in:
Joshua Warner 2021-12-22 19:18:22 -08:00
parent c66c845cd2
commit f19220473a
55 changed files with 680 additions and 683 deletions

View file

@ -17,7 +17,7 @@ use roc_module::symbol::Symbol;
use roc_parse::ast::{self, EscapedChar, StrLiteral};
use roc_parse::pattern::PatternType::*;
use roc_problem::can::{PrecedenceProblem, Problem, RuntimeError};
use roc_region::all::{Located, Region};
use roc_region::all::{Loc, Region};
use roc_types::subs::{VarStore, Variable};
use roc_types::types::Alias;
use std::fmt::Debug;
@ -60,7 +60,7 @@ pub enum Expr {
Str(Box<str>),
List {
elem_var: Variable,
loc_elems: Vec<Located<Expr>>,
loc_elems: Vec<Loc<Expr>>,
},
// Lookups
@ -70,25 +70,25 @@ pub enum Expr {
cond_var: Variable,
expr_var: Variable,
region: Region,
loc_cond: Box<Located<Expr>>,
loc_cond: Box<Loc<Expr>>,
branches: Vec<WhenBranch>,
},
If {
cond_var: Variable,
branch_var: Variable,
branches: Vec<(Located<Expr>, Located<Expr>)>,
final_else: Box<Located<Expr>>,
branches: Vec<(Loc<Expr>, Loc<Expr>)>,
final_else: Box<Loc<Expr>>,
},
// Let
LetRec(Vec<Def>, Box<Located<Expr>>, Variable),
LetNonRec(Box<Def>, Box<Located<Expr>>, Variable),
LetRec(Vec<Def>, Box<Loc<Expr>>, Variable),
LetNonRec(Box<Def>, Box<Loc<Expr>>, Variable),
/// This is *only* for calling functions, not for tag application.
/// The Tag variant contains any applied values inside it.
Call(
Box<(Variable, Located<Expr>, Variable, Variable)>,
Vec<(Variable, Located<Expr>)>,
Box<(Variable, Loc<Expr>, Variable, Variable)>,
Vec<(Variable, Loc<Expr>)>,
CalledVia,
),
RunLowLevel {
@ -118,7 +118,7 @@ pub enum Expr {
record_var: Variable,
ext_var: Variable,
field_var: Variable,
loc_expr: Box<Located<Expr>>,
loc_expr: Box<Loc<Expr>>,
field: Lowercase,
},
/// field accessor as a function, e.g. (.foo) expr
@ -146,7 +146,7 @@ pub enum Expr {
variant_var: Variable,
ext_var: Variable,
name: TagName,
arguments: Vec<(Variable, Located<Expr>)>,
arguments: Vec<(Variable, Loc<Expr>)>,
},
ZeroArgumentTag {
@ -154,11 +154,11 @@ pub enum Expr {
variant_var: Variable,
ext_var: Variable,
name: TagName,
arguments: Vec<(Variable, Located<Expr>)>,
arguments: Vec<(Variable, Loc<Expr>)>,
},
// Test
Expect(Box<Located<Expr>>, Box<Located<Expr>>),
Expect(Box<Loc<Expr>>, Box<Loc<Expr>>),
// Compiles, but will crash if reached
RuntimeError(RuntimeError),
@ -172,8 +172,8 @@ pub struct ClosureData {
pub name: Symbol,
pub captured_symbols: Vec<(Symbol, Variable)>,
pub recursive: Recursive,
pub arguments: Vec<(Variable, Located<Pattern>)>,
pub loc_body: Box<Located<Expr>>,
pub arguments: Vec<(Variable, Loc<Pattern>)>,
pub loc_body: Box<Loc<Expr>>,
}
#[derive(Clone, Debug, PartialEq)]
@ -181,7 +181,7 @@ pub struct Field {
pub var: Variable,
// The region of the full `foo: f bar`, rather than just `f bar`
pub region: Region,
pub loc_expr: Box<Located<Expr>>,
pub loc_expr: Box<Loc<Expr>>,
}
#[derive(Clone, Debug, PartialEq)]
@ -193,9 +193,9 @@ pub enum Recursive {
#[derive(Clone, Debug, PartialEq)]
pub struct WhenBranch {
pub patterns: Vec<Located<Pattern>>,
pub value: Located<Expr>,
pub guard: Option<Located<Expr>>,
pub patterns: Vec<Loc<Pattern>>,
pub value: Loc<Expr>,
pub guard: Option<Loc<Expr>>,
}
pub fn canonicalize_expr<'a>(
@ -204,7 +204,7 @@ pub fn canonicalize_expr<'a>(
scope: &mut Scope,
region: Region,
expr: &'a ast::Expr<'a>,
) -> (Located<Expr>, Output) {
) -> (Loc<Expr>, Output) {
use Expr::*;
let (expr, output) = match expr {
@ -762,7 +762,7 @@ pub fn canonicalize_expr<'a>(
binop1_position.col,
binop1_position.col + binop1.width(),
);
let loc_binop1 = Located::at(region1, *binop1);
let loc_binop1 = Loc::at(region1, *binop1);
let region2 = Region::new(
binop2_position.row,
@ -770,7 +770,7 @@ pub fn canonicalize_expr<'a>(
binop2_position.col,
binop2_position.col + binop2.width(),
);
let loc_binop2 = Located::at(region2, *binop2);
let loc_binop2 = Loc::at(region2, *binop2);
let problem =
PrecedenceProblem::BothNonAssociative(*whole_region, loc_binop1, loc_binop2);
@ -859,7 +859,7 @@ pub fn canonicalize_expr<'a>(
// a rounding error anyway (especially given that they'll be surfaced as warnings), LLVM will
// DCE them in optimized builds, and it's not worth the bookkeeping for dev builds.
(
Located {
Loc {
region,
value: expr,
},
@ -1076,7 +1076,7 @@ fn canonicalize_fields<'a>(
var_store: &mut VarStore,
scope: &mut Scope,
region: Region,
fields: &'a [Located<ast::AssignedField<'a, ast::Expr<'a>>>],
fields: &'a [Loc<ast::AssignedField<'a, ast::Expr<'a>>>],
) -> Result<(SendMap<Lowercase, Field>, Output), CanonicalizeRecordProblem> {
let mut can_fields = SendMap::default();
let mut output = Output::default();
@ -1136,7 +1136,7 @@ fn canonicalize_field<'a>(
scope: &mut Scope,
field: &'a ast::AssignedField<'a, ast::Expr<'a>>,
region: Region,
) -> Result<(Lowercase, Located<Expr>, Output, Variable), CanonicalizeFieldProblem> {
) -> Result<(Lowercase, Loc<Expr>, Output, Variable), CanonicalizeFieldProblem> {
use roc_parse::ast::AssignedField::*;
match field {
@ -1251,7 +1251,7 @@ pub fn inline_calls(var_store: &mut VarStore, scope: &mut Scope, expr: Expr) ->
for loc_elem in loc_elems {
let value = inline_calls(var_store, scope, loc_elem.value);
new_elems.push(Located {
new_elems.push(Loc {
value,
region: loc_elem.region,
});
@ -1270,7 +1270,7 @@ pub fn inline_calls(var_store: &mut VarStore, scope: &mut Scope, expr: Expr) ->
loc_cond,
branches,
} => {
let loc_cond = Box::new(Located {
let loc_cond = Box::new(Loc {
region: loc_cond.region,
value: inline_calls(var_store, scope, loc_cond.value),
});
@ -1278,12 +1278,12 @@ pub fn inline_calls(var_store: &mut VarStore, scope: &mut Scope, expr: Expr) ->
let mut new_branches = Vec::with_capacity(branches.len());
for branch in branches {
let value = Located {
let value = Loc {
value: inline_calls(var_store, scope, branch.value.value),
region: branch.value.region,
};
let guard = match branch.guard {
Some(loc_expr) => Some(Located {
Some(loc_expr) => Some(Loc {
region: loc_expr.region,
value: inline_calls(var_store, scope, loc_expr.value),
}),
@ -1315,12 +1315,12 @@ pub fn inline_calls(var_store: &mut VarStore, scope: &mut Scope, expr: Expr) ->
let mut new_branches = Vec::with_capacity(branches.len());
for (loc_cond, loc_expr) in branches {
let loc_cond = Located {
let loc_cond = Loc {
value: inline_calls(var_store, scope, loc_cond.value),
region: loc_cond.region,
};
let loc_expr = Located {
let loc_expr = Loc {
value: inline_calls(var_store, scope, loc_expr.value),
region: loc_expr.region,
};
@ -1328,7 +1328,7 @@ pub fn inline_calls(var_store: &mut VarStore, scope: &mut Scope, expr: Expr) ->
new_branches.push((loc_cond, loc_expr));
}
let final_else = Box::new(Located {
let final_else = Box::new(Loc {
region: final_else.region,
value: inline_calls(var_store, scope, final_else.value),
});
@ -1342,12 +1342,12 @@ pub fn inline_calls(var_store: &mut VarStore, scope: &mut Scope, expr: Expr) ->
}
Expect(loc_condition, loc_expr) => {
let loc_condition = Located {
let loc_condition = Loc {
region: loc_condition.region,
value: inline_calls(var_store, scope, loc_condition.value),
};
let loc_expr = Located {
let loc_expr = Loc {
region: loc_expr.region,
value: inline_calls(var_store, scope, loc_expr.value),
};
@ -1361,7 +1361,7 @@ pub fn inline_calls(var_store: &mut VarStore, scope: &mut Scope, expr: Expr) ->
for def in defs {
new_defs.push(Def {
loc_pattern: def.loc_pattern,
loc_expr: Located {
loc_expr: Loc {
region: def.loc_expr.region,
value: inline_calls(var_store, scope, def.loc_expr.value),
},
@ -1371,7 +1371,7 @@ pub fn inline_calls(var_store: &mut VarStore, scope: &mut Scope, expr: Expr) ->
});
}
let loc_expr = Located {
let loc_expr = Loc {
region: loc_expr.region,
value: inline_calls(var_store, scope, loc_expr.value),
};
@ -1382,7 +1382,7 @@ pub fn inline_calls(var_store: &mut VarStore, scope: &mut Scope, expr: Expr) ->
LetNonRec(def, loc_expr, var) => {
let def = Def {
loc_pattern: def.loc_pattern,
loc_expr: Located {
loc_expr: Loc {
region: def.loc_expr.region,
value: inline_calls(var_store, scope, def.loc_expr.value),
},
@ -1391,7 +1391,7 @@ pub fn inline_calls(var_store: &mut VarStore, scope: &mut Scope, expr: Expr) ->
annotation: def.annotation,
};
let loc_expr = Located {
let loc_expr = Loc {
region: loc_expr.region,
value: inline_calls(var_store, scope, loc_expr.value),
};
@ -1411,7 +1411,7 @@ pub fn inline_calls(var_store: &mut VarStore, scope: &mut Scope, expr: Expr) ->
loc_body,
}) => {
let loc_expr = *loc_body;
let loc_expr = Located {
let loc_expr = Loc {
value: inline_calls(var_store, scope, loc_expr.value),
region: loc_expr.region,
};
@ -1486,7 +1486,7 @@ pub fn inline_calls(var_store: &mut VarStore, scope: &mut Scope, expr: Expr) ->
Var(symbol) if symbol.is_builtin() => match builtin_defs_map(symbol, var_store) {
Some(Def {
loc_expr:
Located {
Loc {
value:
Closure(ClosureData {
recursive,
@ -1526,7 +1526,7 @@ pub fn inline_calls(var_store: &mut VarStore, scope: &mut Scope, expr: Expr) ->
annotation: None,
};
loc_answer = Located {
loc_answer = Loc {
region: Region::zero(),
value: LetNonRec(
Box::new(def),
@ -1585,7 +1585,7 @@ pub fn is_valid_interpolation(expr: &ast::Expr<'_>) -> bool {
}
enum StrSegment {
Interpolation(Located<Expr>),
Interpolation(Loc<Expr>),
Plaintext(Box<str>),
}
@ -1684,22 +1684,22 @@ fn desugar_str_segments(var_store: &mut VarStore, segments: Vec<StrSegment>) ->
let mut iter = segments.into_iter().rev();
let mut loc_expr = match iter.next() {
Some(Plaintext(string)) => Located::new(0, 0, 0, 0, Expr::Str(string)),
Some(Plaintext(string)) => Loc::new(0, 0, 0, 0, Expr::Str(string)),
Some(Interpolation(loc_expr)) => loc_expr,
None => {
// No segments? Empty string!
Located::new(0, 0, 0, 0, Expr::Str("".into()))
Loc::new(0, 0, 0, 0, Expr::Str("".into()))
}
};
for seg in iter {
let loc_new_expr = match seg {
Plaintext(string) => Located::new(0, 0, 0, 0, Expr::Str(string)),
Plaintext(string) => Loc::new(0, 0, 0, 0, Expr::Str(string)),
Interpolation(loc_interpolated_expr) => loc_interpolated_expr,
};
let fn_expr = Located::new(0, 0, 0, 0, Expr::Var(Symbol::STR_CONCAT));
let fn_expr = Loc::new(0, 0, 0, 0, Expr::Var(Symbol::STR_CONCAT));
let expr = Expr::Call(
Box::new((
var_store.fresh(),
@ -1714,7 +1714,7 @@ fn desugar_str_segments(var_store: &mut VarStore, segments: Vec<StrSegment>) ->
CalledVia::StringInterpolation,
);
loc_expr = Located::new(0, 0, 0, 0, expr);
loc_expr = Loc::new(0, 0, 0, 0, expr);
}
loc_expr.value