From 4096442f753e2ff53cef6c9730c092f946bef7dc Mon Sep 17 00:00:00 2001 From: John Date: Fri, 26 Jul 2024 02:14:41 -0500 Subject: [PATCH] cl-typeck: Turn ref into a linked list. This should be fine, since the only thing you can do with a ref is dereference it. --- compiler/cl-typeck/src/entry/display.rs | 6 ++---- compiler/cl-typeck/src/type_expression.rs | 8 ++++++-- compiler/cl-typeck/src/type_kind.rs | 2 +- compiler/cl-typeck/src/type_kind/display.rs | 7 +------ 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/compiler/cl-typeck/src/entry/display.rs b/compiler/cl-typeck/src/entry/display.rs index fa7cbb1..6fac33f 100644 --- a/compiler/cl-typeck/src/entry/display.rs +++ b/compiler/cl-typeck/src/entry/display.rs @@ -21,10 +21,8 @@ impl fmt::Display for Entry<'_, '_> { TypeKind::Instance(id) => write!(f, "{}", self.with_id(*id)), TypeKind::Intrinsic(kind) => write!(f, "{kind}"), TypeKind::Adt(adt) => write_adt(adt, self, f), - &TypeKind::Ref(cnt, id) => { - for _ in 0..cnt { - f.write_str("&")?; - } + &TypeKind::Ref(id) => { + f.write_str("&")?; let h_id = self.with_id(id); write_name_or(h_id, f) } diff --git a/compiler/cl-typeck/src/type_expression.rs b/compiler/cl-typeck/src/type_expression.rs index bc0f451..5135c29 100644 --- a/compiler/cl-typeck/src/type_expression.rs +++ b/compiler/cl-typeck/src/type_expression.rs @@ -97,8 +97,12 @@ impl TypeExpression for TyTuple { impl TypeExpression for TyRef { fn evaluate(&self, table: &mut Table, node: Handle) -> Result { let Self { mutable: _, count, to } = self; - let kind = TypeKind::Ref(*count, to.evaluate(table, node)?); - Ok(table.anon_type(kind)) + let mut t = to.evaluate(table, node)?; + for _ in 0..*count { + let kind = TypeKind::Ref(t); + t = table.anon_type(kind) + } + Ok(t) } } diff --git a/compiler/cl-typeck/src/type_kind.rs b/compiler/cl-typeck/src/type_kind.rs index bdca147..b8d6f7d 100644 --- a/compiler/cl-typeck/src/type_kind.rs +++ b/compiler/cl-typeck/src/type_kind.rs @@ -17,7 +17,7 @@ pub enum TypeKind { /// A user-defined aromatic data type Adt(Adt), /// A reference to an already-defined type: &T - Ref(u16, Handle), + Ref(Handle), /// A contiguous view of dynamically sized memory Slice(Handle), /// A contiguous view of statically sized memory diff --git a/compiler/cl-typeck/src/type_kind/display.rs b/compiler/cl-typeck/src/type_kind/display.rs index 898e944..0c0fda7 100644 --- a/compiler/cl-typeck/src/type_kind/display.rs +++ b/compiler/cl-typeck/src/type_kind/display.rs @@ -11,12 +11,7 @@ impl Display for TypeKind { TypeKind::Instance(def) => write!(f, "alias to #{def}"), TypeKind::Intrinsic(i) => i.fmt(f), TypeKind::Adt(a) => a.fmt(f), - TypeKind::Ref(cnt, def) => { - for _ in 0..*cnt { - f.write_str("&")?; - } - def.fmt(f) - } + TypeKind::Ref(def) => write!(f, "&{def}"), TypeKind::Slice(def) => write!(f, "slice [#{def}]"), TypeKind::Array(def, size) => write!(f, "array [#{def}; {size}]"), TypeKind::Tuple(defs) => {