authorgravatar for michael.dusan@gmail.comMichael Dusan <michael.dusan@gmail.com> 2020-02-10 23:08:33-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2020-02-10 23:08:33-05:00
loge624c862894ec50998aafb3026d4ed45208acd6d
treea01d54c8d5ba3178eaed1fa8d0ef9c081d95d9f2
parent26183660558c43133d862912c602e316f43698c7
parentedb210905dcbe666fa5222bceacd2e5bdb16bb89
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #4389 from mikdusan/stage1-mem

stage1: memory/report overhaul

33 files changed, 2210 insertions(+), 1082 deletions(-)

CMakeLists.txt+3-1
......@@ -450,7 +450,7 @@ set(ZIG_MAIN_SRC "${CMAKE_SOURCE_DIR}/src/main.cpp")
450450set(ZIG0_SHIM_SRC "${CMAKE_SOURCE_DIR}/src/userland.cpp")
451451
452452if(ZIG_ENABLE_MEM_PROFILE)
453 set(ZIG_SOURCES_MEM_PROFILE "${CMAKE_SOURCE_DIR}/src/memory_profiling.cpp")
453 set(ZIG_SOURCES_MEM_PROFILE "${CMAKE_SOURCE_DIR}/src/mem_profile.cpp")
454454endif()
455455
456456set(ZIG_SOURCES
......@@ -466,10 +466,12 @@ set(ZIG_SOURCES
466466 "${CMAKE_SOURCE_DIR}/src/errmsg.cpp"
467467 "${CMAKE_SOURCE_DIR}/src/error.cpp"
468468 "${CMAKE_SOURCE_DIR}/src/glibc.cpp"
469 "${CMAKE_SOURCE_DIR}/src/heap.cpp"
469470 "${CMAKE_SOURCE_DIR}/src/ir.cpp"
470471 "${CMAKE_SOURCE_DIR}/src/ir_print.cpp"
471472 "${CMAKE_SOURCE_DIR}/src/libc_installation.cpp"
472473 "${CMAKE_SOURCE_DIR}/src/link.cpp"
474 "${CMAKE_SOURCE_DIR}/src/mem.cpp"
473475 "${CMAKE_SOURCE_DIR}/src/os.cpp"
474476 "${CMAKE_SOURCE_DIR}/src/parser.cpp"
475477 "${CMAKE_SOURCE_DIR}/src/range_set.cpp"
src/all_types.hpp+3-1
......@@ -2000,6 +2000,9 @@ struct CFile {
20002000
20012001// When adding fields, check if they should be added to the hash computation in build_with_cache
20022002struct CodeGen {
2003 // arena allocator destroyed just prior to codegen emit
2004 heap::ArenaAllocator *pass1_arena;
2005
20032006 //////////////////////////// Runtime State
20042007 LLVMModuleRef module;
20052008 ZigList<ErrorMsg*> errors;
......@@ -2280,7 +2283,6 @@ struct ZigVar {
22802283 Scope *parent_scope;
22812284 Scope *child_scope;
22822285 LLVMValueRef param_value_ref;
2283 IrExecutableSrc *owner_exec;
22842286
22852287 Buf *section_name;
22862288
src/analyze.cpp+92-97
......@@ -80,7 +80,7 @@ ErrorMsg *add_error_note(CodeGen *g, ErrorMsg *parent_msg, const AstNode *node,
8080}
8181
8282ZigType *new_type_table_entry(ZigTypeId id) {
83 ZigType *entry = allocate<ZigType>(1);
83 ZigType *entry = heap::c_allocator.create<ZigType>();
8484 entry->id = id;
8585 return entry;
8686}
......@@ -140,7 +140,7 @@ void init_scope(CodeGen *g, Scope *dest, ScopeId id, AstNode *source_node, Scope
140140static ScopeDecls *create_decls_scope(CodeGen *g, AstNode *node, Scope *parent, ZigType *container_type,
141141 ZigType *import, Buf *bare_name)
142142{
143 ScopeDecls *scope = allocate<ScopeDecls>(1);
143 ScopeDecls *scope = heap::c_allocator.create<ScopeDecls>();
144144 init_scope(g, &scope->base, ScopeIdDecls, node, parent);
145145 scope->decl_table.init(4);
146146 scope->container_type = container_type;
......@@ -151,7 +151,7 @@ static ScopeDecls *create_decls_scope(CodeGen *g, AstNode *node, Scope *parent,
151151
152152ScopeBlock *create_block_scope(CodeGen *g, AstNode *node, Scope *parent) {
153153 assert(node->type == NodeTypeBlock);
154 ScopeBlock *scope = allocate<ScopeBlock>(1);
154 ScopeBlock *scope = heap::c_allocator.create<ScopeBlock>();
155155 init_scope(g, &scope->base, ScopeIdBlock, node, parent);
156156 scope->name = node->data.block.name;
157157 return scope;
......@@ -159,20 +159,20 @@ ScopeBlock *create_block_scope(CodeGen *g, AstNode *node, Scope *parent) {
159159
160160ScopeDefer *create_defer_scope(CodeGen *g, AstNode *node, Scope *parent) {
161161 assert(node->type == NodeTypeDefer);
162 ScopeDefer *scope = allocate<ScopeDefer>(1);
162 ScopeDefer *scope = heap::c_allocator.create<ScopeDefer>();
163163 init_scope(g, &scope->base, ScopeIdDefer, node, parent);
164164 return scope;
165165}
166166
167167ScopeDeferExpr *create_defer_expr_scope(CodeGen *g, AstNode *node, Scope *parent) {
168168 assert(node->type == NodeTypeDefer);
169 ScopeDeferExpr *scope = allocate<ScopeDeferExpr>(1);
169 ScopeDeferExpr *scope = heap::c_allocator.create<ScopeDeferExpr>();
170170 init_scope(g, &scope->base, ScopeIdDeferExpr, node, parent);
171171 return scope;
172172}
173173
174174Scope *create_var_scope(CodeGen *g, AstNode *node, Scope *parent, ZigVar *var) {
175 ScopeVarDecl *scope = allocate<ScopeVarDecl>(1);
175 ScopeVarDecl *scope = heap::c_allocator.create<ScopeVarDecl>();
176176 init_scope(g, &scope->base, ScopeIdVarDecl, node, parent);
177177 scope->var = var;
178178 return &scope->base;
......@@ -180,14 +180,14 @@ Scope *create_var_scope(CodeGen *g, AstNode *node, Scope *parent, ZigVar *var) {
180180
181181ScopeCImport *create_cimport_scope(CodeGen *g, AstNode *node, Scope *parent) {
182182 assert(node->type == NodeTypeFnCallExpr);
183 ScopeCImport *scope = allocate<ScopeCImport>(1);
183 ScopeCImport *scope = heap::c_allocator.create<ScopeCImport>();
184184 init_scope(g, &scope->base, ScopeIdCImport, node, parent);
185185 buf_resize(&scope->buf, 0);
186186 return scope;
187187}
188188
189189ScopeLoop *create_loop_scope(CodeGen *g, AstNode *node, Scope *parent) {
190 ScopeLoop *scope = allocate<ScopeLoop>(1);
190 ScopeLoop *scope = heap::c_allocator.create<ScopeLoop>();
191191 init_scope(g, &scope->base, ScopeIdLoop, node, parent);
192192 if (node->type == NodeTypeWhileExpr) {
193193 scope->name = node->data.while_expr.name;
......@@ -200,7 +200,7 @@ ScopeLoop *create_loop_scope(CodeGen *g, AstNode *node, Scope *parent) {
200200}
201201
202202Scope *create_runtime_scope(CodeGen *g, AstNode *node, Scope *parent, IrInstSrc *is_comptime) {
203 ScopeRuntime *scope = allocate<ScopeRuntime>(1);
203 ScopeRuntime *scope = heap::c_allocator.create<ScopeRuntime>();
204204 scope->is_comptime = is_comptime;
205205 init_scope(g, &scope->base, ScopeIdRuntime, node, parent);
206206 return &scope->base;
......@@ -208,37 +208,37 @@ Scope *create_runtime_scope(CodeGen *g, AstNode *node, Scope *parent, IrInstSrc
208208
209209ScopeSuspend *create_suspend_scope(CodeGen *g, AstNode *node, Scope *parent) {
210210 assert(node->type == NodeTypeSuspend);
211 ScopeSuspend *scope = allocate<ScopeSuspend>(1);
211 ScopeSuspend *scope = heap::c_allocator.create<ScopeSuspend>();
212212 init_scope(g, &scope->base, ScopeIdSuspend, node, parent);
213213 return scope;
214214}
215215
216216ScopeFnDef *create_fndef_scope(CodeGen *g, AstNode *node, Scope *parent, ZigFn *fn_entry) {
217 ScopeFnDef *scope = allocate<ScopeFnDef>(1);
217 ScopeFnDef *scope = heap::c_allocator.create<ScopeFnDef>();
218218 init_scope(g, &scope->base, ScopeIdFnDef, node, parent);
219219 scope->fn_entry = fn_entry;
220220 return scope;
221221}
222222
223223Scope *create_comptime_scope(CodeGen *g, AstNode *node, Scope *parent) {
224 ScopeCompTime *scope = allocate<ScopeCompTime>(1);
224 ScopeCompTime *scope = heap::c_allocator.create<ScopeCompTime>();
225225 init_scope(g, &scope->base, ScopeIdCompTime, node, parent);
226226 return &scope->base;
227227}
228228
229229Scope *create_typeof_scope(CodeGen *g, AstNode *node, Scope *parent) {
230 ScopeTypeOf *scope = allocate<ScopeTypeOf>(1);
230 ScopeTypeOf *scope = heap::c_allocator.create<ScopeTypeOf>();
231231 init_scope(g, &scope->base, ScopeIdTypeOf, node, parent);
232232 return &scope->base;
233233}
234234
235235ScopeExpr *create_expr_scope(CodeGen *g, AstNode *node, Scope *parent) {
236 ScopeExpr *scope = allocate<ScopeExpr>(1);
236 ScopeExpr *scope = heap::c_allocator.create<ScopeExpr>();
237237 init_scope(g, &scope->base, ScopeIdExpr, node, parent);
238238 ScopeExpr *parent_expr = find_expr_scope(parent);
239239 if (parent_expr != nullptr) {
240240 size_t new_len = parent_expr->children_len + 1;
241 parent_expr->children_ptr = reallocate_nonzero<ScopeExpr *>(
241 parent_expr->children_ptr = heap::c_allocator.reallocate_nonzero<ScopeExpr *>(
242242 parent_expr->children_ptr, parent_expr->children_len, new_len);
243243 parent_expr->children_ptr[parent_expr->children_len] = scope;
244244 parent_expr->children_len = new_len;
......@@ -1104,8 +1104,8 @@ ZigValue *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, ZigType *
11041104{
11051105 Error err;
11061106
1107 ZigValue *result = create_const_vals(1);
1108 ZigValue *result_ptr = create_const_vals(1);
1107 ZigValue *result = g->pass1_arena->create<ZigValue>();
1108 ZigValue *result_ptr = g->pass1_arena->create<ZigValue>();
11091109 result->special = ConstValSpecialUndef;
11101110 result->type = (type_entry == nullptr) ? g->builtin_types.entry_var : type_entry;
11111111 result_ptr->special = ConstValSpecialStatic;
......@@ -1122,7 +1122,6 @@ ZigValue *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, ZigType *
11221122 {
11231123 return g->invalid_inst_gen->value;
11241124 }
1125 destroy(result_ptr, "ZigValue");
11261125 return result;
11271126}
11281127
......@@ -1507,7 +1506,7 @@ void init_fn_type_id(FnTypeId *fn_type_id, AstNode *proto_node, CallingConventio
15071506
15081507 fn_type_id->cc = cc;
15091508 fn_type_id->param_count = fn_proto->params.length;
1510 fn_type_id->param_info = allocate<FnTypeParamInfo>(param_count_alloc);
1509 fn_type_id->param_info = heap::c_allocator.allocate<FnTypeParamInfo>(param_count_alloc);
15111510 fn_type_id->next_param_index = 0;
15121511 fn_type_id->is_var_args = fn_proto->is_var_args;
15131512}
......@@ -2171,7 +2170,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {
21712170 bool packed = (struct_type->data.structure.layout == ContainerLayoutPacked);
21722171 struct_type->data.structure.resolve_loop_flag_other = true;
21732172
2174 uint32_t *host_int_bytes = packed ? allocate<uint32_t>(struct_type->data.structure.gen_field_count) : nullptr;
2173 uint32_t *host_int_bytes = packed ? heap::c_allocator.allocate<uint32_t>(struct_type->data.structure.gen_field_count) : nullptr;
21752174
21762175 size_t packed_bits_offset = 0;
21772176 size_t next_offset = 0;
......@@ -2657,7 +2656,7 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) {
26572656 }
26582657
26592658 enum_type->data.enumeration.src_field_count = field_count;
2660 enum_type->data.enumeration.fields = allocate<TypeEnumField>(field_count);
2659 enum_type->data.enumeration.fields = heap::c_allocator.allocate<TypeEnumField>(field_count);
26612660 enum_type->data.enumeration.fields_by_name.init(field_count);
26622661
26632662 HashMap<BigInt, AstNode *, bigint_hash, bigint_eql> occupied_tag_values = {};
......@@ -3034,7 +3033,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
30343033 return ErrorSemanticAnalyzeFail;
30353034 }
30363035 union_type->data.unionation.src_field_count = field_count;
3037 union_type->data.unionation.fields = allocate<TypeUnionField>(field_count);
3036 union_type->data.unionation.fields = heap::c_allocator.allocate<TypeUnionField>(field_count);
30383037 union_type->data.unionation.fields_by_name.init(field_count);
30393038
30403039 Scope *scope = &union_type->data.unionation.decls_scope->base;
......@@ -3053,7 +3052,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
30533052 if (create_enum_type) {
30543053 occupied_tag_values.init(field_count);
30553054
3056 di_enumerators = allocate<ZigLLVMDIEnumerator*>(field_count);
3055 di_enumerators = heap::c_allocator.allocate<ZigLLVMDIEnumerator*>(field_count);
30573056
30583057 ZigType *tag_int_type;
30593058 if (enum_type_node != nullptr) {
......@@ -3086,7 +3085,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
30863085 tag_type->data.enumeration.decl_node = decl_node;
30873086 tag_type->data.enumeration.layout = ContainerLayoutAuto;
30883087 tag_type->data.enumeration.src_field_count = field_count;
3089 tag_type->data.enumeration.fields = allocate<TypeEnumField>(field_count);
3088 tag_type->data.enumeration.fields = heap::c_allocator.allocate<TypeEnumField>(field_count);
30903089 tag_type->data.enumeration.fields_by_name.init(field_count);
30913090 tag_type->data.enumeration.decls_scope = union_type->data.unionation.decls_scope;
30923091 } else if (enum_type_node != nullptr) {
......@@ -3106,7 +3105,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
31063105 return err;
31073106 }
31083107 tag_type = enum_type;
3109 covered_enum_fields = allocate<bool>(enum_type->data.enumeration.src_field_count);
3108 covered_enum_fields = heap::c_allocator.allocate<bool>(enum_type->data.enumeration.src_field_count);
31103109 } else {
31113110 tag_type = nullptr;
31123111 }
......@@ -3244,7 +3243,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
32443243 }
32453244 covered_enum_fields[union_field->enum_field->decl_index] = true;
32463245 } else {
3247 union_field->enum_field = allocate<TypeEnumField>(1);
3246 union_field->enum_field = heap::c_allocator.create<TypeEnumField>();
32483247 union_field->enum_field->name = field_name;
32493248 union_field->enum_field->decl_index = i;
32503249 bigint_init_unsigned(&union_field->enum_field->value, i);
......@@ -3366,8 +3365,8 @@ static void get_fully_qualified_decl_name(CodeGen *g, Buf *buf, Tld *tld, bool i
33663365}
33673366
33683367ZigFn *create_fn_raw(CodeGen *g, FnInline inline_value) {
3369 ZigFn *fn_entry = allocate<ZigFn>(1, "ZigFn");
3370 fn_entry->ir_executable = allocate<IrExecutableSrc>(1, "IrExecutableSrc");
3368 ZigFn *fn_entry = heap::c_allocator.create<ZigFn>();
3369 fn_entry->ir_executable = heap::c_allocator.create<IrExecutableSrc>();
33713370
33723371 fn_entry->prealloc_backward_branch_quota = default_backward_branch_quota;
33733372
......@@ -3642,7 +3641,7 @@ static void preview_test_decl(CodeGen *g, AstNode *node, ScopeDecls *decls_scope
36423641 return;
36433642 }
36443643
3645 TldFn *tld_fn = allocate<TldFn>(1);
3644 TldFn *tld_fn = heap::c_allocator.create<TldFn>();
36463645 init_tld(&tld_fn->base, TldIdFn, test_name, VisibModPrivate, node, &decls_scope->base);
36473646 g->resolve_queue.append(&tld_fn->base);
36483647}
......@@ -3650,7 +3649,7 @@ static void preview_test_decl(CodeGen *g, AstNode *node, ScopeDecls *decls_scope
36503649static void preview_comptime_decl(CodeGen *g, AstNode *node, ScopeDecls *decls_scope) {
36513650 assert(node->type == NodeTypeCompTime);
36523651
3653 TldCompTime *tld_comptime = allocate<TldCompTime>(1);
3652 TldCompTime *tld_comptime = heap::c_allocator.create<TldCompTime>();
36543653 init_tld(&tld_comptime->base, TldIdCompTime, nullptr, VisibModPrivate, node, &decls_scope->base);
36553654 g->resolve_queue.append(&tld_comptime->base);
36563655}
......@@ -3673,7 +3672,7 @@ void update_compile_var(CodeGen *g, Buf *name, ZigValue *value) {
36733672 resolve_top_level_decl(g, tld, tld->source_node, false);
36743673 assert(tld->id == TldIdVar && tld->resolution == TldResolutionOk);
36753674 TldVar *tld_var = (TldVar *)tld;
3676 copy_const_val(tld_var->var->const_value, value);
3675 copy_const_val(g, tld_var->var->const_value, value);
36773676 tld_var->var->var_type = value->type;
36783677 tld_var->var->align_bytes = get_abi_alignment(g, value->type);
36793678}
......@@ -3693,7 +3692,7 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {
36933692 {
36943693 Buf *name = node->data.variable_declaration.symbol;
36953694 VisibMod visib_mod = node->data.variable_declaration.visib_mod;
3696 TldVar *tld_var = allocate<TldVar>(1);
3695 TldVar *tld_var = heap::c_allocator.create<TldVar>();
36973696 init_tld(&tld_var->base, TldIdVar, name, visib_mod, node, &decls_scope->base);
36983697 tld_var->extern_lib_name = node->data.variable_declaration.lib_name;
36993698 add_top_level_decl(g, decls_scope, &tld_var->base);
......@@ -3709,7 +3708,7 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {
37093708 }
37103709
37113710 VisibMod visib_mod = node->data.fn_proto.visib_mod;
3712 TldFn *tld_fn = allocate<TldFn>(1);
3711 TldFn *tld_fn = heap::c_allocator.create<TldFn>();
37133712 init_tld(&tld_fn->base, TldIdFn, fn_name, visib_mod, node, &decls_scope->base);
37143713 tld_fn->extern_lib_name = node->data.fn_proto.lib_name;
37153714 add_top_level_decl(g, decls_scope, &tld_fn->base);
......@@ -3718,7 +3717,7 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {
37183717 }
37193718 case NodeTypeUsingNamespace: {
37203719 VisibMod visib_mod = node->data.using_namespace.visib_mod;
3721 TldUsingNamespace *tld_using_namespace = allocate<TldUsingNamespace>(1);
3720 TldUsingNamespace *tld_using_namespace = heap::c_allocator.create<TldUsingNamespace>();
37223721 init_tld(&tld_using_namespace->base, TldIdUsingNamespace, nullptr, visib_mod, node, &decls_scope->base);
37233722 add_top_level_decl(g, decls_scope, &tld_using_namespace->base);
37243723 decls_scope->use_decls.append(tld_using_namespace);
......@@ -3845,7 +3844,7 @@ ZigVar *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf
38453844 assert(const_value != nullptr);
38463845 assert(var_type != nullptr);
38473846
3848 ZigVar *variable_entry = allocate<ZigVar>(1);
3847 ZigVar *variable_entry = heap::c_allocator.create<ZigVar>();
38493848 variable_entry->const_value = const_value;
38503849 variable_entry->var_type = var_type;
38513850 variable_entry->parent_scope = parent_scope;
......@@ -3984,7 +3983,7 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var, bool allow_lazy) {
39843983 ZigType *type = explicit_type ? explicit_type : implicit_type;
39853984 assert(type != nullptr); // should have been caught by the parser
39863985
3987 ZigValue *init_val = (init_value != nullptr) ? init_value : create_const_runtime(type);
3986 ZigValue *init_val = (init_value != nullptr) ? init_value : create_const_runtime(g, type);
39883987
39893988 tld_var->var = add_variable(g, source_node, tld_var->base.parent_scope, var_decl->symbol,
39903989 is_const, init_val, &tld_var->base, type);
......@@ -4491,7 +4490,7 @@ static Error define_local_param_variables(CodeGen *g, ZigFn *fn_table_entry) {
44914490 }
44924491
44934492 ZigVar *var = add_variable(g, param_decl_node, fn_table_entry->child_scope,
4494 param_name, true, create_const_runtime(param_type), nullptr, param_type);
4493 param_name, true, create_const_runtime(g, param_type), nullptr, param_type);
44954494 var->src_arg_index = i;
44964495 fn_table_entry->child_scope = var->child_scope;
44974496 var->shadowable = var->shadowable || is_var_args;
......@@ -4786,7 +4785,7 @@ static void analyze_fn_ir(CodeGen *g, ZigFn *fn, AstNode *return_type_node) {
47864785 } else {
47874786 return_err_set_type->data.error_set.err_count = inferred_err_set_type->data.error_set.err_count;
47884787 if (inferred_err_set_type->data.error_set.err_count > 0) {
4789 return_err_set_type->data.error_set.errors = allocate<ErrorTableEntry *>(inferred_err_set_type->data.error_set.err_count);
4788 return_err_set_type->data.error_set.errors = heap::c_allocator.allocate<ErrorTableEntry *>(inferred_err_set_type->data.error_set.err_count);
47904789 for (uint32_t i = 0; i < inferred_err_set_type->data.error_set.err_count; i += 1) {
47914790 return_err_set_type->data.error_set.errors[i] = inferred_err_set_type->data.error_set.errors[i];
47924791 }
......@@ -4919,7 +4918,7 @@ ZigType *add_source_file(CodeGen *g, ZigPackage *package, Buf *resolved_path, Bu
49194918 Buf *bare_name = buf_alloc();
49204919 os_path_extname(src_basename, bare_name, nullptr);
49214920
4922 RootStruct *root_struct = allocate<RootStruct>(1);
4921 RootStruct *root_struct = heap::c_allocator.create<RootStruct>();
49234922 root_struct->package = package;
49244923 root_struct->source_code = source_code;
49254924 root_struct->line_offsets = tokenization.line_offsets;
......@@ -4946,7 +4945,7 @@ ZigType *add_source_file(CodeGen *g, ZigPackage *package, Buf *resolved_path, Bu
49464945 scan_decls(g, import_entry->data.structure.decls_scope, top_level_decl);
49474946 }
49484947
4949 TldContainer *tld_container = allocate<TldContainer>(1);
4948 TldContainer *tld_container = heap::c_allocator.create<TldContainer>();
49504949 init_tld(&tld_container->base, TldIdContainer, namespace_name, VisibModPub, root_node, nullptr);
49514950 tld_container->type_entry = import_entry;
49524951 tld_container->decls_scope = import_entry->data.structure.decls_scope;
......@@ -5694,14 +5693,14 @@ ZigValue *get_the_one_possible_value(CodeGen *g, ZigType *type_entry) {
56945693 if (entry != nullptr) {
56955694 return entry->value;
56965695 }
5697 ZigValue *result = create_const_vals(1);
5696 ZigValue *result = g->pass1_arena->create<ZigValue>();
56985697 result->type = type_entry;
56995698 result->special = ConstValSpecialStatic;
57005699 if (result->type->id == ZigTypeIdStruct) {
57015700 // The fields array cannot be left unpopulated
57025701 const ZigType *struct_type = result->type;
57035702 const size_t field_count = struct_type->data.structure.src_field_count;
5704 result->data.x_struct.fields = alloc_const_vals_ptrs(field_count);
5703 result->data.x_struct.fields = alloc_const_vals_ptrs(g, field_count);
57055704 for (size_t i = 0; i < field_count; i += 1) {
57065705 TypeStructField *field = struct_type->data.structure.fields[i];
57075706 ZigType *field_type = resolve_struct_field_type(g, field);
......@@ -5786,7 +5785,7 @@ void init_const_str_lit(CodeGen *g, ZigValue *const_val, Buf *str) {
57865785 }
57875786
57885787 // first we build the underlying array
5789 ZigValue *array_val = create_const_vals(1);
5788 ZigValue *array_val = g->pass1_arena->create<ZigValue>();
57905789 array_val->special = ConstValSpecialStatic;
57915790 array_val->type = get_array_type(g, g->builtin_types.entry_u8, buf_len(str), g->intern.for_zero_byte());
57925791 array_val->data.x_array.special = ConstArraySpecialBuf;
......@@ -5803,7 +5802,7 @@ void init_const_str_lit(CodeGen *g, ZigValue *const_val, Buf *str) {
58035802}
58045803
58055804ZigValue *create_const_str_lit(CodeGen *g, Buf *str) {
5806 ZigValue *const_val = create_const_vals(1);
5805 ZigValue *const_val = g->pass1_arena->create<ZigValue>();
58075806 init_const_str_lit(g, const_val, str);
58085807 return const_val;
58095808}
......@@ -5814,8 +5813,8 @@ void init_const_bigint(ZigValue *const_val, ZigType *type, const BigInt *bigint)
58145813 bigint_init_bigint(&const_val->data.x_bigint, bigint);
58155814}
58165815
5817ZigValue *create_const_bigint(ZigType *type, const BigInt *bigint) {
5818 ZigValue *const_val = create_const_vals(1);
5816ZigValue *create_const_bigint(CodeGen *g, ZigType *type, const BigInt *bigint) {
5817 ZigValue *const_val = g->pass1_arena->create<ZigValue>();
58195818 init_const_bigint(const_val, type, bigint);
58205819 return const_val;
58215820}
......@@ -5828,8 +5827,8 @@ void init_const_unsigned_negative(ZigValue *const_val, ZigType *type, uint64_t x
58285827 const_val->data.x_bigint.is_negative = negative;
58295828}
58305829
5831ZigValue *create_const_unsigned_negative(ZigType *type, uint64_t x, bool negative) {
5832 ZigValue *const_val = create_const_vals(1);
5830ZigValue *create_const_unsigned_negative(CodeGen *g, ZigType *type, uint64_t x, bool negative) {
5831 ZigValue *const_val = g->pass1_arena->create<ZigValue>();
58335832 init_const_unsigned_negative(const_val, type, x, negative);
58345833 return const_val;
58355834}
......@@ -5839,7 +5838,7 @@ void init_const_usize(CodeGen *g, ZigValue *const_val, uint64_t x) {
58395838}
58405839
58415840ZigValue *create_const_usize(CodeGen *g, uint64_t x) {
5842 return create_const_unsigned_negative(g->builtin_types.entry_usize, x, false);
5841 return create_const_unsigned_negative(g, g->builtin_types.entry_usize, x, false);
58435842}
58445843
58455844void init_const_signed(ZigValue *const_val, ZigType *type, int64_t x) {
......@@ -5848,8 +5847,8 @@ void init_const_signed(ZigValue *const_val, ZigType *type, int64_t x) {
58485847 bigint_init_signed(&const_val->data.x_bigint, x);
58495848}
58505849
5851ZigValue *create_const_signed(ZigType *type, int64_t x) {
5852 ZigValue *const_val = create_const_vals(1);
5850ZigValue *create_const_signed(CodeGen *g, ZigType *type, int64_t x) {
5851 ZigValue *const_val = g->pass1_arena->create<ZigValue>();
58535852 init_const_signed(const_val, type, x);
58545853 return const_val;
58555854}
......@@ -5860,8 +5859,8 @@ void init_const_null(ZigValue *const_val, ZigType *type) {
58605859 const_val->data.x_optional = nullptr;
58615860}
58625861
5863ZigValue *create_const_null(ZigType *type) {
5864 ZigValue *const_val = create_const_vals(1);
5862ZigValue *create_const_null(CodeGen *g, ZigType *type) {
5863 ZigValue *const_val = g->pass1_arena->create<ZigValue>();
58655864 init_const_null(const_val, type);
58665865 return const_val;
58675866}
......@@ -5893,8 +5892,8 @@ void init_const_float(ZigValue *const_val, ZigType *type, double value) {
58935892 }
58945893}
58955894
5896ZigValue *create_const_float(ZigType *type, double value) {
5897 ZigValue *const_val = create_const_vals(1);
5895ZigValue *create_const_float(CodeGen *g, ZigType *type, double value) {
5896 ZigValue *const_val = g->pass1_arena->create<ZigValue>();
58985897 init_const_float(const_val, type, value);
58995898 return const_val;
59005899}
......@@ -5905,8 +5904,8 @@ void init_const_enum(ZigValue *const_val, ZigType *type, const BigInt *tag) {
59055904 bigint_init_bigint(&const_val->data.x_enum_tag, tag);
59065905}
59075906
5908ZigValue *create_const_enum(ZigType *type, const BigInt *tag) {
5909 ZigValue *const_val = create_const_vals(1);
5907ZigValue *create_const_enum(CodeGen *g, ZigType *type, const BigInt *tag) {
5908 ZigValue *const_val = g->pass1_arena->create<ZigValue>();
59105909 init_const_enum(const_val, type, tag);
59115910 return const_val;
59125911}
......@@ -5919,7 +5918,7 @@ void init_const_bool(CodeGen *g, ZigValue *const_val, bool value) {
59195918}
59205919
59215920ZigValue *create_const_bool(CodeGen *g, bool value) {
5922 ZigValue *const_val = create_const_vals(1);
5921 ZigValue *const_val = g->pass1_arena->create<ZigValue>();
59235922 init_const_bool(g, const_val, value);
59245923 return const_val;
59255924}
......@@ -5929,8 +5928,8 @@ void init_const_runtime(ZigValue *const_val, ZigType *type) {
59295928 const_val->type = type;
59305929}
59315930
5932ZigValue *create_const_runtime(ZigType *type) {
5933 ZigValue *const_val = create_const_vals(1);
5931ZigValue *create_const_runtime(CodeGen *g, ZigType *type) {
5932 ZigValue *const_val = g->pass1_arena->create<ZigValue>();
59345933 init_const_runtime(const_val, type);
59355934 return const_val;
59365935}
......@@ -5942,7 +5941,7 @@ void init_const_type(CodeGen *g, ZigValue *const_val, ZigType *type_value) {
59425941}
59435942
59445943ZigValue *create_const_type(CodeGen *g, ZigType *type_value) {
5945 ZigValue *const_val = create_const_vals(1);
5944 ZigValue *const_val = g->pass1_arena->create<ZigValue>();
59465945 init_const_type(g, const_val, type_value);
59475946 return const_val;
59485947}
......@@ -5957,7 +5956,7 @@ void init_const_slice(CodeGen *g, ZigValue *const_val, ZigValue *array_val,
59575956
59585957 const_val->special = ConstValSpecialStatic;
59595958 const_val->type = get_slice_type(g, ptr_type);
5960 const_val->data.x_struct.fields = alloc_const_vals_ptrs(2);
5959 const_val->data.x_struct.fields = alloc_const_vals_ptrs(g, 2);
59615960
59625961 init_const_ptr_array(g, const_val->data.x_struct.fields[slice_ptr_index], array_val, start, is_const,
59635962 PtrLenUnknown);
......@@ -5965,7 +5964,7 @@ void init_const_slice(CodeGen *g, ZigValue *const_val, ZigValue *array_val,
59655964}
59665965
59675966ZigValue *create_const_slice(CodeGen *g, ZigValue *array_val, size_t start, size_t len, bool is_const) {
5968 ZigValue *const_val = create_const_vals(1);
5967 ZigValue *const_val = g->pass1_arena->create<ZigValue>();
59695968 init_const_slice(g, const_val, array_val, start, len, is_const);
59705969 return const_val;
59715970}
......@@ -5987,7 +5986,7 @@ void init_const_ptr_array(CodeGen *g, ZigValue *const_val, ZigValue *array_val,
59875986ZigValue *create_const_ptr_array(CodeGen *g, ZigValue *array_val, size_t elem_index, bool is_const,
59885987 PtrLen ptr_len)
59895988{
5990 ZigValue *const_val = create_const_vals(1);
5989 ZigValue *const_val = g->pass1_arena->create<ZigValue>();
59915990 init_const_ptr_array(g, const_val, array_val, elem_index, is_const, ptr_len);
59925991 return const_val;
59935992}
......@@ -6000,7 +5999,7 @@ void init_const_ptr_ref(CodeGen *g, ZigValue *const_val, ZigValue *pointee_val,
60005999}
60016000
60026001ZigValue *create_const_ptr_ref(CodeGen *g, ZigValue *pointee_val, bool is_const) {
6003 ZigValue *const_val = create_const_vals(1);
6002 ZigValue *const_val = g->pass1_arena->create<ZigValue>();
60046003 init_const_ptr_ref(g, const_val, pointee_val, is_const);
60056004 return const_val;
60066005}
......@@ -6017,25 +6016,21 @@ void init_const_ptr_hard_coded_addr(CodeGen *g, ZigValue *const_val, ZigType *po
60176016ZigValue *create_const_ptr_hard_coded_addr(CodeGen *g, ZigType *pointee_type,
60186017 size_t addr, bool is_const)
60196018{
6020 ZigValue *const_val = create_const_vals(1);
6019 ZigValue *const_val = g->pass1_arena->create<ZigValue>();
60216020 init_const_ptr_hard_coded_addr(g, const_val, pointee_type, addr, is_const);
60226021 return const_val;
60236022}
60246023
6025ZigValue *create_const_vals(size_t count) {
6026 return allocate<ZigValue>(count, "ZigValue");
6024ZigValue **alloc_const_vals_ptrs(CodeGen *g, size_t count) {
6025 return realloc_const_vals_ptrs(g, nullptr, 0, count);
60276026}
60286027
6029ZigValue **alloc_const_vals_ptrs(size_t count) {
6030 return realloc_const_vals_ptrs(nullptr, 0, count);
6031}
6032
6033ZigValue **realloc_const_vals_ptrs(ZigValue **ptr, size_t old_count, size_t new_count) {
6028ZigValue **realloc_const_vals_ptrs(CodeGen *g, ZigValue **ptr, size_t old_count, size_t new_count) {
60346029 assert(new_count >= old_count);
60356030
60366031 size_t new_item_count = new_count - old_count;
6037 ZigValue **result = reallocate(ptr, old_count, new_count, "ZigValue*");
6038 ZigValue *vals = create_const_vals(new_item_count);
6032 ZigValue **result = heap::c_allocator.reallocate(ptr, old_count, new_count);
6033 ZigValue *vals = g->pass1_arena->allocate<ZigValue>(new_item_count);
60396034 for (size_t i = old_count; i < new_count; i += 1) {
60406035 result[i] = &vals[i - old_count];
60416036 }
......@@ -6050,8 +6045,8 @@ TypeStructField **realloc_type_struct_fields(TypeStructField **ptr, size_t old_c
60506045 assert(new_count >= old_count);
60516046
60526047 size_t new_item_count = new_count - old_count;
6053 TypeStructField **result = reallocate(ptr, old_count, new_count, "TypeStructField*");
6054 TypeStructField *vals = allocate<TypeStructField>(new_item_count, "TypeStructField");
6048 TypeStructField **result = heap::c_allocator.reallocate(ptr, old_count, new_count);
6049 TypeStructField *vals = heap::c_allocator.allocate<TypeStructField>(new_item_count);
60556050 for (size_t i = old_count; i < new_count; i += 1) {
60566051 result[i] = &vals[i - old_count];
60576052 }
......@@ -6062,7 +6057,7 @@ static ZigType *get_async_fn_type(CodeGen *g, ZigType *orig_fn_type) {
60626057 if (orig_fn_type->data.fn.fn_type_id.cc == CallingConventionAsync)
60636058 return orig_fn_type;
60646059
6065 ZigType *fn_type = allocate_nonzero<ZigType>(1);
6060 ZigType *fn_type = heap::c_allocator.allocate_nonzero<ZigType>(1);
60666061 *fn_type = *orig_fn_type;
60676062 fn_type->data.fn.fn_type_id.cc = CallingConventionAsync;
60686063 fn_type->llvm_type = nullptr;
......@@ -6236,11 +6231,11 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
62366231 ZigType *fn_type = get_async_fn_type(g, fn->type_entry);
62376232
62386233 if (fn->analyzed_executable.need_err_code_spill) {
6239 IrInstGenAlloca *alloca_gen = allocate<IrInstGenAlloca>(1);
6234 IrInstGenAlloca *alloca_gen = heap::c_allocator.create<IrInstGenAlloca>();
62406235 alloca_gen->base.id = IrInstGenIdAlloca;
62416236 alloca_gen->base.base.source_node = fn->proto_node;
62426237 alloca_gen->base.base.scope = fn->child_scope;
6243 alloca_gen->base.value = allocate<ZigValue>(1, "ZigValue");
6238 alloca_gen->base.value = g->pass1_arena->create<ZigValue>();
62446239 alloca_gen->base.value->type = get_pointer_to_type(g, g->builtin_types.entry_global_error_set, false);
62456240 alloca_gen->base.base.ref_count = 1;
62466241 alloca_gen->name_hint = "";
......@@ -7375,7 +7370,7 @@ static void init_const_undefined(CodeGen *g, ZigValue *const_val) {
73757370
73767371 const_val->special = ConstValSpecialStatic;
73777372 size_t field_count = wanted_type->data.structure.src_field_count;
7378 const_val->data.x_struct.fields = alloc_const_vals_ptrs(field_count);
7373 const_val->data.x_struct.fields = alloc_const_vals_ptrs(g, field_count);
73797374 for (size_t i = 0; i < field_count; i += 1) {
73807375 ZigValue *field_val = const_val->data.x_struct.fields[i];
73817376 field_val->type = resolve_struct_field_type(g, wanted_type->data.structure.fields[i]);
......@@ -7418,7 +7413,7 @@ void expand_undef_array(CodeGen *g, ZigValue *const_val) {
74187413 return;
74197414 case ConstArraySpecialUndef: {
74207415 const_val->data.x_array.special = ConstArraySpecialNone;
7421 const_val->data.x_array.data.s_none.elements = create_const_vals(elem_count);
7416 const_val->data.x_array.data.s_none.elements = g->pass1_arena->allocate<ZigValue>(elem_count);
74227417 for (size_t i = 0; i < elem_count; i += 1) {
74237418 ZigValue *element_val = &const_val->data.x_array.data.s_none.elements[i];
74247419 element_val->type = elem_type;
......@@ -7437,7 +7432,7 @@ void expand_undef_array(CodeGen *g, ZigValue *const_val) {
74377432
74387433 const_val->data.x_array.special = ConstArraySpecialNone;
74397434 assert(elem_count == buf_len(buf));
7440 const_val->data.x_array.data.s_none.elements = create_const_vals(elem_count);
7435 const_val->data.x_array.data.s_none.elements = g->pass1_arena->allocate<ZigValue>(elem_count);
74417436 for (size_t i = 0; i < elem_count; i += 1) {
74427437 ZigValue *this_char = &const_val->data.x_array.data.s_none.elements[i];
74437438 this_char->special = ConstValSpecialStatic;
......@@ -7609,7 +7604,7 @@ const char *type_id_name(ZigTypeId id) {
76097604}
76107605
76117606LinkLib *create_link_lib(Buf *name) {
7612 LinkLib *link_lib = allocate<LinkLib>(1);
7607 LinkLib *link_lib = heap::c_allocator.create<LinkLib>();
76137608 link_lib->name = name;
76147609 return link_lib;
76157610}
......@@ -8137,7 +8132,7 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS
81378132
81388133 size_t field_count = struct_type->data.structure.src_field_count;
81398134 // Every field could potentially have a generated padding field after it.
8140 LLVMTypeRef *element_types = allocate<LLVMTypeRef>(field_count * 2);
8135 LLVMTypeRef *element_types = heap::c_allocator.allocate<LLVMTypeRef>(field_count * 2);
81418136
81428137 bool packed = (struct_type->data.structure.layout == ContainerLayoutPacked);
81438138 size_t packed_bits_offset = 0;
......@@ -8272,7 +8267,7 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS
82728267 (unsigned)struct_type->data.structure.gen_field_count, packed);
82738268 }
82748269
8275 ZigLLVMDIType **di_element_types = allocate<ZigLLVMDIType*>(debug_field_count);
8270 ZigLLVMDIType **di_element_types = heap::c_allocator.allocate<ZigLLVMDIType*>(debug_field_count);
82768271 size_t debug_field_index = 0;
82778272 for (size_t i = 0; i < field_count; i += 1) {
82788273 TypeStructField *field = struct_type->data.structure.fields[i];
......@@ -8389,7 +8384,7 @@ static void resolve_llvm_types_enum(CodeGen *g, ZigType *enum_type, ResolveStatu
83898384 uint32_t field_count = enum_type->data.enumeration.src_field_count;
83908385
83918386 assert(field_count == 0 || enum_type->data.enumeration.fields != nullptr);
8392 ZigLLVMDIEnumerator **di_enumerators = allocate<ZigLLVMDIEnumerator*>(field_count);
8387 ZigLLVMDIEnumerator **di_enumerators = heap::c_allocator.allocate<ZigLLVMDIEnumerator*>(field_count);
83938388
83948389 for (uint32_t i = 0; i < field_count; i += 1) {
83958390 TypeEnumField *enum_field = &enum_type->data.enumeration.fields[i];
......@@ -8456,7 +8451,7 @@ static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type, ResolveSta
84568451 if (ResolveStatusLLVMFwdDecl >= wanted_resolve_status) return;
84578452 }
84588453
8459 ZigLLVMDIType **union_inner_di_types = allocate<ZigLLVMDIType*>(gen_field_count);
8454 ZigLLVMDIType **union_inner_di_types = heap::c_allocator.allocate<ZigLLVMDIType*>(gen_field_count);
84608455 uint32_t field_count = union_type->data.unionation.src_field_count;
84618456 for (uint32_t i = 0; i < field_count; i += 1) {
84628457 TypeUnionField *union_field = &union_type->data.unionation.fields[i];
......@@ -8895,7 +8890,7 @@ static void resolve_llvm_types_fn_type(CodeGen *g, ZigType *fn_type) {
88958890 param_di_types.append(get_llvm_di_type(g, gen_type));
88968891 }
88978892 if (is_async) {
8898 fn_type->data.fn.gen_param_info = allocate<FnGenParamInfo>(2);
8893 fn_type->data.fn.gen_param_info = heap::c_allocator.allocate<FnGenParamInfo>(2);
88998894
89008895 ZigType *frame_type = get_any_frame_type(g, fn_type_id->return_type);
89018896 gen_param_types.append(get_llvm_type(g, frame_type));
......@@ -8912,7 +8907,7 @@ static void resolve_llvm_types_fn_type(CodeGen *g, ZigType *fn_type) {
89128907 fn_type->data.fn.gen_param_info[1].gen_index = 1;
89138908 fn_type->data.fn.gen_param_info[1].type = g->builtin_types.entry_usize;
89148909 } else {
8915 fn_type->data.fn.gen_param_info = allocate<FnGenParamInfo>(fn_type_id->param_count);
8910 fn_type->data.fn.gen_param_info = heap::c_allocator.allocate<FnGenParamInfo>(fn_type_id->param_count);
89168911 for (size_t i = 0; i < fn_type_id->param_count; i += 1) {
89178912 FnTypeParamInfo *src_param_info = &fn_type->data.fn.fn_type_id.param_info[i];
89188913 ZigType *type_entry = src_param_info->type;
......@@ -9369,7 +9364,7 @@ bool type_has_optional_repr(ZigType *ty) {
93699364 }
93709365}
93719366
9372void copy_const_val(ZigValue *dest, ZigValue *src) {
9367void copy_const_val(CodeGen *g, ZigValue *dest, ZigValue *src) {
93739368 uint32_t prev_align = dest->llvm_align;
93749369 ConstParent prev_parent = dest->parent;
93759370 memcpy(dest, src, sizeof(ZigValue));
......@@ -9378,26 +9373,26 @@ void copy_const_val(ZigValue *dest, ZigValue *src) {
93789373 return;
93799374 dest->parent = prev_parent;
93809375 if (dest->type->id == ZigTypeIdStruct) {
9381 dest->data.x_struct.fields = alloc_const_vals_ptrs(dest->type->data.structure.src_field_count);
9376 dest->data.x_struct.fields = alloc_const_vals_ptrs(g, dest->type->data.structure.src_field_count);
93829377 for (size_t i = 0; i < dest->type->data.structure.src_field_count; i += 1) {
9383 copy_const_val(dest->data.x_struct.fields[i], src->data.x_struct.fields[i]);
9378 copy_const_val(g, dest->data.x_struct.fields[i], src->data.x_struct.fields[i]);
93849379 dest->data.x_struct.fields[i]->parent.id = ConstParentIdStruct;
93859380 dest->data.x_struct.fields[i]->parent.data.p_struct.struct_val = dest;
93869381 dest->data.x_struct.fields[i]->parent.data.p_struct.field_index = i;
93879382 }
93889383 } else if (dest->type->id == ZigTypeIdArray) {
93899384 if (dest->data.x_array.special == ConstArraySpecialNone) {
9390 dest->data.x_array.data.s_none.elements = create_const_vals(dest->type->data.array.len);
9385 dest->data.x_array.data.s_none.elements = g->pass1_arena->allocate<ZigValue>(dest->type->data.array.len);
93919386 for (uint64_t i = 0; i < dest->type->data.array.len; i += 1) {
9392 copy_const_val(&dest->data.x_array.data.s_none.elements[i], &src->data.x_array.data.s_none.elements[i]);
9387 copy_const_val(g, &dest->data.x_array.data.s_none.elements[i], &src->data.x_array.data.s_none.elements[i]);
93939388 dest->data.x_array.data.s_none.elements[i].parent.id = ConstParentIdArray;
93949389 dest->data.x_array.data.s_none.elements[i].parent.data.p_array.array_val = dest;
93959390 dest->data.x_array.data.s_none.elements[i].parent.data.p_array.elem_index = i;
93969391 }
93979392 }
93989393 } else if (type_has_optional_repr(dest->type) && dest->data.x_optional != nullptr) {
9399 dest->data.x_optional = create_const_vals(1);
9400 copy_const_val(dest->data.x_optional, src->data.x_optional);
9394 dest->data.x_optional = g->pass1_arena->create<ZigValue>();
9395 copy_const_val(g, dest->data.x_optional, src->data.x_optional);
94019396 dest->data.x_optional->parent.id = ConstParentIdOptionalPayload;
94029397 dest->data.x_optional->parent.data.p_optional_payload.optional_val = dest;
94039398 }
src/analyze.hpp+10-11
......@@ -128,22 +128,22 @@ void init_const_str_lit(CodeGen *g, ZigValue *const_val, Buf *str);
128128ZigValue *create_const_str_lit(CodeGen *g, Buf *str);
129129
130130void init_const_bigint(ZigValue *const_val, ZigType *type, const BigInt *bigint);
131ZigValue *create_const_bigint(ZigType *type, const BigInt *bigint);
131ZigValue *create_const_bigint(CodeGen *g, ZigType *type, const BigInt *bigint);
132132
133133void init_const_unsigned_negative(ZigValue *const_val, ZigType *type, uint64_t x, bool negative);
134ZigValue *create_const_unsigned_negative(ZigType *type, uint64_t x, bool negative);
134ZigValue *create_const_unsigned_negative(CodeGen *g, ZigType *type, uint64_t x, bool negative);
135135
136136void init_const_signed(ZigValue *const_val, ZigType *type, int64_t x);
137ZigValue *create_const_signed(ZigType *type, int64_t x);
137ZigValue *create_const_signed(CodeGen *g, ZigType *type, int64_t x);
138138
139139void init_const_usize(CodeGen *g, ZigValue *const_val, uint64_t x);
140140ZigValue *create_const_usize(CodeGen *g, uint64_t x);
141141
142142void init_const_float(ZigValue *const_val, ZigType *type, double value);
143ZigValue *create_const_float(ZigType *type, double value);
143ZigValue *create_const_float(CodeGen *g, ZigType *type, double value);
144144
145145void init_const_enum(ZigValue *const_val, ZigType *type, const BigInt *tag);
146ZigValue *create_const_enum(ZigType *type, const BigInt *tag);
146ZigValue *create_const_enum(CodeGen *g, ZigType *type, const BigInt *tag);
147147
148148void init_const_bool(CodeGen *g, ZigValue *const_val, bool value);
149149ZigValue *create_const_bool(CodeGen *g, bool value);
......@@ -152,7 +152,7 @@ void init_const_type(CodeGen *g, ZigValue *const_val, ZigType *type_value);
152152ZigValue *create_const_type(CodeGen *g, ZigType *type_value);
153153
154154void init_const_runtime(ZigValue *const_val, ZigType *type);
155ZigValue *create_const_runtime(ZigType *type);
155ZigValue *create_const_runtime(CodeGen *g, ZigType *type);
156156
157157void init_const_ptr_ref(CodeGen *g, ZigValue *const_val, ZigValue *pointee_val, bool is_const);
158158ZigValue *create_const_ptr_ref(CodeGen *g, ZigValue *pointee_val, bool is_const);
......@@ -172,11 +172,10 @@ void init_const_slice(CodeGen *g, ZigValue *const_val, ZigValue *array_val,
172172ZigValue *create_const_slice(CodeGen *g, ZigValue *array_val, size_t start, size_t len, bool is_const);
173173
174174void init_const_null(ZigValue *const_val, ZigType *type);
175ZigValue *create_const_null(ZigType *type);
175ZigValue *create_const_null(CodeGen *g, ZigType *type);
176176
177ZigValue *create_const_vals(size_t count);
178ZigValue **alloc_const_vals_ptrs(size_t count);
179ZigValue **realloc_const_vals_ptrs(ZigValue **ptr, size_t old_count, size_t new_count);
177ZigValue **alloc_const_vals_ptrs(CodeGen *g, size_t count);
178ZigValue **realloc_const_vals_ptrs(CodeGen *g, ZigValue **ptr, size_t old_count, size_t new_count);
180179
181180TypeStructField **alloc_type_struct_fields(size_t count);
182181TypeStructField **realloc_type_struct_fields(TypeStructField **ptr, size_t old_count, size_t new_count);
......@@ -275,7 +274,7 @@ Error analyze_import(CodeGen *codegen, ZigType *source_import, Buf *import_targe
275274 ZigType **out_import, Buf **out_import_target_path, Buf *out_full_path);
276275ZigValue *get_the_one_possible_value(CodeGen *g, ZigType *type_entry);
277276bool is_anon_container(ZigType *ty);
278void copy_const_val(ZigValue *dest, ZigValue *src);
277void copy_const_val(CodeGen *g, ZigValue *dest, ZigValue *src);
279278bool type_has_optional_repr(ZigType *ty);
280279bool is_opt_err_set(ZigType *ty);
281280bool type_is_numeric(ZigType *ty);
src/bigint.cpp+16-16
......@@ -93,7 +93,7 @@ static void to_twos_complement(BigInt *dest, const BigInt *op, size_t bit_count)
9393 if (dest->data.digit == 0) dest->digit_count = 0;
9494 return;
9595 }
96 dest->data.digits = allocate_nonzero<uint64_t>(dest->digit_count);
96 dest->data.digits = heap::c_allocator.allocate_nonzero<uint64_t>(dest->digit_count);
9797 for (size_t i = 0; i < digits_to_copy; i += 1) {
9898 uint64_t digit = (i < op->digit_count) ? op_digits[i] : 0;
9999 dest->data.digits[i] = digit;
......@@ -174,7 +174,7 @@ void bigint_init_data(BigInt *dest, const uint64_t *digits, size_t digit_count,
174174
175175 dest->digit_count = digit_count;
176176 dest->is_negative = is_negative;
177 dest->data.digits = allocate_nonzero<uint64_t>(digit_count);
177 dest->data.digits = heap::c_allocator.allocate_nonzero<uint64_t>(digit_count);
178178 memcpy(dest->data.digits, digits, sizeof(uint64_t) * digit_count);
179179
180180 bigint_normalize(dest);
......@@ -191,13 +191,13 @@ void bigint_init_bigint(BigInt *dest, const BigInt *src) {
191191 }
192192 dest->is_negative = src->is_negative;
193193 dest->digit_count = src->digit_count;
194 dest->data.digits = allocate_nonzero<uint64_t>(dest->digit_count);
194 dest->data.digits = heap::c_allocator.allocate_nonzero<uint64_t>(dest->digit_count);
195195 memcpy(dest->data.digits, src->data.digits, sizeof(uint64_t) * dest->digit_count);
196196}
197197
198198void bigint_deinit(BigInt *bi) {
199199 if (bi->digit_count > 1)
200 deallocate<uint64_t>(bi->data.digits, bi->digit_count);
200 heap::c_allocator.deallocate(bi->data.digits, bi->digit_count);
201201}
202202
203203void bigint_init_bigfloat(BigInt *dest, const BigFloat *op) {
......@@ -227,7 +227,7 @@ void bigint_init_bigfloat(BigInt *dest, const BigFloat *op) {
227227 f128M_rem(&abs_val, &max_u64, &remainder);
228228
229229 dest->digit_count = 2;
230 dest->data.digits = allocate_nonzero<uint64_t>(dest->digit_count);
230 dest->data.digits = heap::c_allocator.allocate_nonzero<uint64_t>(dest->digit_count);
231231 dest->data.digits[0] = f128M_to_ui64(&remainder, softfloat_round_minMag, false);
232232 dest->data.digits[1] = f128M_to_ui64(&amt, softfloat_round_minMag, false);
233233 bigint_normalize(dest);
......@@ -345,7 +345,7 @@ void bigint_read_twos_complement(BigInt *dest, const uint8_t *buf, size_t bit_co
345345 if (dest->digit_count == 1) {
346346 digits = &dest->data.digit;
347347 } else {
348 digits = allocate_nonzero<uint64_t>(dest->digit_count);
348 digits = heap::c_allocator.allocate_nonzero<uint64_t>(dest->digit_count);
349349 dest->data.digits = digits;
350350 }
351351
......@@ -464,7 +464,7 @@ void bigint_add(BigInt *dest, const BigInt *op1, const BigInt *op2) {
464464 }
465465 size_t i = 1;
466466 uint64_t first_digit = dest->data.digit;
467 dest->data.digits = allocate_nonzero<uint64_t>(max(op1->digit_count, op2->digit_count) + 1);
467 dest->data.digits = heap::c_allocator.allocate_nonzero<uint64_t>(max(op1->digit_count, op2->digit_count) + 1);
468468 dest->data.digits[0] = first_digit;
469469
470470 for (;;) {
......@@ -532,7 +532,7 @@ void bigint_add(BigInt *dest, const BigInt *op1, const BigInt *op2) {
532532 return;
533533 }
534534 uint64_t first_digit = dest->data.digit;
535 dest->data.digits = allocate_nonzero<uint64_t>(bigger_op->digit_count);
535 dest->data.digits = heap::c_allocator.allocate_nonzero<uint64_t>(bigger_op->digit_count);
536536 dest->data.digits[0] = first_digit;
537537 size_t i = 1;
538538
......@@ -1032,7 +1032,7 @@ static void bigint_unsigned_division(const BigInt *op1, const BigInt *op2, BigIn
10321032 if (lhsWords == 1) {
10331033 Quotient->data.digit = Make_64(Q[1], Q[0]);
10341034 } else {
1035 Quotient->data.digits = allocate<uint64_t>(lhsWords);
1035 Quotient->data.digits = heap::c_allocator.allocate<uint64_t>(lhsWords);
10361036 for (size_t i = 0; i < lhsWords; i += 1) {
10371037 Quotient->data.digits[i] = Make_64(Q[i*2+1], Q[i*2]);
10381038 }
......@@ -1046,7 +1046,7 @@ static void bigint_unsigned_division(const BigInt *op1, const BigInt *op2, BigIn
10461046 if (rhsWords == 1) {
10471047 Remainder->data.digit = Make_64(R[1], R[0]);
10481048 } else {
1049 Remainder->data.digits = allocate<uint64_t>(rhsWords);
1049 Remainder->data.digits = heap::c_allocator.allocate<uint64_t>(rhsWords);
10501050 for (size_t i = 0; i < rhsWords; i += 1) {
10511051 Remainder->data.digits[i] = Make_64(R[i*2+1], R[i*2]);
10521052 }
......@@ -1218,7 +1218,7 @@ void bigint_or(BigInt *dest, const BigInt *op1, const BigInt *op2) {
12181218 return;
12191219 }
12201220 dest->digit_count = max(op1->digit_count, op2->digit_count);
1221 dest->data.digits = allocate_nonzero<uint64_t>(dest->digit_count);
1221 dest->data.digits = heap::c_allocator.allocate_nonzero<uint64_t>(dest->digit_count);
12221222 for (size_t i = 0; i < dest->digit_count; i += 1) {
12231223 uint64_t digit = 0;
12241224 if (i < op1->digit_count) {
......@@ -1262,7 +1262,7 @@ void bigint_and(BigInt *dest, const BigInt *op1, const BigInt *op2) {
12621262 }
12631263
12641264 dest->digit_count = max(op1->digit_count, op2->digit_count);
1265 dest->data.digits = allocate_nonzero<uint64_t>(dest->digit_count);
1265 dest->data.digits = heap::c_allocator.allocate_nonzero<uint64_t>(dest->digit_count);
12661266
12671267 size_t i = 0;
12681268 for (; i < op1->digit_count && i < op2->digit_count; i += 1) {
......@@ -1308,7 +1308,7 @@ void bigint_xor(BigInt *dest, const BigInt *op1, const BigInt *op2) {
13081308 return;
13091309 }
13101310 dest->digit_count = max(op1->digit_count, op2->digit_count);
1311 dest->data.digits = allocate_nonzero<uint64_t>(dest->digit_count);
1311 dest->data.digits = heap::c_allocator.allocate_nonzero<uint64_t>(dest->digit_count);
13121312 size_t i = 0;
13131313 for (; i < op1->digit_count && i < op2->digit_count; i += 1) {
13141314 dest->data.digits[i] = op1_digits[i] ^ op2_digits[i];
......@@ -1358,7 +1358,7 @@ void bigint_shl(BigInt *dest, const BigInt *op1, const BigInt *op2) {
13581358 uint64_t digit_shift_count = shift_amt / 64;
13591359 uint64_t leftover_shift_count = shift_amt % 64;
13601360
1361 dest->data.digits = allocate<uint64_t>(op1->digit_count + digit_shift_count + 1);
1361 dest->data.digits = heap::c_allocator.allocate<uint64_t>(op1->digit_count + digit_shift_count + 1);
13621362 dest->digit_count = digit_shift_count;
13631363 uint64_t carry = 0;
13641364 for (size_t i = 0; i < op1->digit_count; i += 1) {
......@@ -1421,7 +1421,7 @@ void bigint_shr(BigInt *dest, const BigInt *op1, const BigInt *op2) {
14211421 if (dest->digit_count == 1) {
14221422 digits = &dest->data.digit;
14231423 } else {
1424 digits = allocate<uint64_t>(dest->digit_count);
1424 digits = heap::c_allocator.allocate<uint64_t>(dest->digit_count);
14251425 dest->data.digits = digits;
14261426 }
14271427
......@@ -1492,7 +1492,7 @@ void bigint_not(BigInt *dest, const BigInt *op, size_t bit_count, bool is_signed
14921492 }
14931493 dest->digit_count = (bit_count + 63) / 64;
14941494 assert(dest->digit_count >= op->digit_count);
1495 dest->data.digits = allocate_nonzero<uint64_t>(dest->digit_count);
1495 dest->data.digits = heap::c_allocator.allocate_nonzero<uint64_t>(dest->digit_count);
14961496 size_t i = 0;
14971497 for (; i < op->digit_count; i += 1) {
14981498 dest->data.digits[i] = ~op_digits[i];
src/buffer.hpp+4-5
......@@ -50,7 +50,7 @@ static inline void buf_resize(Buf *buf, size_t new_len) {
5050}
5151
5252static inline Buf *buf_alloc_fixed(size_t size) {
53 Buf *buf = allocate<Buf>(1);
53 Buf *buf = heap::c_allocator.create<Buf>();
5454 buf_resize(buf, size);
5555 return buf;
5656}
......@@ -65,7 +65,7 @@ static inline void buf_deinit(Buf *buf) {
6565
6666static inline void buf_destroy(Buf *buf) {
6767 buf_deinit(buf);
68 free(buf);
68 heap::c_allocator.destroy(buf);
6969}
7070
7171static inline void buf_init_from_mem(Buf *buf, const char *ptr, size_t len) {
......@@ -85,7 +85,7 @@ static inline void buf_init_from_buf(Buf *buf, Buf *other) {
8585
8686static inline Buf *buf_create_from_mem(const char *ptr, size_t len) {
8787 assert(len != SIZE_MAX);
88 Buf *buf = allocate<Buf>(1);
88 Buf *buf = heap::c_allocator.create<Buf>();
8989 buf_init_from_mem(buf, ptr, len);
9090 return buf;
9191}
......@@ -108,7 +108,7 @@ static inline Buf *buf_slice(Buf *in_buf, size_t start, size_t end) {
108108 assert(end != SIZE_MAX);
109109 assert(start < buf_len(in_buf));
110110 assert(end <= buf_len(in_buf));
111 Buf *out_buf = allocate<Buf>(1);
111 Buf *out_buf = heap::c_allocator.create<Buf>();
112112 out_buf->list.resize(end - start + 1);
113113 memcpy(buf_ptr(out_buf), buf_ptr(in_buf) + start, end - start);
114114 out_buf->list.at(buf_len(out_buf)) = 0;
......@@ -211,5 +211,4 @@ static inline void buf_replace(Buf* buf, char from, char to) {
211211 }
212212}
213213
214
215214#endif
src/codegen.cpp+40-35
......@@ -21,6 +21,7 @@
2121#include "userland.h"
2222#include "dump_analysis.hpp"
2323#include "softfloat.hpp"
24#include "mem_profile.hpp"
2425
2526#include <stdio.h>
2627#include <errno.h>
......@@ -57,7 +58,7 @@ static void init_darwin_native(CodeGen *g) {
5758}
5859
5960static ZigPackage *new_package(const char *root_src_dir, const char *root_src_path, const char *pkg_path) {
60 ZigPackage *entry = allocate<ZigPackage>(1);
61 ZigPackage *entry = heap::c_allocator.create<ZigPackage>();
6162 entry->package_table.init(4);
6263 buf_init_from_str(&entry->root_src_dir, root_src_dir);
6364 buf_init_from_str(&entry->root_src_path, root_src_path);
......@@ -4327,7 +4328,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutableGen *executable, IrIn
43274328 }
43284329 size_t field_count = arg_calc.field_index;
43294330
4330 LLVMTypeRef *field_types = allocate_nonzero<LLVMTypeRef>(field_count);
4331 LLVMTypeRef *field_types = heap::c_allocator.allocate_nonzero<LLVMTypeRef>(field_count);
43314332 LLVMGetStructElementTypes(LLVMGetElementType(LLVMTypeOf(frame_result_loc)), field_types);
43324333 assert(LLVMCountStructElementTypes(LLVMGetElementType(LLVMTypeOf(frame_result_loc))) == arg_calc_start.field_index);
43334334
......@@ -4680,8 +4681,8 @@ static LLVMValueRef ir_render_asm_gen(CodeGen *g, IrExecutableGen *executable, I
46804681 instruction->return_count;
46814682 size_t total_index = 0;
46824683 size_t param_index = 0;
4683 LLVMTypeRef *param_types = allocate<LLVMTypeRef>(input_and_output_count);
4684 LLVMValueRef *param_values = allocate<LLVMValueRef>(input_and_output_count);
4684 LLVMTypeRef *param_types = heap::c_allocator.allocate<LLVMTypeRef>(input_and_output_count);
4685 LLVMValueRef *param_values = heap::c_allocator.allocate<LLVMValueRef>(input_and_output_count);
46854686 for (size_t i = 0; i < asm_expr->output_list.length; i += 1, total_index += 1) {
46864687 AsmOutput *asm_output = asm_expr->output_list.at(i);
46874688 bool is_return = (asm_output->return_type != nullptr);
......@@ -4923,7 +4924,7 @@ static LLVMValueRef ir_render_shuffle_vector(CodeGen *g, IrExecutableGen *execut
49234924 // second vector. These start at -1 and go down, and are easiest to use
49244925 // with the ~ operator. Here we convert between the two formats.
49254926 IrInstGen *mask = instruction->mask;
4926 LLVMValueRef *values = allocate<LLVMValueRef>(len_mask);
4927 LLVMValueRef *values = heap::c_allocator.allocate<LLVMValueRef>(len_mask);
49274928 for (uint64_t i = 0; i < len_mask; i++) {
49284929 if (mask->value->data.x_array.data.s_none.elements[i].special == ConstValSpecialUndef) {
49294930 values[i] = LLVMGetUndef(LLVMInt32Type());
......@@ -4935,7 +4936,7 @@ static LLVMValueRef ir_render_shuffle_vector(CodeGen *g, IrExecutableGen *execut
49354936 }
49364937
49374938 LLVMValueRef llvm_mask_value = LLVMConstVector(values, len_mask);
4938 free(values);
4939 heap::c_allocator.deallocate(values, len_mask);
49394940
49404941 return LLVMBuildShuffleVector(g->builder,
49414942 ir_llvm_value(g, instruction->a),
......@@ -5003,8 +5004,8 @@ static LLVMValueRef ir_render_phi(CodeGen *g, IrExecutableGen *executable, IrIns
50035004 }
50045005
50055006 LLVMValueRef phi = LLVMBuildPhi(g->builder, phi_type, "");
5006 LLVMValueRef *incoming_values = allocate<LLVMValueRef>(instruction->incoming_count);
5007 LLVMBasicBlockRef *incoming_blocks = allocate<LLVMBasicBlockRef>(instruction->incoming_count);
5007 LLVMValueRef *incoming_values = heap::c_allocator.allocate<LLVMValueRef>(instruction->incoming_count);
5008 LLVMBasicBlockRef *incoming_blocks = heap::c_allocator.allocate<LLVMBasicBlockRef>(instruction->incoming_count);
50085009 for (size_t i = 0; i < instruction->incoming_count; i += 1) {
50095010 incoming_values[i] = ir_llvm_value(g, instruction->incoming_values[i]);
50105011 incoming_blocks[i] = instruction->incoming_blocks[i]->llvm_exit_block;
......@@ -5977,12 +5978,12 @@ static LLVMValueRef ir_render_bswap(CodeGen *g, IrExecutableGen *executable, IrI
59775978 LLVMValueRef shift_amt = LLVMConstInt(get_llvm_type(g, extended_type), 8, false);
59785979 if (is_vector) {
59795980 extended_type = get_vector_type(g, expr_type->data.vector.len, extended_type);
5980 LLVMValueRef *values = allocate_nonzero<LLVMValueRef>(expr_type->data.vector.len);
5981 LLVMValueRef *values = heap::c_allocator.allocate_nonzero<LLVMValueRef>(expr_type->data.vector.len);
59815982 for (uint32_t i = 0; i < expr_type->data.vector.len; i += 1) {
59825983 values[i] = shift_amt;
59835984 }
59845985 shift_amt = LLVMConstVector(values, expr_type->data.vector.len);
5985 free(values);
5986 heap::c_allocator.deallocate(values, expr_type->data.vector.len);
59865987 }
59875988 // aabbcc
59885989 LLVMValueRef extended = LLVMBuildZExt(g->builder, op, get_llvm_type(g, extended_type), "");
......@@ -7015,7 +7016,7 @@ check: switch (const_val->special) {
70157016 }
70167017 case ZigTypeIdStruct:
70177018 {
7018 LLVMValueRef *fields = allocate<LLVMValueRef>(type_entry->data.structure.gen_field_count);
7019 LLVMValueRef *fields = heap::c_allocator.allocate<LLVMValueRef>(type_entry->data.structure.gen_field_count);
70197020 size_t src_field_count = type_entry->data.structure.src_field_count;
70207021 bool make_unnamed_struct = false;
70217022 assert(type_entry->data.structure.resolve_status == ResolveStatusLLVMFull);
......@@ -7074,7 +7075,7 @@ check: switch (const_val->special) {
70747075 } else {
70757076 const LLVMValueRef AMT = LLVMConstInt(LLVMTypeOf(val), 8, false);
70767077
7077 LLVMValueRef *values = allocate<LLVMValueRef>(size_in_bytes);
7078 LLVMValueRef *values = heap::c_allocator.allocate<LLVMValueRef>(size_in_bytes);
70787079 for (size_t i = 0; i < size_in_bytes; i++) {
70797080 const size_t idx = is_big_endian ? size_in_bytes - 1 - i : i;
70807081 values[idx] = LLVMConstTruncOrBitCast(val, LLVMInt8Type());
......@@ -7138,7 +7139,7 @@ check: switch (const_val->special) {
71387139 case ConstArraySpecialNone: {
71397140 uint64_t extra_len_from_sentinel = (type_entry->data.array.sentinel != nullptr) ? 1 : 0;
71407141 uint64_t full_len = len + extra_len_from_sentinel;
7141 LLVMValueRef *values = allocate<LLVMValueRef>(full_len);
7142 LLVMValueRef *values = heap::c_allocator.allocate<LLVMValueRef>(full_len);
71427143 LLVMTypeRef element_type_ref = get_llvm_type(g, type_entry->data.array.child_type);
71437144 bool make_unnamed_struct = false;
71447145 for (uint64_t i = 0; i < len; i += 1) {
......@@ -7170,7 +7171,7 @@ check: switch (const_val->special) {
71707171 case ConstArraySpecialUndef:
71717172 return LLVMGetUndef(get_llvm_type(g, type_entry));
71727173 case ConstArraySpecialNone: {
7173 LLVMValueRef *values = allocate<LLVMValueRef>(len);
7174 LLVMValueRef *values = heap::c_allocator.allocate<LLVMValueRef>(len);
71747175 for (uint64_t i = 0; i < len; i += 1) {
71757176 ZigValue *elem_value = &const_val->data.x_array.data.s_none.elements[i];
71767177 values[i] = gen_const_val(g, elem_value, "");
......@@ -7180,7 +7181,7 @@ check: switch (const_val->special) {
71807181 case ConstArraySpecialBuf: {
71817182 Buf *buf = const_val->data.x_array.data.s_buf;
71827183 assert(buf_len(buf) == len);
7183 LLVMValueRef *values = allocate<LLVMValueRef>(len);
7184 LLVMValueRef *values = heap::c_allocator.allocate<LLVMValueRef>(len);
71847185 for (uint64_t i = 0; i < len; i += 1) {
71857186 values[i] = LLVMConstInt(g->builtin_types.entry_u8->llvm_type, buf_ptr(buf)[i], false);
71867187 }
......@@ -7382,7 +7383,7 @@ static void generate_error_name_table(CodeGen *g) {
73827383 PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0, false);
73837384 ZigType *str_type = get_slice_type(g, u8_ptr_type);
73847385
7385 LLVMValueRef *values = allocate<LLVMValueRef>(g->errors_by_index.length);
7386 LLVMValueRef *values = heap::c_allocator.allocate<LLVMValueRef>(g->errors_by_index.length);
73867387 values[0] = LLVMGetUndef(get_llvm_type(g, str_type));
73877388 for (size_t i = 1; i < g->errors_by_index.length; i += 1) {
73887389 ErrorTableEntry *err_entry = g->errors_by_index.at(i);
......@@ -7911,6 +7912,9 @@ static void do_code_gen(CodeGen *g) {
79117912}
79127913
79137914static void zig_llvm_emit_output(CodeGen *g) {
7915 g->pass1_arena->destruct(&heap::c_allocator);
7916 g->pass1_arena = nullptr;
7917
79147918 bool is_small = g->build_mode == BuildModeSmallRelease;
79157919
79167920 Buf *output_path = &g->o_file_output_path;
......@@ -8207,7 +8211,7 @@ static void define_intern_values(CodeGen *g) {
82078211}
82088212
82098213static BuiltinFnEntry *create_builtin_fn(CodeGen *g, BuiltinFnId id, const char *name, size_t count) {
8210 BuiltinFnEntry *builtin_fn = allocate<BuiltinFnEntry>(1);
8214 BuiltinFnEntry *builtin_fn = heap::c_allocator.create<BuiltinFnEntry>();
82118215 buf_init_from_str(&builtin_fn->name, name);
82128216 builtin_fn->id = id;
82138217 builtin_fn->param_count = count;
......@@ -8925,16 +8929,16 @@ static void init(CodeGen *g) {
89258929 define_builtin_types(g);
89268930 define_intern_values(g);
89278931
8928 IrInstGen *sentinel_instructions = allocate<IrInstGen>(2);
8932 IrInstGen *sentinel_instructions = heap::c_allocator.allocate<IrInstGen>(2);
89298933 g->invalid_inst_gen = &sentinel_instructions[0];
8930 g->invalid_inst_gen->value = allocate<ZigValue>(1, "ZigValue");
8934 g->invalid_inst_gen->value = g->pass1_arena->create<ZigValue>();
89318935 g->invalid_inst_gen->value->type = g->builtin_types.entry_invalid;
89328936
89338937 g->unreach_instruction = &sentinel_instructions[1];
8934 g->unreach_instruction->value = allocate<ZigValue>(1, "ZigValue");
8938 g->unreach_instruction->value = g->pass1_arena->create<ZigValue>();
89358939 g->unreach_instruction->value->type = g->builtin_types.entry_unreachable;
89368940
8937 g->invalid_inst_src = allocate<IrInstSrc>(1);
8941 g->invalid_inst_src = heap::c_allocator.create<IrInstSrc>();
89388942
89398943 define_builtin_fns(g);
89408944 Error err;
......@@ -9016,7 +9020,7 @@ static void detect_libc(CodeGen *g) {
90169020 buf_ptr(g->zig_lib_dir), target_os_name(g->zig_target->os));
90179021
90189022 g->libc_include_dir_len = 4;
9019 g->libc_include_dir_list = allocate<Buf*>(g->libc_include_dir_len);
9023 g->libc_include_dir_list = heap::c_allocator.allocate<Buf*>(g->libc_include_dir_len);
90209024 g->libc_include_dir_list[0] = arch_include_dir;
90219025 g->libc_include_dir_list[1] = generic_include_dir;
90229026 g->libc_include_dir_list[2] = arch_os_include_dir;
......@@ -9025,7 +9029,7 @@ static void detect_libc(CodeGen *g) {
90259029 }
90269030
90279031 if (g->zig_target->is_native) {
9028 g->libc = allocate<ZigLibCInstallation>(1);
9032 g->libc = heap::c_allocator.create<ZigLibCInstallation>();
90299033
90309034 // search for native_libc.txt in following dirs:
90319035 // - LOCAL_CACHE_DIR
......@@ -9105,7 +9109,7 @@ static void detect_libc(CodeGen *g) {
91059109 size_t want_um_and_shared_dirs = (g->zig_target->os == OsWindows) ? 2 : 0;
91069110 size_t dir_count = 1 + want_sys_dir + want_um_and_shared_dirs;
91079111 g->libc_include_dir_len = 0;
9108 g->libc_include_dir_list = allocate<Buf*>(dir_count);
9112 g->libc_include_dir_list = heap::c_allocator.allocate<Buf*>(dir_count);
91099113
91109114 g->libc_include_dir_list[g->libc_include_dir_len] = &g->libc->include_dir;
91119115 g->libc_include_dir_len += 1;
......@@ -9472,10 +9476,10 @@ static void update_test_functions_builtin_decl(CodeGen *g) {
94729476 if ((err = type_resolve(g, struct_type, ResolveStatusSizeKnown)))
94739477 zig_unreachable();
94749478
9475 ZigValue *test_fn_array = create_const_vals(1);
9479 ZigValue *test_fn_array = g->pass1_arena->create<ZigValue>();
94769480 test_fn_array->type = get_array_type(g, struct_type, g->test_fns.length, nullptr);
94779481 test_fn_array->special = ConstValSpecialStatic;
9478 test_fn_array->data.x_array.data.s_none.elements = create_const_vals(g->test_fns.length);
9482 test_fn_array->data.x_array.data.s_none.elements = g->pass1_arena->allocate<ZigValue>(g->test_fns.length);
94799483
94809484 for (size_t i = 0; i < g->test_fns.length; i += 1) {
94819485 ZigFn *test_fn_entry = g->test_fns.at(i);
......@@ -9486,7 +9490,7 @@ static void update_test_functions_builtin_decl(CodeGen *g) {
94869490 this_val->parent.id = ConstParentIdArray;
94879491 this_val->parent.data.p_array.array_val = test_fn_array;
94889492 this_val->parent.data.p_array.elem_index = i;
9489 this_val->data.x_struct.fields = alloc_const_vals_ptrs(3);
9493 this_val->data.x_struct.fields = alloc_const_vals_ptrs(g, 3);
94909494
94919495 ZigValue *name_field = this_val->data.x_struct.fields[0];
94929496 ZigValue *name_array_val = create_const_str_lit(g, &test_fn_entry->symbol_name)->data.x_ptr.data.ref.pointee;
......@@ -9505,7 +9509,7 @@ static void update_test_functions_builtin_decl(CodeGen *g) {
95059509 frame_size_field->data.x_optional = nullptr;
95069510
95079511 if (fn_is_async(test_fn_entry)) {
9508 frame_size_field->data.x_optional = create_const_vals(1);
9512 frame_size_field->data.x_optional = g->pass1_arena->create<ZigValue>();
95099513 frame_size_field->data.x_optional->special = ConstValSpecialStatic;
95109514 frame_size_field->data.x_optional->type = g->builtin_types.entry_usize;
95119515 bigint_init_unsigned(&frame_size_field->data.x_optional->data.x_bigint,
......@@ -9640,7 +9644,7 @@ static Error get_tmp_filename(CodeGen *g, Buf *out, Buf *suffix) {
96409644
96419645Error create_c_object_cache(CodeGen *g, CacheHash **out_cache_hash, bool verbose) {
96429646 Error err;
9643 CacheHash *cache_hash = allocate<CacheHash>(1);
9647 CacheHash *cache_hash = heap::c_allocator.create<CacheHash>();
96449648 Buf *manifest_dir = buf_sprintf("%s" OS_SEP CACHE_HASH_SUBDIR, buf_ptr(g->cache_dir));
96459649 cache_init(cache_hash, manifest_dir);
96469650
......@@ -10794,7 +10798,8 @@ CodeGen *codegen_create(Buf *main_pkg_path, Buf *root_src_path, const ZigTarget
1079410798 OutType out_type, BuildMode build_mode, Buf *override_lib_dir,
1079510799 ZigLibCInstallation *libc, Buf *cache_dir, bool is_test_build, Stage2ProgressNode *progress_node)
1079610800{
10797 CodeGen *g = allocate<CodeGen>(1);
10801 CodeGen *g = heap::c_allocator.create<CodeGen>();
10802 g->pass1_arena = heap::ArenaAllocator::construct(&heap::c_allocator, &heap::c_allocator, "pass1");
1079810803 g->main_progress_node = progress_node;
1079910804
1080010805 codegen_add_time_event(g, "Initialize");
......@@ -10937,35 +10942,35 @@ void codegen_switch_sub_prog_node(CodeGen *g, Stage2ProgressNode *node) {
1093710942
1093810943ZigValue *CodeGen::Intern::for_undefined() {
1093910944#ifdef ZIG_ENABLE_MEM_PROFILE
10940 memprof_intern_count.x_undefined += 1;
10945 mem::intern_counters.x_undefined += 1;
1094110946#endif
1094210947 return &this->x_undefined;
1094310948}
1094410949
1094510950ZigValue *CodeGen::Intern::for_void() {
1094610951#ifdef ZIG_ENABLE_MEM_PROFILE
10947 memprof_intern_count.x_void += 1;
10952 mem::intern_counters.x_void += 1;
1094810953#endif
1094910954 return &this->x_void;
1095010955}
1095110956
1095210957ZigValue *CodeGen::Intern::for_null() {
1095310958#ifdef ZIG_ENABLE_MEM_PROFILE
10954 memprof_intern_count.x_null += 1;
10959 mem::intern_counters.x_null += 1;
1095510960#endif
1095610961 return &this->x_null;
1095710962}
1095810963
1095910964ZigValue *CodeGen::Intern::for_unreachable() {
1096010965#ifdef ZIG_ENABLE_MEM_PROFILE
10961 memprof_intern_count.x_unreachable += 1;
10966 mem::intern_counters.x_unreachable += 1;
1096210967#endif
1096310968 return &this->x_unreachable;
1096410969}
1096510970
1096610971ZigValue *CodeGen::Intern::for_zero_byte() {
1096710972#ifdef ZIG_ENABLE_MEM_PROFILE
10968 memprof_intern_count.zero_byte += 1;
10973 mem::intern_counters.zero_byte += 1;
1096910974#endif
1097010975 return &this->zero_byte;
1097110976}
src/errmsg.cpp+2-2
......@@ -99,7 +99,7 @@ void err_msg_add_note(ErrorMsg *parent, ErrorMsg *note) {
9999ErrorMsg *err_msg_create_with_offset(Buf *path, size_t line, size_t column, size_t offset,
100100 const char *source, Buf *msg)
101101{
102 ErrorMsg *err_msg = allocate<ErrorMsg>(1);
102 ErrorMsg *err_msg = heap::c_allocator.create<ErrorMsg>();
103103 err_msg->path = path;
104104 err_msg->line_start = line;
105105 err_msg->column_start = column;
......@@ -138,7 +138,7 @@ ErrorMsg *err_msg_create_with_offset(Buf *path, size_t line, size_t column, size
138138ErrorMsg *err_msg_create_with_line(Buf *path, size_t line, size_t column,
139139 Buf *source, ZigList<size_t> *line_offsets, Buf *msg)
140140{
141 ErrorMsg *err_msg = allocate<ErrorMsg>(1);
141 ErrorMsg *err_msg = heap::c_allocator.create<ErrorMsg>();
142142 err_msg->path = path;
143143 err_msg->line_start = line;
144144 err_msg->column_start = column;
src/glibc.cpp+4-4
......@@ -21,7 +21,7 @@ static const ZigGLibCLib glibc_libs[] = {
2121Error glibc_load_metadata(ZigGLibCAbi **out_result, Buf *zig_lib_dir, bool verbose) {
2222 Error err;
2323
24 ZigGLibCAbi *glibc_abi = allocate<ZigGLibCAbi>(1);
24 ZigGLibCAbi *glibc_abi = heap::c_allocator.create<ZigGLibCAbi>();
2525 glibc_abi->vers_txt_path = buf_sprintf("%s" OS_SEP "libc" OS_SEP "glibc" OS_SEP "vers.txt", buf_ptr(zig_lib_dir));
2626 glibc_abi->fns_txt_path = buf_sprintf("%s" OS_SEP "libc" OS_SEP "glibc" OS_SEP "fns.txt", buf_ptr(zig_lib_dir));
2727 glibc_abi->abi_txt_path = buf_sprintf("%s" OS_SEP "libc" OS_SEP "glibc" OS_SEP "abi.txt", buf_ptr(zig_lib_dir));
......@@ -100,10 +100,10 @@ Error glibc_load_metadata(ZigGLibCAbi **out_result, Buf *zig_lib_dir, bool verbo
100100 Optional<Slice<uint8_t>> opt_line = SplitIterator_next_separate(&it);
101101 if (!opt_line.is_some) break;
102102
103 ver_list_base = allocate<ZigGLibCVerList>(glibc_abi->all_functions.length);
103 ver_list_base = heap::c_allocator.allocate<ZigGLibCVerList>(glibc_abi->all_functions.length);
104104 SplitIterator line_it = memSplit(opt_line.value, str(" "));
105105 for (;;) {
106 ZigTarget *target = allocate<ZigTarget>(1);
106 ZigTarget *target = heap::c_allocator.create<ZigTarget>();
107107 Optional<Slice<uint8_t>> opt_target = SplitIterator_next(&line_it);
108108 if (!opt_target.is_some) break;
109109
......@@ -174,7 +174,7 @@ Error glibc_build_dummies_and_maps(CodeGen *g, const ZigGLibCAbi *glibc_abi, con
174174 Error err;
175175
176176 Buf *cache_dir = get_global_cache_dir();
177 CacheHash *cache_hash = allocate<CacheHash>(1);
177 CacheHash *cache_hash = heap::c_allocator.create<CacheHash>();
178178 Buf *manifest_dir = buf_sprintf("%s" OS_SEP CACHE_HASH_SUBDIR, buf_ptr(cache_dir));
179179 cache_init(cache_hash, manifest_dir);
180180
src/hash_map.hpp+3-3
......@@ -19,7 +19,7 @@ public:
1919 init_capacity(capacity);
2020 }
2121 void deinit(void) {
22 free(_entries);
22 heap::c_allocator.deallocate(_entries, _capacity);
2323 }
2424
2525 struct Entry {
......@@ -57,7 +57,7 @@ public:
5757 if (old_entry->used)
5858 internal_put(old_entry->key, old_entry->value);
5959 }
60 free(old_entries);
60 heap::c_allocator.deallocate(old_entries, old_capacity);
6161 }
6262 }
6363
......@@ -164,7 +164,7 @@ private:
164164
165165 void init_capacity(int capacity) {
166166 _capacity = capacity;
167 _entries = allocate<Entry>(_capacity);
167 _entries = heap::c_allocator.allocate<Entry>(_capacity);
168168 _size = 0;
169169 _max_distance_from_start_index = 0;
170170 for (int i = 0; i < _capacity; i += 1) {
src/heap.cpp created+377
......@@ -0,0 +1,377 @@
1/*
2 * Copyright (c) 2020 Andrew Kelley
3 *
4 * This file is part of zig, which is MIT licensed.
5 * See http://opensource.org/licenses/MIT
6 */
7
8#include <new>
9#include <string.h>
10
11#include "config.h"
12#include "heap.hpp"
13#include "mem_profile.hpp"
14
15namespace heap {
16
17extern mem::Allocator &bootstrap_allocator;
18
19//
20// BootstrapAllocator implementation is identical to CAllocator minus
21// profile profile functionality. Splitting off to a base interface doesn't
22// seem worthwhile.
23//
24
25void BootstrapAllocator::init(const char *name) {}
26void BootstrapAllocator::deinit() {}
27
28void *BootstrapAllocator::internal_allocate(const mem::TypeInfo &info, size_t count) {
29 return mem::os::calloc(count, info.size);
30}
31
32void *BootstrapAllocator::internal_allocate_nonzero(const mem::TypeInfo &info, size_t count) {
33 return mem::os::malloc(count * info.size);
34}
35
36void *BootstrapAllocator::internal_reallocate(const mem::TypeInfo &info, void *old_ptr, size_t old_count, size_t new_count) {
37 auto new_ptr = this->internal_reallocate_nonzero(info, old_ptr, old_count, new_count);
38 if (new_count > old_count)
39 memset(reinterpret_cast<uint8_t *>(new_ptr) + (old_count * info.size), 0, (new_count - old_count) * info.size);
40 return new_ptr;
41}
42
43void *BootstrapAllocator::internal_reallocate_nonzero(const mem::TypeInfo &info, void *old_ptr, size_t old_count, size_t new_count) {
44 return mem::os::realloc(old_ptr, new_count * info.size);
45}
46
47void BootstrapAllocator::internal_deallocate(const mem::TypeInfo &info, void *ptr, size_t count) {
48 mem::os::free(ptr);
49}
50
51void CAllocator::init(const char *name) {
52#ifdef ZIG_ENABLE_MEM_PROFILE
53 this->profile = bootstrap_allocator.create<mem::Profile>();
54 this->profile->init(name, "CAllocator");
55#endif
56}
57
58void CAllocator::deinit() {
59#ifdef ZIG_ENABLE_MEM_PROFILE
60 assert(this->profile);
61 this->profile->deinit();
62 bootstrap_allocator.destroy(this->profile);
63 this->profile = nullptr;
64#endif
65}
66
67CAllocator *CAllocator::construct(mem::Allocator *allocator, const char *name) {
68 auto p = new(allocator->create<CAllocator>()) CAllocator();
69 p->init(name);
70 return p;
71}
72
73void CAllocator::destruct(mem::Allocator *allocator) {
74 this->deinit();
75 allocator->destroy(this);
76}
77
78#ifdef ZIG_ENABLE_MEM_PROFILE
79void CAllocator::print_report(FILE *file) {
80 this->profile->print_report(file);
81}
82#endif
83
84void *CAllocator::internal_allocate(const mem::TypeInfo &info, size_t count) {
85#ifdef ZIG_ENABLE_MEM_PROFILE
86 this->profile->record_alloc(info, count);
87#endif
88 return mem::os::calloc(count, info.size);
89}
90
91void *CAllocator::internal_allocate_nonzero(const mem::TypeInfo &info, size_t count) {
92#ifdef ZIG_ENABLE_MEM_PROFILE
93 this->profile->record_alloc(info, count);
94#endif
95 return mem::os::malloc(count * info.size);
96}
97
98void *CAllocator::internal_reallocate(const mem::TypeInfo &info, void *old_ptr, size_t old_count, size_t new_count) {
99 auto new_ptr = this->internal_reallocate_nonzero(info, old_ptr, old_count, new_count);
100 if (new_count > old_count)
101 memset(reinterpret_cast<uint8_t *>(new_ptr) + (old_count * info.size), 0, (new_count - old_count) * info.size);
102 return new_ptr;
103}
104
105void *CAllocator::internal_reallocate_nonzero(const mem::TypeInfo &info, void *old_ptr, size_t old_count, size_t new_count) {
106#ifdef ZIG_ENABLE_MEM_PROFILE
107 this->profile->record_dealloc(info, old_count);
108 this->profile->record_alloc(info, new_count);
109#endif
110 return mem::os::realloc(old_ptr, new_count * info.size);
111}
112
113void CAllocator::internal_deallocate(const mem::TypeInfo &info, void *ptr, size_t count) {
114#ifdef ZIG_ENABLE_MEM_PROFILE
115 this->profile->record_dealloc(info, count);
116#endif
117 mem::os::free(ptr);
118}
119
120struct ArenaAllocator::Impl {
121 Allocator *backing;
122
123 // regular allocations bump through a segment of static size
124 struct Segment {
125 static constexpr size_t size = 65536;
126 static constexpr size_t object_threshold = 4096;
127
128 uint8_t data[size];
129 };
130
131 // active segment
132 Segment *segment;
133 size_t segment_offset;
134
135 // keep track of segments
136 struct SegmentTrack {
137 static constexpr size_t size = (4096 - sizeof(SegmentTrack *)) / sizeof(Segment *);
138
139 // null if first
140 SegmentTrack *prev;
141 Segment *segments[size];
142 };
143 static_assert(sizeof(SegmentTrack) <= 4096, "unwanted struct padding");
144
145 // active segment track
146 SegmentTrack *segment_track;
147 size_t segment_track_remain;
148
149 // individual allocations punted to backing allocator
150 struct Object {
151 uint8_t *ptr;
152 size_t len;
153 };
154
155 // keep track of objects
156 struct ObjectTrack {
157 static constexpr size_t size = (4096 - sizeof(ObjectTrack *)) / sizeof(Object);
158
159 // null if first
160 ObjectTrack *prev;
161 Object objects[size];
162 };
163 static_assert(sizeof(ObjectTrack) <= 4096, "unwanted struct padding");
164
165 // active object track
166 ObjectTrack *object_track;
167 size_t object_track_remain;
168
169 ATTRIBUTE_RETURNS_NOALIAS inline void *allocate(const mem::TypeInfo& info, size_t count);
170 inline void *reallocate(const mem::TypeInfo& info, void *old_ptr, size_t old_count, size_t new_count);
171
172 inline void new_segment();
173 inline void track_segment();
174 inline void track_object(Object object);
175};
176
177void *ArenaAllocator::Impl::allocate(const mem::TypeInfo& info, size_t count) {
178#ifndef NDEBUG
179 // make behavior when size == 0 portable
180 if (info.size == 0 || count == 0)
181 return nullptr;
182#endif
183 const size_t nbytes = info.size * count;
184 this->segment_offset = (this->segment_offset + (info.alignment - 1)) & ~(info.alignment - 1);
185 if (nbytes >= Segment::object_threshold) {
186 auto ptr = this->backing->allocate<uint8_t>(nbytes);
187 this->track_object({ptr, nbytes});
188 return ptr;
189 }
190 if (this->segment_offset + nbytes > Segment::size)
191 this->new_segment();
192 auto ptr = &this->segment->data[this->segment_offset];
193 this->segment_offset += nbytes;
194 return ptr;
195}
196
197void *ArenaAllocator::Impl::reallocate(const mem::TypeInfo& info, void *old_ptr, size_t old_count, size_t new_count) {
198#ifndef NDEBUG
199 // make behavior when size == 0 portable
200 if (info.size == 0 && old_ptr == nullptr)
201 return nullptr;
202#endif
203 const size_t new_nbytes = info.size * new_count;
204 if (new_nbytes <= info.size * old_count)
205 return old_ptr;
206 const size_t old_nbytes = info.size * old_count;
207 this->segment_offset = (this->segment_offset + (info.alignment - 1)) & ~(info.alignment - 1);
208 if (new_nbytes >= Segment::object_threshold) {
209 auto new_ptr = this->backing->allocate<uint8_t>(new_nbytes);
210 this->track_object({new_ptr, new_nbytes});
211 memcpy(new_ptr, old_ptr, old_nbytes);
212 return new_ptr;
213 }
214 if (this->segment_offset + new_nbytes > Segment::size)
215 this->new_segment();
216 auto new_ptr = &this->segment->data[this->segment_offset];
217 this->segment_offset += new_nbytes;
218 memcpy(new_ptr, old_ptr, old_nbytes);
219 return new_ptr;
220}
221
222void ArenaAllocator::Impl::new_segment() {
223 this->segment = this->backing->create<Segment>();
224 this->segment_offset = 0;
225 this->track_segment();
226}
227
228void ArenaAllocator::Impl::track_segment() {
229 assert(this->segment != nullptr);
230 if (this->segment_track_remain < 1) {
231 auto prev = this->segment_track;
232 this->segment_track = this->backing->create<SegmentTrack>();
233 this->segment_track->prev = prev;
234 this->segment_track_remain = SegmentTrack::size;
235 }
236 this->segment_track_remain -= 1;
237 this->segment_track->segments[this->segment_track_remain] = this->segment;
238}
239
240void ArenaAllocator::Impl::track_object(Object object) {
241 if (this->object_track_remain < 1) {
242 auto prev = this->object_track;
243 this->object_track = this->backing->create<ObjectTrack>();
244 this->object_track->prev = prev;
245 this->object_track_remain = ObjectTrack::size;
246 }
247 this->object_track_remain -= 1;
248 this->object_track->objects[this->object_track_remain] = object;
249}
250
251void ArenaAllocator::init(Allocator *backing, const char *name) {
252#ifdef ZIG_ENABLE_MEM_PROFILE
253 this->profile = bootstrap_allocator.create<mem::Profile>();
254 this->profile->init(name, "ArenaAllocator");
255#endif
256 this->impl = bootstrap_allocator.create<Impl>();
257 {
258 auto &r = *this->impl;
259 r.backing = backing;
260 r.segment_offset = Impl::Segment::size;
261 }
262}
263
264void ArenaAllocator::deinit() {
265 auto &backing = *this->impl->backing;
266
267 // segments
268 if (this->impl->segment_track) {
269 // active track is not full and bounded by track_remain
270 auto prev = this->impl->segment_track->prev;
271 {
272 auto t = this->impl->segment_track;
273 for (size_t i = this->impl->segment_track_remain; i < Impl::SegmentTrack::size; ++i)
274 backing.destroy(t->segments[i]);
275 backing.destroy(t);
276 }
277
278 // previous tracks are full
279 for (auto t = prev; t != nullptr;) {
280 for (size_t i = 0; i < Impl::SegmentTrack::size; ++i)
281 backing.destroy(t->segments[i]);
282 prev = t->prev;
283 backing.destroy(t);
284 t = prev;
285 }
286 }
287
288 // objects
289 if (this->impl->object_track) {
290 // active track is not full and bounded by track_remain
291 auto prev = this->impl->object_track->prev;
292 {
293 auto t = this->impl->object_track;
294 for (size_t i = this->impl->object_track_remain; i < Impl::ObjectTrack::size; ++i) {
295 auto &obj = t->objects[i];
296 backing.deallocate(obj.ptr, obj.len);
297 }
298 backing.destroy(t);
299 }
300
301 // previous tracks are full
302 for (auto t = prev; t != nullptr;) {
303 for (size_t i = 0; i < Impl::ObjectTrack::size; ++i) {
304 auto &obj = t->objects[i];
305 backing.deallocate(obj.ptr, obj.len);
306 }
307 prev = t->prev;
308 backing.destroy(t);
309 t = prev;
310 }
311 }
312
313#ifdef ZIG_ENABLE_MEM_PROFILE
314 assert(this->profile);
315 this->profile->deinit();
316 bootstrap_allocator.destroy(this->profile);
317 this->profile = nullptr;
318#endif
319}
320
321ArenaAllocator *ArenaAllocator::construct(mem::Allocator *allocator, mem::Allocator *backing, const char *name) {
322 auto p = new(allocator->create<ArenaAllocator>()) ArenaAllocator;
323 p->init(backing, name);
324 return p;
325}
326
327void ArenaAllocator::destruct(mem::Allocator *allocator) {
328 this->deinit();
329 allocator->destroy(this);
330}
331
332#ifdef ZIG_ENABLE_MEM_PROFILE
333void ArenaAllocator::print_report(FILE *file) {
334 this->profile->print_report(file);
335}
336#endif
337
338void *ArenaAllocator::internal_allocate(const mem::TypeInfo &info, size_t count) {
339#ifdef ZIG_ENABLE_MEM_PROFILE
340 this->profile->record_alloc(info, count);
341#endif
342 return this->impl->allocate(info, count);
343}
344
345void *ArenaAllocator::internal_allocate_nonzero(const mem::TypeInfo &info, size_t count) {
346#ifdef ZIG_ENABLE_MEM_PROFILE
347 this->profile->record_alloc(info, count);
348#endif
349 return this->impl->allocate(info, count);
350}
351
352void *ArenaAllocator::internal_reallocate(const mem::TypeInfo &info, void *old_ptr, size_t old_count, size_t new_count) {
353 return this->internal_reallocate_nonzero(info, old_ptr, old_count, new_count);
354}
355
356void *ArenaAllocator::internal_reallocate_nonzero(const mem::TypeInfo &info, void *old_ptr, size_t old_count, size_t new_count) {
357#ifdef ZIG_ENABLE_MEM_PROFILE
358 this->profile->record_dealloc(info, old_count);
359 this->profile->record_alloc(info, new_count);
360#endif
361 return this->impl->reallocate(info, old_ptr, old_count, new_count);
362}
363
364void ArenaAllocator::internal_deallocate(const mem::TypeInfo &info, void *ptr, size_t count) {
365#ifdef ZIG_ENABLE_MEM_PROFILE
366 this->profile->record_dealloc(info, count);
367#endif
368 // noop
369}
370
371BootstrapAllocator bootstrap_allocator_state;
372mem::Allocator &bootstrap_allocator = bootstrap_allocator_state;
373
374CAllocator c_allocator_state;
375mem::Allocator &c_allocator = c_allocator_state;
376
377} // namespace heap
src/heap.hpp created+101
......@@ -0,0 +1,101 @@
1/*
2 * Copyright (c) 2020 Andrew Kelley
3 *
4 * This file is part of zig, which is MIT licensed.
5 * See http://opensource.org/licenses/MIT
6 */
7
8#ifndef ZIG_HEAP_HPP
9#define ZIG_HEAP_HPP
10
11#include "config.h"
12#include "util_base.hpp"
13#include "mem.hpp"
14
15#ifdef ZIG_ENABLE_MEM_PROFILE
16namespace mem {
17 struct Profile;
18}
19#endif
20
21namespace heap {
22
23struct BootstrapAllocator final : mem::Allocator {
24 void init(const char *name);
25 void deinit();
26 void destruct(Allocator *allocator) {}
27
28private:
29 ATTRIBUTE_RETURNS_NOALIAS void *internal_allocate(const mem::TypeInfo &info, size_t count) final;
30 ATTRIBUTE_RETURNS_NOALIAS void *internal_allocate_nonzero(const mem::TypeInfo &info, size_t count) final;
31 void *internal_reallocate(const mem::TypeInfo &info, void *old_ptr, size_t old_count, size_t new_count) final;
32 void *internal_reallocate_nonzero(const mem::TypeInfo &info, void *old_ptr, size_t old_count, size_t new_count) final;
33 void internal_deallocate(const mem::TypeInfo &info, void *ptr, size_t count) final;
34};
35
36struct CAllocator final : mem::Allocator {
37 void init(const char *name);
38 void deinit();
39
40 static CAllocator *construct(mem::Allocator *allocator, const char *name);
41 void destruct(mem::Allocator *allocator) final;
42
43#ifdef ZIG_ENABLE_MEM_PROFILE
44 void print_report(FILE *file = nullptr);
45#endif
46
47private:
48 ATTRIBUTE_RETURNS_NOALIAS void *internal_allocate(const mem::TypeInfo &info, size_t count) final;
49 ATTRIBUTE_RETURNS_NOALIAS void *internal_allocate_nonzero(const mem::TypeInfo &info, size_t count) final;
50 void *internal_reallocate(const mem::TypeInfo &info, void *old_ptr, size_t old_count, size_t new_count) final;
51 void *internal_reallocate_nonzero(const mem::TypeInfo &info, void *old_ptr, size_t old_count, size_t new_count) final;
52 void internal_deallocate(const mem::TypeInfo &info, void *ptr, size_t count) final;
53
54#ifdef ZIG_ENABLE_MEM_PROFILE
55 mem::Profile *profile;
56#endif
57};
58
59//
60// arena allocator
61//
62// - allocations are backed by the underlying allocator's memory
63// - allocations are N:1 relationship to underlying allocations
64// - dellocations are noops
65// - deinit() releases all underlying memory
66//
67struct ArenaAllocator final : mem::Allocator {
68 void init(Allocator *backing, const char *name);
69 void deinit();
70
71 static ArenaAllocator *construct(mem::Allocator *allocator, mem::Allocator *backing, const char *name);
72 void destruct(mem::Allocator *allocator) final;
73
74#ifdef ZIG_ENABLE_MEM_PROFILE
75 void print_report(FILE *file = nullptr);
76#endif
77
78private:
79 ATTRIBUTE_RETURNS_NOALIAS void *internal_allocate(const mem::TypeInfo &info, size_t count) final;
80 ATTRIBUTE_RETURNS_NOALIAS void *internal_allocate_nonzero(const mem::TypeInfo &info, size_t count) final;
81 void *internal_reallocate(const mem::TypeInfo &info, void *old_ptr, size_t old_count, size_t new_count) final;
82 void *internal_reallocate_nonzero(const mem::TypeInfo &info, void *old_ptr, size_t old_count, size_t new_count) final;
83 void internal_deallocate(const mem::TypeInfo &info, void *ptr, size_t count) final;
84
85#ifdef ZIG_ENABLE_MEM_PROFILE
86 mem::Profile *profile;
87#endif
88
89 struct Impl;
90 Impl *impl;
91};
92
93extern BootstrapAllocator bootstrap_allocator_state;
94extern mem::Allocator &bootstrap_allocator;
95
96extern CAllocator c_allocator_state;
97extern mem::Allocator &c_allocator;
98
99} // namespace heap
100
101#endif
src/ir.cpp+501-538
......@@ -269,477 +269,467 @@ static IrInstGen *ir_analyze_test_non_null(IrAnalyze *ira, IrInst *source_inst,
269269static IrInstGen *ir_error_dependency_loop(IrAnalyze *ira, IrInst *source_instr);
270270
271271static void destroy_instruction_src(IrInstSrc *inst) {
272#ifdef ZIG_ENABLE_MEM_PROFILE
273 const char *name = ir_inst_src_type_str(inst->id);
274#else
275 const char *name = nullptr;
276#endif
277272 switch (inst->id) {
278273 case IrInstSrcIdInvalid:
279274 zig_unreachable();
280275 case IrInstSrcIdReturn:
281 return destroy(reinterpret_cast<IrInstSrcReturn *>(inst), name);
276 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcReturn *>(inst));
282277 case IrInstSrcIdConst:
283 return destroy(reinterpret_cast<IrInstSrcConst *>(inst), name);
278 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcConst *>(inst));
284279 case IrInstSrcIdBinOp:
285 return destroy(reinterpret_cast<IrInstSrcBinOp *>(inst), name);
280 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcBinOp *>(inst));
286281 case IrInstSrcIdMergeErrSets:
287 return destroy(reinterpret_cast<IrInstSrcMergeErrSets *>(inst), name);
282 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcMergeErrSets *>(inst));
288283 case IrInstSrcIdDeclVar:
289 return destroy(reinterpret_cast<IrInstSrcDeclVar *>(inst), name);
284 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcDeclVar *>(inst));
290285 case IrInstSrcIdCall:
291 return destroy(reinterpret_cast<IrInstSrcCall *>(inst), name);
286 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcCall *>(inst));
292287 case IrInstSrcIdCallExtra:
293 return destroy(reinterpret_cast<IrInstSrcCallExtra *>(inst), name);
288 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcCallExtra *>(inst));
294289 case IrInstSrcIdUnOp:
295 return destroy(reinterpret_cast<IrInstSrcUnOp *>(inst), name);
290 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcUnOp *>(inst));
296291 case IrInstSrcIdCondBr:
297 return destroy(reinterpret_cast<IrInstSrcCondBr *>(inst), name);
292 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcCondBr *>(inst));
298293 case IrInstSrcIdBr:
299 return destroy(reinterpret_cast<IrInstSrcBr *>(inst), name);
294 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcBr *>(inst));
300295 case IrInstSrcIdPhi:
301 return destroy(reinterpret_cast<IrInstSrcPhi *>(inst), name);
296 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcPhi *>(inst));
302297 case IrInstSrcIdContainerInitList:
303 return destroy(reinterpret_cast<IrInstSrcContainerInitList *>(inst), name);
298 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcContainerInitList *>(inst));
304299 case IrInstSrcIdContainerInitFields:
305 return destroy(reinterpret_cast<IrInstSrcContainerInitFields *>(inst), name);
300 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcContainerInitFields *>(inst));
306301 case IrInstSrcIdUnreachable:
307 return destroy(reinterpret_cast<IrInstSrcUnreachable *>(inst), name);
302 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcUnreachable *>(inst));
308303 case IrInstSrcIdElemPtr:
309 return destroy(reinterpret_cast<IrInstSrcElemPtr *>(inst), name);
304 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcElemPtr *>(inst));
310305 case IrInstSrcIdVarPtr:
311 return destroy(reinterpret_cast<IrInstSrcVarPtr *>(inst), name);
306 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcVarPtr *>(inst));
312307 case IrInstSrcIdLoadPtr:
313 return destroy(reinterpret_cast<IrInstSrcLoadPtr *>(inst), name);
308 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcLoadPtr *>(inst));
314309 case IrInstSrcIdStorePtr:
315 return destroy(reinterpret_cast<IrInstSrcStorePtr *>(inst), name);
310 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcStorePtr *>(inst));
316311 case IrInstSrcIdTypeOf:
317 return destroy(reinterpret_cast<IrInstSrcTypeOf *>(inst), name);
312 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcTypeOf *>(inst));
318313 case IrInstSrcIdFieldPtr:
319 return destroy(reinterpret_cast<IrInstSrcFieldPtr *>(inst), name);
314 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFieldPtr *>(inst));
320315 case IrInstSrcIdSetCold:
321 return destroy(reinterpret_cast<IrInstSrcSetCold *>(inst), name);
316 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSetCold *>(inst));
322317 case IrInstSrcIdSetRuntimeSafety:
323 return destroy(reinterpret_cast<IrInstSrcSetRuntimeSafety *>(inst), name);
318 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSetRuntimeSafety *>(inst));
324319 case IrInstSrcIdSetFloatMode:
325 return destroy(reinterpret_cast<IrInstSrcSetFloatMode *>(inst), name);
320 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSetFloatMode *>(inst));
326321 case IrInstSrcIdArrayType:
327 return destroy(reinterpret_cast<IrInstSrcArrayType *>(inst), name);
322 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcArrayType *>(inst));
328323 case IrInstSrcIdSliceType:
329 return destroy(reinterpret_cast<IrInstSrcSliceType *>(inst), name);
324 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSliceType *>(inst));
330325 case IrInstSrcIdAnyFrameType:
331 return destroy(reinterpret_cast<IrInstSrcAnyFrameType *>(inst), name);
326 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcAnyFrameType *>(inst));
332327 case IrInstSrcIdAsm:
333 return destroy(reinterpret_cast<IrInstSrcAsm *>(inst), name);
328 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcAsm *>(inst));
334329 case IrInstSrcIdSizeOf:
335 return destroy(reinterpret_cast<IrInstSrcSizeOf *>(inst), name);
330 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSizeOf *>(inst));
336331 case IrInstSrcIdTestNonNull:
337 return destroy(reinterpret_cast<IrInstSrcTestNonNull *>(inst), name);
332 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcTestNonNull *>(inst));
338333 case IrInstSrcIdOptionalUnwrapPtr:
339 return destroy(reinterpret_cast<IrInstSrcOptionalUnwrapPtr *>(inst), name);
334 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcOptionalUnwrapPtr *>(inst));
340335 case IrInstSrcIdPopCount:
341 return destroy(reinterpret_cast<IrInstSrcPopCount *>(inst), name);
336 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcPopCount *>(inst));
342337 case IrInstSrcIdClz:
343 return destroy(reinterpret_cast<IrInstSrcClz *>(inst), name);
338 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcClz *>(inst));
344339 case IrInstSrcIdCtz:
345 return destroy(reinterpret_cast<IrInstSrcCtz *>(inst), name);
340 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcCtz *>(inst));
346341 case IrInstSrcIdBswap:
347 return destroy(reinterpret_cast<IrInstSrcBswap *>(inst), name);
342 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcBswap *>(inst));
348343 case IrInstSrcIdBitReverse:
349 return destroy(reinterpret_cast<IrInstSrcBitReverse *>(inst), name);
344 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcBitReverse *>(inst));
350345 case IrInstSrcIdSwitchBr:
351 return destroy(reinterpret_cast<IrInstSrcSwitchBr *>(inst), name);
346 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSwitchBr *>(inst));
352347 case IrInstSrcIdSwitchVar:
353 return destroy(reinterpret_cast<IrInstSrcSwitchVar *>(inst), name);
348 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSwitchVar *>(inst));
354349 case IrInstSrcIdSwitchElseVar:
355 return destroy(reinterpret_cast<IrInstSrcSwitchElseVar *>(inst), name);
350 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSwitchElseVar *>(inst));
356351 case IrInstSrcIdSwitchTarget:
357 return destroy(reinterpret_cast<IrInstSrcSwitchTarget *>(inst), name);
352 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSwitchTarget *>(inst));
358353 case IrInstSrcIdImport:
359 return destroy(reinterpret_cast<IrInstSrcImport *>(inst), name);
354 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcImport *>(inst));
360355 case IrInstSrcIdRef:
361 return destroy(reinterpret_cast<IrInstSrcRef *>(inst), name);
356 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcRef *>(inst));
362357 case IrInstSrcIdCompileErr:
363 return destroy(reinterpret_cast<IrInstSrcCompileErr *>(inst), name);
358 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcCompileErr *>(inst));
364359 case IrInstSrcIdCompileLog:
365 return destroy(reinterpret_cast<IrInstSrcCompileLog *>(inst), name);
360 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcCompileLog *>(inst));
366361 case IrInstSrcIdErrName:
367 return destroy(reinterpret_cast<IrInstSrcErrName *>(inst), name);
362 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcErrName *>(inst));
368363 case IrInstSrcIdCImport:
369 return destroy(reinterpret_cast<IrInstSrcCImport *>(inst), name);
364 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcCImport *>(inst));
370365 case IrInstSrcIdCInclude:
371 return destroy(reinterpret_cast<IrInstSrcCInclude *>(inst), name);
366 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcCInclude *>(inst));
372367 case IrInstSrcIdCDefine:
373 return destroy(reinterpret_cast<IrInstSrcCDefine *>(inst), name);
368 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcCDefine *>(inst));
374369 case IrInstSrcIdCUndef:
375 return destroy(reinterpret_cast<IrInstSrcCUndef *>(inst), name);
370 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcCUndef *>(inst));
376371 case IrInstSrcIdEmbedFile:
377 return destroy(reinterpret_cast<IrInstSrcEmbedFile *>(inst), name);
372 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcEmbedFile *>(inst));
378373 case IrInstSrcIdCmpxchg:
379 return destroy(reinterpret_cast<IrInstSrcCmpxchg *>(inst), name);
374 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcCmpxchg *>(inst));
380375 case IrInstSrcIdFence:
381 return destroy(reinterpret_cast<IrInstSrcFence *>(inst), name);
376 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFence *>(inst));
382377 case IrInstSrcIdTruncate:
383 return destroy(reinterpret_cast<IrInstSrcTruncate *>(inst), name);
378 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcTruncate *>(inst));
384379 case IrInstSrcIdIntCast:
385 return destroy(reinterpret_cast<IrInstSrcIntCast *>(inst), name);
380 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcIntCast *>(inst));
386381 case IrInstSrcIdFloatCast:
387 return destroy(reinterpret_cast<IrInstSrcFloatCast *>(inst), name);
382 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFloatCast *>(inst));
388383 case IrInstSrcIdErrSetCast:
389 return destroy(reinterpret_cast<IrInstSrcErrSetCast *>(inst), name);
384 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcErrSetCast *>(inst));
390385 case IrInstSrcIdFromBytes:
391 return destroy(reinterpret_cast<IrInstSrcFromBytes *>(inst), name);
386 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFromBytes *>(inst));
392387 case IrInstSrcIdToBytes:
393 return destroy(reinterpret_cast<IrInstSrcToBytes *>(inst), name);
388 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcToBytes *>(inst));
394389 case IrInstSrcIdIntToFloat:
395 return destroy(reinterpret_cast<IrInstSrcIntToFloat *>(inst), name);
390 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcIntToFloat *>(inst));
396391 case IrInstSrcIdFloatToInt:
397 return destroy(reinterpret_cast<IrInstSrcFloatToInt *>(inst), name);
392 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFloatToInt *>(inst));
398393 case IrInstSrcIdBoolToInt:
399 return destroy(reinterpret_cast<IrInstSrcBoolToInt *>(inst), name);
394 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcBoolToInt *>(inst));
400395 case IrInstSrcIdIntType:
401 return destroy(reinterpret_cast<IrInstSrcIntType *>(inst), name);
396 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcIntType *>(inst));
402397 case IrInstSrcIdVectorType:
403 return destroy(reinterpret_cast<IrInstSrcVectorType *>(inst), name);
398 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcVectorType *>(inst));
404399 case IrInstSrcIdShuffleVector:
405 return destroy(reinterpret_cast<IrInstSrcShuffleVector *>(inst), name);
400 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcShuffleVector *>(inst));
406401 case IrInstSrcIdSplat:
407 return destroy(reinterpret_cast<IrInstSrcSplat *>(inst), name);
402 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSplat *>(inst));
408403 case IrInstSrcIdBoolNot:
409 return destroy(reinterpret_cast<IrInstSrcBoolNot *>(inst), name);
404 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcBoolNot *>(inst));
410405 case IrInstSrcIdMemset:
411 return destroy(reinterpret_cast<IrInstSrcMemset *>(inst), name);
406 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcMemset *>(inst));
412407 case IrInstSrcIdMemcpy:
413 return destroy(reinterpret_cast<IrInstSrcMemcpy *>(inst), name);
408 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcMemcpy *>(inst));
414409 case IrInstSrcIdSlice:
415 return destroy(reinterpret_cast<IrInstSrcSlice *>(inst), name);
410 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSlice *>(inst));
416411 case IrInstSrcIdMemberCount:
417 return destroy(reinterpret_cast<IrInstSrcMemberCount *>(inst), name);
412 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcMemberCount *>(inst));
418413 case IrInstSrcIdMemberType:
419 return destroy(reinterpret_cast<IrInstSrcMemberType *>(inst), name);
414 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcMemberType *>(inst));
420415 case IrInstSrcIdMemberName:
421 return destroy(reinterpret_cast<IrInstSrcMemberName *>(inst), name);
416 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcMemberName *>(inst));
422417 case IrInstSrcIdBreakpoint:
423 return destroy(reinterpret_cast<IrInstSrcBreakpoint *>(inst), name);
418 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcBreakpoint *>(inst));
424419 case IrInstSrcIdReturnAddress:
425 return destroy(reinterpret_cast<IrInstSrcReturnAddress *>(inst), name);
420 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcReturnAddress *>(inst));
426421 case IrInstSrcIdFrameAddress:
427 return destroy(reinterpret_cast<IrInstSrcFrameAddress *>(inst), name);
422 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFrameAddress *>(inst));
428423 case IrInstSrcIdFrameHandle:
429 return destroy(reinterpret_cast<IrInstSrcFrameHandle *>(inst), name);
424 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFrameHandle *>(inst));
430425 case IrInstSrcIdFrameType:
431 return destroy(reinterpret_cast<IrInstSrcFrameType *>(inst), name);
426 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFrameType *>(inst));
432427 case IrInstSrcIdFrameSize:
433 return destroy(reinterpret_cast<IrInstSrcFrameSize *>(inst), name);
428 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFrameSize *>(inst));
434429 case IrInstSrcIdAlignOf:
435 return destroy(reinterpret_cast<IrInstSrcAlignOf *>(inst), name);
430 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcAlignOf *>(inst));
436431 case IrInstSrcIdOverflowOp:
437 return destroy(reinterpret_cast<IrInstSrcOverflowOp *>(inst), name);
432 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcOverflowOp *>(inst));
438433 case IrInstSrcIdTestErr:
439 return destroy(reinterpret_cast<IrInstSrcTestErr *>(inst), name);
434 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcTestErr *>(inst));
440435 case IrInstSrcIdUnwrapErrCode:
441 return destroy(reinterpret_cast<IrInstSrcUnwrapErrCode *>(inst), name);
436 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcUnwrapErrCode *>(inst));
442437 case IrInstSrcIdUnwrapErrPayload:
443 return destroy(reinterpret_cast<IrInstSrcUnwrapErrPayload *>(inst), name);
438 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcUnwrapErrPayload *>(inst));
444439 case IrInstSrcIdFnProto:
445 return destroy(reinterpret_cast<IrInstSrcFnProto *>(inst), name);
440 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFnProto *>(inst));
446441 case IrInstSrcIdTestComptime:
447 return destroy(reinterpret_cast<IrInstSrcTestComptime *>(inst), name);
442 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcTestComptime *>(inst));
448443 case IrInstSrcIdPtrCast:
449 return destroy(reinterpret_cast<IrInstSrcPtrCast *>(inst), name);
444 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcPtrCast *>(inst));
450445 case IrInstSrcIdBitCast:
451 return destroy(reinterpret_cast<IrInstSrcBitCast *>(inst), name);
446 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcBitCast *>(inst));
452447 case IrInstSrcIdPtrToInt:
453 return destroy(reinterpret_cast<IrInstSrcPtrToInt *>(inst), name);
448 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcPtrToInt *>(inst));
454449 case IrInstSrcIdIntToPtr:
455 return destroy(reinterpret_cast<IrInstSrcIntToPtr *>(inst), name);
450 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcIntToPtr *>(inst));
456451 case IrInstSrcIdIntToEnum:
457 return destroy(reinterpret_cast<IrInstSrcIntToEnum *>(inst), name);
452 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcIntToEnum *>(inst));
458453 case IrInstSrcIdIntToErr:
459 return destroy(reinterpret_cast<IrInstSrcIntToErr *>(inst), name);
454 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcIntToErr *>(inst));
460455 case IrInstSrcIdErrToInt:
461 return destroy(reinterpret_cast<IrInstSrcErrToInt *>(inst), name);
456 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcErrToInt *>(inst));
462457 case IrInstSrcIdCheckSwitchProngs:
463 return destroy(reinterpret_cast<IrInstSrcCheckSwitchProngs *>(inst), name);
458 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcCheckSwitchProngs *>(inst));
464459 case IrInstSrcIdCheckStatementIsVoid:
465 return destroy(reinterpret_cast<IrInstSrcCheckStatementIsVoid *>(inst), name);
460 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcCheckStatementIsVoid *>(inst));
466461 case IrInstSrcIdTypeName:
467 return destroy(reinterpret_cast<IrInstSrcTypeName *>(inst), name);
462 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcTypeName *>(inst));
468463 case IrInstSrcIdTagName:
469 return destroy(reinterpret_cast<IrInstSrcTagName *>(inst), name);
464 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcTagName *>(inst));
470465 case IrInstSrcIdPtrType:
471 return destroy(reinterpret_cast<IrInstSrcPtrType *>(inst), name);
466 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcPtrType *>(inst));
472467 case IrInstSrcIdDeclRef:
473 return destroy(reinterpret_cast<IrInstSrcDeclRef *>(inst), name);
468 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcDeclRef *>(inst));
474469 case IrInstSrcIdPanic:
475 return destroy(reinterpret_cast<IrInstSrcPanic *>(inst), name);
470 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcPanic *>(inst));
476471 case IrInstSrcIdFieldParentPtr:
477 return destroy(reinterpret_cast<IrInstSrcFieldParentPtr *>(inst), name);
472 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFieldParentPtr *>(inst));
478473 case IrInstSrcIdByteOffsetOf:
479 return destroy(reinterpret_cast<IrInstSrcByteOffsetOf *>(inst), name);
474 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcByteOffsetOf *>(inst));
480475 case IrInstSrcIdBitOffsetOf:
481 return destroy(reinterpret_cast<IrInstSrcBitOffsetOf *>(inst), name);
476 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcBitOffsetOf *>(inst));
482477 case IrInstSrcIdTypeInfo:
483 return destroy(reinterpret_cast<IrInstSrcTypeInfo *>(inst), name);
478 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcTypeInfo *>(inst));
484479 case IrInstSrcIdType:
485 return destroy(reinterpret_cast<IrInstSrcType *>(inst), name);
480 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcType *>(inst));
486481 case IrInstSrcIdHasField:
487 return destroy(reinterpret_cast<IrInstSrcHasField *>(inst), name);
482 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcHasField *>(inst));
488483 case IrInstSrcIdTypeId:
489 return destroy(reinterpret_cast<IrInstSrcTypeId *>(inst), name);
484 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcTypeId *>(inst));
490485 case IrInstSrcIdSetEvalBranchQuota:
491 return destroy(reinterpret_cast<IrInstSrcSetEvalBranchQuota *>(inst), name);
486 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSetEvalBranchQuota *>(inst));
492487 case IrInstSrcIdAlignCast:
493 return destroy(reinterpret_cast<IrInstSrcAlignCast *>(inst), name);
488 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcAlignCast *>(inst));
494489 case IrInstSrcIdImplicitCast:
495 return destroy(reinterpret_cast<IrInstSrcImplicitCast *>(inst), name);
490 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcImplicitCast *>(inst));
496491 case IrInstSrcIdResolveResult:
497 return destroy(reinterpret_cast<IrInstSrcResolveResult *>(inst), name);
492 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcResolveResult *>(inst));
498493 case IrInstSrcIdResetResult:
499 return destroy(reinterpret_cast<IrInstSrcResetResult *>(inst), name);
494 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcResetResult *>(inst));
500495 case IrInstSrcIdOpaqueType:
501 return destroy(reinterpret_cast<IrInstSrcOpaqueType *>(inst), name);
496 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcOpaqueType *>(inst));
502497 case IrInstSrcIdSetAlignStack:
503 return destroy(reinterpret_cast<IrInstSrcSetAlignStack *>(inst), name);
498 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSetAlignStack *>(inst));
504499 case IrInstSrcIdArgType:
505 return destroy(reinterpret_cast<IrInstSrcArgType *>(inst), name);
500 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcArgType *>(inst));
506501 case IrInstSrcIdTagType:
507 return destroy(reinterpret_cast<IrInstSrcTagType *>(inst), name);
502 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcTagType *>(inst));
508503 case IrInstSrcIdExport:
509 return destroy(reinterpret_cast<IrInstSrcExport *>(inst), name);
504 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcExport *>(inst));
510505 case IrInstSrcIdErrorReturnTrace:
511 return destroy(reinterpret_cast<IrInstSrcErrorReturnTrace *>(inst), name);
506 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcErrorReturnTrace *>(inst));
512507 case IrInstSrcIdErrorUnion:
513 return destroy(reinterpret_cast<IrInstSrcErrorUnion *>(inst), name);
508 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcErrorUnion *>(inst));
514509 case IrInstSrcIdAtomicRmw:
515 return destroy(reinterpret_cast<IrInstSrcAtomicRmw *>(inst), name);
510 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcAtomicRmw *>(inst));
516511 case IrInstSrcIdSaveErrRetAddr:
517 return destroy(reinterpret_cast<IrInstSrcSaveErrRetAddr *>(inst), name);
512 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSaveErrRetAddr *>(inst));
518513 case IrInstSrcIdAddImplicitReturnType:
519 return destroy(reinterpret_cast<IrInstSrcAddImplicitReturnType *>(inst), name);
514 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcAddImplicitReturnType *>(inst));
520515 case IrInstSrcIdFloatOp:
521 return destroy(reinterpret_cast<IrInstSrcFloatOp *>(inst), name);
516 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFloatOp *>(inst));
522517 case IrInstSrcIdMulAdd:
523 return destroy(reinterpret_cast<IrInstSrcMulAdd *>(inst), name);
518 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcMulAdd *>(inst));
524519 case IrInstSrcIdAtomicLoad:
525 return destroy(reinterpret_cast<IrInstSrcAtomicLoad *>(inst), name);
520 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcAtomicLoad *>(inst));
526521 case IrInstSrcIdAtomicStore:
527 return destroy(reinterpret_cast<IrInstSrcAtomicStore *>(inst), name);
522 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcAtomicStore *>(inst));
528523 case IrInstSrcIdEnumToInt:
529 return destroy(reinterpret_cast<IrInstSrcEnumToInt *>(inst), name);
524 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcEnumToInt *>(inst));
530525 case IrInstSrcIdCheckRuntimeScope:
531 return destroy(reinterpret_cast<IrInstSrcCheckRuntimeScope *>(inst), name);
526 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcCheckRuntimeScope *>(inst));
532527 case IrInstSrcIdHasDecl:
533 return destroy(reinterpret_cast<IrInstSrcHasDecl *>(inst), name);
528 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcHasDecl *>(inst));
534529 case IrInstSrcIdUndeclaredIdent:
535 return destroy(reinterpret_cast<IrInstSrcUndeclaredIdent *>(inst), name);
530 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcUndeclaredIdent *>(inst));
536531 case IrInstSrcIdAlloca:
537 return destroy(reinterpret_cast<IrInstSrcAlloca *>(inst), name);
532 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcAlloca *>(inst));
538533 case IrInstSrcIdEndExpr:
539 return destroy(reinterpret_cast<IrInstSrcEndExpr *>(inst), name);
534 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcEndExpr *>(inst));
540535 case IrInstSrcIdUnionInitNamedField:
541 return destroy(reinterpret_cast<IrInstSrcUnionInitNamedField *>(inst), name);
536 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcUnionInitNamedField *>(inst));
542537 case IrInstSrcIdSuspendBegin:
543 return destroy(reinterpret_cast<IrInstSrcSuspendBegin *>(inst), name);
538 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSuspendBegin *>(inst));
544539 case IrInstSrcIdSuspendFinish:
545 return destroy(reinterpret_cast<IrInstSrcSuspendFinish *>(inst), name);
540 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSuspendFinish *>(inst));
546541 case IrInstSrcIdResume:
547 return destroy(reinterpret_cast<IrInstSrcResume *>(inst), name);
542 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcResume *>(inst));
548543 case IrInstSrcIdAwait:
549 return destroy(reinterpret_cast<IrInstSrcAwait *>(inst), name);
544 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcAwait *>(inst));
550545 case IrInstSrcIdSpillBegin:
551 return destroy(reinterpret_cast<IrInstSrcSpillBegin *>(inst), name);
546 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSpillBegin *>(inst));
552547 case IrInstSrcIdSpillEnd:
553 return destroy(reinterpret_cast<IrInstSrcSpillEnd *>(inst), name);
548 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSpillEnd *>(inst));
554549 case IrInstSrcIdCallArgs:
555 return destroy(reinterpret_cast<IrInstSrcCallArgs *>(inst), name);
550 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcCallArgs *>(inst));
556551 }
557552 zig_unreachable();
558553}
559554
560555void destroy_instruction_gen(IrInstGen *inst) {
561#ifdef ZIG_ENABLE_MEM_PROFILE
562 const char *name = ir_inst_gen_type_str(inst->id);
563#else
564 const char *name = nullptr;
565#endif
566556 switch (inst->id) {
567557 case IrInstGenIdInvalid:
568558 zig_unreachable();
569559 case IrInstGenIdReturn:
570 return destroy(reinterpret_cast<IrInstGenReturn *>(inst), name);
560 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenReturn *>(inst));
571561 case IrInstGenIdConst:
572 return destroy(reinterpret_cast<IrInstGenConst *>(inst), name);
562 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenConst *>(inst));
573563 case IrInstGenIdBinOp:
574 return destroy(reinterpret_cast<IrInstGenBinOp *>(inst), name);
564 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenBinOp *>(inst));
575565 case IrInstGenIdCast:
576 return destroy(reinterpret_cast<IrInstGenCast *>(inst), name);
566 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenCast *>(inst));
577567 case IrInstGenIdCall:
578 return destroy(reinterpret_cast<IrInstGenCall *>(inst), name);
568 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenCall *>(inst));
579569 case IrInstGenIdCondBr:
580 return destroy(reinterpret_cast<IrInstGenCondBr *>(inst), name);
570 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenCondBr *>(inst));
581571 case IrInstGenIdBr:
582 return destroy(reinterpret_cast<IrInstGenBr *>(inst), name);
572 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenBr *>(inst));
583573 case IrInstGenIdPhi:
584 return destroy(reinterpret_cast<IrInstGenPhi *>(inst), name);
574 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenPhi *>(inst));
585575 case IrInstGenIdUnreachable:
586 return destroy(reinterpret_cast<IrInstGenUnreachable *>(inst), name);
576 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenUnreachable *>(inst));
587577 case IrInstGenIdElemPtr:
588 return destroy(reinterpret_cast<IrInstGenElemPtr *>(inst), name);
578 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenElemPtr *>(inst));
589579 case IrInstGenIdVarPtr:
590 return destroy(reinterpret_cast<IrInstGenVarPtr *>(inst), name);
580 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenVarPtr *>(inst));
591581 case IrInstGenIdReturnPtr:
592 return destroy(reinterpret_cast<IrInstGenReturnPtr *>(inst), name);
582 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenReturnPtr *>(inst));
593583 case IrInstGenIdLoadPtr:
594 return destroy(reinterpret_cast<IrInstGenLoadPtr *>(inst), name);
584 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenLoadPtr *>(inst));
595585 case IrInstGenIdStorePtr:
596 return destroy(reinterpret_cast<IrInstGenStorePtr *>(inst), name);
586 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenStorePtr *>(inst));
597587 case IrInstGenIdVectorStoreElem:
598 return destroy(reinterpret_cast<IrInstGenVectorStoreElem *>(inst), name);
588 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenVectorStoreElem *>(inst));
599589 case IrInstGenIdStructFieldPtr:
600 return destroy(reinterpret_cast<IrInstGenStructFieldPtr *>(inst), name);
590 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenStructFieldPtr *>(inst));
601591 case IrInstGenIdUnionFieldPtr:
602 return destroy(reinterpret_cast<IrInstGenUnionFieldPtr *>(inst), name);
592 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenUnionFieldPtr *>(inst));
603593 case IrInstGenIdAsm:
604 return destroy(reinterpret_cast<IrInstGenAsm *>(inst), name);
594 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenAsm *>(inst));
605595 case IrInstGenIdTestNonNull:
606 return destroy(reinterpret_cast<IrInstGenTestNonNull *>(inst), name);
596 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenTestNonNull *>(inst));
607597 case IrInstGenIdOptionalUnwrapPtr:
608 return destroy(reinterpret_cast<IrInstGenOptionalUnwrapPtr *>(inst), name);
598 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenOptionalUnwrapPtr *>(inst));
609599 case IrInstGenIdPopCount:
610 return destroy(reinterpret_cast<IrInstGenPopCount *>(inst), name);
600 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenPopCount *>(inst));
611601 case IrInstGenIdClz:
612 return destroy(reinterpret_cast<IrInstGenClz *>(inst), name);
602 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenClz *>(inst));
613603 case IrInstGenIdCtz:
614 return destroy(reinterpret_cast<IrInstGenCtz *>(inst), name);
604 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenCtz *>(inst));
615605 case IrInstGenIdBswap:
616 return destroy(reinterpret_cast<IrInstGenBswap *>(inst), name);
606 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenBswap *>(inst));
617607 case IrInstGenIdBitReverse:
618 return destroy(reinterpret_cast<IrInstGenBitReverse *>(inst), name);
608 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenBitReverse *>(inst));
619609 case IrInstGenIdSwitchBr:
620 return destroy(reinterpret_cast<IrInstGenSwitchBr *>(inst), name);
610 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenSwitchBr *>(inst));
621611 case IrInstGenIdUnionTag:
622 return destroy(reinterpret_cast<IrInstGenUnionTag *>(inst), name);
612 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenUnionTag *>(inst));
623613 case IrInstGenIdRef:
624 return destroy(reinterpret_cast<IrInstGenRef *>(inst), name);
614 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenRef *>(inst));
625615 case IrInstGenIdErrName:
626 return destroy(reinterpret_cast<IrInstGenErrName *>(inst), name);
616 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenErrName *>(inst));
627617 case IrInstGenIdCmpxchg:
628 return destroy(reinterpret_cast<IrInstGenCmpxchg *>(inst), name);
618 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenCmpxchg *>(inst));
629619 case IrInstGenIdFence:
630 return destroy(reinterpret_cast<IrInstGenFence *>(inst), name);
620 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenFence *>(inst));
631621 case IrInstGenIdTruncate:
632 return destroy(reinterpret_cast<IrInstGenTruncate *>(inst), name);
622 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenTruncate *>(inst));
633623 case IrInstGenIdShuffleVector:
634 return destroy(reinterpret_cast<IrInstGenShuffleVector *>(inst), name);
624 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenShuffleVector *>(inst));
635625 case IrInstGenIdSplat:
636 return destroy(reinterpret_cast<IrInstGenSplat *>(inst), name);
626 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenSplat *>(inst));
637627 case IrInstGenIdBoolNot:
638 return destroy(reinterpret_cast<IrInstGenBoolNot *>(inst), name);
628 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenBoolNot *>(inst));
639629 case IrInstGenIdMemset:
640 return destroy(reinterpret_cast<IrInstGenMemset *>(inst), name);
630 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenMemset *>(inst));
641631 case IrInstGenIdMemcpy:
642 return destroy(reinterpret_cast<IrInstGenMemcpy *>(inst), name);
632 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenMemcpy *>(inst));
643633 case IrInstGenIdSlice:
644 return destroy(reinterpret_cast<IrInstGenSlice *>(inst), name);
634 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenSlice *>(inst));
645635 case IrInstGenIdBreakpoint:
646 return destroy(reinterpret_cast<IrInstGenBreakpoint *>(inst), name);
636 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenBreakpoint *>(inst));
647637 case IrInstGenIdReturnAddress:
648 return destroy(reinterpret_cast<IrInstGenReturnAddress *>(inst), name);
638 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenReturnAddress *>(inst));
649639 case IrInstGenIdFrameAddress:
650 return destroy(reinterpret_cast<IrInstGenFrameAddress *>(inst), name);
640 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenFrameAddress *>(inst));
651641 case IrInstGenIdFrameHandle:
652 return destroy(reinterpret_cast<IrInstGenFrameHandle *>(inst), name);
642 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenFrameHandle *>(inst));
653643 case IrInstGenIdFrameSize:
654 return destroy(reinterpret_cast<IrInstGenFrameSize *>(inst), name);
644 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenFrameSize *>(inst));
655645 case IrInstGenIdOverflowOp:
656 return destroy(reinterpret_cast<IrInstGenOverflowOp *>(inst), name);
646 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenOverflowOp *>(inst));
657647 case IrInstGenIdTestErr:
658 return destroy(reinterpret_cast<IrInstGenTestErr *>(inst), name);
648 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenTestErr *>(inst));
659649 case IrInstGenIdUnwrapErrCode:
660 return destroy(reinterpret_cast<IrInstGenUnwrapErrCode *>(inst), name);
650 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenUnwrapErrCode *>(inst));
661651 case IrInstGenIdUnwrapErrPayload:
662 return destroy(reinterpret_cast<IrInstGenUnwrapErrPayload *>(inst), name);
652 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenUnwrapErrPayload *>(inst));
663653 case IrInstGenIdOptionalWrap:
664 return destroy(reinterpret_cast<IrInstGenOptionalWrap *>(inst), name);
654 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenOptionalWrap *>(inst));
665655 case IrInstGenIdErrWrapCode:
666 return destroy(reinterpret_cast<IrInstGenErrWrapCode *>(inst), name);
656 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenErrWrapCode *>(inst));
667657 case IrInstGenIdErrWrapPayload:
668 return destroy(reinterpret_cast<IrInstGenErrWrapPayload *>(inst), name);
658 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenErrWrapPayload *>(inst));
669659 case IrInstGenIdPtrCast:
670 return destroy(reinterpret_cast<IrInstGenPtrCast *>(inst), name);
660 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenPtrCast *>(inst));
671661 case IrInstGenIdBitCast:
672 return destroy(reinterpret_cast<IrInstGenBitCast *>(inst), name);
662 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenBitCast *>(inst));
673663 case IrInstGenIdWidenOrShorten:
674 return destroy(reinterpret_cast<IrInstGenWidenOrShorten *>(inst), name);
664 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenWidenOrShorten *>(inst));
675665 case IrInstGenIdPtrToInt:
676 return destroy(reinterpret_cast<IrInstGenPtrToInt *>(inst), name);
666 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenPtrToInt *>(inst));
677667 case IrInstGenIdIntToPtr:
678 return destroy(reinterpret_cast<IrInstGenIntToPtr *>(inst), name);
668 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenIntToPtr *>(inst));
679669 case IrInstGenIdIntToEnum:
680 return destroy(reinterpret_cast<IrInstGenIntToEnum *>(inst), name);
670 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenIntToEnum *>(inst));
681671 case IrInstGenIdIntToErr:
682 return destroy(reinterpret_cast<IrInstGenIntToErr *>(inst), name);
672 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenIntToErr *>(inst));
683673 case IrInstGenIdErrToInt:
684 return destroy(reinterpret_cast<IrInstGenErrToInt *>(inst), name);
674 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenErrToInt *>(inst));
685675 case IrInstGenIdTagName:
686 return destroy(reinterpret_cast<IrInstGenTagName *>(inst), name);
676 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenTagName *>(inst));
687677 case IrInstGenIdPanic:
688 return destroy(reinterpret_cast<IrInstGenPanic *>(inst), name);
678 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenPanic *>(inst));
689679 case IrInstGenIdFieldParentPtr:
690 return destroy(reinterpret_cast<IrInstGenFieldParentPtr *>(inst), name);
680 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenFieldParentPtr *>(inst));
691681 case IrInstGenIdAlignCast:
692 return destroy(reinterpret_cast<IrInstGenAlignCast *>(inst), name);
682 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenAlignCast *>(inst));
693683 case IrInstGenIdErrorReturnTrace:
694 return destroy(reinterpret_cast<IrInstGenErrorReturnTrace *>(inst), name);
684 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenErrorReturnTrace *>(inst));
695685 case IrInstGenIdAtomicRmw:
696 return destroy(reinterpret_cast<IrInstGenAtomicRmw *>(inst), name);
686 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenAtomicRmw *>(inst));
697687 case IrInstGenIdSaveErrRetAddr:
698 return destroy(reinterpret_cast<IrInstGenSaveErrRetAddr *>(inst), name);
688 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenSaveErrRetAddr *>(inst));
699689 case IrInstGenIdFloatOp:
700 return destroy(reinterpret_cast<IrInstGenFloatOp *>(inst), name);
690 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenFloatOp *>(inst));
701691 case IrInstGenIdMulAdd:
702 return destroy(reinterpret_cast<IrInstGenMulAdd *>(inst), name);
692 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenMulAdd *>(inst));
703693 case IrInstGenIdAtomicLoad:
704 return destroy(reinterpret_cast<IrInstGenAtomicLoad *>(inst), name);
694 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenAtomicLoad *>(inst));
705695 case IrInstGenIdAtomicStore:
706 return destroy(reinterpret_cast<IrInstGenAtomicStore *>(inst), name);
696 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenAtomicStore *>(inst));
707697 case IrInstGenIdDeclVar:
708 return destroy(reinterpret_cast<IrInstGenDeclVar *>(inst), name);
698 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenDeclVar *>(inst));
709699 case IrInstGenIdArrayToVector:
710 return destroy(reinterpret_cast<IrInstGenArrayToVector *>(inst), name);
700 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenArrayToVector *>(inst));
711701 case IrInstGenIdVectorToArray:
712 return destroy(reinterpret_cast<IrInstGenVectorToArray *>(inst), name);
702 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenVectorToArray *>(inst));
713703 case IrInstGenIdPtrOfArrayToSlice:
714 return destroy(reinterpret_cast<IrInstGenPtrOfArrayToSlice *>(inst), name);
704 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenPtrOfArrayToSlice *>(inst));
715705 case IrInstGenIdAssertZero:
716 return destroy(reinterpret_cast<IrInstGenAssertZero *>(inst), name);
706 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenAssertZero *>(inst));
717707 case IrInstGenIdAssertNonNull:
718 return destroy(reinterpret_cast<IrInstGenAssertNonNull *>(inst), name);
708 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenAssertNonNull *>(inst));
719709 case IrInstGenIdResizeSlice:
720 return destroy(reinterpret_cast<IrInstGenResizeSlice *>(inst), name);
710 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenResizeSlice *>(inst));
721711 case IrInstGenIdAlloca:
722 return destroy(reinterpret_cast<IrInstGenAlloca *>(inst), name);
712 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenAlloca *>(inst));
723713 case IrInstGenIdSuspendBegin:
724 return destroy(reinterpret_cast<IrInstGenSuspendBegin *>(inst), name);
714 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenSuspendBegin *>(inst));
725715 case IrInstGenIdSuspendFinish:
726 return destroy(reinterpret_cast<IrInstGenSuspendFinish *>(inst), name);
716 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenSuspendFinish *>(inst));
727717 case IrInstGenIdResume:
728 return destroy(reinterpret_cast<IrInstGenResume *>(inst), name);
718 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenResume *>(inst));
729719 case IrInstGenIdAwait:
730 return destroy(reinterpret_cast<IrInstGenAwait *>(inst), name);
720 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenAwait *>(inst));
731721 case IrInstGenIdSpillBegin:
732 return destroy(reinterpret_cast<IrInstGenSpillBegin *>(inst), name);
722 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenSpillBegin *>(inst));
733723 case IrInstGenIdSpillEnd:
734 return destroy(reinterpret_cast<IrInstGenSpillEnd *>(inst), name);
724 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenSpillEnd *>(inst));
735725 case IrInstGenIdVectorExtractElem:
736 return destroy(reinterpret_cast<IrInstGenVectorExtractElem *>(inst), name);
726 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenVectorExtractElem *>(inst));
737727 case IrInstGenIdBinaryNot:
738 return destroy(reinterpret_cast<IrInstGenBinaryNot *>(inst), name);
728 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenBinaryNot *>(inst));
739729 case IrInstGenIdNegation:
740 return destroy(reinterpret_cast<IrInstGenNegation *>(inst), name);
730 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenNegation *>(inst));
741731 case IrInstGenIdNegationWrapping:
742 return destroy(reinterpret_cast<IrInstGenNegationWrapping *>(inst), name);
732 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenNegationWrapping *>(inst));
743733 }
744734 zig_unreachable();
745735}
......@@ -760,15 +750,14 @@ static void ira_deref(IrAnalyze *ira) {
760750 IrInstSrc *pass1_inst = pass1_bb->instruction_list.items[inst_i];
761751 destroy_instruction_src(pass1_inst);
762752 }
763 destroy(pass1_bb, "IrBasicBlockSrc");
753 heap::c_allocator.destroy(pass1_bb);
764754 }
765755 ira->old_irb.exec->basic_block_list.deinit();
766756 ira->old_irb.exec->tld_list.deinit();
767 // cannot destroy here because of var->owner_exec
768 //destroy(ira->old_irb.exec, "IrExecutableSrc");
757 heap::c_allocator.destroy(ira->old_irb.exec);
769758 ira->src_implicit_return_type_list.deinit();
770759 ira->resume_stack.deinit();
771 destroy(ira, "IrAnalyze");
760 heap::c_allocator.destroy(ira);
772761}
773762
774763static ZigValue *const_ptr_pointee_unchecked_no_isf(CodeGen *g, ZigValue *const_val) {
......@@ -1017,8 +1006,8 @@ static void ir_ref_var(ZigVar *var) {
10171006static void create_result_ptr(CodeGen *codegen, ZigType *expected_type,
10181007 ZigValue **out_result, ZigValue **out_result_ptr)
10191008{
1020 ZigValue *result = create_const_vals(1);
1021 ZigValue *result_ptr = create_const_vals(1);
1009 ZigValue *result = codegen->pass1_arena->create<ZigValue>();
1010 ZigValue *result_ptr = codegen->pass1_arena->create<ZigValue>();
10221011 result->special = ConstValSpecialUndef;
10231012 result->type = expected_type;
10241013 result_ptr->special = ConstValSpecialStatic;
......@@ -1050,14 +1039,11 @@ ZigType *ir_analyze_type_expr(IrAnalyze *ira, Scope *scope, AstNode *node) {
10501039 assert(result->special != ConstValSpecialRuntime);
10511040 ZigType *res_type = result->data.x_type;
10521041
1053 destroy(result_ptr, "ZigValue");
1054 destroy(result, "ZigValue");
1055
10561042 return res_type;
10571043}
10581044
10591045static IrBasicBlockSrc *ir_create_basic_block(IrBuilderSrc *irb, Scope *scope, const char *name_hint) {
1060 IrBasicBlockSrc *result = allocate<IrBasicBlockSrc>(1, "IrBasicBlockSrc");
1046 IrBasicBlockSrc *result = heap::c_allocator.create<IrBasicBlockSrc>();
10611047 result->scope = scope;
10621048 result->name_hint = name_hint;
10631049 result->debug_id = exec_next_debug_id(irb->exec);
......@@ -1066,7 +1052,7 @@ static IrBasicBlockSrc *ir_create_basic_block(IrBuilderSrc *irb, Scope *scope, c
10661052}
10671053
10681054static IrBasicBlockGen *ir_create_basic_block_gen(IrAnalyze *ira, Scope *scope, const char *name_hint) {
1069 IrBasicBlockGen *result = allocate<IrBasicBlockGen>(1, "IrBasicBlockGen");
1055 IrBasicBlockGen *result = heap::c_allocator.create<IrBasicBlockGen>();
10701056 result->scope = scope;
10711057 result->name_hint = name_hint;
10721058 result->debug_id = exec_next_debug_id_gen(ira->new_irb.exec);
......@@ -1983,12 +1969,7 @@ static constexpr IrInstGenId ir_inst_id(IrInstGenConst *) {
19831969
19841970template<typename T>
19851971static T *ir_create_instruction(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
1986 const char *name = nullptr;
1987#ifdef ZIG_ENABLE_MEM_PROFILE
1988 T *dummy = nullptr;
1989 name = ir_inst_src_type_str(ir_inst_id(dummy));
1990#endif
1991 T *special_instruction = allocate<T>(1, name);
1972 T *special_instruction = heap::c_allocator.create<T>();
19921973 special_instruction->base.id = ir_inst_id(special_instruction);
19931974 special_instruction->base.base.scope = scope;
19941975 special_instruction->base.base.source_node = source_node;
......@@ -1999,29 +1980,19 @@ static T *ir_create_instruction(IrBuilderSrc *irb, Scope *scope, AstNode *source
19991980
20001981template<typename T>
20011982static T *ir_create_inst_gen(IrBuilderGen *irb, Scope *scope, AstNode *source_node) {
2002 const char *name = nullptr;
2003#ifdef ZIG_ENABLE_MEM_PROFILE
2004 T *dummy = nullptr;
2005 name = ir_inst_gen_type_str(ir_inst_id(dummy));
2006#endif
2007 T *special_instruction = allocate<T>(1, name);
1983 T *special_instruction = heap::c_allocator.create<T>();
20081984 special_instruction->base.id = ir_inst_id(special_instruction);
20091985 special_instruction->base.base.scope = scope;
20101986 special_instruction->base.base.source_node = source_node;
20111987 special_instruction->base.base.debug_id = exec_next_debug_id_gen(irb->exec);
20121988 special_instruction->base.owner_bb = irb->current_basic_block;
2013 special_instruction->base.value = allocate<ZigValue>(1, "ZigValue");
1989 special_instruction->base.value = irb->codegen->pass1_arena->create<ZigValue>();
20141990 return special_instruction;
20151991}
20161992
20171993template<typename T>
20181994static T *ir_create_inst_noval(IrBuilderGen *irb, Scope *scope, AstNode *source_node) {
2019 const char *name = nullptr;
2020#ifdef ZIG_ENABLE_MEM_PROFILE
2021 T *dummy = nullptr;
2022 name = ir_inst_gen_type_str(ir_inst_id(dummy));
2023#endif
2024 T *special_instruction = allocate<T>(1, name);
1995 T *special_instruction = heap::c_allocator.create<T>();
20251996 special_instruction->base.id = ir_inst_id(special_instruction);
20261997 special_instruction->base.base.scope = scope;
20271998 special_instruction->base.base.source_node = source_node;
......@@ -2063,11 +2034,11 @@ static T *ir_build_inst_void(IrBuilderGen *irb, Scope *scope, AstNode *source_no
20632034IrInstGen *ir_create_alloca(CodeGen *g, Scope *scope, AstNode *source_node, ZigFn *fn,
20642035 ZigType *var_type, const char *name_hint)
20652036{
2066 IrInstGenAlloca *alloca_gen = allocate<IrInstGenAlloca>(1);
2037 IrInstGenAlloca *alloca_gen = heap::c_allocator.create<IrInstGenAlloca>();
20672038 alloca_gen->base.id = IrInstGenIdAlloca;
20682039 alloca_gen->base.base.source_node = source_node;
20692040 alloca_gen->base.base.scope = scope;
2070 alloca_gen->base.value = allocate<ZigValue>(1, "ZigValue");
2041 alloca_gen->base.value = g->pass1_arena->create<ZigValue>();
20712042 alloca_gen->base.value->type = get_pointer_to_type(g, var_type, false);
20722043 alloca_gen->base.base.ref_count = 1;
20732044 alloca_gen->name_hint = name_hint;
......@@ -2157,7 +2128,7 @@ static IrInstSrc *ir_build_const_undefined(IrBuilderSrc *irb, Scope *scope, AstN
21572128
21582129static IrInstSrc *ir_build_const_uint(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, uint64_t value) {
21592130 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
2160 const_instruction->value = create_const_vals(1);
2131 const_instruction->value = irb->codegen->pass1_arena->create<ZigValue>();
21612132 const_instruction->value->type = irb->codegen->builtin_types.entry_num_lit_int;
21622133 const_instruction->value->special = ConstValSpecialStatic;
21632134 bigint_init_unsigned(&const_instruction->value->data.x_bigint, value);
......@@ -2166,7 +2137,7 @@ static IrInstSrc *ir_build_const_uint(IrBuilderSrc *irb, Scope *scope, AstNode *
21662137
21672138static IrInstSrc *ir_build_const_bigint(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, BigInt *bigint) {
21682139 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
2169 const_instruction->value = create_const_vals(1);
2140 const_instruction->value = irb->codegen->pass1_arena->create<ZigValue>();
21702141 const_instruction->value->type = irb->codegen->builtin_types.entry_num_lit_int;
21712142 const_instruction->value->special = ConstValSpecialStatic;
21722143 bigint_init_bigint(&const_instruction->value->data.x_bigint, bigint);
......@@ -2175,7 +2146,7 @@ static IrInstSrc *ir_build_const_bigint(IrBuilderSrc *irb, Scope *scope, AstNode
21752146
21762147static IrInstSrc *ir_build_const_bigfloat(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, BigFloat *bigfloat) {
21772148 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
2178 const_instruction->value = create_const_vals(1);
2149 const_instruction->value = irb->codegen->pass1_arena->create<ZigValue>();
21792150 const_instruction->value->type = irb->codegen->builtin_types.entry_num_lit_float;
21802151 const_instruction->value->special = ConstValSpecialStatic;
21812152 bigfloat_init_bigfloat(&const_instruction->value->data.x_bigfloat, bigfloat);
......@@ -2191,7 +2162,7 @@ static IrInstSrc *ir_build_const_null(IrBuilderSrc *irb, Scope *scope, AstNode *
21912162
21922163static IrInstSrc *ir_build_const_usize(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, uint64_t value) {
21932164 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
2194 const_instruction->value = create_const_vals(1);
2165 const_instruction->value = irb->codegen->pass1_arena->create<ZigValue>();
21952166 const_instruction->value->type = irb->codegen->builtin_types.entry_usize;
21962167 const_instruction->value->special = ConstValSpecialStatic;
21972168 bigint_init_unsigned(&const_instruction->value->data.x_bigint, value);
......@@ -2202,7 +2173,7 @@ static IrInstSrc *ir_create_const_type(IrBuilderSrc *irb, Scope *scope, AstNode
22022173 ZigType *type_entry)
22032174{
22042175 IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node);
2205 const_instruction->value = create_const_vals(1);
2176 const_instruction->value = irb->codegen->pass1_arena->create<ZigValue>();
22062177 const_instruction->value->type = irb->codegen->builtin_types.entry_type;
22072178 const_instruction->value->special = ConstValSpecialStatic;
22082179 const_instruction->value->data.x_type = type_entry;
......@@ -2219,7 +2190,7 @@ static IrInstSrc *ir_build_const_type(IrBuilderSrc *irb, Scope *scope, AstNode *
22192190
22202191static IrInstSrc *ir_build_const_import(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, ZigType *import) {
22212192 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
2222 const_instruction->value = create_const_vals(1);
2193 const_instruction->value = irb->codegen->pass1_arena->create<ZigValue>();
22232194 const_instruction->value->type = irb->codegen->builtin_types.entry_type;
22242195 const_instruction->value->special = ConstValSpecialStatic;
22252196 const_instruction->value->data.x_type = import;
......@@ -2228,7 +2199,7 @@ static IrInstSrc *ir_build_const_import(IrBuilderSrc *irb, Scope *scope, AstNode
22282199
22292200static IrInstSrc *ir_build_const_bool(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, bool value) {
22302201 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
2231 const_instruction->value = create_const_vals(1);
2202 const_instruction->value = irb->codegen->pass1_arena->create<ZigValue>();
22322203 const_instruction->value->type = irb->codegen->builtin_types.entry_bool;
22332204 const_instruction->value->special = ConstValSpecialStatic;
22342205 const_instruction->value->data.x_bool = value;
......@@ -2237,7 +2208,7 @@ static IrInstSrc *ir_build_const_bool(IrBuilderSrc *irb, Scope *scope, AstNode *
22372208
22382209static IrInstSrc *ir_build_const_enum_literal(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Buf *name) {
22392210 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
2240 const_instruction->value = create_const_vals(1);
2211 const_instruction->value = irb->codegen->pass1_arena->create<ZigValue>();
22412212 const_instruction->value->type = irb->codegen->builtin_types.entry_enum_literal;
22422213 const_instruction->value->special = ConstValSpecialStatic;
22432214 const_instruction->value->data.x_enum_literal = name;
......@@ -2246,7 +2217,7 @@ static IrInstSrc *ir_build_const_enum_literal(IrBuilderSrc *irb, Scope *scope, A
22462217
22472218static IrInstSrc *ir_create_const_str_lit(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Buf *str) {
22482219 IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node);
2249 const_instruction->value = create_const_vals(1);
2220 const_instruction->value = irb->codegen->pass1_arena->create<ZigValue>();
22502221 init_const_str_lit(irb->codegen, const_instruction->value, str);
22512222
22522223 return &const_instruction->base;
......@@ -5244,7 +5215,7 @@ static IrInstSrc *ir_gen_return(IrBuilderSrc *irb, Scope *scope, AstNode *node,
52445215 switch (node->data.return_expr.kind) {
52455216 case ReturnKindUnconditional:
52465217 {
5247 ResultLocReturn *result_loc_ret = allocate<ResultLocReturn>(1, "ResultLocReturn");
5218 ResultLocReturn *result_loc_ret = heap::c_allocator.create<ResultLocReturn>();
52485219 result_loc_ret->base.id = ResultLocIdReturn;
52495220 ir_build_reset_result(irb, scope, node, &result_loc_ret->base);
52505221
......@@ -5332,7 +5303,7 @@ static IrInstSrc *ir_gen_return(IrBuilderSrc *irb, Scope *scope, AstNode *node,
53325303 ir_mark_gen(ir_build_add_implicit_return_type(irb, scope, node, err_val, nullptr));
53335304 IrInstSrcSpillBegin *spill_begin = ir_build_spill_begin_src(irb, scope, node, err_val,
53345305 SpillIdRetErrCode);
5335 ResultLocReturn *result_loc_ret = allocate<ResultLocReturn>(1, "ResultLocReturn");
5306 ResultLocReturn *result_loc_ret = heap::c_allocator.create<ResultLocReturn>();
53365307 result_loc_ret->base.id = ResultLocIdReturn;
53375308 ir_build_reset_result(irb, scope, node, &result_loc_ret->base);
53385309 ir_build_end_expr(irb, scope, node, err_val, &result_loc_ret->base);
......@@ -5360,12 +5331,12 @@ static ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_s
53605331 Buf *name, bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstSrc *is_comptime,
53615332 bool skip_name_check)
53625333{
5363 ZigVar *variable_entry = allocate<ZigVar>(1, "ZigVar");
5334 ZigVar *variable_entry = heap::c_allocator.create<ZigVar>();
53645335 variable_entry->parent_scope = parent_scope;
53655336 variable_entry->shadowable = is_shadowable;
53665337 variable_entry->is_comptime = is_comptime;
53675338 variable_entry->src_arg_index = SIZE_MAX;
5368 variable_entry->const_value = create_const_vals(1);
5339 variable_entry->const_value = codegen->pass1_arena->create<ZigValue>();
53695340
53705341 if (is_comptime != nullptr) {
53715342 is_comptime->base.ref_count += 1;
......@@ -5425,15 +5396,12 @@ static ZigVar *ir_create_var(IrBuilderSrc *irb, AstNode *node, Scope *scope, Buf
54255396 ZigVar *var = create_local_var(irb->codegen, node, scope,
54265397 (is_underscored ? nullptr : name), src_is_const, gen_is_const,
54275398 (is_underscored ? true : is_shadowable), is_comptime, false);
5428 if (is_comptime != nullptr || gen_is_const) {
5429 var->owner_exec = irb->exec;
5430 }
54315399 assert(var->child_scope);
54325400 return var;
54335401}
54345402
54355403static ResultLocPeer *create_peer_result(ResultLocPeerParent *peer_parent) {
5436 ResultLocPeer *result = allocate<ResultLocPeer>(1, "ResultLocPeer");
5404 ResultLocPeer *result = heap::c_allocator.create<ResultLocPeer>();
54375405 result->base.id = ResultLocIdPeer;
54385406 result->base.source_instruction = peer_parent->base.source_instruction;
54395407 result->parent = peer_parent;
......@@ -5472,7 +5440,7 @@ static IrInstSrc *ir_gen_block(IrBuilderSrc *irb, Scope *parent_scope, AstNode *
54725440 scope_block->is_comptime = ir_build_const_bool(irb, parent_scope, block_node,
54735441 ir_should_inline(irb->exec, parent_scope));
54745442
5475 scope_block->peer_parent = allocate<ResultLocPeerParent>(1, "ResultLocPeerParent");
5443 scope_block->peer_parent = heap::c_allocator.create<ResultLocPeerParent>();
54765444 scope_block->peer_parent->base.id = ResultLocIdPeerParent;
54775445 scope_block->peer_parent->base.source_instruction = scope_block->is_comptime;
54785446 scope_block->peer_parent->base.allow_write_through_const = result_loc->allow_write_through_const;
......@@ -5562,7 +5530,7 @@ static IrInstSrc *ir_gen_block(IrBuilderSrc *irb, Scope *parent_scope, AstNode *
55625530 // only generate unconditional defers
55635531
55645532 ir_mark_gen(ir_build_add_implicit_return_type(irb, child_scope, block_node, result, nullptr));
5565 ResultLocReturn *result_loc_ret = allocate<ResultLocReturn>(1, "ResultLocReturn");
5533 ResultLocReturn *result_loc_ret = heap::c_allocator.create<ResultLocReturn>();
55665534 result_loc_ret->base.id = ResultLocIdReturn;
55675535 ir_build_reset_result(irb, parent_scope, block_node, &result_loc_ret->base);
55685536 ir_mark_gen(ir_build_end_expr(irb, parent_scope, block_node, result, &result_loc_ret->base));
......@@ -5604,7 +5572,7 @@ static IrInstSrc *ir_gen_assign(IrBuilderSrc *irb, Scope *scope, AstNode *node)
56045572 if (lvalue == irb->codegen->invalid_inst_src)
56055573 return irb->codegen->invalid_inst_src;
56065574
5607 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1, "ResultLocInstruction");
5575 ResultLocInstruction *result_loc_inst = heap::c_allocator.create<ResultLocInstruction>();
56085576 result_loc_inst->base.id = ResultLocIdInstruction;
56095577 result_loc_inst->base.source_instruction = lvalue;
56105578 ir_ref_instruction(lvalue, irb->current_basic_block);
......@@ -5676,10 +5644,10 @@ static IrInstSrc *ir_gen_bool_or(IrBuilderSrc *irb, Scope *scope, AstNode *node)
56765644
56775645 ir_set_cursor_at_end_and_append_block(irb, true_block);
56785646
5679 IrInstSrc **incoming_values = allocate<IrInstSrc *>(2, "IrInstSrc *");
5647 IrInstSrc **incoming_values = heap::c_allocator.allocate<IrInstSrc *>(2);
56805648 incoming_values[0] = val1;
56815649 incoming_values[1] = val2;
5682 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");
5650 IrBasicBlockSrc **incoming_blocks = heap::c_allocator.allocate<IrBasicBlockSrc *>(2);
56835651 incoming_blocks[0] = post_val1_block;
56845652 incoming_blocks[1] = post_val2_block;
56855653
......@@ -5718,10 +5686,10 @@ static IrInstSrc *ir_gen_bool_and(IrBuilderSrc *irb, Scope *scope, AstNode *node
57185686
57195687 ir_set_cursor_at_end_and_append_block(irb, false_block);
57205688
5721 IrInstSrc **incoming_values = allocate<IrInstSrc *>(2);
5689 IrInstSrc **incoming_values = heap::c_allocator.allocate<IrInstSrc *>(2);
57225690 incoming_values[0] = val1;
57235691 incoming_values[1] = val2;
5724 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");
5692 IrBasicBlockSrc **incoming_blocks = heap::c_allocator.allocate<IrBasicBlockSrc *>(2);
57255693 incoming_blocks[0] = post_val1_block;
57265694 incoming_blocks[1] = post_val2_block;
57275695
......@@ -5731,7 +5699,7 @@ static IrInstSrc *ir_gen_bool_and(IrBuilderSrc *irb, Scope *scope, AstNode *node
57315699static ResultLocPeerParent *ir_build_result_peers(IrBuilderSrc *irb, IrInstSrc *cond_br_inst,
57325700 IrBasicBlockSrc *end_block, ResultLoc *parent, IrInstSrc *is_comptime)
57335701{
5734 ResultLocPeerParent *peer_parent = allocate<ResultLocPeerParent>(1);
5702 ResultLocPeerParent *peer_parent = heap::c_allocator.create<ResultLocPeerParent>();
57355703 peer_parent->base.id = ResultLocIdPeerParent;
57365704 peer_parent->base.source_instruction = cond_br_inst;
57375705 peer_parent->base.allow_write_through_const = parent->allow_write_through_const;
......@@ -5809,10 +5777,10 @@ static IrInstSrc *ir_gen_orelse(IrBuilderSrc *irb, Scope *parent_scope, AstNode
58095777 ir_build_br(irb, parent_scope, node, end_block, is_comptime);
58105778
58115779 ir_set_cursor_at_end_and_append_block(irb, end_block);
5812 IrInstSrc **incoming_values = allocate<IrInstSrc *>(2);
5780 IrInstSrc **incoming_values = heap::c_allocator.allocate<IrInstSrc *>(2);
58135781 incoming_values[0] = null_result;
58145782 incoming_values[1] = unwrapped_payload;
5815 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");
5783 IrBasicBlockSrc **incoming_blocks = heap::c_allocator.allocate<IrBasicBlockSrc *>(2);
58165784 incoming_blocks[0] = after_null_block;
58175785 incoming_blocks[1] = after_ok_block;
58185786 IrInstSrc *phi = ir_build_phi(irb, parent_scope, node, 2, incoming_blocks, incoming_values, peer_parent);
......@@ -5966,7 +5934,7 @@ static void populate_invalid_variable_in_scope(CodeGen *g, Scope *scope, AstNode
59665934 }
59675935 scope = scope->parent;
59685936 }
5969 TldVar *tld_var = allocate<TldVar>(1);
5937 TldVar *tld_var = heap::c_allocator.create<TldVar>();
59705938 init_tld(&tld_var->base, TldIdVar, var_name, VisibModPub, node, &scope_decls->base);
59715939 tld_var->base.resolution = TldResolutionInvalid;
59725940 tld_var->var = add_variable(g, node, &scope_decls->base, var_name, false,
......@@ -5983,7 +5951,7 @@ static IrInstSrc *ir_gen_symbol(IrBuilderSrc *irb, Scope *scope, AstNode *node,
59835951 if (buf_eql_str(variable_name, "_")) {
59845952 if (lval == LValPtr) {
59855953 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, node);
5986 const_instruction->value = create_const_vals(1);
5954 const_instruction->value = irb->codegen->pass1_arena->create<ZigValue>();
59875955 const_instruction->value->type = get_pointer_to_type(irb->codegen,
59885956 irb->codegen->builtin_types.entry_void, false);
59895957 const_instruction->value->special = ConstValSpecialStatic;
......@@ -6177,7 +6145,7 @@ static IrInstSrc *ir_gen_async_call(IrBuilderSrc *irb, Scope *scope, AstNode *aw
61776145 return fn_ref;
61786146
61796147 size_t arg_count = call_node->data.fn_call_expr.params.length - arg_offset;
6180 IrInstSrc **args = allocate<IrInstSrc*>(arg_count);
6148 IrInstSrc **args = heap::c_allocator.allocate<IrInstSrc*>(arg_count);
61816149 for (size_t i = 0; i < arg_count; i += 1) {
61826150 AstNode *arg_node = call_node->data.fn_call_expr.params.at(i + arg_offset);
61836151 IrInstSrc *arg = ir_gen_node(irb, arg_node, scope);
......@@ -6203,7 +6171,7 @@ static IrInstSrc *ir_gen_fn_call_with_args(IrBuilderSrc *irb, Scope *scope, AstN
62036171
62046172 IrInstSrc *fn_type = ir_build_typeof(irb, scope, source_node, fn_ref);
62056173
6206 IrInstSrc **args = allocate<IrInstSrc*>(args_len);
6174 IrInstSrc **args = heap::c_allocator.allocate<IrInstSrc*>(args_len);
62076175 for (size_t i = 0; i < args_len; i += 1) {
62086176 AstNode *arg_node = args_ptr[i];
62096177
......@@ -6388,7 +6356,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod
63886356 }
63896357 case BuiltinFnIdCompileLog:
63906358 {
6391 IrInstSrc **args = allocate<IrInstSrc*>(actual_param_count);
6359 IrInstSrc **args = heap::c_allocator.allocate<IrInstSrc*>(actual_param_count);
63926360
63936361 for (size_t i = 0; i < actual_param_count; i += 1) {
63946362 AstNode *arg_node = node->data.fn_call_expr.params.at(i);
......@@ -7013,7 +6981,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod
70136981 if (dest_type == irb->codegen->invalid_inst_src)
70146982 return dest_type;
70156983
7016 ResultLocBitCast *result_loc_bit_cast = allocate<ResultLocBitCast>(1);
6984 ResultLocBitCast *result_loc_bit_cast = heap::c_allocator.create<ResultLocBitCast>();
70176985 result_loc_bit_cast->base.id = ResultLocIdBitCast;
70186986 result_loc_bit_cast->base.source_instruction = dest_type;
70196987 result_loc_bit_cast->base.allow_write_through_const = result_loc->allow_write_through_const;
......@@ -7166,7 +7134,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod
71667134
71677135 size_t arg_count = node->data.fn_call_expr.params.length - 2;
71687136
7169 IrInstSrc **args = allocate<IrInstSrc*>(arg_count);
7137 IrInstSrc **args = heap::c_allocator.allocate<IrInstSrc*>(arg_count);
71707138 for (size_t i = 0; i < arg_count; i += 1) {
71717139 AstNode *arg_node = node->data.fn_call_expr.params.at(i + 2);
71727140 args[i] = ir_gen_node(irb, arg_node, scope);
......@@ -7595,10 +7563,10 @@ static IrInstSrc *ir_gen_if_bool_expr(IrBuilderSrc *irb, Scope *scope, AstNode *
75957563 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));
75967564
75977565 ir_set_cursor_at_end_and_append_block(irb, endif_block);
7598 IrInstSrc **incoming_values = allocate<IrInstSrc *>(2);
7566 IrInstSrc **incoming_values = heap::c_allocator.allocate<IrInstSrc *>(2);
75997567 incoming_values[0] = then_expr_result;
76007568 incoming_values[1] = else_expr_result;
7601 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");
7569 IrBasicBlockSrc **incoming_blocks = heap::c_allocator.allocate<IrBasicBlockSrc *>(2);
76027570 incoming_blocks[0] = after_then_block;
76037571 incoming_blocks[1] = after_else_block;
76047572
......@@ -7799,7 +7767,7 @@ static IrInstSrc *ir_gen_union_init_expr(IrBuilderSrc *irb, Scope *scope, AstNod
77997767 IrInstSrc *field_ptr = ir_build_field_ptr_instruction(irb, scope, source_node, container_ptr,
78007768 field_name, true);
78017769
7802 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1);
7770 ResultLocInstruction *result_loc_inst = heap::c_allocator.create<ResultLocInstruction>();
78037771 result_loc_inst->base.id = ResultLocIdInstruction;
78047772 result_loc_inst->base.source_instruction = field_ptr;
78057773 ir_ref_instruction(field_ptr, irb->current_basic_block);
......@@ -7875,7 +7843,7 @@ static IrInstSrc *ir_gen_container_init_expr(IrBuilderSrc *irb, Scope *scope, As
78757843 nullptr);
78767844
78777845 size_t field_count = container_init_expr->entries.length;
7878 IrInstSrcContainerInitFieldsField *fields = allocate<IrInstSrcContainerInitFieldsField>(field_count);
7846 IrInstSrcContainerInitFieldsField *fields = heap::c_allocator.allocate<IrInstSrcContainerInitFieldsField>(field_count);
78797847 for (size_t i = 0; i < field_count; i += 1) {
78807848 AstNode *entry_node = container_init_expr->entries.at(i);
78817849 assert(entry_node->type == NodeTypeStructValueField);
......@@ -7884,7 +7852,7 @@ static IrInstSrc *ir_gen_container_init_expr(IrBuilderSrc *irb, Scope *scope, As
78847852 AstNode *expr_node = entry_node->data.struct_val_field.expr;
78857853
78867854 IrInstSrc *field_ptr = ir_build_field_ptr(irb, scope, entry_node, container_ptr, name, true);
7887 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1);
7855 ResultLocInstruction *result_loc_inst = heap::c_allocator.create<ResultLocInstruction>();
78887856 result_loc_inst->base.id = ResultLocIdInstruction;
78897857 result_loc_inst->base.source_instruction = field_ptr;
78907858 result_loc_inst->base.allow_write_through_const = true;
......@@ -7914,14 +7882,14 @@ static IrInstSrc *ir_gen_container_init_expr(IrBuilderSrc *irb, Scope *scope, As
79147882 IrInstSrc *container_ptr = ir_build_resolve_result(irb, scope, node, child_result_loc,
79157883 nullptr);
79167884
7917 IrInstSrc **result_locs = allocate<IrInstSrc *>(item_count);
7885 IrInstSrc **result_locs = heap::c_allocator.allocate<IrInstSrc *>(item_count);
79187886 for (size_t i = 0; i < item_count; i += 1) {
79197887 AstNode *expr_node = container_init_expr->entries.at(i);
79207888
79217889 IrInstSrc *elem_index = ir_build_const_usize(irb, scope, expr_node, i);
79227890 IrInstSrc *elem_ptr = ir_build_elem_ptr(irb, scope, expr_node, container_ptr,
79237891 elem_index, false, PtrLenSingle, init_array_type_source_node);
7924 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1);
7892 ResultLocInstruction *result_loc_inst = heap::c_allocator.create<ResultLocInstruction>();
79257893 result_loc_inst->base.id = ResultLocIdInstruction;
79267894 result_loc_inst->base.source_instruction = elem_ptr;
79277895 result_loc_inst->base.allow_write_through_const = true;
......@@ -7947,7 +7915,7 @@ static IrInstSrc *ir_gen_container_init_expr(IrBuilderSrc *irb, Scope *scope, As
79477915}
79487916
79497917static ResultLocVar *ir_build_var_result_loc(IrBuilderSrc *irb, IrInstSrc *alloca, ZigVar *var) {
7950 ResultLocVar *result_loc_var = allocate<ResultLocVar>(1);
7918 ResultLocVar *result_loc_var = heap::c_allocator.create<ResultLocVar>();
79517919 result_loc_var->base.id = ResultLocIdVar;
79527920 result_loc_var->base.source_instruction = alloca;
79537921 result_loc_var->base.allow_write_through_const = true;
......@@ -7961,7 +7929,7 @@ static ResultLocVar *ir_build_var_result_loc(IrBuilderSrc *irb, IrInstSrc *alloc
79617929static ResultLocCast *ir_build_cast_result_loc(IrBuilderSrc *irb, IrInstSrc *dest_type,
79627930 ResultLoc *parent_result_loc)
79637931{
7964 ResultLocCast *result_loc_cast = allocate<ResultLocCast>(1);
7932 ResultLocCast *result_loc_cast = heap::c_allocator.create<ResultLocCast>();
79657933 result_loc_cast->base.id = ResultLocIdCast;
79667934 result_loc_cast->base.source_instruction = dest_type;
79677935 result_loc_cast->base.allow_write_through_const = parent_result_loc->allow_write_through_const;
......@@ -8804,9 +8772,9 @@ static IrInstSrc *ir_gen_asm_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node
88048772 nullptr, 0, is_volatile, true);
88058773 }
88068774
8807 IrInstSrc **input_list = allocate<IrInstSrc *>(asm_expr->input_list.length);
8808 IrInstSrc **output_types = allocate<IrInstSrc *>(asm_expr->output_list.length);
8809 ZigVar **output_vars = allocate<ZigVar *>(asm_expr->output_list.length);
8775 IrInstSrc **input_list = heap::c_allocator.allocate<IrInstSrc *>(asm_expr->input_list.length);
8776 IrInstSrc **output_types = heap::c_allocator.allocate<IrInstSrc *>(asm_expr->output_list.length);
8777 ZigVar **output_vars = heap::c_allocator.allocate<ZigVar *>(asm_expr->output_list.length);
88108778 size_t return_count = 0;
88118779 if (!is_volatile && asm_expr->output_list.length == 0) {
88128780 add_node_error(irb->codegen, node,
......@@ -8940,10 +8908,10 @@ static IrInstSrc *ir_gen_if_optional_expr(IrBuilderSrc *irb, Scope *scope, AstNo
89408908 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));
89418909
89428910 ir_set_cursor_at_end_and_append_block(irb, endif_block);
8943 IrInstSrc **incoming_values = allocate<IrInstSrc *>(2);
8911 IrInstSrc **incoming_values = heap::c_allocator.allocate<IrInstSrc *>(2);
89448912 incoming_values[0] = then_expr_result;
89458913 incoming_values[1] = else_expr_result;
8946 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");
8914 IrBasicBlockSrc **incoming_blocks = heap::c_allocator.allocate<IrBasicBlockSrc *>(2);
89478915 incoming_blocks[0] = after_then_block;
89488916 incoming_blocks[1] = after_else_block;
89498917
......@@ -9037,10 +9005,10 @@ static IrInstSrc *ir_gen_if_err_expr(IrBuilderSrc *irb, Scope *scope, AstNode *n
90379005 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));
90389006
90399007 ir_set_cursor_at_end_and_append_block(irb, endif_block);
9040 IrInstSrc **incoming_values = allocate<IrInstSrc *>(2);
9008 IrInstSrc **incoming_values = heap::c_allocator.allocate<IrInstSrc *>(2);
90419009 incoming_values[0] = then_expr_result;
90429010 incoming_values[1] = else_expr_result;
9043 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");
9011 IrBasicBlockSrc **incoming_blocks = heap::c_allocator.allocate<IrBasicBlockSrc *>(2);
90449012 incoming_blocks[0] = after_then_block;
90459013 incoming_blocks[1] = after_else_block;
90469014
......@@ -9133,7 +9101,7 @@ static IrInstSrc *ir_gen_switch_expr(IrBuilderSrc *irb, Scope *scope, AstNode *n
91339101
91349102 IrInstSrcSwitchElseVar *switch_else_var = nullptr;
91359103
9136 ResultLocPeerParent *peer_parent = allocate<ResultLocPeerParent>(1);
9104 ResultLocPeerParent *peer_parent = heap::c_allocator.create<ResultLocPeerParent>();
91379105 peer_parent->base.id = ResultLocIdPeerParent;
91389106 peer_parent->base.allow_write_through_const = result_loc->allow_write_through_const;
91399107 peer_parent->end_bb = end_block;
......@@ -9295,7 +9263,7 @@ static IrInstSrc *ir_gen_switch_expr(IrBuilderSrc *irb, Scope *scope, AstNode *n
92959263 ResultLocPeer *this_peer_result_loc = create_peer_result(peer_parent);
92969264
92979265 IrBasicBlockSrc *prong_block = ir_create_basic_block(irb, scope, "SwitchProng");
9298 IrInstSrc **items = allocate<IrInstSrc *>(prong_item_count);
9266 IrInstSrc **items = heap::c_allocator.allocate<IrInstSrc *>(prong_item_count);
92999267
93009268 for (size_t item_i = 0; item_i < prong_item_count; item_i += 1) {
93019269 AstNode *item_node = prong_node->data.switch_prong.items.at(item_i);
......@@ -9677,10 +9645,10 @@ static IrInstSrc *ir_gen_catch(IrBuilderSrc *irb, Scope *parent_scope, AstNode *
96779645 ir_build_br(irb, parent_scope, node, end_block, is_comptime);
96789646
96799647 ir_set_cursor_at_end_and_append_block(irb, end_block);
9680 IrInstSrc **incoming_values = allocate<IrInstSrc *>(2);
9648 IrInstSrc **incoming_values = heap::c_allocator.allocate<IrInstSrc *>(2);
96819649 incoming_values[0] = err_result;
96829650 incoming_values[1] = unwrapped_payload;
9683 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");
9651 IrBasicBlockSrc **incoming_blocks = heap::c_allocator.allocate<IrBasicBlockSrc *>(2);
96849652 incoming_blocks[0] = after_err_block;
96859653 incoming_blocks[1] = after_ok_block;
96869654 IrInstSrc *phi = ir_build_phi(irb, parent_scope, node, 2, incoming_blocks, incoming_values, peer_parent);
......@@ -9747,7 +9715,7 @@ static IrInstSrc *ir_gen_container_decl(IrBuilderSrc *irb, Scope *parent_scope,
97479715 scan_decls(irb->codegen, child_scope, child_node);
97489716 }
97499717
9750 TldContainer *tld_container = allocate<TldContainer>(1);
9718 TldContainer *tld_container = heap::c_allocator.create<TldContainer>();
97519719 init_tld(&tld_container->base, TldIdContainer, bare_name, VisibModPub, node, parent_scope);
97529720 tld_container->type_entry = container_type;
97539721 tld_container->decls_scope = child_scope;
......@@ -9790,7 +9758,7 @@ static ZigType *get_error_set_union(CodeGen *g, ErrorTableEntry **errors, ZigTyp
97909758 }
97919759
97929760 err_set_type->data.error_set.err_count = count;
9793 err_set_type->data.error_set.errors = allocate<ErrorTableEntry *>(count);
9761 err_set_type->data.error_set.errors = heap::c_allocator.allocate<ErrorTableEntry *>(count);
97949762
97959763 bool need_comma = false;
97969764 for (uint32_t i = 0; i < set1->data.error_set.err_count; i += 1) {
......@@ -9837,7 +9805,7 @@ static ZigType *make_err_set_with_one_item(CodeGen *g, Scope *parent_scope, AstN
98379805 err_set_type->abi_align = g->builtin_types.entry_global_error_set->abi_align;
98389806 err_set_type->abi_size = g->builtin_types.entry_global_error_set->abi_size;
98399807 err_set_type->data.error_set.err_count = 1;
9840 err_set_type->data.error_set.errors = allocate<ErrorTableEntry *>(1);
9808 err_set_type->data.error_set.errors = heap::c_allocator.create<ErrorTableEntry *>();
98419809
98429810 err_set_type->data.error_set.errors[0] = err_entry;
98439811
......@@ -9868,16 +9836,16 @@ static IrInstSrc *ir_gen_err_set_decl(IrBuilderSrc *irb, Scope *parent_scope, As
98689836 err_set_type->size_in_bits = irb->codegen->builtin_types.entry_global_error_set->size_in_bits;
98699837 err_set_type->abi_align = irb->codegen->builtin_types.entry_global_error_set->abi_align;
98709838 err_set_type->abi_size = irb->codegen->builtin_types.entry_global_error_set->abi_size;
9871 err_set_type->data.error_set.errors = allocate<ErrorTableEntry *>(err_count);
9839 err_set_type->data.error_set.errors = heap::c_allocator.allocate<ErrorTableEntry *>(err_count);
98729840
98739841 size_t errors_count = irb->codegen->errors_by_index.length + err_count;
9874 ErrorTableEntry **errors = allocate<ErrorTableEntry *>(errors_count, "ErrorTableEntry *");
9842 ErrorTableEntry **errors = heap::c_allocator.allocate<ErrorTableEntry *>(errors_count);
98759843
98769844 for (uint32_t i = 0; i < err_count; i += 1) {
98779845 AstNode *field_node = node->data.err_set_decl.decls.at(i);
98789846 AstNode *symbol_node = ast_field_to_symbol_node(field_node);
98799847 Buf *err_name = symbol_node->data.symbol_expr.symbol;
9880 ErrorTableEntry *err = allocate<ErrorTableEntry>(1);
9848 ErrorTableEntry *err = heap::c_allocator.create<ErrorTableEntry>();
98819849 err->decl_node = field_node;
98829850 buf_init_from_buf(&err->name, err_name);
98839851
......@@ -9902,7 +9870,7 @@ static IrInstSrc *ir_gen_err_set_decl(IrBuilderSrc *irb, Scope *parent_scope, As
99029870 }
99039871 errors[err->value] = err;
99049872 }
9905 deallocate(errors, errors_count, "ErrorTableEntry *");
9873 heap::c_allocator.deallocate(errors, errors_count);
99069874 return ir_build_const_type(irb, parent_scope, node, err_set_type);
99079875}
99089876
......@@ -9910,7 +9878,7 @@ static IrInstSrc *ir_gen_fn_proto(IrBuilderSrc *irb, Scope *parent_scope, AstNod
99109878 assert(node->type == NodeTypeFnProto);
99119879
99129880 size_t param_count = node->data.fn_proto.params.length;
9913 IrInstSrc **param_types = allocate<IrInstSrc*>(param_count);
9881 IrInstSrc **param_types = heap::c_allocator.allocate<IrInstSrc*>(param_count);
99149882
99159883 bool is_var_args = false;
99169884 for (size_t i = 0; i < param_count; i += 1) {
......@@ -10191,7 +10159,7 @@ static IrInstSrc *ir_gen_node_raw(IrBuilderSrc *irb, AstNode *node, Scope *scope
1019110159}
1019210160
1019310161static ResultLoc *no_result_loc(void) {
10194 ResultLocNone *result_loc_none = allocate<ResultLocNone>(1);
10162 ResultLocNone *result_loc_none = heap::c_allocator.create<ResultLocNone>();
1019510163 result_loc_none->base.id = ResultLocIdNone;
1019610164 return &result_loc_none->base;
1019710165}
......@@ -10280,7 +10248,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutableSrc *ir_e
1028010248 if (!instr_is_unreachable(result)) {
1028110249 ir_mark_gen(ir_build_add_implicit_return_type(irb, scope, result->base.source_node, result, nullptr));
1028210250 // no need for save_err_ret_addr because this cannot return error
10283 ResultLocReturn *result_loc_ret = allocate<ResultLocReturn>(1, "ResultLocReturn");
10251 ResultLocReturn *result_loc_ret = heap::c_allocator.create<ResultLocReturn>();
1028410252 result_loc_ret->base.id = ResultLocIdReturn;
1028510253 ir_build_reset_result(irb, scope, node, &result_loc_ret->base);
1028610254 ir_mark_gen(ir_build_end_expr(irb, scope, node, result, &result_loc_ret->base));
......@@ -10372,7 +10340,7 @@ static Error eval_comptime_ptr_reinterpret(IrAnalyze *ira, CodeGen *codegen, Ast
1037210340 if ((err = ir_read_const_ptr(ira, codegen, source_node, &tmp, ptr_val)))
1037310341 return err;
1037410342 ZigValue *child_val = const_ptr_pointee_unchecked(codegen, ptr_val);
10375 copy_const_val(child_val, &tmp);
10343 copy_const_val(codegen, child_val, &tmp);
1037610344 return ErrorNone;
1037710345}
1037810346
......@@ -11522,7 +11490,7 @@ static ZigType *get_error_set_intersection(IrAnalyze *ira, ZigType *set1, ZigTyp
1152211490 return set1;
1152311491 }
1152411492 size_t errors_count = ira->codegen->errors_by_index.length;
11525 ErrorTableEntry **errors = allocate<ErrorTableEntry *>(errors_count, "ErrorTableEntry *");
11493 ErrorTableEntry **errors = heap::c_allocator.allocate<ErrorTableEntry *>(errors_count);
1152611494 populate_error_set_table(errors, set1);
1152711495 ZigList<ErrorTableEntry *> intersection_list = {};
1152811496
......@@ -11543,7 +11511,7 @@ static ZigType *get_error_set_intersection(IrAnalyze *ira, ZigType *set1, ZigTyp
1154311511 buf_appendf(&err_set_type->name, "%s%s", comma, buf_ptr(&existing_entry_with_docs->name));
1154411512 }
1154511513 }
11546 deallocate(errors, errors_count, "ErrorTableEntry *");
11514 heap::c_allocator.deallocate(errors, errors_count);
1154711515
1154811516 err_set_type->data.error_set.err_count = intersection_list.length;
1154911517 err_set_type->data.error_set.errors = intersection_list.items;
......@@ -11596,7 +11564,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
1159611564 actual_ptr_type->data.pointer.ptr_len == PtrLenC;
1159711565 if (!ok_null_term_ptrs) {
1159811566 result.id = ConstCastResultIdPtrSentinel;
11599 result.data.bad_ptr_sentinel = allocate_nonzero<ConstCastPtrSentinel>(1);
11567 result.data.bad_ptr_sentinel = heap::c_allocator.allocate_nonzero<ConstCastPtrSentinel>(1);
1160011568 result.data.bad_ptr_sentinel->wanted_type = wanted_ptr_type;
1160111569 result.data.bad_ptr_sentinel->actual_type = actual_ptr_type;
1160211570 return result;
......@@ -11612,7 +11580,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
1161211580 (!actual_ptr_type->data.pointer.is_volatile || wanted_ptr_type->data.pointer.is_volatile);
1161311581 if (!ok_cv_qualifiers) {
1161411582 result.id = ConstCastResultIdCV;
11615 result.data.bad_cv = allocate_nonzero<ConstCastBadCV>(1);
11583 result.data.bad_cv = heap::c_allocator.allocate_nonzero<ConstCastBadCV>(1);
1161611584 result.data.bad_cv->wanted_type = wanted_ptr_type;
1161711585 result.data.bad_cv->actual_type = actual_ptr_type;
1161811586 return result;
......@@ -11624,7 +11592,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
1162411592 return child;
1162511593 if (child.id != ConstCastResultIdOk) {
1162611594 result.id = ConstCastResultIdPointerChild;
11627 result.data.pointer_mismatch = allocate_nonzero<ConstCastPointerMismatch>(1);
11595 result.data.pointer_mismatch = heap::c_allocator.allocate_nonzero<ConstCastPointerMismatch>(1);
1162811596 result.data.pointer_mismatch->child = child;
1162911597 result.data.pointer_mismatch->wanted_child = wanted_ptr_type->data.pointer.child_type;
1163011598 result.data.pointer_mismatch->actual_child = actual_ptr_type->data.pointer.child_type;
......@@ -11635,7 +11603,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
1163511603 (!wanted_allows_zero && !actual_allows_zero);
1163611604 if (!ok_allows_zero) {
1163711605 result.id = ConstCastResultIdBadAllowsZero;
11638 result.data.bad_allows_zero = allocate_nonzero<ConstCastBadAllowsZero>(1);
11606 result.data.bad_allows_zero = heap::c_allocator.allocate_nonzero<ConstCastBadAllowsZero>(1);
1163911607 result.data.bad_allows_zero->wanted_type = wanted_type;
1164011608 result.data.bad_allows_zero->actual_type = actual_type;
1164111609 return result;
......@@ -11675,7 +11643,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
1167511643 return child;
1167611644 if (child.id != ConstCastResultIdOk) {
1167711645 result.id = ConstCastResultIdArrayChild;
11678 result.data.array_mismatch = allocate_nonzero<ConstCastArrayMismatch>(1);
11646 result.data.array_mismatch = heap::c_allocator.allocate_nonzero<ConstCastArrayMismatch>(1);
1167911647 result.data.array_mismatch->child = child;
1168011648 result.data.array_mismatch->wanted_child = wanted_type->data.array.child_type;
1168111649 result.data.array_mismatch->actual_child = actual_type->data.array.child_type;
......@@ -11686,7 +11654,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
1168611654 const_values_equal(ira->codegen, wanted_type->data.array.sentinel, actual_type->data.array.sentinel));
1168711655 if (!ok_null_terminated) {
1168811656 result.id = ConstCastResultIdSentinelArrays;
11689 result.data.sentinel_arrays = allocate_nonzero<ConstCastBadNullTermArrays>(1);
11657 result.data.sentinel_arrays = heap::c_allocator.allocate_nonzero<ConstCastBadNullTermArrays>(1);
1169011658 result.data.sentinel_arrays->child = child;
1169111659 result.data.sentinel_arrays->wanted_type = wanted_type;
1169211660 result.data.sentinel_arrays->actual_type = actual_type;
......@@ -11714,7 +11682,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
1171411682 actual_ptr_type->data.pointer.sentinel));
1171511683 if (!ok_sentinels) {
1171611684 result.id = ConstCastResultIdPtrSentinel;
11717 result.data.bad_ptr_sentinel = allocate_nonzero<ConstCastPtrSentinel>(1);
11685 result.data.bad_ptr_sentinel = heap::c_allocator.allocate_nonzero<ConstCastPtrSentinel>(1);
1171811686 result.data.bad_ptr_sentinel->wanted_type = wanted_ptr_type;
1171911687 result.data.bad_ptr_sentinel->actual_type = actual_ptr_type;
1172011688 return result;
......@@ -11731,7 +11699,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
1173111699 return child;
1173211700 if (child.id != ConstCastResultIdOk) {
1173311701 result.id = ConstCastResultIdSliceChild;
11734 result.data.slice_mismatch = allocate_nonzero<ConstCastSliceMismatch>(1);
11702 result.data.slice_mismatch = heap::c_allocator.allocate_nonzero<ConstCastSliceMismatch>(1);
1173511703 result.data.slice_mismatch->child = child;
1173611704 result.data.slice_mismatch->actual_child = actual_ptr_type->data.pointer.child_type;
1173711705 result.data.slice_mismatch->wanted_child = wanted_ptr_type->data.pointer.child_type;
......@@ -11748,7 +11716,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
1174811716 return child;
1174911717 if (child.id != ConstCastResultIdOk) {
1175011718 result.id = ConstCastResultIdOptionalChild;
11751 result.data.optional = allocate_nonzero<ConstCastOptionalMismatch>(1);
11719 result.data.optional = heap::c_allocator.allocate_nonzero<ConstCastOptionalMismatch>(1);
1175211720 result.data.optional->child = child;
1175311721 result.data.optional->wanted_child = wanted_type->data.maybe.child_type;
1175411722 result.data.optional->actual_child = actual_type->data.maybe.child_type;
......@@ -11764,7 +11732,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
1176411732 return payload_child;
1176511733 if (payload_child.id != ConstCastResultIdOk) {
1176611734 result.id = ConstCastResultIdErrorUnionPayload;
11767 result.data.error_union_payload = allocate_nonzero<ConstCastErrUnionPayloadMismatch>(1);
11735 result.data.error_union_payload = heap::c_allocator.allocate_nonzero<ConstCastErrUnionPayloadMismatch>(1);
1176811736 result.data.error_union_payload->child = payload_child;
1176911737 result.data.error_union_payload->wanted_payload = wanted_type->data.error_union.payload_type;
1177011738 result.data.error_union_payload->actual_payload = actual_type->data.error_union.payload_type;
......@@ -11776,7 +11744,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
1177611744 return error_set_child;
1177711745 if (error_set_child.id != ConstCastResultIdOk) {
1177811746 result.id = ConstCastResultIdErrorUnionErrorSet;
11779 result.data.error_union_error_set = allocate_nonzero<ConstCastErrUnionErrSetMismatch>(1);
11747 result.data.error_union_error_set = heap::c_allocator.allocate_nonzero<ConstCastErrUnionErrSetMismatch>(1);
1178011748 result.data.error_union_error_set->child = error_set_child;
1178111749 result.data.error_union_error_set->wanted_err_set = wanted_type->data.error_union.err_set_type;
1178211750 result.data.error_union_error_set->actual_err_set = actual_type->data.error_union.err_set_type;
......@@ -11810,7 +11778,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
1181011778 }
1181111779
1181211780 size_t errors_count = g->errors_by_index.length;
11813 ErrorTableEntry **errors = allocate<ErrorTableEntry *>(errors_count, "ErrorTableEntry *");
11781 ErrorTableEntry **errors = heap::c_allocator.allocate<ErrorTableEntry *>(errors_count);
1181411782 for (uint32_t i = 0; i < container_set->data.error_set.err_count; i += 1) {
1181511783 ErrorTableEntry *error_entry = container_set->data.error_set.errors[i];
1181611784 assert(errors[error_entry->value] == nullptr);
......@@ -11822,12 +11790,12 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
1182211790 if (error_entry == nullptr) {
1182311791 if (result.id == ConstCastResultIdOk) {
1182411792 result.id = ConstCastResultIdErrSet;
11825 result.data.error_set_mismatch = allocate<ConstCastErrSetMismatch>(1);
11793 result.data.error_set_mismatch = heap::c_allocator.create<ConstCastErrSetMismatch>();
1182611794 }
1182711795 result.data.error_set_mismatch->missing_errors.append(contained_error_entry);
1182811796 }
1182911797 }
11830 deallocate(errors, errors_count, "ErrorTableEntry *");
11798 heap::c_allocator.deallocate(errors, errors_count);
1183111799 return result;
1183211800 }
1183311801
......@@ -11856,7 +11824,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
1185611824 return child;
1185711825 if (child.id != ConstCastResultIdOk) {
1185811826 result.id = ConstCastResultIdFnReturnType;
11859 result.data.return_type = allocate_nonzero<ConstCastOnly>(1);
11827 result.data.return_type = heap::c_allocator.allocate_nonzero<ConstCastOnly>(1);
1186011828 *result.data.return_type = child;
1186111829 return result;
1186211830 }
......@@ -11885,7 +11853,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
1188511853 result.data.fn_arg.arg_index = i;
1188611854 result.data.fn_arg.actual_param_type = actual_param_info->type;
1188711855 result.data.fn_arg.expected_param_type = expected_param_info->type;
11888 result.data.fn_arg.child = allocate_nonzero<ConstCastOnly>(1);
11856 result.data.fn_arg.child = heap::c_allocator.allocate_nonzero<ConstCastOnly>(1);
1188911857 *result.data.fn_arg.child = arg_child;
1189011858 return result;
1189111859 }
......@@ -11906,14 +11874,14 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
1190611874
1190711875 if (wanted_type->id == ZigTypeIdInt && actual_type->id == ZigTypeIdInt) {
1190811876 result.id = ConstCastResultIdIntShorten;
11909 result.data.int_shorten = allocate_nonzero<ConstCastIntShorten>(1);
11877 result.data.int_shorten = heap::c_allocator.allocate_nonzero<ConstCastIntShorten>(1);
1191011878 result.data.int_shorten->wanted_type = wanted_type;
1191111879 result.data.int_shorten->actual_type = actual_type;
1191211880 return result;
1191311881 }
1191411882
1191511883 result.id = ConstCastResultIdType;
11916 result.data.type_mismatch = allocate_nonzero<ConstCastTypeMismatch>(1);
11884 result.data.type_mismatch = heap::c_allocator.allocate_nonzero<ConstCastTypeMismatch>(1);
1191711885 result.data.type_mismatch->wanted_type = wanted_type;
1191811886 result.data.type_mismatch->actual_type = actual_type;
1191911887 return result;
......@@ -11922,7 +11890,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
1192211890static void update_errors_helper(CodeGen *g, ErrorTableEntry ***errors, size_t *errors_count) {
1192311891 size_t old_errors_count = *errors_count;
1192411892 *errors_count = g->errors_by_index.length;
11925 *errors = reallocate(*errors, old_errors_count, *errors_count);
11893 *errors = heap::c_allocator.reallocate(*errors, old_errors_count, *errors_count);
1192611894}
1192711895
1192811896static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigType *expected_type,
......@@ -12592,7 +12560,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1259212560 return ira->codegen->builtin_types.entry_invalid;
1259312561 }
1259412562
12595 free(errors);
12563 heap::c_allocator.deallocate(errors, errors_count);
1259612564
1259712565 if (convert_to_const_slice) {
1259812566 if (prev_inst->value->type->id == ZigTypeIdPointer) {
......@@ -12671,7 +12639,7 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInst *source_instr,
1267112639 case CastOpBitCast:
1267212640 zig_panic("TODO");
1267312641 case CastOpNoop: {
12674 copy_const_val(const_val, other_val);
12642 copy_const_val(ira->codegen, const_val, other_val);
1267512643 const_val->type = new_type;
1267612644 break;
1267712645 }
......@@ -13200,7 +13168,7 @@ Error ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
1320013168 if (type_is_invalid(return_ptr->type))
1320113169 return ErrorSemanticAnalyzeFail;
1320213170
13203 IrExecutableSrc *ir_executable = allocate<IrExecutableSrc>(1, "IrExecutableSrc");
13171 IrExecutableSrc *ir_executable = heap::c_allocator.create<IrExecutableSrc>();
1320413172 ir_executable->source_node = source_node;
1320513173 ir_executable->parent_exec = parent_exec;
1320613174 ir_executable->name = exec_name;
......@@ -13224,7 +13192,7 @@ Error ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
1322413192 ir_print_src(codegen, stderr, ir_executable, 2);
1322513193 fprintf(stderr, "}\n");
1322613194 }
13227 IrExecutableGen *analyzed_executable = allocate<IrExecutableGen>(1, "IrExecutableGen");
13195 IrExecutableGen *analyzed_executable = heap::c_allocator.create<IrExecutableGen>();
1322813196 analyzed_executable->source_node = source_node;
1322913197 analyzed_executable->parent_exec = parent_exec;
1323013198 analyzed_executable->source_exec = ir_executable;
......@@ -13425,7 +13393,7 @@ static IrInstGen *ir_analyze_optional_wrap(IrAnalyze *ira, IrInst* source_instr,
1342513393 source_instr->scope, source_instr->source_node);
1342613394 const_instruction->base.value->special = ConstValSpecialStatic;
1342713395 if (types_have_same_zig_comptime_repr(ira->codegen, wanted_type, payload_type)) {
13428 copy_const_val(const_instruction->base.value, val);
13396 copy_const_val(ira->codegen, const_instruction->base.value, val);
1342913397 } else {
1343013398 const_instruction->base.value->data.x_optional = val;
1343113399 }
......@@ -13466,7 +13434,7 @@ static IrInstGen *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInst* source_ins
1346613434 if (val == nullptr)
1346713435 return ira->codegen->invalid_inst_gen;
1346813436
13469 ZigValue *err_set_val = create_const_vals(1);
13437 ZigValue *err_set_val = ira->codegen->pass1_arena->create<ZigValue>();
1347013438 err_set_val->type = err_set_type;
1347113439 err_set_val->special = ConstValSpecialStatic;
1347213440 err_set_val->data.x_err_set = nullptr;
......@@ -13578,7 +13546,7 @@ static IrInstGen *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInst* source_instr,
1357813546 if (!val)
1357913547 return ira->codegen->invalid_inst_gen;
1358013548
13581 ZigValue *err_set_val = create_const_vals(1);
13549 ZigValue *err_set_val = ira->codegen->pass1_arena->create<ZigValue>();
1358213550 err_set_val->special = ConstValSpecialStatic;
1358313551 err_set_val->type = wanted_type->data.error_union.err_set_type;
1358413552 err_set_val->data.x_err_set = val->data.x_err_set;
......@@ -13843,7 +13811,7 @@ static IrInstGen *ir_analyze_enum_to_union(IrAnalyze *ira, IrInst* source_instr,
1384313811 result->value->special = ConstValSpecialStatic;
1384413812 result->value->type = wanted_type;
1384513813 bigint_init_bigint(&result->value->data.x_union.tag, &val->data.x_enum_tag);
13846 result->value->data.x_union.payload = create_const_vals(1);
13814 result->value->data.x_union.payload = ira->codegen->pass1_arena->create<ZigValue>();
1384713815 result->value->data.x_union.payload->special = ConstValSpecialStatic;
1384813816 result->value->data.x_union.payload->type = field_type;
1384913817 return result;
......@@ -14148,7 +14116,7 @@ static IrInstGen *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInst* source_instr,
1414814116 if (pointee == nullptr)
1414914117 return ira->codegen->invalid_inst_gen;
1415014118 if (pointee->special != ConstValSpecialRuntime) {
14151 ZigValue *array_val = create_const_vals(1);
14119 ZigValue *array_val = ira->codegen->pass1_arena->create<ZigValue>();
1415214120 array_val->special = ConstValSpecialStatic;
1415314121 array_val->type = array_type;
1415414122 array_val->data.x_array.special = ConstArraySpecialNone;
......@@ -14362,7 +14330,7 @@ static IrInstGen *ir_analyze_array_to_vector(IrAnalyze *ira, IrInst* source_inst
1436214330 if (instr_is_comptime(array)) {
1436314331 // arrays and vectors have the same ZigValue representation
1436414332 IrInstGen *result = ir_const(ira, source_instr, vector_type);
14365 copy_const_val(result->value, array->value);
14333 copy_const_val(ira->codegen, result->value, array->value);
1436614334 result->value->type = vector_type;
1436714335 return result;
1436814336 }
......@@ -14375,7 +14343,7 @@ static IrInstGen *ir_analyze_vector_to_array(IrAnalyze *ira, IrInst* source_inst
1437514343 if (instr_is_comptime(vector)) {
1437614344 // arrays and vectors have the same ZigValue representation
1437714345 IrInstGen *result = ir_const(ira, source_instr, array_type);
14378 copy_const_val(result->value, vector->value);
14346 copy_const_val(ira->codegen, result->value, vector->value);
1437914347 result->value->type = array_type;
1438014348 return result;
1438114349 }
......@@ -14675,7 +14643,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
1467514643 if (wanted_type->id == ZigTypeIdComptimeInt || wanted_type->id == ZigTypeIdInt) {
1467614644 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1467714645 if (actual_type->id == ZigTypeIdComptimeInt || actual_type->id == ZigTypeIdInt) {
14678 copy_const_val(result->value, value->value);
14646 copy_const_val(ira->codegen, result->value, value->value);
1467914647 result->value->type = wanted_type;
1468014648 } else {
1468114649 float_init_bigint(&result->value->data.x_bigint, value->value);
......@@ -16508,7 +16476,7 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i
1650816476 IrInstGen *result = ir_const(ira, &bin_op_instruction->base.base,
1650916477 get_vector_type(ira->codegen, resolved_type->data.vector.len, ira->codegen->builtin_types.entry_bool));
1651016478 result->value->data.x_array.data.s_none.elements =
16511 create_const_vals(resolved_type->data.vector.len);
16479 ira->codegen->pass1_arena->allocate<ZigValue>(resolved_type->data.vector.len);
1651216480
1651316481 expand_undef_array(ira->codegen, result->value);
1651416482 for (size_t i = 0;i < resolved_type->data.vector.len;i++) {
......@@ -16516,7 +16484,7 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i
1651616484 &op1_val->data.x_array.data.s_none.elements[i],
1651716485 &op2_val->data.x_array.data.s_none.elements[i],
1651816486 bin_op_instruction, op_id, one_possible_value);
16519 copy_const_val(&result->value->data.x_array.data.s_none.elements[i], cur_res->value);
16487 copy_const_val(ira->codegen, &result->value->data.x_array.data.s_none.elements[i], cur_res->value);
1652016488 }
1652116489 return result;
1652216490 }
......@@ -17416,7 +17384,7 @@ static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instructi
1741617384 ZigValue *out_array_val;
1741717385 size_t new_len = (op1_array_end - op1_array_index) + (op2_array_end - op2_array_index);
1741817386 if (op1_type->id == ZigTypeIdPointer || op2_type->id == ZigTypeIdPointer) {
17419 out_array_val = create_const_vals(1);
17387 out_array_val = ira->codegen->pass1_arena->create<ZigValue>();
1742017388 out_array_val->special = ConstValSpecialStatic;
1742117389 out_array_val->type = get_array_type(ira->codegen, child_type, new_len, sentinel);
1742217390
......@@ -17428,11 +17396,11 @@ static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instructi
1742817396 true, false, PtrLenUnknown, 0, 0, 0, false,
1742917397 VECTOR_INDEX_NONE, nullptr, sentinel);
1743017398 result->value->type = get_slice_type(ira->codegen, ptr_type);
17431 out_array_val = create_const_vals(1);
17399 out_array_val = ira->codegen->pass1_arena->create<ZigValue>();
1743217400 out_array_val->special = ConstValSpecialStatic;
1743317401 out_array_val->type = get_array_type(ira->codegen, child_type, new_len, sentinel);
1743417402
17435 out_val->data.x_struct.fields = alloc_const_vals_ptrs(2);
17403 out_val->data.x_struct.fields = alloc_const_vals_ptrs(ira->codegen, 2);
1743617404
1743717405 out_val->data.x_struct.fields[slice_ptr_index]->type = ptr_type;
1743817406 out_val->data.x_struct.fields[slice_ptr_index]->special = ConstValSpecialStatic;
......@@ -17449,7 +17417,7 @@ static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instructi
1744917417 } else {
1745017418 result->value->type = get_pointer_to_type_extra2(ira->codegen, child_type, true, false, PtrLenUnknown,
1745117419 0, 0, 0, false, VECTOR_INDEX_NONE, nullptr, sentinel);
17452 out_array_val = create_const_vals(1);
17420 out_array_val = ira->codegen->pass1_arena->create<ZigValue>();
1745317421 out_array_val->special = ConstValSpecialStatic;
1745417422 out_array_val->type = get_array_type(ira->codegen, child_type, new_len, sentinel);
1745517423 out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;
......@@ -17465,7 +17433,7 @@ static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instructi
1746517433 }
1746617434
1746717435 uint64_t full_len = new_len + ((sentinel != nullptr) ? 1 : 0);
17468 out_array_val->data.x_array.data.s_none.elements = create_const_vals(full_len);
17436 out_array_val->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(full_len);
1746917437 // TODO handle the buf case here for an optimization
1747017438 expand_undef_array(ira->codegen, op1_array_val);
1747117439 expand_undef_array(ira->codegen, op2_array_val);
......@@ -17473,21 +17441,21 @@ static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instructi
1747317441 size_t next_index = 0;
1747417442 for (size_t i = op1_array_index; i < op1_array_end; i += 1, next_index += 1) {
1747517443 ZigValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index];
17476 copy_const_val(elem_dest_val, &op1_array_val->data.x_array.data.s_none.elements[i]);
17444 copy_const_val(ira->codegen, elem_dest_val, &op1_array_val->data.x_array.data.s_none.elements[i]);
1747717445 elem_dest_val->parent.id = ConstParentIdArray;
1747817446 elem_dest_val->parent.data.p_array.array_val = out_array_val;
1747917447 elem_dest_val->parent.data.p_array.elem_index = next_index;
1748017448 }
1748117449 for (size_t i = op2_array_index; i < op2_array_end; i += 1, next_index += 1) {
1748217450 ZigValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index];
17483 copy_const_val(elem_dest_val, &op2_array_val->data.x_array.data.s_none.elements[i]);
17451 copy_const_val(ira->codegen, elem_dest_val, &op2_array_val->data.x_array.data.s_none.elements[i]);
1748417452 elem_dest_val->parent.id = ConstParentIdArray;
1748517453 elem_dest_val->parent.data.p_array.array_val = out_array_val;
1748617454 elem_dest_val->parent.data.p_array.elem_index = next_index;
1748717455 }
1748817456 if (next_index < full_len) {
1748917457 ZigValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index];
17490 copy_const_val(elem_dest_val, sentinel);
17458 copy_const_val(ira->codegen, elem_dest_val, sentinel);
1749117459 elem_dest_val->parent.id = ConstParentIdArray;
1749217460 elem_dest_val->parent.data.p_array.array_val = out_array_val;
1749317461 elem_dest_val->parent.data.p_array.elem_index = next_index;
......@@ -17566,13 +17534,13 @@ static IrInstGen *ir_analyze_array_mult(IrAnalyze *ira, IrInstSrcBinOp *instruct
1756617534 // TODO optimize the buf case
1756717535 expand_undef_array(ira->codegen, array_val);
1756817536 size_t extra_null_term = (array_type->data.array.sentinel != nullptr) ? 1 : 0;
17569 out_val->data.x_array.data.s_none.elements = create_const_vals(new_array_len + extra_null_term);
17537 out_val->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(new_array_len + extra_null_term);
1757017538
1757117539 uint64_t i = 0;
1757217540 for (uint64_t x = 0; x < mult_amt; x += 1) {
1757317541 for (uint64_t y = 0; y < old_array_len; y += 1) {
1757417542 ZigValue *elem_dest_val = &out_val->data.x_array.data.s_none.elements[i];
17575 copy_const_val(elem_dest_val, &array_val->data.x_array.data.s_none.elements[y]);
17543 copy_const_val(ira->codegen, elem_dest_val, &array_val->data.x_array.data.s_none.elements[y]);
1757617544 elem_dest_val->parent.id = ConstParentIdArray;
1757717545 elem_dest_val->parent.data.p_array.array_val = out_val;
1757817546 elem_dest_val->parent.data.p_array.elem_index = i;
......@@ -17583,7 +17551,7 @@ static IrInstGen *ir_analyze_array_mult(IrAnalyze *ira, IrInstSrcBinOp *instruct
1758317551
1758417552 if (array_type->data.array.sentinel != nullptr) {
1758517553 ZigValue *elem_dest_val = &out_val->data.x_array.data.s_none.elements[i];
17586 copy_const_val(elem_dest_val, array_type->data.array.sentinel);
17554 copy_const_val(ira->codegen, elem_dest_val, array_type->data.array.sentinel);
1758717555 elem_dest_val->parent.id = ConstParentIdArray;
1758817556 elem_dest_val->parent.data.p_array.array_val = out_val;
1758917557 elem_dest_val->parent.data.p_array.elem_index = i;
......@@ -17624,14 +17592,14 @@ static IrInstGen *ir_analyze_instruction_merge_err_sets(IrAnalyze *ira,
1762417592 }
1762517593
1762617594 size_t errors_count = ira->codegen->errors_by_index.length;
17627 ErrorTableEntry **errors = allocate<ErrorTableEntry *>(errors_count, "ErrorTableEntry *");
17595 ErrorTableEntry **errors = heap::c_allocator.allocate<ErrorTableEntry *>(errors_count);
1762817596 for (uint32_t i = 0, count = op1_type->data.error_set.err_count; i < count; i += 1) {
1762917597 ErrorTableEntry *error_entry = op1_type->data.error_set.errors[i];
1763017598 assert(errors[error_entry->value] == nullptr);
1763117599 errors[error_entry->value] = error_entry;
1763217600 }
1763317601 ZigType *result_type = get_error_set_union(ira->codegen, errors, op1_type, op2_type, instruction->type_name);
17634 deallocate(errors, errors_count, "ErrorTableEntry *");
17602 heap::c_allocator.deallocate(errors, errors_count);
1763517603
1763617604 return ir_const_type(ira, &instruction->base.base, result_type);
1763717605}
......@@ -17730,8 +17698,8 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV
1773017698 if (var->gen_is_const) {
1773117699 var->const_value = init_val;
1773217700 } else {
17733 var->const_value = create_const_vals(1);
17734 copy_const_val(var->const_value, init_val);
17701 var->const_value = ira->codegen->pass1_arena->create<ZigValue>();
17702 copy_const_val(ira->codegen, var->const_value, init_val);
1773517703 }
1773617704 }
1773717705 }
......@@ -17905,7 +17873,7 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport
1790517873 // It's not clear how all the different types are supposed to be handled.
1790617874 // Need comprehensive tests for exporting one thing in one file and declaring an extern var
1790717875 // in another file.
17908 TldFn *tld_fn = allocate<TldFn>(1);
17876 TldFn *tld_fn = heap::c_allocator.create<TldFn>();
1790917877 tld_fn->base.id = TldIdFn;
1791017878 tld_fn->base.source_node = instruction->base.base.source_node;
1791117879
......@@ -18134,7 +18102,7 @@ static IrInstGen *ir_analyze_instruction_error_union(IrAnalyze *ira, IrInstSrcEr
1813418102 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type);
1813518103 result->value->special = ConstValSpecialLazy;
1813618104
18137 LazyValueErrUnionType *lazy_err_union_type = allocate<LazyValueErrUnionType>(1, "LazyValueErrUnionType");
18105 LazyValueErrUnionType *lazy_err_union_type = heap::c_allocator.create<LazyValueErrUnionType>();
1813818106 lazy_err_union_type->ira = ira; ira_ref(ira);
1813918107 result->value->data.x_lazy = &lazy_err_union_type->base;
1814018108 lazy_err_union_type->base.id = LazyValueIdErrUnionType;
......@@ -18155,7 +18123,7 @@ static IrInstGen *ir_analyze_alloca(IrAnalyze *ira, IrInst *source_inst, ZigType
1815518123{
1815618124 Error err;
1815718125
18158 ZigValue *pointee = create_const_vals(1);
18126 ZigValue *pointee = ira->codegen->pass1_arena->create<ZigValue>();
1815918127 pointee->special = ConstValSpecialUndef;
1816018128 pointee->llvm_align = align;
1816118129
......@@ -18236,8 +18204,8 @@ static bool type_can_bit_cast(ZigType *t) {
1823618204 }
1823718205}
1823818206
18239static void set_up_result_loc_for_inferred_comptime(IrInstGen *ptr) {
18240 ZigValue *undef_child = create_const_vals(1);
18207static void set_up_result_loc_for_inferred_comptime(IrAnalyze *ira, IrInstGen *ptr) {
18208 ZigValue *undef_child = ira->codegen->pass1_arena->create<ZigValue>();
1824118209 undef_child->type = ptr->value->type->data.pointer.child_type;
1824218210 undef_child->special = ConstValSpecialUndef;
1824318211 ptr->value->special = ConstValSpecialStatic;
......@@ -18283,7 +18251,7 @@ static IrInstGen *ir_resolve_no_result_loc(IrAnalyze *ira, IrInst *suspend_sourc
1828318251 IrInstGenAlloca *alloca_gen = ir_build_alloca_gen(ira, suspend_source_instr, 0, "");
1828418252 alloca_gen->base.value->type = get_pointer_to_type_extra(ira->codegen, value_type, false, false,
1828518253 PtrLenSingle, 0, 0, 0, false);
18286 set_up_result_loc_for_inferred_comptime(&alloca_gen->base);
18254 set_up_result_loc_for_inferred_comptime(ira, &alloca_gen->base);
1828718255 ZigFn *fn_entry = ira->new_irb.exec->fn_entry;
1828818256 if (fn_entry != nullptr && get_scope_typeof(suspend_source_instr->scope) == nullptr) {
1828918257 fn_entry->alloca_gen_list.append(alloca_gen);
......@@ -18347,7 +18315,6 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i
1834718315 ZigVar *new_var = create_local_var(ira->codegen, var->decl_node, var->child_scope,
1834818316 buf_create_from_str(var->name), var->src_is_const, var->gen_is_const,
1834918317 var->shadowable, var->is_comptime, true);
18350 new_var->owner_exec = var->owner_exec;
1835118318 new_var->align_bytes = var->align_bytes;
1835218319
1835318320 var->next_var = new_var;
......@@ -18686,15 +18653,15 @@ static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr
1868618653 if (!val)
1868718654 return ira->codegen->invalid_inst_gen;
1868818655 field->is_comptime = true;
18689 field->init_val = create_const_vals(1);
18690 copy_const_val(field->init_val, val);
18656 field->init_val = ira->codegen->pass1_arena->create<ZigValue>();
18657 copy_const_val(ira->codegen, field->init_val, val);
1869118658 return result_loc;
1869218659 }
1869318660
1869418661 ZigType *struct_ptr_type = get_pointer_to_type(ira->codegen, isf->inferred_struct_type, false);
1869518662 if (instr_is_comptime(result_loc)) {
1869618663 casted_ptr = ir_const(ira, suspend_source_instr, struct_ptr_type);
18697 copy_const_val(casted_ptr->value, result_loc->value);
18664 copy_const_val(ira->codegen, casted_ptr->value, result_loc->value);
1869818665 casted_ptr->value->type = struct_ptr_type;
1869918666 } else {
1870018667 casted_ptr = result_loc;
......@@ -18707,8 +18674,8 @@ static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr
1870718674 ZigValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val,
1870818675 suspend_source_instr->source_node);
1870918676 struct_val->special = ConstValSpecialStatic;
18710 struct_val->data.x_struct.fields = realloc_const_vals_ptrs(struct_val->data.x_struct.fields,
18711 old_field_count, new_field_count);
18677 struct_val->data.x_struct.fields = realloc_const_vals_ptrs(ira->codegen,
18678 struct_val->data.x_struct.fields, old_field_count, new_field_count);
1871218679
1871318680 ZigValue *field_val = struct_val->data.x_struct.fields[old_field_count];
1871418681 field_val->special = ConstValSpecialUndef;
......@@ -19008,10 +18975,10 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
1900818975 if (!arg_val)
1900918976 return false;
1901018977 } else {
19011 arg_val = create_const_runtime(casted_arg->value->type);
18978 arg_val = create_const_runtime(ira->codegen, casted_arg->value->type);
1901218979 }
1901318980 if (arg_part_of_generic_id) {
19014 copy_const_val(&generic_id->params[generic_id->param_count], arg_val);
18981 copy_const_val(ira->codegen, &generic_id->params[generic_id->param_count], arg_val);
1901518982 generic_id->param_count += 1;
1901618983 }
1901718984
......@@ -19160,7 +19127,7 @@ static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr,
1916019127 if (dest_val == nullptr)
1916119128 return ira->codegen->invalid_inst_gen;
1916219129 if (dest_val->special != ConstValSpecialRuntime) {
19163 copy_const_val(dest_val, value->value);
19130 copy_const_val(ira->codegen, dest_val, value->value);
1916419131
1916519132 if (ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar &&
1916619133 !ira->new_irb.current_basic_block->must_be_comptime_source_instr)
......@@ -19395,8 +19362,6 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1939519362 {
1939619363 return ira->codegen->invalid_inst_gen;
1939719364 }
19398 destroy(result_ptr, "ZigValue");
19399 result_ptr = nullptr;
1940019365
1940119366 if (inferred_err_set_type != nullptr) {
1940219367 inferred_err_set_type->data.error_set.incomplete = false;
......@@ -19404,7 +19369,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1940419369 ErrorTableEntry *err = result->data.x_err_union.error_set->data.x_err_set;
1940519370 if (err != nullptr) {
1940619371 inferred_err_set_type->data.error_set.err_count = 1;
19407 inferred_err_set_type->data.error_set.errors = allocate<ErrorTableEntry *>(1);
19372 inferred_err_set_type->data.error_set.errors = heap::c_allocator.create<ErrorTableEntry *>();
1940819373 inferred_err_set_type->data.error_set.errors[0] = err;
1940919374 }
1941019375 ZigType *fn_inferred_err_set_type = result->type->data.error_union.err_set_type;
......@@ -19438,12 +19403,12 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1943819403
1943919404 size_t new_fn_arg_count = first_arg_1_or_0 + args_len;
1944019405
19441 IrInstGen **casted_args = allocate<IrInstGen *>(new_fn_arg_count);
19406 IrInstGen **casted_args = heap::c_allocator.allocate<IrInstGen *>(new_fn_arg_count);
1944219407
1944319408 // Fork a scope of the function with known values for the parameters.
1944419409 Scope *parent_scope = fn_entry->fndef_scope->base.parent;
1944519410 ZigFn *impl_fn = create_fn(ira->codegen, fn_proto_node);
19446 impl_fn->param_source_nodes = allocate<AstNode *>(new_fn_arg_count);
19411 impl_fn->param_source_nodes = heap::c_allocator.allocate<AstNode *>(new_fn_arg_count);
1944719412 buf_init_from_buf(&impl_fn->symbol_name, &fn_entry->symbol_name);
1944819413 impl_fn->fndef_scope = create_fndef_scope(ira->codegen, impl_fn->body_node, parent_scope, impl_fn);
1944919414 impl_fn->child_scope = &impl_fn->fndef_scope->base;
......@@ -19454,10 +19419,10 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1945419419
1945519420 // TODO maybe GenericFnTypeId can be replaced with using the child_scope directly
1945619421 // as the key in generic_table
19457 GenericFnTypeId *generic_id = allocate<GenericFnTypeId>(1);
19422 GenericFnTypeId *generic_id = heap::c_allocator.create<GenericFnTypeId>();
1945819423 generic_id->fn_entry = fn_entry;
1945919424 generic_id->param_count = 0;
19460 generic_id->params = create_const_vals(new_fn_arg_count);
19425 generic_id->params = ira->codegen->pass1_arena->allocate<ZigValue>(new_fn_arg_count);
1946119426 size_t next_proto_i = 0;
1946219427
1946319428 if (first_arg_ptr) {
......@@ -19517,7 +19482,6 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1951719482 IrInstGenConst *const_instruction = ir_create_inst_noval<IrInstGenConst>(&ira->new_irb,
1951819483 impl_fn->child_scope, fn_proto_node->data.fn_proto.align_expr);
1951919484 const_instruction->base.value = align_result;
19520 destroy(result_ptr, "ZigValue");
1952119485
1952219486 uint32_t align_bytes = 0;
1952319487 ir_resolve_align(ira, &const_instruction->base, nullptr, &align_bytes);
......@@ -19650,7 +19614,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1965019614 }
1965119615
1965219616
19653 IrInstGen **casted_args = allocate<IrInstGen *>(call_param_count);
19617 IrInstGen **casted_args = heap::c_allocator.allocate<IrInstGen *>(call_param_count);
1965419618 size_t next_arg_index = 0;
1965519619 if (first_arg_ptr) {
1965619620 assert(first_arg_ptr->value->type->id == ZigTypeIdPointer);
......@@ -19782,7 +19746,7 @@ static IrInstGen *ir_analyze_fn_call_src(IrAnalyze *ira, IrInstSrcCall *call_ins
1978219746 return ira->codegen->invalid_inst_gen;
1978319747 new_stack_src = &call_instruction->new_stack->base;
1978419748 }
19785 IrInstGen **args_ptr = allocate<IrInstGen *>(call_instruction->arg_count, "IrInstGen *");
19749 IrInstGen **args_ptr = heap::c_allocator.allocate<IrInstGen *>(call_instruction->arg_count);
1978619750 for (size_t i = 0; i < call_instruction->arg_count; i += 1) {
1978719751 args_ptr[i] = call_instruction->args[i]->child;
1978819752 if (type_is_invalid(args_ptr[i]->value->type))
......@@ -19798,7 +19762,7 @@ static IrInstGen *ir_analyze_fn_call_src(IrAnalyze *ira, IrInstSrcCall *call_ins
1979819762 first_arg_ptr, first_arg_ptr_src, modifier, new_stack, new_stack_src,
1979919763 call_instruction->is_async_call_builtin, args_ptr, call_instruction->arg_count, ret_ptr,
1980019764 call_instruction->result_loc);
19801 deallocate(args_ptr, call_instruction->arg_count, "IrInstGen *");
19765 heap::c_allocator.deallocate(args_ptr, call_instruction->arg_count);
1980219766 return result;
1980319767}
1980419768
......@@ -19918,7 +19882,7 @@ static IrInstGen *ir_analyze_instruction_call_extra(IrAnalyze *ira, IrInstSrcCal
1991819882
1991919883 if (is_tuple(args_type)) {
1992019884 args_len = args_type->data.structure.src_field_count;
19921 args_ptr = allocate<IrInstGen *>(args_len, "IrInstGen *");
19885 args_ptr = heap::c_allocator.allocate<IrInstGen *>(args_len);
1992219886 for (size_t i = 0; i < args_len; i += 1) {
1992319887 TypeStructField *arg_field = args_type->data.structure.fields[i];
1992419888 args_ptr[i] = ir_analyze_struct_value_field_value(ira, &instruction->base.base, args, arg_field);
......@@ -19931,12 +19895,12 @@ static IrInstGen *ir_analyze_instruction_call_extra(IrAnalyze *ira, IrInstSrcCal
1993119895 }
1993219896 IrInstGen *result = ir_analyze_call_extra(ira, &instruction->base.base, instruction->options,
1993319897 instruction->fn_ref, args_ptr, args_len, instruction->result_loc);
19934 deallocate(args_ptr, args_len, "IrInstGen *");
19898 heap::c_allocator.deallocate(args_ptr, args_len);
1993519899 return result;
1993619900}
1993719901
1993819902static IrInstGen *ir_analyze_instruction_call_args(IrAnalyze *ira, IrInstSrcCallArgs *instruction) {
19939 IrInstGen **args_ptr = allocate<IrInstGen *>(instruction->args_len, "IrInstGen *");
19903 IrInstGen **args_ptr = heap::c_allocator.allocate<IrInstGen *>(instruction->args_len);
1994019904 for (size_t i = 0; i < instruction->args_len; i += 1) {
1994119905 args_ptr[i] = instruction->args_ptr[i]->child;
1994219906 if (type_is_invalid(args_ptr[i]->value->type))
......@@ -19945,7 +19909,7 @@ static IrInstGen *ir_analyze_instruction_call_args(IrAnalyze *ira, IrInstSrcCall
1994519909
1994619910 IrInstGen *result = ir_analyze_call_extra(ira, &instruction->base.base, instruction->options,
1994719911 instruction->fn_ref, args_ptr, instruction->args_len, instruction->result_loc);
19948 deallocate(args_ptr, instruction->args_len, "IrInstGen *");
19912 heap::c_allocator.deallocate(args_ptr, instruction->args_len);
1994919913 return result;
1995019914}
1995119915
......@@ -20020,7 +19984,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source
2002019984
2002119985 if (dst_size <= src_size) {
2002219986 if (src_size == dst_size && types_have_same_zig_comptime_repr(codegen, out_val->type, pointee->type)) {
20023 copy_const_val(out_val, pointee);
19987 copy_const_val(codegen, out_val, pointee);
2002419988 return ErrorNone;
2002519989 }
2002619990 Buf buf = BUF_INIT;
......@@ -20088,7 +20052,7 @@ static IrInstGen *ir_analyze_optional_type(IrAnalyze *ira, IrInstSrcUnOp *instru
2008820052 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type);
2008920053 result->value->special = ConstValSpecialLazy;
2009020054
20091 LazyValueOptType *lazy_opt_type = allocate<LazyValueOptType>(1, "LazyValueOptType");
20055 LazyValueOptType *lazy_opt_type = heap::c_allocator.create<LazyValueOptType>();
2009220056 lazy_opt_type->ira = ira; ira_ref(ira);
2009320057 result->value->data.x_lazy = &lazy_opt_type->base;
2009420058 lazy_opt_type->base.id = LazyValueIdOptType;
......@@ -20372,7 +20336,7 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i
2037220336
2037320337 if (value->value->special != ConstValSpecialRuntime) {
2037420338 IrInstGen *result = ir_const(ira, &phi_instruction->base.base, nullptr);
20375 copy_const_val(result->value, value->value);
20339 copy_const_val(ira->codegen, result->value, value->value);
2037620340 return result;
2037720341 } else {
2037820342 return value;
......@@ -20386,7 +20350,7 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i
2038620350 peer_parent->peers.length >= 2)
2038720351 {
2038820352 if (peer_parent->resolved_type == nullptr) {
20389 IrInstGen **instructions = allocate<IrInstGen *>(peer_parent->peers.length);
20353 IrInstGen **instructions = heap::c_allocator.allocate<IrInstGen *>(peer_parent->peers.length);
2039020354 for (size_t i = 0; i < peer_parent->peers.length; i += 1) {
2039120355 ResultLocPeer *this_peer = peer_parent->peers.at(i);
2039220356
......@@ -20759,7 +20723,7 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
2075920723 if (index == array_len && array_type->data.array.sentinel != nullptr) {
2076020724 ZigType *elem_type = array_type->data.array.child_type;
2076120725 IrInstGen *sentinel_elem = ir_const(ira, &elem_ptr_instruction->base.base, elem_type);
20762 copy_const_val(sentinel_elem->value, array_type->data.array.sentinel);
20726 copy_const_val(ira->codegen, sentinel_elem->value, array_type->data.array.sentinel);
2076320727 return ir_get_ref(ira, &elem_ptr_instruction->base.base, sentinel_elem, true, false);
2076420728 }
2076520729 if (index >= array_len) {
......@@ -20823,7 +20787,7 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
2082320787 {
2082420788 if (array_type->id == ZigTypeIdArray || array_type->id == ZigTypeIdVector) {
2082520789 array_ptr_val->data.x_array.special = ConstArraySpecialNone;
20826 array_ptr_val->data.x_array.data.s_none.elements = create_const_vals(array_type->data.array.len);
20790 array_ptr_val->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(array_type->data.array.len);
2082720791 array_ptr_val->special = ConstValSpecialStatic;
2082820792 for (size_t i = 0; i < array_type->data.array.len; i += 1) {
2082920793 ZigValue *elem_val = &array_ptr_val->data.x_array.data.s_none.elements[i];
......@@ -20846,11 +20810,11 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
2084620810 return ira->codegen->invalid_inst_gen;
2084720811 }
2084820812
20849 ZigValue *array_init_val = create_const_vals(1);
20813 ZigValue *array_init_val = ira->codegen->pass1_arena->create<ZigValue>();
2085020814 array_init_val->special = ConstValSpecialStatic;
2085120815 array_init_val->type = actual_array_type;
2085220816 array_init_val->data.x_array.special = ConstArraySpecialNone;
20853 array_init_val->data.x_array.data.s_none.elements = create_const_vals(actual_array_type->data.array.len);
20817 array_init_val->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(actual_array_type->data.array.len);
2085420818 array_init_val->special = ConstValSpecialStatic;
2085520819 for (size_t i = 0; i < actual_array_type->data.array.len; i += 1) {
2085620820 ZigValue *elem_val = &array_init_val->data.x_array.data.s_none.elements[i];
......@@ -21176,7 +21140,7 @@ static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_ins
2117621140 if (field->is_comptime) {
2117721141 IrInstGen *elem = ir_const(ira, source_instr, field_type);
2117821142 memoize_field_init_val(ira->codegen, struct_type, field);
21179 copy_const_val(elem->value, field->init_val);
21143 copy_const_val(ira->codegen, elem->value, field->init_val);
2118021144 return ir_get_ref2(ira, source_instr, elem, field_type, true, false);
2118121145 }
2118221146 switch (type_has_one_possible_value(ira->codegen, field_type)) {
......@@ -21224,7 +21188,7 @@ static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_ins
2122421188 if (type_is_invalid(struct_val->type))
2122521189 return ira->codegen->invalid_inst_gen;
2122621190 if (initializing && struct_val->special == ConstValSpecialUndef) {
21227 struct_val->data.x_struct.fields = alloc_const_vals_ptrs(struct_type->data.structure.src_field_count);
21191 struct_val->data.x_struct.fields = alloc_const_vals_ptrs(ira->codegen, struct_type->data.structure.src_field_count);
2122821192 struct_val->special = ConstValSpecialStatic;
2122921193 for (size_t i = 0; i < struct_type->data.structure.src_field_count; i += 1) {
2123021194 ZigValue *field_val = struct_val->data.x_struct.fields[i];
......@@ -21266,7 +21230,7 @@ static IrInstGen *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name,
2126621230 ZigType *container_ptr_type = container_ptr->value->type;
2126721231 ir_assert(container_ptr_type->id == ZigTypeIdPointer, source_instr);
2126821232
21269 InferredStructField *inferred_struct_field = allocate<InferredStructField>(1, "InferredStructField");
21233 InferredStructField *inferred_struct_field = heap::c_allocator.create<InferredStructField>();
2127021234 inferred_struct_field->inferred_struct_type = container_type;
2127121235 inferred_struct_field->field_name = field_name;
2127221236
......@@ -21286,7 +21250,7 @@ static IrInstGen *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name,
2128621250 } else {
2128721251 result = ir_const(ira, source_instr, field_ptr_type);
2128821252 }
21289 copy_const_val(result->value, ptr_val);
21253 copy_const_val(ira->codegen, result->value, ptr_val);
2129021254 result->value->type = field_ptr_type;
2129121255 return result;
2129221256 }
......@@ -21357,7 +21321,7 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name
2135721321 return ira->codegen->invalid_inst_gen;
2135821322
2135921323 if (initializing) {
21360 ZigValue *payload_val = create_const_vals(1);
21324 ZigValue *payload_val = ira->codegen->pass1_arena->create<ZigValue>();
2136121325 payload_val->special = ConstValSpecialUndef;
2136221326 payload_val->type = field_type;
2136321327 payload_val->parent.id = ConstParentIdUnion;
......@@ -21540,7 +21504,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
2154021504 }
2154121505 } else if (is_array_ref(container_type) && !field_ptr_instruction->initializing) {
2154221506 if (buf_eql_str(field_name, "len")) {
21543 ZigValue *len_val = create_const_vals(1);
21507 ZigValue *len_val = ira->codegen->pass1_arena->create<ZigValue>();
2154421508 if (container_type->id == ZigTypeIdPointer) {
2154521509 init_const_usize(ira->codegen, len_val, container_type->data.pointer.child_type->data.array.len);
2154621510 } else {
......@@ -21586,7 +21550,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
2158621550 bool ptr_is_const = true;
2158721551 bool ptr_is_volatile = false;
2158821552 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
21589 create_const_enum(child_type, &field->value), child_type,
21553 create_const_enum(ira->codegen, child_type, &field->value), child_type,
2159021554 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
2159121555 }
2159221556 }
......@@ -21615,7 +21579,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
2161521579 bool ptr_is_const = true;
2161621580 bool ptr_is_volatile = false;
2161721581 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
21618 create_const_enum(enum_type, &field->enum_field->value), enum_type,
21582 create_const_enum(ira->codegen, enum_type, &field->enum_field->value), enum_type,
2161921583 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
2162021584 }
2162121585 }
......@@ -21633,7 +21597,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
2163321597 if (existing_entry) {
2163421598 err_entry = existing_entry->value;
2163521599 } else {
21636 err_entry = allocate<ErrorTableEntry>(1);
21600 err_entry = heap::c_allocator.create<ErrorTableEntry>();
2163721601 err_entry->decl_node = field_ptr_instruction->base.base.source_node;
2163821602 buf_init_from_buf(&err_entry->name, field_name);
2163921603 size_t error_value_count = ira->codegen->errors_by_index.length;
......@@ -21660,7 +21624,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
2166021624 }
2166121625 err_set_type = child_type;
2166221626 }
21663 ZigValue *const_val = create_const_vals(1);
21627 ZigValue *const_val = ira->codegen->pass1_arena->create<ZigValue>();
2166421628 const_val->special = ConstValSpecialStatic;
2166521629 const_val->type = err_set_type;
2166621630 const_val->data.x_err_set = err_entry;
......@@ -21674,7 +21638,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
2167421638 bool ptr_is_const = true;
2167521639 bool ptr_is_volatile = false;
2167621640 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
21677 create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int,
21641 create_const_unsigned_negative(ira->codegen, ira->codegen->builtin_types.entry_num_lit_int,
2167821642 child_type->data.integral.bit_count, false),
2167921643 ira->codegen->builtin_types.entry_num_lit_int,
2168021644 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
......@@ -21696,7 +21660,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
2169621660 bool ptr_is_const = true;
2169721661 bool ptr_is_volatile = false;
2169821662 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
21699 create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int,
21663 create_const_unsigned_negative(ira->codegen, ira->codegen->builtin_types.entry_num_lit_int,
2170021664 child_type->data.floating.bit_count, false),
2170121665 ira->codegen->builtin_types.entry_num_lit_int,
2170221666 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
......@@ -21723,7 +21687,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
2172321687 return ira->codegen->invalid_inst_gen;
2172421688 }
2172521689 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
21726 create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int,
21690 create_const_unsigned_negative(ira->codegen, ira->codegen->builtin_types.entry_num_lit_int,
2172721691 get_ptr_align(ira->codegen, child_type), false),
2172821692 ira->codegen->builtin_types.entry_num_lit_int,
2172921693 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
......@@ -21745,7 +21709,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
2174521709 bool ptr_is_const = true;
2174621710 bool ptr_is_volatile = false;
2174721711 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
21748 create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int,
21712 create_const_unsigned_negative(ira->codegen, ira->codegen->builtin_types.entry_num_lit_int,
2174921713 child_type->data.array.len, false),
2175021714 ira->codegen->builtin_types.entry_num_lit_int,
2175121715 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
......@@ -22025,7 +21989,7 @@ static IrInstGen *ir_analyze_instruction_slice_type(IrAnalyze *ira, IrInstSrcSli
2202521989 IrInstGen *result = ir_const(ira, &slice_type_instruction->base.base, ira->codegen->builtin_types.entry_type);
2202621990 result->value->special = ConstValSpecialLazy;
2202721991
22028 LazyValueSliceType *lazy_slice_type = allocate<LazyValueSliceType>(1, "LazyValueSliceType");
21992 LazyValueSliceType *lazy_slice_type = heap::c_allocator.create<LazyValueSliceType>();
2202921993 lazy_slice_type->ira = ira; ira_ref(ira);
2203021994 result->value->data.x_lazy = &lazy_slice_type->base;
2203121995 lazy_slice_type->base.id = LazyValueIdSliceType;
......@@ -22098,8 +22062,8 @@ static IrInstGen *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstSrcAsm *asm_i
2209822062
2209922063 // TODO validate the output types and variable types
2210022064
22101 IrInstGen **input_list = allocate<IrInstGen *>(asm_expr->input_list.length);
22102 IrInstGen **output_types = allocate<IrInstGen *>(asm_expr->output_list.length);
22065 IrInstGen **input_list = heap::c_allocator.allocate<IrInstGen *>(asm_expr->input_list.length);
22066 IrInstGen **output_types = heap::c_allocator.allocate<IrInstGen *>(asm_expr->output_list.length);
2210322067
2210422068 ZigType *return_type = ira->codegen->builtin_types.entry_void;
2210522069 for (size_t i = 0; i < asm_expr->output_list.length; i += 1) {
......@@ -22138,7 +22102,7 @@ static IrInstGen *ir_analyze_instruction_array_type(IrAnalyze *ira, IrInstSrcArr
2213822102 IrInstGen *result = ir_const(ira, &array_type_instruction->base.base, ira->codegen->builtin_types.entry_type);
2213922103 result->value->special = ConstValSpecialLazy;
2214022104
22141 LazyValueArrayType *lazy_array_type = allocate<LazyValueArrayType>(1, "LazyValueArrayType");
22105 LazyValueArrayType *lazy_array_type = heap::c_allocator.create<LazyValueArrayType>();
2214222106 lazy_array_type->ira = ira; ira_ref(ira);
2214322107 result->value->data.x_lazy = &lazy_array_type->base;
2214422108 lazy_array_type->base.id = LazyValueIdArrayType;
......@@ -22163,7 +22127,7 @@ static IrInstGen *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstSrcSizeOf
2216322127 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int);
2216422128 result->value->special = ConstValSpecialLazy;
2216522129
22166 LazyValueSizeOf *lazy_size_of = allocate<LazyValueSizeOf>(1, "LazyValueSizeOf");
22130 LazyValueSizeOf *lazy_size_of = heap::c_allocator.create<LazyValueSizeOf>();
2216722131 lazy_size_of->ira = ira; ira_ref(ira);
2216822132 result->value->data.x_lazy = &lazy_size_of->base;
2216922133 lazy_size_of->base.id = LazyValueIdSizeOf;
......@@ -22283,7 +22247,7 @@ static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* sou
2228322247 return ira->codegen->invalid_inst_gen;
2228422248 case OnePossibleValueNo:
2228522249 if (!same_comptime_repr) {
22286 ZigValue *payload_val = create_const_vals(1);
22250 ZigValue *payload_val = ira->codegen->pass1_arena->create<ZigValue>();
2228722251 payload_val->type = child_type;
2228822252 payload_val->special = ConstValSpecialUndef;
2228922253 payload_val->parent.id = ConstParentIdOptionalPayload;
......@@ -22530,7 +22494,7 @@ static IrInstGen *ir_analyze_instruction_switch_br(IrAnalyze *ira,
2253022494 }
2253122495 }
2253222496
22533 IrInstGenSwitchBrCase *cases = allocate<IrInstGenSwitchBrCase>(case_count);
22497 IrInstGenSwitchBrCase *cases = heap::c_allocator.allocate<IrInstGenSwitchBrCase>(case_count);
2253422498 for (size_t i = 0; i < case_count; i += 1) {
2253522499 IrInstSrcSwitchBrCase *old_case = &switch_br_instruction->cases[i];
2253622500 IrInstGenSwitchBrCase *new_case = &cases[i];
......@@ -22615,7 +22579,7 @@ static IrInstGen *ir_analyze_instruction_switch_target(IrAnalyze *ira,
2261522579 case ZigTypeIdErrorSet: {
2261622580 if (pointee_val) {
2261722581 IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, nullptr);
22618 copy_const_val(result->value, pointee_val);
22582 copy_const_val(ira->codegen, result->value, pointee_val);
2261922583 result->value->type = target_type;
2262022584 return result;
2262122585 }
......@@ -22835,7 +22799,7 @@ static IrInstGen *ir_analyze_instruction_switch_else_var(IrAnalyze *ira,
2283522799 return target_value_ptr;
2283622800 }
2283722801 // Make note of the errors handled by other cases
22838 ErrorTableEntry **errors = allocate<ErrorTableEntry *>(ira->codegen->errors_by_index.length);
22802 ErrorTableEntry **errors = heap::c_allocator.allocate<ErrorTableEntry *>(ira->codegen->errors_by_index.length);
2283922803 // We may not have any case in the switch if this is a lone else
2284022804 const size_t switch_cases = instruction->switch_br ? instruction->switch_br->case_count : 0;
2284122805 for (size_t case_i = 0; case_i < switch_cases; case_i += 1) {
......@@ -22871,7 +22835,7 @@ static IrInstGen *ir_analyze_instruction_switch_else_var(IrAnalyze *ira,
2287122835 buf_appendf(&err_set_type->name, "%s,", buf_ptr(&error_entry->name));
2287222836 }
2287322837 }
22874 free(errors);
22838 heap::c_allocator.deallocate(errors, ira->codegen->errors_by_index.length);
2287522839
2287622840 err_set_type->data.error_set.err_count = result_list.length;
2287722841 err_set_type->data.error_set.errors = result_list.items;
......@@ -23019,7 +22983,7 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc
2301922983
2302022984 IrInstGen *first_non_const_instruction = nullptr;
2302122985
23022 AstNode **field_assign_nodes = allocate<AstNode *>(actual_field_count);
22986 AstNode **field_assign_nodes = heap::c_allocator.allocate<AstNode *>(actual_field_count);
2302322987 ZigList<IrInstGen *> const_ptrs = {};
2302422988
2302522989 bool is_comptime = ir_should_inline(ira->old_irb.exec, source_instr->scope)
......@@ -23090,7 +23054,7 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc
2309023054 return ira->codegen->invalid_inst_gen;
2309123055
2309223056 IrInstGen *runtime_inst = ir_const(ira, source_instr, field->init_val->type);
23093 copy_const_val(runtime_inst->value, field->init_val);
23057 copy_const_val(ira->codegen, runtime_inst->value, field->init_val);
2309423058
2309523059 IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, source_instr, field, result_loc,
2309623060 container_type, true);
......@@ -23354,7 +23318,7 @@ static IrInstGen *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstSrcErrNa
2335423318 err->cached_error_name_val = create_const_slice(ira->codegen, array_val, 0, buf_len(&err->name), true);
2335523319 }
2335623320 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
23357 copy_const_val(result->value, err->cached_error_name_val);
23321 copy_const_val(ira->codegen, result->value, err->cached_error_name_val);
2335823322 result->value->type = str_type;
2335923323 return result;
2336023324 }
......@@ -23680,11 +23644,11 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa
2368023644 }
2368123645 }
2368223646
23683 ZigValue *declaration_array = create_const_vals(1);
23647 ZigValue *declaration_array = ira->codegen->pass1_arena->create<ZigValue>();
2368423648 declaration_array->special = ConstValSpecialStatic;
2368523649 declaration_array->type = get_array_type(ira->codegen, type_info_declaration_type, declaration_count, nullptr);
2368623650 declaration_array->data.x_array.special = ConstArraySpecialNone;
23687 declaration_array->data.x_array.data.s_none.elements = create_const_vals(declaration_count);
23651 declaration_array->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(declaration_count);
2368823652 init_const_slice(ira->codegen, out_val, declaration_array, 0, declaration_count, false);
2368923653
2369023654 // Loop through the declarations and generate info.
......@@ -23706,7 +23670,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa
2370623670 declaration_val->special = ConstValSpecialStatic;
2370723671 declaration_val->type = type_info_declaration_type;
2370823672
23709 ZigValue **inner_fields = alloc_const_vals_ptrs(3);
23673 ZigValue **inner_fields = alloc_const_vals_ptrs(ira->codegen, 3);
2371023674 ZigValue *name = create_const_str_lit(ira->codegen, curr_entry->key)->data.x_ptr.data.ref.pointee;
2371123675 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(curr_entry->key), true);
2371223676 inner_fields[1]->special = ConstValSpecialStatic;
......@@ -23737,7 +23701,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa
2373723701 // 1: Data.Var: type
2373823702 bigint_init_unsigned(&inner_fields[2]->data.x_union.tag, 1);
2373923703
23740 ZigValue *payload = create_const_vals(1);
23704 ZigValue *payload = ira->codegen->pass1_arena->create<ZigValue>();
2374123705 payload->special = ConstValSpecialStatic;
2374223706 payload->type = ira->codegen->builtin_types.entry_type;
2374323707 payload->data.x_type = var->const_value->type;
......@@ -23758,13 +23722,13 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa
2375823722
2375923723 AstNodeFnProto *fn_node = &fn_entry->proto_node->data.fn_proto;
2376023724
23761 ZigValue *fn_decl_val = create_const_vals(1);
23725 ZigValue *fn_decl_val = ira->codegen->pass1_arena->create<ZigValue>();
2376223726 fn_decl_val->special = ConstValSpecialStatic;
2376323727 fn_decl_val->type = type_info_fn_decl_type;
2376423728 fn_decl_val->parent.id = ConstParentIdUnion;
2376523729 fn_decl_val->parent.data.p_union.union_val = inner_fields[2];
2376623730
23767 ZigValue **fn_decl_fields = alloc_const_vals_ptrs(9);
23731 ZigValue **fn_decl_fields = alloc_const_vals_ptrs(ira->codegen, 9);
2376823732 fn_decl_val->data.x_struct.fields = fn_decl_fields;
2376923733
2377023734 // fn_type: type
......@@ -23802,7 +23766,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa
2380223766 0, 0, 0, false);
2380323767 fn_decl_fields[5]->type = get_optional_type(ira->codegen, get_slice_type(ira->codegen, u8_ptr));
2380423768 if (fn_node->is_extern && fn_node->lib_name != nullptr && buf_len(fn_node->lib_name) > 0) {
23805 fn_decl_fields[5]->data.x_optional = create_const_vals(1);
23769 fn_decl_fields[5]->data.x_optional = ira->codegen->pass1_arena->create<ZigValue>();
2380623770 ZigValue *lib_name = create_const_str_lit(ira->codegen, fn_node->lib_name)->data.x_ptr.data.ref.pointee;
2380723771 init_const_slice(ira->codegen, fn_decl_fields[5]->data.x_optional, lib_name, 0,
2380823772 buf_len(fn_node->lib_name), true);
......@@ -23817,12 +23781,12 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa
2381723781 // arg_names: [][] const u8
2381823782 ensure_field_index(fn_decl_val->type, "arg_names", 7);
2381923783 size_t fn_arg_count = fn_entry->variable_list.length;
23820 ZigValue *fn_arg_name_array = create_const_vals(1);
23784 ZigValue *fn_arg_name_array = ira->codegen->pass1_arena->create<ZigValue>();
2382123785 fn_arg_name_array->special = ConstValSpecialStatic;
2382223786 fn_arg_name_array->type = get_array_type(ira->codegen,
2382323787 get_slice_type(ira->codegen, u8_ptr), fn_arg_count, nullptr);
2382423788 fn_arg_name_array->data.x_array.special = ConstArraySpecialNone;
23825 fn_arg_name_array->data.x_array.data.s_none.elements = create_const_vals(fn_arg_count);
23789 fn_arg_name_array->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(fn_arg_count);
2382623790
2382723791 init_const_slice(ira->codegen, fn_decl_fields[7], fn_arg_name_array, 0, fn_arg_count, false);
2382823792
......@@ -23849,7 +23813,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa
2384923813 // This is a type.
2385023814 bigint_init_unsigned(&inner_fields[2]->data.x_union.tag, 0);
2385123815
23852 ZigValue *payload = create_const_vals(1);
23816 ZigValue *payload = ira->codegen->pass1_arena->create<ZigValue>();
2385323817 payload->special = ConstValSpecialStatic;
2385423818 payload->type = ira->codegen->builtin_types.entry_type;
2385523819 payload->data.x_type = type_entry;
......@@ -23915,11 +23879,11 @@ static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_type_ent
2391523879 ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr);
2391623880 assertNoError(type_resolve(ira->codegen, type_info_pointer_type, ResolveStatusSizeKnown));
2391723881
23918 ZigValue *result = create_const_vals(1);
23882 ZigValue *result = ira->codegen->pass1_arena->create<ZigValue>();
2391923883 result->special = ConstValSpecialStatic;
2392023884 result->type = type_info_pointer_type;
2392123885
23922 ZigValue **fields = alloc_const_vals_ptrs(7);
23886 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 7);
2392323887 result->data.x_struct.fields = fields;
2392423888
2392523889 // size: Size
......@@ -23974,7 +23938,7 @@ static void make_enum_field_val(IrAnalyze *ira, ZigValue *enum_field_val, TypeEn
2397423938 enum_field_val->special = ConstValSpecialStatic;
2397523939 enum_field_val->type = type_info_enum_field_type;
2397623940
23977 ZigValue **inner_fields = alloc_const_vals_ptrs(2);
23941 ZigValue **inner_fields = alloc_const_vals_ptrs(ira->codegen, 2);
2397823942 inner_fields[1]->special = ConstValSpecialStatic;
2397923943 inner_fields[1]->type = ira->codegen->builtin_types.entry_num_lit_int;
2398023944
......@@ -24020,11 +23984,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2402023984 break;
2402123985 case ZigTypeIdInt:
2402223986 {
24023 result = create_const_vals(1);
23987 result = ira->codegen->pass1_arena->create<ZigValue>();
2402423988 result->special = ConstValSpecialStatic;
2402523989 result->type = ir_type_info_get_type(ira, "Int", nullptr);
2402623990
24027 ZigValue **fields = alloc_const_vals_ptrs(2);
23991 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 2);
2402823992 result->data.x_struct.fields = fields;
2402923993
2403023994 // is_signed: bool
......@@ -24042,11 +24006,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2404224006 }
2404324007 case ZigTypeIdFloat:
2404424008 {
24045 result = create_const_vals(1);
24009 result = ira->codegen->pass1_arena->create<ZigValue>();
2404624010 result->special = ConstValSpecialStatic;
2404724011 result->type = ir_type_info_get_type(ira, "Float", nullptr);
2404824012
24049 ZigValue **fields = alloc_const_vals_ptrs(1);
24013 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 1);
2405024014 result->data.x_struct.fields = fields;
2405124015
2405224016 // bits: u8
......@@ -24066,11 +24030,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2406624030 }
2406724031 case ZigTypeIdArray:
2406824032 {
24069 result = create_const_vals(1);
24033 result = ira->codegen->pass1_arena->create<ZigValue>();
2407024034 result->special = ConstValSpecialStatic;
2407124035 result->type = ir_type_info_get_type(ira, "Array", nullptr);
2407224036
24073 ZigValue **fields = alloc_const_vals_ptrs(3);
24037 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 3);
2407424038 result->data.x_struct.fields = fields;
2407524039
2407624040 // len: usize
......@@ -24090,11 +24054,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2409024054 break;
2409124055 }
2409224056 case ZigTypeIdVector: {
24093 result = create_const_vals(1);
24057 result = ira->codegen->pass1_arena->create<ZigValue>();
2409424058 result->special = ConstValSpecialStatic;
2409524059 result->type = ir_type_info_get_type(ira, "Vector", nullptr);
2409624060
24097 ZigValue **fields = alloc_const_vals_ptrs(2);
24061 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 2);
2409824062 result->data.x_struct.fields = fields;
2409924063
2410024064 // len: usize
......@@ -24112,11 +24076,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2411224076 }
2411324077 case ZigTypeIdOptional:
2411424078 {
24115 result = create_const_vals(1);
24079 result = ira->codegen->pass1_arena->create<ZigValue>();
2411624080 result->special = ConstValSpecialStatic;
2411724081 result->type = ir_type_info_get_type(ira, "Optional", nullptr);
2411824082
24119 ZigValue **fields = alloc_const_vals_ptrs(1);
24083 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 1);
2412024084 result->data.x_struct.fields = fields;
2412124085
2412224086 // child: type
......@@ -24128,11 +24092,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2412824092 break;
2412924093 }
2413024094 case ZigTypeIdAnyFrame: {
24131 result = create_const_vals(1);
24095 result = ira->codegen->pass1_arena->create<ZigValue>();
2413224096 result->special = ConstValSpecialStatic;
2413324097 result->type = ir_type_info_get_type(ira, "AnyFrame", nullptr);
2413424098
24135 ZigValue **fields = alloc_const_vals_ptrs(1);
24099 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 1);
2413624100 result->data.x_struct.fields = fields;
2413724101
2413824102 // child: ?type
......@@ -24145,11 +24109,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2414524109 }
2414624110 case ZigTypeIdEnum:
2414724111 {
24148 result = create_const_vals(1);
24112 result = ira->codegen->pass1_arena->create<ZigValue>();
2414924113 result->special = ConstValSpecialStatic;
2415024114 result->type = ir_type_info_get_type(ira, "Enum", nullptr);
2415124115
24152 ZigValue **fields = alloc_const_vals_ptrs(5);
24116 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 5);
2415324117 result->data.x_struct.fields = fields;
2415424118
2415524119 // layout: ContainerLayout
......@@ -24171,11 +24135,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2417124135 }
2417224136 uint32_t enum_field_count = type_entry->data.enumeration.src_field_count;
2417324137
24174 ZigValue *enum_field_array = create_const_vals(1);
24138 ZigValue *enum_field_array = ira->codegen->pass1_arena->create<ZigValue>();
2417524139 enum_field_array->special = ConstValSpecialStatic;
2417624140 enum_field_array->type = get_array_type(ira->codegen, type_info_enum_field_type, enum_field_count, nullptr);
2417724141 enum_field_array->data.x_array.special = ConstArraySpecialNone;
24178 enum_field_array->data.x_array.data.s_none.elements = create_const_vals(enum_field_count);
24142 enum_field_array->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(enum_field_count);
2417924143
2418024144 init_const_slice(ira->codegen, fields[2], enum_field_array, 0, enum_field_count, false);
2418124145
......@@ -24205,7 +24169,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2420524169 }
2420624170 case ZigTypeIdErrorSet:
2420724171 {
24208 result = create_const_vals(1);
24172 result = ira->codegen->pass1_arena->create<ZigValue>();
2420924173 result->special = ConstValSpecialStatic;
2421024174 result->type = ir_type_info_get_type(ira, "ErrorSet", nullptr);
2421124175
......@@ -24220,15 +24184,15 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2422024184 if ((err = type_resolve(ira->codegen, type_info_error_type, ResolveStatusSizeKnown))) {
2422124185 zig_unreachable();
2422224186 }
24223 ZigValue *slice_val = create_const_vals(1);
24187 ZigValue *slice_val = ira->codegen->pass1_arena->create<ZigValue>();
2422424188 result->data.x_optional = slice_val;
2422524189
2422624190 uint32_t error_count = type_entry->data.error_set.err_count;
24227 ZigValue *error_array = create_const_vals(1);
24191 ZigValue *error_array = ira->codegen->pass1_arena->create<ZigValue>();
2422824192 error_array->special = ConstValSpecialStatic;
2422924193 error_array->type = get_array_type(ira->codegen, type_info_error_type, error_count, nullptr);
2423024194 error_array->data.x_array.special = ConstArraySpecialNone;
24231 error_array->data.x_array.data.s_none.elements = create_const_vals(error_count);
24195 error_array->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(error_count);
2423224196
2423324197 init_const_slice(ira->codegen, slice_val, error_array, 0, error_count, false);
2423424198 for (uint32_t error_index = 0; error_index < error_count; error_index++) {
......@@ -24238,7 +24202,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2423824202 error_val->special = ConstValSpecialStatic;
2423924203 error_val->type = type_info_error_type;
2424024204
24241 ZigValue **inner_fields = alloc_const_vals_ptrs(2);
24205 ZigValue **inner_fields = alloc_const_vals_ptrs(ira->codegen, 2);
2424224206 inner_fields[1]->special = ConstValSpecialStatic;
2424324207 inner_fields[1]->type = ira->codegen->builtin_types.entry_num_lit_int;
2424424208
......@@ -24260,11 +24224,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2426024224 }
2426124225 case ZigTypeIdErrorUnion:
2426224226 {
24263 result = create_const_vals(1);
24227 result = ira->codegen->pass1_arena->create<ZigValue>();
2426424228 result->special = ConstValSpecialStatic;
2426524229 result->type = ir_type_info_get_type(ira, "ErrorUnion", nullptr);
2426624230
24267 ZigValue **fields = alloc_const_vals_ptrs(2);
24231 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 2);
2426824232 result->data.x_struct.fields = fields;
2426924233
2427024234 // error_set: type
......@@ -24283,11 +24247,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2428324247 }
2428424248 case ZigTypeIdUnion:
2428524249 {
24286 result = create_const_vals(1);
24250 result = ira->codegen->pass1_arena->create<ZigValue>();
2428724251 result->special = ConstValSpecialStatic;
2428824252 result->type = ir_type_info_get_type(ira, "Union", nullptr);
2428924253
24290 ZigValue **fields = alloc_const_vals_ptrs(4);
24254 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 4);
2429124255 result->data.x_struct.fields = fields;
2429224256
2429324257 // layout: ContainerLayout
......@@ -24304,7 +24268,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2430424268 if (union_decl_node->data.container_decl.auto_enum ||
2430524269 union_decl_node->data.container_decl.init_arg_expr != nullptr)
2430624270 {
24307 ZigValue *tag_type = create_const_vals(1);
24271 ZigValue *tag_type = ira->codegen->pass1_arena->create<ZigValue>();
2430824272 tag_type->special = ConstValSpecialStatic;
2430924273 tag_type->type = ira->codegen->builtin_types.entry_type;
2431024274 tag_type->data.x_type = type_entry->data.unionation.tag_type;
......@@ -24320,11 +24284,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2432024284 zig_unreachable();
2432124285 uint32_t union_field_count = type_entry->data.unionation.src_field_count;
2432224286
24323 ZigValue *union_field_array = create_const_vals(1);
24287 ZigValue *union_field_array = ira->codegen->pass1_arena->create<ZigValue>();
2432424288 union_field_array->special = ConstValSpecialStatic;
2432524289 union_field_array->type = get_array_type(ira->codegen, type_info_union_field_type, union_field_count, nullptr);
2432624290 union_field_array->data.x_array.special = ConstArraySpecialNone;
24327 union_field_array->data.x_array.data.s_none.elements = create_const_vals(union_field_count);
24291 union_field_array->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(union_field_count);
2432824292
2432924293 init_const_slice(ira->codegen, fields[2], union_field_array, 0, union_field_count, false);
2433024294
......@@ -24337,14 +24301,14 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2433724301 union_field_val->special = ConstValSpecialStatic;
2433824302 union_field_val->type = type_info_union_field_type;
2433924303
24340 ZigValue **inner_fields = alloc_const_vals_ptrs(3);
24304 ZigValue **inner_fields = alloc_const_vals_ptrs(ira->codegen, 3);
2434124305 inner_fields[1]->special = ConstValSpecialStatic;
2434224306 inner_fields[1]->type = get_optional_type(ira->codegen, type_info_enum_field_type);
2434324307
2434424308 if (fields[1]->data.x_optional == nullptr) {
2434524309 inner_fields[1]->data.x_optional = nullptr;
2434624310 } else {
24347 inner_fields[1]->data.x_optional = create_const_vals(1);
24311 inner_fields[1]->data.x_optional = ira->codegen->pass1_arena->create<ZigValue>();
2434824312 make_enum_field_val(ira, inner_fields[1]->data.x_optional, union_field->enum_field, type_info_enum_field_type);
2434924313 }
2435024314
......@@ -24379,11 +24343,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2437924343 break;
2438024344 }
2438124345
24382 result = create_const_vals(1);
24346 result = ira->codegen->pass1_arena->create<ZigValue>();
2438324347 result->special = ConstValSpecialStatic;
2438424348 result->type = ir_type_info_get_type(ira, "Struct", nullptr);
2438524349
24386 ZigValue **fields = alloc_const_vals_ptrs(3);
24350 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 3);
2438724351 result->data.x_struct.fields = fields;
2438824352
2438924353 // layout: ContainerLayout
......@@ -24400,11 +24364,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2440024364 }
2440124365 uint32_t struct_field_count = type_entry->data.structure.src_field_count;
2440224366
24403 ZigValue *struct_field_array = create_const_vals(1);
24367 ZigValue *struct_field_array = ira->codegen->pass1_arena->create<ZigValue>();
2440424368 struct_field_array->special = ConstValSpecialStatic;
2440524369 struct_field_array->type = get_array_type(ira->codegen, type_info_struct_field_type, struct_field_count, nullptr);
2440624370 struct_field_array->data.x_array.special = ConstArraySpecialNone;
24407 struct_field_array->data.x_array.data.s_none.elements = create_const_vals(struct_field_count);
24371 struct_field_array->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(struct_field_count);
2440824372
2440924373 init_const_slice(ira->codegen, fields[1], struct_field_array, 0, struct_field_count, false);
2441024374
......@@ -24415,7 +24379,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2441524379 struct_field_val->special = ConstValSpecialStatic;
2441624380 struct_field_val->type = type_info_struct_field_type;
2441724381
24418 ZigValue **inner_fields = alloc_const_vals_ptrs(4);
24382 ZigValue **inner_fields = alloc_const_vals_ptrs(ira->codegen, 4);
2441924383 inner_fields[1]->special = ConstValSpecialStatic;
2442024384 inner_fields[1]->type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_num_lit_int);
2442124385
......@@ -24428,7 +24392,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2442824392 inner_fields[1]->data.x_optional = nullptr;
2442924393 } else {
2443024394 size_t byte_offset = struct_field->offset;
24431 inner_fields[1]->data.x_optional = create_const_vals(1);
24395 inner_fields[1]->data.x_optional = ira->codegen->pass1_arena->create<ZigValue>();
2443224396 inner_fields[1]->data.x_optional->special = ConstValSpecialStatic;
2443324397 inner_fields[1]->data.x_optional->type = ira->codegen->builtin_types.entry_num_lit_int;
2443424398 bigint_init_unsigned(&inner_fields[1]->data.x_optional->data.x_bigint, byte_offset);
......@@ -24464,11 +24428,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2446424428 }
2446524429 case ZigTypeIdFn:
2446624430 {
24467 result = create_const_vals(1);
24431 result = ira->codegen->pass1_arena->create<ZigValue>();
2446824432 result->special = ConstValSpecialStatic;
2446924433 result->type = ir_type_info_get_type(ira, "Fn", nullptr);
2447024434
24471 ZigValue **fields = alloc_const_vals_ptrs(5);
24435 ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 5);
2447224436 result->data.x_struct.fields = fields;
2447324437
2447424438 // calling_convention: TypeInfo.CallingConvention
......@@ -24495,7 +24459,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2449524459 if (type_entry->data.fn.fn_type_id.return_type == nullptr)
2449624460 fields[3]->data.x_optional = nullptr;
2449724461 else {
24498 ZigValue *return_type = create_const_vals(1);
24462 ZigValue *return_type = ira->codegen->pass1_arena->create<ZigValue>();
2449924463 return_type->special = ConstValSpecialStatic;
2450024464 return_type->type = ira->codegen->builtin_types.entry_type;
2450124465 return_type->data.x_type = type_entry->data.fn.fn_type_id.return_type;
......@@ -24509,11 +24473,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2450924473 size_t fn_arg_count = type_entry->data.fn.fn_type_id.param_count -
2451024474 (is_varargs && type_entry->data.fn.fn_type_id.cc != CallingConventionC);
2451124475
24512 ZigValue *fn_arg_array = create_const_vals(1);
24476 ZigValue *fn_arg_array = ira->codegen->pass1_arena->create<ZigValue>();
2451324477 fn_arg_array->special = ConstValSpecialStatic;
2451424478 fn_arg_array->type = get_array_type(ira->codegen, type_info_fn_arg_type, fn_arg_count, nullptr);
2451524479 fn_arg_array->data.x_array.special = ConstArraySpecialNone;
24516 fn_arg_array->data.x_array.data.s_none.elements = create_const_vals(fn_arg_count);
24480 fn_arg_array->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(fn_arg_count);
2451724481
2451824482 init_const_slice(ira->codegen, fields[4], fn_arg_array, 0, fn_arg_count, false);
2451924483
......@@ -24527,7 +24491,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2452724491 bool arg_is_generic = fn_param_info->type == nullptr;
2452824492 if (arg_is_generic) assert(is_generic);
2452924493
24530 ZigValue **inner_fields = alloc_const_vals_ptrs(3);
24494 ZigValue **inner_fields = alloc_const_vals_ptrs(ira->codegen, 3);
2453124495 inner_fields[0]->special = ConstValSpecialStatic;
2453224496 inner_fields[0]->type = ira->codegen->builtin_types.entry_bool;
2453324497 inner_fields[0]->data.x_bool = arg_is_generic;
......@@ -24540,7 +24504,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
2454024504 if (arg_is_generic)
2454124505 inner_fields[2]->data.x_optional = nullptr;
2454224506 else {
24543 ZigValue *arg_type = create_const_vals(1);
24507 ZigValue *arg_type = ira->codegen->pass1_arena->create<ZigValue>();
2454424508 arg_type->special = ConstValSpecialStatic;
2454524509 arg_type->type = ira->codegen->builtin_types.entry_type;
2454624510 arg_type->data.x_type = fn_param_info->type;
......@@ -24866,7 +24830,7 @@ static IrInstGen *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstSrcType
2486624830 type_entry->cached_const_name_val = create_const_str_lit(ira->codegen, type_bare_name(type_entry));
2486724831 }
2486824832 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
24869 copy_const_val(result->value, type_entry->cached_const_name_val);
24833 copy_const_val(ira->codegen, result->value, type_entry->cached_const_name_val);
2487024834 return result;
2487124835}
2487224836
......@@ -24898,7 +24862,6 @@ static IrInstGen *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstSrcCImpo
2489824862 }
2489924863 if (type_is_invalid(cimport_result->type))
2490024864 return ira->codegen->invalid_inst_gen;
24901 destroy(result_ptr, "ZigValue");
2490224865
2490324866 ZigPackage *cur_scope_pkg = scope_package(instruction->base.base.scope);
2490424867 Buf *namespace_name = buf_sprintf("%s.cimport:%" ZIG_PRI_usize ":%" ZIG_PRI_usize,
......@@ -25577,11 +25540,11 @@ static IrInstGen *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstSrcToByt
2557725540 return ira->codegen->invalid_inst_gen;
2557825541
2557925542 IrInstGen *result = ir_const(ira, &instruction->base.base, dest_slice_type);
25580 result->value->data.x_struct.fields = alloc_const_vals_ptrs(2);
25543 result->value->data.x_struct.fields = alloc_const_vals_ptrs(ira->codegen, 2);
2558125544
2558225545 ZigValue *ptr_val = result->value->data.x_struct.fields[slice_ptr_index];
2558325546 ZigValue *target_ptr_val = target_val->data.x_struct.fields[slice_ptr_index];
25584 copy_const_val(ptr_val, target_ptr_val);
25547 copy_const_val(ira->codegen, ptr_val, target_ptr_val);
2558525548 ptr_val->type = dest_ptr_type;
2558625549
2558725550 ZigValue *len_val = result->value->data.x_struct.fields[slice_len_index];
......@@ -25868,7 +25831,7 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr
2586825831 expand_undef_array(ira->codegen, b_val);
2586925832
2587025833 IrInstGen *result = ir_const(ira, source_instr, result_type);
25871 result->value->data.x_array.data.s_none.elements = create_const_vals(len_mask);
25834 result->value->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(len_mask);
2587225835 for (uint32_t i = 0; i < mask_val->type->data.vector.len; i += 1) {
2587325836 ZigValue *mask_elem_val = &mask_val->data.x_array.data.s_none.elements[i];
2587425837 ZigValue *result_elem_val = &result->value->data.x_array.data.s_none.elements[i];
......@@ -25881,7 +25844,7 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr
2588125844 ZigValue *src_elem_val = (v >= 0) ?
2588225845 &a->value->data.x_array.data.s_none.elements[v] :
2588325846 &b->value->data.x_array.data.s_none.elements[~v];
25884 copy_const_val(result_elem_val, src_elem_val);
25847 copy_const_val(ira->codegen, result_elem_val, src_elem_val);
2588525848
2588625849 ir_assert(result_elem_val->special == ConstValSpecialStatic, source_instr);
2588725850 }
......@@ -25901,7 +25864,7 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr
2590125864
2590225865 IrInstGen *expand_mask = ir_const(ira, &mask->base,
2590325866 get_vector_type(ira->codegen, len_max, ira->codegen->builtin_types.entry_i32));
25904 expand_mask->value->data.x_array.data.s_none.elements = create_const_vals(len_max);
25867 expand_mask->value->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(len_max);
2590525868 uint32_t i = 0;
2590625869 for (; i < len_min; i += 1)
2590725870 bigint_init_unsigned(&expand_mask->value->data.x_array.data.s_none.elements[i].data.x_bigint, i);
......@@ -25971,9 +25934,9 @@ static IrInstGen *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstSrcSplat *i
2597125934 return ir_const_undef(ira, &instruction->base.base, return_type);
2597225935
2597325936 IrInstGen *result = ir_const(ira, &instruction->base.base, return_type);
25974 result->value->data.x_array.data.s_none.elements = create_const_vals(len_int);
25937 result->value->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(len_int);
2597525938 for (uint32_t i = 0; i < len_int; i += 1) {
25976 copy_const_val(&result->value->data.x_array.data.s_none.elements[i], scalar_val);
25939 copy_const_val(ira->codegen, &result->value->data.x_array.data.s_none.elements[i], scalar_val);
2597725940 }
2597825941 return result;
2597925942 }
......@@ -26111,7 +26074,7 @@ static IrInstGen *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstSrcMemset
2611126074 }
2611226075
2611326076 for (size_t i = start; i < end; i += 1) {
26114 copy_const_val(&dest_elements[i], byte_val);
26077 copy_const_val(ira->codegen, &dest_elements[i], byte_val);
2611526078 }
2611626079
2611726080 return ir_const_void(ira, &instruction->base.base);
......@@ -26287,7 +26250,7 @@ static IrInstGen *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstSrcMemcpy
2628726250 // TODO check for noalias violations - this should be generalized to work for any function
2628826251
2628926252 for (size_t i = 0; i < count; i += 1) {
26290 copy_const_val(&dest_elements[dest_start + i], &src_elements[src_start + i]);
26253 copy_const_val(ira->codegen, &dest_elements[dest_start + i], &src_elements[src_start + i]);
2629126254 }
2629226255
2629326256 return ir_const_void(ira, &instruction->base.base);
......@@ -26571,7 +26534,7 @@ static IrInstGen *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstSrcSlice *i
2657126534
2657226535 IrInstGen *result = ir_const(ira, &instruction->base.base, return_type);
2657326536 ZigValue *out_val = result->value;
26574 out_val->data.x_struct.fields = alloc_const_vals_ptrs(2);
26537 out_val->data.x_struct.fields = alloc_const_vals_ptrs(ira->codegen, 2);
2657526538
2657626539 ZigValue *ptr_val = out_val->data.x_struct.fields[slice_ptr_index];
2657726540
......@@ -26866,7 +26829,7 @@ static IrInstGen *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstSrcAlign
2686626829 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int);
2686726830 result->value->special = ConstValSpecialLazy;
2686826831
26869 LazyValueAlignOf *lazy_align_of = allocate<LazyValueAlignOf>(1, "LazyValueAlignOf");
26832 LazyValueAlignOf *lazy_align_of = heap::c_allocator.create<LazyValueAlignOf>();
2687026833 lazy_align_of->ira = ira; ira_ref(ira);
2687126834 result->value->data.x_lazy = &lazy_align_of->base;
2687226835 lazy_align_of->base.id = LazyValueIdAlignOf;
......@@ -27192,7 +27155,7 @@ static IrInstGen *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInst* source_inst
2719227155 return ira->codegen->invalid_inst_gen;
2719327156
2719427157 if (initializing && err_union_val->special == ConstValSpecialUndef) {
27195 ZigValue *vals = create_const_vals(2);
27158 ZigValue *vals = ira->codegen->pass1_arena->allocate<ZigValue>(2);
2719627159 ZigValue *err_set_val = &vals[0];
2719727160 ZigValue *payload_val = &vals[1];
2719827161
......@@ -27273,7 +27236,7 @@ static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInst* source
2727327236 if (err_union_val == nullptr)
2727427237 return ira->codegen->invalid_inst_gen;
2727527238 if (initializing && err_union_val->special == ConstValSpecialUndef) {
27276 ZigValue *vals = create_const_vals(2);
27239 ZigValue *vals = ira->codegen->pass1_arena->allocate<ZigValue>(2);
2727727240 ZigValue *err_set_val = &vals[0];
2727827241 ZigValue *payload_val = &vals[1];
2727927242
......@@ -27335,7 +27298,7 @@ static IrInstGen *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstSrcFnPro
2733527298 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type);
2733627299 result->value->special = ConstValSpecialLazy;
2733727300
27338 LazyValueFnType *lazy_fn_type = allocate<LazyValueFnType>(1, "LazyValueFnType");
27301 LazyValueFnType *lazy_fn_type = heap::c_allocator.create<LazyValueFnType>();
2733927302 lazy_fn_type->ira = ira; ira_ref(ira);
2734027303 result->value->data.x_lazy = &lazy_fn_type->base;
2734127304 lazy_fn_type->base.id = LazyValueIdFnType;
......@@ -27363,7 +27326,7 @@ static IrInstGen *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstSrcFnPro
2736327326
2736427327 size_t param_count = proto_node->data.fn_proto.params.length;
2736527328 lazy_fn_type->proto_node = proto_node;
27366 lazy_fn_type->param_types = allocate<IrInstGen *>(param_count);
27329 lazy_fn_type->param_types = heap::c_allocator.allocate<IrInstGen *>(param_count);
2736727330
2736827331 for (size_t param_index = 0; param_index < param_count; param_index += 1) {
2736927332 AstNode *param_node = proto_node->data.fn_proto.params.at(param_index);
......@@ -27518,7 +27481,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2751827481 }
2751927482
2752027483 size_t field_prev_uses_count = ira->codegen->errors_by_index.length;
27521 AstNode **field_prev_uses = allocate<AstNode *>(field_prev_uses_count, "AstNode *");
27484 AstNode **field_prev_uses = heap::c_allocator.allocate<AstNode *>(field_prev_uses_count);
2752227485
2752327486 for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) {
2752427487 IrInstSrcCheckSwitchProngsRange *range = &instruction->ranges[range_i];
......@@ -27575,7 +27538,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2757527538 }
2757627539 }
2757727540
27578 deallocate(field_prev_uses, field_prev_uses_count, "AstNode *");
27541 heap::c_allocator.deallocate(field_prev_uses, field_prev_uses_count);
2757927542 } else if (switch_type->id == ZigTypeIdInt) {
2758027543 RangeSet rs = {0};
2758127544 for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) {
......@@ -27768,7 +27731,7 @@ static IrInstGen *ir_align_cast(IrAnalyze *ira, IrInstGen *target, uint32_t alig
2776827731 }
2776927732
2777027733 IrInstGen *result = ir_const(ira, &target->base, result_type);
27771 copy_const_val(result->value, val);
27734 copy_const_val(ira->codegen, result->value, val);
2777227735 result->value->type = result_type;
2777327736 return result;
2777427737 }
......@@ -27864,7 +27827,7 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn
2786427827 InferredStructField *isf = (val->type->id == ZigTypeIdPointer) ?
2786527828 val->type->data.pointer.inferred_struct_field : nullptr;
2786627829 if (isf == nullptr) {
27867 copy_const_val(result->value, val);
27830 copy_const_val(ira->codegen, result->value, val);
2786827831 } else {
2786927832 // The destination value should have x_ptr struct pointing to underlying struct value
2787027833 result->value->data.x_ptr.mut = val->data.x_ptr.mut;
......@@ -28021,7 +27984,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ZigValue *val)
2802127984 while (gen_i < gen_field_count) {
2802227985 size_t big_int_byte_count = val->type->data.structure.host_int_bytes[gen_i];
2802327986 if (big_int_byte_count > child_buf_len) {
28024 child_buf = allocate_nonzero<uint8_t>(big_int_byte_count);
27987 child_buf = heap::c_allocator.allocate_nonzero<uint8_t>(big_int_byte_count);
2802527988 child_buf_len = big_int_byte_count;
2802627989 }
2802727990 BigInt big_int;
......@@ -28084,7 +28047,7 @@ static Error buf_read_value_bytes_array(IrAnalyze *ira, CodeGen *codegen, AstNod
2808428047
2808528048 switch (val->data.x_array.special) {
2808628049 case ConstArraySpecialNone:
28087 val->data.x_array.data.s_none.elements = create_const_vals(len);
28050 val->data.x_array.data.s_none.elements = codegen->pass1_arena->allocate<ZigValue>(len);
2808828051 for (size_t i = 0; i < len; i++) {
2808928052 ZigValue *elem = &val->data.x_array.data.s_none.elements[i];
2809028053 elem->special = ConstValSpecialStatic;
......@@ -28170,7 +28133,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou
2817028133 }
2817128134 case ContainerLayoutExtern: {
2817228135 size_t src_field_count = val->type->data.structure.src_field_count;
28173 val->data.x_struct.fields = alloc_const_vals_ptrs(src_field_count);
28136 val->data.x_struct.fields = alloc_const_vals_ptrs(codegen, src_field_count);
2817428137 for (size_t field_i = 0; field_i < src_field_count; field_i += 1) {
2817528138 ZigValue *field_val = val->data.x_struct.fields[field_i];
2817628139 field_val->special = ConstValSpecialStatic;
......@@ -28187,7 +28150,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou
2818728150 }
2818828151 case ContainerLayoutPacked: {
2818928152 size_t src_field_count = val->type->data.structure.src_field_count;
28190 val->data.x_struct.fields = alloc_const_vals_ptrs(src_field_count);
28153 val->data.x_struct.fields = alloc_const_vals_ptrs(codegen, src_field_count);
2819128154 size_t gen_field_count = val->type->data.structure.gen_field_count;
2819228155 size_t gen_i = 0;
2819328156 size_t src_i = 0;
......@@ -28199,7 +28162,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou
2819928162 while (gen_i < gen_field_count) {
2820028163 size_t big_int_byte_count = val->type->data.structure.host_int_bytes[gen_i];
2820128164 if (big_int_byte_count > child_buf_len) {
28202 child_buf = allocate_nonzero<uint8_t>(big_int_byte_count);
28165 child_buf = heap::c_allocator.allocate_nonzero<uint8_t>(big_int_byte_count);
2820328166 child_buf_len = big_int_byte_count;
2820428167 }
2820528168 BigInt big_int;
......@@ -28309,7 +28272,7 @@ static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrIn
2830928272 return ira->codegen->invalid_inst_gen;
2831028273
2831128274 IrInstGen *result = ir_const(ira, source_instr, dest_type);
28312 uint8_t *buf = allocate_nonzero<uint8_t>(src_size_bytes);
28275 uint8_t *buf = heap::c_allocator.allocate_nonzero<uint8_t>(src_size_bytes);
2831328276 buf_write_value_bytes(ira->codegen, buf, val);
2831428277 if ((err = buf_read_value_bytes(ira, ira->codegen, source_instr->source_node, buf, result->value)))
2831528278 return ira->codegen->invalid_inst_gen;
......@@ -28451,7 +28414,7 @@ static IrInstGen *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstSrcPtrTy
2845128414 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type);
2845228415 result->value->special = ConstValSpecialLazy;
2845328416
28454 LazyValuePtrType *lazy_ptr_type = allocate<LazyValuePtrType>(1, "LazyValuePtrType");
28417 LazyValuePtrType *lazy_ptr_type = heap::c_allocator.create<LazyValuePtrType>();
2845528418 lazy_ptr_type->ira = ira; ira_ref(ira);
2845628419 result->value->data.x_lazy = &lazy_ptr_type->base;
2845728420 lazy_ptr_type->base.id = LazyValueIdPtrType;
......@@ -29150,11 +29113,11 @@ static IrInstGen *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstSrcBswap *i
2915029113 return ir_const_undef(ira, &instruction->base.base, op_type);
2915129114
2915229115 IrInstGen *result = ir_const(ira, &instruction->base.base, op_type);
29153 size_t buf_size = int_type->data.integral.bit_count / 8;
29154 uint8_t *buf = allocate_nonzero<uint8_t>(buf_size);
29116 const size_t buf_size = int_type->data.integral.bit_count / 8;
29117 uint8_t *buf = heap::c_allocator.allocate_nonzero<uint8_t>(buf_size);
2915529118 if (is_vector) {
2915629119 expand_undef_array(ira->codegen, val);
29157 result->value->data.x_array.data.s_none.elements = create_const_vals(op_type->data.vector.len);
29120 result->value->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(op_type->data.vector.len);
2915829121 for (unsigned i = 0; i < op_type->data.vector.len; i += 1) {
2915929122 ZigValue *op_elem_val = &val->data.x_array.data.s_none.elements[i];
2916029123 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, instruction->base.base.source_node,
......@@ -29178,7 +29141,7 @@ static IrInstGen *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstSrcBswap *i
2917829141 bigint_read_twos_complement(&result->value->data.x_bigint, buf, int_type->data.integral.bit_count, false,
2917929142 int_type->data.integral.is_signed);
2918029143 }
29181 free(buf);
29144 heap::c_allocator.deallocate(buf, buf_size);
2918229145 return result;
2918329146 }
2918429147
......@@ -29210,8 +29173,8 @@ static IrInstGen *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstSrcBi
2921029173 IrInstGen *result = ir_const(ira, &instruction->base.base, int_type);
2921129174 size_t num_bits = int_type->data.integral.bit_count;
2921229175 size_t buf_size = (num_bits + 7) / 8;
29213 uint8_t *comptime_buf = allocate_nonzero<uint8_t>(buf_size);
29214 uint8_t *result_buf = allocate_nonzero<uint8_t>(buf_size);
29176 uint8_t *comptime_buf = heap::c_allocator.allocate_nonzero<uint8_t>(buf_size);
29177 uint8_t *result_buf = heap::c_allocator.allocate_nonzero<uint8_t>(buf_size);
2921529178 memset(comptime_buf,0,buf_size);
2921629179 memset(result_buf,0,buf_size);
2921729180
......@@ -29897,7 +29860,7 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutableSrc *old_exec, IrExecutableGen
2989729860 assert(old_exec->first_err_trace_msg == nullptr);
2989829861 assert(expected_type == nullptr || !type_is_invalid(expected_type));
2989929862
29900 IrAnalyze *ira = allocate<IrAnalyze>(1, "IrAnalyze");
29863 IrAnalyze *ira = heap::c_allocator.create<IrAnalyze>();
2990129864 ira->ref_count = 1;
2990229865 old_exec->analysis = ira;
2990329866 ira->codegen = codegen;
src/ir.hpp-2
......@@ -37,6 +37,4 @@ ZigValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ZigValue *const_va
3737void dbg_ir_break(const char *src_file, uint32_t line);
3838void dbg_ir_clear(void);
3939
40void destroy_instruction_gen(IrInstGen *inst);
41
4240#endif
src/link.cpp+19-19
......@@ -650,7 +650,7 @@ static const char *build_libunwind(CodeGen *parent, Stage2ProgressNode *progress
650650 };
651651 ZigList<CFile *> c_source_files = {0};
652652 for (size_t i = 0; i < array_length(unwind_src); i += 1) {
653 CFile *c_file = allocate<CFile>(1);
653 CFile *c_file = heap::c_allocator.create<CFile>();
654654 c_file->source_path = path_from_libunwind(parent, unwind_src[i].path);
655655 switch (unwind_src[i].kind) {
656656 case SrcC:
......@@ -1111,7 +1111,7 @@ static const char *build_musl(CodeGen *parent, Stage2ProgressNode *progress_node
11111111 Buf *full_path = buf_sprintf("%s" OS_SEP "libc" OS_SEP "%s",
11121112 buf_ptr(parent->zig_lib_dir), buf_ptr(src_file));
11131113
1114 CFile *c_file = allocate<CFile>(1);
1114 CFile *c_file = heap::c_allocator.create<CFile>();
11151115 c_file->source_path = buf_ptr(full_path);
11161116
11171117 musl_add_cc_args(parent, c_file, src_kind == MuslSrcO3);
......@@ -1127,7 +1127,7 @@ static const char *build_musl(CodeGen *parent, Stage2ProgressNode *progress_node
11271127}
11281128
11291129static void add_msvcrt_os_dep(CodeGen *parent, CodeGen *child_gen, const char *src_path) {
1130 CFile *c_file = allocate<CFile>(1);
1130 CFile *c_file = heap::c_allocator.create<CFile>();
11311131 c_file->source_path = buf_ptr(buf_sprintf("%s" OS_SEP "libc" OS_SEP "mingw" OS_SEP "%s",
11321132 buf_ptr(parent->zig_lib_dir), src_path));
11331133 c_file->args.append("-DHAVE_CONFIG_H");
......@@ -1151,7 +1151,7 @@ static void add_msvcrt_os_dep(CodeGen *parent, CodeGen *child_gen, const char *s
11511151}
11521152
11531153static void add_mingwex_os_dep(CodeGen *parent, CodeGen *child_gen, const char *src_path) {
1154 CFile *c_file = allocate<CFile>(1);
1154 CFile *c_file = heap::c_allocator.create<CFile>();
11551155 c_file->source_path = buf_ptr(buf_sprintf("%s" OS_SEP "libc" OS_SEP "mingw" OS_SEP "%s",
11561156 buf_ptr(parent->zig_lib_dir), src_path));
11571157 c_file->args.append("-DHAVE_CONFIG_H");
......@@ -1178,7 +1178,7 @@ static void add_mingwex_os_dep(CodeGen *parent, CodeGen *child_gen, const char *
11781178static const char *get_libc_crt_file(CodeGen *parent, const char *file, Stage2ProgressNode *progress_node) {
11791179 if (parent->libc == nullptr && parent->zig_target->os == OsWindows) {
11801180 if (strcmp(file, "crt2.o") == 0) {
1181 CFile *c_file = allocate<CFile>(1);
1181 CFile *c_file = heap::c_allocator.create<CFile>();
11821182 c_file->source_path = buf_ptr(buf_sprintf(
11831183 "%s" OS_SEP "libc" OS_SEP "mingw" OS_SEP "crt" OS_SEP "crtexe.c", buf_ptr(parent->zig_lib_dir)));
11841184 mingw_add_cc_args(parent, c_file);
......@@ -1190,7 +1190,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file, Stage2Pr
11901190 //c_file->args.append("-DWPRFLAG=1");
11911191 return build_libc_object(parent, "crt2", c_file, progress_node);
11921192 } else if (strcmp(file, "dllcrt2.o") == 0) {
1193 CFile *c_file = allocate<CFile>(1);
1193 CFile *c_file = heap::c_allocator.create<CFile>();
11941194 c_file->source_path = buf_ptr(buf_sprintf(
11951195 "%s" OS_SEP "libc" OS_SEP "mingw" OS_SEP "crt" OS_SEP "crtdll.c", buf_ptr(parent->zig_lib_dir)));
11961196 mingw_add_cc_args(parent, c_file);
......@@ -1231,7 +1231,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file, Stage2Pr
12311231 "mingw" OS_SEP "crt" OS_SEP "cxa_atexit.c",
12321232 };
12331233 for (size_t i = 0; i < array_length(deps); i += 1) {
1234 CFile *c_file = allocate<CFile>(1);
1234 CFile *c_file = heap::c_allocator.create<CFile>();
12351235 c_file->source_path = path_from_libc(parent, deps[i]);
12361236 c_file->args.append("-DHAVE_CONFIG_H");
12371237 c_file->args.append("-D_SYSCRT=1");
......@@ -1301,7 +1301,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file, Stage2Pr
13011301 }
13021302 } else if (parent->libc == nullptr && target_is_glibc(parent->zig_target)) {
13031303 if (strcmp(file, "crti.o") == 0) {
1304 CFile *c_file = allocate<CFile>(1);
1304 CFile *c_file = heap::c_allocator.create<CFile>();
13051305 c_file->source_path = glibc_start_asm_path(parent, "crti.S");
13061306 glibc_add_include_dirs(parent, c_file);
13071307 c_file->args.append("-D_LIBC_REENTRANT");
......@@ -1317,7 +1317,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file, Stage2Pr
13171317 c_file->args.append("-Wa,--noexecstack");
13181318 return build_libc_object(parent, "crti", c_file, progress_node);
13191319 } else if (strcmp(file, "crtn.o") == 0) {
1320 CFile *c_file = allocate<CFile>(1);
1320 CFile *c_file = heap::c_allocator.create<CFile>();
13211321 c_file->source_path = glibc_start_asm_path(parent, "crtn.S");
13221322 glibc_add_include_dirs(parent, c_file);
13231323 c_file->args.append("-D_LIBC_REENTRANT");
......@@ -1328,7 +1328,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file, Stage2Pr
13281328 c_file->args.append("-Wa,--noexecstack");
13291329 return build_libc_object(parent, "crtn", c_file, progress_node);
13301330 } else if (strcmp(file, "start.os") == 0) {
1331 CFile *c_file = allocate<CFile>(1);
1331 CFile *c_file = heap::c_allocator.create<CFile>();
13321332 c_file->source_path = glibc_start_asm_path(parent, "start.S");
13331333 glibc_add_include_dirs(parent, c_file);
13341334 c_file->args.append("-D_LIBC_REENTRANT");
......@@ -1346,7 +1346,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file, Stage2Pr
13461346 c_file->args.append("-Wa,--noexecstack");
13471347 return build_libc_object(parent, "start", c_file, progress_node);
13481348 } else if (strcmp(file, "abi-note.o") == 0) {
1349 CFile *c_file = allocate<CFile>(1);
1349 CFile *c_file = heap::c_allocator.create<CFile>();
13501350 c_file->source_path = path_from_libc(parent, "glibc" OS_SEP "csu" OS_SEP "abi-note.S");
13511351 c_file->args.append("-I");
13521352 c_file->args.append(path_from_libc(parent, "glibc" OS_SEP "csu"));
......@@ -1369,7 +1369,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file, Stage2Pr
13691369 } else if (strcmp(file, "libc_nonshared.a") == 0) {
13701370 CodeGen *child_gen = create_child_codegen(parent, nullptr, OutTypeLib, nullptr, "c_nonshared", progress_node);
13711371 {
1372 CFile *c_file = allocate<CFile>(1);
1372 CFile *c_file = heap::c_allocator.create<CFile>();
13731373 c_file->source_path = path_from_libc(parent, "glibc" OS_SEP "csu" OS_SEP "elf-init.c");
13741374 c_file->args.append("-std=gnu11");
13751375 c_file->args.append("-fgnu89-inline");
......@@ -1419,7 +1419,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file, Stage2Pr
14191419 {"stack_chk_fail_local", "glibc" OS_SEP "debug" OS_SEP "stack_chk_fail_local.c"},
14201420 };
14211421 for (size_t i = 0; i < array_length(deps); i += 1) {
1422 CFile *c_file = allocate<CFile>(1);
1422 CFile *c_file = heap::c_allocator.create<CFile>();
14231423 c_file->source_path = path_from_libc(parent, deps[i].path);
14241424 c_file->args.append("-std=gnu11");
14251425 c_file->args.append("-fgnu89-inline");
......@@ -1451,26 +1451,26 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file, Stage2Pr
14511451 }
14521452 } else if (parent->libc == nullptr && target_is_musl(parent->zig_target)) {
14531453 if (strcmp(file, "crti.o") == 0) {
1454 CFile *c_file = allocate<CFile>(1);
1454 CFile *c_file = heap::c_allocator.create<CFile>();
14551455 c_file->source_path = musl_start_asm_path(parent, "crti.s");
14561456 musl_add_cc_args(parent, c_file, false);
14571457 c_file->args.append("-Qunused-arguments");
14581458 return build_libc_object(parent, "crti", c_file, progress_node);
14591459 } else if (strcmp(file, "crtn.o") == 0) {
1460 CFile *c_file = allocate<CFile>(1);
1460 CFile *c_file = heap::c_allocator.create<CFile>();
14611461 c_file->source_path = musl_start_asm_path(parent, "crtn.s");
14621462 c_file->args.append("-Qunused-arguments");
14631463 musl_add_cc_args(parent, c_file, false);
14641464 return build_libc_object(parent, "crtn", c_file, progress_node);
14651465 } else if (strcmp(file, "crt1.o") == 0) {
1466 CFile *c_file = allocate<CFile>(1);
1466 CFile *c_file = heap::c_allocator.create<CFile>();
14671467 c_file->source_path = path_from_libc(parent, "musl" OS_SEP "crt" OS_SEP "crt1.c");
14681468 musl_add_cc_args(parent, c_file, false);
14691469 c_file->args.append("-fno-stack-protector");
14701470 c_file->args.append("-DCRT");
14711471 return build_libc_object(parent, "crt1", c_file, progress_node);
14721472 } else if (strcmp(file, "Scrt1.o") == 0) {
1473 CFile *c_file = allocate<CFile>(1);
1473 CFile *c_file = heap::c_allocator.create<CFile>();
14741474 c_file->source_path = path_from_libc(parent, "musl" OS_SEP "crt" OS_SEP "Scrt1.c");
14751475 musl_add_cc_args(parent, c_file, false);
14761476 c_file->args.append("-fPIC");
......@@ -1982,7 +1982,7 @@ static const char *get_def_lib(CodeGen *parent, const char *name, Buf *def_in_fi
19821982 Buf *def_include_dir = buf_sprintf("%s" OS_SEP "libc" OS_SEP "mingw" OS_SEP "def-include",
19831983 buf_ptr(parent->zig_lib_dir));
19841984
1985 CacheHash *cache_hash = allocate<CacheHash>(1);
1985 CacheHash *cache_hash = heap::c_allocator.create<CacheHash>();
19861986 cache_init(cache_hash, manifest_dir);
19871987
19881988 cache_buf(cache_hash, compiler_id);
......@@ -2367,7 +2367,7 @@ static void construct_linker_job_coff(LinkJob *lj) {
23672367
23682368 lj->args.append(get_def_lib(g, name, &lib_path));
23692369
2370 free(name);
2370 mem::os::free(name);
23712371 }
23722372}
23732373
src/list.hpp+2-4
......@@ -13,7 +13,7 @@
1313template<typename T>
1414struct ZigList {
1515 void deinit() {
16 deallocate(items, capacity);
16 heap::c_allocator.deallocate(items, capacity);
1717 }
1818 void append(const T& item) {
1919 ensure_capacity(length + 1);
......@@ -70,7 +70,7 @@ struct ZigList {
7070 better_capacity = better_capacity * 5 / 2 + 8;
7171 } while (better_capacity < new_capacity);
7272
73 items = reallocate_nonzero(items, capacity, better_capacity);
73 items = heap::c_allocator.reallocate_nonzero(items, capacity, better_capacity);
7474 capacity = better_capacity;
7575 }
7676
......@@ -91,5 +91,3 @@ struct ZigList {
9191};
9292
9393#endif
94
95
src/main.cpp+27-21
......@@ -11,12 +11,14 @@
1111#include "compiler.hpp"
1212#include "config.h"
1313#include "error.hpp"
14#include "heap.hpp"
1415#include "os.hpp"
1516#include "target.hpp"
1617#include "libc_installation.hpp"
1718#include "userland.h"
1819#include "glibc.hpp"
1920#include "dump_analysis.hpp"
21#include "mem_profile.hpp"
2022
2123#include <stdio.h>
2224
......@@ -243,21 +245,10 @@ int main_exit(Stage2ProgressNode *root_progress_node, int exit_code) {
243245 if (root_progress_node != nullptr) {
244246 stage2_progress_end(root_progress_node);
245247 }
246#ifdef ZIG_ENABLE_MEM_PROFILE
247 if (mem_report) {
248 memprof_dump_stats(stderr);
249 }
250#endif
251248 return exit_code;
252249}
253250
254int main(int argc, char **argv) {
255 stage2_attach_segfault_handler();
256
257#ifdef ZIG_ENABLE_MEM_PROFILE
258 memprof_init();
259#endif
260
251static int main0(int argc, char **argv) {
261252 char *arg0 = argv[0];
262253 Error err;
263254
......@@ -278,9 +269,6 @@ int main(int argc, char **argv) {
278269 return ZigClang_main(argc, argv);
279270 }
280271
281 // Must be before all os.hpp function calls.
282 os_init();
283
284272 if (argc == 2 && strcmp(argv[1], "id") == 0) {
285273 Buf *compiler_id;
286274 if ((err = get_compiler_id(&compiler_id))) {
......@@ -439,7 +427,7 @@ int main(int argc, char **argv) {
439427 bool enable_doc_generation = false;
440428 bool disable_bin_generation = false;
441429 const char *cache_dir = nullptr;
442 CliPkg *cur_pkg = allocate<CliPkg>(1);
430 CliPkg *cur_pkg = heap::c_allocator.create<CliPkg>();
443431 BuildMode build_mode = BuildModeDebug;
444432 ZigList<const char *> test_exec_args = {0};
445433 int runtime_args_start = -1;
......@@ -635,6 +623,7 @@ int main(int argc, char **argv) {
635623 } else if (strcmp(arg, "-fmem-report") == 0) {
636624#ifdef ZIG_ENABLE_MEM_PROFILE
637625 mem_report = true;
626 mem::report_print = true;
638627#else
639628 fprintf(stderr, "-fmem-report requires configuring with -DZIG_ENABLE_MEM_PROFILE=ON\n");
640629 return print_error_usage(arg0);
......@@ -695,7 +684,7 @@ int main(int argc, char **argv) {
695684 fprintf(stderr, "Expected 2 arguments after --pkg-begin\n");
696685 return print_error_usage(arg0);
697686 }
698 CliPkg *new_cur_pkg = allocate<CliPkg>(1);
687 CliPkg *new_cur_pkg = heap::c_allocator.create<CliPkg>();
699688 i += 1;
700689 new_cur_pkg->name = argv[i];
701690 i += 1;
......@@ -810,7 +799,7 @@ int main(int argc, char **argv) {
810799 } else if (strcmp(arg, "--object") == 0) {
811800 objects.append(argv[i]);
812801 } else if (strcmp(arg, "--c-source") == 0) {
813 CFile *c_file = allocate<CFile>(1);
802 CFile *c_file = heap::c_allocator.create<CFile>();
814803 for (;;) {
815804 if (argv[i][0] == '-') {
816805 c_file->args.append(argv[i]);
......@@ -990,7 +979,7 @@ int main(int argc, char **argv) {
990979 }
991980 }
992981 if (target_is_glibc(&target)) {
993 target.glibc_version = allocate<ZigGLibCVersion>(1);
982 target.glibc_version = heap::c_allocator.create<ZigGLibCVersion>();
994983
995984 if (target_glibc != nullptr) {
996985 if ((err = target_parse_glibc_version(target.glibc_version, target_glibc))) {
......@@ -1138,7 +1127,7 @@ int main(int argc, char **argv) {
11381127 }
11391128 ZigLibCInstallation *libc = nullptr;
11401129 if (libc_txt != nullptr) {
1141 libc = allocate<ZigLibCInstallation>(1);
1130 libc = heap::c_allocator.create<ZigLibCInstallation>();
11421131 if ((err = zig_libc_parse(libc, buf_create_from_str(libc_txt), &target, true))) {
11431132 fprintf(stderr, "Unable to parse --libc text file: %s\n", err_str(err));
11441133 return main_exit(root_progress_node, EXIT_FAILURE);
......@@ -1269,7 +1258,8 @@ int main(int argc, char **argv) {
12691258
12701259 if (cmd == CmdRun) {
12711260#ifdef ZIG_ENABLE_MEM_PROFILE
1272 memprof_dump_stats(stderr);
1261 if (mem::report_print)
1262 mem::print_report();
12731263#endif
12741264
12751265 const char *exec_path = buf_ptr(&g->output_file_path);
......@@ -1384,4 +1374,20 @@ int main(int argc, char **argv) {
13841374 case CmdNone:
13851375 return print_full_usage(arg0, stderr, EXIT_FAILURE);
13861376 }
1377 zig_unreachable();
1378}
1379
1380int main(int argc, char **argv) {
1381 stage2_attach_segfault_handler();
1382 os_init();
1383 mem::init();
1384
1385 auto result = main0(argc, argv);
1386
1387#ifdef ZIG_ENABLE_MEM_PROFILE
1388 if (mem::report_print)
1389 mem::intern_counters.print_report();
1390#endif
1391 mem::deinit();
1392 return result;
13871393}
src/mem.cpp created+37
......@@ -0,0 +1,37 @@
1/*
2 * Copyright (c) 2020 Andrew Kelley
3 *
4 * This file is part of zig, which is MIT licensed.
5 * See http://opensource.org/licenses/MIT
6 */
7
8#include "config.h"
9#include "mem.hpp"
10#include "mem_profile.hpp"
11#include "heap.hpp"
12
13namespace mem {
14
15void init() {
16 heap::bootstrap_allocator_state.init("heap::bootstrap_allocator");
17 heap::c_allocator_state.init("heap::c_allocator");
18}
19
20void deinit() {
21 heap::c_allocator_state.deinit();
22 heap::bootstrap_allocator_state.deinit();
23}
24
25#ifdef ZIG_ENABLE_MEM_PROFILE
26void print_report(FILE *file) {
27 heap::c_allocator_state.print_report(file);
28 intern_counters.print_report(file);
29}
30#endif
31
32#ifdef ZIG_ENABLE_MEM_PROFILE
33bool report_print = false;
34FILE *report_file{nullptr};
35#endif
36
37} // namespace mem
src/mem.hpp created+149
......@@ -0,0 +1,149 @@
1/*
2 * Copyright (c) 2020 Andrew Kelley
3 *
4 * This file is part of zig, which is MIT licensed.
5 * See http://opensource.org/licenses/MIT
6 */
7
8#ifndef ZIG_MEM_HPP
9#define ZIG_MEM_HPP
10
11#include <stdint.h>
12#include <stdio.h>
13#include <stdlib.h>
14
15#include "config.h"
16#include "util_base.hpp"
17#include "mem_type_info.hpp"
18
19//
20// -- Memory Allocation General Notes --
21//
22// `heap::c_allocator` is the preferred general allocator.
23//
24// `heap::bootstrap_allocator` is an implementation detail for use
25// by allocators themselves when incidental heap may be required for
26// profiling and statistics. It breaks the infinite recursion cycle.
27//
28// `mem::os` contains a raw wrapper for system malloc API used in
29// preference to calling ::{malloc, free, calloc, realloc} directly.
30// This isolates usage and helps with audits:
31//
32// mem::os::malloc
33// mem::os::free
34// mem::os::calloc
35// mem::os::realloc
36//
37namespace mem {
38
39// initialize mem module before any use
40void init();
41
42// deinitialize mem module to free memory and print report
43void deinit();
44
45// isolate system/libc allocators
46namespace os {
47
48ATTRIBUTE_RETURNS_NOALIAS
49inline void *malloc(size_t size) {
50#ifndef NDEBUG
51 // make behavior when size == 0 portable
52 if (size == 0)
53 return nullptr;
54#endif
55 auto ptr = ::malloc(size);
56 if (ptr == nullptr)
57 zig_panic("allocation failed");
58 return ptr;
59}
60
61inline void free(void *ptr) {
62 ::free(ptr);
63}
64
65ATTRIBUTE_RETURNS_NOALIAS
66inline void *calloc(size_t count, size_t size) {
67#ifndef NDEBUG
68 // make behavior when size == 0 portable
69 if (count == 0 || size == 0)
70 return nullptr;
71#endif
72 auto ptr = ::calloc(count, size);
73 if (ptr == nullptr)
74 zig_panic("allocation failed");
75 return ptr;
76}
77
78inline void *realloc(void *old_ptr, size_t size) {
79#ifndef NDEBUG
80 // make behavior when size == 0 portable
81 if (old_ptr == nullptr && size == 0)
82 return nullptr;
83#endif
84 auto ptr = ::realloc(old_ptr, size);
85 if (ptr == nullptr)
86 zig_panic("allocation failed");
87 return ptr;
88}
89
90} // namespace os
91
92struct Allocator {
93 virtual void destruct(Allocator *allocator) = 0;
94
95 template <typename T> ATTRIBUTE_RETURNS_NOALIAS
96 T *allocate(size_t count) {
97 return reinterpret_cast<T *>(this->internal_allocate(TypeInfo::make<T>(), count));
98 }
99
100 template <typename T> ATTRIBUTE_RETURNS_NOALIAS
101 T *allocate_nonzero(size_t count) {
102 return reinterpret_cast<T *>(this->internal_allocate_nonzero(TypeInfo::make<T>(), count));
103 }
104
105 template <typename T>
106 T *reallocate(T *old_ptr, size_t old_count, size_t new_count) {
107 return reinterpret_cast<T *>(this->internal_reallocate(TypeInfo::make<T>(), old_ptr, old_count, new_count));
108 }
109
110 template <typename T>
111 T *reallocate_nonzero(T *old_ptr, size_t old_count, size_t new_count) {
112 return reinterpret_cast<T *>(this->internal_reallocate_nonzero(TypeInfo::make<T>(), old_ptr, old_count, new_count));
113 }
114
115 template<typename T>
116 void deallocate(T *ptr, size_t count) {
117 this->internal_deallocate(TypeInfo::make<T>(), ptr, count);
118 }
119
120 template<typename T>
121 T *create() {
122 return reinterpret_cast<T *>(this->internal_allocate(TypeInfo::make<T>(), 1));
123 }
124
125 template<typename T>
126 void destroy(T *ptr) {
127 this->internal_deallocate(TypeInfo::make<T>(), ptr, 1);
128 }
129
130protected:
131 ATTRIBUTE_RETURNS_NOALIAS virtual void *internal_allocate(const TypeInfo &info, size_t count) = 0;
132 ATTRIBUTE_RETURNS_NOALIAS virtual void *internal_allocate_nonzero(const TypeInfo &info, size_t count) = 0;
133 virtual void *internal_reallocate(const TypeInfo &info, void *old_ptr, size_t old_count, size_t new_count) = 0;
134 virtual void *internal_reallocate_nonzero(const TypeInfo &info, void *old_ptr, size_t old_count, size_t new_count) = 0;
135 virtual void internal_deallocate(const TypeInfo &info, void *ptr, size_t count) = 0;
136};
137
138#ifdef ZIG_ENABLE_MEM_PROFILE
139void print_report(FILE *file = nullptr);
140
141// global memory report flag
142extern bool report_print;
143// global memory report default destination
144extern FILE *report_file;
145#endif
146
147} // namespace mem
148
149#endif
src/mem_hash_map.hpp created+244
......@@ -0,0 +1,244 @@
1/*
2 * Copyright (c) 2015 Andrew Kelley
3 *
4 * This file is part of zig, which is MIT licensed.
5 * See http://opensource.org/licenses/MIT
6 */
7
8#ifndef ZIG_MEM_HASH_MAP_HPP
9#define ZIG_MEM_HASH_MAP_HPP
10
11#include "mem.hpp"
12
13namespace mem {
14
15template<typename K, typename V, uint32_t (*HashFunction)(K key), bool (*EqualFn)(K a, K b)>
16class HashMap {
17public:
18 void init(Allocator& allocator, int capacity) {
19 init_capacity(allocator, capacity);
20 }
21 void deinit(Allocator& allocator) {
22 allocator.deallocate(_entries, _capacity);
23 }
24
25 struct Entry {
26 K key;
27 V value;
28 bool used;
29 int distance_from_start_index;
30 };
31
32 void clear() {
33 for (int i = 0; i < _capacity; i += 1) {
34 _entries[i].used = false;
35 }
36 _size = 0;
37 _max_distance_from_start_index = 0;
38 _modification_count += 1;
39 }
40
41 int size() const {
42 return _size;
43 }
44
45 void put(Allocator& allocator, const K &key, const V &value) {
46 _modification_count += 1;
47 internal_put(key, value);
48
49 // if we get too full (60%), double the capacity
50 if (_size * 5 >= _capacity * 3) {
51 Entry *old_entries = _entries;
52 int old_capacity = _capacity;
53 init_capacity(allocator, _capacity * 2);
54 // dump all of the old elements into the new table
55 for (int i = 0; i < old_capacity; i += 1) {
56 Entry *old_entry = &old_entries[i];
57 if (old_entry->used)
58 internal_put(old_entry->key, old_entry->value);
59 }
60 allocator.deallocate(old_entries, old_capacity);
61 }
62 }
63
64 Entry *put_unique(Allocator& allocator, const K &key, const V &value) {
65 // TODO make this more efficient
66 Entry *entry = internal_get(key);
67 if (entry)
68 return entry;
69 put(allocator, key, value);
70 return nullptr;
71 }
72
73 const V &get(const K &key) const {
74 Entry *entry = internal_get(key);
75 if (!entry)
76 zig_panic("key not found");
77 return entry->value;
78 }
79
80 Entry *maybe_get(const K &key) const {
81 return internal_get(key);
82 }
83
84 void maybe_remove(const K &key) {
85 if (maybe_get(key)) {
86 remove(key);
87 }
88 }
89
90 void remove(const K &key) {
91 _modification_count += 1;
92 int start_index = key_to_index(key);
93 for (int roll_over = 0; roll_over <= _max_distance_from_start_index; roll_over += 1) {
94 int index = (start_index + roll_over) % _capacity;
95 Entry *entry = &_entries[index];
96
97 if (!entry->used)
98 zig_panic("key not found");
99
100 if (!EqualFn(entry->key, key))
101 continue;
102
103 for (; roll_over < _capacity; roll_over += 1) {
104 int next_index = (start_index + roll_over + 1) % _capacity;
105 Entry *next_entry = &_entries[next_index];
106 if (!next_entry->used || next_entry->distance_from_start_index == 0) {
107 entry->used = false;
108 _size -= 1;
109 return;
110 }
111 *entry = *next_entry;
112 entry->distance_from_start_index -= 1;
113 entry = next_entry;
114 }
115 zig_panic("shifting everything in the table");
116 }
117 zig_panic("key not found");
118 }
119
120 class Iterator {
121 public:
122 Entry *next() {
123 if (_inital_modification_count != _table->_modification_count)
124 zig_panic("concurrent modification");
125 if (_count >= _table->size())
126 return NULL;
127 for (; _index < _table->_capacity; _index += 1) {
128 Entry *entry = &_table->_entries[_index];
129 if (entry->used) {
130 _index += 1;
131 _count += 1;
132 return entry;
133 }
134 }
135 zig_panic("no next item");
136 }
137
138 private:
139 const HashMap * _table;
140 // how many items have we returned
141 int _count = 0;
142 // iterator through the entry array
143 int _index = 0;
144 // used to detect concurrent modification
145 uint32_t _inital_modification_count;
146 Iterator(const HashMap * table) :
147 _table(table), _inital_modification_count(table->_modification_count) {
148 }
149 friend HashMap;
150 };
151
152 // you must not modify the underlying HashMap while this iterator is still in use
153 Iterator entry_iterator() const {
154 return Iterator(this);
155 }
156
157private:
158 Entry *_entries;
159 int _capacity;
160 int _size;
161 int _max_distance_from_start_index;
162 // this is used to detect bugs where a hashtable is edited while an iterator is running.
163 uint32_t _modification_count;
164
165 void init_capacity(Allocator& allocator, int capacity) {
166 _capacity = capacity;
167 _entries = allocator.allocate<Entry>(_capacity);
168 _size = 0;
169 _max_distance_from_start_index = 0;
170 for (int i = 0; i < _capacity; i += 1) {
171 _entries[i].used = false;
172 }
173 }
174
175 void internal_put(K key, V value) {
176 int start_index = key_to_index(key);
177 for (int roll_over = 0, distance_from_start_index = 0;
178 roll_over < _capacity; roll_over += 1, distance_from_start_index += 1)
179 {
180 int index = (start_index + roll_over) % _capacity;
181 Entry *entry = &_entries[index];
182
183 if (entry->used && !EqualFn(entry->key, key)) {
184 if (entry->distance_from_start_index < distance_from_start_index) {
185 // robin hood to the rescue
186 Entry tmp = *entry;
187 if (distance_from_start_index > _max_distance_from_start_index)
188 _max_distance_from_start_index = distance_from_start_index;
189 *entry = {
190 key,
191 value,
192 true,
193 distance_from_start_index,
194 };
195 key = tmp.key;
196 value = tmp.value;
197 distance_from_start_index = tmp.distance_from_start_index;
198 }
199 continue;
200 }
201
202 if (!entry->used) {
203 // adding an entry. otherwise overwriting old value with
204 // same key
205 _size += 1;
206 }
207
208 if (distance_from_start_index > _max_distance_from_start_index)
209 _max_distance_from_start_index = distance_from_start_index;
210 *entry = {
211 key,
212 value,
213 true,
214 distance_from_start_index,
215 };
216 return;
217 }
218 zig_panic("put into a full HashMap");
219 }
220
221
222 Entry *internal_get(const K &key) const {
223 int start_index = key_to_index(key);
224 for (int roll_over = 0; roll_over <= _max_distance_from_start_index; roll_over += 1) {
225 int index = (start_index + roll_over) % _capacity;
226 Entry *entry = &_entries[index];
227
228 if (!entry->used)
229 return NULL;
230
231 if (EqualFn(entry->key, key))
232 return entry;
233 }
234 return NULL;
235 }
236
237 int key_to_index(const K &key) const {
238 return (int)(HashFunction(key) % ((uint32_t)_capacity));
239 }
240};
241
242} // namespace mem
243
244#endif
src/mem_list.hpp created+101
......@@ -0,0 +1,101 @@
1/*
2 * Copyright (c) 2015 Andrew Kelley
3 *
4 * This file is part of zig, which is MIT licensed.
5 * See http://opensource.org/licenses/MIT
6 */
7
8#ifndef ZIG_MEM_LIST_HPP
9#define ZIG_MEM_LIST_HPP
10
11#include "mem.hpp"
12
13namespace mem {
14
15template<typename T>
16struct List {
17 void deinit(Allocator& allocator) {
18 allocator.deallocate<T>(items, capacity);
19 }
20
21 void append(Allocator& allocator, const T& item) {
22 ensure_capacity(allocator, length + 1);
23 items[length++] = item;
24 }
25
26 // remember that the pointer to this item is invalid after you
27 // modify the length of the list
28 const T & at(size_t index) const {
29 assert(index != SIZE_MAX);
30 assert(index < length);
31 return items[index];
32 }
33
34 T & at(size_t index) {
35 assert(index != SIZE_MAX);
36 assert(index < length);
37 return items[index];
38 }
39
40 T pop() {
41 assert(length >= 1);
42 return items[--length];
43 }
44
45 T *add_one() {
46 resize(length + 1);
47 return &last();
48 }
49
50 const T & last() const {
51 assert(length >= 1);
52 return items[length - 1];
53 }
54
55 T & last() {
56 assert(length >= 1);
57 return items[length - 1];
58 }
59
60 void resize(Allocator& allocator, size_t new_length) {
61 assert(new_length != SIZE_MAX);
62 ensure_capacity(allocator, new_length);
63 length = new_length;
64 }
65
66 void clear() {
67 length = 0;
68 }
69
70 void ensure_capacity(Allocator& allocator, size_t new_capacity) {
71 if (capacity >= new_capacity)
72 return;
73
74 size_t better_capacity = capacity;
75 do {
76 better_capacity = better_capacity * 5 / 2 + 8;
77 } while (better_capacity < new_capacity);
78
79 items = allocator.reallocate_nonzero<T>(items, capacity, better_capacity);
80 capacity = better_capacity;
81 }
82
83 T swap_remove(size_t index) {
84 if (length - 1 == index) return pop();
85
86 assert(index != SIZE_MAX);
87 assert(index < length);
88
89 T old_item = items[index];
90 items[index] = pop();
91 return old_item;
92 }
93
94 T *items{nullptr};
95 size_t length{0};
96 size_t capacity{0};
97};
98
99} // namespace mem
100
101#endif
src/mem_profile.cpp created+181
......@@ -0,0 +1,181 @@
1/*
2 * Copyright (c) 2020 Andrew Kelley
3 *
4 * This file is part of zig, which is MIT licensed.
5 * See http://opensource.org/licenses/MIT
6 */
7
8#include "config.h"
9
10#ifdef ZIG_ENABLE_MEM_PROFILE
11
12#include "mem.hpp"
13#include "mem_list.hpp"
14#include "mem_profile.hpp"
15#include "heap.hpp"
16
17namespace mem {
18
19void Profile::init(const char *name, const char *kind) {
20 this->name = name;
21 this->kind = kind;
22 this->usage_table.init(heap::bootstrap_allocator, 1024);
23}
24
25void Profile::deinit() {
26 assert(this->name != nullptr);
27 if (mem::report_print)
28 this->print_report();
29 this->usage_table.deinit(heap::bootstrap_allocator);
30 this->name = nullptr;
31}
32
33void Profile::record_alloc(const TypeInfo &info, size_t count) {
34 if (count == 0) return;
35 auto existing_entry = this->usage_table.put_unique(
36 heap::bootstrap_allocator,
37 UsageKey{info.name_ptr, info.name_len},
38 Entry{info, 1, count, 0, 0} );
39 if (existing_entry != nullptr) {
40 assert(existing_entry->value.info.size == info.size); // allocated name does not match type
41 existing_entry->value.alloc.calls += 1;
42 existing_entry->value.alloc.objects += count;
43 }
44}
45
46void Profile::record_dealloc(const TypeInfo &info, size_t count) {
47 if (count == 0) return;
48 auto existing_entry = this->usage_table.maybe_get(UsageKey{info.name_ptr, info.name_len});
49 if (existing_entry == nullptr) {
50 fprintf(stderr, "deallocated name '");
51 for (size_t i = 0; i < info.name_len; ++i)
52 fputc(info.name_ptr[i], stderr);
53 zig_panic("' (size %zu) not found in allocated table; compromised memory usage stats", info.size);
54 }
55 if (existing_entry->value.info.size != info.size) {
56 fprintf(stderr, "deallocated name '");
57 for (size_t i = 0; i < info.name_len; ++i)
58 fputc(info.name_ptr[i], stderr);
59 zig_panic("' does not match expected type size %zu", info.size);
60 }
61 assert(existing_entry->value.alloc.calls - existing_entry->value.dealloc.calls > 0);
62 assert(existing_entry->value.alloc.objects - existing_entry->value.dealloc.objects >= count);
63 existing_entry->value.dealloc.calls += 1;
64 existing_entry->value.dealloc.objects += count;
65}
66
67static size_t entry_remain_total_bytes(const Profile::Entry *entry) {
68 return (entry->alloc.objects - entry->dealloc.objects) * entry->info.size;
69}
70
71static int entry_compare(const void *a, const void *b) {
72 size_t total_a = entry_remain_total_bytes(*reinterpret_cast<Profile::Entry *const *>(a));
73 size_t total_b = entry_remain_total_bytes(*reinterpret_cast<Profile::Entry *const *>(b));
74 if (total_a > total_b)
75 return -1;
76 if (total_a < total_b)
77 return 1;
78 return 0;
79};
80
81void Profile::print_report(FILE *file) {
82 if (!file) {
83 file = report_file;
84 if (!file)
85 file = stderr;
86 }
87 fprintf(file, "\n--- MEMORY PROFILE REPORT [%s]: %s ---\n", this->kind, this->name);
88
89 List<const Entry *> list;
90 auto it = this->usage_table.entry_iterator();
91 for (;;) {
92 auto entry = it.next();
93 if (!entry)
94 break;
95 list.append(heap::bootstrap_allocator, &entry->value);
96 }
97
98 qsort(list.items, list.length, sizeof(const Entry *), entry_compare);
99
100 size_t total_bytes_alloc = 0;
101 size_t total_bytes_dealloc = 0;
102
103 size_t total_calls_alloc = 0;
104 size_t total_calls_dealloc = 0;
105
106 for (size_t i = 0; i < list.length; i += 1) {
107 const Entry *entry = list.at(i);
108 fprintf(file, " ");
109 for (size_t j = 0; j < entry->info.name_len; ++j)
110 fputc(entry->info.name_ptr[j], file);
111 fprintf(file, ": %zu bytes each", entry->info.size);
112
113 fprintf(file, ", alloc{ %zu calls, %zu objects, total ", entry->alloc.calls, entry->alloc.objects);
114 const auto alloc_num_bytes = entry->alloc.objects * entry->info.size;
115 zig_pretty_print_bytes(file, alloc_num_bytes);
116
117 fprintf(file, " }, dealloc{ %zu calls, %zu objects, total ", entry->dealloc.calls, entry->dealloc.objects);
118 const auto dealloc_num_bytes = entry->dealloc.objects * entry->info.size;
119 zig_pretty_print_bytes(file, dealloc_num_bytes);
120
121 fprintf(file, " }, remain{ %zu calls, %zu objects, total ",
122 entry->alloc.calls - entry->dealloc.calls,
123 entry->alloc.objects - entry->dealloc.objects );
124 const auto remain_num_bytes = alloc_num_bytes - dealloc_num_bytes;
125 zig_pretty_print_bytes(file, remain_num_bytes);
126
127 fprintf(file, " }\n");
128
129 total_bytes_alloc += alloc_num_bytes;
130 total_bytes_dealloc += dealloc_num_bytes;
131
132 total_calls_alloc += entry->alloc.calls;
133 total_calls_dealloc += entry->dealloc.calls;
134 }
135
136 fprintf(file, "\n Total bytes allocated: ");
137 zig_pretty_print_bytes(file, total_bytes_alloc);
138 fprintf(file, ", deallocated: ");
139 zig_pretty_print_bytes(file, total_bytes_dealloc);
140 fprintf(file, ", remaining: ");
141 zig_pretty_print_bytes(file, total_bytes_alloc - total_bytes_dealloc);
142
143 fprintf(file, "\n Total calls alloc: %zu, dealloc: %zu, remain: %zu\n",
144 total_calls_alloc, total_calls_dealloc, (total_calls_alloc - total_calls_dealloc));
145
146 list.deinit(heap::bootstrap_allocator);
147}
148
149uint32_t Profile::usage_hash(UsageKey key) {
150 // FNV 32-bit hash
151 uint32_t h = 2166136261;
152 for (size_t i = 0; i < key.name_len; ++i) {
153 h = h ^ key.name_ptr[i];
154 h = h * 16777619;
155 }
156 return h;
157}
158
159bool Profile::usage_equal(UsageKey a, UsageKey b) {
160 return memcmp(a.name_ptr, b.name_ptr, a.name_len > b.name_len ? a.name_len : b.name_len) == 0;
161}
162
163void InternCounters::print_report(FILE *file) {
164 if (!file) {
165 file = report_file;
166 if (!file)
167 file = stderr;
168 }
169 fprintf(file, "\n--- IR INTERNING REPORT ---\n");
170 fprintf(file, " undefined: interned %zu times\n", intern_counters.x_undefined);
171 fprintf(file, " void: interned %zu times\n", intern_counters.x_void);
172 fprintf(file, " null: interned %zu times\n", intern_counters.x_null);
173 fprintf(file, " unreachable: interned %zu times\n", intern_counters.x_unreachable);
174 fprintf(file, " zero_byte: interned %zu times\n", intern_counters.zero_byte);
175}
176
177InternCounters intern_counters;
178
179} // namespace mem
180
181#endif
src/mem_profile.hpp created+71
......@@ -0,0 +1,71 @@
1/*
2 * Copyright (c) 2020 Andrew Kelley
3 *
4 * This file is part of zig, which is MIT licensed.
5 * See http://opensource.org/licenses/MIT
6 */
7
8#ifndef ZIG_MEM_PROFILE_HPP
9#define ZIG_MEM_PROFILE_HPP
10
11#include "config.h"
12
13#ifdef ZIG_ENABLE_MEM_PROFILE
14
15#include <stdio.h>
16
17#include "mem.hpp"
18#include "mem_hash_map.hpp"
19#include "util.hpp"
20
21namespace mem {
22
23struct Profile {
24 void init(const char *name, const char *kind);
25 void deinit();
26
27 void record_alloc(const TypeInfo &info, size_t count);
28 void record_dealloc(const TypeInfo &info, size_t count);
29
30 void print_report(FILE *file = nullptr);
31
32 struct Entry {
33 TypeInfo info;
34
35 struct Use {
36 size_t calls;
37 size_t objects;
38 } alloc, dealloc;
39 };
40
41private:
42 const char *name;
43 const char *kind;
44
45 struct UsageKey {
46 const char *name_ptr;
47 size_t name_len;
48 };
49
50 static uint32_t usage_hash(UsageKey key);
51 static bool usage_equal(UsageKey a, UsageKey b);
52
53 HashMap<UsageKey, Entry, usage_hash, usage_equal> usage_table;
54};
55
56struct InternCounters {
57 size_t x_undefined;
58 size_t x_void;
59 size_t x_null;
60 size_t x_unreachable;
61 size_t zero_byte;
62
63 void print_report(FILE *file = nullptr);
64};
65
66extern InternCounters intern_counters;
67
68} // namespace mem
69
70#endif
71#endif
src/mem_type_info.hpp created+136
......@@ -0,0 +1,136 @@
1/*
2 * Copyright (c) 2020 Andrew Kelley
3 *
4 * This file is part of zig, which is MIT licensed.
5 * See http://opensource.org/licenses/MIT
6 */
7
8#ifndef ZIG_MEM_TYPE_INFO_HPP
9#define ZIG_MEM_TYPE_INFO_HPP
10
11#include "config.h"
12
13#ifndef ZIG_TYPE_INFO_IMPLEMENTATION
14# ifdef ZIG_ENABLE_MEM_PROFILE
15# define ZIG_TYPE_INFO_IMPLEMENTATION 1
16# else
17# define ZIG_TYPE_INFO_IMPLEMENTATION 0
18# endif
19#endif
20
21namespace mem {
22
23#if ZIG_TYPE_INFO_IMPLEMENTATION == 0
24
25struct TypeInfo {
26 size_t size;
27 size_t alignment;
28
29 template <typename T>
30 static constexpr TypeInfo make() {
31 return {sizeof(T), alignof(T)};
32 }
33};
34
35#elif ZIG_TYPE_INFO_IMPLEMENTATION == 1
36
37//
38// A non-portable way to get a human-readable type-name compatible with
39// non-RTTI C++ compiler mode; eg. `-fno-rtti`.
40//
41// Minimum requirements are c++11 and a compiler that has a constant for the
42// current function's decorated name whereby a template-type name can be
43// computed. eg. `__PRETTY_FUNCTION__` or `__FUNCSIG__`.
44//
45// given the following snippet:
46//
47// | #include <stdio.h>
48// |
49// | struct Top {};
50// | namespace mynamespace {
51// | using custom = unsigned int;
52// | struct Foo {
53// | struct Bar {};
54// | };
55// | };
56// |
57// | template <typename T>
58// | void foobar() {
59// | #ifdef _MSC_VER
60// | fprintf(stderr, "--> %s\n", __FUNCSIG__);
61// | #else
62// | fprintf(stderr, "--> %s\n", __PRETTY_FUNCTION__);
63// | #endif
64// | }
65// |
66// | int main() {
67// | foobar<Top>();
68// | foobar<unsigned int>();
69// | foobar<mynamespace::custom>();
70// | foobar<mynamespace::Foo*>();
71// | foobar<mynamespace::Foo::Bar*>();
72// | }
73//
74// gcc 9.2.0 produces:
75// --> void foobar() [with T = Top]
76// --> void foobar() [with T = unsigned int]
77// --> void foobar() [with T = unsigned int]
78// --> void foobar() [with T = mynamespace::Foo*]
79// --> void foobar() [with T = mynamespace::Foo::Bar*]
80//
81// xcode 11.3.1/clang produces:
82// --> void foobar() [T = Top]
83// --> void foobar() [T = unsigned int]
84// --> void foobar() [T = unsigned int]
85// --> void foobar() [T = mynamespace::Foo *]
86// --> void foobar() [T = mynamespace::Foo::Bar *]
87//
88// VStudio 2019 16.5.0/msvc produces:
89// --> void __cdecl foobar<struct Top>(void)
90// --> void __cdecl foobar<unsigned int>(void)
91// --> void __cdecl foobar<unsigned int>(void)
92// --> void __cdecl foobar<structmynamespace::Foo*>(void)
93// --> void __cdecl foobar<structmynamespace::Foo::Bar*>(void)
94//
95struct TypeInfo {
96 const char *name_ptr;
97 size_t name_len;
98 size_t size;
99 size_t alignment;
100
101 static constexpr TypeInfo to_type_info(const char *str, size_t start, size_t end, size_t size, size_t alignment) {
102 return TypeInfo{str + start, end - start, size, alignment};
103 }
104
105 static constexpr size_t index_of(const char *str, char c) {
106 return *str == c ? 0 : 1 + index_of(str + 1, c);
107 }
108
109 template <typename T>
110 static constexpr const char *decorated_name() {
111#ifdef _MSC_VER
112 return __FUNCSIG__;
113#else
114 return __PRETTY_FUNCTION__;
115#endif
116 }
117
118 static constexpr TypeInfo extract(const char *decorated, size_t size, size_t alignment) {
119#ifdef _MSC_VER
120 return to_type_info(decorated, index_of(decorated, '<') + 1, index_of(decorated, '>'), size, alignment);
121#else
122 return to_type_info(decorated, index_of(decorated, '=') + 2, index_of(decorated, ']'), size, alignment);
123#endif
124 }
125
126 template <typename T>
127 static constexpr TypeInfo make() {
128 return TypeInfo::extract(TypeInfo::decorated_name<T>(), sizeof(T), alignof(T));
129 }
130};
131
132#endif // ZIG_TYPE_INFO_IMPLEMENTATION
133
134} // namespace mem
135
136#endif
src/memory_profiling.cpp deleted-150
......@@ -1,150 +0,0 @@
1#include "memory_profiling.hpp"
2#include "hash_map.hpp"
3#include "list.hpp"
4#include "util.hpp"
5#include <string.h>
6
7#ifdef ZIG_ENABLE_MEM_PROFILE
8
9MemprofInternCount memprof_intern_count;
10
11static bool str_eql_str(const char *a, const char *b) {
12 return strcmp(a, b) == 0;
13}
14
15static uint32_t str_hash(const char *s) {
16 // FNV 32-bit hash
17 uint32_t h = 2166136261;
18 for (; *s; s += 1) {
19 h = h ^ *s;
20 h = h * 16777619;
21 }
22 return h;
23}
24
25struct CountAndSize {
26 size_t item_count;
27 size_t type_size;
28};
29
30ZigList<const char *> unknown_names = {};
31HashMap<const char *, CountAndSize, str_hash, str_eql_str> usage_table = {};
32bool table_active = false;
33
34static const char *get_default_name(const char *name_or_null, size_t type_size) {
35 if (name_or_null != nullptr) return name_or_null;
36 if (type_size >= unknown_names.length) {
37 table_active = false;
38 while (type_size >= unknown_names.length) {
39 unknown_names.append(nullptr);
40 }
41 table_active = true;
42 }
43 if (unknown_names.at(type_size) == nullptr) {
44 char buf[100];
45 sprintf(buf, "Unknown_%zu%c", type_size, 0);
46 unknown_names.at(type_size) = strdup(buf);
47 }
48 return unknown_names.at(type_size);
49}
50
51void memprof_alloc(const char *name, size_t count, size_t type_size) {
52 if (!table_active) return;
53 if (count == 0) return;
54 // temporarily disable during table put
55 table_active = false;
56 name = get_default_name(name, type_size);
57 auto existing_entry = usage_table.put_unique(name, {count, type_size});
58 if (existing_entry != nullptr) {
59 assert(existing_entry->value.type_size == type_size); // allocated name does not match type
60 existing_entry->value.item_count += count;
61 }
62 table_active = true;
63}
64
65void memprof_dealloc(const char *name, size_t count, size_t type_size) {
66 if (!table_active) return;
67 if (count == 0) return;
68 name = get_default_name(name, type_size);
69 auto existing_entry = usage_table.maybe_get(name);
70 if (existing_entry == nullptr) {
71 zig_panic("deallocated name '%s' (size %zu) not found in allocated table; compromised memory usage stats",
72 name, type_size);
73 }
74 if (existing_entry->value.type_size != type_size) {
75 zig_panic("deallocated name '%s' does not match expected type size %zu", name, type_size);
76 }
77 existing_entry->value.item_count -= count;
78}
79
80void memprof_init(void) {
81 usage_table.init(1024);
82 table_active = true;
83}
84
85struct MemItem {
86 const char *type_name;
87 CountAndSize count_and_size;
88};
89
90static size_t get_bytes(const MemItem *item) {
91 return item->count_and_size.item_count * item->count_and_size.type_size;
92}
93
94static int compare_bytes_desc(const void *a, const void *b) {
95 size_t size_a = get_bytes((const MemItem *)(a));
96 size_t size_b = get_bytes((const MemItem *)(b));
97 if (size_a > size_b)
98 return -1;
99 if (size_a < size_b)
100 return 1;
101 return 0;
102}
103
104void memprof_dump_stats(FILE *file) {
105 assert(table_active);
106 // disable modifications from this function
107 table_active = false;
108
109 ZigList<MemItem> list = {};
110
111 auto it = usage_table.entry_iterator();
112 for (;;) {
113 auto *entry = it.next();
114 if (!entry)
115 break;
116
117 list.append({entry->key, entry->value});
118 }
119
120 qsort(list.items, list.length, sizeof(MemItem), compare_bytes_desc);
121
122 size_t total_bytes_used = 0;
123
124 for (size_t i = 0; i < list.length; i += 1) {
125 const MemItem *item = &list.at(i);
126 fprintf(file, "%s: %zu items, %zu bytes each, total ", item->type_name,
127 item->count_and_size.item_count, item->count_and_size.type_size);
128 size_t bytes = get_bytes(item);
129 zig_pretty_print_bytes(file, bytes);
130 fprintf(file, "\n");
131
132 total_bytes_used += bytes;
133 }
134
135 fprintf(stderr, "Total bytes used: ");
136 zig_pretty_print_bytes(file, total_bytes_used);
137 fprintf(file, "\n");
138
139 list.deinit();
140 table_active = true;
141
142 fprintf(stderr, "\n");
143 fprintf(stderr, "undefined: interned %zu times\n", memprof_intern_count.x_undefined);
144 fprintf(stderr, "void: interned %zu times\n", memprof_intern_count.x_void);
145 fprintf(stderr, "null: interned %zu times\n", memprof_intern_count.x_null);
146 fprintf(stderr, "unreachable: interned %zu times\n", memprof_intern_count.x_unreachable);
147 fprintf(stderr, "zero_byte: interned %zu times\n", memprof_intern_count.zero_byte);
148}
149
150#endif
src/memory_profiling.hpp deleted-31
......@@ -1,31 +0,0 @@
1/*
2 * Copyright (c) 2019 Andrew Kelley
3 *
4 * This file is part of zig, which is MIT licensed.
5 * See http://opensource.org/licenses/MIT
6 */
7
8#ifndef ZIG_MEMORY_PROFILING_HPP
9#define ZIG_MEMORY_PROFILING_HPP
10
11#include "config.h"
12
13#include <stddef.h>
14#include <stdio.h>
15
16struct MemprofInternCount {
17 size_t x_undefined;
18 size_t x_void;
19 size_t x_null;
20 size_t x_unreachable;
21 size_t zero_byte;
22};
23extern MemprofInternCount memprof_intern_count;
24
25void memprof_init(void);
26
27void memprof_alloc(const char *name, size_t item_count, size_t type_size);
28void memprof_dealloc(const char *name, size_t item_count, size_t type_size);
29
30void memprof_dump_stats(FILE *file);
31#endif
src/os.cpp+7-7
......@@ -107,7 +107,7 @@ static void populate_termination(Termination *term, int status) {
107107}
108108
109109static void os_spawn_process_posix(ZigList<const char *> &args, Termination *term) {
110 const char **argv = allocate<const char *>(args.length + 1);
110 const char **argv = heap::c_allocator.allocate<const char *>(args.length + 1);
111111 for (size_t i = 0; i < args.length; i += 1) {
112112 argv[i] = args.at(i);
113113 }
......@@ -688,7 +688,7 @@ static Buf os_path_resolve_posix(Buf **paths_ptr, size_t paths_len) {
688688
689689 if (have_abs) {
690690 result_len = max_size;
691 result_ptr = allocate_nonzero<uint8_t>(result_len);
691 result_ptr = heap::c_allocator.allocate_nonzero<uint8_t>(result_len);
692692 } else {
693693 Buf cwd = BUF_INIT;
694694 int err;
......@@ -696,7 +696,7 @@ static Buf os_path_resolve_posix(Buf **paths_ptr, size_t paths_len) {
696696 zig_panic("get cwd failed");
697697 }
698698 result_len = max_size + buf_len(&cwd) + 1;
699 result_ptr = allocate_nonzero<uint8_t>(result_len);
699 result_ptr = heap::c_allocator.allocate_nonzero<uint8_t>(result_len);
700700 memcpy(result_ptr, buf_ptr(&cwd), buf_len(&cwd));
701701 result_index += buf_len(&cwd);
702702 }
......@@ -816,7 +816,7 @@ static Error os_exec_process_posix(ZigList<const char *> &args,
816816 if (dup2(stderr_pipe[1], STDERR_FILENO) == -1)
817817 zig_panic("dup2 failed");
818818
819 const char **argv = allocate<const char *>(args.length + 1);
819 const char **argv = heap::c_allocator.allocate<const char *>(args.length + 1);
820820 argv[args.length] = nullptr;
821821 for (size_t i = 0; i < args.length; i += 1) {
822822 argv[i] = args.at(i);
......@@ -1134,7 +1134,7 @@ static bool is_stderr_cyg_pty(void) {
11341134 if (stderr_handle == INVALID_HANDLE_VALUE)
11351135 return false;
11361136
1137 int size = sizeof(FILE_NAME_INFO) + sizeof(WCHAR) * MAX_PATH;
1137 const int size = sizeof(FILE_NAME_INFO) + sizeof(WCHAR) * MAX_PATH;
11381138 FILE_NAME_INFO *nameinfo;
11391139 WCHAR *p = NULL;
11401140
......@@ -1142,7 +1142,7 @@ static bool is_stderr_cyg_pty(void) {
11421142 if (GetFileType(stderr_handle) != FILE_TYPE_PIPE) {
11431143 return 0;
11441144 }
1145 nameinfo = (FILE_NAME_INFO *)allocate<char>(size);
1145 nameinfo = reinterpret_cast<FILE_NAME_INFO *>(heap::c_allocator.allocate<char>(size));
11461146 if (nameinfo == NULL) {
11471147 return 0;
11481148 }
......@@ -1179,7 +1179,7 @@ static bool is_stderr_cyg_pty(void) {
11791179 }
11801180 }
11811181 }
1182 free(nameinfo);
1182 heap::c_allocator.deallocate(reinterpret_cast<char *>(nameinfo), size);
11831183 return (p != NULL);
11841184}
11851185#endif
src/parser.cpp+3-3
......@@ -147,7 +147,7 @@ static void ast_invalid_token_error(ParseContext *pc, Token *token) {
147147}
148148
149149static AstNode *ast_create_node_no_line_info(ParseContext *pc, NodeType type) {
150 AstNode *node = allocate<AstNode>(1, "AstNode");
150 AstNode *node = heap::c_allocator.create<AstNode>();
151151 node->type = type;
152152 node->owner = pc->owner;
153153 return node;
......@@ -1966,7 +1966,7 @@ static AsmOutput *ast_parse_asm_output_item(ParseContext *pc) {
19661966
19671967 expect_token(pc, TokenIdRParen);
19681968
1969 AsmOutput *res = allocate<AsmOutput>(1);
1969 AsmOutput *res = heap::c_allocator.create<AsmOutput>();
19701970 res->asm_symbolic_name = token_buf(sym_name);
19711971 res->constraint = token_buf(str);
19721972 res->variable_name = token_buf(var_name);
......@@ -2003,7 +2003,7 @@ static AsmInput *ast_parse_asm_input_item(ParseContext *pc) {
20032003 AstNode *expr = ast_expect(pc, ast_parse_expr);
20042004 expect_token(pc, TokenIdRParen);
20052005
2006 AsmInput *res = allocate<AsmInput>(1);
2006 AsmInput *res = heap::c_allocator.create<AsmInput>();
20072007 res->asm_symbolic_name = token_buf(sym_name);
20082008 res->constraint = token_buf(constraint);
20092009 res->expr = expr;
src/target.cpp+1-1
......@@ -520,7 +520,7 @@ void get_native_target(ZigTarget *target) {
520520 target->abi = target_default_abi(target->arch, target->os);
521521 }
522522 if (target_is_glibc(target)) {
523 target->glibc_version = allocate<ZigGLibCVersion>(1);
523 target->glibc_version = heap::c_allocator.create<ZigGLibCVersion>();
524524 target_init_default_glibc_version(target);
525525#ifdef ZIG_OS_LINUX
526526 Error err;
src/tokenizer.cpp+2-2
......@@ -397,10 +397,10 @@ static void invalid_char_error(Tokenize *t, uint8_t c) {
397397void tokenize(Buf *buf, Tokenization *out) {
398398 Tokenize t = {0};
399399 t.out = out;
400 t.tokens = out->tokens = allocate<ZigList<Token>>(1);
400 t.tokens = out->tokens = heap::c_allocator.create<ZigList<Token>>();
401401 t.buf = buf;
402402
403 out->line_offsets = allocate<ZigList<size_t>>(1);
403 out->line_offsets = heap::c_allocator.create<ZigList<size_t>>();
404404 out->line_offsets->append(0);
405405
406406 // Skip the UTF-8 BOM if present
src/userland.cpp+2-2
......@@ -101,7 +101,7 @@ Error stage2_cpu_features_parse(struct Stage2CpuFeatures **out, const char *zig_
101101 const char *cpu_name, const char *cpu_features)
102102{
103103 if (zig_triple == nullptr) {
104 Stage2CpuFeatures *result = allocate<Stage2CpuFeatures>(1, "Stage2CpuFeatures");
104 Stage2CpuFeatures *result = heap::c_allocator.create<Stage2CpuFeatures>();
105105 result->llvm_cpu_name = ZigLLVMGetHostCPUName();
106106 result->llvm_cpu_features = ZigLLVMGetNativeFeatures();
107107 result->builtin_str = "arch.getBaselineCpuFeatures();\n";
......@@ -110,7 +110,7 @@ Error stage2_cpu_features_parse(struct Stage2CpuFeatures **out, const char *zig_
110110 return ErrorNone;
111111 }
112112 if (cpu_name == nullptr && cpu_features == nullptr) {
113 Stage2CpuFeatures *result = allocate<Stage2CpuFeatures>(1, "Stage2CpuFeatures");
113 Stage2CpuFeatures *result = heap::c_allocator.create<Stage2CpuFeatures>();
114114 result->builtin_str = "arch.getBaselineCpuFeatures();\n";
115115 result->cache_hash = "\n\n";
116116 *out = result;
src/util.hpp+5-127
......@@ -8,69 +8,19 @@
88#ifndef ZIG_UTIL_HPP
99#define ZIG_UTIL_HPP
1010
11#include "memory_profiling.hpp"
12
1311#include <stdlib.h>
1412#include <stdint.h>
1513#include <string.h>
16#include <assert.h>
1714#include <ctype.h>
1815
1916#if defined(_MSC_VER)
20
2117#include <intrin.h>
22
23#define ATTRIBUTE_COLD __declspec(noinline)
24#define ATTRIBUTE_PRINTF(a, b)
25#define ATTRIBUTE_RETURNS_NOALIAS __declspec(restrict)
26#define ATTRIBUTE_NORETURN __declspec(noreturn)
27#define ATTRIBUTE_MUST_USE
28
29#define BREAKPOINT __debugbreak()
30
31#else
32
33#define ATTRIBUTE_COLD __attribute__((cold))
34#define ATTRIBUTE_PRINTF(a, b) __attribute__((format(printf, a, b)))
35#define ATTRIBUTE_RETURNS_NOALIAS __attribute__((__malloc__))
36#define ATTRIBUTE_NORETURN __attribute__((noreturn))
37#define ATTRIBUTE_MUST_USE __attribute__((warn_unused_result))
38
39#if defined(__MINGW32__) || defined(__MINGW64__)
40#define BREAKPOINT __debugbreak()
41#elif defined(__i386__) || defined(__x86_64__)
42#define BREAKPOINT __asm__ volatile("int $0x03");
43#elif defined(__clang__)
44#define BREAKPOINT __builtin_debugtrap()
45#elif defined(__GNUC__)
46#define BREAKPOINT __builtin_trap()
47#else
48#include <signal.h>
49#define BREAKPOINT raise(SIGTRAP)
50#endif
51
52#endif
53
54ATTRIBUTE_COLD
55ATTRIBUTE_NORETURN
56ATTRIBUTE_PRINTF(1, 2)
57void zig_panic(const char *format, ...);
58
59static inline void zig_assert(bool ok, const char *file, int line, const char *func) {
60 if (!ok) {
61 zig_panic("Assertion failed at %s:%d in %s. This is a bug in the Zig compiler.", file, line, func);
62 }
63}
64
65#ifdef _WIN32
66#define __func__ __FUNCTION__
6718#endif
6819
69#define zig_unreachable() zig_panic("Unreachable at %s:%d in %s. This is a bug in the Zig compiler.", __FILE__, __LINE__, __func__)
70
71// Assertions in stage1 are always on, and they call zig @panic.
72#undef assert
73#define assert(ok) zig_assert(ok, __FILE__, __LINE__, __func__)
20#include "config.h"
21#include "util_base.hpp"
22#include "heap.hpp"
23#include "mem.hpp"
7424
7525#if defined(_MSC_VER)
7626static inline int clzll(unsigned long long mask) {
......@@ -107,78 +57,6 @@ static inline int ctzll(unsigned long long mask) {
10757#define ctzll(x) __builtin_ctzll(x)
10858#endif
10959
110
111template<typename T>
112ATTRIBUTE_RETURNS_NOALIAS static inline T *allocate_nonzero(size_t count, const char *name = nullptr) {
113#ifdef ZIG_ENABLE_MEM_PROFILE
114 memprof_alloc(name, count, sizeof(T));
115#endif
116#ifndef NDEBUG
117 // make behavior when size == 0 portable
118 if (count == 0)
119 return nullptr;
120#endif
121 T *ptr = reinterpret_cast<T*>(malloc(count * sizeof(T)));
122 if (!ptr)
123 zig_panic("allocation failed");
124 return ptr;
125}
126
127template<typename T>
128ATTRIBUTE_RETURNS_NOALIAS static inline T *allocate(size_t count, const char *name = nullptr) {
129#ifdef ZIG_ENABLE_MEM_PROFILE
130 memprof_alloc(name, count, sizeof(T));
131#endif
132#ifndef NDEBUG
133 // make behavior when size == 0 portable
134 if (count == 0)
135 return nullptr;
136#endif
137 T *ptr = reinterpret_cast<T*>(calloc(count, sizeof(T)));
138 if (!ptr)
139 zig_panic("allocation failed");
140 return ptr;
141}
142
143template<typename T>
144static inline T *reallocate(T *old, size_t old_count, size_t new_count, const char *name = nullptr) {
145 T *ptr = reallocate_nonzero(old, old_count, new_count);
146 if (new_count > old_count) {
147 memset(&ptr[old_count], 0, (new_count - old_count) * sizeof(T));
148 }
149 return ptr;
150}
151
152template<typename T>
153static inline T *reallocate_nonzero(T *old, size_t old_count, size_t new_count, const char *name = nullptr) {
154#ifdef ZIG_ENABLE_MEM_PROFILE
155 memprof_dealloc(name, old_count, sizeof(T));
156 memprof_alloc(name, new_count, sizeof(T));
157#endif
158#ifndef NDEBUG
159 // make behavior when size == 0 portable
160 if (new_count == 0 && old == nullptr)
161 return nullptr;
162#endif
163 T *ptr = reinterpret_cast<T*>(realloc(old, new_count * sizeof(T)));
164 if (!ptr)
165 zig_panic("allocation failed");
166 return ptr;
167}
168
169template<typename T>
170static inline void deallocate(T *old, size_t count, const char *name = nullptr) {
171#ifdef ZIG_ENABLE_MEM_PROFILE
172 memprof_dealloc(name, count, sizeof(T));
173#endif
174 free(old);
175}
176
177template<typename T>
178static inline void destroy(T *old, const char *name = nullptr) {
179 return deallocate(old, 1, name);
180}
181
18260template <typename T, size_t n>
18361constexpr size_t array_length(const T (&)[n]) {
18462 return n;
......@@ -293,7 +171,7 @@ struct Slice {
293171 }
294172
295173 static inline Slice<T> alloc(size_t n) {
296 return {allocate_nonzero<T>(n), n};
174 return {heap::c_allocator.allocate_nonzero<T>(n), n};
297175 }
298176};
299177
src/util_base.hpp created+67
......@@ -0,0 +1,67 @@
1/*
2 * Copyright (c) 2015 Andrew Kelley
3 *
4 * This file is part of zig, which is MIT licensed.
5 * See http://opensource.org/licenses/MIT
6 */
7
8#ifndef ZIG_UTIL_BASE_HPP
9#define ZIG_UTIL_BASE_HPP
10
11#include <assert.h>
12
13#if defined(_MSC_VER)
14
15#define ATTRIBUTE_COLD __declspec(noinline)
16#define ATTRIBUTE_PRINTF(a, b)
17#define ATTRIBUTE_RETURNS_NOALIAS __declspec(restrict)
18#define ATTRIBUTE_NORETURN __declspec(noreturn)
19#define ATTRIBUTE_MUST_USE
20
21#define BREAKPOINT __debugbreak()
22
23#else
24
25#define ATTRIBUTE_COLD __attribute__((cold))
26#define ATTRIBUTE_PRINTF(a, b) __attribute__((format(printf, a, b)))
27#define ATTRIBUTE_RETURNS_NOALIAS __attribute__((__malloc__))
28#define ATTRIBUTE_NORETURN __attribute__((noreturn))
29#define ATTRIBUTE_MUST_USE __attribute__((warn_unused_result))
30
31#if defined(__MINGW32__) || defined(__MINGW64__)
32#define BREAKPOINT __debugbreak()
33#elif defined(__i386__) || defined(__x86_64__)
34#define BREAKPOINT __asm__ volatile("int $0x03");
35#elif defined(__clang__)
36#define BREAKPOINT __builtin_debugtrap()
37#elif defined(__GNUC__)
38#define BREAKPOINT __builtin_trap()
39#else
40#include <signal.h>
41#define BREAKPOINT raise(SIGTRAP)
42#endif
43
44#endif
45
46ATTRIBUTE_COLD
47ATTRIBUTE_NORETURN
48ATTRIBUTE_PRINTF(1, 2)
49void zig_panic(const char *format, ...);
50
51static inline void zig_assert(bool ok, const char *file, int line, const char *func) {
52 if (!ok) {
53 zig_panic("Assertion failed at %s:%d in %s. This is a bug in the Zig compiler.", file, line, func);
54 }
55}
56
57#ifdef _WIN32
58#define __func__ __FUNCTION__
59#endif
60
61#define zig_unreachable() zig_panic("Unreachable at %s:%d in %s. This is a bug in the Zig compiler.", __FILE__, __LINE__, __func__)
62
63// Assertions in stage1 are always on, and they call zig @panic.
64#undef assert
65#define assert(ok) zig_assert(ok, __FILE__, __LINE__, __func__)
66
67#endif