Skip to content

Commit eb6f25f

Browse files
committed
inline ConstGlobalRefs into ZigValue
Having ConstGlobalRefs be a pointer in ZigValue was a hack that caused plenty of bugs. It was used to work around difficulties in type coercing array values into slices. However, after #3787 is merged, array values no longer type coerce into slices, and so this provided an opportunity to clean up the code. This has the nice effect of reducing stage1 peak RAM usage during the std lib tests from 3.443 GiB to 3.405 GiB (saving 39 MiB). There is one behavior test failing in this branch, which I plan to debug after merging #3787.
1 parent 4b6740e commit eb6f25f

File tree

6 files changed

+103
-164
lines changed

6 files changed

+103
-164
lines changed

src/all_types.hpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -313,12 +313,6 @@ struct RuntimeHintSlice {
313313
uint64_t len;
314314
};
315315

316-
struct ConstGlobalRefs {
317-
LLVMValueRef llvm_value;
318-
LLVMValueRef llvm_global;
319-
uint32_t align;
320-
};
321-
322316
enum LazyValueId {
323317
LazyValueIdInvalid,
324318
LazyValueIdAlignOf,
@@ -409,8 +403,10 @@ struct LazyValueErrUnionType {
409403
struct ZigValue {
410404
ZigType *type;
411405
ConstValSpecial special;
406+
uint32_t llvm_align;
412407
ConstParent parent;
413-
ConstGlobalRefs *global_refs;
408+
LLVMValueRef llvm_value;
409+
LLVMValueRef llvm_global;
414410

415411
union {
416412
// populated if special == ConstValSpecialStatic

src/analyze.cpp

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5909,12 +5909,7 @@ ZigValue *create_const_arg_tuple(CodeGen *g, size_t arg_index_start, size_t arg_
59095909

59105910

59115911
ZigValue *create_const_vals(size_t count) {
5912-
ConstGlobalRefs *global_refs = allocate<ConstGlobalRefs>(count, "ConstGlobalRefs");
5913-
ZigValue *vals = allocate<ZigValue>(count, "ZigValue");
5914-
for (size_t i = 0; i < count; i += 1) {
5915-
vals[i].global_refs = &global_refs[i];
5916-
}
5917-
return vals;
5912+
return allocate<ZigValue>(count, "ZigValue");
59185913
}
59195914

59205915
ZigValue **alloc_const_vals_ptrs(size_t count) {
@@ -6492,48 +6487,36 @@ bool const_values_equal_ptr(ZigValue *a, ZigValue *b) {
64926487
return false;
64936488
return true;
64946489
case ConstPtrSpecialBaseArray:
6495-
if (a->data.x_ptr.data.base_array.array_val != b->data.x_ptr.data.base_array.array_val &&
6496-
a->data.x_ptr.data.base_array.array_val->global_refs !=
6497-
b->data.x_ptr.data.base_array.array_val->global_refs)
6498-
{
6490+
if (a->data.x_ptr.data.base_array.array_val != b->data.x_ptr.data.base_array.array_val) {
64996491
return false;
65006492
}
65016493
if (a->data.x_ptr.data.base_array.elem_index != b->data.x_ptr.data.base_array.elem_index)
65026494
return false;
65036495
return true;
65046496
case ConstPtrSpecialBaseStruct:
6505-
if (a->data.x_ptr.data.base_struct.struct_val != b->data.x_ptr.data.base_struct.struct_val &&
6506-
a->data.x_ptr.data.base_struct.struct_val->global_refs !=
6507-
b->data.x_ptr.data.base_struct.struct_val->global_refs)
6508-
{
6497+
if (a->data.x_ptr.data.base_struct.struct_val != b->data.x_ptr.data.base_struct.struct_val) {
65096498
return false;
65106499
}
65116500
if (a->data.x_ptr.data.base_struct.field_index != b->data.x_ptr.data.base_struct.field_index)
65126501
return false;
65136502
return true;
65146503
case ConstPtrSpecialBaseErrorUnionCode:
65156504
if (a->data.x_ptr.data.base_err_union_code.err_union_val !=
6516-
b->data.x_ptr.data.base_err_union_code.err_union_val &&
6517-
a->data.x_ptr.data.base_err_union_code.err_union_val->global_refs !=
6518-
b->data.x_ptr.data.base_err_union_code.err_union_val->global_refs)
6505+
b->data.x_ptr.data.base_err_union_code.err_union_val)
65196506
{
65206507
return false;
65216508
}
65226509
return true;
65236510
case ConstPtrSpecialBaseErrorUnionPayload:
65246511
if (a->data.x_ptr.data.base_err_union_payload.err_union_val !=
6525-
b->data.x_ptr.data.base_err_union_payload.err_union_val &&
6526-
a->data.x_ptr.data.base_err_union_payload.err_union_val->global_refs !=
6527-
b->data.x_ptr.data.base_err_union_payload.err_union_val->global_refs)
6512+
b->data.x_ptr.data.base_err_union_payload.err_union_val)
65286513
{
65296514
return false;
65306515
}
65316516
return true;
65326517
case ConstPtrSpecialBaseOptionalPayload:
65336518
if (a->data.x_ptr.data.base_optional_payload.optional_val !=
6534-
b->data.x_ptr.data.base_optional_payload.optional_val &&
6535-
a->data.x_ptr.data.base_optional_payload.optional_val->global_refs !=
6536-
b->data.x_ptr.data.base_optional_payload.optional_val->global_refs)
6519+
b->data.x_ptr.data.base_optional_payload.optional_val)
65376520
{
65386521
return false;
65396522
}

0 commit comments

Comments
 (0)