mirror of
https://github.com/HigherOrderCO/Kind1.git
synced 2024-08-16 03:40:33 +03:00
fix: erasure
This commit is contained in:
parent
ef4c8f34cd
commit
523b8f2963
@ -191,7 +191,7 @@ pub fn derive_match(
|
||||
types.push(Argument {
|
||||
hidden: false,
|
||||
erased: false,
|
||||
name: Ident::new_static(&format!("{}_", cons.name.to_string()), range),
|
||||
name: Ident::new_static(&format!("_{}", cons.name.to_string()), range),
|
||||
typ: Some(cons_type),
|
||||
range,
|
||||
});
|
||||
@ -239,11 +239,11 @@ pub fn derive_match(
|
||||
spine_params = sum
|
||||
.parameters
|
||||
.extend(&cons.args)
|
||||
.map(|x| x.name.with_name(|f| format!("{}_", f)))
|
||||
.map(|x| x.name.with_name(|f| format!("_{}", f)))
|
||||
.to_vec();
|
||||
spine = cons
|
||||
.args
|
||||
.map(|x| x.name.with_name(|f| format!("{}_", f)))
|
||||
.map(|x| x.name.with_name(|f| format!("_{}", f)))
|
||||
.to_vec();
|
||||
args_indices = args
|
||||
.iter()
|
||||
@ -261,7 +261,7 @@ pub fn derive_match(
|
||||
let renames = FxHashMap::from_iter(
|
||||
sum.parameters
|
||||
.extend(&cons.args)
|
||||
.map(|x| (x.name.to_string(), format!("{}_", x.name.to_string())))
|
||||
.map(|x| (x.name.to_string(), format!("_{}", x.name.to_string())))
|
||||
.iter()
|
||||
.cloned(),
|
||||
);
|
||||
@ -280,12 +280,12 @@ pub fn derive_match(
|
||||
.parameters
|
||||
.extend(&sum.indices)
|
||||
.extend(&cons.args)
|
||||
.map(|x| x.name.with_name(|f| format!("{}_", f)))
|
||||
.map(|x| x.name.with_name(|f| format!("_{}", f)))
|
||||
.to_vec();
|
||||
spine = sum
|
||||
.indices
|
||||
.extend(&cons.args)
|
||||
.map(|x| x.name.with_name(|f| format!("{}_", f)))
|
||||
.map(|x| x.name.with_name(|f| format!("_{}", f)))
|
||||
.to_vec();
|
||||
args_indices = sum
|
||||
.indices
|
||||
|
@ -106,7 +106,7 @@ pub fn derive_open(range: Range, rec: &RecordDecl) -> concrete::Entry {
|
||||
let spine: Vec<Ident> = rec
|
||||
.fields
|
||||
.iter()
|
||||
.map(|(name, _, _)| name.with_name(|f| format!("{}_", f)))
|
||||
.map(|(name, _, _)| name.with_name(|f| format!("_{}", f)))
|
||||
.collect();
|
||||
|
||||
pats.push(Box::new(Pat {
|
||||
|
@ -59,7 +59,7 @@ fn ident_to_path(
|
||||
ident: &QualifiedIdent,
|
||||
search_on_parent: bool,
|
||||
) -> Result<Option<PathBuf>, Box<dyn Diagnostic>> {
|
||||
let name = ident.root.to_string();
|
||||
let name = ident.to_string();
|
||||
let segments = name.as_str().split('.').collect::<Vec<&str>>();
|
||||
let mut raw_path = root.to_path_buf();
|
||||
raw_path.push(PathBuf::from(segments.join("/")));
|
||||
|
@ -13,6 +13,7 @@ use kind_report::data::Diagnostic;
|
||||
pub struct Session {
|
||||
pub loaded_paths: Vec<Rc<PathBuf>>,
|
||||
pub loaded_sources: Vec<String>,
|
||||
|
||||
pub loaded_paths_map: FxHashMap<PathBuf, usize>,
|
||||
|
||||
/// It will be useful in the future
|
||||
|
@ -262,24 +262,12 @@ impl<'a> Parser<'a> {
|
||||
self.eat_id("as")?;
|
||||
let alias = self.parse_upper_id()?;
|
||||
|
||||
match (origin, alias) {
|
||||
(
|
||||
QualifiedIdent {
|
||||
aux: Some(_),
|
||||
range,
|
||||
..
|
||||
},
|
||||
_,
|
||||
)
|
||||
| (
|
||||
_,
|
||||
QualifiedIdent {
|
||||
aux: Some(_),
|
||||
range,
|
||||
..
|
||||
},
|
||||
) => Err(SyntaxDiagnostic::ImportsCannotHaveAlias(range)),
|
||||
(origin, alias) => Ok((origin.to_string(), alias.to_string())),
|
||||
if origin.get_aux().is_some() {
|
||||
Err(SyntaxDiagnostic::ImportsCannotHaveAlias(origin.range))
|
||||
} else if alias.get_aux().is_some() {
|
||||
Err(SyntaxDiagnostic::ImportsCannotHaveAlias(alias.range))
|
||||
} else {
|
||||
Ok((origin.to_string(), alias.to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ impl<'a> DesugarState<'a> {
|
||||
if create_var {
|
||||
arguments.push(desugared::Expr::var(self.gen_name(arg.range)))
|
||||
} else {
|
||||
arguments.push(self.gen_hole_expr())
|
||||
arguments.push(self.gen_hole_expr(arg.range))
|
||||
}
|
||||
} else {
|
||||
arguments.push(spine_iter.next().unwrap().to_owned())
|
||||
@ -93,7 +93,7 @@ impl<'a> DesugarState<'a> {
|
||||
if entry.arguments[i].hidden {
|
||||
// It's not expected that positional arguments require the range so
|
||||
// it's the reason why we are using a terrible "ghost range"
|
||||
arguments[i] = Some((Range::ghost_range(), self.gen_hole_expr()))
|
||||
arguments[i] = Some((Range::ghost_range(), self.gen_hole_expr(Range::ghost_range())))
|
||||
}
|
||||
}
|
||||
} else if entry.arguments.len() != args.len() {
|
||||
|
@ -249,7 +249,7 @@ impl<'a> DesugarState<'a> {
|
||||
} else {
|
||||
let mut idx: Vec<Ident> = sum.indices.iter().map(|x| x.name.clone()).collect();
|
||||
idx.push(Ident::generate("_val"));
|
||||
idx.iter().rfold(self.gen_hole_expr(), |expr, l| {
|
||||
idx.iter().rfold(self.gen_hole_expr(match_.typ.range), |expr, l| {
|
||||
desugared::Expr::lambda(l.range, l.clone(), expr, false)
|
||||
})
|
||||
};
|
||||
|
@ -280,7 +280,7 @@ impl<'a> DesugarState<'a> {
|
||||
typ.range,
|
||||
self.gen_name(expr.range),
|
||||
self.desugar_expr(typ),
|
||||
self.gen_hole_expr(),
|
||||
self.gen_hole_expr(typ.range),
|
||||
*erased,
|
||||
),
|
||||
),
|
||||
|
@ -61,13 +61,13 @@ impl<'a> DesugarState<'a> {
|
||||
|
||||
fn gen_name(&mut self, range: Range) -> Ident {
|
||||
self.name_count += 1;
|
||||
Ident::new(format!("x{}_", self.name_count), range)
|
||||
Ident::new(format!("_x{}", self.name_count), range)
|
||||
}
|
||||
|
||||
fn gen_hole_expr(&mut self) -> Box<desugared::Expr> {
|
||||
fn gen_hole_expr(&mut self, range: Range) -> Box<desugared::Expr> {
|
||||
Box::new(desugared::Expr {
|
||||
data: desugared::ExprKind::Hole(self.gen_hole()),
|
||||
span: Span::Generated,
|
||||
span: Span::Locatable(range),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -265,22 +265,13 @@ impl<'a> ErasureState<'a> {
|
||||
|
||||
match &expr.data {
|
||||
Num(_) | Str(_) => Box::new(expr.clone()),
|
||||
Typ | NumType(_) | Err => {
|
||||
Typ | NumType(_) | Err | Hole(_) | Hlp(_) => {
|
||||
let span = expr.span.to_range().unwrap();
|
||||
if !self.unify(span, *on, (None, Relevance::Irrelevant), false) {
|
||||
self.err_irrelevant(None, span, None)
|
||||
}
|
||||
Box::new(expr.clone())
|
||||
}
|
||||
Hole(_) | Hlp(_) => match &expr.span {
|
||||
kind_span::Span::Generated => Box::new(expr.clone()),
|
||||
kind_span::Span::Locatable(span) => {
|
||||
if !self.unify(*span, *on, (None, Relevance::Irrelevant), false) {
|
||||
self.err_irrelevant(None, *span, None)
|
||||
}
|
||||
Box::new(expr.clone())
|
||||
}
|
||||
},
|
||||
Var(name) => {
|
||||
let relev = self.ctx.get(name.to_str()).unwrap();
|
||||
let declared_ty = (relev.1).0;
|
||||
|
@ -16,15 +16,15 @@ pub struct Expand {
|
||||
|
||||
impl Visitor for Expand {
|
||||
fn visit_qualified_ident(&mut self, ident: &mut kind_tree::symbol::QualifiedIdent) {
|
||||
if ident.aux.is_none() {
|
||||
if ident.get_aux().is_none() {
|
||||
return;
|
||||
}
|
||||
let alias = match self.names.get(&ident.root.to_string()) {
|
||||
let alias = match self.names.get(&ident.get_root().to_string()) {
|
||||
Some(path) => path,
|
||||
None => {
|
||||
self.errors
|
||||
.send(Box::new(PassError::CannotFindAlias(
|
||||
ident.root.to_string(),
|
||||
ident.get_root().to_string(),
|
||||
ident.range,
|
||||
)))
|
||||
.unwrap();
|
||||
@ -32,10 +32,10 @@ impl Visitor for Expand {
|
||||
return;
|
||||
}
|
||||
};
|
||||
match &ident.aux {
|
||||
match &ident.get_aux() {
|
||||
Some(post) => {
|
||||
ident.change_root(format!("{}.{}", alias, post));
|
||||
ident.aux = None;
|
||||
ident.reset_aux()
|
||||
}
|
||||
None => ident.change_root(alias.clone()),
|
||||
}
|
||||
|
@ -94,12 +94,12 @@ impl UnboundCollector {
|
||||
fn visit_top_level_names(&mut self, toplevel: &mut TopLevel) {
|
||||
match toplevel {
|
||||
TopLevel::SumType(sum) => {
|
||||
debug_assert!(sum.name.aux.is_none());
|
||||
debug_assert!(sum.name.get_aux().is_none());
|
||||
self.top_level_defs
|
||||
.insert(sum.name.get_root(), sum.name.range);
|
||||
for cons in &sum.constructors {
|
||||
let name_cons = sum.name.add_segment(cons.name.to_str());
|
||||
debug_assert!(name_cons.aux.is_none());
|
||||
debug_assert!(name_cons.get_aux().is_none());
|
||||
self.top_level_defs
|
||||
.insert(name_cons.get_root(), name_cons.range);
|
||||
}
|
||||
@ -107,8 +107,8 @@ impl UnboundCollector {
|
||||
TopLevel::RecordType(rec) => {
|
||||
let name_cons = rec.name.add_segment(rec.constructor.to_str());
|
||||
|
||||
debug_assert!(rec.name.aux.is_none());
|
||||
debug_assert!(name_cons.aux.is_none());
|
||||
debug_assert!(rec.name.get_aux().is_none());
|
||||
debug_assert!(name_cons.get_aux().is_none());
|
||||
|
||||
self.top_level_defs
|
||||
.insert(rec.name.get_root(), rec.name.range);
|
||||
@ -117,7 +117,7 @@ impl UnboundCollector {
|
||||
}
|
||||
|
||||
TopLevel::Entry(entry) => {
|
||||
debug_assert!(entry.name.aux.is_none());
|
||||
debug_assert!(entry.name.get_aux().is_none());
|
||||
self.top_level_defs
|
||||
.insert(entry.name.get_root(), entry.name.range);
|
||||
}
|
||||
@ -140,7 +140,7 @@ impl Visitor for UnboundCollector {
|
||||
}
|
||||
|
||||
fn visit_qualified_ident(&mut self, ident: &mut QualifiedIdent) {
|
||||
debug_assert!(ident.aux.is_none());
|
||||
debug_assert!(ident.get_aux().is_none());
|
||||
if !self.top_level_defs.contains_key(&ident.get_root()) {
|
||||
let entry = self.unbound_top_level.entry(ident.get_root()).or_default();
|
||||
entry.insert(ident.clone());
|
||||
|
@ -49,8 +49,9 @@ pub struct Ident {
|
||||
/// constructions.
|
||||
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
|
||||
pub struct QualifiedIdent {
|
||||
pub root: Symbol,
|
||||
pub aux: Option<Symbol>,
|
||||
root: Symbol,
|
||||
aux: Option<Symbol>,
|
||||
|
||||
pub range: Range,
|
||||
|
||||
/// Flag that is useful to avoid unbound errors while
|
||||
@ -82,6 +83,16 @@ impl QualifiedIdent {
|
||||
self.root.data.clone()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_aux(&self) -> Option<Symbol> {
|
||||
self.aux.clone()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn reset_aux(&mut self) {
|
||||
self.aux = None
|
||||
}
|
||||
|
||||
pub fn change_root(&mut self, str: String) {
|
||||
self.root = Symbol::new(str);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user