When looking at Luke's last PR, I had a question on how we store type variables for numbers. It looks like the number CIR nodes contain struct fields to hold num_var
s:
num: struct {
num_var: TypeVar,
literal: StringLiteral.Idx,
value: IntValue,
bound: types.Num.Int.Precision,
region: Region,
},
int: struct {
num_var: TypeVar,
requirements: types.Num.Int.Requirements,
value: IntValue,
region: Region,
},
My question is this:
Is num_var
supposed to represent the root Num(a(b))
type var, or the sub (Int(Signed8))
) type var, or something else?
If it's intended to represent the root Num
, then is there a reason we can't use the CIR Expr.Idx
for that? Or is there something that having this as a sub-field gets us?
This rust compiler also has this field, but I'm wondering in the Zig compilers "CIR node Idxs as Type Vars" design makes this unnecessary
It looks like there's a similar thing on tuple
as well:
const expr_idx = self.can_ir.store.addExpr(CIR.Expr{
.tuple = .{
.elems = elems_span,
.tuple_var = tuple_type_var,
.region = region,
},
)
I think here tuple_var
is meant to reference the type of whole tuple, but I think we could assign the type at expr_idx
?
i think the type var depends. For num
it's the range included the type like Int(Signed8)
and for int
it would be whatever fills the a
in Integer(a)
yeah I was thinking the same thing
I don't think that field is necessary anymore
also I have a PR that gets rid of bound
and literal
We had record_var inside the record CIR.Expr and I removed that and used the expression id instead for the type of the whole record.
Richard Feldman said:
I don't think that field is necessary anymore
@Richard Feldman are you looking at removing them in your PR?
I can see you have removed the requirements
field
I have not removed it
feel free to though!
Last updated: Jul 06 2025 at 12:14 UTC