Skip to content

Commit

Permalink
Fix compilation errors in bytecode::typecheck::reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
yannham committed Dec 20, 2024
1 parent 1732e47 commit 4db2879
Showing 1 changed file with 53 additions and 22 deletions.
75 changes: 53 additions & 22 deletions core/src/bytecode/typecheck/reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,40 +135,54 @@ pub trait ToType<'ast> {
///
/// When reporting error, we want to distinguish occurrences of unification variables and type
/// constants in a human-readable way.
fn to_type(self, reg: &mut NameReg, table: &UnifTable<'ast>) -> Self::Target;
fn to_type(
self,
alloc: &'ast AstAlloc,
reg: &mut NameReg,
table: &UnifTable<'ast>,
) -> Self::Target;
}

impl<'ast> ToType<'ast> for UnifType<'ast> {
type Target = Type<'ast>;

fn to_type(self, reg: &mut NameReg, table: &UnifTable<'ast>) -> Self::Target {
fn to_type(
self,
alloc: &'ast AstAlloc,
reg: &mut NameReg,
table: &UnifTable<'ast>,
) -> Self::Target {
let ty = self.into_root(table);

match ty {
UnifType::UnifVar { id, .. } => {
Type::from(TypeF::Var(reg.gen_var_name(id, VarKindDiscriminant::Type)))
TypeF::Var(reg.gen_var_name(id, VarKindDiscriminant::Type)).into()
}
UnifType::Constant(id) => {
Type::from(TypeF::Var(reg.gen_cst_name(id, VarKindDiscriminant::Type)))
TypeF::Var(reg.gen_cst_name(id, VarKindDiscriminant::Type)).into()
}
UnifType::Concrete { typ, .. } => {
let mapped = typ.map_state(
|btyp, reg| Box::new(btyp.to_type(reg, table)),
|rrows, reg| rrows.to_type(reg, table),
|erows, reg| erows.to_type(reg, table),
UnifType::Concrete { typ, .. } => typ
.map_state(
|btyp, reg| alloc.alloc(btyp.to_type(alloc, reg, table)),
|rrows, reg| rrows.to_type(alloc, reg, table),
|erows, reg| erows.to_type(alloc, reg, table),
|(ctr, _env), _reg| ctr,
reg,
);
Type::from(mapped)
}
)
.into(),
}
}
}

impl<'ast> ToType<'ast> for UnifRecordRows<'ast> {
type Target = RecordRows<'ast>;

fn to_type(self, reg: &mut NameReg, table: &UnifTable<'ast>) -> Self::Target {
fn to_type(
self,
alloc: &'ast AstAlloc,
reg: &mut NameReg,
table: &UnifTable<'ast>,
) -> Self::Target {
let rrows = self.into_root(table);

match rrows {
Expand All @@ -180,8 +194,8 @@ impl<'ast> ToType<'ast> for UnifRecordRows<'ast> {
)),
UnifRecordRows::Concrete { rrows, .. } => {
let mapped = rrows.map_state(
|btyp, reg| Box::new(btyp.to_type(reg, table)),
|rrows, reg| Box::new(rrows.to_type(reg, table)),
|btyp, reg| alloc.alloc(btyp.to_type(alloc, reg, table)),
|rrows, reg| alloc.alloc(rrows.to_type(alloc, reg, table)),
reg,
);
RecordRows(mapped)
Expand All @@ -193,7 +207,12 @@ impl<'ast> ToType<'ast> for UnifRecordRows<'ast> {
impl<'ast> ToType<'ast> for UnifEnumRows<'ast> {
type Target = EnumRows<'ast>;

fn to_type(self, reg: &mut NameReg, table: &UnifTable<'ast>) -> Self::Target {
fn to_type(
self,
alloc: &'ast AstAlloc,
reg: &mut NameReg,
table: &UnifTable<'ast>,
) -> Self::Target {
let erows = self.into_root(table);

match erows {
Expand All @@ -205,8 +224,8 @@ impl<'ast> ToType<'ast> for UnifEnumRows<'ast> {
)),
UnifEnumRows::Concrete { erows, .. } => {
let mapped = erows.map_state(
|btyp, reg| Box::new(btyp.to_type(reg, table)),
|erows, reg| Box::new(erows.to_type(reg, table)),
|btyp, reg| alloc.alloc(btyp.to_type(alloc, reg, table)),
|erows, reg| alloc.alloc(erows.to_type(alloc, reg, table)),
reg,
);
EnumRows(mapped)
Expand All @@ -218,21 +237,33 @@ impl<'ast> ToType<'ast> for UnifEnumRows<'ast> {
impl<'ast> ToType<'ast> for UnifEnumRow<'ast> {
type Target = EnumRow<'ast>;

fn to_type(self, reg: &mut NameReg, table: &UnifTable<'ast>) -> Self::Target {
fn to_type(
self,
alloc: &'ast AstAlloc,
reg: &mut NameReg,
table: &UnifTable<'ast>,
) -> Self::Target {
EnumRow {
id: self.id,
typ: self.typ.map(|typ| Box::new(typ.to_type(reg, table))),
typ: self
.typ
.map(|typ| alloc.alloc(typ.to_type(alloc, reg, table))),
}
}
}

impl<'ast> ToType<'ast> for UnifRecordRow<'ast> {
type Target = RecordRow<'ast>;

fn to_type(self, reg: &mut NameReg, table: &UnifTable<'ast>) -> Self::Target {
fn to_type(
self,
alloc: &'ast AstAlloc,
reg: &mut NameReg,
table: &UnifTable<'ast>,
) -> Self::Target {
RecordRow {
id: self.id,
typ: Box::new(self.typ.to_type(reg, table)),
typ: alloc.alloc(self.typ.to_type(alloc, reg, table)),
}
}
}

0 comments on commit 4db2879

Please sign in to comment.