Skip to content

Commit

Permalink
Up
Browse files Browse the repository at this point in the history
  • Loading branch information
azdavis committed Dec 20, 2023
1 parent 8698533 commit 3d75ccf
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 164 deletions.
132 changes: 67 additions & 65 deletions Cargo.lock

Large diffs are not rendered by default.

29 changes: 14 additions & 15 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,26 @@ publish = false
anyhow = "1.0.75"
better-panic = "0.3.0"
codespan-reporting = "0.11.1"
crossbeam-channel = "0.5.8"
crossbeam-channel = "0.5.9"
drop_bomb = "0.1.5"
env_logger = "0.10.0"
flate2 = "1.0.27"
env_logger = "0.10.1"
flate2 = "1.0.28"
la-arena = "0.3.1"
log = "0.4.20"
lsp-server = "0.7.3"
lsp-types = { version = "0.94.1", features = ["proposed"] }
num-bigint = "0.4.3"
num-traits = "0.2.16"
once_cell = "1.18.0"
lsp-server = "0.7.5"
lsp-types = { version = "0.95.0", features = ["proposed"] }
num-bigint = "0.4.4"
num-traits = "0.2.17"
once_cell = "1.19.0"
pico-args = "0.5.0"
pretty_assertions = "1.4.0"
prettyplease = "0.2.15"
proc-macro2 = "1.0.70"
pulldown-cmark = "0.9.3"
quote = "1.0.33"
rowan = "0.15.11"
serde = { version = "1.0.186", features = ["derive"] }
serde_json = "1.0.105"
syn = "2.0.41"
toml = "0.7.6"
rowan = "0.15.15"
serde = { version = "1.0.193", features = ["derive"] }
serde_json = "1.0.108"
toml = "0.8.8"
# language-util
code-h2-md-map.git = "https://github.com/azdavis/language-util.git"
diagnostic.git = "https://github.com/azdavis/language-util.git"
Expand All @@ -45,14 +43,15 @@ fmt-util.git = "https://github.com/azdavis/language-util.git"
idx.git = "https://github.com/azdavis/language-util.git"
paths.git = "https://github.com/azdavis/language-util.git"
pattern-match.git = "https://github.com/azdavis/language-util.git"
str-util.git = "https://github.com/azdavis/language-util.git"
str-util.features = ["serde"]
str-util.git = "https://github.com/azdavis/language-util.git"
syntax-gen.git = "https://github.com/azdavis/language-util.git"
text-pos.git = "https://github.com/azdavis/language-util.git"
text-size-util.git = "https://github.com/azdavis/language-util.git"
token.git = "https://github.com/azdavis/language-util.git"
topo-sort.git = "https://github.com/azdavis/language-util.git"
uniq.git = "https://github.com/azdavis/language-util.git"
write-rs-tokens.git = "https://github.com/azdavis/language-util.git"
# sml-libs
sml-libs.git = "https://github.com/azdavis/sml-libs.git"

Expand Down
59 changes: 27 additions & 32 deletions crates/sml-hir-lower/src/dec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ fn get_top_dec_one(st: &mut St<'_>, top_dec: ast::DecOne) -> sml_hir::StrDecIdx
//
// to have `4` be bound to `x`, but that's weird to do _in a source file_. at a REPL it's
// fine, but millet doesn't check a REPL, it checks source files.
pat: st.pat(sml_hir::Pat::Wild, ptr.clone()),
pat: st.pat(sml_hir::Pat::Wild, ptr),
exp: exp::get(st, top_dec.exp()),
};
let dec = sml_hir::Dec::Val(Vec::new(), vec![bind], sml_hir::ValFlavor::TopLevelExp);
let dec = st.dec(dec, ptr.clone());
let dec = st.dec(dec, ptr);
st.str_dec(sml_hir::StrDec::Dec(vec![dec]), ptr)
}
_ => get_str_dec_one(st, top_dec),
Expand Down Expand Up @@ -151,11 +151,11 @@ fn get_str_dec_one(st: &mut St<'_>, str_dec: ast::DecOne) -> sml_hir::StrDecIdx
});
let param_name = st.fresh();
let param_sig = sml_hir::SigExp::Spec(get_spec(st, decs));
let param_sig = st.sig_exp(param_sig, ptr.clone());
let dec = st
.dec(sml_hir::Dec::Open(vec![sml_path::Path::one(param_name.clone())]), ptr.clone());
let str_dec = st.str_dec(sml_hir::StrDec::Dec(vec![dec]), ptr.clone());
let body = st.str_exp(sml_hir::StrExp::Let(vec![str_dec], body), ptr.clone());
let param_sig = st.sig_exp(param_sig, ptr);
let dec =
st.dec(sml_hir::Dec::Open(vec![sml_path::Path::one(param_name.clone())]), ptr);
let str_dec = st.str_dec(sml_hir::StrDec::Dec(vec![dec]), ptr);
let body = st.str_exp(sml_hir::StrExp::Let(vec![str_dec], body), ptr);
(param_name, param_sig, body, sml_hir::Flavor::Sugared)
}
};
Expand Down Expand Up @@ -208,7 +208,7 @@ fn get_str_exp(st: &mut St<'_>, str_exp: Option<ast::StrExp>) -> sml_hir::StrExp
ast::AppStrExpArg::Dec(x) => Some(x),
});
let sd = get_str_dec(st, decs);
(st.str_exp(sml_hir::StrExp::Struct(sd), ptr.clone()), sml_hir::Flavor::Sugared)
(st.str_exp(sml_hir::StrExp::Struct(sd), ptr), sml_hir::Flavor::Sugared)
}
};
sml_hir::StrExp::App(get_name(str_exp.name())?, arg, flavor)
Expand Down Expand Up @@ -272,7 +272,7 @@ where
sml_hir::SharingKind::Derived
};
let paths_eq: Vec<_> = tail.path_eqs().filter_map(|x| get_path(x.path()?)).collect();
vec![st.spec(sml_hir::Spec::Sharing(ac, kind, paths_eq), ptr.clone())]
vec![st.spec(sml_hir::Spec::Sharing(ac, kind, paths_eq), ptr)]
}));
}
specs
Expand Down Expand Up @@ -352,18 +352,13 @@ fn get_spec_one(st: &mut St<'_>, dec: Option<ast::DecOne>) -> Vec<sml_hir::SpecI
let mut ret = f(sml_hir::TyDesc { name: name.clone(), ty_vars: ty_vars.clone() });
if let Some(ty) = ty_desc.eq_ty() {
let ty = ty::get(st, ty.ty());
let spec_idx = st.spec(ret, ptr.clone());
let sig_exp = st.sig_exp(sml_hir::SigExp::Spec(vec![spec_idx]), ptr.clone());
let sig_exp = st.sig_exp(
sml_hir::SigExp::Where(
sig_exp,
sml_hir::WhereKind::Type(ty_vars, sml_path::Path::one(name), ty),
),
ptr.clone(),
);
let spec_idx = st.spec(ret, ptr);
let sig_exp = st.sig_exp(sml_hir::SigExp::Spec(vec![spec_idx]), ptr);
let where_kind = sml_hir::WhereKind::Type(ty_vars, sml_path::Path::one(name), ty);
let sig_exp = st.sig_exp(sml_hir::SigExp::Where(sig_exp, where_kind), ptr);
ret = sml_hir::Spec::Include(sig_exp);
}
Some(st.spec(ret, ptr.clone()))
Some(st.spec(ret, ptr))
});
iter.collect()
}
Expand All @@ -377,7 +372,7 @@ fn get_spec_one(st: &mut St<'_>, dec: Option<ast::DecOne>) -> Vec<sml_hir::SpecI
}
let binds = dat_binds(st, dec.dat_binds());
let dat = sml_hir::Spec::Datatype(binds);
vec![st.spec(dat, ptr.clone())]
vec![st.spec(dat, ptr)]
}
ast::DecOne::DatCopyDec(dec) => {
if !st.lang().dec.datatype_copy {
Expand All @@ -401,7 +396,7 @@ fn get_spec_one(st: &mut St<'_>, dec: Option<ast::DecOne>) -> Vec<sml_hir::SpecI
None
}
});
Some(st.spec(sml_hir::Spec::Exception(sml_hir::ExDesc { name, ty }), ptr.clone()))
Some(st.spec(sml_hir::Spec::Exception(sml_hir::ExDesc { name, ty }), ptr))
});
iter.collect()
}
Expand Down Expand Up @@ -434,7 +429,7 @@ fn get_spec_one(st: &mut St<'_>, dec: Option<ast::DecOne>) -> Vec<sml_hir::SpecI
}
};
let spec = sml_hir::Spec::Str(sml_hir::StrDesc { name, sig_exp });
Some(st.spec(spec, ptr.clone()))
Some(st.spec(spec, ptr))
});
iter.collect()
}
Expand All @@ -444,7 +439,7 @@ fn get_spec_one(st: &mut St<'_>, dec: Option<ast::DecOne>) -> Vec<sml_hir::SpecI
}
let iter = dec.sig_exps().map(|x| {
let spec = sml_hir::Spec::Include(get_sig_exp(st, Some(x)));
st.spec(spec, ptr.clone())
st.spec(spec, ptr)
});
let specs: Vec<_> = iter.collect();
if specs.is_empty() {
Expand Down Expand Up @@ -561,7 +556,7 @@ fn get_one(st: &mut St<'_>, dec: ast::DecOne) -> Option<sml_hir::DecIdx> {
let lhs = head.lhs();
let rhs = head.rhs();
let tup = tuple([pat::get(st, None, lhs), pat::get(st, None, rhs)]);
pats.push(st.pat(tup, ptr.clone()));
pats.push(st.pat(tup, ptr));
head.name_star_eq()
}
})
Expand Down Expand Up @@ -591,7 +586,7 @@ fn get_one(st: &mut St<'_>, dec: ast::DecOne) -> Option<sml_hir::DecIdx> {
let pat = if pats.len() == 1 {
pats.pop().unwrap()
} else {
st.pat(pat::tuple(pats), ptr.clone())
st.pat(pat::tuple(pats), ptr)
};
let ty = case.ty_annotation().map(|ty_ann| {
forbid_opaque_asc(st, ty_ann.ascription());
Expand Down Expand Up @@ -626,19 +621,19 @@ fn get_one(st: &mut St<'_>, dec: ast::DecOne) -> Option<sml_hir::DecIdx> {
let exp = {
let arg_names: Vec<_> = (0..num_pats.unwrap_or(1)).map(|_| st.fresh()).collect();
let mut arg_exprs =
arg_names.iter().map(|name| st.exp(exp::name(name.as_str()), ptr.clone()));
arg_names.iter().map(|name| st.exp(exp::name(name.as_str()), ptr));
let head = if arg_exprs.len() == 1 {
arg_exprs.next().unwrap()
} else {
let tup = exp::tuple(arg_exprs);
st.exp(tup, ptr.clone())
st.exp(tup, ptr)
};
let flavor = sml_hir::FnFlavor::FunCase { tuple: num_pats.is_some_and(|x| x != 1) };
let case = exp::case(st, head, arms, ptr.clone(), flavor);
arg_names.into_iter().rev().fold(st.exp(case, ptr.clone()), |body, name| {
let pat = st.pat(pat::name(name.as_str()), ptr.clone());
let case = exp::case(st, head, arms, ptr, flavor);
arg_names.into_iter().rev().fold(st.exp(case, ptr), |body, name| {
let pat = st.pat(pat::name(name.as_str()), ptr);
let arm = sml_hir::Arm { pat, exp: body };
st.exp(sml_hir::Exp::Fn(vec![arm], sml_hir::FnFlavor::FunArg), ptr.clone())
st.exp(sml_hir::Exp::Fn(vec![arm], sml_hir::FnFlavor::FunArg), ptr)
})
};
sml_hir::ValBind {
Expand Down Expand Up @@ -761,7 +756,7 @@ fn get_one(st: &mut St<'_>, dec: ast::DecOne) -> Option<sml_hir::DecIdx> {
}
let bind = sml_hir::ValBind {
rec: false,
pat: st.pat(pat::tuple([]), ptr.clone()),
pat: st.pat(pat::tuple([]), ptr),
exp: exp::get(st, inner.exp()),
};
sml_hir::Dec::Val(Vec::new(), vec![bind], sml_hir::ValFlavor::Do)
Expand Down
64 changes: 32 additions & 32 deletions crates/sml-hir-lower/src/exp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub(crate) fn get(st: &mut St<'_>, exp: Option<ast::Exp>) -> sml_hir::ExpIdx {
let e = ErrorKind::Disallowed(Disallowed::SuccMl("expression row punning"));
st.err_tok(&tok, e);
}
st.exp(sml_hir::Exp::Path(sml_path::Path::one(name.clone())), ptr.clone())
st.exp(sml_hir::Exp::Path(sml_path::Path::one(name.clone())), ptr)
}
sml_hir::Lab::Num(_) => {
st.err_tok(&tok, ErrorKind::MissingRhs(MissingRhs::ExpRow));
Expand All @@ -62,10 +62,10 @@ pub(crate) fn get(st: &mut St<'_>, exp: Option<ast::Exp>) -> sml_hir::ExpIdx {
}
let lab = get_lab(st, exp.lab()?);
let fresh = st.fresh();
let pat = st.pat(pat::name(fresh.as_str()), ptr.clone());
let pat = st.pat(pat::name(fresh.as_str()), ptr);
let param =
st.pat(sml_hir::Pat::Record { rows: vec![(lab, pat)], allows_other: true }, ptr.clone());
let body = st.exp(name(fresh.as_str()), ptr.clone());
st.pat(sml_hir::Pat::Record { rows: vec![(lab, pat)], allows_other: true }, ptr);
let body = st.exp(name(fresh.as_str()), ptr);
let arm = sml_hir::Arm { pat: param, exp: body };
sml_hir::Exp::Fn(vec![arm], sml_hir::FnFlavor::Selector)
}
Expand Down Expand Up @@ -100,9 +100,9 @@ pub(crate) fn get(st: &mut St<'_>, exp: Option<ast::Exp>) -> sml_hir::ExpIdx {
#[allow(clippy::needless_collect)]
let exps: Vec<_> = exp.exp_args().map(|x| get(st, x.exp())).collect();
exps.into_iter().rev().fold(name("nil"), |ac, x| {
let cons = st.exp(name("::"), ptr.clone());
let ac = st.exp(ac, ptr.clone());
sml_hir::Exp::App(cons, st.exp(tuple([x, ac]), ptr.clone()))
let cons = st.exp(name("::"), ptr);
let ac = st.exp(ac, ptr);
sml_hir::Exp::App(cons, st.exp(tuple([x, ac]), ptr))
})
}
ast::Exp::VectorExp(exp) => {
Expand Down Expand Up @@ -144,7 +144,7 @@ pub(crate) fn get(st: &mut St<'_>, exp: Option<ast::Exp>) -> sml_hir::ExpIdx {
let e = ErrorKind::Disallowed(Disallowed::SuccMl("trailing `;` in `let` expressions"));
st.err_tok(&s, e);
}
exps.push(st.exp(tuple([]), ptr.clone()));
exps.push(st.exp(tuple([]), ptr));
}
let exp = exp_idx_in_seq(st, exps, exp.syntax());
sml_hir::Exp::Let(dec, exp)
Expand All @@ -159,10 +159,10 @@ pub(crate) fn get(st: &mut St<'_>, exp: Option<ast::Exp>) -> sml_hir::ExpIdx {
if !st.lang().exp.infix {
st.err(exp.syntax(), ErrorKind::Disallowed(Disallowed::Exp("infix application")));
}
let func = exp.name_star_eq().and_then(|x| st.exp(name(x.token.text()), ptr.clone()));
let func = exp.name_star_eq().and_then(|x| st.exp(name(x.token.text()), ptr));
let lhs = get(st, exp.lhs());
let rhs = get(st, exp.rhs());
let arg = st.exp(tuple([lhs, rhs]), ptr.clone());
let arg = st.exp(tuple([lhs, rhs]), ptr);
sml_hir::Exp::App(func, arg)
}
ast::Exp::TypedExp(exp) => {
Expand All @@ -183,8 +183,8 @@ pub(crate) fn get(st: &mut St<'_>, exp: Option<ast::Exp>) -> sml_hir::ExpIdx {
}
let cond = get(st, lhs);
let yes = get(st, rhs);
let no = st.exp(name("false"), ptr.clone());
if_(st, cond, yes, no, ptr.clone(), sml_hir::FnFlavor::BoolBinOp)
let no = st.exp(name("false"), ptr);
if_(st, cond, yes, no, ptr, sml_hir::FnFlavor::BoolBinOp)
}
ast::Exp::OrelseExp(exp) => {
if !st.lang().exp.orelse {
Expand All @@ -196,9 +196,9 @@ pub(crate) fn get(st: &mut St<'_>, exp: Option<ast::Exp>) -> sml_hir::ExpIdx {
st.err(exp.syntax(), ErrorKind::ComplexBoolExp);
}
let cond = get(st, lhs);
let yes = st.exp(name("true"), ptr.clone());
let yes = st.exp(name("true"), ptr);
let no = get(st, rhs);
if_(st, cond, yes, no, ptr.clone(), sml_hir::FnFlavor::BoolBinOp)
if_(st, cond, yes, no, ptr, sml_hir::FnFlavor::BoolBinOp)
}
ast::Exp::HandleExp(exp) => {
if !st.lang().exp.handle {
Expand Down Expand Up @@ -227,7 +227,7 @@ pub(crate) fn get(st: &mut St<'_>, exp: Option<ast::Exp>) -> sml_hir::ExpIdx {
let cond = get(st, cond);
let yes = get(st, yes);
let no = get(st, no);
if_(st, cond, yes, no, ptr.clone(), sml_hir::FnFlavor::If)
if_(st, cond, yes, no, ptr, sml_hir::FnFlavor::If)
}
ast::Exp::WhileExp(exp) => {
if !st.lang().exp.while_ {
Expand All @@ -237,20 +237,20 @@ pub(crate) fn get(st: &mut St<'_>, exp: Option<ast::Exp>) -> sml_hir::ExpIdx {
let fn_body = {
let cond = get(st, exp.cond());
let body = get(st, exp.body());
let call = call_unit_fn(st, &vid, ptr.clone());
let call = call_unit_fn(st, &vid, ptr);
let yes = exp_idx_in_seq(st, [body, call], exp.syntax());
let no = st.exp(tuple([]), ptr.clone());
let fn_body = if_(st, cond, yes, no, ptr.clone(), sml_hir::FnFlavor::While);
st.exp(fn_body, ptr.clone())
let no = st.exp(tuple([]), ptr);
let fn_body = if_(st, cond, yes, no, ptr, sml_hir::FnFlavor::While);
st.exp(fn_body, ptr)
};
let arg_pat = st.pat(pat::tuple([]), ptr.clone());
let arg_pat = st.pat(pat::tuple([]), ptr);
let arm = sml_hir::Arm { pat: arg_pat, exp: fn_body };
let fn_exp = st.exp(sml_hir::Exp::Fn(vec![arm], sml_hir::FnFlavor::While), ptr.clone());
let vid_pat = st.pat(pat::name(vid.as_str()), ptr.clone());
let fn_exp = st.exp(sml_hir::Exp::Fn(vec![arm], sml_hir::FnFlavor::While), ptr);
let vid_pat = st.pat(pat::name(vid.as_str()), ptr);
let bind = sml_hir::ValBind { rec: true, pat: vid_pat, exp: fn_exp };
let val =
st.dec(sml_hir::Dec::Val(vec![], vec![bind], sml_hir::ValFlavor::While), ptr.clone());
sml_hir::Exp::Let(vec![val], call_unit_fn(st, &vid, ptr.clone()))
st.dec(sml_hir::Dec::Val(vec![], vec![bind], sml_hir::ValFlavor::While), ptr);
sml_hir::Exp::Let(vec![val], call_unit_fn(st, &vid, ptr))
}
ast::Exp::CaseExp(exp) => {
if !st.lang().exp.case {
Expand All @@ -261,7 +261,7 @@ pub(crate) fn get(st: &mut St<'_>, exp: Option<ast::Exp>) -> sml_hir::ExpIdx {
if arms.len() == 1 {
st.err(exp.syntax(), ErrorKind::OneArmedCase);
}
case(st, head, arms, ptr.clone(), sml_hir::FnFlavor::Case)
case(st, head, arms, ptr, sml_hir::FnFlavor::Case)
}
ast::Exp::FnExp(exp) => {
if !st.lang().exp.fn_ {
Expand Down Expand Up @@ -338,8 +338,8 @@ where
}

fn call_unit_fn(st: &mut St<'_>, vid: &str_util::Name, ptr: SyntaxNodePtr) -> sml_hir::ExpIdx {
let vid_exp = st.exp(name(vid.as_str()), ptr.clone());
let arg_exp = st.exp(sml_hir::Exp::Record(vec![]), ptr.clone());
let vid_exp = st.exp(name(vid.as_str()), ptr);
let arg_exp = st.exp(sml_hir::Exp::Record(vec![]), ptr);
st.exp(sml_hir::Exp::App(vid_exp, arg_exp), ptr)
}

Expand All @@ -361,10 +361,10 @@ where
{
let ptr = SyntaxNodePtr::new(exp);
let ret = exps.into_iter().rev().reduce(|ac, x| {
let wild = st.pat(sml_hir::Pat::Wild, ptr.clone());
let wild = st.pat(sml_hir::Pat::Wild, ptr);
let arm = sml_hir::Arm { pat: wild, exp: ac };
let c = case(st, x, vec![arm], ptr.clone(), sml_hir::FnFlavor::Seq);
st.exp(c, ptr.clone())
let c = case(st, x, vec![arm], ptr, sml_hir::FnFlavor::Seq);
st.exp(c, ptr)
});
if ret.is_none() {
st.err(exp, ErrorKind::EmptyExpSemiSeq);
Expand All @@ -380,8 +380,8 @@ fn if_(
ptr: SyntaxNodePtr,
flavor: sml_hir::FnFlavor,
) -> sml_hir::Exp {
let yes_pat = st.pat(pat::name("true"), ptr.clone());
let no_pat = st.pat(pat::name("false"), ptr.clone());
let yes_pat = st.pat(pat::name("true"), ptr);
let no_pat = st.pat(pat::name("false"), ptr);
let yes_arm = sml_hir::Arm { pat: yes_pat, exp: yes };
let no_arm = sml_hir::Arm { pat: no_pat, exp: no };
case(st, cond, vec![yes_arm, no_arm], ptr, flavor)
Expand Down
Loading

0 comments on commit 3d75ccf

Please sign in to comment.