| ... | @@ -559,6 +559,10 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionAlignCast *) { | ... | @@ -559,6 +559,10 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionAlignCast *) { |
| 559 | return IrInstructionIdAlignCast; | 559 | return IrInstructionIdAlignCast; |
| 560 | } | 560 | } |
| 561 | | 561 | |
| | 562 | static constexpr IrInstructionId ir_instruction_id(IrInstructionOpaqueType *) { |
| | 563 | return IrInstructionIdOpaqueType; |
| | 564 | } |
| | 565 | |
| 562 | template<typename T> | 566 | template<typename T> |
| 563 | static T *ir_create_instruction(IrBuilder *irb, Scope *scope, AstNode *source_node) { | 567 | static T *ir_create_instruction(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 564 | T *special_instruction = allocate<T>(1); | 568 | T *special_instruction = allocate<T>(1); |
| ... | @@ -2238,6 +2242,12 @@ static IrInstruction *ir_build_align_cast(IrBuilder *irb, Scope *scope, AstNode | ... | @@ -2238,6 +2242,12 @@ static IrInstruction *ir_build_align_cast(IrBuilder *irb, Scope *scope, AstNode |
| 2238 | return &instruction->base; | 2242 | return &instruction->base; |
| 2239 | } | 2243 | } |
| 2240 | | 2244 | |
| | 2245 | static IrInstruction *ir_build_opaque_type(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| | 2246 | IrInstructionOpaqueType *instruction = ir_build_instruction<IrInstructionOpaqueType>(irb, scope, source_node); |
| | 2247 | |
| | 2248 | return &instruction->base; |
| | 2249 | } |
| | 2250 | |
| 2241 | static IrInstruction *ir_instruction_br_get_dep(IrInstructionBr *instruction, size_t index) { | 2251 | static IrInstruction *ir_instruction_br_get_dep(IrInstructionBr *instruction, size_t index) { |
| 2242 | return nullptr; | 2252 | return nullptr; |
| 2243 | } | 2253 | } |
| ... | @@ -2956,6 +2966,10 @@ static IrInstruction *ir_instruction_aligncast_get_dep(IrInstructionAlignCast *i | ... | @@ -2956,6 +2966,10 @@ static IrInstruction *ir_instruction_aligncast_get_dep(IrInstructionAlignCast *i |
| 2956 | } | 2966 | } |
| 2957 | } | 2967 | } |
| 2958 | | 2968 | |
| | 2969 | static IrInstruction *ir_instruction_opaquetype_get_dep(IrInstructionOpaqueType *instruction, size_t index) { |
| | 2970 | return nullptr; |
| | 2971 | } |
| | 2972 | |
| 2959 | static IrInstruction *ir_instruction_get_dep(IrInstruction *instruction, size_t index) { | 2973 | static IrInstruction *ir_instruction_get_dep(IrInstruction *instruction, size_t index) { |
| 2960 | switch (instruction->id) { | 2974 | switch (instruction->id) { |
| 2961 | case IrInstructionIdInvalid: | 2975 | case IrInstructionIdInvalid: |
| ... | @@ -3154,6 +3168,8 @@ static IrInstruction *ir_instruction_get_dep(IrInstruction *instruction, size_t | ... | @@ -3154,6 +3168,8 @@ static IrInstruction *ir_instruction_get_dep(IrInstruction *instruction, size_t |
| 3154 | return ir_instruction_ptrtypeof_get_dep((IrInstructionPtrTypeOf *) instruction, index); | 3168 | return ir_instruction_ptrtypeof_get_dep((IrInstructionPtrTypeOf *) instruction, index); |
| 3155 | case IrInstructionIdAlignCast: | 3169 | case IrInstructionIdAlignCast: |
| 3156 | return ir_instruction_aligncast_get_dep((IrInstructionAlignCast *) instruction, index); | 3170 | return ir_instruction_aligncast_get_dep((IrInstructionAlignCast *) instruction, index); |
| | 3171 | case IrInstructionIdOpaqueType: |
| | 3172 | return ir_instruction_opaquetype_get_dep((IrInstructionOpaqueType *) instruction, index); |
| 3157 | } | 3173 | } |
| 3158 | zig_unreachable(); | 3174 | zig_unreachable(); |
| 3159 | } | 3175 | } |
| ... | @@ -4578,6 +4594,8 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo | ... | @@ -4578,6 +4594,8 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo |
| 4578 | | 4594 | |
| 4579 | return ir_build_align_cast(irb, scope, node, arg0_value, arg1_value); | 4595 | return ir_build_align_cast(irb, scope, node, arg0_value, arg1_value); |
| 4580 | } | 4596 | } |
| | 4597 | case BuiltinFnIdOpaqueType: |
| | 4598 | return ir_build_opaque_type(irb, scope, node); |
| 4581 | } | 4599 | } |
| 4582 | zig_unreachable(); | 4600 | zig_unreachable(); |
| 4583 | } | 4601 | } |
| ... | @@ -6044,27 +6062,30 @@ static bool render_instance_name_recursive(CodeGen *codegen, Buf *name, Scope *o | ... | @@ -6044,27 +6062,30 @@ static bool render_instance_name_recursive(CodeGen *codegen, Buf *name, Scope *o |
| 6044 | return true; | 6062 | return true; |
| 6045 | } | 6063 | } |
| 6046 | | 6064 | |
| 6047 | static IrInstruction *ir_gen_container_decl(IrBuilder *irb, Scope *parent_scope, AstNode *node) { | 6065 | static Buf *get_anon_type_name(CodeGen *codegen, IrExecutable *exec, const char *kind_name, AstNode *source_node) { |
| 6048 | assert(node->type == NodeTypeContainerDecl); | 6066 | if (exec->name) { |
| 6049 | | 6067 | return exec->name; |
| 6050 | ContainerKind kind = node->data.container_decl.kind; | | |
| 6051 | Buf *name; | | |
| 6052 | if (irb->exec->name) { | | |
| 6053 | name = irb->exec->name; | | |
| 6054 | } else { | 6068 | } else { |
| 6055 | FnTableEntry *fn_entry = exec_fn_entry(irb->exec); | 6069 | FnTableEntry *fn_entry = exec_fn_entry(exec); |
| 6056 | if (fn_entry) { | 6070 | if (fn_entry) { |
| 6057 | name = buf_alloc(); | 6071 | Buf *name = buf_alloc(); |
| 6058 | buf_append_buf(name, &fn_entry->symbol_name); | 6072 | buf_append_buf(name, &fn_entry->symbol_name); |
| 6059 | buf_appendf(name, "("); | 6073 | buf_appendf(name, "("); |
| 6060 | render_instance_name_recursive(irb->codegen, name, &fn_entry->fndef_scope->base, irb->exec->begin_scope); | 6074 | render_instance_name_recursive(codegen, name, &fn_entry->fndef_scope->base, exec->begin_scope); |
| 6061 | buf_appendf(name, ")"); | 6075 | buf_appendf(name, ")"); |
| | 6076 | return name; |
| 6062 | } else { | 6077 | } else { |
| 6063 | name = buf_sprintf("(anonymous %s at %s:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ")", container_string(kind), | 6078 | return buf_sprintf("(anonymous %s at %s:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ")", kind_name, |
| 6064 | buf_ptr(node->owner->path), node->line + 1, node->column + 1); | 6079 | buf_ptr(source_node->owner->path), source_node->line + 1, source_node->column + 1); |
| 6065 | } | 6080 | } |
| 6066 | } | 6081 | } |
| | 6082 | } |
| 6067 | | 6083 | |
| | 6084 | static IrInstruction *ir_gen_container_decl(IrBuilder *irb, Scope *parent_scope, AstNode *node) { |
| | 6085 | assert(node->type == NodeTypeContainerDecl); |
| | 6086 | |
| | 6087 | ContainerKind kind = node->data.container_decl.kind; |
| | 6088 | Buf *name = get_anon_type_name(irb->codegen, irb->exec, container_string(kind), node); |
| 6068 | | 6089 | |
| 6069 | VisibMod visib_mod = VisibModPub; | 6090 | VisibMod visib_mod = VisibModPub; |
| 6070 | TldContainer *tld_container = allocate<TldContainer>(1); | 6091 | TldContainer *tld_container = allocate<TldContainer>(1); |
| ... | @@ -15143,6 +15164,14 @@ static TypeTableEntry *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstr | ... | @@ -15143,6 +15164,14 @@ static TypeTableEntry *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstr |
| 15143 | return result->value.type; | 15164 | return result->value.type; |
| 15144 | } | 15165 | } |
| 15145 | | 15166 | |
| | 15167 | static TypeTableEntry *ir_analyze_instruction_opaque_type(IrAnalyze *ira, IrInstructionOpaqueType *instruction) { |
| | 15168 | Buf *name = get_anon_type_name(ira->codegen, ira->new_irb.exec, "opaque", instruction->base.source_node); |
| | 15169 | ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); |
| | 15170 | out_val->data.x_type = get_opaque_type(ira->codegen, instruction->base.scope, instruction->base.source_node, |
| | 15171 | buf_ptr(name)); |
| | 15172 | return ira->codegen->builtin_types.entry_type; |
| | 15173 | } |
| | 15174 | |
| 15146 | static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstruction *instruction) { | 15175 | static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstruction *instruction) { |
| 15147 | switch (instruction->id) { | 15176 | switch (instruction->id) { |
| 15148 | case IrInstructionIdInvalid: | 15177 | case IrInstructionIdInvalid: |
| ... | @@ -15329,6 +15358,8 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi | ... | @@ -15329,6 +15358,8 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi |
| 15329 | return ir_analyze_instruction_ptr_type_of(ira, (IrInstructionPtrTypeOf *)instruction); | 15358 | return ir_analyze_instruction_ptr_type_of(ira, (IrInstructionPtrTypeOf *)instruction); |
| 15330 | case IrInstructionIdAlignCast: | 15359 | case IrInstructionIdAlignCast: |
| 15331 | return ir_analyze_instruction_align_cast(ira, (IrInstructionAlignCast *)instruction); | 15360 | return ir_analyze_instruction_align_cast(ira, (IrInstructionAlignCast *)instruction); |
| | 15361 | case IrInstructionIdOpaqueType: |
| | 15362 | return ir_analyze_instruction_opaque_type(ira, (IrInstructionOpaqueType *)instruction); |
| 15332 | } | 15363 | } |
| 15333 | zig_unreachable(); | 15364 | zig_unreachable(); |
| 15334 | } | 15365 | } |
| ... | @@ -15507,6 +15538,7 @@ bool ir_has_side_effects(IrInstruction *instruction) { | ... | @@ -15507,6 +15538,7 @@ bool ir_has_side_effects(IrInstruction *instruction) { |
| 15507 | case IrInstructionIdOffsetOf: | 15538 | case IrInstructionIdOffsetOf: |
| 15508 | case IrInstructionIdTypeId: | 15539 | case IrInstructionIdTypeId: |
| 15509 | case IrInstructionIdAlignCast: | 15540 | case IrInstructionIdAlignCast: |
| | 15541 | case IrInstructionIdOpaqueType: |
| 15510 | return false; | 15542 | return false; |
| 15511 | case IrInstructionIdAsm: | 15543 | case IrInstructionIdAsm: |
| 15512 | { | 15544 | { |