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")...@@ -450,7 +450,7 @@ set(ZIG_MAIN_SRC "${CMAKE_SOURCE_DIR}/src/main.cpp")
450set(ZIG0_SHIM_SRC "${CMAKE_SOURCE_DIR}/src/userland.cpp")450set(ZIG0_SHIM_SRC "${CMAKE_SOURCE_DIR}/src/userland.cpp")
451451
452if(ZIG_ENABLE_MEM_PROFILE)452if(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")
454endif()454endif()
455455
456set(ZIG_SOURCES456set(ZIG_SOURCES
...@@ -466,10 +466,12 @@ set(ZIG_SOURCES...@@ -466,10 +466,12 @@ set(ZIG_SOURCES
466 "${CMAKE_SOURCE_DIR}/src/errmsg.cpp"466 "${CMAKE_SOURCE_DIR}/src/errmsg.cpp"
467 "${CMAKE_SOURCE_DIR}/src/error.cpp"467 "${CMAKE_SOURCE_DIR}/src/error.cpp"
468 "${CMAKE_SOURCE_DIR}/src/glibc.cpp"468 "${CMAKE_SOURCE_DIR}/src/glibc.cpp"
469 "${CMAKE_SOURCE_DIR}/src/heap.cpp"
469 "${CMAKE_SOURCE_DIR}/src/ir.cpp"470 "${CMAKE_SOURCE_DIR}/src/ir.cpp"
470 "${CMAKE_SOURCE_DIR}/src/ir_print.cpp"471 "${CMAKE_SOURCE_DIR}/src/ir_print.cpp"
471 "${CMAKE_SOURCE_DIR}/src/libc_installation.cpp"472 "${CMAKE_SOURCE_DIR}/src/libc_installation.cpp"
472 "${CMAKE_SOURCE_DIR}/src/link.cpp"473 "${CMAKE_SOURCE_DIR}/src/link.cpp"
474 "${CMAKE_SOURCE_DIR}/src/mem.cpp"
473 "${CMAKE_SOURCE_DIR}/src/os.cpp"475 "${CMAKE_SOURCE_DIR}/src/os.cpp"
474 "${CMAKE_SOURCE_DIR}/src/parser.cpp"476 "${CMAKE_SOURCE_DIR}/src/parser.cpp"
475 "${CMAKE_SOURCE_DIR}/src/range_set.cpp"477 "${CMAKE_SOURCE_DIR}/src/range_set.cpp"
src/all_types.hpp+3-1
...@@ -2000,6 +2000,9 @@ struct CFile {...@@ -2000,6 +2000,9 @@ struct CFile {
20002000
2001// When adding fields, check if they should be added to the hash computation in build_with_cache2001// When adding fields, check if they should be added to the hash computation in build_with_cache
2002struct CodeGen {2002struct CodeGen {
2003 // arena allocator destroyed just prior to codegen emit
2004 heap::ArenaAllocator *pass1_arena;
2005
2003 //////////////////////////// Runtime State2006 //////////////////////////// Runtime State
2004 LLVMModuleRef module;2007 LLVMModuleRef module;
2005 ZigList<ErrorMsg*> errors;2008 ZigList<ErrorMsg*> errors;
...@@ -2280,7 +2283,6 @@ struct ZigVar {...@@ -2280,7 +2283,6 @@ struct ZigVar {
2280 Scope *parent_scope;2283 Scope *parent_scope;
2281 Scope *child_scope;2284 Scope *child_scope;
2282 LLVMValueRef param_value_ref;2285 LLVMValueRef param_value_ref;
2283 IrExecutableSrc *owner_exec;
22842286
2285 Buf *section_name;2287 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,...@@ -80,7 +80,7 @@ ErrorMsg *add_error_note(CodeGen *g, ErrorMsg *parent_msg, const AstNode *node,
80}80}
8181
82ZigType *new_type_table_entry(ZigTypeId id) {82ZigType *new_type_table_entry(ZigTypeId id) {
83 ZigType *entry = allocate<ZigType>(1);83 ZigType *entry = heap::c_allocator.create<ZigType>();
84 entry->id = id;84 entry->id = id;
85 return entry;85 return entry;
86}86}
...@@ -140,7 +140,7 @@ void init_scope(CodeGen *g, Scope *dest, ScopeId id, AstNode *source_node, Scope...@@ -140,7 +140,7 @@ void init_scope(CodeGen *g, Scope *dest, ScopeId id, AstNode *source_node, Scope
140static ScopeDecls *create_decls_scope(CodeGen *g, AstNode *node, Scope *parent, ZigType *container_type,140static ScopeDecls *create_decls_scope(CodeGen *g, AstNode *node, Scope *parent, ZigType *container_type,
141 ZigType *import, Buf *bare_name)141 ZigType *import, Buf *bare_name)
142{142{
143 ScopeDecls *scope = allocate<ScopeDecls>(1);143 ScopeDecls *scope = heap::c_allocator.create<ScopeDecls>();
144 init_scope(g, &scope->base, ScopeIdDecls, node, parent);144 init_scope(g, &scope->base, ScopeIdDecls, node, parent);
145 scope->decl_table.init(4);145 scope->decl_table.init(4);
146 scope->container_type = container_type;146 scope->container_type = container_type;
...@@ -151,7 +151,7 @@ static ScopeDecls *create_decls_scope(CodeGen *g, AstNode *node, Scope *parent,...@@ -151,7 +151,7 @@ static ScopeDecls *create_decls_scope(CodeGen *g, AstNode *node, Scope *parent,
151151
152ScopeBlock *create_block_scope(CodeGen *g, AstNode *node, Scope *parent) {152ScopeBlock *create_block_scope(CodeGen *g, AstNode *node, Scope *parent) {
153 assert(node->type == NodeTypeBlock);153 assert(node->type == NodeTypeBlock);
154 ScopeBlock *scope = allocate<ScopeBlock>(1);154 ScopeBlock *scope = heap::c_allocator.create<ScopeBlock>();
155 init_scope(g, &scope->base, ScopeIdBlock, node, parent);155 init_scope(g, &scope->base, ScopeIdBlock, node, parent);
156 scope->name = node->data.block.name;156 scope->name = node->data.block.name;
157 return scope;157 return scope;
...@@ -159,20 +159,20 @@ ScopeBlock *create_block_scope(CodeGen *g, AstNode *node, Scope *parent) {...@@ -159,20 +159,20 @@ ScopeBlock *create_block_scope(CodeGen *g, AstNode *node, Scope *parent) {
159159
160ScopeDefer *create_defer_scope(CodeGen *g, AstNode *node, Scope *parent) {160ScopeDefer *create_defer_scope(CodeGen *g, AstNode *node, Scope *parent) {
161 assert(node->type == NodeTypeDefer);161 assert(node->type == NodeTypeDefer);
162 ScopeDefer *scope = allocate<ScopeDefer>(1);162 ScopeDefer *scope = heap::c_allocator.create<ScopeDefer>();
163 init_scope(g, &scope->base, ScopeIdDefer, node, parent);163 init_scope(g, &scope->base, ScopeIdDefer, node, parent);
164 return scope;164 return scope;
165}165}
166166
167ScopeDeferExpr *create_defer_expr_scope(CodeGen *g, AstNode *node, Scope *parent) {167ScopeDeferExpr *create_defer_expr_scope(CodeGen *g, AstNode *node, Scope *parent) {
168 assert(node->type == NodeTypeDefer);168 assert(node->type == NodeTypeDefer);
169 ScopeDeferExpr *scope = allocate<ScopeDeferExpr>(1);169 ScopeDeferExpr *scope = heap::c_allocator.create<ScopeDeferExpr>();
170 init_scope(g, &scope->base, ScopeIdDeferExpr, node, parent);170 init_scope(g, &scope->base, ScopeIdDeferExpr, node, parent);
171 return scope;171 return scope;
172}172}
173173
174Scope *create_var_scope(CodeGen *g, AstNode *node, Scope *parent, ZigVar *var) {174Scope *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>();
176 init_scope(g, &scope->base, ScopeIdVarDecl, node, parent);176 init_scope(g, &scope->base, ScopeIdVarDecl, node, parent);
177 scope->var = var;177 scope->var = var;
178 return &scope->base;178 return &scope->base;
...@@ -180,14 +180,14 @@ Scope *create_var_scope(CodeGen *g, AstNode *node, Scope *parent, ZigVar *var) {...@@ -180,14 +180,14 @@ Scope *create_var_scope(CodeGen *g, AstNode *node, Scope *parent, ZigVar *var) {
180180
181ScopeCImport *create_cimport_scope(CodeGen *g, AstNode *node, Scope *parent) {181ScopeCImport *create_cimport_scope(CodeGen *g, AstNode *node, Scope *parent) {
182 assert(node->type == NodeTypeFnCallExpr);182 assert(node->type == NodeTypeFnCallExpr);
183 ScopeCImport *scope = allocate<ScopeCImport>(1);183 ScopeCImport *scope = heap::c_allocator.create<ScopeCImport>();
184 init_scope(g, &scope->base, ScopeIdCImport, node, parent);184 init_scope(g, &scope->base, ScopeIdCImport, node, parent);
185 buf_resize(&scope->buf, 0);185 buf_resize(&scope->buf, 0);
186 return scope;186 return scope;
187}187}
188188
189ScopeLoop *create_loop_scope(CodeGen *g, AstNode *node, Scope *parent) {189ScopeLoop *create_loop_scope(CodeGen *g, AstNode *node, Scope *parent) {
190 ScopeLoop *scope = allocate<ScopeLoop>(1);190 ScopeLoop *scope = heap::c_allocator.create<ScopeLoop>();
191 init_scope(g, &scope->base, ScopeIdLoop, node, parent);191 init_scope(g, &scope->base, ScopeIdLoop, node, parent);
192 if (node->type == NodeTypeWhileExpr) {192 if (node->type == NodeTypeWhileExpr) {
193 scope->name = node->data.while_expr.name;193 scope->name = node->data.while_expr.name;
...@@ -200,7 +200,7 @@ ScopeLoop *create_loop_scope(CodeGen *g, AstNode *node, Scope *parent) {...@@ -200,7 +200,7 @@ ScopeLoop *create_loop_scope(CodeGen *g, AstNode *node, Scope *parent) {
200}200}
201201
202Scope *create_runtime_scope(CodeGen *g, AstNode *node, Scope *parent, IrInstSrc *is_comptime) {202Scope *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>();
204 scope->is_comptime = is_comptime;204 scope->is_comptime = is_comptime;
205 init_scope(g, &scope->base, ScopeIdRuntime, node, parent);205 init_scope(g, &scope->base, ScopeIdRuntime, node, parent);
206 return &scope->base;206 return &scope->base;
...@@ -208,37 +208,37 @@ Scope *create_runtime_scope(CodeGen *g, AstNode *node, Scope *parent, IrInstSrc...@@ -208,37 +208,37 @@ Scope *create_runtime_scope(CodeGen *g, AstNode *node, Scope *parent, IrInstSrc
208208
209ScopeSuspend *create_suspend_scope(CodeGen *g, AstNode *node, Scope *parent) {209ScopeSuspend *create_suspend_scope(CodeGen *g, AstNode *node, Scope *parent) {
210 assert(node->type == NodeTypeSuspend);210 assert(node->type == NodeTypeSuspend);
211 ScopeSuspend *scope = allocate<ScopeSuspend>(1);211 ScopeSuspend *scope = heap::c_allocator.create<ScopeSuspend>();
212 init_scope(g, &scope->base, ScopeIdSuspend, node, parent);212 init_scope(g, &scope->base, ScopeIdSuspend, node, parent);
213 return scope;213 return scope;
214}214}
215215
216ScopeFnDef *create_fndef_scope(CodeGen *g, AstNode *node, Scope *parent, ZigFn *fn_entry) {216ScopeFnDef *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>();
218 init_scope(g, &scope->base, ScopeIdFnDef, node, parent);218 init_scope(g, &scope->base, ScopeIdFnDef, node, parent);
219 scope->fn_entry = fn_entry;219 scope->fn_entry = fn_entry;
220 return scope;220 return scope;
221}221}
222222
223Scope *create_comptime_scope(CodeGen *g, AstNode *node, Scope *parent) {223Scope *create_comptime_scope(CodeGen *g, AstNode *node, Scope *parent) {
224 ScopeCompTime *scope = allocate<ScopeCompTime>(1);224 ScopeCompTime *scope = heap::c_allocator.create<ScopeCompTime>();
225 init_scope(g, &scope->base, ScopeIdCompTime, node, parent);225 init_scope(g, &scope->base, ScopeIdCompTime, node, parent);
226 return &scope->base;226 return &scope->base;
227}227}
228228
229Scope *create_typeof_scope(CodeGen *g, AstNode *node, Scope *parent) {229Scope *create_typeof_scope(CodeGen *g, AstNode *node, Scope *parent) {
230 ScopeTypeOf *scope = allocate<ScopeTypeOf>(1);230 ScopeTypeOf *scope = heap::c_allocator.create<ScopeTypeOf>();
231 init_scope(g, &scope->base, ScopeIdTypeOf, node, parent);231 init_scope(g, &scope->base, ScopeIdTypeOf, node, parent);
232 return &scope->base;232 return &scope->base;
233}233}
234234
235ScopeExpr *create_expr_scope(CodeGen *g, AstNode *node, Scope *parent) {235ScopeExpr *create_expr_scope(CodeGen *g, AstNode *node, Scope *parent) {
236 ScopeExpr *scope = allocate<ScopeExpr>(1);236 ScopeExpr *scope = heap::c_allocator.create<ScopeExpr>();
237 init_scope(g, &scope->base, ScopeIdExpr, node, parent);237 init_scope(g, &scope->base, ScopeIdExpr, node, parent);
238 ScopeExpr *parent_expr = find_expr_scope(parent);238 ScopeExpr *parent_expr = find_expr_scope(parent);
239 if (parent_expr != nullptr) {239 if (parent_expr != nullptr) {
240 size_t new_len = parent_expr->children_len + 1;240 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 *>(
242 parent_expr->children_ptr, parent_expr->children_len, new_len);242 parent_expr->children_ptr, parent_expr->children_len, new_len);
243 parent_expr->children_ptr[parent_expr->children_len] = scope;243 parent_expr->children_ptr[parent_expr->children_len] = scope;
244 parent_expr->children_len = new_len;244 parent_expr->children_len = new_len;
...@@ -1104,8 +1104,8 @@ ZigValue *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, ZigType *...@@ -1104,8 +1104,8 @@ ZigValue *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, ZigType *
1104{1104{
1105 Error err;1105 Error err;
11061106
1107 ZigValue *result = create_const_vals(1);1107 ZigValue *result = g->pass1_arena->create<ZigValue>();
1108 ZigValue *result_ptr = create_const_vals(1);1108 ZigValue *result_ptr = g->pass1_arena->create<ZigValue>();
1109 result->special = ConstValSpecialUndef;1109 result->special = ConstValSpecialUndef;
1110 result->type = (type_entry == nullptr) ? g->builtin_types.entry_var : type_entry;1110 result->type = (type_entry == nullptr) ? g->builtin_types.entry_var : type_entry;
1111 result_ptr->special = ConstValSpecialStatic;1111 result_ptr->special = ConstValSpecialStatic;
...@@ -1122,7 +1122,6 @@ ZigValue *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, ZigType *...@@ -1122,7 +1122,6 @@ ZigValue *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, ZigType *
1122 {1122 {
1123 return g->invalid_inst_gen->value;1123 return g->invalid_inst_gen->value;
1124 }1124 }
1125 destroy(result_ptr, "ZigValue");
1126 return result;1125 return result;
1127}1126}
11281127
...@@ -1507,7 +1506,7 @@ void init_fn_type_id(FnTypeId *fn_type_id, AstNode *proto_node, CallingConventio...@@ -1507,7 +1506,7 @@ void init_fn_type_id(FnTypeId *fn_type_id, AstNode *proto_node, CallingConventio
15071506
1508 fn_type_id->cc = cc;1507 fn_type_id->cc = cc;
1509 fn_type_id->param_count = fn_proto->params.length;1508 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);
1511 fn_type_id->next_param_index = 0;1510 fn_type_id->next_param_index = 0;
1512 fn_type_id->is_var_args = fn_proto->is_var_args;1511 fn_type_id->is_var_args = fn_proto->is_var_args;
1513}1512}
...@@ -2171,7 +2170,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {...@@ -2171,7 +2170,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {
2171 bool packed = (struct_type->data.structure.layout == ContainerLayoutPacked);2170 bool packed = (struct_type->data.structure.layout == ContainerLayoutPacked);
2172 struct_type->data.structure.resolve_loop_flag_other = true;2171 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
2176 size_t packed_bits_offset = 0;2175 size_t packed_bits_offset = 0;
2177 size_t next_offset = 0;2176 size_t next_offset = 0;
...@@ -2657,7 +2656,7 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) {...@@ -2657,7 +2656,7 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) {
2657 }2656 }
26582657
2659 enum_type->data.enumeration.src_field_count = field_count;2658 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);
2661 enum_type->data.enumeration.fields_by_name.init(field_count);2660 enum_type->data.enumeration.fields_by_name.init(field_count);
26622661
2663 HashMap<BigInt, AstNode *, bigint_hash, bigint_eql> occupied_tag_values = {};2662 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) {...@@ -3034,7 +3033,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
3034 return ErrorSemanticAnalyzeFail;3033 return ErrorSemanticAnalyzeFail;
3035 }3034 }
3036 union_type->data.unionation.src_field_count = field_count;3035 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);
3038 union_type->data.unionation.fields_by_name.init(field_count);3037 union_type->data.unionation.fields_by_name.init(field_count);
30393038
3040 Scope *scope = &union_type->data.unionation.decls_scope->base;3039 Scope *scope = &union_type->data.unionation.decls_scope->base;
...@@ -3053,7 +3052,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {...@@ -3053,7 +3052,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
3053 if (create_enum_type) {3052 if (create_enum_type) {
3054 occupied_tag_values.init(field_count);3053 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
3058 ZigType *tag_int_type;3057 ZigType *tag_int_type;
3059 if (enum_type_node != nullptr) {3058 if (enum_type_node != nullptr) {
...@@ -3086,7 +3085,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {...@@ -3086,7 +3085,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
3086 tag_type->data.enumeration.decl_node = decl_node;3085 tag_type->data.enumeration.decl_node = decl_node;
3087 tag_type->data.enumeration.layout = ContainerLayoutAuto;3086 tag_type->data.enumeration.layout = ContainerLayoutAuto;
3088 tag_type->data.enumeration.src_field_count = field_count;3087 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);
3090 tag_type->data.enumeration.fields_by_name.init(field_count);3089 tag_type->data.enumeration.fields_by_name.init(field_count);
3091 tag_type->data.enumeration.decls_scope = union_type->data.unionation.decls_scope;3090 tag_type->data.enumeration.decls_scope = union_type->data.unionation.decls_scope;
3092 } else if (enum_type_node != nullptr) {3091 } else if (enum_type_node != nullptr) {
...@@ -3106,7 +3105,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {...@@ -3106,7 +3105,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
3106 return err;3105 return err;
3107 }3106 }
3108 tag_type = enum_type;3107 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);
3110 } else {3109 } else {
3111 tag_type = nullptr;3110 tag_type = nullptr;
3112 }3111 }
...@@ -3244,7 +3243,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {...@@ -3244,7 +3243,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
3244 }3243 }
3245 covered_enum_fields[union_field->enum_field->decl_index] = true;3244 covered_enum_fields[union_field->enum_field->decl_index] = true;
3246 } else {3245 } else {
3247 union_field->enum_field = allocate<TypeEnumField>(1);3246 union_field->enum_field = heap::c_allocator.create<TypeEnumField>();
3248 union_field->enum_field->name = field_name;3247 union_field->enum_field->name = field_name;
3249 union_field->enum_field->decl_index = i;3248 union_field->enum_field->decl_index = i;
3250 bigint_init_unsigned(&union_field->enum_field->value, i);3249 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...@@ -3366,8 +3365,8 @@ static void get_fully_qualified_decl_name(CodeGen *g, Buf *buf, Tld *tld, bool i
3366}3365}
33673366
3368ZigFn *create_fn_raw(CodeGen *g, FnInline inline_value) {3367ZigFn *create_fn_raw(CodeGen *g, FnInline inline_value) {
3369 ZigFn *fn_entry = allocate<ZigFn>(1, "ZigFn");3368 ZigFn *fn_entry = heap::c_allocator.create<ZigFn>();
3370 fn_entry->ir_executable = allocate<IrExecutableSrc>(1, "IrExecutableSrc");3369 fn_entry->ir_executable = heap::c_allocator.create<IrExecutableSrc>();
33713370
3372 fn_entry->prealloc_backward_branch_quota = default_backward_branch_quota;3371 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...@@ -3642,7 +3641,7 @@ static void preview_test_decl(CodeGen *g, AstNode *node, ScopeDecls *decls_scope
3642 return;3641 return;
3643 }3642 }
36443643
3645 TldFn *tld_fn = allocate<TldFn>(1);3644 TldFn *tld_fn = heap::c_allocator.create<TldFn>();
3646 init_tld(&tld_fn->base, TldIdFn, test_name, VisibModPrivate, node, &decls_scope->base);3645 init_tld(&tld_fn->base, TldIdFn, test_name, VisibModPrivate, node, &decls_scope->base);
3647 g->resolve_queue.append(&tld_fn->base);3646 g->resolve_queue.append(&tld_fn->base);
3648}3647}
...@@ -3650,7 +3649,7 @@ static void preview_test_decl(CodeGen *g, AstNode *node, ScopeDecls *decls_scope...@@ -3650,7 +3649,7 @@ static void preview_test_decl(CodeGen *g, AstNode *node, ScopeDecls *decls_scope
3650static void preview_comptime_decl(CodeGen *g, AstNode *node, ScopeDecls *decls_scope) {3649static void preview_comptime_decl(CodeGen *g, AstNode *node, ScopeDecls *decls_scope) {
3651 assert(node->type == NodeTypeCompTime);3650 assert(node->type == NodeTypeCompTime);
36523651
3653 TldCompTime *tld_comptime = allocate<TldCompTime>(1);3652 TldCompTime *tld_comptime = heap::c_allocator.create<TldCompTime>();
3654 init_tld(&tld_comptime->base, TldIdCompTime, nullptr, VisibModPrivate, node, &decls_scope->base);3653 init_tld(&tld_comptime->base, TldIdCompTime, nullptr, VisibModPrivate, node, &decls_scope->base);
3655 g->resolve_queue.append(&tld_comptime->base);3654 g->resolve_queue.append(&tld_comptime->base);
3656}3655}
...@@ -3673,7 +3672,7 @@ void update_compile_var(CodeGen *g, Buf *name, ZigValue *value) {...@@ -3673,7 +3672,7 @@ void update_compile_var(CodeGen *g, Buf *name, ZigValue *value) {
3673 resolve_top_level_decl(g, tld, tld->source_node, false);3672 resolve_top_level_decl(g, tld, tld->source_node, false);
3674 assert(tld->id == TldIdVar && tld->resolution == TldResolutionOk);3673 assert(tld->id == TldIdVar && tld->resolution == TldResolutionOk);
3675 TldVar *tld_var = (TldVar *)tld;3674 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);
3677 tld_var->var->var_type = value->type;3676 tld_var->var->var_type = value->type;
3678 tld_var->var->align_bytes = get_abi_alignment(g, value->type);3677 tld_var->var->align_bytes = get_abi_alignment(g, value->type);
3679}3678}
...@@ -3693,7 +3692,7 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {...@@ -3693,7 +3692,7 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {
3693 {3692 {
3694 Buf *name = node->data.variable_declaration.symbol;3693 Buf *name = node->data.variable_declaration.symbol;
3695 VisibMod visib_mod = node->data.variable_declaration.visib_mod;3694 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>();
3697 init_tld(&tld_var->base, TldIdVar, name, visib_mod, node, &decls_scope->base);3696 init_tld(&tld_var->base, TldIdVar, name, visib_mod, node, &decls_scope->base);
3698 tld_var->extern_lib_name = node->data.variable_declaration.lib_name;3697 tld_var->extern_lib_name = node->data.variable_declaration.lib_name;
3699 add_top_level_decl(g, decls_scope, &tld_var->base);3698 add_top_level_decl(g, decls_scope, &tld_var->base);
...@@ -3709,7 +3708,7 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {...@@ -3709,7 +3708,7 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {
3709 }3708 }
37103709
3711 VisibMod visib_mod = node->data.fn_proto.visib_mod;3710 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>();
3713 init_tld(&tld_fn->base, TldIdFn, fn_name, visib_mod, node, &decls_scope->base);3712 init_tld(&tld_fn->base, TldIdFn, fn_name, visib_mod, node, &decls_scope->base);
3714 tld_fn->extern_lib_name = node->data.fn_proto.lib_name;3713 tld_fn->extern_lib_name = node->data.fn_proto.lib_name;
3715 add_top_level_decl(g, decls_scope, &tld_fn->base);3714 add_top_level_decl(g, decls_scope, &tld_fn->base);
...@@ -3718,7 +3717,7 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {...@@ -3718,7 +3717,7 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {
3718 }3717 }
3719 case NodeTypeUsingNamespace: {3718 case NodeTypeUsingNamespace: {
3720 VisibMod visib_mod = node->data.using_namespace.visib_mod;3719 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>();
3722 init_tld(&tld_using_namespace->base, TldIdUsingNamespace, nullptr, visib_mod, node, &decls_scope->base);3721 init_tld(&tld_using_namespace->base, TldIdUsingNamespace, nullptr, visib_mod, node, &decls_scope->base);
3723 add_top_level_decl(g, decls_scope, &tld_using_namespace->base);3722 add_top_level_decl(g, decls_scope, &tld_using_namespace->base);
3724 decls_scope->use_decls.append(tld_using_namespace);3723 decls_scope->use_decls.append(tld_using_namespace);
...@@ -3845,7 +3844,7 @@ ZigVar *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf...@@ -3845,7 +3844,7 @@ ZigVar *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf
3845 assert(const_value != nullptr);3844 assert(const_value != nullptr);
3846 assert(var_type != nullptr);3845 assert(var_type != nullptr);
38473846
3848 ZigVar *variable_entry = allocate<ZigVar>(1);3847 ZigVar *variable_entry = heap::c_allocator.create<ZigVar>();
3849 variable_entry->const_value = const_value;3848 variable_entry->const_value = const_value;
3850 variable_entry->var_type = var_type;3849 variable_entry->var_type = var_type;
3851 variable_entry->parent_scope = parent_scope;3850 variable_entry->parent_scope = parent_scope;
...@@ -3984,7 +3983,7 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var, bool allow_lazy) {...@@ -3984,7 +3983,7 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var, bool allow_lazy) {
3984 ZigType *type = explicit_type ? explicit_type : implicit_type;3983 ZigType *type = explicit_type ? explicit_type : implicit_type;
3985 assert(type != nullptr); // should have been caught by the parser3984 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
3989 tld_var->var = add_variable(g, source_node, tld_var->base.parent_scope, var_decl->symbol,3988 tld_var->var = add_variable(g, source_node, tld_var->base.parent_scope, var_decl->symbol,
3990 is_const, init_val, &tld_var->base, type);3989 is_const, init_val, &tld_var->base, type);
...@@ -4491,7 +4490,7 @@ static Error define_local_param_variables(CodeGen *g, ZigFn *fn_table_entry) {...@@ -4491,7 +4490,7 @@ static Error define_local_param_variables(CodeGen *g, ZigFn *fn_table_entry) {
4491 }4490 }
44924491
4493 ZigVar *var = add_variable(g, param_decl_node, fn_table_entry->child_scope,4492 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);
4495 var->src_arg_index = i;4494 var->src_arg_index = i;
4496 fn_table_entry->child_scope = var->child_scope;4495 fn_table_entry->child_scope = var->child_scope;
4497 var->shadowable = var->shadowable || is_var_args;4496 var->shadowable = var->shadowable || is_var_args;
...@@ -4786,7 +4785,7 @@ static void analyze_fn_ir(CodeGen *g, ZigFn *fn, AstNode *return_type_node) {...@@ -4786,7 +4785,7 @@ static void analyze_fn_ir(CodeGen *g, ZigFn *fn, AstNode *return_type_node) {
4786 } else {4785 } else {
4787 return_err_set_type->data.error_set.err_count = inferred_err_set_type->data.error_set.err_count;4786 return_err_set_type->data.error_set.err_count = inferred_err_set_type->data.error_set.err_count;
4788 if (inferred_err_set_type->data.error_set.err_count > 0) {4787 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);
4790 for (uint32_t i = 0; i < inferred_err_set_type->data.error_set.err_count; i += 1) {4789 for (uint32_t i = 0; i < inferred_err_set_type->data.error_set.err_count; i += 1) {
4791 return_err_set_type->data.error_set.errors[i] = inferred_err_set_type->data.error_set.errors[i];4790 return_err_set_type->data.error_set.errors[i] = inferred_err_set_type->data.error_set.errors[i];
4792 }4791 }
...@@ -4919,7 +4918,7 @@ ZigType *add_source_file(CodeGen *g, ZigPackage *package, Buf *resolved_path, Bu...@@ -4919,7 +4918,7 @@ ZigType *add_source_file(CodeGen *g, ZigPackage *package, Buf *resolved_path, Bu
4919 Buf *bare_name = buf_alloc();4918 Buf *bare_name = buf_alloc();
4920 os_path_extname(src_basename, bare_name, nullptr);4919 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>();
4923 root_struct->package = package;4922 root_struct->package = package;
4924 root_struct->source_code = source_code;4923 root_struct->source_code = source_code;
4925 root_struct->line_offsets = tokenization.line_offsets;4924 root_struct->line_offsets = tokenization.line_offsets;
...@@ -4946,7 +4945,7 @@ ZigType *add_source_file(CodeGen *g, ZigPackage *package, Buf *resolved_path, Bu...@@ -4946,7 +4945,7 @@ ZigType *add_source_file(CodeGen *g, ZigPackage *package, Buf *resolved_path, Bu
4946 scan_decls(g, import_entry->data.structure.decls_scope, top_level_decl);4945 scan_decls(g, import_entry->data.structure.decls_scope, top_level_decl);
4947 }4946 }
49484947
4949 TldContainer *tld_container = allocate<TldContainer>(1);4948 TldContainer *tld_container = heap::c_allocator.create<TldContainer>();
4950 init_tld(&tld_container->base, TldIdContainer, namespace_name, VisibModPub, root_node, nullptr);4949 init_tld(&tld_container->base, TldIdContainer, namespace_name, VisibModPub, root_node, nullptr);
4951 tld_container->type_entry = import_entry;4950 tld_container->type_entry = import_entry;
4952 tld_container->decls_scope = import_entry->data.structure.decls_scope;4951 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) {...@@ -5694,14 +5693,14 @@ ZigValue *get_the_one_possible_value(CodeGen *g, ZigType *type_entry) {
5694 if (entry != nullptr) {5693 if (entry != nullptr) {
5695 return entry->value;5694 return entry->value;
5696 }5695 }
5697 ZigValue *result = create_const_vals(1);5696 ZigValue *result = g->pass1_arena->create<ZigValue>();
5698 result->type = type_entry;5697 result->type = type_entry;
5699 result->special = ConstValSpecialStatic;5698 result->special = ConstValSpecialStatic;
5700 if (result->type->id == ZigTypeIdStruct) {5699 if (result->type->id == ZigTypeIdStruct) {
5701 // The fields array cannot be left unpopulated5700 // The fields array cannot be left unpopulated
5702 const ZigType *struct_type = result->type;5701 const ZigType *struct_type = result->type;
5703 const size_t field_count = struct_type->data.structure.src_field_count;5702 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);
5705 for (size_t i = 0; i < field_count; i += 1) {5704 for (size_t i = 0; i < field_count; i += 1) {
5706 TypeStructField *field = struct_type->data.structure.fields[i];5705 TypeStructField *field = struct_type->data.structure.fields[i];
5707 ZigType *field_type = resolve_struct_field_type(g, field);5706 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) {...@@ -5786,7 +5785,7 @@ void init_const_str_lit(CodeGen *g, ZigValue *const_val, Buf *str) {
5786 }5785 }
57875786
5788 // first we build the underlying array5787 // first we build the underlying array
5789 ZigValue *array_val = create_const_vals(1);5788 ZigValue *array_val = g->pass1_arena->create<ZigValue>();
5790 array_val->special = ConstValSpecialStatic;5789 array_val->special = ConstValSpecialStatic;
5791 array_val->type = get_array_type(g, g->builtin_types.entry_u8, buf_len(str), g->intern.for_zero_byte());5790 array_val->type = get_array_type(g, g->builtin_types.entry_u8, buf_len(str), g->intern.for_zero_byte());
5792 array_val->data.x_array.special = ConstArraySpecialBuf;5791 array_val->data.x_array.special = ConstArraySpecialBuf;
...@@ -5803,7 +5802,7 @@ void init_const_str_lit(CodeGen *g, ZigValue *const_val, Buf *str) {...@@ -5803,7 +5802,7 @@ void init_const_str_lit(CodeGen *g, ZigValue *const_val, Buf *str) {
5803}5802}
58045803
5805ZigValue *create_const_str_lit(CodeGen *g, Buf *str) {5804ZigValue *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>();
5807 init_const_str_lit(g, const_val, str);5806 init_const_str_lit(g, const_val, str);
5808 return const_val;5807 return const_val;
5809}5808}
...@@ -5814,8 +5813,8 @@ void init_const_bigint(ZigValue *const_val, ZigType *type, const BigInt *bigint)...@@ -5814,8 +5813,8 @@ void init_const_bigint(ZigValue *const_val, ZigType *type, const BigInt *bigint)
5814 bigint_init_bigint(&const_val->data.x_bigint, bigint);5813 bigint_init_bigint(&const_val->data.x_bigint, bigint);
5815}5814}
58165815
5817ZigValue *create_const_bigint(ZigType *type, const BigInt *bigint) {5816ZigValue *create_const_bigint(CodeGen *g, ZigType *type, const BigInt *bigint) {
5818 ZigValue *const_val = create_const_vals(1);5817 ZigValue *const_val = g->pass1_arena->create<ZigValue>();
5819 init_const_bigint(const_val, type, bigint);5818 init_const_bigint(const_val, type, bigint);
5820 return const_val;5819 return const_val;
5821}5820}
...@@ -5828,8 +5827,8 @@ void init_const_unsigned_negative(ZigValue *const_val, ZigType *type, uint64_t x...@@ -5828,8 +5827,8 @@ void init_const_unsigned_negative(ZigValue *const_val, ZigType *type, uint64_t x
5828 const_val->data.x_bigint.is_negative = negative;5827 const_val->data.x_bigint.is_negative = negative;
5829}5828}
58305829
5831ZigValue *create_const_unsigned_negative(ZigType *type, uint64_t x, bool negative) {5830ZigValue *create_const_unsigned_negative(CodeGen *g, ZigType *type, uint64_t x, bool negative) {
5832 ZigValue *const_val = create_const_vals(1);5831 ZigValue *const_val = g->pass1_arena->create<ZigValue>();
5833 init_const_unsigned_negative(const_val, type, x, negative);5832 init_const_unsigned_negative(const_val, type, x, negative);
5834 return const_val;5833 return const_val;
5835}5834}
...@@ -5839,7 +5838,7 @@ void init_const_usize(CodeGen *g, ZigValue *const_val, uint64_t x) {...@@ -5839,7 +5838,7 @@ void init_const_usize(CodeGen *g, ZigValue *const_val, uint64_t x) {
5839}5838}
58405839
5841ZigValue *create_const_usize(CodeGen *g, uint64_t x) {5840ZigValue *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);
5843}5842}
58445843
5845void init_const_signed(ZigValue *const_val, ZigType *type, int64_t x) {5844void 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) {...@@ -5848,8 +5847,8 @@ void init_const_signed(ZigValue *const_val, ZigType *type, int64_t x) {
5848 bigint_init_signed(&const_val->data.x_bigint, x);5847 bigint_init_signed(&const_val->data.x_bigint, x);
5849}5848}
58505849
5851ZigValue *create_const_signed(ZigType *type, int64_t x) {5850ZigValue *create_const_signed(CodeGen *g, ZigType *type, int64_t x) {
5852 ZigValue *const_val = create_const_vals(1);5851 ZigValue *const_val = g->pass1_arena->create<ZigValue>();
5853 init_const_signed(const_val, type, x);5852 init_const_signed(const_val, type, x);
5854 return const_val;5853 return const_val;
5855}5854}
...@@ -5860,8 +5859,8 @@ void init_const_null(ZigValue *const_val, ZigType *type) {...@@ -5860,8 +5859,8 @@ void init_const_null(ZigValue *const_val, ZigType *type) {
5860 const_val->data.x_optional = nullptr;5859 const_val->data.x_optional = nullptr;
5861}5860}
58625861
5863ZigValue *create_const_null(ZigType *type) {5862ZigValue *create_const_null(CodeGen *g, ZigType *type) {
5864 ZigValue *const_val = create_const_vals(1);5863 ZigValue *const_val = g->pass1_arena->create<ZigValue>();
5865 init_const_null(const_val, type);5864 init_const_null(const_val, type);
5866 return const_val;5865 return const_val;
5867}5866}
...@@ -5893,8 +5892,8 @@ void init_const_float(ZigValue *const_val, ZigType *type, double value) {...@@ -5893,8 +5892,8 @@ void init_const_float(ZigValue *const_val, ZigType *type, double value) {
5893 }5892 }
5894}5893}
58955894
5896ZigValue *create_const_float(ZigType *type, double value) {5895ZigValue *create_const_float(CodeGen *g, ZigType *type, double value) {
5897 ZigValue *const_val = create_const_vals(1);5896 ZigValue *const_val = g->pass1_arena->create<ZigValue>();
5898 init_const_float(const_val, type, value);5897 init_const_float(const_val, type, value);
5899 return const_val;5898 return const_val;
5900}5899}
...@@ -5905,8 +5904,8 @@ void init_const_enum(ZigValue *const_val, ZigType *type, const BigInt *tag) {...@@ -5905,8 +5904,8 @@ void init_const_enum(ZigValue *const_val, ZigType *type, const BigInt *tag) {
5905 bigint_init_bigint(&const_val->data.x_enum_tag, tag);5904 bigint_init_bigint(&const_val->data.x_enum_tag, tag);
5906}5905}
59075906
5908ZigValue *create_const_enum(ZigType *type, const BigInt *tag) {5907ZigValue *create_const_enum(CodeGen *g, ZigType *type, const BigInt *tag) {
5909 ZigValue *const_val = create_const_vals(1);5908 ZigValue *const_val = g->pass1_arena->create<ZigValue>();
5910 init_const_enum(const_val, type, tag);5909 init_const_enum(const_val, type, tag);
5911 return const_val;5910 return const_val;
5912}5911}
...@@ -5919,7 +5918,7 @@ void init_const_bool(CodeGen *g, ZigValue *const_val, bool value) {...@@ -5919,7 +5918,7 @@ void init_const_bool(CodeGen *g, ZigValue *const_val, bool value) {
5919}5918}
59205919
5921ZigValue *create_const_bool(CodeGen *g, bool value) {5920ZigValue *create_const_bool(CodeGen *g, bool value) {
5922 ZigValue *const_val = create_const_vals(1);5921 ZigValue *const_val = g->pass1_arena->create<ZigValue>();
5923 init_const_bool(g, const_val, value);5922 init_const_bool(g, const_val, value);
5924 return const_val;5923 return const_val;
5925}5924}
...@@ -5929,8 +5928,8 @@ void init_const_runtime(ZigValue *const_val, ZigType *type) {...@@ -5929,8 +5928,8 @@ void init_const_runtime(ZigValue *const_val, ZigType *type) {
5929 const_val->type = type;5928 const_val->type = type;
5930}5929}
59315930
5932ZigValue *create_const_runtime(ZigType *type) {5931ZigValue *create_const_runtime(CodeGen *g, ZigType *type) {
5933 ZigValue *const_val = create_const_vals(1);5932 ZigValue *const_val = g->pass1_arena->create<ZigValue>();
5934 init_const_runtime(const_val, type);5933 init_const_runtime(const_val, type);
5935 return const_val;5934 return const_val;
5936}5935}
...@@ -5942,7 +5941,7 @@ void init_const_type(CodeGen *g, ZigValue *const_val, ZigType *type_value) {...@@ -5942,7 +5941,7 @@ void init_const_type(CodeGen *g, ZigValue *const_val, ZigType *type_value) {
5942}5941}
59435942
5944ZigValue *create_const_type(CodeGen *g, ZigType *type_value) {5943ZigValue *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>();
5946 init_const_type(g, const_val, type_value);5945 init_const_type(g, const_val, type_value);
5947 return const_val;5946 return const_val;
5948}5947}
...@@ -5957,7 +5956,7 @@ void init_const_slice(CodeGen *g, ZigValue *const_val, ZigValue *array_val,...@@ -5957,7 +5956,7 @@ void init_const_slice(CodeGen *g, ZigValue *const_val, ZigValue *array_val,
59575956
5958 const_val->special = ConstValSpecialStatic;5957 const_val->special = ConstValSpecialStatic;
5959 const_val->type = get_slice_type(g, ptr_type);5958 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
5962 init_const_ptr_array(g, const_val->data.x_struct.fields[slice_ptr_index], array_val, start, is_const,5961 init_const_ptr_array(g, const_val->data.x_struct.fields[slice_ptr_index], array_val, start, is_const,
5963 PtrLenUnknown);5962 PtrLenUnknown);
...@@ -5965,7 +5964,7 @@ void init_const_slice(CodeGen *g, ZigValue *const_val, ZigValue *array_val,...@@ -5965,7 +5964,7 @@ void init_const_slice(CodeGen *g, ZigValue *const_val, ZigValue *array_val,
5965}5964}
59665965
5967ZigValue *create_const_slice(CodeGen *g, ZigValue *array_val, size_t start, size_t len, bool is_const) {5966ZigValue *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>();
5969 init_const_slice(g, const_val, array_val, start, len, is_const);5968 init_const_slice(g, const_val, array_val, start, len, is_const);
5970 return const_val;5969 return const_val;
5971}5970}
...@@ -5987,7 +5986,7 @@ void init_const_ptr_array(CodeGen *g, ZigValue *const_val, ZigValue *array_val,...@@ -5987,7 +5986,7 @@ void init_const_ptr_array(CodeGen *g, ZigValue *const_val, ZigValue *array_val,
5987ZigValue *create_const_ptr_array(CodeGen *g, ZigValue *array_val, size_t elem_index, bool is_const,5986ZigValue *create_const_ptr_array(CodeGen *g, ZigValue *array_val, size_t elem_index, bool is_const,
5988 PtrLen ptr_len)5987 PtrLen ptr_len)
5989{5988{
5990 ZigValue *const_val = create_const_vals(1);5989 ZigValue *const_val = g->pass1_arena->create<ZigValue>();
5991 init_const_ptr_array(g, const_val, array_val, elem_index, is_const, ptr_len);5990 init_const_ptr_array(g, const_val, array_val, elem_index, is_const, ptr_len);
5992 return const_val;5991 return const_val;
5993}5992}
...@@ -6000,7 +5999,7 @@ void init_const_ptr_ref(CodeGen *g, ZigValue *const_val, ZigValue *pointee_val,...@@ -6000,7 +5999,7 @@ void init_const_ptr_ref(CodeGen *g, ZigValue *const_val, ZigValue *pointee_val,
6000}5999}
60016000
6002ZigValue *create_const_ptr_ref(CodeGen *g, ZigValue *pointee_val, bool is_const) {6001ZigValue *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>();
6004 init_const_ptr_ref(g, const_val, pointee_val, is_const);6003 init_const_ptr_ref(g, const_val, pointee_val, is_const);
6005 return const_val;6004 return const_val;
6006}6005}
...@@ -6017,25 +6016,21 @@ void init_const_ptr_hard_coded_addr(CodeGen *g, ZigValue *const_val, ZigType *po...@@ -6017,25 +6016,21 @@ void init_const_ptr_hard_coded_addr(CodeGen *g, ZigValue *const_val, ZigType *po
6017ZigValue *create_const_ptr_hard_coded_addr(CodeGen *g, ZigType *pointee_type,6016ZigValue *create_const_ptr_hard_coded_addr(CodeGen *g, ZigType *pointee_type,
6018 size_t addr, bool is_const)6017 size_t addr, bool is_const)
6019{6018{
6020 ZigValue *const_val = create_const_vals(1);6019 ZigValue *const_val = g->pass1_arena->create<ZigValue>();
6021 init_const_ptr_hard_coded_addr(g, const_val, pointee_type, addr, is_const);6020 init_const_ptr_hard_coded_addr(g, const_val, pointee_type, addr, is_const);
6022 return const_val;6021 return const_val;
6023}6022}
60246023
6025ZigValue *create_const_vals(size_t count) {6024ZigValue **alloc_const_vals_ptrs(CodeGen *g, size_t count) {
6026 return allocate<ZigValue>(count, "ZigValue");6025 return realloc_const_vals_ptrs(g, nullptr, 0, count);
6027}6026}
60286027
6029ZigValue **alloc_const_vals_ptrs(size_t count) {6028ZigValue **realloc_const_vals_ptrs(CodeGen *g, ZigValue **ptr, size_t old_count, size_t new_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) {
6034 assert(new_count >= old_count);6029 assert(new_count >= old_count);
60356030
6036 size_t new_item_count = new_count - old_count;6031 size_t new_item_count = new_count - old_count;
6037 ZigValue **result = reallocate(ptr, old_count, new_count, "ZigValue*");6032 ZigValue **result = heap::c_allocator.reallocate(ptr, old_count, new_count);
6038 ZigValue *vals = create_const_vals(new_item_count);6033 ZigValue *vals = g->pass1_arena->allocate<ZigValue>(new_item_count);
6039 for (size_t i = old_count; i < new_count; i += 1) {6034 for (size_t i = old_count; i < new_count; i += 1) {
6040 result[i] = &vals[i - old_count];6035 result[i] = &vals[i - old_count];
6041 }6036 }
...@@ -6050,8 +6045,8 @@ TypeStructField **realloc_type_struct_fields(TypeStructField **ptr, size_t old_c...@@ -6050,8 +6045,8 @@ TypeStructField **realloc_type_struct_fields(TypeStructField **ptr, size_t old_c
6050 assert(new_count >= old_count);6045 assert(new_count >= old_count);
60516046
6052 size_t new_item_count = new_count - old_count;6047 size_t new_item_count = new_count - old_count;
6053 TypeStructField **result = reallocate(ptr, old_count, new_count, "TypeStructField*");6048 TypeStructField **result = heap::c_allocator.reallocate(ptr, old_count, new_count);
6054 TypeStructField *vals = allocate<TypeStructField>(new_item_count, "TypeStructField");6049 TypeStructField *vals = heap::c_allocator.allocate<TypeStructField>(new_item_count);
6055 for (size_t i = old_count; i < new_count; i += 1) {6050 for (size_t i = old_count; i < new_count; i += 1) {
6056 result[i] = &vals[i - old_count];6051 result[i] = &vals[i - old_count];
6057 }6052 }
...@@ -6062,7 +6057,7 @@ static ZigType *get_async_fn_type(CodeGen *g, ZigType *orig_fn_type) {...@@ -6062,7 +6057,7 @@ static ZigType *get_async_fn_type(CodeGen *g, ZigType *orig_fn_type) {
6062 if (orig_fn_type->data.fn.fn_type_id.cc == CallingConventionAsync)6057 if (orig_fn_type->data.fn.fn_type_id.cc == CallingConventionAsync)
6063 return orig_fn_type;6058 return orig_fn_type;
60646059
6065 ZigType *fn_type = allocate_nonzero<ZigType>(1);6060 ZigType *fn_type = heap::c_allocator.allocate_nonzero<ZigType>(1);
6066 *fn_type = *orig_fn_type;6061 *fn_type = *orig_fn_type;
6067 fn_type->data.fn.fn_type_id.cc = CallingConventionAsync;6062 fn_type->data.fn.fn_type_id.cc = CallingConventionAsync;
6068 fn_type->llvm_type = nullptr;6063 fn_type->llvm_type = nullptr;
...@@ -6236,11 +6231,11 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {...@@ -6236,11 +6231,11 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
6236 ZigType *fn_type = get_async_fn_type(g, fn->type_entry);6231 ZigType *fn_type = get_async_fn_type(g, fn->type_entry);
62376232
6238 if (fn->analyzed_executable.need_err_code_spill) {6233 if (fn->analyzed_executable.need_err_code_spill) {
6239 IrInstGenAlloca *alloca_gen = allocate<IrInstGenAlloca>(1);6234 IrInstGenAlloca *alloca_gen = heap::c_allocator.create<IrInstGenAlloca>();
6240 alloca_gen->base.id = IrInstGenIdAlloca;6235 alloca_gen->base.id = IrInstGenIdAlloca;
6241 alloca_gen->base.base.source_node = fn->proto_node;6236 alloca_gen->base.base.source_node = fn->proto_node;
6242 alloca_gen->base.base.scope = fn->child_scope;6237 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>();
6244 alloca_gen->base.value->type = get_pointer_to_type(g, g->builtin_types.entry_global_error_set, false);6239 alloca_gen->base.value->type = get_pointer_to_type(g, g->builtin_types.entry_global_error_set, false);
6245 alloca_gen->base.base.ref_count = 1;6240 alloca_gen->base.base.ref_count = 1;
6246 alloca_gen->name_hint = "";6241 alloca_gen->name_hint = "";
...@@ -7375,7 +7370,7 @@ static void init_const_undefined(CodeGen *g, ZigValue *const_val) {...@@ -7375,7 +7370,7 @@ static void init_const_undefined(CodeGen *g, ZigValue *const_val) {
73757370
7376 const_val->special = ConstValSpecialStatic;7371 const_val->special = ConstValSpecialStatic;
7377 size_t field_count = wanted_type->data.structure.src_field_count;7372 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);
7379 for (size_t i = 0; i < field_count; i += 1) {7374 for (size_t i = 0; i < field_count; i += 1) {
7380 ZigValue *field_val = const_val->data.x_struct.fields[i];7375 ZigValue *field_val = const_val->data.x_struct.fields[i];
7381 field_val->type = resolve_struct_field_type(g, wanted_type->data.structure.fields[i]);7376 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) {...@@ -7418,7 +7413,7 @@ void expand_undef_array(CodeGen *g, ZigValue *const_val) {
7418 return;7413 return;
7419 case ConstArraySpecialUndef: {7414 case ConstArraySpecialUndef: {
7420 const_val->data.x_array.special = ConstArraySpecialNone;7415 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);
7422 for (size_t i = 0; i < elem_count; i += 1) {7417 for (size_t i = 0; i < elem_count; i += 1) {
7423 ZigValue *element_val = &const_val->data.x_array.data.s_none.elements[i];7418 ZigValue *element_val = &const_val->data.x_array.data.s_none.elements[i];
7424 element_val->type = elem_type;7419 element_val->type = elem_type;
...@@ -7437,7 +7432,7 @@ void expand_undef_array(CodeGen *g, ZigValue *const_val) {...@@ -7437,7 +7432,7 @@ void expand_undef_array(CodeGen *g, ZigValue *const_val) {
74377432
7438 const_val->data.x_array.special = ConstArraySpecialNone;7433 const_val->data.x_array.special = ConstArraySpecialNone;
7439 assert(elem_count == buf_len(buf));7434 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);
7441 for (size_t i = 0; i < elem_count; i += 1) {7436 for (size_t i = 0; i < elem_count; i += 1) {
7442 ZigValue *this_char = &const_val->data.x_array.data.s_none.elements[i];7437 ZigValue *this_char = &const_val->data.x_array.data.s_none.elements[i];
7443 this_char->special = ConstValSpecialStatic;7438 this_char->special = ConstValSpecialStatic;
...@@ -7609,7 +7604,7 @@ const char *type_id_name(ZigTypeId id) {...@@ -7609,7 +7604,7 @@ const char *type_id_name(ZigTypeId id) {
7609}7604}
76107605
7611LinkLib *create_link_lib(Buf *name) {7606LinkLib *create_link_lib(Buf *name) {
7612 LinkLib *link_lib = allocate<LinkLib>(1);7607 LinkLib *link_lib = heap::c_allocator.create<LinkLib>();
7613 link_lib->name = name;7608 link_lib->name = name;
7614 return link_lib;7609 return link_lib;
7615}7610}
...@@ -8137,7 +8132,7 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS...@@ -8137,7 +8132,7 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS
81378132
8138 size_t field_count = struct_type->data.structure.src_field_count;8133 size_t field_count = struct_type->data.structure.src_field_count;
8139 // Every field could potentially have a generated padding field after it.8134 // 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
8142 bool packed = (struct_type->data.structure.layout == ContainerLayoutPacked);8137 bool packed = (struct_type->data.structure.layout == ContainerLayoutPacked);
8143 size_t packed_bits_offset = 0;8138 size_t packed_bits_offset = 0;
...@@ -8272,7 +8267,7 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS...@@ -8272,7 +8267,7 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS
8272 (unsigned)struct_type->data.structure.gen_field_count, packed);8267 (unsigned)struct_type->data.structure.gen_field_count, packed);
8273 }8268 }
82748269
8275 ZigLLVMDIType **di_element_types = allocate<ZigLLVMDIType*>(debug_field_count);8270 ZigLLVMDIType **di_element_types = heap::c_allocator.allocate<ZigLLVMDIType*>(debug_field_count);
8276 size_t debug_field_index = 0;8271 size_t debug_field_index = 0;
8277 for (size_t i = 0; i < field_count; i += 1) {8272 for (size_t i = 0; i < field_count; i += 1) {
8278 TypeStructField *field = struct_type->data.structure.fields[i];8273 TypeStructField *field = struct_type->data.structure.fields[i];
...@@ -8389,7 +8384,7 @@ static void resolve_llvm_types_enum(CodeGen *g, ZigType *enum_type, ResolveStatu...@@ -8389,7 +8384,7 @@ static void resolve_llvm_types_enum(CodeGen *g, ZigType *enum_type, ResolveStatu
8389 uint32_t field_count = enum_type->data.enumeration.src_field_count;8384 uint32_t field_count = enum_type->data.enumeration.src_field_count;
83908385
8391 assert(field_count == 0 || enum_type->data.enumeration.fields != nullptr);8386 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
8394 for (uint32_t i = 0; i < field_count; i += 1) {8389 for (uint32_t i = 0; i < field_count; i += 1) {
8395 TypeEnumField *enum_field = &enum_type->data.enumeration.fields[i];8390 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...@@ -8456,7 +8451,7 @@ static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type, ResolveSta
8456 if (ResolveStatusLLVMFwdDecl >= wanted_resolve_status) return;8451 if (ResolveStatusLLVMFwdDecl >= wanted_resolve_status) return;
8457 }8452 }
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);
8460 uint32_t field_count = union_type->data.unionation.src_field_count;8455 uint32_t field_count = union_type->data.unionation.src_field_count;
8461 for (uint32_t i = 0; i < field_count; i += 1) {8456 for (uint32_t i = 0; i < field_count; i += 1) {
8462 TypeUnionField *union_field = &union_type->data.unionation.fields[i];8457 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) {...@@ -8895,7 +8890,7 @@ static void resolve_llvm_types_fn_type(CodeGen *g, ZigType *fn_type) {
8895 param_di_types.append(get_llvm_di_type(g, gen_type));8890 param_di_types.append(get_llvm_di_type(g, gen_type));
8896 }8891 }
8897 if (is_async) {8892 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
8900 ZigType *frame_type = get_any_frame_type(g, fn_type_id->return_type);8895 ZigType *frame_type = get_any_frame_type(g, fn_type_id->return_type);
8901 gen_param_types.append(get_llvm_type(g, frame_type));8896 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) {...@@ -8912,7 +8907,7 @@ static void resolve_llvm_types_fn_type(CodeGen *g, ZigType *fn_type) {
8912 fn_type->data.fn.gen_param_info[1].gen_index = 1;8907 fn_type->data.fn.gen_param_info[1].gen_index = 1;
8913 fn_type->data.fn.gen_param_info[1].type = g->builtin_types.entry_usize;8908 fn_type->data.fn.gen_param_info[1].type = g->builtin_types.entry_usize;
8914 } else {8909 } 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);
8916 for (size_t i = 0; i < fn_type_id->param_count; i += 1) {8911 for (size_t i = 0; i < fn_type_id->param_count; i += 1) {
8917 FnTypeParamInfo *src_param_info = &fn_type->data.fn.fn_type_id.param_info[i];8912 FnTypeParamInfo *src_param_info = &fn_type->data.fn.fn_type_id.param_info[i];
8918 ZigType *type_entry = src_param_info->type;8913 ZigType *type_entry = src_param_info->type;
...@@ -9369,7 +9364,7 @@ bool type_has_optional_repr(ZigType *ty) {...@@ -9369,7 +9364,7 @@ bool type_has_optional_repr(ZigType *ty) {
9369 }9364 }
9370}9365}
93719366
9372void copy_const_val(ZigValue *dest, ZigValue *src) {9367void copy_const_val(CodeGen *g, ZigValue *dest, ZigValue *src) {
9373 uint32_t prev_align = dest->llvm_align;9368 uint32_t prev_align = dest->llvm_align;
9374 ConstParent prev_parent = dest->parent;9369 ConstParent prev_parent = dest->parent;
9375 memcpy(dest, src, sizeof(ZigValue));9370 memcpy(dest, src, sizeof(ZigValue));
...@@ -9378,26 +9373,26 @@ void copy_const_val(ZigValue *dest, ZigValue *src) {...@@ -9378,26 +9373,26 @@ void copy_const_val(ZigValue *dest, ZigValue *src) {
9378 return;9373 return;
9379 dest->parent = prev_parent;9374 dest->parent = prev_parent;
9380 if (dest->type->id == ZigTypeIdStruct) {9375 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);
9382 for (size_t i = 0; i < dest->type->data.structure.src_field_count; i += 1) {9377 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]);
9384 dest->data.x_struct.fields[i]->parent.id = ConstParentIdStruct;9379 dest->data.x_struct.fields[i]->parent.id = ConstParentIdStruct;
9385 dest->data.x_struct.fields[i]->parent.data.p_struct.struct_val = dest;9380 dest->data.x_struct.fields[i]->parent.data.p_struct.struct_val = dest;
9386 dest->data.x_struct.fields[i]->parent.data.p_struct.field_index = i;9381 dest->data.x_struct.fields[i]->parent.data.p_struct.field_index = i;
9387 }9382 }
9388 } else if (dest->type->id == ZigTypeIdArray) {9383 } else if (dest->type->id == ZigTypeIdArray) {
9389 if (dest->data.x_array.special == ConstArraySpecialNone) {9384 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);
9391 for (uint64_t i = 0; i < dest->type->data.array.len; i += 1) {9386 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]);
9393 dest->data.x_array.data.s_none.elements[i].parent.id = ConstParentIdArray;9388 dest->data.x_array.data.s_none.elements[i].parent.id = ConstParentIdArray;
9394 dest->data.x_array.data.s_none.elements[i].parent.data.p_array.array_val = dest;9389 dest->data.x_array.data.s_none.elements[i].parent.data.p_array.array_val = dest;
9395 dest->data.x_array.data.s_none.elements[i].parent.data.p_array.elem_index = i;9390 dest->data.x_array.data.s_none.elements[i].parent.data.p_array.elem_index = i;
9396 }9391 }
9397 }9392 }
9398 } else if (type_has_optional_repr(dest->type) && dest->data.x_optional != nullptr) {9393 } else if (type_has_optional_repr(dest->type) && dest->data.x_optional != nullptr) {
9399 dest->data.x_optional = create_const_vals(1);9394 dest->data.x_optional = g->pass1_arena->create<ZigValue>();
9400 copy_const_val(dest->data.x_optional, src->data.x_optional);9395 copy_const_val(g, dest->data.x_optional, src->data.x_optional);
9401 dest->data.x_optional->parent.id = ConstParentIdOptionalPayload;9396 dest->data.x_optional->parent.id = ConstParentIdOptionalPayload;
9402 dest->data.x_optional->parent.data.p_optional_payload.optional_val = dest;9397 dest->data.x_optional->parent.data.p_optional_payload.optional_val = dest;
9403 }9398 }
src/analyze.hpp+10-11
...@@ -128,22 +128,22 @@ void init_const_str_lit(CodeGen *g, ZigValue *const_val, Buf *str);...@@ -128,22 +128,22 @@ void init_const_str_lit(CodeGen *g, ZigValue *const_val, Buf *str);
128ZigValue *create_const_str_lit(CodeGen *g, Buf *str);128ZigValue *create_const_str_lit(CodeGen *g, Buf *str);
129129
130void init_const_bigint(ZigValue *const_val, ZigType *type, const BigInt *bigint);130void 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
133void init_const_unsigned_negative(ZigValue *const_val, ZigType *type, uint64_t x, bool negative);133void 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
136void init_const_signed(ZigValue *const_val, ZigType *type, int64_t x);136void 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
139void init_const_usize(CodeGen *g, ZigValue *const_val, uint64_t x);139void init_const_usize(CodeGen *g, ZigValue *const_val, uint64_t x);
140ZigValue *create_const_usize(CodeGen *g, uint64_t x);140ZigValue *create_const_usize(CodeGen *g, uint64_t x);
141141
142void init_const_float(ZigValue *const_val, ZigType *type, double value);142void 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
145void init_const_enum(ZigValue *const_val, ZigType *type, const BigInt *tag);145void 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
148void init_const_bool(CodeGen *g, ZigValue *const_val, bool value);148void init_const_bool(CodeGen *g, ZigValue *const_val, bool value);
149ZigValue *create_const_bool(CodeGen *g, bool value);149ZigValue *create_const_bool(CodeGen *g, bool value);
...@@ -152,7 +152,7 @@ void init_const_type(CodeGen *g, ZigValue *const_val, ZigType *type_value);...@@ -152,7 +152,7 @@ void init_const_type(CodeGen *g, ZigValue *const_val, ZigType *type_value);
152ZigValue *create_const_type(CodeGen *g, ZigType *type_value);152ZigValue *create_const_type(CodeGen *g, ZigType *type_value);
153153
154void init_const_runtime(ZigValue *const_val, ZigType *type);154void init_const_runtime(ZigValue *const_val, ZigType *type);
155ZigValue *create_const_runtime(ZigType *type);155ZigValue *create_const_runtime(CodeGen *g, ZigType *type);
156156
157void init_const_ptr_ref(CodeGen *g, ZigValue *const_val, ZigValue *pointee_val, bool is_const);157void init_const_ptr_ref(CodeGen *g, ZigValue *const_val, ZigValue *pointee_val, bool is_const);
158ZigValue *create_const_ptr_ref(CodeGen *g, ZigValue *pointee_val, bool is_const);158ZigValue *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,...@@ -172,11 +172,10 @@ void init_const_slice(CodeGen *g, ZigValue *const_val, ZigValue *array_val,
172ZigValue *create_const_slice(CodeGen *g, ZigValue *array_val, size_t start, size_t len, bool is_const);172ZigValue *create_const_slice(CodeGen *g, ZigValue *array_val, size_t start, size_t len, bool is_const);
173173
174void init_const_null(ZigValue *const_val, ZigType *type);174void 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);177ZigValue **alloc_const_vals_ptrs(CodeGen *g, size_t count);
178ZigValue **alloc_const_vals_ptrs(size_t count);178ZigValue **realloc_const_vals_ptrs(CodeGen *g, ZigValue **ptr, size_t old_count, size_t new_count);
179ZigValue **realloc_const_vals_ptrs(ZigValue **ptr, size_t old_count, size_t new_count);
180179
181TypeStructField **alloc_type_struct_fields(size_t count);180TypeStructField **alloc_type_struct_fields(size_t count);
182TypeStructField **realloc_type_struct_fields(TypeStructField **ptr, size_t old_count, size_t new_count);181TypeStructField **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...@@ -275,7 +274,7 @@ Error analyze_import(CodeGen *codegen, ZigType *source_import, Buf *import_targe
275 ZigType **out_import, Buf **out_import_target_path, Buf *out_full_path);274 ZigType **out_import, Buf **out_import_target_path, Buf *out_full_path);
276ZigValue *get_the_one_possible_value(CodeGen *g, ZigType *type_entry);275ZigValue *get_the_one_possible_value(CodeGen *g, ZigType *type_entry);
277bool is_anon_container(ZigType *ty);276bool is_anon_container(ZigType *ty);
278void copy_const_val(ZigValue *dest, ZigValue *src);277void copy_const_val(CodeGen *g, ZigValue *dest, ZigValue *src);
279bool type_has_optional_repr(ZigType *ty);278bool type_has_optional_repr(ZigType *ty);
280bool is_opt_err_set(ZigType *ty);279bool is_opt_err_set(ZigType *ty);
281bool type_is_numeric(ZigType *ty);280bool 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)...@@ -93,7 +93,7 @@ static void to_twos_complement(BigInt *dest, const BigInt *op, size_t bit_count)
93 if (dest->data.digit == 0) dest->digit_count = 0;93 if (dest->data.digit == 0) dest->digit_count = 0;
94 return;94 return;
95 }95 }
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);
97 for (size_t i = 0; i < digits_to_copy; i += 1) {97 for (size_t i = 0; i < digits_to_copy; i += 1) {
98 uint64_t digit = (i < op->digit_count) ? op_digits[i] : 0;98 uint64_t digit = (i < op->digit_count) ? op_digits[i] : 0;
99 dest->data.digits[i] = digit;99 dest->data.digits[i] = digit;
...@@ -174,7 +174,7 @@ void bigint_init_data(BigInt *dest, const uint64_t *digits, size_t digit_count,...@@ -174,7 +174,7 @@ void bigint_init_data(BigInt *dest, const uint64_t *digits, size_t digit_count,
174174
175 dest->digit_count = digit_count;175 dest->digit_count = digit_count;
176 dest->is_negative = is_negative;176 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);
178 memcpy(dest->data.digits, digits, sizeof(uint64_t) * digit_count);178 memcpy(dest->data.digits, digits, sizeof(uint64_t) * digit_count);
179179
180 bigint_normalize(dest);180 bigint_normalize(dest);
...@@ -191,13 +191,13 @@ void bigint_init_bigint(BigInt *dest, const BigInt *src) {...@@ -191,13 +191,13 @@ void bigint_init_bigint(BigInt *dest, const BigInt *src) {
191 }191 }
192 dest->is_negative = src->is_negative;192 dest->is_negative = src->is_negative;
193 dest->digit_count = src->digit_count;193 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);
195 memcpy(dest->data.digits, src->data.digits, sizeof(uint64_t) * dest->digit_count);195 memcpy(dest->data.digits, src->data.digits, sizeof(uint64_t) * dest->digit_count);
196}196}
197197
198void bigint_deinit(BigInt *bi) {198void bigint_deinit(BigInt *bi) {
199 if (bi->digit_count > 1)199 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);
201}201}
202202
203void bigint_init_bigfloat(BigInt *dest, const BigFloat *op) {203void bigint_init_bigfloat(BigInt *dest, const BigFloat *op) {
...@@ -227,7 +227,7 @@ void bigint_init_bigfloat(BigInt *dest, const BigFloat *op) {...@@ -227,7 +227,7 @@ void bigint_init_bigfloat(BigInt *dest, const BigFloat *op) {
227 f128M_rem(&abs_val, &max_u64, &remainder);227 f128M_rem(&abs_val, &max_u64, &remainder);
228228
229 dest->digit_count = 2;229 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);
231 dest->data.digits[0] = f128M_to_ui64(&remainder, softfloat_round_minMag, false);231 dest->data.digits[0] = f128M_to_ui64(&remainder, softfloat_round_minMag, false);
232 dest->data.digits[1] = f128M_to_ui64(&amt, softfloat_round_minMag, false);232 dest->data.digits[1] = f128M_to_ui64(&amt, softfloat_round_minMag, false);
233 bigint_normalize(dest);233 bigint_normalize(dest);
...@@ -345,7 +345,7 @@ void bigint_read_twos_complement(BigInt *dest, const uint8_t *buf, size_t bit_co...@@ -345,7 +345,7 @@ void bigint_read_twos_complement(BigInt *dest, const uint8_t *buf, size_t bit_co
345 if (dest->digit_count == 1) {345 if (dest->digit_count == 1) {
346 digits = &dest->data.digit;346 digits = &dest->data.digit;
347 } else {347 } else {
348 digits = allocate_nonzero<uint64_t>(dest->digit_count);348 digits = heap::c_allocator.allocate_nonzero<uint64_t>(dest->digit_count);
349 dest->data.digits = digits;349 dest->data.digits = digits;
350 }350 }
351351
...@@ -464,7 +464,7 @@ void bigint_add(BigInt *dest, const BigInt *op1, const BigInt *op2) {...@@ -464,7 +464,7 @@ void bigint_add(BigInt *dest, const BigInt *op1, const BigInt *op2) {
464 }464 }
465 size_t i = 1;465 size_t i = 1;
466 uint64_t first_digit = dest->data.digit;466 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);
468 dest->data.digits[0] = first_digit;468 dest->data.digits[0] = first_digit;
469469
470 for (;;) {470 for (;;) {
...@@ -532,7 +532,7 @@ void bigint_add(BigInt *dest, const BigInt *op1, const BigInt *op2) {...@@ -532,7 +532,7 @@ void bigint_add(BigInt *dest, const BigInt *op1, const BigInt *op2) {
532 return;532 return;
533 }533 }
534 uint64_t first_digit = dest->data.digit;534 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);
536 dest->data.digits[0] = first_digit;536 dest->data.digits[0] = first_digit;
537 size_t i = 1;537 size_t i = 1;
538538
...@@ -1032,7 +1032,7 @@ static void bigint_unsigned_division(const BigInt *op1, const BigInt *op2, BigIn...@@ -1032,7 +1032,7 @@ static void bigint_unsigned_division(const BigInt *op1, const BigInt *op2, BigIn
1032 if (lhsWords == 1) {1032 if (lhsWords == 1) {
1033 Quotient->data.digit = Make_64(Q[1], Q[0]);1033 Quotient->data.digit = Make_64(Q[1], Q[0]);
1034 } else {1034 } else {
1035 Quotient->data.digits = allocate<uint64_t>(lhsWords);1035 Quotient->data.digits = heap::c_allocator.allocate<uint64_t>(lhsWords);
1036 for (size_t i = 0; i < lhsWords; i += 1) {1036 for (size_t i = 0; i < lhsWords; i += 1) {
1037 Quotient->data.digits[i] = Make_64(Q[i*2+1], Q[i*2]);1037 Quotient->data.digits[i] = Make_64(Q[i*2+1], Q[i*2]);
1038 }1038 }
...@@ -1046,7 +1046,7 @@ static void bigint_unsigned_division(const BigInt *op1, const BigInt *op2, BigIn...@@ -1046,7 +1046,7 @@ static void bigint_unsigned_division(const BigInt *op1, const BigInt *op2, BigIn
1046 if (rhsWords == 1) {1046 if (rhsWords == 1) {
1047 Remainder->data.digit = Make_64(R[1], R[0]);1047 Remainder->data.digit = Make_64(R[1], R[0]);
1048 } else {1048 } else {
1049 Remainder->data.digits = allocate<uint64_t>(rhsWords);1049 Remainder->data.digits = heap::c_allocator.allocate<uint64_t>(rhsWords);
1050 for (size_t i = 0; i < rhsWords; i += 1) {1050 for (size_t i = 0; i < rhsWords; i += 1) {
1051 Remainder->data.digits[i] = Make_64(R[i*2+1], R[i*2]);1051 Remainder->data.digits[i] = Make_64(R[i*2+1], R[i*2]);
1052 }1052 }
...@@ -1218,7 +1218,7 @@ void bigint_or(BigInt *dest, const BigInt *op1, const BigInt *op2) {...@@ -1218,7 +1218,7 @@ void bigint_or(BigInt *dest, const BigInt *op1, const BigInt *op2) {
1218 return;1218 return;
1219 }1219 }
1220 dest->digit_count = max(op1->digit_count, op2->digit_count);1220 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);
1222 for (size_t i = 0; i < dest->digit_count; i += 1) {1222 for (size_t i = 0; i < dest->digit_count; i += 1) {
1223 uint64_t digit = 0;1223 uint64_t digit = 0;
1224 if (i < op1->digit_count) {1224 if (i < op1->digit_count) {
...@@ -1262,7 +1262,7 @@ void bigint_and(BigInt *dest, const BigInt *op1, const BigInt *op2) {...@@ -1262,7 +1262,7 @@ void bigint_and(BigInt *dest, const BigInt *op1, const BigInt *op2) {
1262 }1262 }
12631263
1264 dest->digit_count = max(op1->digit_count, op2->digit_count);1264 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
1267 size_t i = 0;1267 size_t i = 0;
1268 for (; i < op1->digit_count && i < op2->digit_count; i += 1) {1268 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) {...@@ -1308,7 +1308,7 @@ void bigint_xor(BigInt *dest, const BigInt *op1, const BigInt *op2) {
1308 return;1308 return;
1309 }1309 }
1310 dest->digit_count = max(op1->digit_count, op2->digit_count);1310 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);
1312 size_t i = 0;1312 size_t i = 0;
1313 for (; i < op1->digit_count && i < op2->digit_count; i += 1) {1313 for (; i < op1->digit_count && i < op2->digit_count; i += 1) {
1314 dest->data.digits[i] = op1_digits[i] ^ op2_digits[i];1314 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) {...@@ -1358,7 +1358,7 @@ void bigint_shl(BigInt *dest, const BigInt *op1, const BigInt *op2) {
1358 uint64_t digit_shift_count = shift_amt / 64;1358 uint64_t digit_shift_count = shift_amt / 64;
1359 uint64_t leftover_shift_count = shift_amt % 64;1359 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);
1362 dest->digit_count = digit_shift_count;1362 dest->digit_count = digit_shift_count;
1363 uint64_t carry = 0;1363 uint64_t carry = 0;
1364 for (size_t i = 0; i < op1->digit_count; i += 1) {1364 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) {...@@ -1421,7 +1421,7 @@ void bigint_shr(BigInt *dest, const BigInt *op1, const BigInt *op2) {
1421 if (dest->digit_count == 1) {1421 if (dest->digit_count == 1) {
1422 digits = &dest->data.digit;1422 digits = &dest->data.digit;
1423 } else {1423 } else {
1424 digits = allocate<uint64_t>(dest->digit_count);1424 digits = heap::c_allocator.allocate<uint64_t>(dest->digit_count);
1425 dest->data.digits = digits;1425 dest->data.digits = digits;
1426 }1426 }
14271427
...@@ -1492,7 +1492,7 @@ void bigint_not(BigInt *dest, const BigInt *op, size_t bit_count, bool is_signed...@@ -1492,7 +1492,7 @@ void bigint_not(BigInt *dest, const BigInt *op, size_t bit_count, bool is_signed
1492 }1492 }
1493 dest->digit_count = (bit_count + 63) / 64;1493 dest->digit_count = (bit_count + 63) / 64;
1494 assert(dest->digit_count >= op->digit_count);1494 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);
1496 size_t i = 0;1496 size_t i = 0;
1497 for (; i < op->digit_count; i += 1) {1497 for (; i < op->digit_count; i += 1) {
1498 dest->data.digits[i] = ~op_digits[i];1498 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) {...@@ -50,7 +50,7 @@ static inline void buf_resize(Buf *buf, size_t new_len) {
50}50}
5151
52static inline Buf *buf_alloc_fixed(size_t size) {52static inline Buf *buf_alloc_fixed(size_t size) {
53 Buf *buf = allocate<Buf>(1);53 Buf *buf = heap::c_allocator.create<Buf>();
54 buf_resize(buf, size);54 buf_resize(buf, size);
55 return buf;55 return buf;
56}56}
...@@ -65,7 +65,7 @@ static inline void buf_deinit(Buf *buf) {...@@ -65,7 +65,7 @@ static inline void buf_deinit(Buf *buf) {
6565
66static inline void buf_destroy(Buf *buf) {66static inline void buf_destroy(Buf *buf) {
67 buf_deinit(buf);67 buf_deinit(buf);
68 free(buf);68 heap::c_allocator.destroy(buf);
69}69}
7070
71static inline void buf_init_from_mem(Buf *buf, const char *ptr, size_t len) {71static 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) {...@@ -85,7 +85,7 @@ static inline void buf_init_from_buf(Buf *buf, Buf *other) {
8585
86static inline Buf *buf_create_from_mem(const char *ptr, size_t len) {86static inline Buf *buf_create_from_mem(const char *ptr, size_t len) {
87 assert(len != SIZE_MAX);87 assert(len != SIZE_MAX);
88 Buf *buf = allocate<Buf>(1);88 Buf *buf = heap::c_allocator.create<Buf>();
89 buf_init_from_mem(buf, ptr, len);89 buf_init_from_mem(buf, ptr, len);
90 return buf;90 return buf;
91}91}
...@@ -108,7 +108,7 @@ static inline Buf *buf_slice(Buf *in_buf, size_t start, size_t end) {...@@ -108,7 +108,7 @@ static inline Buf *buf_slice(Buf *in_buf, size_t start, size_t end) {
108 assert(end != SIZE_MAX);108 assert(end != SIZE_MAX);
109 assert(start < buf_len(in_buf));109 assert(start < buf_len(in_buf));
110 assert(end <= buf_len(in_buf));110 assert(end <= buf_len(in_buf));
111 Buf *out_buf = allocate<Buf>(1);111 Buf *out_buf = heap::c_allocator.create<Buf>();
112 out_buf->list.resize(end - start + 1);112 out_buf->list.resize(end - start + 1);
113 memcpy(buf_ptr(out_buf), buf_ptr(in_buf) + start, end - start);113 memcpy(buf_ptr(out_buf), buf_ptr(in_buf) + start, end - start);
114 out_buf->list.at(buf_len(out_buf)) = 0;114 out_buf->list.at(buf_len(out_buf)) = 0;
...@@ -211,5 +211,4 @@ static inline void buf_replace(Buf* buf, char from, char to) {...@@ -211,5 +211,4 @@ static inline void buf_replace(Buf* buf, char from, char to) {
211 }211 }
212}212}
213213
214
215#endif214#endif
src/codegen.cpp+40-35
...@@ -21,6 +21,7 @@...@@ -21,6 +21,7 @@
21#include "userland.h"21#include "userland.h"
22#include "dump_analysis.hpp"22#include "dump_analysis.hpp"
23#include "softfloat.hpp"23#include "softfloat.hpp"
24#include "mem_profile.hpp"
2425
25#include <stdio.h>26#include <stdio.h>
26#include <errno.h>27#include <errno.h>
...@@ -57,7 +58,7 @@ static void init_darwin_native(CodeGen *g) {...@@ -57,7 +58,7 @@ static void init_darwin_native(CodeGen *g) {
57}58}
5859
59static ZigPackage *new_package(const char *root_src_dir, const char *root_src_path, const char *pkg_path) {60static 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>();
61 entry->package_table.init(4);62 entry->package_table.init(4);
62 buf_init_from_str(&entry->root_src_dir, root_src_dir);63 buf_init_from_str(&entry->root_src_dir, root_src_dir);
63 buf_init_from_str(&entry->root_src_path, root_src_path);64 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...@@ -4327,7 +4328,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutableGen *executable, IrIn
4327 }4328 }
4328 size_t field_count = arg_calc.field_index;4329 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);
4331 LLVMGetStructElementTypes(LLVMGetElementType(LLVMTypeOf(frame_result_loc)), field_types);4332 LLVMGetStructElementTypes(LLVMGetElementType(LLVMTypeOf(frame_result_loc)), field_types);
4332 assert(LLVMCountStructElementTypes(LLVMGetElementType(LLVMTypeOf(frame_result_loc))) == arg_calc_start.field_index);4333 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...@@ -4680,8 +4681,8 @@ static LLVMValueRef ir_render_asm_gen(CodeGen *g, IrExecutableGen *executable, I
4680 instruction->return_count;4681 instruction->return_count;
4681 size_t total_index = 0;4682 size_t total_index = 0;
4682 size_t param_index = 0;4683 size_t param_index = 0;
4683 LLVMTypeRef *param_types = allocate<LLVMTypeRef>(input_and_output_count);4684 LLVMTypeRef *param_types = heap::c_allocator.allocate<LLVMTypeRef>(input_and_output_count);
4684 LLVMValueRef *param_values = allocate<LLVMValueRef>(input_and_output_count);4685 LLVMValueRef *param_values = heap::c_allocator.allocate<LLVMValueRef>(input_and_output_count);
4685 for (size_t i = 0; i < asm_expr->output_list.length; i += 1, total_index += 1) {4686 for (size_t i = 0; i < asm_expr->output_list.length; i += 1, total_index += 1) {
4686 AsmOutput *asm_output = asm_expr->output_list.at(i);4687 AsmOutput *asm_output = asm_expr->output_list.at(i);
4687 bool is_return = (asm_output->return_type != nullptr);4688 bool is_return = (asm_output->return_type != nullptr);
...@@ -4923,7 +4924,7 @@ static LLVMValueRef ir_render_shuffle_vector(CodeGen *g, IrExecutableGen *execut...@@ -4923,7 +4924,7 @@ static LLVMValueRef ir_render_shuffle_vector(CodeGen *g, IrExecutableGen *execut
4923 // second vector. These start at -1 and go down, and are easiest to use4924 // second vector. These start at -1 and go down, and are easiest to use
4924 // with the ~ operator. Here we convert between the two formats.4925 // with the ~ operator. Here we convert between the two formats.
4925 IrInstGen *mask = instruction->mask;4926 IrInstGen *mask = instruction->mask;
4926 LLVMValueRef *values = allocate<LLVMValueRef>(len_mask);4927 LLVMValueRef *values = heap::c_allocator.allocate<LLVMValueRef>(len_mask);
4927 for (uint64_t i = 0; i < len_mask; i++) {4928 for (uint64_t i = 0; i < len_mask; i++) {
4928 if (mask->value->data.x_array.data.s_none.elements[i].special == ConstValSpecialUndef) {4929 if (mask->value->data.x_array.data.s_none.elements[i].special == ConstValSpecialUndef) {
4929 values[i] = LLVMGetUndef(LLVMInt32Type());4930 values[i] = LLVMGetUndef(LLVMInt32Type());
...@@ -4935,7 +4936,7 @@ static LLVMValueRef ir_render_shuffle_vector(CodeGen *g, IrExecutableGen *execut...@@ -4935,7 +4936,7 @@ static LLVMValueRef ir_render_shuffle_vector(CodeGen *g, IrExecutableGen *execut
4935 }4936 }
49364937
4937 LLVMValueRef llvm_mask_value = LLVMConstVector(values, len_mask);4938 LLVMValueRef llvm_mask_value = LLVMConstVector(values, len_mask);
4938 free(values);4939 heap::c_allocator.deallocate(values, len_mask);
49394940
4940 return LLVMBuildShuffleVector(g->builder,4941 return LLVMBuildShuffleVector(g->builder,
4941 ir_llvm_value(g, instruction->a),4942 ir_llvm_value(g, instruction->a),
...@@ -5003,8 +5004,8 @@ static LLVMValueRef ir_render_phi(CodeGen *g, IrExecutableGen *executable, IrIns...@@ -5003,8 +5004,8 @@ static LLVMValueRef ir_render_phi(CodeGen *g, IrExecutableGen *executable, IrIns
5003 }5004 }
50045005
5005 LLVMValueRef phi = LLVMBuildPhi(g->builder, phi_type, "");5006 LLVMValueRef phi = LLVMBuildPhi(g->builder, phi_type, "");
5006 LLVMValueRef *incoming_values = allocate<LLVMValueRef>(instruction->incoming_count);5007 LLVMValueRef *incoming_values = heap::c_allocator.allocate<LLVMValueRef>(instruction->incoming_count);
5007 LLVMBasicBlockRef *incoming_blocks = allocate<LLVMBasicBlockRef>(instruction->incoming_count);5008 LLVMBasicBlockRef *incoming_blocks = heap::c_allocator.allocate<LLVMBasicBlockRef>(instruction->incoming_count);
5008 for (size_t i = 0; i < instruction->incoming_count; i += 1) {5009 for (size_t i = 0; i < instruction->incoming_count; i += 1) {
5009 incoming_values[i] = ir_llvm_value(g, instruction->incoming_values[i]);5010 incoming_values[i] = ir_llvm_value(g, instruction->incoming_values[i]);
5010 incoming_blocks[i] = instruction->incoming_blocks[i]->llvm_exit_block;5011 incoming_blocks[i] = instruction->incoming_blocks[i]->llvm_exit_block;
...@@ -5977,12 +5978,12 @@ static LLVMValueRef ir_render_bswap(CodeGen *g, IrExecutableGen *executable, IrI...@@ -5977,12 +5978,12 @@ static LLVMValueRef ir_render_bswap(CodeGen *g, IrExecutableGen *executable, IrI
5977 LLVMValueRef shift_amt = LLVMConstInt(get_llvm_type(g, extended_type), 8, false);5978 LLVMValueRef shift_amt = LLVMConstInt(get_llvm_type(g, extended_type), 8, false);
5978 if (is_vector) {5979 if (is_vector) {
5979 extended_type = get_vector_type(g, expr_type->data.vector.len, extended_type);5980 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);
5981 for (uint32_t i = 0; i < expr_type->data.vector.len; i += 1) {5982 for (uint32_t i = 0; i < expr_type->data.vector.len; i += 1) {
5982 values[i] = shift_amt;5983 values[i] = shift_amt;
5983 }5984 }
5984 shift_amt = LLVMConstVector(values, expr_type->data.vector.len);5985 shift_amt = LLVMConstVector(values, expr_type->data.vector.len);
5985 free(values);5986 heap::c_allocator.deallocate(values, expr_type->data.vector.len);
5986 }5987 }
5987 // aabbcc5988 // aabbcc
5988 LLVMValueRef extended = LLVMBuildZExt(g->builder, op, get_llvm_type(g, extended_type), "");5989 LLVMValueRef extended = LLVMBuildZExt(g->builder, op, get_llvm_type(g, extended_type), "");
...@@ -7015,7 +7016,7 @@ check: switch (const_val->special) {...@@ -7015,7 +7016,7 @@ check: switch (const_val->special) {
7015 }7016 }
7016 case ZigTypeIdStruct:7017 case ZigTypeIdStruct:
7017 {7018 {
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);
7019 size_t src_field_count = type_entry->data.structure.src_field_count;7020 size_t src_field_count = type_entry->data.structure.src_field_count;
7020 bool make_unnamed_struct = false;7021 bool make_unnamed_struct = false;
7021 assert(type_entry->data.structure.resolve_status == ResolveStatusLLVMFull);7022 assert(type_entry->data.structure.resolve_status == ResolveStatusLLVMFull);
...@@ -7074,7 +7075,7 @@ check: switch (const_val->special) {...@@ -7074,7 +7075,7 @@ check: switch (const_val->special) {
7074 } else {7075 } else {
7075 const LLVMValueRef AMT = LLVMConstInt(LLVMTypeOf(val), 8, false);7076 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);
7078 for (size_t i = 0; i < size_in_bytes; i++) {7079 for (size_t i = 0; i < size_in_bytes; i++) {
7079 const size_t idx = is_big_endian ? size_in_bytes - 1 - i : i;7080 const size_t idx = is_big_endian ? size_in_bytes - 1 - i : i;
7080 values[idx] = LLVMConstTruncOrBitCast(val, LLVMInt8Type());7081 values[idx] = LLVMConstTruncOrBitCast(val, LLVMInt8Type());
...@@ -7138,7 +7139,7 @@ check: switch (const_val->special) {...@@ -7138,7 +7139,7 @@ check: switch (const_val->special) {
7138 case ConstArraySpecialNone: {7139 case ConstArraySpecialNone: {
7139 uint64_t extra_len_from_sentinel = (type_entry->data.array.sentinel != nullptr) ? 1 : 0;7140 uint64_t extra_len_from_sentinel = (type_entry->data.array.sentinel != nullptr) ? 1 : 0;
7140 uint64_t full_len = len + extra_len_from_sentinel;7141 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);
7142 LLVMTypeRef element_type_ref = get_llvm_type(g, type_entry->data.array.child_type);7143 LLVMTypeRef element_type_ref = get_llvm_type(g, type_entry->data.array.child_type);
7143 bool make_unnamed_struct = false;7144 bool make_unnamed_struct = false;
7144 for (uint64_t i = 0; i < len; i += 1) {7145 for (uint64_t i = 0; i < len; i += 1) {
...@@ -7170,7 +7171,7 @@ check: switch (const_val->special) {...@@ -7170,7 +7171,7 @@ check: switch (const_val->special) {
7170 case ConstArraySpecialUndef:7171 case ConstArraySpecialUndef:
7171 return LLVMGetUndef(get_llvm_type(g, type_entry));7172 return LLVMGetUndef(get_llvm_type(g, type_entry));
7172 case ConstArraySpecialNone: {7173 case ConstArraySpecialNone: {
7173 LLVMValueRef *values = allocate<LLVMValueRef>(len);7174 LLVMValueRef *values = heap::c_allocator.allocate<LLVMValueRef>(len);
7174 for (uint64_t i = 0; i < len; i += 1) {7175 for (uint64_t i = 0; i < len; i += 1) {
7175 ZigValue *elem_value = &const_val->data.x_array.data.s_none.elements[i];7176 ZigValue *elem_value = &const_val->data.x_array.data.s_none.elements[i];
7176 values[i] = gen_const_val(g, elem_value, "");7177 values[i] = gen_const_val(g, elem_value, "");
...@@ -7180,7 +7181,7 @@ check: switch (const_val->special) {...@@ -7180,7 +7181,7 @@ check: switch (const_val->special) {
7180 case ConstArraySpecialBuf: {7181 case ConstArraySpecialBuf: {
7181 Buf *buf = const_val->data.x_array.data.s_buf;7182 Buf *buf = const_val->data.x_array.data.s_buf;
7182 assert(buf_len(buf) == len);7183 assert(buf_len(buf) == len);
7183 LLVMValueRef *values = allocate<LLVMValueRef>(len);7184 LLVMValueRef *values = heap::c_allocator.allocate<LLVMValueRef>(len);
7184 for (uint64_t i = 0; i < len; i += 1) {7185 for (uint64_t i = 0; i < len; i += 1) {
7185 values[i] = LLVMConstInt(g->builtin_types.entry_u8->llvm_type, buf_ptr(buf)[i], false);7186 values[i] = LLVMConstInt(g->builtin_types.entry_u8->llvm_type, buf_ptr(buf)[i], false);
7186 }7187 }
...@@ -7382,7 +7383,7 @@ static void generate_error_name_table(CodeGen *g) {...@@ -7382,7 +7383,7 @@ static void generate_error_name_table(CodeGen *g) {
7382 PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0, false);7383 PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0, false);
7383 ZigType *str_type = get_slice_type(g, u8_ptr_type);7384 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);
7386 values[0] = LLVMGetUndef(get_llvm_type(g, str_type));7387 values[0] = LLVMGetUndef(get_llvm_type(g, str_type));
7387 for (size_t i = 1; i < g->errors_by_index.length; i += 1) {7388 for (size_t i = 1; i < g->errors_by_index.length; i += 1) {
7388 ErrorTableEntry *err_entry = g->errors_by_index.at(i);7389 ErrorTableEntry *err_entry = g->errors_by_index.at(i);
...@@ -7911,6 +7912,9 @@ static void do_code_gen(CodeGen *g) {...@@ -7911,6 +7912,9 @@ static void do_code_gen(CodeGen *g) {
7911}7912}
79127913
7913static void zig_llvm_emit_output(CodeGen *g) {7914static void zig_llvm_emit_output(CodeGen *g) {
7915 g->pass1_arena->destruct(&heap::c_allocator);
7916 g->pass1_arena = nullptr;
7917
7914 bool is_small = g->build_mode == BuildModeSmallRelease;7918 bool is_small = g->build_mode == BuildModeSmallRelease;
79157919
7916 Buf *output_path = &g->o_file_output_path;7920 Buf *output_path = &g->o_file_output_path;
...@@ -8207,7 +8211,7 @@ static void define_intern_values(CodeGen *g) {...@@ -8207,7 +8211,7 @@ static void define_intern_values(CodeGen *g) {
8207}8211}
82088212
8209static BuiltinFnEntry *create_builtin_fn(CodeGen *g, BuiltinFnId id, const char *name, size_t count) {8213static 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>();
8211 buf_init_from_str(&builtin_fn->name, name);8215 buf_init_from_str(&builtin_fn->name, name);
8212 builtin_fn->id = id;8216 builtin_fn->id = id;
8213 builtin_fn->param_count = count;8217 builtin_fn->param_count = count;
...@@ -8925,16 +8929,16 @@ static void init(CodeGen *g) {...@@ -8925,16 +8929,16 @@ static void init(CodeGen *g) {
8925 define_builtin_types(g);8929 define_builtin_types(g);
8926 define_intern_values(g);8930 define_intern_values(g);
89278931
8928 IrInstGen *sentinel_instructions = allocate<IrInstGen>(2);8932 IrInstGen *sentinel_instructions = heap::c_allocator.allocate<IrInstGen>(2);
8929 g->invalid_inst_gen = &sentinel_instructions[0];8933 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>();
8931 g->invalid_inst_gen->value->type = g->builtin_types.entry_invalid;8935 g->invalid_inst_gen->value->type = g->builtin_types.entry_invalid;
89328936
8933 g->unreach_instruction = &sentinel_instructions[1];8937 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>();
8935 g->unreach_instruction->value->type = g->builtin_types.entry_unreachable;8939 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
8939 define_builtin_fns(g);8943 define_builtin_fns(g);
8940 Error err;8944 Error err;
...@@ -9016,7 +9020,7 @@ static void detect_libc(CodeGen *g) {...@@ -9016,7 +9020,7 @@ static void detect_libc(CodeGen *g) {
9016 buf_ptr(g->zig_lib_dir), target_os_name(g->zig_target->os));9020 buf_ptr(g->zig_lib_dir), target_os_name(g->zig_target->os));
90179021
9018 g->libc_include_dir_len = 4;9022 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);
9020 g->libc_include_dir_list[0] = arch_include_dir;9024 g->libc_include_dir_list[0] = arch_include_dir;
9021 g->libc_include_dir_list[1] = generic_include_dir;9025 g->libc_include_dir_list[1] = generic_include_dir;
9022 g->libc_include_dir_list[2] = arch_os_include_dir;9026 g->libc_include_dir_list[2] = arch_os_include_dir;
...@@ -9025,7 +9029,7 @@ static void detect_libc(CodeGen *g) {...@@ -9025,7 +9029,7 @@ static void detect_libc(CodeGen *g) {
9025 }9029 }
90269030
9027 if (g->zig_target->is_native) {9031 if (g->zig_target->is_native) {
9028 g->libc = allocate<ZigLibCInstallation>(1);9032 g->libc = heap::c_allocator.create<ZigLibCInstallation>();
90299033
9030 // search for native_libc.txt in following dirs:9034 // search for native_libc.txt in following dirs:
9031 // - LOCAL_CACHE_DIR9035 // - LOCAL_CACHE_DIR
...@@ -9105,7 +9109,7 @@ static void detect_libc(CodeGen *g) {...@@ -9105,7 +9109,7 @@ static void detect_libc(CodeGen *g) {
9105 size_t want_um_and_shared_dirs = (g->zig_target->os == OsWindows) ? 2 : 0;9109 size_t want_um_and_shared_dirs = (g->zig_target->os == OsWindows) ? 2 : 0;
9106 size_t dir_count = 1 + want_sys_dir + want_um_and_shared_dirs;9110 size_t dir_count = 1 + want_sys_dir + want_um_and_shared_dirs;
9107 g->libc_include_dir_len = 0;9111 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
9110 g->libc_include_dir_list[g->libc_include_dir_len] = &g->libc->include_dir;9114 g->libc_include_dir_list[g->libc_include_dir_len] = &g->libc->include_dir;
9111 g->libc_include_dir_len += 1;9115 g->libc_include_dir_len += 1;
...@@ -9472,10 +9476,10 @@ static void update_test_functions_builtin_decl(CodeGen *g) {...@@ -9472,10 +9476,10 @@ static void update_test_functions_builtin_decl(CodeGen *g) {
9472 if ((err = type_resolve(g, struct_type, ResolveStatusSizeKnown)))9476 if ((err = type_resolve(g, struct_type, ResolveStatusSizeKnown)))
9473 zig_unreachable();9477 zig_unreachable();
94749478
9475 ZigValue *test_fn_array = create_const_vals(1);9479 ZigValue *test_fn_array = g->pass1_arena->create<ZigValue>();
9476 test_fn_array->type = get_array_type(g, struct_type, g->test_fns.length, nullptr);9480 test_fn_array->type = get_array_type(g, struct_type, g->test_fns.length, nullptr);
9477 test_fn_array->special = ConstValSpecialStatic;9481 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
9480 for (size_t i = 0; i < g->test_fns.length; i += 1) {9484 for (size_t i = 0; i < g->test_fns.length; i += 1) {
9481 ZigFn *test_fn_entry = g->test_fns.at(i);9485 ZigFn *test_fn_entry = g->test_fns.at(i);
...@@ -9486,7 +9490,7 @@ static void update_test_functions_builtin_decl(CodeGen *g) {...@@ -9486,7 +9490,7 @@ static void update_test_functions_builtin_decl(CodeGen *g) {
9486 this_val->parent.id = ConstParentIdArray;9490 this_val->parent.id = ConstParentIdArray;
9487 this_val->parent.data.p_array.array_val = test_fn_array;9491 this_val->parent.data.p_array.array_val = test_fn_array;
9488 this_val->parent.data.p_array.elem_index = i;9492 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
9491 ZigValue *name_field = this_val->data.x_struct.fields[0];9495 ZigValue *name_field = this_val->data.x_struct.fields[0];
9492 ZigValue *name_array_val = create_const_str_lit(g, &test_fn_entry->symbol_name)->data.x_ptr.data.ref.pointee;9496 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) {...@@ -9505,7 +9509,7 @@ static void update_test_functions_builtin_decl(CodeGen *g) {
9505 frame_size_field->data.x_optional = nullptr;9509 frame_size_field->data.x_optional = nullptr;
95069510
9507 if (fn_is_async(test_fn_entry)) {9511 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>();
9509 frame_size_field->data.x_optional->special = ConstValSpecialStatic;9513 frame_size_field->data.x_optional->special = ConstValSpecialStatic;
9510 frame_size_field->data.x_optional->type = g->builtin_types.entry_usize;9514 frame_size_field->data.x_optional->type = g->builtin_types.entry_usize;
9511 bigint_init_unsigned(&frame_size_field->data.x_optional->data.x_bigint,9515 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) {...@@ -9640,7 +9644,7 @@ static Error get_tmp_filename(CodeGen *g, Buf *out, Buf *suffix) {
96409644
9641Error create_c_object_cache(CodeGen *g, CacheHash **out_cache_hash, bool verbose) {9645Error create_c_object_cache(CodeGen *g, CacheHash **out_cache_hash, bool verbose) {
9642 Error err;9646 Error err;
9643 CacheHash *cache_hash = allocate<CacheHash>(1);9647 CacheHash *cache_hash = heap::c_allocator.create<CacheHash>();
9644 Buf *manifest_dir = buf_sprintf("%s" OS_SEP CACHE_HASH_SUBDIR, buf_ptr(g->cache_dir));9648 Buf *manifest_dir = buf_sprintf("%s" OS_SEP CACHE_HASH_SUBDIR, buf_ptr(g->cache_dir));
9645 cache_init(cache_hash, manifest_dir);9649 cache_init(cache_hash, manifest_dir);
96469650
...@@ -10794,7 +10798,8 @@ CodeGen *codegen_create(Buf *main_pkg_path, Buf *root_src_path, const ZigTarget...@@ -10794,7 +10798,8 @@ CodeGen *codegen_create(Buf *main_pkg_path, Buf *root_src_path, const ZigTarget
10794 OutType out_type, BuildMode build_mode, Buf *override_lib_dir,10798 OutType out_type, BuildMode build_mode, Buf *override_lib_dir,
10795 ZigLibCInstallation *libc, Buf *cache_dir, bool is_test_build, Stage2ProgressNode *progress_node)10799 ZigLibCInstallation *libc, Buf *cache_dir, bool is_test_build, Stage2ProgressNode *progress_node)
10796{10800{
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");
10798 g->main_progress_node = progress_node;10803 g->main_progress_node = progress_node;
1079910804
10800 codegen_add_time_event(g, "Initialize");10805 codegen_add_time_event(g, "Initialize");
...@@ -10937,35 +10942,35 @@ void codegen_switch_sub_prog_node(CodeGen *g, Stage2ProgressNode *node) {...@@ -10937,35 +10942,35 @@ void codegen_switch_sub_prog_node(CodeGen *g, Stage2ProgressNode *node) {
1093710942
10938ZigValue *CodeGen::Intern::for_undefined() {10943ZigValue *CodeGen::Intern::for_undefined() {
10939#ifdef ZIG_ENABLE_MEM_PROFILE10944#ifdef ZIG_ENABLE_MEM_PROFILE
10940 memprof_intern_count.x_undefined += 1;10945 mem::intern_counters.x_undefined += 1;
10941#endif10946#endif
10942 return &this->x_undefined;10947 return &this->x_undefined;
10943}10948}
1094410949
10945ZigValue *CodeGen::Intern::for_void() {10950ZigValue *CodeGen::Intern::for_void() {
10946#ifdef ZIG_ENABLE_MEM_PROFILE10951#ifdef ZIG_ENABLE_MEM_PROFILE
10947 memprof_intern_count.x_void += 1;10952 mem::intern_counters.x_void += 1;
10948#endif10953#endif
10949 return &this->x_void;10954 return &this->x_void;
10950}10955}
1095110956
10952ZigValue *CodeGen::Intern::for_null() {10957ZigValue *CodeGen::Intern::for_null() {
10953#ifdef ZIG_ENABLE_MEM_PROFILE10958#ifdef ZIG_ENABLE_MEM_PROFILE
10954 memprof_intern_count.x_null += 1;10959 mem::intern_counters.x_null += 1;
10955#endif10960#endif
10956 return &this->x_null;10961 return &this->x_null;
10957}10962}
1095810963
10959ZigValue *CodeGen::Intern::for_unreachable() {10964ZigValue *CodeGen::Intern::for_unreachable() {
10960#ifdef ZIG_ENABLE_MEM_PROFILE10965#ifdef ZIG_ENABLE_MEM_PROFILE
10961 memprof_intern_count.x_unreachable += 1;10966 mem::intern_counters.x_unreachable += 1;
10962#endif10967#endif
10963 return &this->x_unreachable;10968 return &this->x_unreachable;
10964}10969}
1096510970
10966ZigValue *CodeGen::Intern::for_zero_byte() {10971ZigValue *CodeGen::Intern::for_zero_byte() {
10967#ifdef ZIG_ENABLE_MEM_PROFILE10972#ifdef ZIG_ENABLE_MEM_PROFILE
10968 memprof_intern_count.zero_byte += 1;10973 mem::intern_counters.zero_byte += 1;
10969#endif10974#endif
10970 return &this->zero_byte;10975 return &this->zero_byte;
10971}10976}
src/errmsg.cpp+2-2
...@@ -99,7 +99,7 @@ void err_msg_add_note(ErrorMsg *parent, ErrorMsg *note) {...@@ -99,7 +99,7 @@ void err_msg_add_note(ErrorMsg *parent, ErrorMsg *note) {
99ErrorMsg *err_msg_create_with_offset(Buf *path, size_t line, size_t column, size_t offset,99ErrorMsg *err_msg_create_with_offset(Buf *path, size_t line, size_t column, size_t offset,
100 const char *source, Buf *msg)100 const char *source, Buf *msg)
101{101{
102 ErrorMsg *err_msg = allocate<ErrorMsg>(1);102 ErrorMsg *err_msg = heap::c_allocator.create<ErrorMsg>();
103 err_msg->path = path;103 err_msg->path = path;
104 err_msg->line_start = line;104 err_msg->line_start = line;
105 err_msg->column_start = column;105 err_msg->column_start = column;
...@@ -138,7 +138,7 @@ ErrorMsg *err_msg_create_with_offset(Buf *path, size_t line, size_t column, size...@@ -138,7 +138,7 @@ ErrorMsg *err_msg_create_with_offset(Buf *path, size_t line, size_t column, size
138ErrorMsg *err_msg_create_with_line(Buf *path, size_t line, size_t column,138ErrorMsg *err_msg_create_with_line(Buf *path, size_t line, size_t column,
139 Buf *source, ZigList<size_t> *line_offsets, Buf *msg)139 Buf *source, ZigList<size_t> *line_offsets, Buf *msg)
140{140{
141 ErrorMsg *err_msg = allocate<ErrorMsg>(1);141 ErrorMsg *err_msg = heap::c_allocator.create<ErrorMsg>();
142 err_msg->path = path;142 err_msg->path = path;
143 err_msg->line_start = line;143 err_msg->line_start = line;
144 err_msg->column_start = column;144 err_msg->column_start = column;
src/glibc.cpp+4-4
...@@ -21,7 +21,7 @@ static const ZigGLibCLib glibc_libs[] = {...@@ -21,7 +21,7 @@ static const ZigGLibCLib glibc_libs[] = {
21Error glibc_load_metadata(ZigGLibCAbi **out_result, Buf *zig_lib_dir, bool verbose) {21Error glibc_load_metadata(ZigGLibCAbi **out_result, Buf *zig_lib_dir, bool verbose) {
22 Error err;22 Error err;
2323
24 ZigGLibCAbi *glibc_abi = allocate<ZigGLibCAbi>(1);24 ZigGLibCAbi *glibc_abi = heap::c_allocator.create<ZigGLibCAbi>();
25 glibc_abi->vers_txt_path = buf_sprintf("%s" OS_SEP "libc" OS_SEP "glibc" OS_SEP "vers.txt", buf_ptr(zig_lib_dir));25 glibc_abi->vers_txt_path = buf_sprintf("%s" OS_SEP "libc" OS_SEP "glibc" OS_SEP "vers.txt", buf_ptr(zig_lib_dir));
26 glibc_abi->fns_txt_path = buf_sprintf("%s" OS_SEP "libc" OS_SEP "glibc" OS_SEP "fns.txt", buf_ptr(zig_lib_dir));26 glibc_abi->fns_txt_path = buf_sprintf("%s" OS_SEP "libc" OS_SEP "glibc" OS_SEP "fns.txt", buf_ptr(zig_lib_dir));
27 glibc_abi->abi_txt_path = buf_sprintf("%s" OS_SEP "libc" OS_SEP "glibc" OS_SEP "abi.txt", buf_ptr(zig_lib_dir));27 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...@@ -100,10 +100,10 @@ Error glibc_load_metadata(ZigGLibCAbi **out_result, Buf *zig_lib_dir, bool verbo
100 Optional<Slice<uint8_t>> opt_line = SplitIterator_next_separate(&it);100 Optional<Slice<uint8_t>> opt_line = SplitIterator_next_separate(&it);
101 if (!opt_line.is_some) break;101 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);
104 SplitIterator line_it = memSplit(opt_line.value, str(" "));104 SplitIterator line_it = memSplit(opt_line.value, str(" "));
105 for (;;) {105 for (;;) {
106 ZigTarget *target = allocate<ZigTarget>(1);106 ZigTarget *target = heap::c_allocator.create<ZigTarget>();
107 Optional<Slice<uint8_t>> opt_target = SplitIterator_next(&line_it);107 Optional<Slice<uint8_t>> opt_target = SplitIterator_next(&line_it);
108 if (!opt_target.is_some) break;108 if (!opt_target.is_some) break;
109109
...@@ -174,7 +174,7 @@ Error glibc_build_dummies_and_maps(CodeGen *g, const ZigGLibCAbi *glibc_abi, con...@@ -174,7 +174,7 @@ Error glibc_build_dummies_and_maps(CodeGen *g, const ZigGLibCAbi *glibc_abi, con
174 Error err;174 Error err;
175175
176 Buf *cache_dir = get_global_cache_dir();176 Buf *cache_dir = get_global_cache_dir();
177 CacheHash *cache_hash = allocate<CacheHash>(1);177 CacheHash *cache_hash = heap::c_allocator.create<CacheHash>();
178 Buf *manifest_dir = buf_sprintf("%s" OS_SEP CACHE_HASH_SUBDIR, buf_ptr(cache_dir));178 Buf *manifest_dir = buf_sprintf("%s" OS_SEP CACHE_HASH_SUBDIR, buf_ptr(cache_dir));
179 cache_init(cache_hash, manifest_dir);179 cache_init(cache_hash, manifest_dir);
180180
src/hash_map.hpp+3-3
...@@ -19,7 +19,7 @@ public:...@@ -19,7 +19,7 @@ public:
19 init_capacity(capacity);19 init_capacity(capacity);
20 }20 }
21 void deinit(void) {21 void deinit(void) {
22 free(_entries);22 heap::c_allocator.deallocate(_entries, _capacity);
23 }23 }
2424
25 struct Entry {25 struct Entry {
...@@ -57,7 +57,7 @@ public:...@@ -57,7 +57,7 @@ public:
57 if (old_entry->used)57 if (old_entry->used)
58 internal_put(old_entry->key, old_entry->value);58 internal_put(old_entry->key, old_entry->value);
59 }59 }
60 free(old_entries);60 heap::c_allocator.deallocate(old_entries, old_capacity);
61 }61 }
62 }62 }
6363
...@@ -164,7 +164,7 @@ private:...@@ -164,7 +164,7 @@ private:
164164
165 void init_capacity(int capacity) {165 void init_capacity(int capacity) {
166 _capacity = capacity;166 _capacity = capacity;
167 _entries = allocate<Entry>(_capacity);167 _entries = heap::c_allocator.allocate<Entry>(_capacity);
168 _size = 0;168 _size = 0;
169 _max_distance_from_start_index = 0;169 _max_distance_from_start_index = 0;
170 for (int i = 0; i < _capacity; i += 1) {170 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,...@@ -269,477 +269,467 @@ static IrInstGen *ir_analyze_test_non_null(IrAnalyze *ira, IrInst *source_inst,
269static IrInstGen *ir_error_dependency_loop(IrAnalyze *ira, IrInst *source_instr);269static IrInstGen *ir_error_dependency_loop(IrAnalyze *ira, IrInst *source_instr);
270270
271static void destroy_instruction_src(IrInstSrc *inst) {271static 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
277 switch (inst->id) {272 switch (inst->id) {
278 case IrInstSrcIdInvalid:273 case IrInstSrcIdInvalid:
279 zig_unreachable();274 zig_unreachable();
280 case IrInstSrcIdReturn:275 case IrInstSrcIdReturn:
281 return destroy(reinterpret_cast<IrInstSrcReturn *>(inst), name);276 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcReturn *>(inst));
282 case IrInstSrcIdConst:277 case IrInstSrcIdConst:
283 return destroy(reinterpret_cast<IrInstSrcConst *>(inst), name);278 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcConst *>(inst));
284 case IrInstSrcIdBinOp:279 case IrInstSrcIdBinOp:
285 return destroy(reinterpret_cast<IrInstSrcBinOp *>(inst), name);280 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcBinOp *>(inst));
286 case IrInstSrcIdMergeErrSets:281 case IrInstSrcIdMergeErrSets:
287 return destroy(reinterpret_cast<IrInstSrcMergeErrSets *>(inst), name);282 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcMergeErrSets *>(inst));
288 case IrInstSrcIdDeclVar:283 case IrInstSrcIdDeclVar:
289 return destroy(reinterpret_cast<IrInstSrcDeclVar *>(inst), name);284 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcDeclVar *>(inst));
290 case IrInstSrcIdCall:285 case IrInstSrcIdCall:
291 return destroy(reinterpret_cast<IrInstSrcCall *>(inst), name);286 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcCall *>(inst));
292 case IrInstSrcIdCallExtra:287 case IrInstSrcIdCallExtra:
293 return destroy(reinterpret_cast<IrInstSrcCallExtra *>(inst), name);288 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcCallExtra *>(inst));
294 case IrInstSrcIdUnOp:289 case IrInstSrcIdUnOp:
295 return destroy(reinterpret_cast<IrInstSrcUnOp *>(inst), name);290 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcUnOp *>(inst));
296 case IrInstSrcIdCondBr:291 case IrInstSrcIdCondBr:
297 return destroy(reinterpret_cast<IrInstSrcCondBr *>(inst), name);292 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcCondBr *>(inst));
298 case IrInstSrcIdBr:293 case IrInstSrcIdBr:
299 return destroy(reinterpret_cast<IrInstSrcBr *>(inst), name);294 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcBr *>(inst));
300 case IrInstSrcIdPhi:295 case IrInstSrcIdPhi:
301 return destroy(reinterpret_cast<IrInstSrcPhi *>(inst), name);296 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcPhi *>(inst));
302 case IrInstSrcIdContainerInitList:297 case IrInstSrcIdContainerInitList:
303 return destroy(reinterpret_cast<IrInstSrcContainerInitList *>(inst), name);298 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcContainerInitList *>(inst));
304 case IrInstSrcIdContainerInitFields:299 case IrInstSrcIdContainerInitFields:
305 return destroy(reinterpret_cast<IrInstSrcContainerInitFields *>(inst), name);300 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcContainerInitFields *>(inst));
306 case IrInstSrcIdUnreachable:301 case IrInstSrcIdUnreachable:
307 return destroy(reinterpret_cast<IrInstSrcUnreachable *>(inst), name);302 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcUnreachable *>(inst));
308 case IrInstSrcIdElemPtr:303 case IrInstSrcIdElemPtr:
309 return destroy(reinterpret_cast<IrInstSrcElemPtr *>(inst), name);304 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcElemPtr *>(inst));
310 case IrInstSrcIdVarPtr:305 case IrInstSrcIdVarPtr:
311 return destroy(reinterpret_cast<IrInstSrcVarPtr *>(inst), name);306 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcVarPtr *>(inst));
312 case IrInstSrcIdLoadPtr:307 case IrInstSrcIdLoadPtr:
313 return destroy(reinterpret_cast<IrInstSrcLoadPtr *>(inst), name);308 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcLoadPtr *>(inst));
314 case IrInstSrcIdStorePtr:309 case IrInstSrcIdStorePtr:
315 return destroy(reinterpret_cast<IrInstSrcStorePtr *>(inst), name);310 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcStorePtr *>(inst));
316 case IrInstSrcIdTypeOf:311 case IrInstSrcIdTypeOf:
317 return destroy(reinterpret_cast<IrInstSrcTypeOf *>(inst), name);312 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcTypeOf *>(inst));
318 case IrInstSrcIdFieldPtr:313 case IrInstSrcIdFieldPtr:
319 return destroy(reinterpret_cast<IrInstSrcFieldPtr *>(inst), name);314 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFieldPtr *>(inst));
320 case IrInstSrcIdSetCold:315 case IrInstSrcIdSetCold:
321 return destroy(reinterpret_cast<IrInstSrcSetCold *>(inst), name);316 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSetCold *>(inst));
322 case IrInstSrcIdSetRuntimeSafety:317 case IrInstSrcIdSetRuntimeSafety:
323 return destroy(reinterpret_cast<IrInstSrcSetRuntimeSafety *>(inst), name);318 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSetRuntimeSafety *>(inst));
324 case IrInstSrcIdSetFloatMode:319 case IrInstSrcIdSetFloatMode:
325 return destroy(reinterpret_cast<IrInstSrcSetFloatMode *>(inst), name);320 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSetFloatMode *>(inst));
326 case IrInstSrcIdArrayType:321 case IrInstSrcIdArrayType:
327 return destroy(reinterpret_cast<IrInstSrcArrayType *>(inst), name);322 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcArrayType *>(inst));
328 case IrInstSrcIdSliceType:323 case IrInstSrcIdSliceType:
329 return destroy(reinterpret_cast<IrInstSrcSliceType *>(inst), name);324 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSliceType *>(inst));
330 case IrInstSrcIdAnyFrameType:325 case IrInstSrcIdAnyFrameType:
331 return destroy(reinterpret_cast<IrInstSrcAnyFrameType *>(inst), name);326 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcAnyFrameType *>(inst));
332 case IrInstSrcIdAsm:327 case IrInstSrcIdAsm:
333 return destroy(reinterpret_cast<IrInstSrcAsm *>(inst), name);328 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcAsm *>(inst));
334 case IrInstSrcIdSizeOf:329 case IrInstSrcIdSizeOf:
335 return destroy(reinterpret_cast<IrInstSrcSizeOf *>(inst), name);330 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSizeOf *>(inst));
336 case IrInstSrcIdTestNonNull:331 case IrInstSrcIdTestNonNull:
337 return destroy(reinterpret_cast<IrInstSrcTestNonNull *>(inst), name);332 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcTestNonNull *>(inst));
338 case IrInstSrcIdOptionalUnwrapPtr:333 case IrInstSrcIdOptionalUnwrapPtr:
339 return destroy(reinterpret_cast<IrInstSrcOptionalUnwrapPtr *>(inst), name);334 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcOptionalUnwrapPtr *>(inst));
340 case IrInstSrcIdPopCount:335 case IrInstSrcIdPopCount:
341 return destroy(reinterpret_cast<IrInstSrcPopCount *>(inst), name);336 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcPopCount *>(inst));
342 case IrInstSrcIdClz:337 case IrInstSrcIdClz:
343 return destroy(reinterpret_cast<IrInstSrcClz *>(inst), name);338 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcClz *>(inst));
344 case IrInstSrcIdCtz:339 case IrInstSrcIdCtz:
345 return destroy(reinterpret_cast<IrInstSrcCtz *>(inst), name);340 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcCtz *>(inst));
346 case IrInstSrcIdBswap:341 case IrInstSrcIdBswap:
347 return destroy(reinterpret_cast<IrInstSrcBswap *>(inst), name);342 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcBswap *>(inst));
348 case IrInstSrcIdBitReverse:343 case IrInstSrcIdBitReverse:
349 return destroy(reinterpret_cast<IrInstSrcBitReverse *>(inst), name);344 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcBitReverse *>(inst));
350 case IrInstSrcIdSwitchBr:345 case IrInstSrcIdSwitchBr:
351 return destroy(reinterpret_cast<IrInstSrcSwitchBr *>(inst), name);346 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSwitchBr *>(inst));
352 case IrInstSrcIdSwitchVar:347 case IrInstSrcIdSwitchVar:
353 return destroy(reinterpret_cast<IrInstSrcSwitchVar *>(inst), name);348 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSwitchVar *>(inst));
354 case IrInstSrcIdSwitchElseVar:349 case IrInstSrcIdSwitchElseVar:
355 return destroy(reinterpret_cast<IrInstSrcSwitchElseVar *>(inst), name);350 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSwitchElseVar *>(inst));
356 case IrInstSrcIdSwitchTarget:351 case IrInstSrcIdSwitchTarget:
357 return destroy(reinterpret_cast<IrInstSrcSwitchTarget *>(inst), name);352 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSwitchTarget *>(inst));
358 case IrInstSrcIdImport:353 case IrInstSrcIdImport:
359 return destroy(reinterpret_cast<IrInstSrcImport *>(inst), name);354 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcImport *>(inst));
360 case IrInstSrcIdRef:355 case IrInstSrcIdRef:
361 return destroy(reinterpret_cast<IrInstSrcRef *>(inst), name);356 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcRef *>(inst));
362 case IrInstSrcIdCompileErr:357 case IrInstSrcIdCompileErr:
363 return destroy(reinterpret_cast<IrInstSrcCompileErr *>(inst), name);358 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcCompileErr *>(inst));
364 case IrInstSrcIdCompileLog:359 case IrInstSrcIdCompileLog:
365 return destroy(reinterpret_cast<IrInstSrcCompileLog *>(inst), name);360 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcCompileLog *>(inst));
366 case IrInstSrcIdErrName:361 case IrInstSrcIdErrName:
367 return destroy(reinterpret_cast<IrInstSrcErrName *>(inst), name);362 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcErrName *>(inst));
368 case IrInstSrcIdCImport:363 case IrInstSrcIdCImport:
369 return destroy(reinterpret_cast<IrInstSrcCImport *>(inst), name);364 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcCImport *>(inst));
370 case IrInstSrcIdCInclude:365 case IrInstSrcIdCInclude:
371 return destroy(reinterpret_cast<IrInstSrcCInclude *>(inst), name);366 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcCInclude *>(inst));
372 case IrInstSrcIdCDefine:367 case IrInstSrcIdCDefine:
373 return destroy(reinterpret_cast<IrInstSrcCDefine *>(inst), name);368 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcCDefine *>(inst));
374 case IrInstSrcIdCUndef:369 case IrInstSrcIdCUndef:
375 return destroy(reinterpret_cast<IrInstSrcCUndef *>(inst), name);370 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcCUndef *>(inst));
376 case IrInstSrcIdEmbedFile:371 case IrInstSrcIdEmbedFile:
377 return destroy(reinterpret_cast<IrInstSrcEmbedFile *>(inst), name);372 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcEmbedFile *>(inst));
378 case IrInstSrcIdCmpxchg:373 case IrInstSrcIdCmpxchg:
379 return destroy(reinterpret_cast<IrInstSrcCmpxchg *>(inst), name);374 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcCmpxchg *>(inst));
380 case IrInstSrcIdFence:375 case IrInstSrcIdFence:
381 return destroy(reinterpret_cast<IrInstSrcFence *>(inst), name);376 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFence *>(inst));
382 case IrInstSrcIdTruncate:377 case IrInstSrcIdTruncate:
383 return destroy(reinterpret_cast<IrInstSrcTruncate *>(inst), name);378 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcTruncate *>(inst));
384 case IrInstSrcIdIntCast:379 case IrInstSrcIdIntCast:
385 return destroy(reinterpret_cast<IrInstSrcIntCast *>(inst), name);380 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcIntCast *>(inst));
386 case IrInstSrcIdFloatCast:381 case IrInstSrcIdFloatCast:
387 return destroy(reinterpret_cast<IrInstSrcFloatCast *>(inst), name);382 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFloatCast *>(inst));
388 case IrInstSrcIdErrSetCast:383 case IrInstSrcIdErrSetCast:
389 return destroy(reinterpret_cast<IrInstSrcErrSetCast *>(inst), name);384 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcErrSetCast *>(inst));
390 case IrInstSrcIdFromBytes:385 case IrInstSrcIdFromBytes:
391 return destroy(reinterpret_cast<IrInstSrcFromBytes *>(inst), name);386 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFromBytes *>(inst));
392 case IrInstSrcIdToBytes:387 case IrInstSrcIdToBytes:
393 return destroy(reinterpret_cast<IrInstSrcToBytes *>(inst), name);388 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcToBytes *>(inst));
394 case IrInstSrcIdIntToFloat:389 case IrInstSrcIdIntToFloat:
395 return destroy(reinterpret_cast<IrInstSrcIntToFloat *>(inst), name);390 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcIntToFloat *>(inst));
396 case IrInstSrcIdFloatToInt:391 case IrInstSrcIdFloatToInt:
397 return destroy(reinterpret_cast<IrInstSrcFloatToInt *>(inst), name);392 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFloatToInt *>(inst));
398 case IrInstSrcIdBoolToInt:393 case IrInstSrcIdBoolToInt:
399 return destroy(reinterpret_cast<IrInstSrcBoolToInt *>(inst), name);394 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcBoolToInt *>(inst));
400 case IrInstSrcIdIntType:395 case IrInstSrcIdIntType:
401 return destroy(reinterpret_cast<IrInstSrcIntType *>(inst), name);396 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcIntType *>(inst));
402 case IrInstSrcIdVectorType:397 case IrInstSrcIdVectorType:
403 return destroy(reinterpret_cast<IrInstSrcVectorType *>(inst), name);398 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcVectorType *>(inst));
404 case IrInstSrcIdShuffleVector:399 case IrInstSrcIdShuffleVector:
405 return destroy(reinterpret_cast<IrInstSrcShuffleVector *>(inst), name);400 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcShuffleVector *>(inst));
406 case IrInstSrcIdSplat:401 case IrInstSrcIdSplat:
407 return destroy(reinterpret_cast<IrInstSrcSplat *>(inst), name);402 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSplat *>(inst));
408 case IrInstSrcIdBoolNot:403 case IrInstSrcIdBoolNot:
409 return destroy(reinterpret_cast<IrInstSrcBoolNot *>(inst), name);404 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcBoolNot *>(inst));
410 case IrInstSrcIdMemset:405 case IrInstSrcIdMemset:
411 return destroy(reinterpret_cast<IrInstSrcMemset *>(inst), name);406 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcMemset *>(inst));
412 case IrInstSrcIdMemcpy:407 case IrInstSrcIdMemcpy:
413 return destroy(reinterpret_cast<IrInstSrcMemcpy *>(inst), name);408 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcMemcpy *>(inst));
414 case IrInstSrcIdSlice:409 case IrInstSrcIdSlice:
415 return destroy(reinterpret_cast<IrInstSrcSlice *>(inst), name);410 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSlice *>(inst));
416 case IrInstSrcIdMemberCount:411 case IrInstSrcIdMemberCount:
417 return destroy(reinterpret_cast<IrInstSrcMemberCount *>(inst), name);412 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcMemberCount *>(inst));
418 case IrInstSrcIdMemberType:413 case IrInstSrcIdMemberType:
419 return destroy(reinterpret_cast<IrInstSrcMemberType *>(inst), name);414 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcMemberType *>(inst));
420 case IrInstSrcIdMemberName:415 case IrInstSrcIdMemberName:
421 return destroy(reinterpret_cast<IrInstSrcMemberName *>(inst), name);416 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcMemberName *>(inst));
422 case IrInstSrcIdBreakpoint:417 case IrInstSrcIdBreakpoint:
423 return destroy(reinterpret_cast<IrInstSrcBreakpoint *>(inst), name);418 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcBreakpoint *>(inst));
424 case IrInstSrcIdReturnAddress:419 case IrInstSrcIdReturnAddress:
425 return destroy(reinterpret_cast<IrInstSrcReturnAddress *>(inst), name);420 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcReturnAddress *>(inst));
426 case IrInstSrcIdFrameAddress:421 case IrInstSrcIdFrameAddress:
427 return destroy(reinterpret_cast<IrInstSrcFrameAddress *>(inst), name);422 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFrameAddress *>(inst));
428 case IrInstSrcIdFrameHandle:423 case IrInstSrcIdFrameHandle:
429 return destroy(reinterpret_cast<IrInstSrcFrameHandle *>(inst), name);424 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFrameHandle *>(inst));
430 case IrInstSrcIdFrameType:425 case IrInstSrcIdFrameType:
431 return destroy(reinterpret_cast<IrInstSrcFrameType *>(inst), name);426 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFrameType *>(inst));
432 case IrInstSrcIdFrameSize:427 case IrInstSrcIdFrameSize:
433 return destroy(reinterpret_cast<IrInstSrcFrameSize *>(inst), name);428 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFrameSize *>(inst));
434 case IrInstSrcIdAlignOf:429 case IrInstSrcIdAlignOf:
435 return destroy(reinterpret_cast<IrInstSrcAlignOf *>(inst), name);430 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcAlignOf *>(inst));
436 case IrInstSrcIdOverflowOp:431 case IrInstSrcIdOverflowOp:
437 return destroy(reinterpret_cast<IrInstSrcOverflowOp *>(inst), name);432 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcOverflowOp *>(inst));
438 case IrInstSrcIdTestErr:433 case IrInstSrcIdTestErr:
439 return destroy(reinterpret_cast<IrInstSrcTestErr *>(inst), name);434 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcTestErr *>(inst));
440 case IrInstSrcIdUnwrapErrCode:435 case IrInstSrcIdUnwrapErrCode:
441 return destroy(reinterpret_cast<IrInstSrcUnwrapErrCode *>(inst), name);436 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcUnwrapErrCode *>(inst));
442 case IrInstSrcIdUnwrapErrPayload:437 case IrInstSrcIdUnwrapErrPayload:
443 return destroy(reinterpret_cast<IrInstSrcUnwrapErrPayload *>(inst), name);438 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcUnwrapErrPayload *>(inst));
444 case IrInstSrcIdFnProto:439 case IrInstSrcIdFnProto:
445 return destroy(reinterpret_cast<IrInstSrcFnProto *>(inst), name);440 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFnProto *>(inst));
446 case IrInstSrcIdTestComptime:441 case IrInstSrcIdTestComptime:
447 return destroy(reinterpret_cast<IrInstSrcTestComptime *>(inst), name);442 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcTestComptime *>(inst));
448 case IrInstSrcIdPtrCast:443 case IrInstSrcIdPtrCast:
449 return destroy(reinterpret_cast<IrInstSrcPtrCast *>(inst), name);444 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcPtrCast *>(inst));
450 case IrInstSrcIdBitCast:445 case IrInstSrcIdBitCast:
451 return destroy(reinterpret_cast<IrInstSrcBitCast *>(inst), name);446 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcBitCast *>(inst));
452 case IrInstSrcIdPtrToInt:447 case IrInstSrcIdPtrToInt:
453 return destroy(reinterpret_cast<IrInstSrcPtrToInt *>(inst), name);448 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcPtrToInt *>(inst));
454 case IrInstSrcIdIntToPtr:449 case IrInstSrcIdIntToPtr:
455 return destroy(reinterpret_cast<IrInstSrcIntToPtr *>(inst), name);450 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcIntToPtr *>(inst));
456 case IrInstSrcIdIntToEnum:451 case IrInstSrcIdIntToEnum:
457 return destroy(reinterpret_cast<IrInstSrcIntToEnum *>(inst), name);452 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcIntToEnum *>(inst));
458 case IrInstSrcIdIntToErr:453 case IrInstSrcIdIntToErr:
459 return destroy(reinterpret_cast<IrInstSrcIntToErr *>(inst), name);454 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcIntToErr *>(inst));
460 case IrInstSrcIdErrToInt:455 case IrInstSrcIdErrToInt:
461 return destroy(reinterpret_cast<IrInstSrcErrToInt *>(inst), name);456 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcErrToInt *>(inst));
462 case IrInstSrcIdCheckSwitchProngs:457 case IrInstSrcIdCheckSwitchProngs:
463 return destroy(reinterpret_cast<IrInstSrcCheckSwitchProngs *>(inst), name);458 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcCheckSwitchProngs *>(inst));
464 case IrInstSrcIdCheckStatementIsVoid:459 case IrInstSrcIdCheckStatementIsVoid:
465 return destroy(reinterpret_cast<IrInstSrcCheckStatementIsVoid *>(inst), name);460 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcCheckStatementIsVoid *>(inst));
466 case IrInstSrcIdTypeName:461 case IrInstSrcIdTypeName:
467 return destroy(reinterpret_cast<IrInstSrcTypeName *>(inst), name);462 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcTypeName *>(inst));
468 case IrInstSrcIdTagName:463 case IrInstSrcIdTagName:
469 return destroy(reinterpret_cast<IrInstSrcTagName *>(inst), name);464 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcTagName *>(inst));
470 case IrInstSrcIdPtrType:465 case IrInstSrcIdPtrType:
471 return destroy(reinterpret_cast<IrInstSrcPtrType *>(inst), name);466 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcPtrType *>(inst));
472 case IrInstSrcIdDeclRef:467 case IrInstSrcIdDeclRef:
473 return destroy(reinterpret_cast<IrInstSrcDeclRef *>(inst), name);468 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcDeclRef *>(inst));
474 case IrInstSrcIdPanic:469 case IrInstSrcIdPanic:
475 return destroy(reinterpret_cast<IrInstSrcPanic *>(inst), name);470 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcPanic *>(inst));
476 case IrInstSrcIdFieldParentPtr:471 case IrInstSrcIdFieldParentPtr:
477 return destroy(reinterpret_cast<IrInstSrcFieldParentPtr *>(inst), name);472 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFieldParentPtr *>(inst));
478 case IrInstSrcIdByteOffsetOf:473 case IrInstSrcIdByteOffsetOf:
479 return destroy(reinterpret_cast<IrInstSrcByteOffsetOf *>(inst), name);474 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcByteOffsetOf *>(inst));
480 case IrInstSrcIdBitOffsetOf:475 case IrInstSrcIdBitOffsetOf:
481 return destroy(reinterpret_cast<IrInstSrcBitOffsetOf *>(inst), name);476 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcBitOffsetOf *>(inst));
482 case IrInstSrcIdTypeInfo:477 case IrInstSrcIdTypeInfo:
483 return destroy(reinterpret_cast<IrInstSrcTypeInfo *>(inst), name);478 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcTypeInfo *>(inst));
484 case IrInstSrcIdType:479 case IrInstSrcIdType:
485 return destroy(reinterpret_cast<IrInstSrcType *>(inst), name);480 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcType *>(inst));
486 case IrInstSrcIdHasField:481 case IrInstSrcIdHasField:
487 return destroy(reinterpret_cast<IrInstSrcHasField *>(inst), name);482 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcHasField *>(inst));
488 case IrInstSrcIdTypeId:483 case IrInstSrcIdTypeId:
489 return destroy(reinterpret_cast<IrInstSrcTypeId *>(inst), name);484 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcTypeId *>(inst));
490 case IrInstSrcIdSetEvalBranchQuota:485 case IrInstSrcIdSetEvalBranchQuota:
491 return destroy(reinterpret_cast<IrInstSrcSetEvalBranchQuota *>(inst), name);486 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSetEvalBranchQuota *>(inst));
492 case IrInstSrcIdAlignCast:487 case IrInstSrcIdAlignCast:
493 return destroy(reinterpret_cast<IrInstSrcAlignCast *>(inst), name);488 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcAlignCast *>(inst));
494 case IrInstSrcIdImplicitCast:489 case IrInstSrcIdImplicitCast:
495 return destroy(reinterpret_cast<IrInstSrcImplicitCast *>(inst), name);490 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcImplicitCast *>(inst));
496 case IrInstSrcIdResolveResult:491 case IrInstSrcIdResolveResult:
497 return destroy(reinterpret_cast<IrInstSrcResolveResult *>(inst), name);492 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcResolveResult *>(inst));
498 case IrInstSrcIdResetResult:493 case IrInstSrcIdResetResult:
499 return destroy(reinterpret_cast<IrInstSrcResetResult *>(inst), name);494 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcResetResult *>(inst));
500 case IrInstSrcIdOpaqueType:495 case IrInstSrcIdOpaqueType:
501 return destroy(reinterpret_cast<IrInstSrcOpaqueType *>(inst), name);496 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcOpaqueType *>(inst));
502 case IrInstSrcIdSetAlignStack:497 case IrInstSrcIdSetAlignStack:
503 return destroy(reinterpret_cast<IrInstSrcSetAlignStack *>(inst), name);498 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSetAlignStack *>(inst));
504 case IrInstSrcIdArgType:499 case IrInstSrcIdArgType:
505 return destroy(reinterpret_cast<IrInstSrcArgType *>(inst), name);500 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcArgType *>(inst));
506 case IrInstSrcIdTagType:501 case IrInstSrcIdTagType:
507 return destroy(reinterpret_cast<IrInstSrcTagType *>(inst), name);502 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcTagType *>(inst));
508 case IrInstSrcIdExport:503 case IrInstSrcIdExport:
509 return destroy(reinterpret_cast<IrInstSrcExport *>(inst), name);504 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcExport *>(inst));
510 case IrInstSrcIdErrorReturnTrace:505 case IrInstSrcIdErrorReturnTrace:
511 return destroy(reinterpret_cast<IrInstSrcErrorReturnTrace *>(inst), name);506 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcErrorReturnTrace *>(inst));
512 case IrInstSrcIdErrorUnion:507 case IrInstSrcIdErrorUnion:
513 return destroy(reinterpret_cast<IrInstSrcErrorUnion *>(inst), name);508 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcErrorUnion *>(inst));
514 case IrInstSrcIdAtomicRmw:509 case IrInstSrcIdAtomicRmw:
515 return destroy(reinterpret_cast<IrInstSrcAtomicRmw *>(inst), name);510 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcAtomicRmw *>(inst));
516 case IrInstSrcIdSaveErrRetAddr:511 case IrInstSrcIdSaveErrRetAddr:
517 return destroy(reinterpret_cast<IrInstSrcSaveErrRetAddr *>(inst), name);512 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSaveErrRetAddr *>(inst));
518 case IrInstSrcIdAddImplicitReturnType:513 case IrInstSrcIdAddImplicitReturnType:
519 return destroy(reinterpret_cast<IrInstSrcAddImplicitReturnType *>(inst), name);514 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcAddImplicitReturnType *>(inst));
520 case IrInstSrcIdFloatOp:515 case IrInstSrcIdFloatOp:
521 return destroy(reinterpret_cast<IrInstSrcFloatOp *>(inst), name);516 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcFloatOp *>(inst));
522 case IrInstSrcIdMulAdd:517 case IrInstSrcIdMulAdd:
523 return destroy(reinterpret_cast<IrInstSrcMulAdd *>(inst), name);518 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcMulAdd *>(inst));
524 case IrInstSrcIdAtomicLoad:519 case IrInstSrcIdAtomicLoad:
525 return destroy(reinterpret_cast<IrInstSrcAtomicLoad *>(inst), name);520 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcAtomicLoad *>(inst));
526 case IrInstSrcIdAtomicStore:521 case IrInstSrcIdAtomicStore:
527 return destroy(reinterpret_cast<IrInstSrcAtomicStore *>(inst), name);522 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcAtomicStore *>(inst));
528 case IrInstSrcIdEnumToInt:523 case IrInstSrcIdEnumToInt:
529 return destroy(reinterpret_cast<IrInstSrcEnumToInt *>(inst), name);524 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcEnumToInt *>(inst));
530 case IrInstSrcIdCheckRuntimeScope:525 case IrInstSrcIdCheckRuntimeScope:
531 return destroy(reinterpret_cast<IrInstSrcCheckRuntimeScope *>(inst), name);526 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcCheckRuntimeScope *>(inst));
532 case IrInstSrcIdHasDecl:527 case IrInstSrcIdHasDecl:
533 return destroy(reinterpret_cast<IrInstSrcHasDecl *>(inst), name);528 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcHasDecl *>(inst));
534 case IrInstSrcIdUndeclaredIdent:529 case IrInstSrcIdUndeclaredIdent:
535 return destroy(reinterpret_cast<IrInstSrcUndeclaredIdent *>(inst), name);530 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcUndeclaredIdent *>(inst));
536 case IrInstSrcIdAlloca:531 case IrInstSrcIdAlloca:
537 return destroy(reinterpret_cast<IrInstSrcAlloca *>(inst), name);532 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcAlloca *>(inst));
538 case IrInstSrcIdEndExpr:533 case IrInstSrcIdEndExpr:
539 return destroy(reinterpret_cast<IrInstSrcEndExpr *>(inst), name);534 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcEndExpr *>(inst));
540 case IrInstSrcIdUnionInitNamedField:535 case IrInstSrcIdUnionInitNamedField:
541 return destroy(reinterpret_cast<IrInstSrcUnionInitNamedField *>(inst), name);536 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcUnionInitNamedField *>(inst));
542 case IrInstSrcIdSuspendBegin:537 case IrInstSrcIdSuspendBegin:
543 return destroy(reinterpret_cast<IrInstSrcSuspendBegin *>(inst), name);538 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSuspendBegin *>(inst));
544 case IrInstSrcIdSuspendFinish:539 case IrInstSrcIdSuspendFinish:
545 return destroy(reinterpret_cast<IrInstSrcSuspendFinish *>(inst), name);540 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSuspendFinish *>(inst));
546 case IrInstSrcIdResume:541 case IrInstSrcIdResume:
547 return destroy(reinterpret_cast<IrInstSrcResume *>(inst), name);542 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcResume *>(inst));
548 case IrInstSrcIdAwait:543 case IrInstSrcIdAwait:
549 return destroy(reinterpret_cast<IrInstSrcAwait *>(inst), name);544 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcAwait *>(inst));
550 case IrInstSrcIdSpillBegin:545 case IrInstSrcIdSpillBegin:
551 return destroy(reinterpret_cast<IrInstSrcSpillBegin *>(inst), name);546 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSpillBegin *>(inst));
552 case IrInstSrcIdSpillEnd:547 case IrInstSrcIdSpillEnd:
553 return destroy(reinterpret_cast<IrInstSrcSpillEnd *>(inst), name);548 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcSpillEnd *>(inst));
554 case IrInstSrcIdCallArgs:549 case IrInstSrcIdCallArgs:
555 return destroy(reinterpret_cast<IrInstSrcCallArgs *>(inst), name);550 return heap::c_allocator.destroy(reinterpret_cast<IrInstSrcCallArgs *>(inst));
556 }551 }
557 zig_unreachable();552 zig_unreachable();
558}553}
559554
560void destroy_instruction_gen(IrInstGen *inst) {555void 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
566 switch (inst->id) {556 switch (inst->id) {
567 case IrInstGenIdInvalid:557 case IrInstGenIdInvalid:
568 zig_unreachable();558 zig_unreachable();
569 case IrInstGenIdReturn:559 case IrInstGenIdReturn:
570 return destroy(reinterpret_cast<IrInstGenReturn *>(inst), name);560 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenReturn *>(inst));
571 case IrInstGenIdConst:561 case IrInstGenIdConst:
572 return destroy(reinterpret_cast<IrInstGenConst *>(inst), name);562 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenConst *>(inst));
573 case IrInstGenIdBinOp:563 case IrInstGenIdBinOp:
574 return destroy(reinterpret_cast<IrInstGenBinOp *>(inst), name);564 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenBinOp *>(inst));
575 case IrInstGenIdCast:565 case IrInstGenIdCast:
576 return destroy(reinterpret_cast<IrInstGenCast *>(inst), name);566 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenCast *>(inst));
577 case IrInstGenIdCall:567 case IrInstGenIdCall:
578 return destroy(reinterpret_cast<IrInstGenCall *>(inst), name);568 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenCall *>(inst));
579 case IrInstGenIdCondBr:569 case IrInstGenIdCondBr:
580 return destroy(reinterpret_cast<IrInstGenCondBr *>(inst), name);570 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenCondBr *>(inst));
581 case IrInstGenIdBr:571 case IrInstGenIdBr:
582 return destroy(reinterpret_cast<IrInstGenBr *>(inst), name);572 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenBr *>(inst));
583 case IrInstGenIdPhi:573 case IrInstGenIdPhi:
584 return destroy(reinterpret_cast<IrInstGenPhi *>(inst), name);574 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenPhi *>(inst));
585 case IrInstGenIdUnreachable:575 case IrInstGenIdUnreachable:
586 return destroy(reinterpret_cast<IrInstGenUnreachable *>(inst), name);576 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenUnreachable *>(inst));
587 case IrInstGenIdElemPtr:577 case IrInstGenIdElemPtr:
588 return destroy(reinterpret_cast<IrInstGenElemPtr *>(inst), name);578 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenElemPtr *>(inst));
589 case IrInstGenIdVarPtr:579 case IrInstGenIdVarPtr:
590 return destroy(reinterpret_cast<IrInstGenVarPtr *>(inst), name);580 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenVarPtr *>(inst));
591 case IrInstGenIdReturnPtr:581 case IrInstGenIdReturnPtr:
592 return destroy(reinterpret_cast<IrInstGenReturnPtr *>(inst), name);582 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenReturnPtr *>(inst));
593 case IrInstGenIdLoadPtr:583 case IrInstGenIdLoadPtr:
594 return destroy(reinterpret_cast<IrInstGenLoadPtr *>(inst), name);584 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenLoadPtr *>(inst));
595 case IrInstGenIdStorePtr:585 case IrInstGenIdStorePtr:
596 return destroy(reinterpret_cast<IrInstGenStorePtr *>(inst), name);586 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenStorePtr *>(inst));
597 case IrInstGenIdVectorStoreElem:587 case IrInstGenIdVectorStoreElem:
598 return destroy(reinterpret_cast<IrInstGenVectorStoreElem *>(inst), name);588 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenVectorStoreElem *>(inst));
599 case IrInstGenIdStructFieldPtr:589 case IrInstGenIdStructFieldPtr:
600 return destroy(reinterpret_cast<IrInstGenStructFieldPtr *>(inst), name);590 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenStructFieldPtr *>(inst));
601 case IrInstGenIdUnionFieldPtr:591 case IrInstGenIdUnionFieldPtr:
602 return destroy(reinterpret_cast<IrInstGenUnionFieldPtr *>(inst), name);592 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenUnionFieldPtr *>(inst));
603 case IrInstGenIdAsm:593 case IrInstGenIdAsm:
604 return destroy(reinterpret_cast<IrInstGenAsm *>(inst), name);594 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenAsm *>(inst));
605 case IrInstGenIdTestNonNull:595 case IrInstGenIdTestNonNull:
606 return destroy(reinterpret_cast<IrInstGenTestNonNull *>(inst), name);596 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenTestNonNull *>(inst));
607 case IrInstGenIdOptionalUnwrapPtr:597 case IrInstGenIdOptionalUnwrapPtr:
608 return destroy(reinterpret_cast<IrInstGenOptionalUnwrapPtr *>(inst), name);598 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenOptionalUnwrapPtr *>(inst));
609 case IrInstGenIdPopCount:599 case IrInstGenIdPopCount:
610 return destroy(reinterpret_cast<IrInstGenPopCount *>(inst), name);600 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenPopCount *>(inst));
611 case IrInstGenIdClz:601 case IrInstGenIdClz:
612 return destroy(reinterpret_cast<IrInstGenClz *>(inst), name);602 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenClz *>(inst));
613 case IrInstGenIdCtz:603 case IrInstGenIdCtz:
614 return destroy(reinterpret_cast<IrInstGenCtz *>(inst), name);604 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenCtz *>(inst));
615 case IrInstGenIdBswap:605 case IrInstGenIdBswap:
616 return destroy(reinterpret_cast<IrInstGenBswap *>(inst), name);606 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenBswap *>(inst));
617 case IrInstGenIdBitReverse:607 case IrInstGenIdBitReverse:
618 return destroy(reinterpret_cast<IrInstGenBitReverse *>(inst), name);608 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenBitReverse *>(inst));
619 case IrInstGenIdSwitchBr:609 case IrInstGenIdSwitchBr:
620 return destroy(reinterpret_cast<IrInstGenSwitchBr *>(inst), name);610 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenSwitchBr *>(inst));
621 case IrInstGenIdUnionTag:611 case IrInstGenIdUnionTag:
622 return destroy(reinterpret_cast<IrInstGenUnionTag *>(inst), name);612 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenUnionTag *>(inst));
623 case IrInstGenIdRef:613 case IrInstGenIdRef:
624 return destroy(reinterpret_cast<IrInstGenRef *>(inst), name);614 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenRef *>(inst));
625 case IrInstGenIdErrName:615 case IrInstGenIdErrName:
626 return destroy(reinterpret_cast<IrInstGenErrName *>(inst), name);616 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenErrName *>(inst));
627 case IrInstGenIdCmpxchg:617 case IrInstGenIdCmpxchg:
628 return destroy(reinterpret_cast<IrInstGenCmpxchg *>(inst), name);618 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenCmpxchg *>(inst));
629 case IrInstGenIdFence:619 case IrInstGenIdFence:
630 return destroy(reinterpret_cast<IrInstGenFence *>(inst), name);620 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenFence *>(inst));
631 case IrInstGenIdTruncate:621 case IrInstGenIdTruncate:
632 return destroy(reinterpret_cast<IrInstGenTruncate *>(inst), name);622 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenTruncate *>(inst));
633 case IrInstGenIdShuffleVector:623 case IrInstGenIdShuffleVector:
634 return destroy(reinterpret_cast<IrInstGenShuffleVector *>(inst), name);624 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenShuffleVector *>(inst));
635 case IrInstGenIdSplat:625 case IrInstGenIdSplat:
636 return destroy(reinterpret_cast<IrInstGenSplat *>(inst), name);626 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenSplat *>(inst));
637 case IrInstGenIdBoolNot:627 case IrInstGenIdBoolNot:
638 return destroy(reinterpret_cast<IrInstGenBoolNot *>(inst), name);628 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenBoolNot *>(inst));
639 case IrInstGenIdMemset:629 case IrInstGenIdMemset:
640 return destroy(reinterpret_cast<IrInstGenMemset *>(inst), name);630 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenMemset *>(inst));
641 case IrInstGenIdMemcpy:631 case IrInstGenIdMemcpy:
642 return destroy(reinterpret_cast<IrInstGenMemcpy *>(inst), name);632 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenMemcpy *>(inst));
643 case IrInstGenIdSlice:633 case IrInstGenIdSlice:
644 return destroy(reinterpret_cast<IrInstGenSlice *>(inst), name);634 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenSlice *>(inst));
645 case IrInstGenIdBreakpoint:635 case IrInstGenIdBreakpoint:
646 return destroy(reinterpret_cast<IrInstGenBreakpoint *>(inst), name);636 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenBreakpoint *>(inst));
647 case IrInstGenIdReturnAddress:637 case IrInstGenIdReturnAddress:
648 return destroy(reinterpret_cast<IrInstGenReturnAddress *>(inst), name);638 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenReturnAddress *>(inst));
649 case IrInstGenIdFrameAddress:639 case IrInstGenIdFrameAddress:
650 return destroy(reinterpret_cast<IrInstGenFrameAddress *>(inst), name);640 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenFrameAddress *>(inst));
651 case IrInstGenIdFrameHandle:641 case IrInstGenIdFrameHandle:
652 return destroy(reinterpret_cast<IrInstGenFrameHandle *>(inst), name);642 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenFrameHandle *>(inst));
653 case IrInstGenIdFrameSize:643 case IrInstGenIdFrameSize:
654 return destroy(reinterpret_cast<IrInstGenFrameSize *>(inst), name);644 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenFrameSize *>(inst));
655 case IrInstGenIdOverflowOp:645 case IrInstGenIdOverflowOp:
656 return destroy(reinterpret_cast<IrInstGenOverflowOp *>(inst), name);646 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenOverflowOp *>(inst));
657 case IrInstGenIdTestErr:647 case IrInstGenIdTestErr:
658 return destroy(reinterpret_cast<IrInstGenTestErr *>(inst), name);648 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenTestErr *>(inst));
659 case IrInstGenIdUnwrapErrCode:649 case IrInstGenIdUnwrapErrCode:
660 return destroy(reinterpret_cast<IrInstGenUnwrapErrCode *>(inst), name);650 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenUnwrapErrCode *>(inst));
661 case IrInstGenIdUnwrapErrPayload:651 case IrInstGenIdUnwrapErrPayload:
662 return destroy(reinterpret_cast<IrInstGenUnwrapErrPayload *>(inst), name);652 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenUnwrapErrPayload *>(inst));
663 case IrInstGenIdOptionalWrap:653 case IrInstGenIdOptionalWrap:
664 return destroy(reinterpret_cast<IrInstGenOptionalWrap *>(inst), name);654 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenOptionalWrap *>(inst));
665 case IrInstGenIdErrWrapCode:655 case IrInstGenIdErrWrapCode:
666 return destroy(reinterpret_cast<IrInstGenErrWrapCode *>(inst), name);656 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenErrWrapCode *>(inst));
667 case IrInstGenIdErrWrapPayload:657 case IrInstGenIdErrWrapPayload:
668 return destroy(reinterpret_cast<IrInstGenErrWrapPayload *>(inst), name);658 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenErrWrapPayload *>(inst));
669 case IrInstGenIdPtrCast:659 case IrInstGenIdPtrCast:
670 return destroy(reinterpret_cast<IrInstGenPtrCast *>(inst), name);660 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenPtrCast *>(inst));
671 case IrInstGenIdBitCast:661 case IrInstGenIdBitCast:
672 return destroy(reinterpret_cast<IrInstGenBitCast *>(inst), name);662 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenBitCast *>(inst));
673 case IrInstGenIdWidenOrShorten:663 case IrInstGenIdWidenOrShorten:
674 return destroy(reinterpret_cast<IrInstGenWidenOrShorten *>(inst), name);664 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenWidenOrShorten *>(inst));
675 case IrInstGenIdPtrToInt:665 case IrInstGenIdPtrToInt:
676 return destroy(reinterpret_cast<IrInstGenPtrToInt *>(inst), name);666 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenPtrToInt *>(inst));
677 case IrInstGenIdIntToPtr:667 case IrInstGenIdIntToPtr:
678 return destroy(reinterpret_cast<IrInstGenIntToPtr *>(inst), name);668 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenIntToPtr *>(inst));
679 case IrInstGenIdIntToEnum:669 case IrInstGenIdIntToEnum:
680 return destroy(reinterpret_cast<IrInstGenIntToEnum *>(inst), name);670 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenIntToEnum *>(inst));
681 case IrInstGenIdIntToErr:671 case IrInstGenIdIntToErr:
682 return destroy(reinterpret_cast<IrInstGenIntToErr *>(inst), name);672 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenIntToErr *>(inst));
683 case IrInstGenIdErrToInt:673 case IrInstGenIdErrToInt:
684 return destroy(reinterpret_cast<IrInstGenErrToInt *>(inst), name);674 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenErrToInt *>(inst));
685 case IrInstGenIdTagName:675 case IrInstGenIdTagName:
686 return destroy(reinterpret_cast<IrInstGenTagName *>(inst), name);676 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenTagName *>(inst));
687 case IrInstGenIdPanic:677 case IrInstGenIdPanic:
688 return destroy(reinterpret_cast<IrInstGenPanic *>(inst), name);678 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenPanic *>(inst));
689 case IrInstGenIdFieldParentPtr:679 case IrInstGenIdFieldParentPtr:
690 return destroy(reinterpret_cast<IrInstGenFieldParentPtr *>(inst), name);680 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenFieldParentPtr *>(inst));
691 case IrInstGenIdAlignCast:681 case IrInstGenIdAlignCast:
692 return destroy(reinterpret_cast<IrInstGenAlignCast *>(inst), name);682 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenAlignCast *>(inst));
693 case IrInstGenIdErrorReturnTrace:683 case IrInstGenIdErrorReturnTrace:
694 return destroy(reinterpret_cast<IrInstGenErrorReturnTrace *>(inst), name);684 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenErrorReturnTrace *>(inst));
695 case IrInstGenIdAtomicRmw:685 case IrInstGenIdAtomicRmw:
696 return destroy(reinterpret_cast<IrInstGenAtomicRmw *>(inst), name);686 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenAtomicRmw *>(inst));
697 case IrInstGenIdSaveErrRetAddr:687 case IrInstGenIdSaveErrRetAddr:
698 return destroy(reinterpret_cast<IrInstGenSaveErrRetAddr *>(inst), name);688 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenSaveErrRetAddr *>(inst));
699 case IrInstGenIdFloatOp:689 case IrInstGenIdFloatOp:
700 return destroy(reinterpret_cast<IrInstGenFloatOp *>(inst), name);690 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenFloatOp *>(inst));
701 case IrInstGenIdMulAdd:691 case IrInstGenIdMulAdd:
702 return destroy(reinterpret_cast<IrInstGenMulAdd *>(inst), name);692 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenMulAdd *>(inst));
703 case IrInstGenIdAtomicLoad:693 case IrInstGenIdAtomicLoad:
704 return destroy(reinterpret_cast<IrInstGenAtomicLoad *>(inst), name);694 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenAtomicLoad *>(inst));
705 case IrInstGenIdAtomicStore:695 case IrInstGenIdAtomicStore:
706 return destroy(reinterpret_cast<IrInstGenAtomicStore *>(inst), name);696 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenAtomicStore *>(inst));
707 case IrInstGenIdDeclVar:697 case IrInstGenIdDeclVar:
708 return destroy(reinterpret_cast<IrInstGenDeclVar *>(inst), name);698 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenDeclVar *>(inst));
709 case IrInstGenIdArrayToVector:699 case IrInstGenIdArrayToVector:
710 return destroy(reinterpret_cast<IrInstGenArrayToVector *>(inst), name);700 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenArrayToVector *>(inst));
711 case IrInstGenIdVectorToArray:701 case IrInstGenIdVectorToArray:
712 return destroy(reinterpret_cast<IrInstGenVectorToArray *>(inst), name);702 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenVectorToArray *>(inst));
713 case IrInstGenIdPtrOfArrayToSlice:703 case IrInstGenIdPtrOfArrayToSlice:
714 return destroy(reinterpret_cast<IrInstGenPtrOfArrayToSlice *>(inst), name);704 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenPtrOfArrayToSlice *>(inst));
715 case IrInstGenIdAssertZero:705 case IrInstGenIdAssertZero:
716 return destroy(reinterpret_cast<IrInstGenAssertZero *>(inst), name);706 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenAssertZero *>(inst));
717 case IrInstGenIdAssertNonNull:707 case IrInstGenIdAssertNonNull:
718 return destroy(reinterpret_cast<IrInstGenAssertNonNull *>(inst), name);708 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenAssertNonNull *>(inst));
719 case IrInstGenIdResizeSlice:709 case IrInstGenIdResizeSlice:
720 return destroy(reinterpret_cast<IrInstGenResizeSlice *>(inst), name);710 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenResizeSlice *>(inst));
721 case IrInstGenIdAlloca:711 case IrInstGenIdAlloca:
722 return destroy(reinterpret_cast<IrInstGenAlloca *>(inst), name);712 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenAlloca *>(inst));
723 case IrInstGenIdSuspendBegin:713 case IrInstGenIdSuspendBegin:
724 return destroy(reinterpret_cast<IrInstGenSuspendBegin *>(inst), name);714 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenSuspendBegin *>(inst));
725 case IrInstGenIdSuspendFinish:715 case IrInstGenIdSuspendFinish:
726 return destroy(reinterpret_cast<IrInstGenSuspendFinish *>(inst), name);716 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenSuspendFinish *>(inst));
727 case IrInstGenIdResume:717 case IrInstGenIdResume:
728 return destroy(reinterpret_cast<IrInstGenResume *>(inst), name);718 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenResume *>(inst));
729 case IrInstGenIdAwait:719 case IrInstGenIdAwait:
730 return destroy(reinterpret_cast<IrInstGenAwait *>(inst), name);720 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenAwait *>(inst));
731 case IrInstGenIdSpillBegin:721 case IrInstGenIdSpillBegin:
732 return destroy(reinterpret_cast<IrInstGenSpillBegin *>(inst), name);722 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenSpillBegin *>(inst));
733 case IrInstGenIdSpillEnd:723 case IrInstGenIdSpillEnd:
734 return destroy(reinterpret_cast<IrInstGenSpillEnd *>(inst), name);724 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenSpillEnd *>(inst));
735 case IrInstGenIdVectorExtractElem:725 case IrInstGenIdVectorExtractElem:
736 return destroy(reinterpret_cast<IrInstGenVectorExtractElem *>(inst), name);726 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenVectorExtractElem *>(inst));
737 case IrInstGenIdBinaryNot:727 case IrInstGenIdBinaryNot:
738 return destroy(reinterpret_cast<IrInstGenBinaryNot *>(inst), name);728 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenBinaryNot *>(inst));
739 case IrInstGenIdNegation:729 case IrInstGenIdNegation:
740 return destroy(reinterpret_cast<IrInstGenNegation *>(inst), name);730 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenNegation *>(inst));
741 case IrInstGenIdNegationWrapping:731 case IrInstGenIdNegationWrapping:
742 return destroy(reinterpret_cast<IrInstGenNegationWrapping *>(inst), name);732 return heap::c_allocator.destroy(reinterpret_cast<IrInstGenNegationWrapping *>(inst));
743 }733 }
744 zig_unreachable();734 zig_unreachable();
745}735}
...@@ -760,15 +750,14 @@ static void ira_deref(IrAnalyze *ira) {...@@ -760,15 +750,14 @@ static void ira_deref(IrAnalyze *ira) {
760 IrInstSrc *pass1_inst = pass1_bb->instruction_list.items[inst_i];750 IrInstSrc *pass1_inst = pass1_bb->instruction_list.items[inst_i];
761 destroy_instruction_src(pass1_inst);751 destroy_instruction_src(pass1_inst);
762 }752 }
763 destroy(pass1_bb, "IrBasicBlockSrc");753 heap::c_allocator.destroy(pass1_bb);
764 }754 }
765 ira->old_irb.exec->basic_block_list.deinit();755 ira->old_irb.exec->basic_block_list.deinit();
766 ira->old_irb.exec->tld_list.deinit();756 ira->old_irb.exec->tld_list.deinit();
767 // cannot destroy here because of var->owner_exec757 heap::c_allocator.destroy(ira->old_irb.exec);
768 //destroy(ira->old_irb.exec, "IrExecutableSrc");
769 ira->src_implicit_return_type_list.deinit();758 ira->src_implicit_return_type_list.deinit();
770 ira->resume_stack.deinit();759 ira->resume_stack.deinit();
771 destroy(ira, "IrAnalyze");760 heap::c_allocator.destroy(ira);
772}761}
773762
774static ZigValue *const_ptr_pointee_unchecked_no_isf(CodeGen *g, ZigValue *const_val) {763static ZigValue *const_ptr_pointee_unchecked_no_isf(CodeGen *g, ZigValue *const_val) {
...@@ -1017,8 +1006,8 @@ static void ir_ref_var(ZigVar *var) {...@@ -1017,8 +1006,8 @@ static void ir_ref_var(ZigVar *var) {
1017static void create_result_ptr(CodeGen *codegen, ZigType *expected_type,1006static void create_result_ptr(CodeGen *codegen, ZigType *expected_type,
1018 ZigValue **out_result, ZigValue **out_result_ptr)1007 ZigValue **out_result, ZigValue **out_result_ptr)
1019{1008{
1020 ZigValue *result = create_const_vals(1);1009 ZigValue *result = codegen->pass1_arena->create<ZigValue>();
1021 ZigValue *result_ptr = create_const_vals(1);1010 ZigValue *result_ptr = codegen->pass1_arena->create<ZigValue>();
1022 result->special = ConstValSpecialUndef;1011 result->special = ConstValSpecialUndef;
1023 result->type = expected_type;1012 result->type = expected_type;
1024 result_ptr->special = ConstValSpecialStatic;1013 result_ptr->special = ConstValSpecialStatic;
...@@ -1050,14 +1039,11 @@ ZigType *ir_analyze_type_expr(IrAnalyze *ira, Scope *scope, AstNode *node) {...@@ -1050,14 +1039,11 @@ ZigType *ir_analyze_type_expr(IrAnalyze *ira, Scope *scope, AstNode *node) {
1050 assert(result->special != ConstValSpecialRuntime);1039 assert(result->special != ConstValSpecialRuntime);
1051 ZigType *res_type = result->data.x_type;1040 ZigType *res_type = result->data.x_type;
10521041
1053 destroy(result_ptr, "ZigValue");
1054 destroy(result, "ZigValue");
1055
1056 return res_type;1042 return res_type;
1057}1043}
10581044
1059static IrBasicBlockSrc *ir_create_basic_block(IrBuilderSrc *irb, Scope *scope, const char *name_hint) {1045static 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>();
1061 result->scope = scope;1047 result->scope = scope;
1062 result->name_hint = name_hint;1048 result->name_hint = name_hint;
1063 result->debug_id = exec_next_debug_id(irb->exec);1049 result->debug_id = exec_next_debug_id(irb->exec);
...@@ -1066,7 +1052,7 @@ static IrBasicBlockSrc *ir_create_basic_block(IrBuilderSrc *irb, Scope *scope, c...@@ -1066,7 +1052,7 @@ static IrBasicBlockSrc *ir_create_basic_block(IrBuilderSrc *irb, Scope *scope, c
1066}1052}
10671053
1068static IrBasicBlockGen *ir_create_basic_block_gen(IrAnalyze *ira, Scope *scope, const char *name_hint) {1054static 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>();
1070 result->scope = scope;1056 result->scope = scope;
1071 result->name_hint = name_hint;1057 result->name_hint = name_hint;
1072 result->debug_id = exec_next_debug_id_gen(ira->new_irb.exec);1058 result->debug_id = exec_next_debug_id_gen(ira->new_irb.exec);
...@@ -1983,12 +1969,7 @@ static constexpr IrInstGenId ir_inst_id(IrInstGenConst *) {...@@ -1983,12 +1969,7 @@ static constexpr IrInstGenId ir_inst_id(IrInstGenConst *) {
19831969
1984template<typename T>1970template<typename T>
1985static T *ir_create_instruction(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {1971static T *ir_create_instruction(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
1986 const char *name = nullptr;1972 T *special_instruction = heap::c_allocator.create<T>();
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);
1992 special_instruction->base.id = ir_inst_id(special_instruction);1973 special_instruction->base.id = ir_inst_id(special_instruction);
1993 special_instruction->base.base.scope = scope;1974 special_instruction->base.base.scope = scope;
1994 special_instruction->base.base.source_node = source_node;1975 special_instruction->base.base.source_node = source_node;
...@@ -1999,29 +1980,19 @@ static T *ir_create_instruction(IrBuilderSrc *irb, Scope *scope, AstNode *source...@@ -1999,29 +1980,19 @@ static T *ir_create_instruction(IrBuilderSrc *irb, Scope *scope, AstNode *source
19991980
2000template<typename T>1981template<typename T>
2001static T *ir_create_inst_gen(IrBuilderGen *irb, Scope *scope, AstNode *source_node) {1982static T *ir_create_inst_gen(IrBuilderGen *irb, Scope *scope, AstNode *source_node) {
2002 const char *name = nullptr;1983 T *special_instruction = heap::c_allocator.create<T>();
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);
2008 special_instruction->base.id = ir_inst_id(special_instruction);1984 special_instruction->base.id = ir_inst_id(special_instruction);
2009 special_instruction->base.base.scope = scope;1985 special_instruction->base.base.scope = scope;
2010 special_instruction->base.base.source_node = source_node;1986 special_instruction->base.base.source_node = source_node;
2011 special_instruction->base.base.debug_id = exec_next_debug_id_gen(irb->exec);1987 special_instruction->base.base.debug_id = exec_next_debug_id_gen(irb->exec);
2012 special_instruction->base.owner_bb = irb->current_basic_block;1988 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>();
2014 return special_instruction;1990 return special_instruction;
2015}1991}
20161992
2017template<typename T>1993template<typename T>
2018static T *ir_create_inst_noval(IrBuilderGen *irb, Scope *scope, AstNode *source_node) {1994static T *ir_create_inst_noval(IrBuilderGen *irb, Scope *scope, AstNode *source_node) {
2019 const char *name = nullptr;1995 T *special_instruction = heap::c_allocator.create<T>();
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);
2025 special_instruction->base.id = ir_inst_id(special_instruction);1996 special_instruction->base.id = ir_inst_id(special_instruction);
2026 special_instruction->base.base.scope = scope;1997 special_instruction->base.base.scope = scope;
2027 special_instruction->base.base.source_node = source_node;1998 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...@@ -2063,11 +2034,11 @@ static T *ir_build_inst_void(IrBuilderGen *irb, Scope *scope, AstNode *source_no
2063IrInstGen *ir_create_alloca(CodeGen *g, Scope *scope, AstNode *source_node, ZigFn *fn,2034IrInstGen *ir_create_alloca(CodeGen *g, Scope *scope, AstNode *source_node, ZigFn *fn,
2064 ZigType *var_type, const char *name_hint)2035 ZigType *var_type, const char *name_hint)
2065{2036{
2066 IrInstGenAlloca *alloca_gen = allocate<IrInstGenAlloca>(1);2037 IrInstGenAlloca *alloca_gen = heap::c_allocator.create<IrInstGenAlloca>();
2067 alloca_gen->base.id = IrInstGenIdAlloca;2038 alloca_gen->base.id = IrInstGenIdAlloca;
2068 alloca_gen->base.base.source_node = source_node;2039 alloca_gen->base.base.source_node = source_node;
2069 alloca_gen->base.base.scope = scope;2040 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>();
2071 alloca_gen->base.value->type = get_pointer_to_type(g, var_type, false);2042 alloca_gen->base.value->type = get_pointer_to_type(g, var_type, false);
2072 alloca_gen->base.base.ref_count = 1;2043 alloca_gen->base.base.ref_count = 1;
2073 alloca_gen->name_hint = name_hint;2044 alloca_gen->name_hint = name_hint;
...@@ -2157,7 +2128,7 @@ static IrInstSrc *ir_build_const_undefined(IrBuilderSrc *irb, Scope *scope, AstN...@@ -2157,7 +2128,7 @@ static IrInstSrc *ir_build_const_undefined(IrBuilderSrc *irb, Scope *scope, AstN
21572128
2158static IrInstSrc *ir_build_const_uint(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, uint64_t value) {2129static IrInstSrc *ir_build_const_uint(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, uint64_t value) {
2159 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);2130 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>();
2161 const_instruction->value->type = irb->codegen->builtin_types.entry_num_lit_int;2132 const_instruction->value->type = irb->codegen->builtin_types.entry_num_lit_int;
2162 const_instruction->value->special = ConstValSpecialStatic;2133 const_instruction->value->special = ConstValSpecialStatic;
2163 bigint_init_unsigned(&const_instruction->value->data.x_bigint, value);2134 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 *...@@ -2166,7 +2137,7 @@ static IrInstSrc *ir_build_const_uint(IrBuilderSrc *irb, Scope *scope, AstNode *
21662137
2167static IrInstSrc *ir_build_const_bigint(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, BigInt *bigint) {2138static IrInstSrc *ir_build_const_bigint(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, BigInt *bigint) {
2168 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);2139 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>();
2170 const_instruction->value->type = irb->codegen->builtin_types.entry_num_lit_int;2141 const_instruction->value->type = irb->codegen->builtin_types.entry_num_lit_int;
2171 const_instruction->value->special = ConstValSpecialStatic;2142 const_instruction->value->special = ConstValSpecialStatic;
2172 bigint_init_bigint(&const_instruction->value->data.x_bigint, bigint);2143 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...@@ -2175,7 +2146,7 @@ static IrInstSrc *ir_build_const_bigint(IrBuilderSrc *irb, Scope *scope, AstNode
21752146
2176static IrInstSrc *ir_build_const_bigfloat(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, BigFloat *bigfloat) {2147static IrInstSrc *ir_build_const_bigfloat(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, BigFloat *bigfloat) {
2177 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);2148 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>();
2179 const_instruction->value->type = irb->codegen->builtin_types.entry_num_lit_float;2150 const_instruction->value->type = irb->codegen->builtin_types.entry_num_lit_float;
2180 const_instruction->value->special = ConstValSpecialStatic;2151 const_instruction->value->special = ConstValSpecialStatic;
2181 bigfloat_init_bigfloat(&const_instruction->value->data.x_bigfloat, bigfloat);2152 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 *...@@ -2191,7 +2162,7 @@ static IrInstSrc *ir_build_const_null(IrBuilderSrc *irb, Scope *scope, AstNode *
21912162
2192static IrInstSrc *ir_build_const_usize(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, uint64_t value) {2163static IrInstSrc *ir_build_const_usize(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, uint64_t value) {
2193 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);2164 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>();
2195 const_instruction->value->type = irb->codegen->builtin_types.entry_usize;2166 const_instruction->value->type = irb->codegen->builtin_types.entry_usize;
2196 const_instruction->value->special = ConstValSpecialStatic;2167 const_instruction->value->special = ConstValSpecialStatic;
2197 bigint_init_unsigned(&const_instruction->value->data.x_bigint, value);2168 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...@@ -2202,7 +2173,7 @@ static IrInstSrc *ir_create_const_type(IrBuilderSrc *irb, Scope *scope, AstNode
2202 ZigType *type_entry)2173 ZigType *type_entry)
2203{2174{
2204 IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node);2175 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>();
2206 const_instruction->value->type = irb->codegen->builtin_types.entry_type;2177 const_instruction->value->type = irb->codegen->builtin_types.entry_type;
2207 const_instruction->value->special = ConstValSpecialStatic;2178 const_instruction->value->special = ConstValSpecialStatic;
2208 const_instruction->value->data.x_type = type_entry;2179 const_instruction->value->data.x_type = type_entry;
...@@ -2219,7 +2190,7 @@ static IrInstSrc *ir_build_const_type(IrBuilderSrc *irb, Scope *scope, AstNode *...@@ -2219,7 +2190,7 @@ static IrInstSrc *ir_build_const_type(IrBuilderSrc *irb, Scope *scope, AstNode *
22192190
2220static IrInstSrc *ir_build_const_import(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, ZigType *import) {2191static IrInstSrc *ir_build_const_import(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, ZigType *import) {
2221 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);2192 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>();
2223 const_instruction->value->type = irb->codegen->builtin_types.entry_type;2194 const_instruction->value->type = irb->codegen->builtin_types.entry_type;
2224 const_instruction->value->special = ConstValSpecialStatic;2195 const_instruction->value->special = ConstValSpecialStatic;
2225 const_instruction->value->data.x_type = import;2196 const_instruction->value->data.x_type = import;
...@@ -2228,7 +2199,7 @@ static IrInstSrc *ir_build_const_import(IrBuilderSrc *irb, Scope *scope, AstNode...@@ -2228,7 +2199,7 @@ static IrInstSrc *ir_build_const_import(IrBuilderSrc *irb, Scope *scope, AstNode
22282199
2229static IrInstSrc *ir_build_const_bool(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, bool value) {2200static IrInstSrc *ir_build_const_bool(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, bool value) {
2230 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);2201 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>();
2232 const_instruction->value->type = irb->codegen->builtin_types.entry_bool;2203 const_instruction->value->type = irb->codegen->builtin_types.entry_bool;
2233 const_instruction->value->special = ConstValSpecialStatic;2204 const_instruction->value->special = ConstValSpecialStatic;
2234 const_instruction->value->data.x_bool = value;2205 const_instruction->value->data.x_bool = value;
...@@ -2237,7 +2208,7 @@ static IrInstSrc *ir_build_const_bool(IrBuilderSrc *irb, Scope *scope, AstNode *...@@ -2237,7 +2208,7 @@ static IrInstSrc *ir_build_const_bool(IrBuilderSrc *irb, Scope *scope, AstNode *
22372208
2238static IrInstSrc *ir_build_const_enum_literal(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Buf *name) {2209static IrInstSrc *ir_build_const_enum_literal(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Buf *name) {
2239 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);2210 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>();
2241 const_instruction->value->type = irb->codegen->builtin_types.entry_enum_literal;2212 const_instruction->value->type = irb->codegen->builtin_types.entry_enum_literal;
2242 const_instruction->value->special = ConstValSpecialStatic;2213 const_instruction->value->special = ConstValSpecialStatic;
2243 const_instruction->value->data.x_enum_literal = name;2214 const_instruction->value->data.x_enum_literal = name;
...@@ -2246,7 +2217,7 @@ static IrInstSrc *ir_build_const_enum_literal(IrBuilderSrc *irb, Scope *scope, A...@@ -2246,7 +2217,7 @@ static IrInstSrc *ir_build_const_enum_literal(IrBuilderSrc *irb, Scope *scope, A
22462217
2247static IrInstSrc *ir_create_const_str_lit(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Buf *str) {2218static IrInstSrc *ir_create_const_str_lit(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Buf *str) {
2248 IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node);2219 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>();
2250 init_const_str_lit(irb->codegen, const_instruction->value, str);2221 init_const_str_lit(irb->codegen, const_instruction->value, str);
22512222
2252 return &const_instruction->base;2223 return &const_instruction->base;
...@@ -5244,7 +5215,7 @@ static IrInstSrc *ir_gen_return(IrBuilderSrc *irb, Scope *scope, AstNode *node,...@@ -5244,7 +5215,7 @@ static IrInstSrc *ir_gen_return(IrBuilderSrc *irb, Scope *scope, AstNode *node,
5244 switch (node->data.return_expr.kind) {5215 switch (node->data.return_expr.kind) {
5245 case ReturnKindUnconditional:5216 case ReturnKindUnconditional:
5246 {5217 {
5247 ResultLocReturn *result_loc_ret = allocate<ResultLocReturn>(1, "ResultLocReturn");5218 ResultLocReturn *result_loc_ret = heap::c_allocator.create<ResultLocReturn>();
5248 result_loc_ret->base.id = ResultLocIdReturn;5219 result_loc_ret->base.id = ResultLocIdReturn;
5249 ir_build_reset_result(irb, scope, node, &result_loc_ret->base);5220 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,...@@ -5332,7 +5303,7 @@ static IrInstSrc *ir_gen_return(IrBuilderSrc *irb, Scope *scope, AstNode *node,
5332 ir_mark_gen(ir_build_add_implicit_return_type(irb, scope, node, err_val, nullptr));5303 ir_mark_gen(ir_build_add_implicit_return_type(irb, scope, node, err_val, nullptr));
5333 IrInstSrcSpillBegin *spill_begin = ir_build_spill_begin_src(irb, scope, node, err_val,5304 IrInstSrcSpillBegin *spill_begin = ir_build_spill_begin_src(irb, scope, node, err_val,
5334 SpillIdRetErrCode);5305 SpillIdRetErrCode);
5335 ResultLocReturn *result_loc_ret = allocate<ResultLocReturn>(1, "ResultLocReturn");5306 ResultLocReturn *result_loc_ret = heap::c_allocator.create<ResultLocReturn>();
5336 result_loc_ret->base.id = ResultLocIdReturn;5307 result_loc_ret->base.id = ResultLocIdReturn;
5337 ir_build_reset_result(irb, scope, node, &result_loc_ret->base);5308 ir_build_reset_result(irb, scope, node, &result_loc_ret->base);
5338 ir_build_end_expr(irb, scope, node, err_val, &result_loc_ret->base);5309 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...@@ -5360,12 +5331,12 @@ static ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_s
5360 Buf *name, bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstSrc *is_comptime,5331 Buf *name, bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstSrc *is_comptime,
5361 bool skip_name_check)5332 bool skip_name_check)
5362{5333{
5363 ZigVar *variable_entry = allocate<ZigVar>(1, "ZigVar");5334 ZigVar *variable_entry = heap::c_allocator.create<ZigVar>();
5364 variable_entry->parent_scope = parent_scope;5335 variable_entry->parent_scope = parent_scope;
5365 variable_entry->shadowable = is_shadowable;5336 variable_entry->shadowable = is_shadowable;
5366 variable_entry->is_comptime = is_comptime;5337 variable_entry->is_comptime = is_comptime;
5367 variable_entry->src_arg_index = SIZE_MAX;5338 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
5370 if (is_comptime != nullptr) {5341 if (is_comptime != nullptr) {
5371 is_comptime->base.ref_count += 1;5342 is_comptime->base.ref_count += 1;
...@@ -5425,15 +5396,12 @@ static ZigVar *ir_create_var(IrBuilderSrc *irb, AstNode *node, Scope *scope, Buf...@@ -5425,15 +5396,12 @@ static ZigVar *ir_create_var(IrBuilderSrc *irb, AstNode *node, Scope *scope, Buf
5425 ZigVar *var = create_local_var(irb->codegen, node, scope,5396 ZigVar *var = create_local_var(irb->codegen, node, scope,
5426 (is_underscored ? nullptr : name), src_is_const, gen_is_const,5397 (is_underscored ? nullptr : name), src_is_const, gen_is_const,
5427 (is_underscored ? true : is_shadowable), is_comptime, false);5398 (is_underscored ? true : is_shadowable), is_comptime, false);
5428 if (is_comptime != nullptr || gen_is_const) {
5429 var->owner_exec = irb->exec;
5430 }
5431 assert(var->child_scope);5399 assert(var->child_scope);
5432 return var;5400 return var;
5433}5401}
54345402
5435static ResultLocPeer *create_peer_result(ResultLocPeerParent *peer_parent) {5403static ResultLocPeer *create_peer_result(ResultLocPeerParent *peer_parent) {
5436 ResultLocPeer *result = allocate<ResultLocPeer>(1, "ResultLocPeer");5404 ResultLocPeer *result = heap::c_allocator.create<ResultLocPeer>();
5437 result->base.id = ResultLocIdPeer;5405 result->base.id = ResultLocIdPeer;
5438 result->base.source_instruction = peer_parent->base.source_instruction;5406 result->base.source_instruction = peer_parent->base.source_instruction;
5439 result->parent = peer_parent;5407 result->parent = peer_parent;
...@@ -5472,7 +5440,7 @@ static IrInstSrc *ir_gen_block(IrBuilderSrc *irb, Scope *parent_scope, AstNode *...@@ -5472,7 +5440,7 @@ static IrInstSrc *ir_gen_block(IrBuilderSrc *irb, Scope *parent_scope, AstNode *
5472 scope_block->is_comptime = ir_build_const_bool(irb, parent_scope, block_node,5440 scope_block->is_comptime = ir_build_const_bool(irb, parent_scope, block_node,
5473 ir_should_inline(irb->exec, parent_scope));5441 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>();
5476 scope_block->peer_parent->base.id = ResultLocIdPeerParent;5444 scope_block->peer_parent->base.id = ResultLocIdPeerParent;
5477 scope_block->peer_parent->base.source_instruction = scope_block->is_comptime;5445 scope_block->peer_parent->base.source_instruction = scope_block->is_comptime;
5478 scope_block->peer_parent->base.allow_write_through_const = result_loc->allow_write_through_const;5446 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 *...@@ -5562,7 +5530,7 @@ static IrInstSrc *ir_gen_block(IrBuilderSrc *irb, Scope *parent_scope, AstNode *
5562 // only generate unconditional defers5530 // only generate unconditional defers
55635531
5564 ir_mark_gen(ir_build_add_implicit_return_type(irb, child_scope, block_node, result, nullptr));5532 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>();
5566 result_loc_ret->base.id = ResultLocIdReturn;5534 result_loc_ret->base.id = ResultLocIdReturn;
5567 ir_build_reset_result(irb, parent_scope, block_node, &result_loc_ret->base);5535 ir_build_reset_result(irb, parent_scope, block_node, &result_loc_ret->base);
5568 ir_mark_gen(ir_build_end_expr(irb, parent_scope, block_node, result, &result_loc_ret->base));5536 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)...@@ -5604,7 +5572,7 @@ static IrInstSrc *ir_gen_assign(IrBuilderSrc *irb, Scope *scope, AstNode *node)
5604 if (lvalue == irb->codegen->invalid_inst_src)5572 if (lvalue == irb->codegen->invalid_inst_src)
5605 return irb->codegen->invalid_inst_src;5573 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>();
5608 result_loc_inst->base.id = ResultLocIdInstruction;5576 result_loc_inst->base.id = ResultLocIdInstruction;
5609 result_loc_inst->base.source_instruction = lvalue;5577 result_loc_inst->base.source_instruction = lvalue;
5610 ir_ref_instruction(lvalue, irb->current_basic_block);5578 ir_ref_instruction(lvalue, irb->current_basic_block);
...@@ -5676,10 +5644,10 @@ static IrInstSrc *ir_gen_bool_or(IrBuilderSrc *irb, Scope *scope, AstNode *node)...@@ -5676,10 +5644,10 @@ static IrInstSrc *ir_gen_bool_or(IrBuilderSrc *irb, Scope *scope, AstNode *node)
56765644
5677 ir_set_cursor_at_end_and_append_block(irb, true_block);5645 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);
5680 incoming_values[0] = val1;5648 incoming_values[0] = val1;
5681 incoming_values[1] = val2;5649 incoming_values[1] = val2;
5682 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");5650 IrBasicBlockSrc **incoming_blocks = heap::c_allocator.allocate<IrBasicBlockSrc *>(2);
5683 incoming_blocks[0] = post_val1_block;5651 incoming_blocks[0] = post_val1_block;
5684 incoming_blocks[1] = post_val2_block;5652 incoming_blocks[1] = post_val2_block;
56855653
...@@ -5718,10 +5686,10 @@ static IrInstSrc *ir_gen_bool_and(IrBuilderSrc *irb, Scope *scope, AstNode *node...@@ -5718,10 +5686,10 @@ static IrInstSrc *ir_gen_bool_and(IrBuilderSrc *irb, Scope *scope, AstNode *node
57185686
5719 ir_set_cursor_at_end_and_append_block(irb, false_block);5687 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);
5722 incoming_values[0] = val1;5690 incoming_values[0] = val1;
5723 incoming_values[1] = val2;5691 incoming_values[1] = val2;
5724 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");5692 IrBasicBlockSrc **incoming_blocks = heap::c_allocator.allocate<IrBasicBlockSrc *>(2);
5725 incoming_blocks[0] = post_val1_block;5693 incoming_blocks[0] = post_val1_block;
5726 incoming_blocks[1] = post_val2_block;5694 incoming_blocks[1] = post_val2_block;
57275695
...@@ -5731,7 +5699,7 @@ static IrInstSrc *ir_gen_bool_and(IrBuilderSrc *irb, Scope *scope, AstNode *node...@@ -5731,7 +5699,7 @@ static IrInstSrc *ir_gen_bool_and(IrBuilderSrc *irb, Scope *scope, AstNode *node
5731static ResultLocPeerParent *ir_build_result_peers(IrBuilderSrc *irb, IrInstSrc *cond_br_inst,5699static ResultLocPeerParent *ir_build_result_peers(IrBuilderSrc *irb, IrInstSrc *cond_br_inst,
5732 IrBasicBlockSrc *end_block, ResultLoc *parent, IrInstSrc *is_comptime)5700 IrBasicBlockSrc *end_block, ResultLoc *parent, IrInstSrc *is_comptime)
5733{5701{
5734 ResultLocPeerParent *peer_parent = allocate<ResultLocPeerParent>(1);5702 ResultLocPeerParent *peer_parent = heap::c_allocator.create<ResultLocPeerParent>();
5735 peer_parent->base.id = ResultLocIdPeerParent;5703 peer_parent->base.id = ResultLocIdPeerParent;
5736 peer_parent->base.source_instruction = cond_br_inst;5704 peer_parent->base.source_instruction = cond_br_inst;
5737 peer_parent->base.allow_write_through_const = parent->allow_write_through_const;5705 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...@@ -5809,10 +5777,10 @@ static IrInstSrc *ir_gen_orelse(IrBuilderSrc *irb, Scope *parent_scope, AstNode
5809 ir_build_br(irb, parent_scope, node, end_block, is_comptime);5777 ir_build_br(irb, parent_scope, node, end_block, is_comptime);
58105778
5811 ir_set_cursor_at_end_and_append_block(irb, end_block);5779 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);
5813 incoming_values[0] = null_result;5781 incoming_values[0] = null_result;
5814 incoming_values[1] = unwrapped_payload;5782 incoming_values[1] = unwrapped_payload;
5815 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");5783 IrBasicBlockSrc **incoming_blocks = heap::c_allocator.allocate<IrBasicBlockSrc *>(2);
5816 incoming_blocks[0] = after_null_block;5784 incoming_blocks[0] = after_null_block;
5817 incoming_blocks[1] = after_ok_block;5785 incoming_blocks[1] = after_ok_block;
5818 IrInstSrc *phi = ir_build_phi(irb, parent_scope, node, 2, incoming_blocks, incoming_values, peer_parent);5786 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...@@ -5966,7 +5934,7 @@ static void populate_invalid_variable_in_scope(CodeGen *g, Scope *scope, AstNode
5966 }5934 }
5967 scope = scope->parent;5935 scope = scope->parent;
5968 }5936 }
5969 TldVar *tld_var = allocate<TldVar>(1);5937 TldVar *tld_var = heap::c_allocator.create<TldVar>();
5970 init_tld(&tld_var->base, TldIdVar, var_name, VisibModPub, node, &scope_decls->base);5938 init_tld(&tld_var->base, TldIdVar, var_name, VisibModPub, node, &scope_decls->base);
5971 tld_var->base.resolution = TldResolutionInvalid;5939 tld_var->base.resolution = TldResolutionInvalid;
5972 tld_var->var = add_variable(g, node, &scope_decls->base, var_name, false,5940 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,...@@ -5983,7 +5951,7 @@ static IrInstSrc *ir_gen_symbol(IrBuilderSrc *irb, Scope *scope, AstNode *node,
5983 if (buf_eql_str(variable_name, "_")) {5951 if (buf_eql_str(variable_name, "_")) {
5984 if (lval == LValPtr) {5952 if (lval == LValPtr) {
5985 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, node);5953 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>();
5987 const_instruction->value->type = get_pointer_to_type(irb->codegen,5955 const_instruction->value->type = get_pointer_to_type(irb->codegen,
5988 irb->codegen->builtin_types.entry_void, false);5956 irb->codegen->builtin_types.entry_void, false);
5989 const_instruction->value->special = ConstValSpecialStatic;5957 const_instruction->value->special = ConstValSpecialStatic;
...@@ -6177,7 +6145,7 @@ static IrInstSrc *ir_gen_async_call(IrBuilderSrc *irb, Scope *scope, AstNode *aw...@@ -6177,7 +6145,7 @@ static IrInstSrc *ir_gen_async_call(IrBuilderSrc *irb, Scope *scope, AstNode *aw
6177 return fn_ref;6145 return fn_ref;
61786146
6179 size_t arg_count = call_node->data.fn_call_expr.params.length - arg_offset;6147 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);
6181 for (size_t i = 0; i < arg_count; i += 1) {6149 for (size_t i = 0; i < arg_count; i += 1) {
6182 AstNode *arg_node = call_node->data.fn_call_expr.params.at(i + arg_offset);6150 AstNode *arg_node = call_node->data.fn_call_expr.params.at(i + arg_offset);
6183 IrInstSrc *arg = ir_gen_node(irb, arg_node, scope);6151 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...@@ -6203,7 +6171,7 @@ static IrInstSrc *ir_gen_fn_call_with_args(IrBuilderSrc *irb, Scope *scope, AstN
62036171
6204 IrInstSrc *fn_type = ir_build_typeof(irb, scope, source_node, fn_ref);6172 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);
6207 for (size_t i = 0; i < args_len; i += 1) {6175 for (size_t i = 0; i < args_len; i += 1) {
6208 AstNode *arg_node = args_ptr[i];6176 AstNode *arg_node = args_ptr[i];
62096177
...@@ -6388,7 +6356,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod...@@ -6388,7 +6356,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod
6388 }6356 }
6389 case BuiltinFnIdCompileLog:6357 case BuiltinFnIdCompileLog:
6390 {6358 {
6391 IrInstSrc **args = allocate<IrInstSrc*>(actual_param_count);6359 IrInstSrc **args = heap::c_allocator.allocate<IrInstSrc*>(actual_param_count);
63926360
6393 for (size_t i = 0; i < actual_param_count; i += 1) {6361 for (size_t i = 0; i < actual_param_count; i += 1) {
6394 AstNode *arg_node = node->data.fn_call_expr.params.at(i);6362 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...@@ -7013,7 +6981,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod
7013 if (dest_type == irb->codegen->invalid_inst_src)6981 if (dest_type == irb->codegen->invalid_inst_src)
7014 return dest_type;6982 return dest_type;
70156983
7016 ResultLocBitCast *result_loc_bit_cast = allocate<ResultLocBitCast>(1);6984 ResultLocBitCast *result_loc_bit_cast = heap::c_allocator.create<ResultLocBitCast>();
7017 result_loc_bit_cast->base.id = ResultLocIdBitCast;6985 result_loc_bit_cast->base.id = ResultLocIdBitCast;
7018 result_loc_bit_cast->base.source_instruction = dest_type;6986 result_loc_bit_cast->base.source_instruction = dest_type;
7019 result_loc_bit_cast->base.allow_write_through_const = result_loc->allow_write_through_const;6987 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...@@ -7166,7 +7134,7 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod
71667134
7167 size_t arg_count = node->data.fn_call_expr.params.length - 2;7135 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);
7170 for (size_t i = 0; i < arg_count; i += 1) {7138 for (size_t i = 0; i < arg_count; i += 1) {
7171 AstNode *arg_node = node->data.fn_call_expr.params.at(i + 2);7139 AstNode *arg_node = node->data.fn_call_expr.params.at(i + 2);
7172 args[i] = ir_gen_node(irb, arg_node, scope);7140 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 *...@@ -7595,10 +7563,10 @@ static IrInstSrc *ir_gen_if_bool_expr(IrBuilderSrc *irb, Scope *scope, AstNode *
7595 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));7563 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));
75967564
7597 ir_set_cursor_at_end_and_append_block(irb, endif_block);7565 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);
7599 incoming_values[0] = then_expr_result;7567 incoming_values[0] = then_expr_result;
7600 incoming_values[1] = else_expr_result;7568 incoming_values[1] = else_expr_result;
7601 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");7569 IrBasicBlockSrc **incoming_blocks = heap::c_allocator.allocate<IrBasicBlockSrc *>(2);
7602 incoming_blocks[0] = after_then_block;7570 incoming_blocks[0] = after_then_block;
7603 incoming_blocks[1] = after_else_block;7571 incoming_blocks[1] = after_else_block;
76047572
...@@ -7799,7 +7767,7 @@ static IrInstSrc *ir_gen_union_init_expr(IrBuilderSrc *irb, Scope *scope, AstNod...@@ -7799,7 +7767,7 @@ static IrInstSrc *ir_gen_union_init_expr(IrBuilderSrc *irb, Scope *scope, AstNod
7799 IrInstSrc *field_ptr = ir_build_field_ptr_instruction(irb, scope, source_node, container_ptr,7767 IrInstSrc *field_ptr = ir_build_field_ptr_instruction(irb, scope, source_node, container_ptr,
7800 field_name, true);7768 field_name, true);
78017769
7802 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1);7770 ResultLocInstruction *result_loc_inst = heap::c_allocator.create<ResultLocInstruction>();
7803 result_loc_inst->base.id = ResultLocIdInstruction;7771 result_loc_inst->base.id = ResultLocIdInstruction;
7804 result_loc_inst->base.source_instruction = field_ptr;7772 result_loc_inst->base.source_instruction = field_ptr;
7805 ir_ref_instruction(field_ptr, irb->current_basic_block);7773 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...@@ -7875,7 +7843,7 @@ static IrInstSrc *ir_gen_container_init_expr(IrBuilderSrc *irb, Scope *scope, As
7875 nullptr);7843 nullptr);
78767844
7877 size_t field_count = container_init_expr->entries.length;7845 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);
7879 for (size_t i = 0; i < field_count; i += 1) {7847 for (size_t i = 0; i < field_count; i += 1) {
7880 AstNode *entry_node = container_init_expr->entries.at(i);7848 AstNode *entry_node = container_init_expr->entries.at(i);
7881 assert(entry_node->type == NodeTypeStructValueField);7849 assert(entry_node->type == NodeTypeStructValueField);
...@@ -7884,7 +7852,7 @@ static IrInstSrc *ir_gen_container_init_expr(IrBuilderSrc *irb, Scope *scope, As...@@ -7884,7 +7852,7 @@ static IrInstSrc *ir_gen_container_init_expr(IrBuilderSrc *irb, Scope *scope, As
7884 AstNode *expr_node = entry_node->data.struct_val_field.expr;7852 AstNode *expr_node = entry_node->data.struct_val_field.expr;
78857853
7886 IrInstSrc *field_ptr = ir_build_field_ptr(irb, scope, entry_node, container_ptr, name, true);7854 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>();
7888 result_loc_inst->base.id = ResultLocIdInstruction;7856 result_loc_inst->base.id = ResultLocIdInstruction;
7889 result_loc_inst->base.source_instruction = field_ptr;7857 result_loc_inst->base.source_instruction = field_ptr;
7890 result_loc_inst->base.allow_write_through_const = true;7858 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...@@ -7914,14 +7882,14 @@ static IrInstSrc *ir_gen_container_init_expr(IrBuilderSrc *irb, Scope *scope, As
7914 IrInstSrc *container_ptr = ir_build_resolve_result(irb, scope, node, child_result_loc,7882 IrInstSrc *container_ptr = ir_build_resolve_result(irb, scope, node, child_result_loc,
7915 nullptr);7883 nullptr);
79167884
7917 IrInstSrc **result_locs = allocate<IrInstSrc *>(item_count);7885 IrInstSrc **result_locs = heap::c_allocator.allocate<IrInstSrc *>(item_count);
7918 for (size_t i = 0; i < item_count; i += 1) {7886 for (size_t i = 0; i < item_count; i += 1) {
7919 AstNode *expr_node = container_init_expr->entries.at(i);7887 AstNode *expr_node = container_init_expr->entries.at(i);
79207888
7921 IrInstSrc *elem_index = ir_build_const_usize(irb, scope, expr_node, i);7889 IrInstSrc *elem_index = ir_build_const_usize(irb, scope, expr_node, i);
7922 IrInstSrc *elem_ptr = ir_build_elem_ptr(irb, scope, expr_node, container_ptr,7890 IrInstSrc *elem_ptr = ir_build_elem_ptr(irb, scope, expr_node, container_ptr,
7923 elem_index, false, PtrLenSingle, init_array_type_source_node);7891 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>();
7925 result_loc_inst->base.id = ResultLocIdInstruction;7893 result_loc_inst->base.id = ResultLocIdInstruction;
7926 result_loc_inst->base.source_instruction = elem_ptr;7894 result_loc_inst->base.source_instruction = elem_ptr;
7927 result_loc_inst->base.allow_write_through_const = true;7895 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...@@ -7947,7 +7915,7 @@ static IrInstSrc *ir_gen_container_init_expr(IrBuilderSrc *irb, Scope *scope, As
7947}7915}
79487916
7949static ResultLocVar *ir_build_var_result_loc(IrBuilderSrc *irb, IrInstSrc *alloca, ZigVar *var) {7917static 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>();
7951 result_loc_var->base.id = ResultLocIdVar;7919 result_loc_var->base.id = ResultLocIdVar;
7952 result_loc_var->base.source_instruction = alloca;7920 result_loc_var->base.source_instruction = alloca;
7953 result_loc_var->base.allow_write_through_const = true;7921 result_loc_var->base.allow_write_through_const = true;
...@@ -7961,7 +7929,7 @@ static ResultLocVar *ir_build_var_result_loc(IrBuilderSrc *irb, IrInstSrc *alloc...@@ -7961,7 +7929,7 @@ static ResultLocVar *ir_build_var_result_loc(IrBuilderSrc *irb, IrInstSrc *alloc
7961static ResultLocCast *ir_build_cast_result_loc(IrBuilderSrc *irb, IrInstSrc *dest_type,7929static ResultLocCast *ir_build_cast_result_loc(IrBuilderSrc *irb, IrInstSrc *dest_type,
7962 ResultLoc *parent_result_loc)7930 ResultLoc *parent_result_loc)
7963{7931{
7964 ResultLocCast *result_loc_cast = allocate<ResultLocCast>(1);7932 ResultLocCast *result_loc_cast = heap::c_allocator.create<ResultLocCast>();
7965 result_loc_cast->base.id = ResultLocIdCast;7933 result_loc_cast->base.id = ResultLocIdCast;
7966 result_loc_cast->base.source_instruction = dest_type;7934 result_loc_cast->base.source_instruction = dest_type;
7967 result_loc_cast->base.allow_write_through_const = parent_result_loc->allow_write_through_const;7935 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...@@ -8804,9 +8772,9 @@ static IrInstSrc *ir_gen_asm_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node
8804 nullptr, 0, is_volatile, true);8772 nullptr, 0, is_volatile, true);
8805 }8773 }
88068774
8807 IrInstSrc **input_list = allocate<IrInstSrc *>(asm_expr->input_list.length);8775 IrInstSrc **input_list = heap::c_allocator.allocate<IrInstSrc *>(asm_expr->input_list.length);
8808 IrInstSrc **output_types = allocate<IrInstSrc *>(asm_expr->output_list.length);8776 IrInstSrc **output_types = heap::c_allocator.allocate<IrInstSrc *>(asm_expr->output_list.length);
8809 ZigVar **output_vars = allocate<ZigVar *>(asm_expr->output_list.length);8777 ZigVar **output_vars = heap::c_allocator.allocate<ZigVar *>(asm_expr->output_list.length);
8810 size_t return_count = 0;8778 size_t return_count = 0;
8811 if (!is_volatile && asm_expr->output_list.length == 0) {8779 if (!is_volatile && asm_expr->output_list.length == 0) {
8812 add_node_error(irb->codegen, node,8780 add_node_error(irb->codegen, node,
...@@ -8940,10 +8908,10 @@ static IrInstSrc *ir_gen_if_optional_expr(IrBuilderSrc *irb, Scope *scope, AstNo...@@ -8940,10 +8908,10 @@ static IrInstSrc *ir_gen_if_optional_expr(IrBuilderSrc *irb, Scope *scope, AstNo
8940 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));8908 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));
89418909
8942 ir_set_cursor_at_end_and_append_block(irb, endif_block);8910 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);
8944 incoming_values[0] = then_expr_result;8912 incoming_values[0] = then_expr_result;
8945 incoming_values[1] = else_expr_result;8913 incoming_values[1] = else_expr_result;
8946 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");8914 IrBasicBlockSrc **incoming_blocks = heap::c_allocator.allocate<IrBasicBlockSrc *>(2);
8947 incoming_blocks[0] = after_then_block;8915 incoming_blocks[0] = after_then_block;
8948 incoming_blocks[1] = after_else_block;8916 incoming_blocks[1] = after_else_block;
89498917
...@@ -9037,10 +9005,10 @@ static IrInstSrc *ir_gen_if_err_expr(IrBuilderSrc *irb, Scope *scope, AstNode *n...@@ -9037,10 +9005,10 @@ static IrInstSrc *ir_gen_if_err_expr(IrBuilderSrc *irb, Scope *scope, AstNode *n
9037 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));9005 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));
90389006
9039 ir_set_cursor_at_end_and_append_block(irb, endif_block);9007 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);
9041 incoming_values[0] = then_expr_result;9009 incoming_values[0] = then_expr_result;
9042 incoming_values[1] = else_expr_result;9010 incoming_values[1] = else_expr_result;
9043 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");9011 IrBasicBlockSrc **incoming_blocks = heap::c_allocator.allocate<IrBasicBlockSrc *>(2);
9044 incoming_blocks[0] = after_then_block;9012 incoming_blocks[0] = after_then_block;
9045 incoming_blocks[1] = after_else_block;9013 incoming_blocks[1] = after_else_block;
90469014
...@@ -9133,7 +9101,7 @@ static IrInstSrc *ir_gen_switch_expr(IrBuilderSrc *irb, Scope *scope, AstNode *n...@@ -9133,7 +9101,7 @@ static IrInstSrc *ir_gen_switch_expr(IrBuilderSrc *irb, Scope *scope, AstNode *n
91339101
9134 IrInstSrcSwitchElseVar *switch_else_var = nullptr;9102 IrInstSrcSwitchElseVar *switch_else_var = nullptr;
91359103
9136 ResultLocPeerParent *peer_parent = allocate<ResultLocPeerParent>(1);9104 ResultLocPeerParent *peer_parent = heap::c_allocator.create<ResultLocPeerParent>();
9137 peer_parent->base.id = ResultLocIdPeerParent;9105 peer_parent->base.id = ResultLocIdPeerParent;
9138 peer_parent->base.allow_write_through_const = result_loc->allow_write_through_const;9106 peer_parent->base.allow_write_through_const = result_loc->allow_write_through_const;
9139 peer_parent->end_bb = end_block;9107 peer_parent->end_bb = end_block;
...@@ -9295,7 +9263,7 @@ static IrInstSrc *ir_gen_switch_expr(IrBuilderSrc *irb, Scope *scope, AstNode *n...@@ -9295,7 +9263,7 @@ static IrInstSrc *ir_gen_switch_expr(IrBuilderSrc *irb, Scope *scope, AstNode *n
9295 ResultLocPeer *this_peer_result_loc = create_peer_result(peer_parent);9263 ResultLocPeer *this_peer_result_loc = create_peer_result(peer_parent);
92969264
9297 IrBasicBlockSrc *prong_block = ir_create_basic_block(irb, scope, "SwitchProng");9265 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
9300 for (size_t item_i = 0; item_i < prong_item_count; item_i += 1) {9268 for (size_t item_i = 0; item_i < prong_item_count; item_i += 1) {
9301 AstNode *item_node = prong_node->data.switch_prong.items.at(item_i);9269 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 *...@@ -9677,10 +9645,10 @@ static IrInstSrc *ir_gen_catch(IrBuilderSrc *irb, Scope *parent_scope, AstNode *
9677 ir_build_br(irb, parent_scope, node, end_block, is_comptime);9645 ir_build_br(irb, parent_scope, node, end_block, is_comptime);
96789646
9679 ir_set_cursor_at_end_and_append_block(irb, end_block);9647 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);
9681 incoming_values[0] = err_result;9649 incoming_values[0] = err_result;
9682 incoming_values[1] = unwrapped_payload;9650 incoming_values[1] = unwrapped_payload;
9683 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");9651 IrBasicBlockSrc **incoming_blocks = heap::c_allocator.allocate<IrBasicBlockSrc *>(2);
9684 incoming_blocks[0] = after_err_block;9652 incoming_blocks[0] = after_err_block;
9685 incoming_blocks[1] = after_ok_block;9653 incoming_blocks[1] = after_ok_block;
9686 IrInstSrc *phi = ir_build_phi(irb, parent_scope, node, 2, incoming_blocks, incoming_values, peer_parent);9654 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,...@@ -9747,7 +9715,7 @@ static IrInstSrc *ir_gen_container_decl(IrBuilderSrc *irb, Scope *parent_scope,
9747 scan_decls(irb->codegen, child_scope, child_node);9715 scan_decls(irb->codegen, child_scope, child_node);
9748 }9716 }
97499717
9750 TldContainer *tld_container = allocate<TldContainer>(1);9718 TldContainer *tld_container = heap::c_allocator.create<TldContainer>();
9751 init_tld(&tld_container->base, TldIdContainer, bare_name, VisibModPub, node, parent_scope);9719 init_tld(&tld_container->base, TldIdContainer, bare_name, VisibModPub, node, parent_scope);
9752 tld_container->type_entry = container_type;9720 tld_container->type_entry = container_type;
9753 tld_container->decls_scope = child_scope;9721 tld_container->decls_scope = child_scope;
...@@ -9790,7 +9758,7 @@ static ZigType *get_error_set_union(CodeGen *g, ErrorTableEntry **errors, ZigTyp...@@ -9790,7 +9758,7 @@ static ZigType *get_error_set_union(CodeGen *g, ErrorTableEntry **errors, ZigTyp
9790 }9758 }
97919759
9792 err_set_type->data.error_set.err_count = count;9760 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
9795 bool need_comma = false;9763 bool need_comma = false;
9796 for (uint32_t i = 0; i < set1->data.error_set.err_count; i += 1) {9764 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...@@ -9837,7 +9805,7 @@ static ZigType *make_err_set_with_one_item(CodeGen *g, Scope *parent_scope, AstN
9837 err_set_type->abi_align = g->builtin_types.entry_global_error_set->abi_align;9805 err_set_type->abi_align = g->builtin_types.entry_global_error_set->abi_align;
9838 err_set_type->abi_size = g->builtin_types.entry_global_error_set->abi_size;9806 err_set_type->abi_size = g->builtin_types.entry_global_error_set->abi_size;
9839 err_set_type->data.error_set.err_count = 1;9807 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
9842 err_set_type->data.error_set.errors[0] = err_entry;9810 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...@@ -9868,16 +9836,16 @@ static IrInstSrc *ir_gen_err_set_decl(IrBuilderSrc *irb, Scope *parent_scope, As
9868 err_set_type->size_in_bits = irb->codegen->builtin_types.entry_global_error_set->size_in_bits;9836 err_set_type->size_in_bits = irb->codegen->builtin_types.entry_global_error_set->size_in_bits;
9869 err_set_type->abi_align = irb->codegen->builtin_types.entry_global_error_set->abi_align;9837 err_set_type->abi_align = irb->codegen->builtin_types.entry_global_error_set->abi_align;
9870 err_set_type->abi_size = irb->codegen->builtin_types.entry_global_error_set->abi_size;9838 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
9873 size_t errors_count = irb->codegen->errors_by_index.length + err_count;9841 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
9876 for (uint32_t i = 0; i < err_count; i += 1) {9844 for (uint32_t i = 0; i < err_count; i += 1) {
9877 AstNode *field_node = node->data.err_set_decl.decls.at(i);9845 AstNode *field_node = node->data.err_set_decl.decls.at(i);
9878 AstNode *symbol_node = ast_field_to_symbol_node(field_node);9846 AstNode *symbol_node = ast_field_to_symbol_node(field_node);
9879 Buf *err_name = symbol_node->data.symbol_expr.symbol;9847 Buf *err_name = symbol_node->data.symbol_expr.symbol;
9880 ErrorTableEntry *err = allocate<ErrorTableEntry>(1);9848 ErrorTableEntry *err = heap::c_allocator.create<ErrorTableEntry>();
9881 err->decl_node = field_node;9849 err->decl_node = field_node;
9882 buf_init_from_buf(&err->name, err_name);9850 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...@@ -9902,7 +9870,7 @@ static IrInstSrc *ir_gen_err_set_decl(IrBuilderSrc *irb, Scope *parent_scope, As
9902 }9870 }
9903 errors[err->value] = err;9871 errors[err->value] = err;
9904 }9872 }
9905 deallocate(errors, errors_count, "ErrorTableEntry *");9873 heap::c_allocator.deallocate(errors, errors_count);
9906 return ir_build_const_type(irb, parent_scope, node, err_set_type);9874 return ir_build_const_type(irb, parent_scope, node, err_set_type);
9907}9875}
99089876
...@@ -9910,7 +9878,7 @@ static IrInstSrc *ir_gen_fn_proto(IrBuilderSrc *irb, Scope *parent_scope, AstNod...@@ -9910,7 +9878,7 @@ static IrInstSrc *ir_gen_fn_proto(IrBuilderSrc *irb, Scope *parent_scope, AstNod
9910 assert(node->type == NodeTypeFnProto);9878 assert(node->type == NodeTypeFnProto);
99119879
9912 size_t param_count = node->data.fn_proto.params.length;9880 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
9915 bool is_var_args = false;9883 bool is_var_args = false;
9916 for (size_t i = 0; i < param_count; i += 1) {9884 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...@@ -10191,7 +10159,7 @@ static IrInstSrc *ir_gen_node_raw(IrBuilderSrc *irb, AstNode *node, Scope *scope
10191}10159}
1019210160
10193static ResultLoc *no_result_loc(void) {10161static ResultLoc *no_result_loc(void) {
10194 ResultLocNone *result_loc_none = allocate<ResultLocNone>(1);10162 ResultLocNone *result_loc_none = heap::c_allocator.create<ResultLocNone>();
10195 result_loc_none->base.id = ResultLocIdNone;10163 result_loc_none->base.id = ResultLocIdNone;
10196 return &result_loc_none->base;10164 return &result_loc_none->base;
10197}10165}
...@@ -10280,7 +10248,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutableSrc *ir_e...@@ -10280,7 +10248,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutableSrc *ir_e
10280 if (!instr_is_unreachable(result)) {10248 if (!instr_is_unreachable(result)) {
10281 ir_mark_gen(ir_build_add_implicit_return_type(irb, scope, result->base.source_node, result, nullptr));10249 ir_mark_gen(ir_build_add_implicit_return_type(irb, scope, result->base.source_node, result, nullptr));
10282 // no need for save_err_ret_addr because this cannot return error10250 // 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>();
10284 result_loc_ret->base.id = ResultLocIdReturn;10252 result_loc_ret->base.id = ResultLocIdReturn;
10285 ir_build_reset_result(irb, scope, node, &result_loc_ret->base);10253 ir_build_reset_result(irb, scope, node, &result_loc_ret->base);
10286 ir_mark_gen(ir_build_end_expr(irb, scope, node, result, &result_loc_ret->base));10254 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...@@ -10372,7 +10340,7 @@ static Error eval_comptime_ptr_reinterpret(IrAnalyze *ira, CodeGen *codegen, Ast
10372 if ((err = ir_read_const_ptr(ira, codegen, source_node, &tmp, ptr_val)))10340 if ((err = ir_read_const_ptr(ira, codegen, source_node, &tmp, ptr_val)))
10373 return err;10341 return err;
10374 ZigValue *child_val = const_ptr_pointee_unchecked(codegen, ptr_val);10342 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);
10376 return ErrorNone;10344 return ErrorNone;
10377}10345}
1037810346
...@@ -11522,7 +11490,7 @@ static ZigType *get_error_set_intersection(IrAnalyze *ira, ZigType *set1, ZigTyp...@@ -11522,7 +11490,7 @@ static ZigType *get_error_set_intersection(IrAnalyze *ira, ZigType *set1, ZigTyp
11522 return set1;11490 return set1;
11523 }11491 }
11524 size_t errors_count = ira->codegen->errors_by_index.length;11492 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);
11526 populate_error_set_table(errors, set1);11494 populate_error_set_table(errors, set1);
11527 ZigList<ErrorTableEntry *> intersection_list = {};11495 ZigList<ErrorTableEntry *> intersection_list = {};
1152811496
...@@ -11543,7 +11511,7 @@ static ZigType *get_error_set_intersection(IrAnalyze *ira, ZigType *set1, ZigTyp...@@ -11543,7 +11511,7 @@ static ZigType *get_error_set_intersection(IrAnalyze *ira, ZigType *set1, ZigTyp
11543 buf_appendf(&err_set_type->name, "%s%s", comma, buf_ptr(&existing_entry_with_docs->name));11511 buf_appendf(&err_set_type->name, "%s%s", comma, buf_ptr(&existing_entry_with_docs->name));
11544 }11512 }
11545 }11513 }
11546 deallocate(errors, errors_count, "ErrorTableEntry *");11514 heap::c_allocator.deallocate(errors, errors_count);
1154711515
11548 err_set_type->data.error_set.err_count = intersection_list.length;11516 err_set_type->data.error_set.err_count = intersection_list.length;
11549 err_set_type->data.error_set.errors = intersection_list.items;11517 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...@@ -11596,7 +11564,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
11596 actual_ptr_type->data.pointer.ptr_len == PtrLenC;11564 actual_ptr_type->data.pointer.ptr_len == PtrLenC;
11597 if (!ok_null_term_ptrs) {11565 if (!ok_null_term_ptrs) {
11598 result.id = ConstCastResultIdPtrSentinel;11566 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);
11600 result.data.bad_ptr_sentinel->wanted_type = wanted_ptr_type;11568 result.data.bad_ptr_sentinel->wanted_type = wanted_ptr_type;
11601 result.data.bad_ptr_sentinel->actual_type = actual_ptr_type;11569 result.data.bad_ptr_sentinel->actual_type = actual_ptr_type;
11602 return result;11570 return result;
...@@ -11612,7 +11580,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted...@@ -11612,7 +11580,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
11612 (!actual_ptr_type->data.pointer.is_volatile || wanted_ptr_type->data.pointer.is_volatile);11580 (!actual_ptr_type->data.pointer.is_volatile || wanted_ptr_type->data.pointer.is_volatile);
11613 if (!ok_cv_qualifiers) {11581 if (!ok_cv_qualifiers) {
11614 result.id = ConstCastResultIdCV;11582 result.id = ConstCastResultIdCV;
11615 result.data.bad_cv = allocate_nonzero<ConstCastBadCV>(1);11583 result.data.bad_cv = heap::c_allocator.allocate_nonzero<ConstCastBadCV>(1);
11616 result.data.bad_cv->wanted_type = wanted_ptr_type;11584 result.data.bad_cv->wanted_type = wanted_ptr_type;
11617 result.data.bad_cv->actual_type = actual_ptr_type;11585 result.data.bad_cv->actual_type = actual_ptr_type;
11618 return result;11586 return result;
...@@ -11624,7 +11592,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted...@@ -11624,7 +11592,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
11624 return child;11592 return child;
11625 if (child.id != ConstCastResultIdOk) {11593 if (child.id != ConstCastResultIdOk) {
11626 result.id = ConstCastResultIdPointerChild;11594 result.id = ConstCastResultIdPointerChild;
11627 result.data.pointer_mismatch = allocate_nonzero<ConstCastPointerMismatch>(1);11595 result.data.pointer_mismatch = heap::c_allocator.allocate_nonzero<ConstCastPointerMismatch>(1);
11628 result.data.pointer_mismatch->child = child;11596 result.data.pointer_mismatch->child = child;
11629 result.data.pointer_mismatch->wanted_child = wanted_ptr_type->data.pointer.child_type;11597 result.data.pointer_mismatch->wanted_child = wanted_ptr_type->data.pointer.child_type;
11630 result.data.pointer_mismatch->actual_child = actual_ptr_type->data.pointer.child_type;11598 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...@@ -11635,7 +11603,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
11635 (!wanted_allows_zero && !actual_allows_zero);11603 (!wanted_allows_zero && !actual_allows_zero);
11636 if (!ok_allows_zero) {11604 if (!ok_allows_zero) {
11637 result.id = ConstCastResultIdBadAllowsZero;11605 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);
11639 result.data.bad_allows_zero->wanted_type = wanted_type;11607 result.data.bad_allows_zero->wanted_type = wanted_type;
11640 result.data.bad_allows_zero->actual_type = actual_type;11608 result.data.bad_allows_zero->actual_type = actual_type;
11641 return result;11609 return result;
...@@ -11675,7 +11643,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted...@@ -11675,7 +11643,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
11675 return child;11643 return child;
11676 if (child.id != ConstCastResultIdOk) {11644 if (child.id != ConstCastResultIdOk) {
11677 result.id = ConstCastResultIdArrayChild;11645 result.id = ConstCastResultIdArrayChild;
11678 result.data.array_mismatch = allocate_nonzero<ConstCastArrayMismatch>(1);11646 result.data.array_mismatch = heap::c_allocator.allocate_nonzero<ConstCastArrayMismatch>(1);
11679 result.data.array_mismatch->child = child;11647 result.data.array_mismatch->child = child;
11680 result.data.array_mismatch->wanted_child = wanted_type->data.array.child_type;11648 result.data.array_mismatch->wanted_child = wanted_type->data.array.child_type;
11681 result.data.array_mismatch->actual_child = actual_type->data.array.child_type;11649 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...@@ -11686,7 +11654,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
11686 const_values_equal(ira->codegen, wanted_type->data.array.sentinel, actual_type->data.array.sentinel));11654 const_values_equal(ira->codegen, wanted_type->data.array.sentinel, actual_type->data.array.sentinel));
11687 if (!ok_null_terminated) {11655 if (!ok_null_terminated) {
11688 result.id = ConstCastResultIdSentinelArrays;11656 result.id = ConstCastResultIdSentinelArrays;
11689 result.data.sentinel_arrays = allocate_nonzero<ConstCastBadNullTermArrays>(1);11657 result.data.sentinel_arrays = heap::c_allocator.allocate_nonzero<ConstCastBadNullTermArrays>(1);
11690 result.data.sentinel_arrays->child = child;11658 result.data.sentinel_arrays->child = child;
11691 result.data.sentinel_arrays->wanted_type = wanted_type;11659 result.data.sentinel_arrays->wanted_type = wanted_type;
11692 result.data.sentinel_arrays->actual_type = actual_type;11660 result.data.sentinel_arrays->actual_type = actual_type;
...@@ -11714,7 +11682,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted...@@ -11714,7 +11682,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
11714 actual_ptr_type->data.pointer.sentinel));11682 actual_ptr_type->data.pointer.sentinel));
11715 if (!ok_sentinels) {11683 if (!ok_sentinels) {
11716 result.id = ConstCastResultIdPtrSentinel;11684 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);
11718 result.data.bad_ptr_sentinel->wanted_type = wanted_ptr_type;11686 result.data.bad_ptr_sentinel->wanted_type = wanted_ptr_type;
11719 result.data.bad_ptr_sentinel->actual_type = actual_ptr_type;11687 result.data.bad_ptr_sentinel->actual_type = actual_ptr_type;
11720 return result;11688 return result;
...@@ -11731,7 +11699,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted...@@ -11731,7 +11699,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
11731 return child;11699 return child;
11732 if (child.id != ConstCastResultIdOk) {11700 if (child.id != ConstCastResultIdOk) {
11733 result.id = ConstCastResultIdSliceChild;11701 result.id = ConstCastResultIdSliceChild;
11734 result.data.slice_mismatch = allocate_nonzero<ConstCastSliceMismatch>(1);11702 result.data.slice_mismatch = heap::c_allocator.allocate_nonzero<ConstCastSliceMismatch>(1);
11735 result.data.slice_mismatch->child = child;11703 result.data.slice_mismatch->child = child;
11736 result.data.slice_mismatch->actual_child = actual_ptr_type->data.pointer.child_type;11704 result.data.slice_mismatch->actual_child = actual_ptr_type->data.pointer.child_type;
11737 result.data.slice_mismatch->wanted_child = wanted_ptr_type->data.pointer.child_type;11705 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...@@ -11748,7 +11716,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
11748 return child;11716 return child;
11749 if (child.id != ConstCastResultIdOk) {11717 if (child.id != ConstCastResultIdOk) {
11750 result.id = ConstCastResultIdOptionalChild;11718 result.id = ConstCastResultIdOptionalChild;
11751 result.data.optional = allocate_nonzero<ConstCastOptionalMismatch>(1);11719 result.data.optional = heap::c_allocator.allocate_nonzero<ConstCastOptionalMismatch>(1);
11752 result.data.optional->child = child;11720 result.data.optional->child = child;
11753 result.data.optional->wanted_child = wanted_type->data.maybe.child_type;11721 result.data.optional->wanted_child = wanted_type->data.maybe.child_type;
11754 result.data.optional->actual_child = actual_type->data.maybe.child_type;11722 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...@@ -11764,7 +11732,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
11764 return payload_child;11732 return payload_child;
11765 if (payload_child.id != ConstCastResultIdOk) {11733 if (payload_child.id != ConstCastResultIdOk) {
11766 result.id = ConstCastResultIdErrorUnionPayload;11734 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);
11768 result.data.error_union_payload->child = payload_child;11736 result.data.error_union_payload->child = payload_child;
11769 result.data.error_union_payload->wanted_payload = wanted_type->data.error_union.payload_type;11737 result.data.error_union_payload->wanted_payload = wanted_type->data.error_union.payload_type;
11770 result.data.error_union_payload->actual_payload = actual_type->data.error_union.payload_type;11738 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...@@ -11776,7 +11744,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
11776 return error_set_child;11744 return error_set_child;
11777 if (error_set_child.id != ConstCastResultIdOk) {11745 if (error_set_child.id != ConstCastResultIdOk) {
11778 result.id = ConstCastResultIdErrorUnionErrorSet;11746 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);
11780 result.data.error_union_error_set->child = error_set_child;11748 result.data.error_union_error_set->child = error_set_child;
11781 result.data.error_union_error_set->wanted_err_set = wanted_type->data.error_union.err_set_type;11749 result.data.error_union_error_set->wanted_err_set = wanted_type->data.error_union.err_set_type;
11782 result.data.error_union_error_set->actual_err_set = actual_type->data.error_union.err_set_type;11750 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...@@ -11810,7 +11778,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
11810 }11778 }
1181111779
11812 size_t errors_count = g->errors_by_index.length;11780 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);
11814 for (uint32_t i = 0; i < container_set->data.error_set.err_count; i += 1) {11782 for (uint32_t i = 0; i < container_set->data.error_set.err_count; i += 1) {
11815 ErrorTableEntry *error_entry = container_set->data.error_set.errors[i];11783 ErrorTableEntry *error_entry = container_set->data.error_set.errors[i];
11816 assert(errors[error_entry->value] == nullptr);11784 assert(errors[error_entry->value] == nullptr);
...@@ -11822,12 +11790,12 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted...@@ -11822,12 +11790,12 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
11822 if (error_entry == nullptr) {11790 if (error_entry == nullptr) {
11823 if (result.id == ConstCastResultIdOk) {11791 if (result.id == ConstCastResultIdOk) {
11824 result.id = ConstCastResultIdErrSet;11792 result.id = ConstCastResultIdErrSet;
11825 result.data.error_set_mismatch = allocate<ConstCastErrSetMismatch>(1);11793 result.data.error_set_mismatch = heap::c_allocator.create<ConstCastErrSetMismatch>();
11826 }11794 }
11827 result.data.error_set_mismatch->missing_errors.append(contained_error_entry);11795 result.data.error_set_mismatch->missing_errors.append(contained_error_entry);
11828 }11796 }
11829 }11797 }
11830 deallocate(errors, errors_count, "ErrorTableEntry *");11798 heap::c_allocator.deallocate(errors, errors_count);
11831 return result;11799 return result;
11832 }11800 }
1183311801
...@@ -11856,7 +11824,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted...@@ -11856,7 +11824,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
11856 return child;11824 return child;
11857 if (child.id != ConstCastResultIdOk) {11825 if (child.id != ConstCastResultIdOk) {
11858 result.id = ConstCastResultIdFnReturnType;11826 result.id = ConstCastResultIdFnReturnType;
11859 result.data.return_type = allocate_nonzero<ConstCastOnly>(1);11827 result.data.return_type = heap::c_allocator.allocate_nonzero<ConstCastOnly>(1);
11860 *result.data.return_type = child;11828 *result.data.return_type = child;
11861 return result;11829 return result;
11862 }11830 }
...@@ -11885,7 +11853,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted...@@ -11885,7 +11853,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
11885 result.data.fn_arg.arg_index = i;11853 result.data.fn_arg.arg_index = i;
11886 result.data.fn_arg.actual_param_type = actual_param_info->type;11854 result.data.fn_arg.actual_param_type = actual_param_info->type;
11887 result.data.fn_arg.expected_param_type = expected_param_info->type;11855 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);
11889 *result.data.fn_arg.child = arg_child;11857 *result.data.fn_arg.child = arg_child;
11890 return result;11858 return result;
11891 }11859 }
...@@ -11906,14 +11874,14 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted...@@ -11906,14 +11874,14 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
1190611874
11907 if (wanted_type->id == ZigTypeIdInt && actual_type->id == ZigTypeIdInt) {11875 if (wanted_type->id == ZigTypeIdInt && actual_type->id == ZigTypeIdInt) {
11908 result.id = ConstCastResultIdIntShorten;11876 result.id = ConstCastResultIdIntShorten;
11909 result.data.int_shorten = allocate_nonzero<ConstCastIntShorten>(1);11877 result.data.int_shorten = heap::c_allocator.allocate_nonzero<ConstCastIntShorten>(1);
11910 result.data.int_shorten->wanted_type = wanted_type;11878 result.data.int_shorten->wanted_type = wanted_type;
11911 result.data.int_shorten->actual_type = actual_type;11879 result.data.int_shorten->actual_type = actual_type;
11912 return result;11880 return result;
11913 }11881 }
1191411882
11915 result.id = ConstCastResultIdType;11883 result.id = ConstCastResultIdType;
11916 result.data.type_mismatch = allocate_nonzero<ConstCastTypeMismatch>(1);11884 result.data.type_mismatch = heap::c_allocator.allocate_nonzero<ConstCastTypeMismatch>(1);
11917 result.data.type_mismatch->wanted_type = wanted_type;11885 result.data.type_mismatch->wanted_type = wanted_type;
11918 result.data.type_mismatch->actual_type = actual_type;11886 result.data.type_mismatch->actual_type = actual_type;
11919 return result;11887 return result;
...@@ -11922,7 +11890,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted...@@ -11922,7 +11890,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
11922static void update_errors_helper(CodeGen *g, ErrorTableEntry ***errors, size_t *errors_count) {11890static void update_errors_helper(CodeGen *g, ErrorTableEntry ***errors, size_t *errors_count) {
11923 size_t old_errors_count = *errors_count;11891 size_t old_errors_count = *errors_count;
11924 *errors_count = g->errors_by_index.length;11892 *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);
11926}11894}
1192711895
11928static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigType *expected_type,11896static 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...@@ -12592,7 +12560,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
12592 return ira->codegen->builtin_types.entry_invalid;12560 return ira->codegen->builtin_types.entry_invalid;
12593 }12561 }
1259412562
12595 free(errors);12563 heap::c_allocator.deallocate(errors, errors_count);
1259612564
12597 if (convert_to_const_slice) {12565 if (convert_to_const_slice) {
12598 if (prev_inst->value->type->id == ZigTypeIdPointer) {12566 if (prev_inst->value->type->id == ZigTypeIdPointer) {
...@@ -12671,7 +12639,7 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInst *source_instr,...@@ -12671,7 +12639,7 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInst *source_instr,
12671 case CastOpBitCast:12639 case CastOpBitCast:
12672 zig_panic("TODO");12640 zig_panic("TODO");
12673 case CastOpNoop: {12641 case CastOpNoop: {
12674 copy_const_val(const_val, other_val);12642 copy_const_val(ira->codegen, const_val, other_val);
12675 const_val->type = new_type;12643 const_val->type = new_type;
12676 break;12644 break;
12677 }12645 }
...@@ -13200,7 +13168,7 @@ Error ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,...@@ -13200,7 +13168,7 @@ Error ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
13200 if (type_is_invalid(return_ptr->type))13168 if (type_is_invalid(return_ptr->type))
13201 return ErrorSemanticAnalyzeFail;13169 return ErrorSemanticAnalyzeFail;
1320213170
13203 IrExecutableSrc *ir_executable = allocate<IrExecutableSrc>(1, "IrExecutableSrc");13171 IrExecutableSrc *ir_executable = heap::c_allocator.create<IrExecutableSrc>();
13204 ir_executable->source_node = source_node;13172 ir_executable->source_node = source_node;
13205 ir_executable->parent_exec = parent_exec;13173 ir_executable->parent_exec = parent_exec;
13206 ir_executable->name = exec_name;13174 ir_executable->name = exec_name;
...@@ -13224,7 +13192,7 @@ Error ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,...@@ -13224,7 +13192,7 @@ Error ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
13224 ir_print_src(codegen, stderr, ir_executable, 2);13192 ir_print_src(codegen, stderr, ir_executable, 2);
13225 fprintf(stderr, "}\n");13193 fprintf(stderr, "}\n");
13226 }13194 }
13227 IrExecutableGen *analyzed_executable = allocate<IrExecutableGen>(1, "IrExecutableGen");13195 IrExecutableGen *analyzed_executable = heap::c_allocator.create<IrExecutableGen>();
13228 analyzed_executable->source_node = source_node;13196 analyzed_executable->source_node = source_node;
13229 analyzed_executable->parent_exec = parent_exec;13197 analyzed_executable->parent_exec = parent_exec;
13230 analyzed_executable->source_exec = ir_executable;13198 analyzed_executable->source_exec = ir_executable;
...@@ -13425,7 +13393,7 @@ static IrInstGen *ir_analyze_optional_wrap(IrAnalyze *ira, IrInst* source_instr,...@@ -13425,7 +13393,7 @@ static IrInstGen *ir_analyze_optional_wrap(IrAnalyze *ira, IrInst* source_instr,
13425 source_instr->scope, source_instr->source_node);13393 source_instr->scope, source_instr->source_node);
13426 const_instruction->base.value->special = ConstValSpecialStatic;13394 const_instruction->base.value->special = ConstValSpecialStatic;
13427 if (types_have_same_zig_comptime_repr(ira->codegen, wanted_type, payload_type)) {13395 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);
13429 } else {13397 } else {
13430 const_instruction->base.value->data.x_optional = val;13398 const_instruction->base.value->data.x_optional = val;
13431 }13399 }
...@@ -13466,7 +13434,7 @@ static IrInstGen *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInst* source_ins...@@ -13466,7 +13434,7 @@ static IrInstGen *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInst* source_ins
13466 if (val == nullptr)13434 if (val == nullptr)
13467 return ira->codegen->invalid_inst_gen;13435 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>();
13470 err_set_val->type = err_set_type;13438 err_set_val->type = err_set_type;
13471 err_set_val->special = ConstValSpecialStatic;13439 err_set_val->special = ConstValSpecialStatic;
13472 err_set_val->data.x_err_set = nullptr;13440 err_set_val->data.x_err_set = nullptr;
...@@ -13578,7 +13546,7 @@ static IrInstGen *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInst* source_instr,...@@ -13578,7 +13546,7 @@ static IrInstGen *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInst* source_instr,
13578 if (!val)13546 if (!val)
13579 return ira->codegen->invalid_inst_gen;13547 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>();
13582 err_set_val->special = ConstValSpecialStatic;13550 err_set_val->special = ConstValSpecialStatic;
13583 err_set_val->type = wanted_type->data.error_union.err_set_type;13551 err_set_val->type = wanted_type->data.error_union.err_set_type;
13584 err_set_val->data.x_err_set = val->data.x_err_set;13552 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,...@@ -13843,7 +13811,7 @@ static IrInstGen *ir_analyze_enum_to_union(IrAnalyze *ira, IrInst* source_instr,
13843 result->value->special = ConstValSpecialStatic;13811 result->value->special = ConstValSpecialStatic;
13844 result->value->type = wanted_type;13812 result->value->type = wanted_type;
13845 bigint_init_bigint(&result->value->data.x_union.tag, &val->data.x_enum_tag);13813 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>();
13847 result->value->data.x_union.payload->special = ConstValSpecialStatic;13815 result->value->data.x_union.payload->special = ConstValSpecialStatic;
13848 result->value->data.x_union.payload->type = field_type;13816 result->value->data.x_union.payload->type = field_type;
13849 return result;13817 return result;
...@@ -14148,7 +14116,7 @@ static IrInstGen *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInst* source_instr,...@@ -14148,7 +14116,7 @@ static IrInstGen *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInst* source_instr,
14148 if (pointee == nullptr)14116 if (pointee == nullptr)
14149 return ira->codegen->invalid_inst_gen;14117 return ira->codegen->invalid_inst_gen;
14150 if (pointee->special != ConstValSpecialRuntime) {14118 if (pointee->special != ConstValSpecialRuntime) {
14151 ZigValue *array_val = create_const_vals(1);14119 ZigValue *array_val = ira->codegen->pass1_arena->create<ZigValue>();
14152 array_val->special = ConstValSpecialStatic;14120 array_val->special = ConstValSpecialStatic;
14153 array_val->type = array_type;14121 array_val->type = array_type;
14154 array_val->data.x_array.special = ConstArraySpecialNone;14122 array_val->data.x_array.special = ConstArraySpecialNone;
...@@ -14362,7 +14330,7 @@ static IrInstGen *ir_analyze_array_to_vector(IrAnalyze *ira, IrInst* source_inst...@@ -14362,7 +14330,7 @@ static IrInstGen *ir_analyze_array_to_vector(IrAnalyze *ira, IrInst* source_inst
14362 if (instr_is_comptime(array)) {14330 if (instr_is_comptime(array)) {
14363 // arrays and vectors have the same ZigValue representation14331 // arrays and vectors have the same ZigValue representation
14364 IrInstGen *result = ir_const(ira, source_instr, vector_type);14332 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);
14366 result->value->type = vector_type;14334 result->value->type = vector_type;
14367 return result;14335 return result;
14368 }14336 }
...@@ -14375,7 +14343,7 @@ static IrInstGen *ir_analyze_vector_to_array(IrAnalyze *ira, IrInst* source_inst...@@ -14375,7 +14343,7 @@ static IrInstGen *ir_analyze_vector_to_array(IrAnalyze *ira, IrInst* source_inst
14375 if (instr_is_comptime(vector)) {14343 if (instr_is_comptime(vector)) {
14376 // arrays and vectors have the same ZigValue representation14344 // arrays and vectors have the same ZigValue representation
14377 IrInstGen *result = ir_const(ira, source_instr, array_type);14345 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);
14379 result->value->type = array_type;14347 result->value->type = array_type;
14380 return result;14348 return result;
14381 }14349 }
...@@ -14675,7 +14643,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,...@@ -14675,7 +14643,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
14675 if (wanted_type->id == ZigTypeIdComptimeInt || wanted_type->id == ZigTypeIdInt) {14643 if (wanted_type->id == ZigTypeIdComptimeInt || wanted_type->id == ZigTypeIdInt) {
14676 IrInstGen *result = ir_const(ira, source_instr, wanted_type);14644 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
14677 if (actual_type->id == ZigTypeIdComptimeInt || actual_type->id == ZigTypeIdInt) {14645 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);
14679 result->value->type = wanted_type;14647 result->value->type = wanted_type;
14680 } else {14648 } else {
14681 float_init_bigint(&result->value->data.x_bigint, value->value);14649 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...@@ -16508,7 +16476,7 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i
16508 IrInstGen *result = ir_const(ira, &bin_op_instruction->base.base,16476 IrInstGen *result = ir_const(ira, &bin_op_instruction->base.base,
16509 get_vector_type(ira->codegen, resolved_type->data.vector.len, ira->codegen->builtin_types.entry_bool));16477 get_vector_type(ira->codegen, resolved_type->data.vector.len, ira->codegen->builtin_types.entry_bool));
16510 result->value->data.x_array.data.s_none.elements =16478 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
16513 expand_undef_array(ira->codegen, result->value);16481 expand_undef_array(ira->codegen, result->value);
16514 for (size_t i = 0;i < resolved_type->data.vector.len;i++) {16482 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...@@ -16516,7 +16484,7 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i
16516 &op1_val->data.x_array.data.s_none.elements[i],16484 &op1_val->data.x_array.data.s_none.elements[i],
16517 &op2_val->data.x_array.data.s_none.elements[i],16485 &op2_val->data.x_array.data.s_none.elements[i],
16518 bin_op_instruction, op_id, one_possible_value);16486 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);
16520 }16488 }
16521 return result;16489 return result;
16522 }16490 }
...@@ -17416,7 +17384,7 @@ static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instructi...@@ -17416,7 +17384,7 @@ static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instructi
17416 ZigValue *out_array_val;17384 ZigValue *out_array_val;
17417 size_t new_len = (op1_array_end - op1_array_index) + (op2_array_end - op2_array_index);17385 size_t new_len = (op1_array_end - op1_array_index) + (op2_array_end - op2_array_index);
17418 if (op1_type->id == ZigTypeIdPointer || op2_type->id == ZigTypeIdPointer) {17386 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>();
17420 out_array_val->special = ConstValSpecialStatic;17388 out_array_val->special = ConstValSpecialStatic;
17421 out_array_val->type = get_array_type(ira->codegen, child_type, new_len, sentinel);17389 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...@@ -17428,11 +17396,11 @@ static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instructi
17428 true, false, PtrLenUnknown, 0, 0, 0, false,17396 true, false, PtrLenUnknown, 0, 0, 0, false,
17429 VECTOR_INDEX_NONE, nullptr, sentinel);17397 VECTOR_INDEX_NONE, nullptr, sentinel);
17430 result->value->type = get_slice_type(ira->codegen, ptr_type);17398 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>();
17432 out_array_val->special = ConstValSpecialStatic;17400 out_array_val->special = ConstValSpecialStatic;
17433 out_array_val->type = get_array_type(ira->codegen, child_type, new_len, sentinel);17401 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
17437 out_val->data.x_struct.fields[slice_ptr_index]->type = ptr_type;17405 out_val->data.x_struct.fields[slice_ptr_index]->type = ptr_type;
17438 out_val->data.x_struct.fields[slice_ptr_index]->special = ConstValSpecialStatic;17406 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...@@ -17449,7 +17417,7 @@ static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instructi
17449 } else {17417 } else {
17450 result->value->type = get_pointer_to_type_extra2(ira->codegen, child_type, true, false, PtrLenUnknown,17418 result->value->type = get_pointer_to_type_extra2(ira->codegen, child_type, true, false, PtrLenUnknown,
17451 0, 0, 0, false, VECTOR_INDEX_NONE, nullptr, sentinel);17419 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>();
17453 out_array_val->special = ConstValSpecialStatic;17421 out_array_val->special = ConstValSpecialStatic;
17454 out_array_val->type = get_array_type(ira->codegen, child_type, new_len, sentinel);17422 out_array_val->type = get_array_type(ira->codegen, child_type, new_len, sentinel);
17455 out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;17423 out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;
...@@ -17465,7 +17433,7 @@ static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instructi...@@ -17465,7 +17433,7 @@ static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instructi
17465 }17433 }
1746617434
17467 uint64_t full_len = new_len + ((sentinel != nullptr) ? 1 : 0);17435 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);
17469 // TODO handle the buf case here for an optimization17437 // TODO handle the buf case here for an optimization
17470 expand_undef_array(ira->codegen, op1_array_val);17438 expand_undef_array(ira->codegen, op1_array_val);
17471 expand_undef_array(ira->codegen, op2_array_val);17439 expand_undef_array(ira->codegen, op2_array_val);
...@@ -17473,21 +17441,21 @@ static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instructi...@@ -17473,21 +17441,21 @@ static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instructi
17473 size_t next_index = 0;17441 size_t next_index = 0;
17474 for (size_t i = op1_array_index; i < op1_array_end; i += 1, next_index += 1) {17442 for (size_t i = op1_array_index; i < op1_array_end; i += 1, next_index += 1) {
17475 ZigValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index];17443 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]);
17477 elem_dest_val->parent.id = ConstParentIdArray;17445 elem_dest_val->parent.id = ConstParentIdArray;
17478 elem_dest_val->parent.data.p_array.array_val = out_array_val;17446 elem_dest_val->parent.data.p_array.array_val = out_array_val;
17479 elem_dest_val->parent.data.p_array.elem_index = next_index;17447 elem_dest_val->parent.data.p_array.elem_index = next_index;
17480 }17448 }
17481 for (size_t i = op2_array_index; i < op2_array_end; i += 1, next_index += 1) {17449 for (size_t i = op2_array_index; i < op2_array_end; i += 1, next_index += 1) {
17482 ZigValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index];17450 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]);
17484 elem_dest_val->parent.id = ConstParentIdArray;17452 elem_dest_val->parent.id = ConstParentIdArray;
17485 elem_dest_val->parent.data.p_array.array_val = out_array_val;17453 elem_dest_val->parent.data.p_array.array_val = out_array_val;
17486 elem_dest_val->parent.data.p_array.elem_index = next_index;17454 elem_dest_val->parent.data.p_array.elem_index = next_index;
17487 }17455 }
17488 if (next_index < full_len) {17456 if (next_index < full_len) {
17489 ZigValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index];17457 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);
17491 elem_dest_val->parent.id = ConstParentIdArray;17459 elem_dest_val->parent.id = ConstParentIdArray;
17492 elem_dest_val->parent.data.p_array.array_val = out_array_val;17460 elem_dest_val->parent.data.p_array.array_val = out_array_val;
17493 elem_dest_val->parent.data.p_array.elem_index = next_index;17461 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...@@ -17566,13 +17534,13 @@ static IrInstGen *ir_analyze_array_mult(IrAnalyze *ira, IrInstSrcBinOp *instruct
17566 // TODO optimize the buf case17534 // TODO optimize the buf case
17567 expand_undef_array(ira->codegen, array_val);17535 expand_undef_array(ira->codegen, array_val);
17568 size_t extra_null_term = (array_type->data.array.sentinel != nullptr) ? 1 : 0;17536 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
17571 uint64_t i = 0;17539 uint64_t i = 0;
17572 for (uint64_t x = 0; x < mult_amt; x += 1) {17540 for (uint64_t x = 0; x < mult_amt; x += 1) {
17573 for (uint64_t y = 0; y < old_array_len; y += 1) {17541 for (uint64_t y = 0; y < old_array_len; y += 1) {
17574 ZigValue *elem_dest_val = &out_val->data.x_array.data.s_none.elements[i];17542 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]);
17576 elem_dest_val->parent.id = ConstParentIdArray;17544 elem_dest_val->parent.id = ConstParentIdArray;
17577 elem_dest_val->parent.data.p_array.array_val = out_val;17545 elem_dest_val->parent.data.p_array.array_val = out_val;
17578 elem_dest_val->parent.data.p_array.elem_index = i;17546 elem_dest_val->parent.data.p_array.elem_index = i;
...@@ -17583,7 +17551,7 @@ static IrInstGen *ir_analyze_array_mult(IrAnalyze *ira, IrInstSrcBinOp *instruct...@@ -17583,7 +17551,7 @@ static IrInstGen *ir_analyze_array_mult(IrAnalyze *ira, IrInstSrcBinOp *instruct
1758317551
17584 if (array_type->data.array.sentinel != nullptr) {17552 if (array_type->data.array.sentinel != nullptr) {
17585 ZigValue *elem_dest_val = &out_val->data.x_array.data.s_none.elements[i];17553 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);
17587 elem_dest_val->parent.id = ConstParentIdArray;17555 elem_dest_val->parent.id = ConstParentIdArray;
17588 elem_dest_val->parent.data.p_array.array_val = out_val;17556 elem_dest_val->parent.data.p_array.array_val = out_val;
17589 elem_dest_val->parent.data.p_array.elem_index = i;17557 elem_dest_val->parent.data.p_array.elem_index = i;
...@@ -17624,14 +17592,14 @@ static IrInstGen *ir_analyze_instruction_merge_err_sets(IrAnalyze *ira,...@@ -17624,14 +17592,14 @@ static IrInstGen *ir_analyze_instruction_merge_err_sets(IrAnalyze *ira,
17624 }17592 }
1762517593
17626 size_t errors_count = ira->codegen->errors_by_index.length;17594 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);
17628 for (uint32_t i = 0, count = op1_type->data.error_set.err_count; i < count; i += 1) {17596 for (uint32_t i = 0, count = op1_type->data.error_set.err_count; i < count; i += 1) {
17629 ErrorTableEntry *error_entry = op1_type->data.error_set.errors[i];17597 ErrorTableEntry *error_entry = op1_type->data.error_set.errors[i];
17630 assert(errors[error_entry->value] == nullptr);17598 assert(errors[error_entry->value] == nullptr);
17631 errors[error_entry->value] = error_entry;17599 errors[error_entry->value] = error_entry;
17632 }17600 }
17633 ZigType *result_type = get_error_set_union(ira->codegen, errors, op1_type, op2_type, instruction->type_name);17601 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
17636 return ir_const_type(ira, &instruction->base.base, result_type);17604 return ir_const_type(ira, &instruction->base.base, result_type);
17637}17605}
...@@ -17730,8 +17698,8 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV...@@ -17730,8 +17698,8 @@ static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclV
17730 if (var->gen_is_const) {17698 if (var->gen_is_const) {
17731 var->const_value = init_val;17699 var->const_value = init_val;
17732 } else {17700 } else {
17733 var->const_value = create_const_vals(1);17701 var->const_value = ira->codegen->pass1_arena->create<ZigValue>();
17734 copy_const_val(var->const_value, init_val);17702 copy_const_val(ira->codegen, var->const_value, init_val);
17735 }17703 }
17736 }17704 }
17737 }17705 }
...@@ -17905,7 +17873,7 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport...@@ -17905,7 +17873,7 @@ static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport
17905 // It's not clear how all the different types are supposed to be handled.17873 // It's not clear how all the different types are supposed to be handled.
17906 // Need comprehensive tests for exporting one thing in one file and declaring an extern var17874 // Need comprehensive tests for exporting one thing in one file and declaring an extern var
17907 // in another file.17875 // in another file.
17908 TldFn *tld_fn = allocate<TldFn>(1);17876 TldFn *tld_fn = heap::c_allocator.create<TldFn>();
17909 tld_fn->base.id = TldIdFn;17877 tld_fn->base.id = TldIdFn;
17910 tld_fn->base.source_node = instruction->base.base.source_node;17878 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...@@ -18134,7 +18102,7 @@ static IrInstGen *ir_analyze_instruction_error_union(IrAnalyze *ira, IrInstSrcEr
18134 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type);18102 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type);
18135 result->value->special = ConstValSpecialLazy;18103 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>();
18138 lazy_err_union_type->ira = ira; ira_ref(ira);18106 lazy_err_union_type->ira = ira; ira_ref(ira);
18139 result->value->data.x_lazy = &lazy_err_union_type->base;18107 result->value->data.x_lazy = &lazy_err_union_type->base;
18140 lazy_err_union_type->base.id = LazyValueIdErrUnionType;18108 lazy_err_union_type->base.id = LazyValueIdErrUnionType;
...@@ -18155,7 +18123,7 @@ static IrInstGen *ir_analyze_alloca(IrAnalyze *ira, IrInst *source_inst, ZigType...@@ -18155,7 +18123,7 @@ static IrInstGen *ir_analyze_alloca(IrAnalyze *ira, IrInst *source_inst, ZigType
18155{18123{
18156 Error err;18124 Error err;
1815718125
18158 ZigValue *pointee = create_const_vals(1);18126 ZigValue *pointee = ira->codegen->pass1_arena->create<ZigValue>();
18159 pointee->special = ConstValSpecialUndef;18127 pointee->special = ConstValSpecialUndef;
18160 pointee->llvm_align = align;18128 pointee->llvm_align = align;
1816118129
...@@ -18236,8 +18204,8 @@ static bool type_can_bit_cast(ZigType *t) {...@@ -18236,8 +18204,8 @@ static bool type_can_bit_cast(ZigType *t) {
18236 }18204 }
18237}18205}
1823818206
18239static void set_up_result_loc_for_inferred_comptime(IrInstGen *ptr) {18207static void set_up_result_loc_for_inferred_comptime(IrAnalyze *ira, IrInstGen *ptr) {
18240 ZigValue *undef_child = create_const_vals(1);18208 ZigValue *undef_child = ira->codegen->pass1_arena->create<ZigValue>();
18241 undef_child->type = ptr->value->type->data.pointer.child_type;18209 undef_child->type = ptr->value->type->data.pointer.child_type;
18242 undef_child->special = ConstValSpecialUndef;18210 undef_child->special = ConstValSpecialUndef;
18243 ptr->value->special = ConstValSpecialStatic;18211 ptr->value->special = ConstValSpecialStatic;
...@@ -18283,7 +18251,7 @@ static IrInstGen *ir_resolve_no_result_loc(IrAnalyze *ira, IrInst *suspend_sourc...@@ -18283,7 +18251,7 @@ static IrInstGen *ir_resolve_no_result_loc(IrAnalyze *ira, IrInst *suspend_sourc
18283 IrInstGenAlloca *alloca_gen = ir_build_alloca_gen(ira, suspend_source_instr, 0, "");18251 IrInstGenAlloca *alloca_gen = ir_build_alloca_gen(ira, suspend_source_instr, 0, "");
18284 alloca_gen->base.value->type = get_pointer_to_type_extra(ira->codegen, value_type, false, false,18252 alloca_gen->base.value->type = get_pointer_to_type_extra(ira->codegen, value_type, false, false,
18285 PtrLenSingle, 0, 0, 0, false);18253 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);
18287 ZigFn *fn_entry = ira->new_irb.exec->fn_entry;18255 ZigFn *fn_entry = ira->new_irb.exec->fn_entry;
18288 if (fn_entry != nullptr && get_scope_typeof(suspend_source_instr->scope) == nullptr) {18256 if (fn_entry != nullptr && get_scope_typeof(suspend_source_instr->scope) == nullptr) {
18289 fn_entry->alloca_gen_list.append(alloca_gen);18257 fn_entry->alloca_gen_list.append(alloca_gen);
...@@ -18347,7 +18315,6 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i...@@ -18347,7 +18315,6 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i
18347 ZigVar *new_var = create_local_var(ira->codegen, var->decl_node, var->child_scope,18315 ZigVar *new_var = create_local_var(ira->codegen, var->decl_node, var->child_scope,
18348 buf_create_from_str(var->name), var->src_is_const, var->gen_is_const,18316 buf_create_from_str(var->name), var->src_is_const, var->gen_is_const,
18349 var->shadowable, var->is_comptime, true);18317 var->shadowable, var->is_comptime, true);
18350 new_var->owner_exec = var->owner_exec;
18351 new_var->align_bytes = var->align_bytes;18318 new_var->align_bytes = var->align_bytes;
1835218319
18353 var->next_var = new_var;18320 var->next_var = new_var;
...@@ -18686,15 +18653,15 @@ static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr...@@ -18686,15 +18653,15 @@ static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr
18686 if (!val)18653 if (!val)
18687 return ira->codegen->invalid_inst_gen;18654 return ira->codegen->invalid_inst_gen;
18688 field->is_comptime = true;18655 field->is_comptime = true;
18689 field->init_val = create_const_vals(1);18656 field->init_val = ira->codegen->pass1_arena->create<ZigValue>();
18690 copy_const_val(field->init_val, val);18657 copy_const_val(ira->codegen, field->init_val, val);
18691 return result_loc;18658 return result_loc;
18692 }18659 }
1869318660
18694 ZigType *struct_ptr_type = get_pointer_to_type(ira->codegen, isf->inferred_struct_type, false);18661 ZigType *struct_ptr_type = get_pointer_to_type(ira->codegen, isf->inferred_struct_type, false);
18695 if (instr_is_comptime(result_loc)) {18662 if (instr_is_comptime(result_loc)) {
18696 casted_ptr = ir_const(ira, suspend_source_instr, struct_ptr_type);18663 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);
18698 casted_ptr->value->type = struct_ptr_type;18665 casted_ptr->value->type = struct_ptr_type;
18699 } else {18666 } else {
18700 casted_ptr = result_loc;18667 casted_ptr = result_loc;
...@@ -18707,8 +18674,8 @@ static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr...@@ -18707,8 +18674,8 @@ static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr
18707 ZigValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val,18674 ZigValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val,
18708 suspend_source_instr->source_node);18675 suspend_source_instr->source_node);
18709 struct_val->special = ConstValSpecialStatic;18676 struct_val->special = ConstValSpecialStatic;
18710 struct_val->data.x_struct.fields = realloc_const_vals_ptrs(struct_val->data.x_struct.fields,18677 struct_val->data.x_struct.fields = realloc_const_vals_ptrs(ira->codegen,
18711 old_field_count, new_field_count);18678 struct_val->data.x_struct.fields, old_field_count, new_field_count);
1871218679
18713 ZigValue *field_val = struct_val->data.x_struct.fields[old_field_count];18680 ZigValue *field_val = struct_val->data.x_struct.fields[old_field_count];
18714 field_val->special = ConstValSpecialUndef;18681 field_val->special = ConstValSpecialUndef;
...@@ -19008,10 +18975,10 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod...@@ -19008,10 +18975,10 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
19008 if (!arg_val)18975 if (!arg_val)
19009 return false;18976 return false;
19010 } else {18977 } else {
19011 arg_val = create_const_runtime(casted_arg->value->type);18978 arg_val = create_const_runtime(ira->codegen, casted_arg->value->type);
19012 }18979 }
19013 if (arg_part_of_generic_id) {18980 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);
19015 generic_id->param_count += 1;18982 generic_id->param_count += 1;
19016 }18983 }
1901718984
...@@ -19160,7 +19127,7 @@ static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr,...@@ -19160,7 +19127,7 @@ static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr,
19160 if (dest_val == nullptr)19127 if (dest_val == nullptr)
19161 return ira->codegen->invalid_inst_gen;19128 return ira->codegen->invalid_inst_gen;
19162 if (dest_val->special != ConstValSpecialRuntime) {19129 if (dest_val->special != ConstValSpecialRuntime) {
19163 copy_const_val(dest_val, value->value);19130 copy_const_val(ira->codegen, dest_val, value->value);
1916419131
19165 if (ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar &&19132 if (ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar &&
19166 !ira->new_irb.current_basic_block->must_be_comptime_source_instr)19133 !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,...@@ -19395,8 +19362,6 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
19395 {19362 {
19396 return ira->codegen->invalid_inst_gen;19363 return ira->codegen->invalid_inst_gen;
19397 }19364 }
19398 destroy(result_ptr, "ZigValue");
19399 result_ptr = nullptr;
1940019365
19401 if (inferred_err_set_type != nullptr) {19366 if (inferred_err_set_type != nullptr) {
19402 inferred_err_set_type->data.error_set.incomplete = false;19367 inferred_err_set_type->data.error_set.incomplete = false;
...@@ -19404,7 +19369,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,...@@ -19404,7 +19369,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
19404 ErrorTableEntry *err = result->data.x_err_union.error_set->data.x_err_set;19369 ErrorTableEntry *err = result->data.x_err_union.error_set->data.x_err_set;
19405 if (err != nullptr) {19370 if (err != nullptr) {
19406 inferred_err_set_type->data.error_set.err_count = 1;19371 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 *>();
19408 inferred_err_set_type->data.error_set.errors[0] = err;19373 inferred_err_set_type->data.error_set.errors[0] = err;
19409 }19374 }
19410 ZigType *fn_inferred_err_set_type = result->type->data.error_union.err_set_type;19375 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,...@@ -19438,12 +19403,12 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1943819403
19439 size_t new_fn_arg_count = first_arg_1_or_0 + args_len;19404 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
19443 // Fork a scope of the function with known values for the parameters.19408 // Fork a scope of the function with known values for the parameters.
19444 Scope *parent_scope = fn_entry->fndef_scope->base.parent;19409 Scope *parent_scope = fn_entry->fndef_scope->base.parent;
19445 ZigFn *impl_fn = create_fn(ira->codegen, fn_proto_node);19410 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);
19447 buf_init_from_buf(&impl_fn->symbol_name, &fn_entry->symbol_name);19412 buf_init_from_buf(&impl_fn->symbol_name, &fn_entry->symbol_name);
19448 impl_fn->fndef_scope = create_fndef_scope(ira->codegen, impl_fn->body_node, parent_scope, impl_fn);19413 impl_fn->fndef_scope = create_fndef_scope(ira->codegen, impl_fn->body_node, parent_scope, impl_fn);
19449 impl_fn->child_scope = &impl_fn->fndef_scope->base;19414 impl_fn->child_scope = &impl_fn->fndef_scope->base;
...@@ -19454,10 +19419,10 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,...@@ -19454,10 +19419,10 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
1945419419
19455 // TODO maybe GenericFnTypeId can be replaced with using the child_scope directly19420 // TODO maybe GenericFnTypeId can be replaced with using the child_scope directly
19456 // as the key in generic_table19421 // as the key in generic_table
19457 GenericFnTypeId *generic_id = allocate<GenericFnTypeId>(1);19422 GenericFnTypeId *generic_id = heap::c_allocator.create<GenericFnTypeId>();
19458 generic_id->fn_entry = fn_entry;19423 generic_id->fn_entry = fn_entry;
19459 generic_id->param_count = 0;19424 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);
19461 size_t next_proto_i = 0;19426 size_t next_proto_i = 0;
1946219427
19463 if (first_arg_ptr) {19428 if (first_arg_ptr) {
...@@ -19517,7 +19482,6 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,...@@ -19517,7 +19482,6 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
19517 IrInstGenConst *const_instruction = ir_create_inst_noval<IrInstGenConst>(&ira->new_irb,19482 IrInstGenConst *const_instruction = ir_create_inst_noval<IrInstGenConst>(&ira->new_irb,
19518 impl_fn->child_scope, fn_proto_node->data.fn_proto.align_expr);19483 impl_fn->child_scope, fn_proto_node->data.fn_proto.align_expr);
19519 const_instruction->base.value = align_result;19484 const_instruction->base.value = align_result;
19520 destroy(result_ptr, "ZigValue");
1952119485
19522 uint32_t align_bytes = 0;19486 uint32_t align_bytes = 0;
19523 ir_resolve_align(ira, &const_instruction->base, nullptr, &align_bytes);19487 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,...@@ -19650,7 +19614,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
19650 }19614 }
1965119615
1965219616
19653 IrInstGen **casted_args = allocate<IrInstGen *>(call_param_count);19617 IrInstGen **casted_args = heap::c_allocator.allocate<IrInstGen *>(call_param_count);
19654 size_t next_arg_index = 0;19618 size_t next_arg_index = 0;
19655 if (first_arg_ptr) {19619 if (first_arg_ptr) {
19656 assert(first_arg_ptr->value->type->id == ZigTypeIdPointer);19620 assert(first_arg_ptr->value->type->id == ZigTypeIdPointer);
...@@ -19782,7 +19746,7 @@ static IrInstGen *ir_analyze_fn_call_src(IrAnalyze *ira, IrInstSrcCall *call_ins...@@ -19782,7 +19746,7 @@ static IrInstGen *ir_analyze_fn_call_src(IrAnalyze *ira, IrInstSrcCall *call_ins
19782 return ira->codegen->invalid_inst_gen;19746 return ira->codegen->invalid_inst_gen;
19783 new_stack_src = &call_instruction->new_stack->base;19747 new_stack_src = &call_instruction->new_stack->base;
19784 }19748 }
19785 IrInstGen **args_ptr = allocate<IrInstGen *>(call_instruction->arg_count, "IrInstGen *");19749 IrInstGen **args_ptr = heap::c_allocator.allocate<IrInstGen *>(call_instruction->arg_count);
19786 for (size_t i = 0; i < call_instruction->arg_count; i += 1) {19750 for (size_t i = 0; i < call_instruction->arg_count; i += 1) {
19787 args_ptr[i] = call_instruction->args[i]->child;19751 args_ptr[i] = call_instruction->args[i]->child;
19788 if (type_is_invalid(args_ptr[i]->value->type))19752 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...@@ -19798,7 +19762,7 @@ static IrInstGen *ir_analyze_fn_call_src(IrAnalyze *ira, IrInstSrcCall *call_ins
19798 first_arg_ptr, first_arg_ptr_src, modifier, new_stack, new_stack_src,19762 first_arg_ptr, first_arg_ptr_src, modifier, new_stack, new_stack_src,
19799 call_instruction->is_async_call_builtin, args_ptr, call_instruction->arg_count, ret_ptr,19763 call_instruction->is_async_call_builtin, args_ptr, call_instruction->arg_count, ret_ptr,
19800 call_instruction->result_loc);19764 call_instruction->result_loc);
19801 deallocate(args_ptr, call_instruction->arg_count, "IrInstGen *");19765 heap::c_allocator.deallocate(args_ptr, call_instruction->arg_count);
19802 return result;19766 return result;
19803}19767}
1980419768
...@@ -19918,7 +19882,7 @@ static IrInstGen *ir_analyze_instruction_call_extra(IrAnalyze *ira, IrInstSrcCal...@@ -19918,7 +19882,7 @@ static IrInstGen *ir_analyze_instruction_call_extra(IrAnalyze *ira, IrInstSrcCal
1991819882
19919 if (is_tuple(args_type)) {19883 if (is_tuple(args_type)) {
19920 args_len = args_type->data.structure.src_field_count;19884 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);
19922 for (size_t i = 0; i < args_len; i += 1) {19886 for (size_t i = 0; i < args_len; i += 1) {
19923 TypeStructField *arg_field = args_type->data.structure.fields[i];19887 TypeStructField *arg_field = args_type->data.structure.fields[i];
19924 args_ptr[i] = ir_analyze_struct_value_field_value(ira, &instruction->base.base, args, arg_field);19888 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...@@ -19931,12 +19895,12 @@ static IrInstGen *ir_analyze_instruction_call_extra(IrAnalyze *ira, IrInstSrcCal
19931 }19895 }
19932 IrInstGen *result = ir_analyze_call_extra(ira, &instruction->base.base, instruction->options,19896 IrInstGen *result = ir_analyze_call_extra(ira, &instruction->base.base, instruction->options,
19933 instruction->fn_ref, args_ptr, args_len, instruction->result_loc);19897 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);
19935 return result;19899 return result;
19936}19900}
1993719901
19938static IrInstGen *ir_analyze_instruction_call_args(IrAnalyze *ira, IrInstSrcCallArgs *instruction) {19902static 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);
19940 for (size_t i = 0; i < instruction->args_len; i += 1) {19904 for (size_t i = 0; i < instruction->args_len; i += 1) {
19941 args_ptr[i] = instruction->args_ptr[i]->child;19905 args_ptr[i] = instruction->args_ptr[i]->child;
19942 if (type_is_invalid(args_ptr[i]->value->type))19906 if (type_is_invalid(args_ptr[i]->value->type))
...@@ -19945,7 +19909,7 @@ static IrInstGen *ir_analyze_instruction_call_args(IrAnalyze *ira, IrInstSrcCall...@@ -19945,7 +19909,7 @@ static IrInstGen *ir_analyze_instruction_call_args(IrAnalyze *ira, IrInstSrcCall
1994519909
19946 IrInstGen *result = ir_analyze_call_extra(ira, &instruction->base.base, instruction->options,19910 IrInstGen *result = ir_analyze_call_extra(ira, &instruction->base.base, instruction->options,
19947 instruction->fn_ref, args_ptr, instruction->args_len, instruction->result_loc);19911 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);
19949 return result;19913 return result;
19950}19914}
1995119915
...@@ -20020,7 +19984,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source...@@ -20020,7 +19984,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source
2002019984
20021 if (dst_size <= src_size) {19985 if (dst_size <= src_size) {
20022 if (src_size == dst_size && types_have_same_zig_comptime_repr(codegen, out_val->type, pointee->type)) {19986 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);
20024 return ErrorNone;19988 return ErrorNone;
20025 }19989 }
20026 Buf buf = BUF_INIT;19990 Buf buf = BUF_INIT;
...@@ -20088,7 +20052,7 @@ static IrInstGen *ir_analyze_optional_type(IrAnalyze *ira, IrInstSrcUnOp *instru...@@ -20088,7 +20052,7 @@ static IrInstGen *ir_analyze_optional_type(IrAnalyze *ira, IrInstSrcUnOp *instru
20088 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type);20052 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type);
20089 result->value->special = ConstValSpecialLazy;20053 result->value->special = ConstValSpecialLazy;
2009020054
20091 LazyValueOptType *lazy_opt_type = allocate<LazyValueOptType>(1, "LazyValueOptType");20055 LazyValueOptType *lazy_opt_type = heap::c_allocator.create<LazyValueOptType>();
20092 lazy_opt_type->ira = ira; ira_ref(ira);20056 lazy_opt_type->ira = ira; ira_ref(ira);
20093 result->value->data.x_lazy = &lazy_opt_type->base;20057 result->value->data.x_lazy = &lazy_opt_type->base;
20094 lazy_opt_type->base.id = LazyValueIdOptType;20058 lazy_opt_type->base.id = LazyValueIdOptType;
...@@ -20372,7 +20336,7 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i...@@ -20372,7 +20336,7 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i
2037220336
20373 if (value->value->special != ConstValSpecialRuntime) {20337 if (value->value->special != ConstValSpecialRuntime) {
20374 IrInstGen *result = ir_const(ira, &phi_instruction->base.base, nullptr);20338 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);
20376 return result;20340 return result;
20377 } else {20341 } else {
20378 return value;20342 return value;
...@@ -20386,7 +20350,7 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i...@@ -20386,7 +20350,7 @@ static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_i
20386 peer_parent->peers.length >= 2)20350 peer_parent->peers.length >= 2)
20387 {20351 {
20388 if (peer_parent->resolved_type == nullptr) {20352 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);
20390 for (size_t i = 0; i < peer_parent->peers.length; i += 1) {20354 for (size_t i = 0; i < peer_parent->peers.length; i += 1) {
20391 ResultLocPeer *this_peer = peer_parent->peers.at(i);20355 ResultLocPeer *this_peer = peer_parent->peers.at(i);
2039220356
...@@ -20759,7 +20723,7 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP...@@ -20759,7 +20723,7 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
20759 if (index == array_len && array_type->data.array.sentinel != nullptr) {20723 if (index == array_len && array_type->data.array.sentinel != nullptr) {
20760 ZigType *elem_type = array_type->data.array.child_type;20724 ZigType *elem_type = array_type->data.array.child_type;
20761 IrInstGen *sentinel_elem = ir_const(ira, &elem_ptr_instruction->base.base, elem_type);20725 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);
20763 return ir_get_ref(ira, &elem_ptr_instruction->base.base, sentinel_elem, true, false);20727 return ir_get_ref(ira, &elem_ptr_instruction->base.base, sentinel_elem, true, false);
20764 }20728 }
20765 if (index >= array_len) {20729 if (index >= array_len) {
...@@ -20823,7 +20787,7 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP...@@ -20823,7 +20787,7 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
20823 {20787 {
20824 if (array_type->id == ZigTypeIdArray || array_type->id == ZigTypeIdVector) {20788 if (array_type->id == ZigTypeIdArray || array_type->id == ZigTypeIdVector) {
20825 array_ptr_val->data.x_array.special = ConstArraySpecialNone;20789 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);
20827 array_ptr_val->special = ConstValSpecialStatic;20791 array_ptr_val->special = ConstValSpecialStatic;
20828 for (size_t i = 0; i < array_type->data.array.len; i += 1) {20792 for (size_t i = 0; i < array_type->data.array.len; i += 1) {
20829 ZigValue *elem_val = &array_ptr_val->data.x_array.data.s_none.elements[i];20793 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...@@ -20846,11 +20810,11 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
20846 return ira->codegen->invalid_inst_gen;20810 return ira->codegen->invalid_inst_gen;
20847 }20811 }
2084820812
20849 ZigValue *array_init_val = create_const_vals(1);20813 ZigValue *array_init_val = ira->codegen->pass1_arena->create<ZigValue>();
20850 array_init_val->special = ConstValSpecialStatic;20814 array_init_val->special = ConstValSpecialStatic;
20851 array_init_val->type = actual_array_type;20815 array_init_val->type = actual_array_type;
20852 array_init_val->data.x_array.special = ConstArraySpecialNone;20816 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);
20854 array_init_val->special = ConstValSpecialStatic;20818 array_init_val->special = ConstValSpecialStatic;
20855 for (size_t i = 0; i < actual_array_type->data.array.len; i += 1) {20819 for (size_t i = 0; i < actual_array_type->data.array.len; i += 1) {
20856 ZigValue *elem_val = &array_init_val->data.x_array.data.s_none.elements[i];20820 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...@@ -21176,7 +21140,7 @@ static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_ins
21176 if (field->is_comptime) {21140 if (field->is_comptime) {
21177 IrInstGen *elem = ir_const(ira, source_instr, field_type);21141 IrInstGen *elem = ir_const(ira, source_instr, field_type);
21178 memoize_field_init_val(ira->codegen, struct_type, field);21142 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);
21180 return ir_get_ref2(ira, source_instr, elem, field_type, true, false);21144 return ir_get_ref2(ira, source_instr, elem, field_type, true, false);
21181 }21145 }
21182 switch (type_has_one_possible_value(ira->codegen, field_type)) {21146 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...@@ -21224,7 +21188,7 @@ static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_ins
21224 if (type_is_invalid(struct_val->type))21188 if (type_is_invalid(struct_val->type))
21225 return ira->codegen->invalid_inst_gen;21189 return ira->codegen->invalid_inst_gen;
21226 if (initializing && struct_val->special == ConstValSpecialUndef) {21190 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);
21228 struct_val->special = ConstValSpecialStatic;21192 struct_val->special = ConstValSpecialStatic;
21229 for (size_t i = 0; i < struct_type->data.structure.src_field_count; i += 1) {21193 for (size_t i = 0; i < struct_type->data.structure.src_field_count; i += 1) {
21230 ZigValue *field_val = struct_val->data.x_struct.fields[i];21194 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,...@@ -21266,7 +21230,7 @@ static IrInstGen *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name,
21266 ZigType *container_ptr_type = container_ptr->value->type;21230 ZigType *container_ptr_type = container_ptr->value->type;
21267 ir_assert(container_ptr_type->id == ZigTypeIdPointer, source_instr);21231 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>();
21270 inferred_struct_field->inferred_struct_type = container_type;21234 inferred_struct_field->inferred_struct_type = container_type;
21271 inferred_struct_field->field_name = field_name;21235 inferred_struct_field->field_name = field_name;
2127221236
...@@ -21286,7 +21250,7 @@ static IrInstGen *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name,...@@ -21286,7 +21250,7 @@ static IrInstGen *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name,
21286 } else {21250 } else {
21287 result = ir_const(ira, source_instr, field_ptr_type);21251 result = ir_const(ira, source_instr, field_ptr_type);
21288 }21252 }
21289 copy_const_val(result->value, ptr_val);21253 copy_const_val(ira->codegen, result->value, ptr_val);
21290 result->value->type = field_ptr_type;21254 result->value->type = field_ptr_type;
21291 return result;21255 return result;
21292 }21256 }
...@@ -21357,7 +21321,7 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name...@@ -21357,7 +21321,7 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name
21357 return ira->codegen->invalid_inst_gen;21321 return ira->codegen->invalid_inst_gen;
2135821322
21359 if (initializing) {21323 if (initializing) {
21360 ZigValue *payload_val = create_const_vals(1);21324 ZigValue *payload_val = ira->codegen->pass1_arena->create<ZigValue>();
21361 payload_val->special = ConstValSpecialUndef;21325 payload_val->special = ConstValSpecialUndef;
21362 payload_val->type = field_type;21326 payload_val->type = field_type;
21363 payload_val->parent.id = ConstParentIdUnion;21327 payload_val->parent.id = ConstParentIdUnion;
...@@ -21540,7 +21504,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel...@@ -21540,7 +21504,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
21540 }21504 }
21541 } else if (is_array_ref(container_type) && !field_ptr_instruction->initializing) {21505 } else if (is_array_ref(container_type) && !field_ptr_instruction->initializing) {
21542 if (buf_eql_str(field_name, "len")) {21506 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>();
21544 if (container_type->id == ZigTypeIdPointer) {21508 if (container_type->id == ZigTypeIdPointer) {
21545 init_const_usize(ira->codegen, len_val, container_type->data.pointer.child_type->data.array.len);21509 init_const_usize(ira->codegen, len_val, container_type->data.pointer.child_type->data.array.len);
21546 } else {21510 } else {
...@@ -21586,7 +21550,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel...@@ -21586,7 +21550,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
21586 bool ptr_is_const = true;21550 bool ptr_is_const = true;
21587 bool ptr_is_volatile = false;21551 bool ptr_is_volatile = false;
21588 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,21552 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,
21590 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);21554 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
21591 }21555 }
21592 }21556 }
...@@ -21615,7 +21579,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel...@@ -21615,7 +21579,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
21615 bool ptr_is_const = true;21579 bool ptr_is_const = true;
21616 bool ptr_is_volatile = false;21580 bool ptr_is_volatile = false;
21617 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,21581 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,
21619 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);21583 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
21620 }21584 }
21621 }21585 }
...@@ -21633,7 +21597,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel...@@ -21633,7 +21597,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
21633 if (existing_entry) {21597 if (existing_entry) {
21634 err_entry = existing_entry->value;21598 err_entry = existing_entry->value;
21635 } else {21599 } else {
21636 err_entry = allocate<ErrorTableEntry>(1);21600 err_entry = heap::c_allocator.create<ErrorTableEntry>();
21637 err_entry->decl_node = field_ptr_instruction->base.base.source_node;21601 err_entry->decl_node = field_ptr_instruction->base.base.source_node;
21638 buf_init_from_buf(&err_entry->name, field_name);21602 buf_init_from_buf(&err_entry->name, field_name);
21639 size_t error_value_count = ira->codegen->errors_by_index.length;21603 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...@@ -21660,7 +21624,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
21660 }21624 }
21661 err_set_type = child_type;21625 err_set_type = child_type;
21662 }21626 }
21663 ZigValue *const_val = create_const_vals(1);21627 ZigValue *const_val = ira->codegen->pass1_arena->create<ZigValue>();
21664 const_val->special = ConstValSpecialStatic;21628 const_val->special = ConstValSpecialStatic;
21665 const_val->type = err_set_type;21629 const_val->type = err_set_type;
21666 const_val->data.x_err_set = err_entry;21630 const_val->data.x_err_set = err_entry;
...@@ -21674,7 +21638,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel...@@ -21674,7 +21638,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
21674 bool ptr_is_const = true;21638 bool ptr_is_const = true;
21675 bool ptr_is_volatile = false;21639 bool ptr_is_volatile = false;
21676 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,21640 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,
21678 child_type->data.integral.bit_count, false),21642 child_type->data.integral.bit_count, false),
21679 ira->codegen->builtin_types.entry_num_lit_int,21643 ira->codegen->builtin_types.entry_num_lit_int,
21680 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);21644 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
...@@ -21696,7 +21660,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel...@@ -21696,7 +21660,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
21696 bool ptr_is_const = true;21660 bool ptr_is_const = true;
21697 bool ptr_is_volatile = false;21661 bool ptr_is_volatile = false;
21698 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,21662 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,
21700 child_type->data.floating.bit_count, false),21664 child_type->data.floating.bit_count, false),
21701 ira->codegen->builtin_types.entry_num_lit_int,21665 ira->codegen->builtin_types.entry_num_lit_int,
21702 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);21666 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
...@@ -21723,7 +21687,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel...@@ -21723,7 +21687,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
21723 return ira->codegen->invalid_inst_gen;21687 return ira->codegen->invalid_inst_gen;
21724 }21688 }
21725 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,21689 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,
21727 get_ptr_align(ira->codegen, child_type), false),21691 get_ptr_align(ira->codegen, child_type), false),
21728 ira->codegen->builtin_types.entry_num_lit_int,21692 ira->codegen->builtin_types.entry_num_lit_int,
21729 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);21693 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
...@@ -21745,7 +21709,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel...@@ -21745,7 +21709,7 @@ static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFiel
21745 bool ptr_is_const = true;21709 bool ptr_is_const = true;
21746 bool ptr_is_volatile = false;21710 bool ptr_is_volatile = false;
21747 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,21711 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,
21749 child_type->data.array.len, false),21713 child_type->data.array.len, false),
21750 ira->codegen->builtin_types.entry_num_lit_int,21714 ira->codegen->builtin_types.entry_num_lit_int,
21751 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);21715 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
...@@ -22025,7 +21989,7 @@ static IrInstGen *ir_analyze_instruction_slice_type(IrAnalyze *ira, IrInstSrcSli...@@ -22025,7 +21989,7 @@ static IrInstGen *ir_analyze_instruction_slice_type(IrAnalyze *ira, IrInstSrcSli
22025 IrInstGen *result = ir_const(ira, &slice_type_instruction->base.base, ira->codegen->builtin_types.entry_type);21989 IrInstGen *result = ir_const(ira, &slice_type_instruction->base.base, ira->codegen->builtin_types.entry_type);
22026 result->value->special = ConstValSpecialLazy;21990 result->value->special = ConstValSpecialLazy;
2202721991
22028 LazyValueSliceType *lazy_slice_type = allocate<LazyValueSliceType>(1, "LazyValueSliceType");21992 LazyValueSliceType *lazy_slice_type = heap::c_allocator.create<LazyValueSliceType>();
22029 lazy_slice_type->ira = ira; ira_ref(ira);21993 lazy_slice_type->ira = ira; ira_ref(ira);
22030 result->value->data.x_lazy = &lazy_slice_type->base;21994 result->value->data.x_lazy = &lazy_slice_type->base;
22031 lazy_slice_type->base.id = LazyValueIdSliceType;21995 lazy_slice_type->base.id = LazyValueIdSliceType;
...@@ -22098,8 +22062,8 @@ static IrInstGen *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstSrcAsm *asm_i...@@ -22098,8 +22062,8 @@ static IrInstGen *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstSrcAsm *asm_i
2209822062
22099 // TODO validate the output types and variable types22063 // TODO validate the output types and variable types
2210022064
22101 IrInstGen **input_list = allocate<IrInstGen *>(asm_expr->input_list.length);22065 IrInstGen **input_list = heap::c_allocator.allocate<IrInstGen *>(asm_expr->input_list.length);
22102 IrInstGen **output_types = allocate<IrInstGen *>(asm_expr->output_list.length);22066 IrInstGen **output_types = heap::c_allocator.allocate<IrInstGen *>(asm_expr->output_list.length);
2210322067
22104 ZigType *return_type = ira->codegen->builtin_types.entry_void;22068 ZigType *return_type = ira->codegen->builtin_types.entry_void;
22105 for (size_t i = 0; i < asm_expr->output_list.length; i += 1) {22069 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...@@ -22138,7 +22102,7 @@ static IrInstGen *ir_analyze_instruction_array_type(IrAnalyze *ira, IrInstSrcArr
22138 IrInstGen *result = ir_const(ira, &array_type_instruction->base.base, ira->codegen->builtin_types.entry_type);22102 IrInstGen *result = ir_const(ira, &array_type_instruction->base.base, ira->codegen->builtin_types.entry_type);
22139 result->value->special = ConstValSpecialLazy;22103 result->value->special = ConstValSpecialLazy;
2214022104
22141 LazyValueArrayType *lazy_array_type = allocate<LazyValueArrayType>(1, "LazyValueArrayType");22105 LazyValueArrayType *lazy_array_type = heap::c_allocator.create<LazyValueArrayType>();
22142 lazy_array_type->ira = ira; ira_ref(ira);22106 lazy_array_type->ira = ira; ira_ref(ira);
22143 result->value->data.x_lazy = &lazy_array_type->base;22107 result->value->data.x_lazy = &lazy_array_type->base;
22144 lazy_array_type->base.id = LazyValueIdArrayType;22108 lazy_array_type->base.id = LazyValueIdArrayType;
...@@ -22163,7 +22127,7 @@ static IrInstGen *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstSrcSizeOf...@@ -22163,7 +22127,7 @@ static IrInstGen *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstSrcSizeOf
22163 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int);22127 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int);
22164 result->value->special = ConstValSpecialLazy;22128 result->value->special = ConstValSpecialLazy;
2216522129
22166 LazyValueSizeOf *lazy_size_of = allocate<LazyValueSizeOf>(1, "LazyValueSizeOf");22130 LazyValueSizeOf *lazy_size_of = heap::c_allocator.create<LazyValueSizeOf>();
22167 lazy_size_of->ira = ira; ira_ref(ira);22131 lazy_size_of->ira = ira; ira_ref(ira);
22168 result->value->data.x_lazy = &lazy_size_of->base;22132 result->value->data.x_lazy = &lazy_size_of->base;
22169 lazy_size_of->base.id = LazyValueIdSizeOf;22133 lazy_size_of->base.id = LazyValueIdSizeOf;
...@@ -22283,7 +22247,7 @@ static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* sou...@@ -22283,7 +22247,7 @@ static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* sou
22283 return ira->codegen->invalid_inst_gen;22247 return ira->codegen->invalid_inst_gen;
22284 case OnePossibleValueNo:22248 case OnePossibleValueNo:
22285 if (!same_comptime_repr) {22249 if (!same_comptime_repr) {
22286 ZigValue *payload_val = create_const_vals(1);22250 ZigValue *payload_val = ira->codegen->pass1_arena->create<ZigValue>();
22287 payload_val->type = child_type;22251 payload_val->type = child_type;
22288 payload_val->special = ConstValSpecialUndef;22252 payload_val->special = ConstValSpecialUndef;
22289 payload_val->parent.id = ConstParentIdOptionalPayload;22253 payload_val->parent.id = ConstParentIdOptionalPayload;
...@@ -22530,7 +22494,7 @@ static IrInstGen *ir_analyze_instruction_switch_br(IrAnalyze *ira,...@@ -22530,7 +22494,7 @@ static IrInstGen *ir_analyze_instruction_switch_br(IrAnalyze *ira,
22530 }22494 }
22531 }22495 }
2253222496
22533 IrInstGenSwitchBrCase *cases = allocate<IrInstGenSwitchBrCase>(case_count);22497 IrInstGenSwitchBrCase *cases = heap::c_allocator.allocate<IrInstGenSwitchBrCase>(case_count);
22534 for (size_t i = 0; i < case_count; i += 1) {22498 for (size_t i = 0; i < case_count; i += 1) {
22535 IrInstSrcSwitchBrCase *old_case = &switch_br_instruction->cases[i];22499 IrInstSrcSwitchBrCase *old_case = &switch_br_instruction->cases[i];
22536 IrInstGenSwitchBrCase *new_case = &cases[i];22500 IrInstGenSwitchBrCase *new_case = &cases[i];
...@@ -22615,7 +22579,7 @@ static IrInstGen *ir_analyze_instruction_switch_target(IrAnalyze *ira,...@@ -22615,7 +22579,7 @@ static IrInstGen *ir_analyze_instruction_switch_target(IrAnalyze *ira,
22615 case ZigTypeIdErrorSet: {22579 case ZigTypeIdErrorSet: {
22616 if (pointee_val) {22580 if (pointee_val) {
22617 IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, nullptr);22581 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);
22619 result->value->type = target_type;22583 result->value->type = target_type;
22620 return result;22584 return result;
22621 }22585 }
...@@ -22835,7 +22799,7 @@ static IrInstGen *ir_analyze_instruction_switch_else_var(IrAnalyze *ira,...@@ -22835,7 +22799,7 @@ static IrInstGen *ir_analyze_instruction_switch_else_var(IrAnalyze *ira,
22835 return target_value_ptr;22799 return target_value_ptr;
22836 }22800 }
22837 // Make note of the errors handled by other cases22801 // 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);
22839 // We may not have any case in the switch if this is a lone else22803 // We may not have any case in the switch if this is a lone else
22840 const size_t switch_cases = instruction->switch_br ? instruction->switch_br->case_count : 0;22804 const size_t switch_cases = instruction->switch_br ? instruction->switch_br->case_count : 0;
22841 for (size_t case_i = 0; case_i < switch_cases; case_i += 1) {22805 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,...@@ -22871,7 +22835,7 @@ static IrInstGen *ir_analyze_instruction_switch_else_var(IrAnalyze *ira,
22871 buf_appendf(&err_set_type->name, "%s,", buf_ptr(&error_entry->name));22835 buf_appendf(&err_set_type->name, "%s,", buf_ptr(&error_entry->name));
22872 }22836 }
22873 }22837 }
22874 free(errors);22838 heap::c_allocator.deallocate(errors, ira->codegen->errors_by_index.length);
2287522839
22876 err_set_type->data.error_set.err_count = result_list.length;22840 err_set_type->data.error_set.err_count = result_list.length;
22877 err_set_type->data.error_set.errors = result_list.items;22841 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...@@ -23019,7 +22983,7 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc
2301922983
23020 IrInstGen *first_non_const_instruction = nullptr;22984 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);
23023 ZigList<IrInstGen *> const_ptrs = {};22987 ZigList<IrInstGen *> const_ptrs = {};
2302422988
23025 bool is_comptime = ir_should_inline(ira->old_irb.exec, source_instr->scope)22989 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...@@ -23090,7 +23054,7 @@ static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *sourc
23090 return ira->codegen->invalid_inst_gen;23054 return ira->codegen->invalid_inst_gen;
2309123055
23092 IrInstGen *runtime_inst = ir_const(ira, source_instr, field->init_val->type);23056 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
23095 IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, source_instr, field, result_loc,23059 IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, source_instr, field, result_loc,
23096 container_type, true);23060 container_type, true);
...@@ -23354,7 +23318,7 @@ static IrInstGen *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstSrcErrNa...@@ -23354,7 +23318,7 @@ static IrInstGen *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstSrcErrNa
23354 err->cached_error_name_val = create_const_slice(ira->codegen, array_val, 0, buf_len(&err->name), true);23318 err->cached_error_name_val = create_const_slice(ira->codegen, array_val, 0, buf_len(&err->name), true);
23355 }23319 }
23356 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);23320 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);
23358 result->value->type = str_type;23322 result->value->type = str_type;
23359 return result;23323 return result;
23360 }23324 }
...@@ -23680,11 +23644,11 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa...@@ -23680,11 +23644,11 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa
23680 }23644 }
23681 }23645 }
2368223646
23683 ZigValue *declaration_array = create_const_vals(1);23647 ZigValue *declaration_array = ira->codegen->pass1_arena->create<ZigValue>();
23684 declaration_array->special = ConstValSpecialStatic;23648 declaration_array->special = ConstValSpecialStatic;
23685 declaration_array->type = get_array_type(ira->codegen, type_info_declaration_type, declaration_count, nullptr);23649 declaration_array->type = get_array_type(ira->codegen, type_info_declaration_type, declaration_count, nullptr);
23686 declaration_array->data.x_array.special = ConstArraySpecialNone;23650 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);
23688 init_const_slice(ira->codegen, out_val, declaration_array, 0, declaration_count, false);23652 init_const_slice(ira->codegen, out_val, declaration_array, 0, declaration_count, false);
2368923653
23690 // Loop through the declarations and generate info.23654 // Loop through the declarations and generate info.
...@@ -23706,7 +23670,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa...@@ -23706,7 +23670,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa
23706 declaration_val->special = ConstValSpecialStatic;23670 declaration_val->special = ConstValSpecialStatic;
23707 declaration_val->type = type_info_declaration_type;23671 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);
23710 ZigValue *name = create_const_str_lit(ira->codegen, curr_entry->key)->data.x_ptr.data.ref.pointee;23674 ZigValue *name = create_const_str_lit(ira->codegen, curr_entry->key)->data.x_ptr.data.ref.pointee;
23711 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(curr_entry->key), true);23675 init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(curr_entry->key), true);
23712 inner_fields[1]->special = ConstValSpecialStatic;23676 inner_fields[1]->special = ConstValSpecialStatic;
...@@ -23737,7 +23701,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa...@@ -23737,7 +23701,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa
23737 // 1: Data.Var: type23701 // 1: Data.Var: type
23738 bigint_init_unsigned(&inner_fields[2]->data.x_union.tag, 1);23702 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>();
23741 payload->special = ConstValSpecialStatic;23705 payload->special = ConstValSpecialStatic;
23742 payload->type = ira->codegen->builtin_types.entry_type;23706 payload->type = ira->codegen->builtin_types.entry_type;
23743 payload->data.x_type = var->const_value->type;23707 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...@@ -23758,13 +23722,13 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa
2375823722
23759 AstNodeFnProto *fn_node = &fn_entry->proto_node->data.fn_proto;23723 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>();
23762 fn_decl_val->special = ConstValSpecialStatic;23726 fn_decl_val->special = ConstValSpecialStatic;
23763 fn_decl_val->type = type_info_fn_decl_type;23727 fn_decl_val->type = type_info_fn_decl_type;
23764 fn_decl_val->parent.id = ConstParentIdUnion;23728 fn_decl_val->parent.id = ConstParentIdUnion;
23765 fn_decl_val->parent.data.p_union.union_val = inner_fields[2];23729 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);
23768 fn_decl_val->data.x_struct.fields = fn_decl_fields;23732 fn_decl_val->data.x_struct.fields = fn_decl_fields;
2376923733
23770 // fn_type: type23734 // fn_type: type
...@@ -23802,7 +23766,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa...@@ -23802,7 +23766,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa
23802 0, 0, 0, false);23766 0, 0, 0, false);
23803 fn_decl_fields[5]->type = get_optional_type(ira->codegen, get_slice_type(ira->codegen, u8_ptr));23767 fn_decl_fields[5]->type = get_optional_type(ira->codegen, get_slice_type(ira->codegen, u8_ptr));
23804 if (fn_node->is_extern && fn_node->lib_name != nullptr && buf_len(fn_node->lib_name) > 0) {23768 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>();
23806 ZigValue *lib_name = create_const_str_lit(ira->codegen, fn_node->lib_name)->data.x_ptr.data.ref.pointee;23770 ZigValue *lib_name = create_const_str_lit(ira->codegen, fn_node->lib_name)->data.x_ptr.data.ref.pointee;
23807 init_const_slice(ira->codegen, fn_decl_fields[5]->data.x_optional, lib_name, 0,23771 init_const_slice(ira->codegen, fn_decl_fields[5]->data.x_optional, lib_name, 0,
23808 buf_len(fn_node->lib_name), true);23772 buf_len(fn_node->lib_name), true);
...@@ -23817,12 +23781,12 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa...@@ -23817,12 +23781,12 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa
23817 // arg_names: [][] const u823781 // arg_names: [][] const u8
23818 ensure_field_index(fn_decl_val->type, "arg_names", 7);23782 ensure_field_index(fn_decl_val->type, "arg_names", 7);
23819 size_t fn_arg_count = fn_entry->variable_list.length;23783 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>();
23821 fn_arg_name_array->special = ConstValSpecialStatic;23785 fn_arg_name_array->special = ConstValSpecialStatic;
23822 fn_arg_name_array->type = get_array_type(ira->codegen,23786 fn_arg_name_array->type = get_array_type(ira->codegen,
23823 get_slice_type(ira->codegen, u8_ptr), fn_arg_count, nullptr);23787 get_slice_type(ira->codegen, u8_ptr), fn_arg_count, nullptr);
23824 fn_arg_name_array->data.x_array.special = ConstArraySpecialNone;23788 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
23827 init_const_slice(ira->codegen, fn_decl_fields[7], fn_arg_name_array, 0, fn_arg_count, false);23791 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...@@ -23849,7 +23813,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigVa
23849 // This is a type.23813 // This is a type.
23850 bigint_init_unsigned(&inner_fields[2]->data.x_union.tag, 0);23814 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>();
23853 payload->special = ConstValSpecialStatic;23817 payload->special = ConstValSpecialStatic;
23854 payload->type = ira->codegen->builtin_types.entry_type;23818 payload->type = ira->codegen->builtin_types.entry_type;
23855 payload->data.x_type = type_entry;23819 payload->data.x_type = type_entry;
...@@ -23915,11 +23879,11 @@ static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_type_ent...@@ -23915,11 +23879,11 @@ static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_type_ent
23915 ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr);23879 ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr);
23916 assertNoError(type_resolve(ira->codegen, type_info_pointer_type, ResolveStatusSizeKnown));23880 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>();
23919 result->special = ConstValSpecialStatic;23883 result->special = ConstValSpecialStatic;
23920 result->type = type_info_pointer_type;23884 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);
23923 result->data.x_struct.fields = fields;23887 result->data.x_struct.fields = fields;
2392423888
23925 // size: Size23889 // size: Size
...@@ -23974,7 +23938,7 @@ static void make_enum_field_val(IrAnalyze *ira, ZigValue *enum_field_val, TypeEn...@@ -23974,7 +23938,7 @@ static void make_enum_field_val(IrAnalyze *ira, ZigValue *enum_field_val, TypeEn
23974 enum_field_val->special = ConstValSpecialStatic;23938 enum_field_val->special = ConstValSpecialStatic;
23975 enum_field_val->type = type_info_enum_field_type;23939 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);
23978 inner_fields[1]->special = ConstValSpecialStatic;23942 inner_fields[1]->special = ConstValSpecialStatic;
23979 inner_fields[1]->type = ira->codegen->builtin_types.entry_num_lit_int;23943 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...@@ -24020,11 +23984,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
24020 break;23984 break;
24021 case ZigTypeIdInt:23985 case ZigTypeIdInt:
24022 {23986 {
24023 result = create_const_vals(1);23987 result = ira->codegen->pass1_arena->create<ZigValue>();
24024 result->special = ConstValSpecialStatic;23988 result->special = ConstValSpecialStatic;
24025 result->type = ir_type_info_get_type(ira, "Int", nullptr);23989 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);
24028 result->data.x_struct.fields = fields;23992 result->data.x_struct.fields = fields;
2402923993
24030 // is_signed: bool23994 // is_signed: bool
...@@ -24042,11 +24006,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy...@@ -24042,11 +24006,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
24042 }24006 }
24043 case ZigTypeIdFloat:24007 case ZigTypeIdFloat:
24044 {24008 {
24045 result = create_const_vals(1);24009 result = ira->codegen->pass1_arena->create<ZigValue>();
24046 result->special = ConstValSpecialStatic;24010 result->special = ConstValSpecialStatic;
24047 result->type = ir_type_info_get_type(ira, "Float", nullptr);24011 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);
24050 result->data.x_struct.fields = fields;24014 result->data.x_struct.fields = fields;
2405124015
24052 // bits: u824016 // bits: u8
...@@ -24066,11 +24030,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy...@@ -24066,11 +24030,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
24066 }24030 }
24067 case ZigTypeIdArray:24031 case ZigTypeIdArray:
24068 {24032 {
24069 result = create_const_vals(1);24033 result = ira->codegen->pass1_arena->create<ZigValue>();
24070 result->special = ConstValSpecialStatic;24034 result->special = ConstValSpecialStatic;
24071 result->type = ir_type_info_get_type(ira, "Array", nullptr);24035 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);
24074 result->data.x_struct.fields = fields;24038 result->data.x_struct.fields = fields;
2407524039
24076 // len: usize24040 // len: usize
...@@ -24090,11 +24054,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy...@@ -24090,11 +24054,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
24090 break;24054 break;
24091 }24055 }
24092 case ZigTypeIdVector: {24056 case ZigTypeIdVector: {
24093 result = create_const_vals(1);24057 result = ira->codegen->pass1_arena->create<ZigValue>();
24094 result->special = ConstValSpecialStatic;24058 result->special = ConstValSpecialStatic;
24095 result->type = ir_type_info_get_type(ira, "Vector", nullptr);24059 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);
24098 result->data.x_struct.fields = fields;24062 result->data.x_struct.fields = fields;
2409924063
24100 // len: usize24064 // len: usize
...@@ -24112,11 +24076,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy...@@ -24112,11 +24076,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
24112 }24076 }
24113 case ZigTypeIdOptional:24077 case ZigTypeIdOptional:
24114 {24078 {
24115 result = create_const_vals(1);24079 result = ira->codegen->pass1_arena->create<ZigValue>();
24116 result->special = ConstValSpecialStatic;24080 result->special = ConstValSpecialStatic;
24117 result->type = ir_type_info_get_type(ira, "Optional", nullptr);24081 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);
24120 result->data.x_struct.fields = fields;24084 result->data.x_struct.fields = fields;
2412124085
24122 // child: type24086 // child: type
...@@ -24128,11 +24092,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy...@@ -24128,11 +24092,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
24128 break;24092 break;
24129 }24093 }
24130 case ZigTypeIdAnyFrame: {24094 case ZigTypeIdAnyFrame: {
24131 result = create_const_vals(1);24095 result = ira->codegen->pass1_arena->create<ZigValue>();
24132 result->special = ConstValSpecialStatic;24096 result->special = ConstValSpecialStatic;
24133 result->type = ir_type_info_get_type(ira, "AnyFrame", nullptr);24097 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);
24136 result->data.x_struct.fields = fields;24100 result->data.x_struct.fields = fields;
2413724101
24138 // child: ?type24102 // child: ?type
...@@ -24145,11 +24109,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy...@@ -24145,11 +24109,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
24145 }24109 }
24146 case ZigTypeIdEnum:24110 case ZigTypeIdEnum:
24147 {24111 {
24148 result = create_const_vals(1);24112 result = ira->codegen->pass1_arena->create<ZigValue>();
24149 result->special = ConstValSpecialStatic;24113 result->special = ConstValSpecialStatic;
24150 result->type = ir_type_info_get_type(ira, "Enum", nullptr);24114 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);
24153 result->data.x_struct.fields = fields;24117 result->data.x_struct.fields = fields;
2415424118
24155 // layout: ContainerLayout24119 // layout: ContainerLayout
...@@ -24171,11 +24135,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy...@@ -24171,11 +24135,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
24171 }24135 }
24172 uint32_t enum_field_count = type_entry->data.enumeration.src_field_count;24136 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>();
24175 enum_field_array->special = ConstValSpecialStatic;24139 enum_field_array->special = ConstValSpecialStatic;
24176 enum_field_array->type = get_array_type(ira->codegen, type_info_enum_field_type, enum_field_count, nullptr);24140 enum_field_array->type = get_array_type(ira->codegen, type_info_enum_field_type, enum_field_count, nullptr);
24177 enum_field_array->data.x_array.special = ConstArraySpecialNone;24141 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
24180 init_const_slice(ira->codegen, fields[2], enum_field_array, 0, enum_field_count, false);24144 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...@@ -24205,7 +24169,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
24205 }24169 }
24206 case ZigTypeIdErrorSet:24170 case ZigTypeIdErrorSet:
24207 {24171 {
24208 result = create_const_vals(1);24172 result = ira->codegen->pass1_arena->create<ZigValue>();
24209 result->special = ConstValSpecialStatic;24173 result->special = ConstValSpecialStatic;
24210 result->type = ir_type_info_get_type(ira, "ErrorSet", nullptr);24174 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...@@ -24220,15 +24184,15 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
24220 if ((err = type_resolve(ira->codegen, type_info_error_type, ResolveStatusSizeKnown))) {24184 if ((err = type_resolve(ira->codegen, type_info_error_type, ResolveStatusSizeKnown))) {
24221 zig_unreachable();24185 zig_unreachable();
24222 }24186 }
24223 ZigValue *slice_val = create_const_vals(1);24187 ZigValue *slice_val = ira->codegen->pass1_arena->create<ZigValue>();
24224 result->data.x_optional = slice_val;24188 result->data.x_optional = slice_val;
2422524189
24226 uint32_t error_count = type_entry->data.error_set.err_count;24190 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>();
24228 error_array->special = ConstValSpecialStatic;24192 error_array->special = ConstValSpecialStatic;
24229 error_array->type = get_array_type(ira->codegen, type_info_error_type, error_count, nullptr);24193 error_array->type = get_array_type(ira->codegen, type_info_error_type, error_count, nullptr);
24230 error_array->data.x_array.special = ConstArraySpecialNone;24194 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
24233 init_const_slice(ira->codegen, slice_val, error_array, 0, error_count, false);24197 init_const_slice(ira->codegen, slice_val, error_array, 0, error_count, false);
24234 for (uint32_t error_index = 0; error_index < error_count; error_index++) {24198 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...@@ -24238,7 +24202,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
24238 error_val->special = ConstValSpecialStatic;24202 error_val->special = ConstValSpecialStatic;
24239 error_val->type = type_info_error_type;24203 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);
24242 inner_fields[1]->special = ConstValSpecialStatic;24206 inner_fields[1]->special = ConstValSpecialStatic;
24243 inner_fields[1]->type = ira->codegen->builtin_types.entry_num_lit_int;24207 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...@@ -24260,11 +24224,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
24260 }24224 }
24261 case ZigTypeIdErrorUnion:24225 case ZigTypeIdErrorUnion:
24262 {24226 {
24263 result = create_const_vals(1);24227 result = ira->codegen->pass1_arena->create<ZigValue>();
24264 result->special = ConstValSpecialStatic;24228 result->special = ConstValSpecialStatic;
24265 result->type = ir_type_info_get_type(ira, "ErrorUnion", nullptr);24229 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);
24268 result->data.x_struct.fields = fields;24232 result->data.x_struct.fields = fields;
2426924233
24270 // error_set: type24234 // error_set: type
...@@ -24283,11 +24247,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy...@@ -24283,11 +24247,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
24283 }24247 }
24284 case ZigTypeIdUnion:24248 case ZigTypeIdUnion:
24285 {24249 {
24286 result = create_const_vals(1);24250 result = ira->codegen->pass1_arena->create<ZigValue>();
24287 result->special = ConstValSpecialStatic;24251 result->special = ConstValSpecialStatic;
24288 result->type = ir_type_info_get_type(ira, "Union", nullptr);24252 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);
24291 result->data.x_struct.fields = fields;24255 result->data.x_struct.fields = fields;
2429224256
24293 // layout: ContainerLayout24257 // layout: ContainerLayout
...@@ -24304,7 +24268,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy...@@ -24304,7 +24268,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
24304 if (union_decl_node->data.container_decl.auto_enum ||24268 if (union_decl_node->data.container_decl.auto_enum ||
24305 union_decl_node->data.container_decl.init_arg_expr != nullptr)24269 union_decl_node->data.container_decl.init_arg_expr != nullptr)
24306 {24270 {
24307 ZigValue *tag_type = create_const_vals(1);24271 ZigValue *tag_type = ira->codegen->pass1_arena->create<ZigValue>();
24308 tag_type->special = ConstValSpecialStatic;24272 tag_type->special = ConstValSpecialStatic;
24309 tag_type->type = ira->codegen->builtin_types.entry_type;24273 tag_type->type = ira->codegen->builtin_types.entry_type;
24310 tag_type->data.x_type = type_entry->data.unionation.tag_type;24274 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...@@ -24320,11 +24284,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
24320 zig_unreachable();24284 zig_unreachable();
24321 uint32_t union_field_count = type_entry->data.unionation.src_field_count;24285 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>();
24324 union_field_array->special = ConstValSpecialStatic;24288 union_field_array->special = ConstValSpecialStatic;
24325 union_field_array->type = get_array_type(ira->codegen, type_info_union_field_type, union_field_count, nullptr);24289 union_field_array->type = get_array_type(ira->codegen, type_info_union_field_type, union_field_count, nullptr);
24326 union_field_array->data.x_array.special = ConstArraySpecialNone;24290 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
24329 init_const_slice(ira->codegen, fields[2], union_field_array, 0, union_field_count, false);24293 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...@@ -24337,14 +24301,14 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
24337 union_field_val->special = ConstValSpecialStatic;24301 union_field_val->special = ConstValSpecialStatic;
24338 union_field_val->type = type_info_union_field_type;24302 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);
24341 inner_fields[1]->special = ConstValSpecialStatic;24305 inner_fields[1]->special = ConstValSpecialStatic;
24342 inner_fields[1]->type = get_optional_type(ira->codegen, type_info_enum_field_type);24306 inner_fields[1]->type = get_optional_type(ira->codegen, type_info_enum_field_type);
2434324307
24344 if (fields[1]->data.x_optional == nullptr) {24308 if (fields[1]->data.x_optional == nullptr) {
24345 inner_fields[1]->data.x_optional = nullptr;24309 inner_fields[1]->data.x_optional = nullptr;
24346 } else {24310 } 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>();
24348 make_enum_field_val(ira, inner_fields[1]->data.x_optional, union_field->enum_field, type_info_enum_field_type);24312 make_enum_field_val(ira, inner_fields[1]->data.x_optional, union_field->enum_field, type_info_enum_field_type);
24349 }24313 }
2435024314
...@@ -24379,11 +24343,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy...@@ -24379,11 +24343,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
24379 break;24343 break;
24380 }24344 }
2438124345
24382 result = create_const_vals(1);24346 result = ira->codegen->pass1_arena->create<ZigValue>();
24383 result->special = ConstValSpecialStatic;24347 result->special = ConstValSpecialStatic;
24384 result->type = ir_type_info_get_type(ira, "Struct", nullptr);24348 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);
24387 result->data.x_struct.fields = fields;24351 result->data.x_struct.fields = fields;
2438824352
24389 // layout: ContainerLayout24353 // layout: ContainerLayout
...@@ -24400,11 +24364,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy...@@ -24400,11 +24364,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
24400 }24364 }
24401 uint32_t struct_field_count = type_entry->data.structure.src_field_count;24365 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>();
24404 struct_field_array->special = ConstValSpecialStatic;24368 struct_field_array->special = ConstValSpecialStatic;
24405 struct_field_array->type = get_array_type(ira->codegen, type_info_struct_field_type, struct_field_count, nullptr);24369 struct_field_array->type = get_array_type(ira->codegen, type_info_struct_field_type, struct_field_count, nullptr);
24406 struct_field_array->data.x_array.special = ConstArraySpecialNone;24370 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
24409 init_const_slice(ira->codegen, fields[1], struct_field_array, 0, struct_field_count, false);24373 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...@@ -24415,7 +24379,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
24415 struct_field_val->special = ConstValSpecialStatic;24379 struct_field_val->special = ConstValSpecialStatic;
24416 struct_field_val->type = type_info_struct_field_type;24380 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);
24419 inner_fields[1]->special = ConstValSpecialStatic;24383 inner_fields[1]->special = ConstValSpecialStatic;
24420 inner_fields[1]->type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_num_lit_int);24384 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...@@ -24428,7 +24392,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
24428 inner_fields[1]->data.x_optional = nullptr;24392 inner_fields[1]->data.x_optional = nullptr;
24429 } else {24393 } else {
24430 size_t byte_offset = struct_field->offset;24394 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>();
24432 inner_fields[1]->data.x_optional->special = ConstValSpecialStatic;24396 inner_fields[1]->data.x_optional->special = ConstValSpecialStatic;
24433 inner_fields[1]->data.x_optional->type = ira->codegen->builtin_types.entry_num_lit_int;24397 inner_fields[1]->data.x_optional->type = ira->codegen->builtin_types.entry_num_lit_int;
24434 bigint_init_unsigned(&inner_fields[1]->data.x_optional->data.x_bigint, byte_offset);24398 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...@@ -24464,11 +24428,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
24464 }24428 }
24465 case ZigTypeIdFn:24429 case ZigTypeIdFn:
24466 {24430 {
24467 result = create_const_vals(1);24431 result = ira->codegen->pass1_arena->create<ZigValue>();
24468 result->special = ConstValSpecialStatic;24432 result->special = ConstValSpecialStatic;
24469 result->type = ir_type_info_get_type(ira, "Fn", nullptr);24433 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);
24472 result->data.x_struct.fields = fields;24436 result->data.x_struct.fields = fields;
2447324437
24474 // calling_convention: TypeInfo.CallingConvention24438 // calling_convention: TypeInfo.CallingConvention
...@@ -24495,7 +24459,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy...@@ -24495,7 +24459,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
24495 if (type_entry->data.fn.fn_type_id.return_type == nullptr)24459 if (type_entry->data.fn.fn_type_id.return_type == nullptr)
24496 fields[3]->data.x_optional = nullptr;24460 fields[3]->data.x_optional = nullptr;
24497 else {24461 else {
24498 ZigValue *return_type = create_const_vals(1);24462 ZigValue *return_type = ira->codegen->pass1_arena->create<ZigValue>();
24499 return_type->special = ConstValSpecialStatic;24463 return_type->special = ConstValSpecialStatic;
24500 return_type->type = ira->codegen->builtin_types.entry_type;24464 return_type->type = ira->codegen->builtin_types.entry_type;
24501 return_type->data.x_type = type_entry->data.fn.fn_type_id.return_type;24465 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...@@ -24509,11 +24473,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
24509 size_t fn_arg_count = type_entry->data.fn.fn_type_id.param_count -24473 size_t fn_arg_count = type_entry->data.fn.fn_type_id.param_count -
24510 (is_varargs && type_entry->data.fn.fn_type_id.cc != CallingConventionC);24474 (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>();
24513 fn_arg_array->special = ConstValSpecialStatic;24477 fn_arg_array->special = ConstValSpecialStatic;
24514 fn_arg_array->type = get_array_type(ira->codegen, type_info_fn_arg_type, fn_arg_count, nullptr);24478 fn_arg_array->type = get_array_type(ira->codegen, type_info_fn_arg_type, fn_arg_count, nullptr);
24515 fn_arg_array->data.x_array.special = ConstArraySpecialNone;24479 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
24518 init_const_slice(ira->codegen, fields[4], fn_arg_array, 0, fn_arg_count, false);24482 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...@@ -24527,7 +24491,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
24527 bool arg_is_generic = fn_param_info->type == nullptr;24491 bool arg_is_generic = fn_param_info->type == nullptr;
24528 if (arg_is_generic) assert(is_generic);24492 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);
24531 inner_fields[0]->special = ConstValSpecialStatic;24495 inner_fields[0]->special = ConstValSpecialStatic;
24532 inner_fields[0]->type = ira->codegen->builtin_types.entry_bool;24496 inner_fields[0]->type = ira->codegen->builtin_types.entry_bool;
24533 inner_fields[0]->data.x_bool = arg_is_generic;24497 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...@@ -24540,7 +24504,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy
24540 if (arg_is_generic)24504 if (arg_is_generic)
24541 inner_fields[2]->data.x_optional = nullptr;24505 inner_fields[2]->data.x_optional = nullptr;
24542 else {24506 else {
24543 ZigValue *arg_type = create_const_vals(1);24507 ZigValue *arg_type = ira->codegen->pass1_arena->create<ZigValue>();
24544 arg_type->special = ConstValSpecialStatic;24508 arg_type->special = ConstValSpecialStatic;
24545 arg_type->type = ira->codegen->builtin_types.entry_type;24509 arg_type->type = ira->codegen->builtin_types.entry_type;
24546 arg_type->data.x_type = fn_param_info->type;24510 arg_type->data.x_type = fn_param_info->type;
...@@ -24866,7 +24830,7 @@ static IrInstGen *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstSrcType...@@ -24866,7 +24830,7 @@ static IrInstGen *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstSrcType
24866 type_entry->cached_const_name_val = create_const_str_lit(ira->codegen, type_bare_name(type_entry));24830 type_entry->cached_const_name_val = create_const_str_lit(ira->codegen, type_bare_name(type_entry));
24867 }24831 }
24868 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);24832 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);
24870 return result;24834 return result;
24871}24835}
2487224836
...@@ -24898,7 +24862,6 @@ static IrInstGen *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstSrcCImpo...@@ -24898,7 +24862,6 @@ static IrInstGen *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstSrcCImpo
24898 }24862 }
24899 if (type_is_invalid(cimport_result->type))24863 if (type_is_invalid(cimport_result->type))
24900 return ira->codegen->invalid_inst_gen;24864 return ira->codegen->invalid_inst_gen;
24901 destroy(result_ptr, "ZigValue");
2490224865
24903 ZigPackage *cur_scope_pkg = scope_package(instruction->base.base.scope);24866 ZigPackage *cur_scope_pkg = scope_package(instruction->base.base.scope);
24904 Buf *namespace_name = buf_sprintf("%s.cimport:%" ZIG_PRI_usize ":%" ZIG_PRI_usize,24867 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...@@ -25577,11 +25540,11 @@ static IrInstGen *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstSrcToByt
25577 return ira->codegen->invalid_inst_gen;25540 return ira->codegen->invalid_inst_gen;
2557825541
25579 IrInstGen *result = ir_const(ira, &instruction->base.base, dest_slice_type);25542 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
25582 ZigValue *ptr_val = result->value->data.x_struct.fields[slice_ptr_index];25545 ZigValue *ptr_val = result->value->data.x_struct.fields[slice_ptr_index];
25583 ZigValue *target_ptr_val = target_val->data.x_struct.fields[slice_ptr_index];25546 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);
25585 ptr_val->type = dest_ptr_type;25548 ptr_val->type = dest_ptr_type;
2558625549
25587 ZigValue *len_val = result->value->data.x_struct.fields[slice_len_index];25550 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...@@ -25868,7 +25831,7 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr
25868 expand_undef_array(ira->codegen, b_val);25831 expand_undef_array(ira->codegen, b_val);
2586925832
25870 IrInstGen *result = ir_const(ira, source_instr, result_type);25833 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);
25872 for (uint32_t i = 0; i < mask_val->type->data.vector.len; i += 1) {25835 for (uint32_t i = 0; i < mask_val->type->data.vector.len; i += 1) {
25873 ZigValue *mask_elem_val = &mask_val->data.x_array.data.s_none.elements[i];25836 ZigValue *mask_elem_val = &mask_val->data.x_array.data.s_none.elements[i];
25874 ZigValue *result_elem_val = &result->value->data.x_array.data.s_none.elements[i];25837 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...@@ -25881,7 +25844,7 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr
25881 ZigValue *src_elem_val = (v >= 0) ?25844 ZigValue *src_elem_val = (v >= 0) ?
25882 &a->value->data.x_array.data.s_none.elements[v] :25845 &a->value->data.x_array.data.s_none.elements[v] :
25883 &b->value->data.x_array.data.s_none.elements[~v];25846 &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
25886 ir_assert(result_elem_val->special == ConstValSpecialStatic, source_instr);25849 ir_assert(result_elem_val->special == ConstValSpecialStatic, source_instr);
25887 }25850 }
...@@ -25901,7 +25864,7 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr...@@ -25901,7 +25864,7 @@ static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr
2590125864
25902 IrInstGen *expand_mask = ir_const(ira, &mask->base,25865 IrInstGen *expand_mask = ir_const(ira, &mask->base,
25903 get_vector_type(ira->codegen, len_max, ira->codegen->builtin_types.entry_i32));25866 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);
25905 uint32_t i = 0;25868 uint32_t i = 0;
25906 for (; i < len_min; i += 1)25869 for (; i < len_min; i += 1)
25907 bigint_init_unsigned(&expand_mask->value->data.x_array.data.s_none.elements[i].data.x_bigint, i);25870 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...@@ -25971,9 +25934,9 @@ static IrInstGen *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstSrcSplat *i
25971 return ir_const_undef(ira, &instruction->base.base, return_type);25934 return ir_const_undef(ira, &instruction->base.base, return_type);
2597225935
25973 IrInstGen *result = ir_const(ira, &instruction->base.base, return_type);25936 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);
25975 for (uint32_t i = 0; i < len_int; i += 1) {25938 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);
25977 }25940 }
25978 return result;25941 return result;
25979 }25942 }
...@@ -26111,7 +26074,7 @@ static IrInstGen *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstSrcMemset...@@ -26111,7 +26074,7 @@ static IrInstGen *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstSrcMemset
26111 }26074 }
2611226075
26113 for (size_t i = start; i < end; i += 1) {26076 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);
26115 }26078 }
2611626079
26117 return ir_const_void(ira, &instruction->base.base);26080 return ir_const_void(ira, &instruction->base.base);
...@@ -26287,7 +26250,7 @@ static IrInstGen *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstSrcMemcpy...@@ -26287,7 +26250,7 @@ static IrInstGen *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstSrcMemcpy
26287 // TODO check for noalias violations - this should be generalized to work for any function26250 // TODO check for noalias violations - this should be generalized to work for any function
2628826251
26289 for (size_t i = 0; i < count; i += 1) {26252 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]);
26291 }26254 }
2629226255
26293 return ir_const_void(ira, &instruction->base.base);26256 return ir_const_void(ira, &instruction->base.base);
...@@ -26571,7 +26534,7 @@ static IrInstGen *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstSrcSlice *i...@@ -26571,7 +26534,7 @@ static IrInstGen *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstSrcSlice *i
2657126534
26572 IrInstGen *result = ir_const(ira, &instruction->base.base, return_type);26535 IrInstGen *result = ir_const(ira, &instruction->base.base, return_type);
26573 ZigValue *out_val = result->value;26536 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
26576 ZigValue *ptr_val = out_val->data.x_struct.fields[slice_ptr_index];26539 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...@@ -26866,7 +26829,7 @@ static IrInstGen *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstSrcAlign
26866 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int);26829 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int);
26867 result->value->special = ConstValSpecialLazy;26830 result->value->special = ConstValSpecialLazy;
2686826831
26869 LazyValueAlignOf *lazy_align_of = allocate<LazyValueAlignOf>(1, "LazyValueAlignOf");26832 LazyValueAlignOf *lazy_align_of = heap::c_allocator.create<LazyValueAlignOf>();
26870 lazy_align_of->ira = ira; ira_ref(ira);26833 lazy_align_of->ira = ira; ira_ref(ira);
26871 result->value->data.x_lazy = &lazy_align_of->base;26834 result->value->data.x_lazy = &lazy_align_of->base;
26872 lazy_align_of->base.id = LazyValueIdAlignOf;26835 lazy_align_of->base.id = LazyValueIdAlignOf;
...@@ -27192,7 +27155,7 @@ static IrInstGen *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInst* source_inst...@@ -27192,7 +27155,7 @@ static IrInstGen *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInst* source_inst
27192 return ira->codegen->invalid_inst_gen;27155 return ira->codegen->invalid_inst_gen;
2719327156
27194 if (initializing && err_union_val->special == ConstValSpecialUndef) {27157 if (initializing && err_union_val->special == ConstValSpecialUndef) {
27195 ZigValue *vals = create_const_vals(2);27158 ZigValue *vals = ira->codegen->pass1_arena->allocate<ZigValue>(2);
27196 ZigValue *err_set_val = &vals[0];27159 ZigValue *err_set_val = &vals[0];
27197 ZigValue *payload_val = &vals[1];27160 ZigValue *payload_val = &vals[1];
2719827161
...@@ -27273,7 +27236,7 @@ static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInst* source...@@ -27273,7 +27236,7 @@ static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInst* source
27273 if (err_union_val == nullptr)27236 if (err_union_val == nullptr)
27274 return ira->codegen->invalid_inst_gen;27237 return ira->codegen->invalid_inst_gen;
27275 if (initializing && err_union_val->special == ConstValSpecialUndef) {27238 if (initializing && err_union_val->special == ConstValSpecialUndef) {
27276 ZigValue *vals = create_const_vals(2);27239 ZigValue *vals = ira->codegen->pass1_arena->allocate<ZigValue>(2);
27277 ZigValue *err_set_val = &vals[0];27240 ZigValue *err_set_val = &vals[0];
27278 ZigValue *payload_val = &vals[1];27241 ZigValue *payload_val = &vals[1];
2727927242
...@@ -27335,7 +27298,7 @@ static IrInstGen *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstSrcFnPro...@@ -27335,7 +27298,7 @@ static IrInstGen *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstSrcFnPro
27335 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type);27298 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type);
27336 result->value->special = ConstValSpecialLazy;27299 result->value->special = ConstValSpecialLazy;
2733727300
27338 LazyValueFnType *lazy_fn_type = allocate<LazyValueFnType>(1, "LazyValueFnType");27301 LazyValueFnType *lazy_fn_type = heap::c_allocator.create<LazyValueFnType>();
27339 lazy_fn_type->ira = ira; ira_ref(ira);27302 lazy_fn_type->ira = ira; ira_ref(ira);
27340 result->value->data.x_lazy = &lazy_fn_type->base;27303 result->value->data.x_lazy = &lazy_fn_type->base;
27341 lazy_fn_type->base.id = LazyValueIdFnType;27304 lazy_fn_type->base.id = LazyValueIdFnType;
...@@ -27363,7 +27326,7 @@ static IrInstGen *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstSrcFnPro...@@ -27363,7 +27326,7 @@ static IrInstGen *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstSrcFnPro
2736327326
27364 size_t param_count = proto_node->data.fn_proto.params.length;27327 size_t param_count = proto_node->data.fn_proto.params.length;
27365 lazy_fn_type->proto_node = proto_node;27328 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
27368 for (size_t param_index = 0; param_index < param_count; param_index += 1) {27331 for (size_t param_index = 0; param_index < param_count; param_index += 1) {
27369 AstNode *param_node = proto_node->data.fn_proto.params.at(param_index);27332 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,...@@ -27518,7 +27481,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
27518 }27481 }
2751927482
27520 size_t field_prev_uses_count = ira->codegen->errors_by_index.length;27483 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
27523 for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) {27486 for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) {
27524 IrInstSrcCheckSwitchProngsRange *range = &instruction->ranges[range_i];27487 IrInstSrcCheckSwitchProngsRange *range = &instruction->ranges[range_i];
...@@ -27575,7 +27538,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -27575,7 +27538,7 @@ static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
27575 }27538 }
27576 }27539 }
2757727540
27578 deallocate(field_prev_uses, field_prev_uses_count, "AstNode *");27541 heap::c_allocator.deallocate(field_prev_uses, field_prev_uses_count);
27579 } else if (switch_type->id == ZigTypeIdInt) {27542 } else if (switch_type->id == ZigTypeIdInt) {
27580 RangeSet rs = {0};27543 RangeSet rs = {0};
27581 for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) {27544 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...@@ -27768,7 +27731,7 @@ static IrInstGen *ir_align_cast(IrAnalyze *ira, IrInstGen *target, uint32_t alig
27768 }27731 }
2776927732
27770 IrInstGen *result = ir_const(ira, &target->base, result_type);27733 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);
27772 result->value->type = result_type;27735 result->value->type = result_type;
27773 return result;27736 return result;
27774 }27737 }
...@@ -27864,7 +27827,7 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn...@@ -27864,7 +27827,7 @@ static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrIn
27864 InferredStructField *isf = (val->type->id == ZigTypeIdPointer) ?27827 InferredStructField *isf = (val->type->id == ZigTypeIdPointer) ?
27865 val->type->data.pointer.inferred_struct_field : nullptr;27828 val->type->data.pointer.inferred_struct_field : nullptr;
27866 if (isf == nullptr) {27829 if (isf == nullptr) {
27867 copy_const_val(result->value, val);27830 copy_const_val(ira->codegen, result->value, val);
27868 } else {27831 } else {
27869 // The destination value should have x_ptr struct pointing to underlying struct value27832 // The destination value should have x_ptr struct pointing to underlying struct value
27870 result->value->data.x_ptr.mut = val->data.x_ptr.mut;27833 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)...@@ -28021,7 +27984,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ZigValue *val)
28021 while (gen_i < gen_field_count) {27984 while (gen_i < gen_field_count) {
28022 size_t big_int_byte_count = val->type->data.structure.host_int_bytes[gen_i];27985 size_t big_int_byte_count = val->type->data.structure.host_int_bytes[gen_i];
28023 if (big_int_byte_count > child_buf_len) {27986 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);
28025 child_buf_len = big_int_byte_count;27988 child_buf_len = big_int_byte_count;
28026 }27989 }
28027 BigInt big_int;27990 BigInt big_int;
...@@ -28084,7 +28047,7 @@ static Error buf_read_value_bytes_array(IrAnalyze *ira, CodeGen *codegen, AstNod...@@ -28084,7 +28047,7 @@ static Error buf_read_value_bytes_array(IrAnalyze *ira, CodeGen *codegen, AstNod
2808428047
28085 switch (val->data.x_array.special) {28048 switch (val->data.x_array.special) {
28086 case ConstArraySpecialNone:28049 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);
28088 for (size_t i = 0; i < len; i++) {28051 for (size_t i = 0; i < len; i++) {
28089 ZigValue *elem = &val->data.x_array.data.s_none.elements[i];28052 ZigValue *elem = &val->data.x_array.data.s_none.elements[i];
28090 elem->special = ConstValSpecialStatic;28053 elem->special = ConstValSpecialStatic;
...@@ -28170,7 +28133,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou...@@ -28170,7 +28133,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou
28170 }28133 }
28171 case ContainerLayoutExtern: {28134 case ContainerLayoutExtern: {
28172 size_t src_field_count = val->type->data.structure.src_field_count;28135 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);
28174 for (size_t field_i = 0; field_i < src_field_count; field_i += 1) {28137 for (size_t field_i = 0; field_i < src_field_count; field_i += 1) {
28175 ZigValue *field_val = val->data.x_struct.fields[field_i];28138 ZigValue *field_val = val->data.x_struct.fields[field_i];
28176 field_val->special = ConstValSpecialStatic;28139 field_val->special = ConstValSpecialStatic;
...@@ -28187,7 +28150,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou...@@ -28187,7 +28150,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou
28187 }28150 }
28188 case ContainerLayoutPacked: {28151 case ContainerLayoutPacked: {
28189 size_t src_field_count = val->type->data.structure.src_field_count;28152 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);
28191 size_t gen_field_count = val->type->data.structure.gen_field_count;28154 size_t gen_field_count = val->type->data.structure.gen_field_count;
28192 size_t gen_i = 0;28155 size_t gen_i = 0;
28193 size_t src_i = 0;28156 size_t src_i = 0;
...@@ -28199,7 +28162,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou...@@ -28199,7 +28162,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou
28199 while (gen_i < gen_field_count) {28162 while (gen_i < gen_field_count) {
28200 size_t big_int_byte_count = val->type->data.structure.host_int_bytes[gen_i];28163 size_t big_int_byte_count = val->type->data.structure.host_int_bytes[gen_i];
28201 if (big_int_byte_count > child_buf_len) {28164 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);
28203 child_buf_len = big_int_byte_count;28166 child_buf_len = big_int_byte_count;
28204 }28167 }
28205 BigInt big_int;28168 BigInt big_int;
...@@ -28309,7 +28272,7 @@ static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrIn...@@ -28309,7 +28272,7 @@ static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrIn
28309 return ira->codegen->invalid_inst_gen;28272 return ira->codegen->invalid_inst_gen;
2831028273
28311 IrInstGen *result = ir_const(ira, source_instr, dest_type);28274 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);
28313 buf_write_value_bytes(ira->codegen, buf, val);28276 buf_write_value_bytes(ira->codegen, buf, val);
28314 if ((err = buf_read_value_bytes(ira, ira->codegen, source_instr->source_node, buf, result->value)))28277 if ((err = buf_read_value_bytes(ira, ira->codegen, source_instr->source_node, buf, result->value)))
28315 return ira->codegen->invalid_inst_gen;28278 return ira->codegen->invalid_inst_gen;
...@@ -28451,7 +28414,7 @@ static IrInstGen *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstSrcPtrTy...@@ -28451,7 +28414,7 @@ static IrInstGen *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstSrcPtrTy
28451 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type);28414 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type);
28452 result->value->special = ConstValSpecialLazy;28415 result->value->special = ConstValSpecialLazy;
2845328416
28454 LazyValuePtrType *lazy_ptr_type = allocate<LazyValuePtrType>(1, "LazyValuePtrType");28417 LazyValuePtrType *lazy_ptr_type = heap::c_allocator.create<LazyValuePtrType>();
28455 lazy_ptr_type->ira = ira; ira_ref(ira);28418 lazy_ptr_type->ira = ira; ira_ref(ira);
28456 result->value->data.x_lazy = &lazy_ptr_type->base;28419 result->value->data.x_lazy = &lazy_ptr_type->base;
28457 lazy_ptr_type->base.id = LazyValueIdPtrType;28420 lazy_ptr_type->base.id = LazyValueIdPtrType;
...@@ -29150,11 +29113,11 @@ static IrInstGen *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstSrcBswap *i...@@ -29150,11 +29113,11 @@ static IrInstGen *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstSrcBswap *i
29150 return ir_const_undef(ira, &instruction->base.base, op_type);29113 return ir_const_undef(ira, &instruction->base.base, op_type);
2915129114
29152 IrInstGen *result = ir_const(ira, &instruction->base.base, op_type);29115 IrInstGen *result = ir_const(ira, &instruction->base.base, op_type);
29153 size_t buf_size = int_type->data.integral.bit_count / 8;29116 const size_t buf_size = int_type->data.integral.bit_count / 8;
29154 uint8_t *buf = allocate_nonzero<uint8_t>(buf_size);29117 uint8_t *buf = heap::c_allocator.allocate_nonzero<uint8_t>(buf_size);
29155 if (is_vector) {29118 if (is_vector) {
29156 expand_undef_array(ira->codegen, val);29119 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);
29158 for (unsigned i = 0; i < op_type->data.vector.len; i += 1) {29121 for (unsigned i = 0; i < op_type->data.vector.len; i += 1) {
29159 ZigValue *op_elem_val = &val->data.x_array.data.s_none.elements[i];29122 ZigValue *op_elem_val = &val->data.x_array.data.s_none.elements[i];
29160 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, instruction->base.base.source_node,29123 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...@@ -29178,7 +29141,7 @@ static IrInstGen *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstSrcBswap *i
29178 bigint_read_twos_complement(&result->value->data.x_bigint, buf, int_type->data.integral.bit_count, false,29141 bigint_read_twos_complement(&result->value->data.x_bigint, buf, int_type->data.integral.bit_count, false,
29179 int_type->data.integral.is_signed);29142 int_type->data.integral.is_signed);
29180 }29143 }
29181 free(buf);29144 heap::c_allocator.deallocate(buf, buf_size);
29182 return result;29145 return result;
29183 }29146 }
2918429147
...@@ -29210,8 +29173,8 @@ static IrInstGen *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstSrcBi...@@ -29210,8 +29173,8 @@ static IrInstGen *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstSrcBi
29210 IrInstGen *result = ir_const(ira, &instruction->base.base, int_type);29173 IrInstGen *result = ir_const(ira, &instruction->base.base, int_type);
29211 size_t num_bits = int_type->data.integral.bit_count;29174 size_t num_bits = int_type->data.integral.bit_count;
29212 size_t buf_size = (num_bits + 7) / 8;29175 size_t buf_size = (num_bits + 7) / 8;
29213 uint8_t *comptime_buf = allocate_nonzero<uint8_t>(buf_size);29176 uint8_t *comptime_buf = heap::c_allocator.allocate_nonzero<uint8_t>(buf_size);
29214 uint8_t *result_buf = allocate_nonzero<uint8_t>(buf_size);29177 uint8_t *result_buf = heap::c_allocator.allocate_nonzero<uint8_t>(buf_size);
29215 memset(comptime_buf,0,buf_size);29178 memset(comptime_buf,0,buf_size);
29216 memset(result_buf,0,buf_size);29179 memset(result_buf,0,buf_size);
2921729180
...@@ -29897,7 +29860,7 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutableSrc *old_exec, IrExecutableGen...@@ -29897,7 +29860,7 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutableSrc *old_exec, IrExecutableGen
29897 assert(old_exec->first_err_trace_msg == nullptr);29860 assert(old_exec->first_err_trace_msg == nullptr);
29898 assert(expected_type == nullptr || !type_is_invalid(expected_type));29861 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>();
29901 ira->ref_count = 1;29864 ira->ref_count = 1;
29902 old_exec->analysis = ira;29865 old_exec->analysis = ira;
29903 ira->codegen = codegen;29866 ira->codegen = codegen;
src/ir.hpp-2
...@@ -37,6 +37,4 @@ ZigValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ZigValue *const_va...@@ -37,6 +37,4 @@ ZigValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ZigValue *const_va
37void dbg_ir_break(const char *src_file, uint32_t line);37void dbg_ir_break(const char *src_file, uint32_t line);
38void dbg_ir_clear(void);38void dbg_ir_clear(void);
3939
40void destroy_instruction_gen(IrInstGen *inst);
41
42#endif40#endif
src/link.cpp+19-19
...@@ -650,7 +650,7 @@ static const char *build_libunwind(CodeGen *parent, Stage2ProgressNode *progress...@@ -650,7 +650,7 @@ static const char *build_libunwind(CodeGen *parent, Stage2ProgressNode *progress
650 };650 };
651 ZigList<CFile *> c_source_files = {0};651 ZigList<CFile *> c_source_files = {0};
652 for (size_t i = 0; i < array_length(unwind_src); i += 1) {652 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>();
654 c_file->source_path = path_from_libunwind(parent, unwind_src[i].path);654 c_file->source_path = path_from_libunwind(parent, unwind_src[i].path);
655 switch (unwind_src[i].kind) {655 switch (unwind_src[i].kind) {
656 case SrcC:656 case SrcC:
...@@ -1111,7 +1111,7 @@ static const char *build_musl(CodeGen *parent, Stage2ProgressNode *progress_node...@@ -1111,7 +1111,7 @@ static const char *build_musl(CodeGen *parent, Stage2ProgressNode *progress_node
1111 Buf *full_path = buf_sprintf("%s" OS_SEP "libc" OS_SEP "%s",1111 Buf *full_path = buf_sprintf("%s" OS_SEP "libc" OS_SEP "%s",
1112 buf_ptr(parent->zig_lib_dir), buf_ptr(src_file));1112 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>();
1115 c_file->source_path = buf_ptr(full_path);1115 c_file->source_path = buf_ptr(full_path);
11161116
1117 musl_add_cc_args(parent, c_file, src_kind == MuslSrcO3);1117 musl_add_cc_args(parent, c_file, src_kind == MuslSrcO3);
...@@ -1127,7 +1127,7 @@ static const char *build_musl(CodeGen *parent, Stage2ProgressNode *progress_node...@@ -1127,7 +1127,7 @@ static const char *build_musl(CodeGen *parent, Stage2ProgressNode *progress_node
1127}1127}
11281128
1129static void add_msvcrt_os_dep(CodeGen *parent, CodeGen *child_gen, const char *src_path) {1129static 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>();
1131 c_file->source_path = buf_ptr(buf_sprintf("%s" OS_SEP "libc" OS_SEP "mingw" OS_SEP "%s",1131 c_file->source_path = buf_ptr(buf_sprintf("%s" OS_SEP "libc" OS_SEP "mingw" OS_SEP "%s",
1132 buf_ptr(parent->zig_lib_dir), src_path));1132 buf_ptr(parent->zig_lib_dir), src_path));
1133 c_file->args.append("-DHAVE_CONFIG_H");1133 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...@@ -1151,7 +1151,7 @@ static void add_msvcrt_os_dep(CodeGen *parent, CodeGen *child_gen, const char *s
1151}1151}
11521152
1153static void add_mingwex_os_dep(CodeGen *parent, CodeGen *child_gen, const char *src_path) {1153static 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>();
1155 c_file->source_path = buf_ptr(buf_sprintf("%s" OS_SEP "libc" OS_SEP "mingw" OS_SEP "%s",1155 c_file->source_path = buf_ptr(buf_sprintf("%s" OS_SEP "libc" OS_SEP "mingw" OS_SEP "%s",
1156 buf_ptr(parent->zig_lib_dir), src_path));1156 buf_ptr(parent->zig_lib_dir), src_path));
1157 c_file->args.append("-DHAVE_CONFIG_H");1157 c_file->args.append("-DHAVE_CONFIG_H");
...@@ -1178,7 +1178,7 @@ static void add_mingwex_os_dep(CodeGen *parent, CodeGen *child_gen, const char *...@@ -1178,7 +1178,7 @@ static void add_mingwex_os_dep(CodeGen *parent, CodeGen *child_gen, const char *
1178static const char *get_libc_crt_file(CodeGen *parent, const char *file, Stage2ProgressNode *progress_node) {1178static const char *get_libc_crt_file(CodeGen *parent, const char *file, Stage2ProgressNode *progress_node) {
1179 if (parent->libc == nullptr && parent->zig_target->os == OsWindows) {1179 if (parent->libc == nullptr && parent->zig_target->os == OsWindows) {
1180 if (strcmp(file, "crt2.o") == 0) {1180 if (strcmp(file, "crt2.o") == 0) {
1181 CFile *c_file = allocate<CFile>(1);1181 CFile *c_file = heap::c_allocator.create<CFile>();
1182 c_file->source_path = buf_ptr(buf_sprintf(1182 c_file->source_path = buf_ptr(buf_sprintf(
1183 "%s" OS_SEP "libc" OS_SEP "mingw" OS_SEP "crt" OS_SEP "crtexe.c", buf_ptr(parent->zig_lib_dir)));1183 "%s" OS_SEP "libc" OS_SEP "mingw" OS_SEP "crt" OS_SEP "crtexe.c", buf_ptr(parent->zig_lib_dir)));
1184 mingw_add_cc_args(parent, c_file);1184 mingw_add_cc_args(parent, c_file);
...@@ -1190,7 +1190,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file, Stage2Pr...@@ -1190,7 +1190,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file, Stage2Pr
1190 //c_file->args.append("-DWPRFLAG=1");1190 //c_file->args.append("-DWPRFLAG=1");
1191 return build_libc_object(parent, "crt2", c_file, progress_node);1191 return build_libc_object(parent, "crt2", c_file, progress_node);
1192 } else if (strcmp(file, "dllcrt2.o") == 0) {1192 } else if (strcmp(file, "dllcrt2.o") == 0) {
1193 CFile *c_file = allocate<CFile>(1);1193 CFile *c_file = heap::c_allocator.create<CFile>();
1194 c_file->source_path = buf_ptr(buf_sprintf(1194 c_file->source_path = buf_ptr(buf_sprintf(
1195 "%s" OS_SEP "libc" OS_SEP "mingw" OS_SEP "crt" OS_SEP "crtdll.c", buf_ptr(parent->zig_lib_dir)));1195 "%s" OS_SEP "libc" OS_SEP "mingw" OS_SEP "crt" OS_SEP "crtdll.c", buf_ptr(parent->zig_lib_dir)));
1196 mingw_add_cc_args(parent, c_file);1196 mingw_add_cc_args(parent, c_file);
...@@ -1231,7 +1231,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file, Stage2Pr...@@ -1231,7 +1231,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file, Stage2Pr
1231 "mingw" OS_SEP "crt" OS_SEP "cxa_atexit.c",1231 "mingw" OS_SEP "crt" OS_SEP "cxa_atexit.c",
1232 };1232 };
1233 for (size_t i = 0; i < array_length(deps); i += 1) {1233 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>();
1235 c_file->source_path = path_from_libc(parent, deps[i]);1235 c_file->source_path = path_from_libc(parent, deps[i]);
1236 c_file->args.append("-DHAVE_CONFIG_H");1236 c_file->args.append("-DHAVE_CONFIG_H");
1237 c_file->args.append("-D_SYSCRT=1");1237 c_file->args.append("-D_SYSCRT=1");
...@@ -1301,7 +1301,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file, Stage2Pr...@@ -1301,7 +1301,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file, Stage2Pr
1301 }1301 }
1302 } else if (parent->libc == nullptr && target_is_glibc(parent->zig_target)) {1302 } else if (parent->libc == nullptr && target_is_glibc(parent->zig_target)) {
1303 if (strcmp(file, "crti.o") == 0) {1303 if (strcmp(file, "crti.o") == 0) {
1304 CFile *c_file = allocate<CFile>(1);1304 CFile *c_file = heap::c_allocator.create<CFile>();
1305 c_file->source_path = glibc_start_asm_path(parent, "crti.S");1305 c_file->source_path = glibc_start_asm_path(parent, "crti.S");
1306 glibc_add_include_dirs(parent, c_file);1306 glibc_add_include_dirs(parent, c_file);
1307 c_file->args.append("-D_LIBC_REENTRANT");1307 c_file->args.append("-D_LIBC_REENTRANT");
...@@ -1317,7 +1317,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file, Stage2Pr...@@ -1317,7 +1317,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file, Stage2Pr
1317 c_file->args.append("-Wa,--noexecstack");1317 c_file->args.append("-Wa,--noexecstack");
1318 return build_libc_object(parent, "crti", c_file, progress_node);1318 return build_libc_object(parent, "crti", c_file, progress_node);
1319 } else if (strcmp(file, "crtn.o") == 0) {1319 } else if (strcmp(file, "crtn.o") == 0) {
1320 CFile *c_file = allocate<CFile>(1);1320 CFile *c_file = heap::c_allocator.create<CFile>();
1321 c_file->source_path = glibc_start_asm_path(parent, "crtn.S");1321 c_file->source_path = glibc_start_asm_path(parent, "crtn.S");
1322 glibc_add_include_dirs(parent, c_file);1322 glibc_add_include_dirs(parent, c_file);
1323 c_file->args.append("-D_LIBC_REENTRANT");1323 c_file->args.append("-D_LIBC_REENTRANT");
...@@ -1328,7 +1328,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file, Stage2Pr...@@ -1328,7 +1328,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file, Stage2Pr
1328 c_file->args.append("-Wa,--noexecstack");1328 c_file->args.append("-Wa,--noexecstack");
1329 return build_libc_object(parent, "crtn", c_file, progress_node);1329 return build_libc_object(parent, "crtn", c_file, progress_node);
1330 } else if (strcmp(file, "start.os") == 0) {1330 } else if (strcmp(file, "start.os") == 0) {
1331 CFile *c_file = allocate<CFile>(1);1331 CFile *c_file = heap::c_allocator.create<CFile>();
1332 c_file->source_path = glibc_start_asm_path(parent, "start.S");1332 c_file->source_path = glibc_start_asm_path(parent, "start.S");
1333 glibc_add_include_dirs(parent, c_file);1333 glibc_add_include_dirs(parent, c_file);
1334 c_file->args.append("-D_LIBC_REENTRANT");1334 c_file->args.append("-D_LIBC_REENTRANT");
...@@ -1346,7 +1346,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file, Stage2Pr...@@ -1346,7 +1346,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file, Stage2Pr
1346 c_file->args.append("-Wa,--noexecstack");1346 c_file->args.append("-Wa,--noexecstack");
1347 return build_libc_object(parent, "start", c_file, progress_node);1347 return build_libc_object(parent, "start", c_file, progress_node);
1348 } else if (strcmp(file, "abi-note.o") == 0) {1348 } else if (strcmp(file, "abi-note.o") == 0) {
1349 CFile *c_file = allocate<CFile>(1);1349 CFile *c_file = heap::c_allocator.create<CFile>();
1350 c_file->source_path = path_from_libc(parent, "glibc" OS_SEP "csu" OS_SEP "abi-note.S");1350 c_file->source_path = path_from_libc(parent, "glibc" OS_SEP "csu" OS_SEP "abi-note.S");
1351 c_file->args.append("-I");1351 c_file->args.append("-I");
1352 c_file->args.append(path_from_libc(parent, "glibc" OS_SEP "csu"));1352 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...@@ -1369,7 +1369,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file, Stage2Pr
1369 } else if (strcmp(file, "libc_nonshared.a") == 0) {1369 } else if (strcmp(file, "libc_nonshared.a") == 0) {
1370 CodeGen *child_gen = create_child_codegen(parent, nullptr, OutTypeLib, nullptr, "c_nonshared", progress_node);1370 CodeGen *child_gen = create_child_codegen(parent, nullptr, OutTypeLib, nullptr, "c_nonshared", progress_node);
1371 {1371 {
1372 CFile *c_file = allocate<CFile>(1);1372 CFile *c_file = heap::c_allocator.create<CFile>();
1373 c_file->source_path = path_from_libc(parent, "glibc" OS_SEP "csu" OS_SEP "elf-init.c");1373 c_file->source_path = path_from_libc(parent, "glibc" OS_SEP "csu" OS_SEP "elf-init.c");
1374 c_file->args.append("-std=gnu11");1374 c_file->args.append("-std=gnu11");
1375 c_file->args.append("-fgnu89-inline");1375 c_file->args.append("-fgnu89-inline");
...@@ -1419,7 +1419,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file, Stage2Pr...@@ -1419,7 +1419,7 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file, Stage2Pr
1419 {"stack_chk_fail_local", "glibc" OS_SEP "debug" OS_SEP "stack_chk_fail_local.c"},1419 {"stack_chk_fail_local", "glibc" OS_SEP "debug" OS_SEP "stack_chk_fail_local.c"},
1420 };1420 };
1421 for (size_t i = 0; i < array_length(deps); i += 1) {1421 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>();
1423 c_file->source_path = path_from_libc(parent, deps[i].path);1423 c_file->source_path = path_from_libc(parent, deps[i].path);
1424 c_file->args.append("-std=gnu11");1424 c_file->args.append("-std=gnu11");
1425 c_file->args.append("-fgnu89-inline");1425 c_file->args.append("-fgnu89-inline");
...@@ -1451,26 +1451,26 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file, Stage2Pr...@@ -1451,26 +1451,26 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file, Stage2Pr
1451 }1451 }
1452 } else if (parent->libc == nullptr && target_is_musl(parent->zig_target)) {1452 } else if (parent->libc == nullptr && target_is_musl(parent->zig_target)) {
1453 if (strcmp(file, "crti.o") == 0) {1453 if (strcmp(file, "crti.o") == 0) {
1454 CFile *c_file = allocate<CFile>(1);1454 CFile *c_file = heap::c_allocator.create<CFile>();
1455 c_file->source_path = musl_start_asm_path(parent, "crti.s");1455 c_file->source_path = musl_start_asm_path(parent, "crti.s");
1456 musl_add_cc_args(parent, c_file, false);1456 musl_add_cc_args(parent, c_file, false);
1457 c_file->args.append("-Qunused-arguments");1457 c_file->args.append("-Qunused-arguments");
1458 return build_libc_object(parent, "crti", c_file, progress_node);1458 return build_libc_object(parent, "crti", c_file, progress_node);
1459 } else if (strcmp(file, "crtn.o") == 0) {1459 } else if (strcmp(file, "crtn.o") == 0) {
1460 CFile *c_file = allocate<CFile>(1);1460 CFile *c_file = heap::c_allocator.create<CFile>();
1461 c_file->source_path = musl_start_asm_path(parent, "crtn.s");1461 c_file->source_path = musl_start_asm_path(parent, "crtn.s");
1462 c_file->args.append("-Qunused-arguments");1462 c_file->args.append("-Qunused-arguments");
1463 musl_add_cc_args(parent, c_file, false);1463 musl_add_cc_args(parent, c_file, false);
1464 return build_libc_object(parent, "crtn", c_file, progress_node);1464 return build_libc_object(parent, "crtn", c_file, progress_node);
1465 } else if (strcmp(file, "crt1.o") == 0) {1465 } else if (strcmp(file, "crt1.o") == 0) {
1466 CFile *c_file = allocate<CFile>(1);1466 CFile *c_file = heap::c_allocator.create<CFile>();
1467 c_file->source_path = path_from_libc(parent, "musl" OS_SEP "crt" OS_SEP "crt1.c");1467 c_file->source_path = path_from_libc(parent, "musl" OS_SEP "crt" OS_SEP "crt1.c");
1468 musl_add_cc_args(parent, c_file, false);1468 musl_add_cc_args(parent, c_file, false);
1469 c_file->args.append("-fno-stack-protector");1469 c_file->args.append("-fno-stack-protector");
1470 c_file->args.append("-DCRT");1470 c_file->args.append("-DCRT");
1471 return build_libc_object(parent, "crt1", c_file, progress_node);1471 return build_libc_object(parent, "crt1", c_file, progress_node);
1472 } else if (strcmp(file, "Scrt1.o") == 0) {1472 } else if (strcmp(file, "Scrt1.o") == 0) {
1473 CFile *c_file = allocate<CFile>(1);1473 CFile *c_file = heap::c_allocator.create<CFile>();
1474 c_file->source_path = path_from_libc(parent, "musl" OS_SEP "crt" OS_SEP "Scrt1.c");1474 c_file->source_path = path_from_libc(parent, "musl" OS_SEP "crt" OS_SEP "Scrt1.c");
1475 musl_add_cc_args(parent, c_file, false);1475 musl_add_cc_args(parent, c_file, false);
1476 c_file->args.append("-fPIC");1476 c_file->args.append("-fPIC");
...@@ -1982,7 +1982,7 @@ static const char *get_def_lib(CodeGen *parent, const char *name, Buf *def_in_fi...@@ -1982,7 +1982,7 @@ static const char *get_def_lib(CodeGen *parent, const char *name, Buf *def_in_fi
1982 Buf *def_include_dir = buf_sprintf("%s" OS_SEP "libc" OS_SEP "mingw" OS_SEP "def-include",1982 Buf *def_include_dir = buf_sprintf("%s" OS_SEP "libc" OS_SEP "mingw" OS_SEP "def-include",
1983 buf_ptr(parent->zig_lib_dir));1983 buf_ptr(parent->zig_lib_dir));
19841984
1985 CacheHash *cache_hash = allocate<CacheHash>(1);1985 CacheHash *cache_hash = heap::c_allocator.create<CacheHash>();
1986 cache_init(cache_hash, manifest_dir);1986 cache_init(cache_hash, manifest_dir);
19871987
1988 cache_buf(cache_hash, compiler_id);1988 cache_buf(cache_hash, compiler_id);
...@@ -2367,7 +2367,7 @@ static void construct_linker_job_coff(LinkJob *lj) {...@@ -2367,7 +2367,7 @@ static void construct_linker_job_coff(LinkJob *lj) {
23672367
2368 lj->args.append(get_def_lib(g, name, &lib_path));2368 lj->args.append(get_def_lib(g, name, &lib_path));
23692369
2370 free(name);2370 mem::os::free(name);
2371 }2371 }
2372}2372}
23732373
src/list.hpp+2-4
...@@ -13,7 +13,7 @@...@@ -13,7 +13,7 @@
13template<typename T>13template<typename T>
14struct ZigList {14struct ZigList {
15 void deinit() {15 void deinit() {
16 deallocate(items, capacity);16 heap::c_allocator.deallocate(items, capacity);
17 }17 }
18 void append(const T& item) {18 void append(const T& item) {
19 ensure_capacity(length + 1);19 ensure_capacity(length + 1);
...@@ -70,7 +70,7 @@ struct ZigList {...@@ -70,7 +70,7 @@ struct ZigList {
70 better_capacity = better_capacity * 5 / 2 + 8;70 better_capacity = better_capacity * 5 / 2 + 8;
71 } while (better_capacity < new_capacity);71 } 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);
74 capacity = better_capacity;74 capacity = better_capacity;
75 }75 }
7676
...@@ -91,5 +91,3 @@ struct ZigList {...@@ -91,5 +91,3 @@ struct ZigList {
91};91};
9292
93#endif93#endif
94
95
src/main.cpp+27-21
...@@ -11,12 +11,14 @@...@@ -11,12 +11,14 @@
11#include "compiler.hpp"11#include "compiler.hpp"
12#include "config.h"12#include "config.h"
13#include "error.hpp"13#include "error.hpp"
14#include "heap.hpp"
14#include "os.hpp"15#include "os.hpp"
15#include "target.hpp"16#include "target.hpp"
16#include "libc_installation.hpp"17#include "libc_installation.hpp"
17#include "userland.h"18#include "userland.h"
18#include "glibc.hpp"19#include "glibc.hpp"
19#include "dump_analysis.hpp"20#include "dump_analysis.hpp"
21#include "mem_profile.hpp"
2022
21#include <stdio.h>23#include <stdio.h>
2224
...@@ -243,21 +245,10 @@ int main_exit(Stage2ProgressNode *root_progress_node, int exit_code) {...@@ -243,21 +245,10 @@ int main_exit(Stage2ProgressNode *root_progress_node, int exit_code) {
243 if (root_progress_node != nullptr) {245 if (root_progress_node != nullptr) {
244 stage2_progress_end(root_progress_node);246 stage2_progress_end(root_progress_node);
245 }247 }
246#ifdef ZIG_ENABLE_MEM_PROFILE
247 if (mem_report) {
248 memprof_dump_stats(stderr);
249 }
250#endif
251 return exit_code;248 return exit_code;
252}249}
253250
254int main(int argc, char **argv) {251static int main0(int argc, char **argv) {
255 stage2_attach_segfault_handler();
256
257#ifdef ZIG_ENABLE_MEM_PROFILE
258 memprof_init();
259#endif
260
261 char *arg0 = argv[0];252 char *arg0 = argv[0];
262 Error err;253 Error err;
263254
...@@ -278,9 +269,6 @@ int main(int argc, char **argv) {...@@ -278,9 +269,6 @@ int main(int argc, char **argv) {
278 return ZigClang_main(argc, argv);269 return ZigClang_main(argc, argv);
279 }270 }
280271
281 // Must be before all os.hpp function calls.
282 os_init();
283
284 if (argc == 2 && strcmp(argv[1], "id") == 0) {272 if (argc == 2 && strcmp(argv[1], "id") == 0) {
285 Buf *compiler_id;273 Buf *compiler_id;
286 if ((err = get_compiler_id(&compiler_id))) {274 if ((err = get_compiler_id(&compiler_id))) {
...@@ -439,7 +427,7 @@ int main(int argc, char **argv) {...@@ -439,7 +427,7 @@ int main(int argc, char **argv) {
439 bool enable_doc_generation = false;427 bool enable_doc_generation = false;
440 bool disable_bin_generation = false;428 bool disable_bin_generation = false;
441 const char *cache_dir = nullptr;429 const char *cache_dir = nullptr;
442 CliPkg *cur_pkg = allocate<CliPkg>(1);430 CliPkg *cur_pkg = heap::c_allocator.create<CliPkg>();
443 BuildMode build_mode = BuildModeDebug;431 BuildMode build_mode = BuildModeDebug;
444 ZigList<const char *> test_exec_args = {0};432 ZigList<const char *> test_exec_args = {0};
445 int runtime_args_start = -1;433 int runtime_args_start = -1;
...@@ -635,6 +623,7 @@ int main(int argc, char **argv) {...@@ -635,6 +623,7 @@ int main(int argc, char **argv) {
635 } else if (strcmp(arg, "-fmem-report") == 0) {623 } else if (strcmp(arg, "-fmem-report") == 0) {
636#ifdef ZIG_ENABLE_MEM_PROFILE624#ifdef ZIG_ENABLE_MEM_PROFILE
637 mem_report = true;625 mem_report = true;
626 mem::report_print = true;
638#else627#else
639 fprintf(stderr, "-fmem-report requires configuring with -DZIG_ENABLE_MEM_PROFILE=ON\n");628 fprintf(stderr, "-fmem-report requires configuring with -DZIG_ENABLE_MEM_PROFILE=ON\n");
640 return print_error_usage(arg0);629 return print_error_usage(arg0);
...@@ -695,7 +684,7 @@ int main(int argc, char **argv) {...@@ -695,7 +684,7 @@ int main(int argc, char **argv) {
695 fprintf(stderr, "Expected 2 arguments after --pkg-begin\n");684 fprintf(stderr, "Expected 2 arguments after --pkg-begin\n");
696 return print_error_usage(arg0);685 return print_error_usage(arg0);
697 }686 }
698 CliPkg *new_cur_pkg = allocate<CliPkg>(1);687 CliPkg *new_cur_pkg = heap::c_allocator.create<CliPkg>();
699 i += 1;688 i += 1;
700 new_cur_pkg->name = argv[i];689 new_cur_pkg->name = argv[i];
701 i += 1;690 i += 1;
...@@ -810,7 +799,7 @@ int main(int argc, char **argv) {...@@ -810,7 +799,7 @@ int main(int argc, char **argv) {
810 } else if (strcmp(arg, "--object") == 0) {799 } else if (strcmp(arg, "--object") == 0) {
811 objects.append(argv[i]);800 objects.append(argv[i]);
812 } else if (strcmp(arg, "--c-source") == 0) {801 } else if (strcmp(arg, "--c-source") == 0) {
813 CFile *c_file = allocate<CFile>(1);802 CFile *c_file = heap::c_allocator.create<CFile>();
814 for (;;) {803 for (;;) {
815 if (argv[i][0] == '-') {804 if (argv[i][0] == '-') {
816 c_file->args.append(argv[i]);805 c_file->args.append(argv[i]);
...@@ -990,7 +979,7 @@ int main(int argc, char **argv) {...@@ -990,7 +979,7 @@ int main(int argc, char **argv) {
990 }979 }
991 }980 }
992 if (target_is_glibc(&target)) {981 if (target_is_glibc(&target)) {
993 target.glibc_version = allocate<ZigGLibCVersion>(1);982 target.glibc_version = heap::c_allocator.create<ZigGLibCVersion>();
994983
995 if (target_glibc != nullptr) {984 if (target_glibc != nullptr) {
996 if ((err = target_parse_glibc_version(target.glibc_version, target_glibc))) {985 if ((err = target_parse_glibc_version(target.glibc_version, target_glibc))) {
...@@ -1138,7 +1127,7 @@ int main(int argc, char **argv) {...@@ -1138,7 +1127,7 @@ int main(int argc, char **argv) {
1138 }1127 }
1139 ZigLibCInstallation *libc = nullptr;1128 ZigLibCInstallation *libc = nullptr;
1140 if (libc_txt != nullptr) {1129 if (libc_txt != nullptr) {
1141 libc = allocate<ZigLibCInstallation>(1);1130 libc = heap::c_allocator.create<ZigLibCInstallation>();
1142 if ((err = zig_libc_parse(libc, buf_create_from_str(libc_txt), &target, true))) {1131 if ((err = zig_libc_parse(libc, buf_create_from_str(libc_txt), &target, true))) {
1143 fprintf(stderr, "Unable to parse --libc text file: %s\n", err_str(err));1132 fprintf(stderr, "Unable to parse --libc text file: %s\n", err_str(err));
1144 return main_exit(root_progress_node, EXIT_FAILURE);1133 return main_exit(root_progress_node, EXIT_FAILURE);
...@@ -1269,7 +1258,8 @@ int main(int argc, char **argv) {...@@ -1269,7 +1258,8 @@ int main(int argc, char **argv) {
12691258
1270 if (cmd == CmdRun) {1259 if (cmd == CmdRun) {
1271#ifdef ZIG_ENABLE_MEM_PROFILE1260#ifdef ZIG_ENABLE_MEM_PROFILE
1272 memprof_dump_stats(stderr);1261 if (mem::report_print)
1262 mem::print_report();
1273#endif1263#endif
12741264
1275 const char *exec_path = buf_ptr(&g->output_file_path);1265 const char *exec_path = buf_ptr(&g->output_file_path);
...@@ -1384,4 +1374,20 @@ int main(int argc, char **argv) {...@@ -1384,4 +1374,20 @@ int main(int argc, char **argv) {
1384 case CmdNone:1374 case CmdNone:
1385 return print_full_usage(arg0, stderr, EXIT_FAILURE);1375 return print_full_usage(arg0, stderr, EXIT_FAILURE);
1386 }1376 }
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;
1387}1393}
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) {...@@ -107,7 +107,7 @@ static void populate_termination(Termination *term, int status) {
107}107}
108108
109static void os_spawn_process_posix(ZigList<const char *> &args, Termination *term) {109static 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);
111 for (size_t i = 0; i < args.length; i += 1) {111 for (size_t i = 0; i < args.length; i += 1) {
112 argv[i] = args.at(i);112 argv[i] = args.at(i);
113 }113 }
...@@ -688,7 +688,7 @@ static Buf os_path_resolve_posix(Buf **paths_ptr, size_t paths_len) {...@@ -688,7 +688,7 @@ static Buf os_path_resolve_posix(Buf **paths_ptr, size_t paths_len) {
688688
689 if (have_abs) {689 if (have_abs) {
690 result_len = max_size;690 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);
692 } else {692 } else {
693 Buf cwd = BUF_INIT;693 Buf cwd = BUF_INIT;
694 int err;694 int err;
...@@ -696,7 +696,7 @@ static Buf os_path_resolve_posix(Buf **paths_ptr, size_t paths_len) {...@@ -696,7 +696,7 @@ static Buf os_path_resolve_posix(Buf **paths_ptr, size_t paths_len) {
696 zig_panic("get cwd failed");696 zig_panic("get cwd failed");
697 }697 }
698 result_len = max_size + buf_len(&cwd) + 1;698 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);
700 memcpy(result_ptr, buf_ptr(&cwd), buf_len(&cwd));700 memcpy(result_ptr, buf_ptr(&cwd), buf_len(&cwd));
701 result_index += buf_len(&cwd);701 result_index += buf_len(&cwd);
702 }702 }
...@@ -816,7 +816,7 @@ static Error os_exec_process_posix(ZigList<const char *> &args,...@@ -816,7 +816,7 @@ static Error os_exec_process_posix(ZigList<const char *> &args,
816 if (dup2(stderr_pipe[1], STDERR_FILENO) == -1)816 if (dup2(stderr_pipe[1], STDERR_FILENO) == -1)
817 zig_panic("dup2 failed");817 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);
820 argv[args.length] = nullptr;820 argv[args.length] = nullptr;
821 for (size_t i = 0; i < args.length; i += 1) {821 for (size_t i = 0; i < args.length; i += 1) {
822 argv[i] = args.at(i);822 argv[i] = args.at(i);
...@@ -1134,7 +1134,7 @@ static bool is_stderr_cyg_pty(void) {...@@ -1134,7 +1134,7 @@ static bool is_stderr_cyg_pty(void) {
1134 if (stderr_handle == INVALID_HANDLE_VALUE)1134 if (stderr_handle == INVALID_HANDLE_VALUE)
1135 return false;1135 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;
1138 FILE_NAME_INFO *nameinfo;1138 FILE_NAME_INFO *nameinfo;
1139 WCHAR *p = NULL;1139 WCHAR *p = NULL;
11401140
...@@ -1142,7 +1142,7 @@ static bool is_stderr_cyg_pty(void) {...@@ -1142,7 +1142,7 @@ static bool is_stderr_cyg_pty(void) {
1142 if (GetFileType(stderr_handle) != FILE_TYPE_PIPE) {1142 if (GetFileType(stderr_handle) != FILE_TYPE_PIPE) {
1143 return 0;1143 return 0;
1144 }1144 }
1145 nameinfo = (FILE_NAME_INFO *)allocate<char>(size);1145 nameinfo = reinterpret_cast<FILE_NAME_INFO *>(heap::c_allocator.allocate<char>(size));
1146 if (nameinfo == NULL) {1146 if (nameinfo == NULL) {
1147 return 0;1147 return 0;
1148 }1148 }
...@@ -1179,7 +1179,7 @@ static bool is_stderr_cyg_pty(void) {...@@ -1179,7 +1179,7 @@ static bool is_stderr_cyg_pty(void) {
1179 }1179 }
1180 }1180 }
1181 }1181 }
1182 free(nameinfo);1182 heap::c_allocator.deallocate(reinterpret_cast<char *>(nameinfo), size);
1183 return (p != NULL);1183 return (p != NULL);
1184}1184}
1185#endif1185#endif
src/parser.cpp+3-3
...@@ -147,7 +147,7 @@ static void ast_invalid_token_error(ParseContext *pc, Token *token) {...@@ -147,7 +147,7 @@ static void ast_invalid_token_error(ParseContext *pc, Token *token) {
147}147}
148148
149static AstNode *ast_create_node_no_line_info(ParseContext *pc, NodeType type) {149static 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>();
151 node->type = type;151 node->type = type;
152 node->owner = pc->owner;152 node->owner = pc->owner;
153 return node;153 return node;
...@@ -1966,7 +1966,7 @@ static AsmOutput *ast_parse_asm_output_item(ParseContext *pc) {...@@ -1966,7 +1966,7 @@ static AsmOutput *ast_parse_asm_output_item(ParseContext *pc) {
19661966
1967 expect_token(pc, TokenIdRParen);1967 expect_token(pc, TokenIdRParen);
19681968
1969 AsmOutput *res = allocate<AsmOutput>(1);1969 AsmOutput *res = heap::c_allocator.create<AsmOutput>();
1970 res->asm_symbolic_name = token_buf(sym_name);1970 res->asm_symbolic_name = token_buf(sym_name);
1971 res->constraint = token_buf(str);1971 res->constraint = token_buf(str);
1972 res->variable_name = token_buf(var_name);1972 res->variable_name = token_buf(var_name);
...@@ -2003,7 +2003,7 @@ static AsmInput *ast_parse_asm_input_item(ParseContext *pc) {...@@ -2003,7 +2003,7 @@ static AsmInput *ast_parse_asm_input_item(ParseContext *pc) {
2003 AstNode *expr = ast_expect(pc, ast_parse_expr);2003 AstNode *expr = ast_expect(pc, ast_parse_expr);
2004 expect_token(pc, TokenIdRParen);2004 expect_token(pc, TokenIdRParen);
20052005
2006 AsmInput *res = allocate<AsmInput>(1);2006 AsmInput *res = heap::c_allocator.create<AsmInput>();
2007 res->asm_symbolic_name = token_buf(sym_name);2007 res->asm_symbolic_name = token_buf(sym_name);
2008 res->constraint = token_buf(constraint);2008 res->constraint = token_buf(constraint);
2009 res->expr = expr;2009 res->expr = expr;
src/target.cpp+1-1
...@@ -520,7 +520,7 @@ void get_native_target(ZigTarget *target) {...@@ -520,7 +520,7 @@ void get_native_target(ZigTarget *target) {
520 target->abi = target_default_abi(target->arch, target->os);520 target->abi = target_default_abi(target->arch, target->os);
521 }521 }
522 if (target_is_glibc(target)) {522 if (target_is_glibc(target)) {
523 target->glibc_version = allocate<ZigGLibCVersion>(1);523 target->glibc_version = heap::c_allocator.create<ZigGLibCVersion>();
524 target_init_default_glibc_version(target);524 target_init_default_glibc_version(target);
525#ifdef ZIG_OS_LINUX525#ifdef ZIG_OS_LINUX
526 Error err;526 Error err;
src/tokenizer.cpp+2-2
...@@ -397,10 +397,10 @@ static void invalid_char_error(Tokenize *t, uint8_t c) {...@@ -397,10 +397,10 @@ static void invalid_char_error(Tokenize *t, uint8_t c) {
397void tokenize(Buf *buf, Tokenization *out) {397void tokenize(Buf *buf, Tokenization *out) {
398 Tokenize t = {0};398 Tokenize t = {0};
399 t.out = out;399 t.out = out;
400 t.tokens = out->tokens = allocate<ZigList<Token>>(1);400 t.tokens = out->tokens = heap::c_allocator.create<ZigList<Token>>();
401 t.buf = buf;401 t.buf = buf;
402402
403 out->line_offsets = allocate<ZigList<size_t>>(1);403 out->line_offsets = heap::c_allocator.create<ZigList<size_t>>();
404 out->line_offsets->append(0);404 out->line_offsets->append(0);
405405
406 // Skip the UTF-8 BOM if present406 // 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_...@@ -101,7 +101,7 @@ Error stage2_cpu_features_parse(struct Stage2CpuFeatures **out, const char *zig_
101 const char *cpu_name, const char *cpu_features)101 const char *cpu_name, const char *cpu_features)
102{102{
103 if (zig_triple == nullptr) {103 if (zig_triple == nullptr) {
104 Stage2CpuFeatures *result = allocate<Stage2CpuFeatures>(1, "Stage2CpuFeatures");104 Stage2CpuFeatures *result = heap::c_allocator.create<Stage2CpuFeatures>();
105 result->llvm_cpu_name = ZigLLVMGetHostCPUName();105 result->llvm_cpu_name = ZigLLVMGetHostCPUName();
106 result->llvm_cpu_features = ZigLLVMGetNativeFeatures();106 result->llvm_cpu_features = ZigLLVMGetNativeFeatures();
107 result->builtin_str = "arch.getBaselineCpuFeatures();\n";107 result->builtin_str = "arch.getBaselineCpuFeatures();\n";
...@@ -110,7 +110,7 @@ Error stage2_cpu_features_parse(struct Stage2CpuFeatures **out, const char *zig_...@@ -110,7 +110,7 @@ Error stage2_cpu_features_parse(struct Stage2CpuFeatures **out, const char *zig_
110 return ErrorNone;110 return ErrorNone;
111 }111 }
112 if (cpu_name == nullptr && cpu_features == nullptr) {112 if (cpu_name == nullptr && cpu_features == nullptr) {
113 Stage2CpuFeatures *result = allocate<Stage2CpuFeatures>(1, "Stage2CpuFeatures");113 Stage2CpuFeatures *result = heap::c_allocator.create<Stage2CpuFeatures>();
114 result->builtin_str = "arch.getBaselineCpuFeatures();\n";114 result->builtin_str = "arch.getBaselineCpuFeatures();\n";
115 result->cache_hash = "\n\n";115 result->cache_hash = "\n\n";
116 *out = result;116 *out = result;
src/util.hpp+5-127
...@@ -8,69 +8,19 @@...@@ -8,69 +8,19 @@
8#ifndef ZIG_UTIL_HPP8#ifndef ZIG_UTIL_HPP
9#define ZIG_UTIL_HPP9#define ZIG_UTIL_HPP
1010
11#include "memory_profiling.hpp"
12
13#include <stdlib.h>11#include <stdlib.h>
14#include <stdint.h>12#include <stdint.h>
15#include <string.h>13#include <string.h>
16#include <assert.h>
17#include <ctype.h>14#include <ctype.h>
1815
19#if defined(_MSC_VER)16#if defined(_MSC_VER)
20
21#include <intrin.h> 17#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__
67#endif18#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__)20#include "config.h"
7021#include "util_base.hpp"
71// Assertions in stage1 are always on, and they call zig @panic.22#include "heap.hpp"
72#undef assert23#include "mem.hpp"
73#define assert(ok) zig_assert(ok, __FILE__, __LINE__, __func__)
7424
75#if defined(_MSC_VER)25#if defined(_MSC_VER)
76static inline int clzll(unsigned long long mask) {26static inline int clzll(unsigned long long mask) {
...@@ -107,78 +57,6 @@ static inline int ctzll(unsigned long long mask) {...@@ -107,78 +57,6 @@ static inline int ctzll(unsigned long long mask) {
107#define ctzll(x) __builtin_ctzll(x)57#define ctzll(x) __builtin_ctzll(x)
108#endif58#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
182template <typename T, size_t n>60template <typename T, size_t n>
183constexpr size_t array_length(const T (&)[n]) {61constexpr size_t array_length(const T (&)[n]) {
184 return n;62 return n;
...@@ -293,7 +171,7 @@ struct Slice {...@@ -293,7 +171,7 @@ struct Slice {
293 }171 }
294172
295 static inline Slice<T> alloc(size_t n) {173 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};
297 }175 }
298};176};
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