Skip to content

Commit b5df18c

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 951dc45 commit b5df18c

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
@@ -5908,12 +5908,7 @@ ZigValue *create_const_arg_tuple(CodeGen *g, size_t arg_index_start, size_t arg_
59085908

59095909

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

59195914
ZigValue **alloc_const_vals_ptrs(size_t count) {
@@ -6480,48 +6475,36 @@ bool const_values_equal_ptr(ZigValue *a, ZigValue *b) {
64806475
return false;
64816476
return true;
64826477
case ConstPtrSpecialBaseArray:
6483-
if (a->data.x_ptr.data.base_array.array_val != b->data.x_ptr.data.base_array.array_val &&
6484-
a->data.x_ptr.data.base_array.array_val->global_refs !=
6485-
b->data.x_ptr.data.base_array.array_val->global_refs)
6486-
{
6478+
if (a->data.x_ptr.data.base_array.array_val != b->data.x_ptr.data.base_array.array_val) {
64876479
return false;
64886480
}
64896481
if (a->data.x_ptr.data.base_array.elem_index != b->data.x_ptr.data.base_array.elem_index)
64906482
return false;
64916483
return true;
64926484
case ConstPtrSpecialBaseStruct:
6493-
if (a->data.x_ptr.data.base_struct.struct_val != b->data.x_ptr.data.base_struct.struct_val &&
6494-
a->data.x_ptr.data.base_struct.struct_val->global_refs !=
6495-
b->data.x_ptr.data.base_struct.struct_val->global_refs)
6496-
{
6485+
if (a->data.x_ptr.data.base_struct.struct_val != b->data.x_ptr.data.base_struct.struct_val) {
64976486
return false;
64986487
}
64996488
if (a->data.x_ptr.data.base_struct.field_index != b->data.x_ptr.data.base_struct.field_index)
65006489
return false;
65016490
return true;
65026491
case ConstPtrSpecialBaseErrorUnionCode:
65036492
if (a->data.x_ptr.data.base_err_union_code.err_union_val !=
6504-
b->data.x_ptr.data.base_err_union_code.err_union_val &&
6505-
a->data.x_ptr.data.base_err_union_code.err_union_val->global_refs !=
6506-
b->data.x_ptr.data.base_err_union_code.err_union_val->global_refs)
6493+
b->data.x_ptr.data.base_err_union_code.err_union_val)
65076494
{
65086495
return false;
65096496
}
65106497
return true;
65116498
case ConstPtrSpecialBaseErrorUnionPayload:
65126499
if (a->data.x_ptr.data.base_err_union_payload.err_union_val !=
6513-
b->data.x_ptr.data.base_err_union_payload.err_union_val &&
6514-
a->data.x_ptr.data.base_err_union_payload.err_union_val->global_refs !=
6515-
b->data.x_ptr.data.base_err_union_payload.err_union_val->global_refs)
6500+
b->data.x_ptr.data.base_err_union_payload.err_union_val)
65166501
{
65176502
return false;
65186503
}
65196504
return true;
65206505
case ConstPtrSpecialBaseOptionalPayload:
65216506
if (a->data.x_ptr.data.base_optional_payload.optional_val !=
6522-
b->data.x_ptr.data.base_optional_payload.optional_val &&
6523-
a->data.x_ptr.data.base_optional_payload.optional_val->global_refs !=
6524-
b->data.x_ptr.data.base_optional_payload.optional_val->global_refs)
6507+
b->data.x_ptr.data.base_optional_payload.optional_val)
65256508
{
65266509
return false;
65276510
}

0 commit comments

Comments
 (0)