Skip to content

Commit 0331fea

Browse files
committed
fix TestRunner
1 parent 04c75e2 commit 0331fea

File tree

3 files changed

+43
-42
lines changed

3 files changed

+43
-42
lines changed

lib/rivet/src/ast/TypeInfo.ri

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub enum TypeInfo < traits.Stringable {
7373
if type_sym !in self.implements {
7474
self.implements.push(type_sym);
7575
for b in self.bases {
76-
@as(+mut TypeInfo.Trait, b.info).implement(type_sym);
76+
@as(TypeInfo.Trait, b.info).implement(type_sym);
7777
}
7878
}
7979
}
@@ -145,8 +145,8 @@ pub enum TypeInfo < traits.Stringable {
145145
};
146146

147147
#[inline]
148-
pub func elem_type(self) -> ?+Type {
149-
return match self {
148+
pub func elem_type(&self) -> ?+Type {
149+
return match self.* {
150150
.Slice(slice) -> slice.elem_type,
151151
.Array(arr) -> arr.elem_type,
152152
.DynArray(vec) -> vec.elem_type,
@@ -155,8 +155,8 @@ pub enum TypeInfo < traits.Stringable {
155155
}
156156

157157
#[inline]
158-
pub func is_mut_array(self) -> bool {
159-
return match self {
158+
pub func is_mut_array(&self) -> bool {
159+
return match self.* {
160160
.Slice(slice) -> slice.is_mut,
161161
.Array(arr) -> arr.is_mut,
162162
.DynArray(vec) -> vec.is_mut,
@@ -165,15 +165,16 @@ pub enum TypeInfo < traits.Stringable {
165165
}
166166

167167
#[inline]
168-
pub func is_primitive(self) -> bool {
169-
return self is .Bool || self is .Rune || self is .SizedInt || self is .SizedUint
170-
|| self is .Uint || self is .Int || self is .ComptimeInt
171-
|| self is .ComptimeFloat || self is .ComptimeFloat || self is .Float;
168+
pub func is_primitive(&self) -> bool {
169+
return self.* is .Bool || self.* is .Rune || self.* is .SizedInt
170+
|| self.* is .SizedUint || self.* is .Uint || self.* is .Int
171+
|| self.* is .ComptimeInt || self.* is .ComptimeFloat
172+
|| self.* is .ComptimeFloat || self.* is .Float;
172173
}
173174

174175
#[inline]
175-
pub func is_compound(self) -> bool {
176-
return self is .Struct || self is .Trait || self is .Enum || self is .Tuple;
176+
pub func is_compound(&self) -> bool {
177+
return self.* is .Struct || self.* is .Trait || self.* is .Enum || self.* is .Tuple;
177178
}
178179

179180
#[inline]

rivetc/src/codegen/__init__.py

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def gen_source_files(self, source_files):
190190
CGen(self.comp).gen(self.out_rir)
191191
if self.comp.prefs.build_mode == prefs.BuildMode.Test:
192192
exit_code = os.system(self.comp.prefs.mod_output)
193-
os.remove(self.comp.prefs.mod_output)
193+
# os.remove(self.comp.prefs.mod_output)
194194
# assert exit_code == 0
195195
if exit_code != 0:
196196
exit(1)
@@ -441,7 +441,7 @@ def gen_stmt(self, stmt):
441441
if not stmt.value.is_ref or (
442442
isinstance(value_t_ir, ir.Pointer) and value_t_ir.is_managed
443443
):
444-
value = ir.Inst(ir.InstKind.LoadPtr, [value])
444+
value = ir.Inst(ir.InstKind.LoadPtr, [value], value_t_ir)
445445
unique_ir_name = self.cur_func.unique_name(stmt.value.name)
446446
self.cur_func.inline_alloca(value_t_ir, unique_ir_name, value)
447447
stmt.scope.update_ir_name(stmt.value.name, unique_ir_name)
@@ -618,6 +618,7 @@ def gen_expr_with_cast(self, expected_typ_, expr, custom_tmp = None):
618618

619619
expr_sym = expr.typ.symbol()
620620
expected_sym = expected_typ_.symbol()
621+
621622
if expected_sym.kind == TypeKind.Trait and expr_typ != expected_typ_ and expr_sym != expected_sym and expr.typ != self.comp.none_t:
622623
res_expr = self.trait_value(res_expr, expr_typ, expected_typ_)
623624
elif expr_sym.kind == TypeKind.Enum and expr_sym.info.is_tagged and expr_sym.info.has_variant(
@@ -1126,7 +1127,7 @@ def gen_expr(self, expr, custom_tmp = None):
11261127
)
11271128
is_vtable_call = True
11281129
if not isinstance(self_expr.typ, ir.Pointer):
1129-
self_expr = ir.Inst(ir.InstKind.LoadPtr, [self_expr])
1130+
self_expr = ir.Inst(ir.InstKind.LoadPtr, [self_expr], self_expr.typ.typ)
11301131
if left_sym.kind == TypeKind.Trait:
11311132
if left2_sym.kind == TypeKind.Trait and left_sym != left2_sym:
11321133
id_value = ir.Inst(
@@ -1218,7 +1219,7 @@ def gen_expr(self, expr, custom_tmp = None):
12181219
elif isinstance(
12191220
receiver.typ, type.Ptr
12201221
) and not expr.sym.self_is_ptr:
1221-
self_expr = ir.Inst(ir.InstKind.LoadPtr, [self_expr])
1222+
self_expr = ir.Inst(ir.InstKind.LoadPtr, [self_expr], self_expr.typ.typ)
12221223
args.append(self_expr)
12231224
args_len = expr.sym.args_len()
12241225
for i, arg in enumerate(expr.args):
@@ -1301,11 +1302,11 @@ def gen_expr(self, expr, custom_tmp = None):
13011302
value = ir.Inst(ir.InstKind.Cast, [inst, ret_typ.ptr()])
13021303
if custom_tmp:
13031304
self.cur_func.store(
1304-
custom_tmp, ir.Inst(ir.InstKind.LoadPtr, [value])
1305+
custom_tmp, ir.Inst(ir.InstKind.LoadPtr, [value], ret_typ.typ)
13051306
)
13061307
else:
13071308
self.cur_func.inline_alloca(
1308-
ret_typ, tmp, ir.Inst(ir.InstKind.LoadPtr, [value])
1309+
ret_typ, tmp, ir.Inst(ir.InstKind.LoadPtr, [value], ret_typ)
13091310
)
13101311
else:
13111312
if custom_tmp:
@@ -1463,7 +1464,7 @@ def gen_expr(self, expr, custom_tmp = None):
14631464
old_inside_selector_expr = self.inside_selector_expr
14641465
self.inside_selector_expr = True
14651466
left_sym = expr.left_typ.symbol()
1466-
left = self.gen_expr_with_cast(expr.left_typ, expr.left)
1467+
left = self.gen_expr(expr.left)
14671468
self.inside_selector_expr = old_inside_selector_expr
14681469
ir_left_typ = self.ir_type(expr.left_typ)
14691470
ir_typ = self.ir_type(expr.typ)
@@ -1498,10 +1499,8 @@ def gen_expr(self, expr, custom_tmp = None):
14981499
return ir.IntLit(ir.UINT_T, str(left.len))
14991500
elif left_sym.kind == TypeKind.Array and expr.field_name == "len":
15001501
return ir.IntLit(ir.UINT_T, str(left_sym.info.size))
1501-
elif left_sym.kind == TypeKind.Trait:
1502-
return ir.Selector(ir_typ.ptr(), left, ir.Name(expr.field_name))
1503-
if isinstance(left.typ, ir.Pointer):
1504-
left = ir.Inst(ir.InstKind.LoadPtr, [left], left.typ.typ)
1502+
if left_sym.kind == TypeKind.Trait:
1503+
ir_typ = ir_typ.ptr(True)
15051504
return ir.Selector(
15061505
ir_typ, left,
15071506
ir.Name(
@@ -1670,7 +1669,7 @@ def gen_expr(self, expr, custom_tmp = None):
16701669
ir.InstKind.GetElementPtr, [left, idx], expr_typ_ir
16711670
)
16721671
if not expr.is_ref:
1673-
value = ir.Inst(ir.InstKind.LoadPtr, [value])
1672+
value = ir.Inst(ir.InstKind.LoadPtr, [value], expr_typ_ir)
16741673
elif s.kind == TypeKind.String:
16751674
value = ir.Inst(
16761675
ir.InstKind.Call, [
@@ -1736,7 +1735,7 @@ def gen_expr(self, expr, custom_tmp = None):
17361735
expr_right_typ = expr.right.typ
17371736
if isinstance(expr_left_typ, type.Option):
17381737
if expr.op in (Kind.Eq, Kind.Ne):
1739-
left = self.gen_expr_with_cast(expr_left_typ, expr.left)
1738+
left = self.gen_expr(expr.left)
17401739
if expr_left_typ.is_pointer():
17411740
op = "==" if expr.op == Kind.Eq else "!="
17421741
return ir.Inst(
@@ -1750,7 +1749,7 @@ def gen_expr(self, expr, custom_tmp = None):
17501749
elif expr.op == Kind.OrElse:
17511750
expr_typ = expr_left_typ
17521751
is_not_never = expr.right.typ != self.comp.never_t
1753-
left = self.gen_expr_with_cast(expr_typ, expr.left)
1752+
left = self.gen_expr(expr.left)
17541753
is_none_label = self.cur_func.local_name()
17551754
is_not_none_label = self.cur_func.local_name()
17561755
exit_label = self.cur_func.local_name(
@@ -1878,7 +1877,7 @@ def gen_expr(self, expr, custom_tmp = None):
18781877
if not ((
18791878
isinstance(var_t2, ir.Pointer) and var_t2.is_managed
18801879
) or expr.var.is_ref):
1881-
val = ir.Inst(ir.InstKind.LoadPtr, [val], var_t2)
1880+
val = ir.Inst(ir.InstKind.LoadPtr, [val], var_t2.typ)
18821881
unique_name = self.cur_func.unique_name(expr.var.name)
18831882
expr.scope.update_ir_name(expr.var.name, unique_name)
18841883
self.cur_func.inline_alloca(var_t, unique_name, val)
@@ -1887,7 +1886,7 @@ def gen_expr(self, expr, custom_tmp = None):
18871886
elif expr.op in (Kind.KwIn, Kind.KwNotIn):
18881887
expr_left_typ = self.comp.comptime_number_to_type(expr_left_typ)
18891888
left = self.gen_expr_with_cast(expr_left_typ, expr.left)
1890-
right = self.gen_expr_with_cast(expr.right.typ, expr.right)
1889+
right = self.gen_expr(expr.right)
18911890
left_sym = expr_left_typ.symbol()
18921891
right_sym = expr.right.typ.symbol()
18931892
contains_method = f"contains_{right_sym.id}"
@@ -2154,7 +2153,7 @@ def gen_expr(self, expr, custom_tmp = None):
21542153
isinstance(var_t, ir.Pointer)
21552154
and var_t.is_managed
21562155
):
2157-
val = ir.Inst(ir.InstKind.LoadPtr, [val])
2156+
val = ir.Inst(ir.InstKind.LoadPtr, [val], var_t.typ)
21582157
unique_name = self.cur_func.unique_name(b.var_name)
21592158
b.scope.update_ir_name(b.var_name, unique_name)
21602159
self.cur_func.inline_alloca(var_t, unique_name, val)
@@ -2342,8 +2341,9 @@ def gen_left_assign(self, expr, right, assign_op):
23422341
else:
23432342
left = self.gen_expr_with_cast(expr.typ, expr)
23442343
elif isinstance(expr, ast.SelectorExpr):
2345-
if expr.is_indirect:
2346-
left = ir.Inst(ir.InstKind.LoadPtr, [self.gen_expr(expr.left)])
2344+
if expr.is_indirect or expr.is_boxed_indirect:
2345+
left_ir = self.gen_expr(expr.left)
2346+
left = ir.Inst(ir.InstKind.LoadPtr, [left_ir], left_ir.typ.typ)
23472347
else:
23482348
left = self.gen_expr_with_cast(expr.typ, expr)
23492349
elif isinstance(expr, ast.IndexExpr):
@@ -2666,8 +2666,7 @@ def trait_value(self, value, value_typ, trait_typ):
26662666
value_sym = self.comp.comptime_number_to_type(value_typ).symbol()
26672667
trait_sym = trait_typ.symbol()
26682668
size, _ = self.comp.type_size(value_typ)
2669-
trait_size, _ = self.comp.type_size(trait_typ)
2670-
tmp = self.boxed_instance(self.ir_type(trait_typ), trait_size)
2669+
tmp = self.boxed_instance(self.ir_type(trait_typ), str(self.comp.pointer_size * 3))
26712670
is_ptr = isinstance(value.typ, ir.Pointer)
26722671
for f in trait_sym.fields:
26732672
f_typ = self.ir_type(f.typ)
@@ -2818,7 +2817,7 @@ def gen_return_trace_clear(self):
28182817
)
28192818

28202819
def gen_guard_expr(self, expr, entry_label, exit_label, gen_cond = True):
2821-
gexpr = self.gen_expr_with_cast(expr.typ, expr.expr)
2820+
gexpr = self.gen_expr(expr.expr)
28222821
var_name = self.cur_func.unique_name(expr.vars[0].name)
28232822
expr.scope.update_ir_name(expr.vars[0].name, var_name)
28242823
if expr.is_result:
@@ -2947,9 +2946,7 @@ def ir_type(self, typ, gen_self_arg = False):
29472946
typ_ = typ_.ptr(True)
29482947
return typ_
29492948
res = ir.Type(cg_utils.mangle_symbol(typ_sym))
2950-
if typ_sym.kind == TypeKind.Trait or (
2951-
isinstance(typ, type.Type) and typ.is_boxed
2952-
):
2949+
if (isinstance(typ, type.Type) and typ.is_boxed) or typ_sym.kind == TypeKind.Trait:
29532950
return res.ptr(True)
29542951
return res
29552952

@@ -3196,6 +3193,7 @@ def generate_contains_method(
31963193
self, left_sym, right_sym, right_is_dyn_array, expr_left_typ,
31973194
expr_right_typ, full_name
31983195
):
3196+
elem_typ = right_sym.info.elem_typ
31993197
right_sym.info.has_contains_method = True
32003198
if right_is_dyn_array:
32013199
self_idx_ = ir.Ident(ir.DYN_ARRAY_T, "self")
@@ -3247,15 +3245,15 @@ def generate_contains_method(
32473245
self.ir_type(expr_left_typ).ptr()
32483246
]
32493247
)
3250-
if is_primitive or right_elem_typ_sym.is_boxed():
3251-
cur_elem = ir.Inst(ir.InstKind.LoadPtr, [cur_elem])
3248+
if is_primitive or (isinstance(elem_typ, type.Type) and elem_typ.is_boxed):
3249+
cur_elem = ir.Inst(ir.InstKind.LoadPtr, [cur_elem], cur_elem.typ)
32523250
else:
32533251
cur_elem = ir.Inst(
32543252
ir.InstKind.GetElementPtr, [self_idx_, inc_v],
32553253
self.ir_type(expr_left_typ)
32563254
)
3257-
if is_primitive or right_elem_typ_sym.is_boxed():
3258-
cur_elem = ir.Inst(ir.InstKind.LoadPtr, [cur_elem])
3255+
if is_primitive or (isinstance(elem_typ, type.Type) and elem_typ.is_boxed):
3256+
cur_elem = ir.Inst(ir.InstKind.LoadPtr, [cur_elem], cur_elem.typ)
32593257
if is_primitive:
32603258
cond = ir.Inst(
32613259
ir.InstKind.Cmp, [ir.Name("=="), cur_elem, elem_idx_]

rivetc/src/type.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,10 @@ def __init__(self, typ):
370370
self.sym = None
371371

372372
def is_pointer(self):
373-
return self.typ.__class__ in (Ptr, Func,
374-
Boxedptr) or self.typ.symbol().is_boxed()
373+
if isinstance(self.typ, Type) and self.typ.is_boxed:
374+
return True
375+
tsym = self.typ.symbol()
376+
return self.typ.__class__ in (Ptr, Func, Boxedptr) or tsym.is_boxed()
375377

376378
def qualstr(self):
377379
return f"?{self.typ.qualstr()}"

0 commit comments

Comments
 (0)