| author | |
| committer | |
| log | d0b055d69e44848cf602a1ce8709ed568728a822 |
| tree | 9c7cd9c0b5a94eba9f69b71b4b1a6f953fdb091f |
| parent | 96d64a40a6cd31b8483c9f2899561c23fa266060 |
| signature | Commit is signed but in an unrecognized format. |
4 files changed, 141 insertions(+), 20 deletions(-)
src/all_types.hpp+3| ... | @@ -473,6 +473,9 @@ struct ZigValue { | ... | @@ -473,6 +473,9 @@ struct ZigValue { |
| 473 | // uncomment these to find bugs. can't leave them uncommented because of a gcc-9 warning | 473 | // uncomment these to find bugs. can't leave them uncommented because of a gcc-9 warning |
| 474 | //ZigValue(const ZigValue &other) = delete; // plz zero initialize with {} | 474 | //ZigValue(const ZigValue &other) = delete; // plz zero initialize with {} |
| 475 | //ZigValue& operator= (const ZigValue &other) = delete; // use copy_const_val | 475 | //ZigValue& operator= (const ZigValue &other) = delete; // use copy_const_val |
| 476 | |||
| 477 | // for use in debuggers | ||
| 478 | void dump(); | ||
| 476 | }; | 479 | }; |
| 477 | 480 | ||
| 478 | enum ReturnKnowledge { | 481 | enum ReturnKnowledge { |
src/analyze.cpp+127-1| ... | @@ -9304,11 +9304,12 @@ bool type_has_optional_repr(ZigType *ty) { | ... | @@ -9304,11 +9304,12 @@ bool type_has_optional_repr(ZigType *ty) { |
| 9304 | 9304 | ||
| 9305 | void copy_const_val(ZigValue *dest, ZigValue *src) { | 9305 | void copy_const_val(ZigValue *dest, ZigValue *src) { |
| 9306 | uint32_t prev_align = dest->llvm_align; | 9306 | uint32_t prev_align = dest->llvm_align; |
| 9307 | ConstParent prev_parent = dest->parent; | ||
| 9307 | memcpy(dest, src, sizeof(ZigValue)); | 9308 | memcpy(dest, src, sizeof(ZigValue)); |
| 9308 | dest->llvm_align = prev_align; | 9309 | dest->llvm_align = prev_align; |
| 9309 | if (src->special != ConstValSpecialStatic) | 9310 | if (src->special != ConstValSpecialStatic) |
| 9310 | return; | 9311 | return; |
| 9311 | dest->parent.id = ConstParentIdNone; | 9312 | dest->parent = prev_parent; |
| 9312 | if (dest->type->id == ZigTypeIdStruct) { | 9313 | if (dest->type->id == ZigTypeIdStruct) { |
| 9313 | dest->data.x_struct.fields = alloc_const_vals_ptrs(dest->type->data.structure.src_field_count); | 9314 | dest->data.x_struct.fields = alloc_const_vals_ptrs(dest->type->data.structure.src_field_count); |
| 9314 | for (size_t i = 0; i < dest->type->data.structure.src_field_count; i += 1) { | 9315 | for (size_t i = 0; i < dest->type->data.structure.src_field_count; i += 1) { |
| ... | @@ -9362,3 +9363,128 @@ bool type_is_numeric(ZigType *ty) { | ... | @@ -9362,3 +9363,128 @@ bool type_is_numeric(ZigType *ty) { |
| 9362 | } | 9363 | } |
| 9363 | zig_unreachable(); | 9364 | zig_unreachable(); |
| 9364 | } | 9365 | } |
| 9366 | |||
| 9367 | static void dump_value_indent(ZigValue *val, int indent) { | ||
| 9368 | for (int i = 0; i < indent; i += 1) { | ||
| 9369 | fprintf(stderr, " "); | ||
| 9370 | } | ||
| 9371 | fprintf(stderr, "Value@%p(", val); | ||
| 9372 | if (val->type != nullptr) { | ||
| 9373 | fprintf(stderr, "%s)", buf_ptr(&val->type->name)); | ||
| 9374 | } else { | ||
| 9375 | fprintf(stderr, "type=nullptr)"); | ||
| 9376 | } | ||
| 9377 | switch (val->special) { | ||
| 9378 | case ConstValSpecialUndef: | ||
| 9379 | fprintf(stderr, "[undefined]\n"); | ||
| 9380 | return; | ||
| 9381 | case ConstValSpecialLazy: | ||
| 9382 | fprintf(stderr, "[lazy]\n"); | ||
| 9383 | return; | ||
| 9384 | case ConstValSpecialRuntime: | ||
| 9385 | fprintf(stderr, "[runtime]\n"); | ||
| 9386 | return; | ||
| 9387 | case ConstValSpecialStatic: | ||
| 9388 | break; | ||
| 9389 | } | ||
| 9390 | if (val->type == nullptr) | ||
| 9391 | return; | ||
| 9392 | switch (val->type->id) { | ||
| 9393 | case ZigTypeIdInvalid: | ||
| 9394 | fprintf(stderr, "<invalid>\n"); | ||
| 9395 | return; | ||
| 9396 | case ZigTypeIdUnreachable: | ||
| 9397 | fprintf(stderr, "<unreachable>\n"); | ||
| 9398 | return; | ||
| 9399 | case ZigTypeIdVoid: | ||
| 9400 | fprintf(stderr, "<{}>\n"); | ||
| 9401 | return; | ||
| 9402 | case ZigTypeIdMetaType: | ||
| 9403 | fprintf(stderr, "<%s>\n", buf_ptr(&val->data.x_type->name)); | ||
| 9404 | return; | ||
| 9405 | case ZigTypeIdBool: | ||
| 9406 | fprintf(stderr, "<%s>\n", val->data.x_bool ? "true" : "false"); | ||
| 9407 | return; | ||
| 9408 | case ZigTypeIdComptimeFloat: | ||
| 9409 | case ZigTypeIdComptimeInt: | ||
| 9410 | case ZigTypeIdInt: | ||
| 9411 | case ZigTypeIdFloat: | ||
| 9412 | case ZigTypeIdUndefined: | ||
| 9413 | fprintf(stderr, "<TODO dump number>\n"); | ||
| 9414 | return; | ||
| 9415 | |||
| 9416 | case ZigTypeIdStruct: | ||
| 9417 | fprintf(stderr, "<struct\n"); | ||
| 9418 | for (size_t i = 0; i < val->type->data.structure.src_field_count; i += 1) { | ||
| 9419 | for (int j = 0; j < indent; j += 1) { | ||
| 9420 | fprintf(stderr, " "); | ||
| 9421 | } | ||
| 9422 | fprintf(stderr, "%s: ", buf_ptr(val->type->data.structure.fields[i]->name)); | ||
| 9423 | dump_value_indent(val->data.x_struct.fields[i], 1); | ||
| 9424 | } | ||
| 9425 | for (int i = 0; i < indent; i += 1) { | ||
| 9426 | fprintf(stderr, " "); | ||
| 9427 | } | ||
| 9428 | fprintf(stderr, ">\n"); | ||
| 9429 | return; | ||
| 9430 | |||
| 9431 | case ZigTypeIdOptional: | ||
| 9432 | fprintf(stderr, "<\n"); | ||
| 9433 | dump_value_indent(val->data.x_optional, indent + 1); | ||
| 9434 | |||
| 9435 | for (int i = 0; i < indent; i += 1) { | ||
| 9436 | fprintf(stderr, " "); | ||
| 9437 | } | ||
| 9438 | fprintf(stderr, ">\n"); | ||
| 9439 | return; | ||
| 9440 | |||
| 9441 | case ZigTypeIdErrorUnion: | ||
| 9442 | if (val->data.x_err_union.payload != nullptr) { | ||
| 9443 | fprintf(stderr, "<\n"); | ||
| 9444 | dump_value_indent(val->data.x_err_union.payload, indent + 1); | ||
| 9445 | } else { | ||
| 9446 | fprintf(stderr, "<\n"); | ||
| 9447 | dump_value_indent(val->data.x_err_union.error_set, 0); | ||
| 9448 | } | ||
| 9449 | for (int i = 0; i < indent; i += 1) { | ||
| 9450 | fprintf(stderr, " "); | ||
| 9451 | } | ||
| 9452 | fprintf(stderr, ">\n"); | ||
| 9453 | return; | ||
| 9454 | |||
| 9455 | case ZigTypeIdPointer: | ||
| 9456 | switch (val->data.x_ptr.special) { | ||
| 9457 | case ConstPtrSpecialRef: | ||
| 9458 | fprintf(stderr, "<ref\n"); | ||
| 9459 | dump_value_indent(val->data.x_ptr.data.ref.pointee, indent + 1); | ||
| 9460 | break; | ||
| 9461 | default: | ||
| 9462 | fprintf(stderr, "TODO dump more pointer things\n"); | ||
| 9463 | } | ||
| 9464 | for (int i = 0; i < indent; i += 1) { | ||
| 9465 | fprintf(stderr, " "); | ||
| 9466 | } | ||
| 9467 | fprintf(stderr, ">\n"); | ||
| 9468 | return; | ||
| 9469 | |||
| 9470 | case ZigTypeIdVector: | ||
| 9471 | case ZigTypeIdArray: | ||
| 9472 | case ZigTypeIdNull: | ||
| 9473 | case ZigTypeIdErrorSet: | ||
| 9474 | case ZigTypeIdEnum: | ||
| 9475 | case ZigTypeIdUnion: | ||
| 9476 | case ZigTypeIdFn: | ||
| 9477 | case ZigTypeIdBoundFn: | ||
| 9478 | case ZigTypeIdOpaque: | ||
| 9479 | case ZigTypeIdFnFrame: | ||
| 9480 | case ZigTypeIdAnyFrame: | ||
| 9481 | case ZigTypeIdEnumLiteral: | ||
| 9482 | fprintf(stderr, "<TODO dump value>\n"); | ||
| 9483 | return; | ||
| 9484 | } | ||
| 9485 | zig_unreachable(); | ||
| 9486 | } | ||
| 9487 | |||
| 9488 | void ZigValue::dump() { | ||
| 9489 | dump_value_indent(this, 0); | ||
| 9490 | } |
src/ir.cpp+8-16| ... | @@ -4190,12 +4190,6 @@ static ScopeDeferExpr *get_scope_defer_expr(Scope *scope) { | ... | @@ -4190,12 +4190,6 @@ static ScopeDeferExpr *get_scope_defer_expr(Scope *scope) { |
| 4190 | static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { | 4190 | static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { |
| 4191 | assert(node->type == NodeTypeReturnExpr); | 4191 | assert(node->type == NodeTypeReturnExpr); |
| 4192 | 4192 | ||
| 4193 | ZigFn *fn_entry = exec_fn_entry(irb->exec); | ||
| 4194 | if (!fn_entry) { | ||
| 4195 | add_node_error(irb->codegen, node, buf_sprintf("return expression outside function definition")); | ||
| 4196 | return irb->codegen->invalid_instruction; | ||
| 4197 | } | ||
| 4198 | |||
| 4199 | ScopeDeferExpr *scope_defer_expr = get_scope_defer_expr(scope); | 4193 | ScopeDeferExpr *scope_defer_expr = get_scope_defer_expr(scope); |
| 4200 | if (scope_defer_expr) { | 4194 | if (scope_defer_expr) { |
| 4201 | if (!scope_defer_expr->reported_err) { | 4195 | if (!scope_defer_expr->reported_err) { |
| ... | @@ -17079,9 +17073,11 @@ static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_in | ... | @@ -17079,9 +17073,11 @@ static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_in |
| 17079 | result->base.value->type = get_pointer_to_type_extra(ira->codegen, var_type, false, false, | 17073 | result->base.value->type = get_pointer_to_type_extra(ira->codegen, var_type, false, false, |
| 17080 | PtrLenSingle, align, 0, 0, false); | 17074 | PtrLenSingle, align, 0, 0, false); |
| 17081 | 17075 | ||
| 17082 | ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); | 17076 | if (!force_comptime) { |
| 17083 | if (fn_entry != nullptr) { | 17077 | ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 17084 | fn_entry->alloca_gen_list.append(result); | 17078 | if (fn_entry != nullptr) { |
| 17079 | fn_entry->alloca_gen_list.append(result); | ||
| 17080 | } | ||
| 17085 | } | 17081 | } |
| 17086 | result->base.is_gen = true; | 17082 | result->base.is_gen = true; |
| 17087 | return &result->base; | 17083 | return &result->base; |
| ... | @@ -17619,7 +17615,8 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s | ... | @@ -17619,7 +17615,8 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s |
| 17619 | result_loc, false, true); | 17615 | result_loc, false, true); |
| 17620 | ZigType *actual_payload_type = actual_elem_type->data.error_union.payload_type; | 17616 | ZigType *actual_payload_type = actual_elem_type->data.error_union.payload_type; |
| 17621 | if (actual_payload_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional && | 17617 | if (actual_payload_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional && |
| 17622 | value_type->id != ZigTypeIdNull) { | 17618 | value_type->id != ZigTypeIdNull) |
| 17619 | { | ||
| 17623 | return ir_analyze_unwrap_optional_payload(ira, suspend_source_instr, unwrapped_err_ptr, false, true); | 17620 | return ir_analyze_unwrap_optional_payload(ira, suspend_source_instr, unwrapped_err_ptr, false, true); |
| 17624 | } else { | 17621 | } else { |
| 17625 | return unwrapped_err_ptr; | 17622 | return unwrapped_err_ptr; |
| ... | @@ -21176,7 +21173,7 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr | ... | @@ -21176,7 +21173,7 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr |
| 21176 | 21173 | ||
| 21177 | if (instr_is_comptime(base_ptr)) { | 21174 | if (instr_is_comptime(base_ptr)) { |
| 21178 | ZigValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad); | 21175 | ZigValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad); |
| 21179 | if (!ptr_val) | 21176 | if (ptr_val == nullptr) |
| 21180 | return ira->codegen->invalid_instruction; | 21177 | return ira->codegen->invalid_instruction; |
| 21181 | if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) { | 21178 | if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 21182 | ZigValue *optional_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node); | 21179 | ZigValue *optional_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node); |
| ... | @@ -28366,11 +28363,6 @@ static IrInstruction *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrIns | ... | @@ -28366,11 +28363,6 @@ static IrInstruction *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrIns |
| 28366 | if (type_is_invalid(operand->value->type)) | 28363 | if (type_is_invalid(operand->value->type)) |
| 28367 | return operand; | 28364 | return operand; |
| 28368 | 28365 | ||
| 28369 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, | ||
| 28370 | &instruction->result_loc_cast->base, operand->value->type, operand, false, true); | ||
| 28371 | if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc))) | ||
| 28372 | return result_loc; | ||
| 28373 | |||
| 28374 | ZigType *dest_type = ir_resolve_type(ira, instruction->result_loc_cast->base.source_instruction->child); | 28366 | ZigType *dest_type = ir_resolve_type(ira, instruction->result_loc_cast->base.source_instruction->child); |
| 28375 | if (type_is_invalid(dest_type)) | 28367 | if (type_is_invalid(dest_type)) |
| 28376 | return ira->codegen->invalid_instruction; | 28368 | return ira->codegen->invalid_instruction; |
test/stage1/behavior.zig+3-3| ... | @@ -54,7 +54,7 @@ comptime { | ... | @@ -54,7 +54,7 @@ comptime { |
| 54 | _ = @import("behavior/byteswap.zig"); | 54 | _ = @import("behavior/byteswap.zig"); |
| 55 | _ = @import("behavior/byval_arg_var.zig"); | 55 | _ = @import("behavior/byval_arg_var.zig"); |
| 56 | _ = @import("behavior/call.zig"); | 56 | _ = @import("behavior/call.zig"); |
| 57 | //_ = @import("behavior/cast.zig"); | 57 | _ = @import("behavior/cast.zig"); |
| 58 | _ = @import("behavior/const_slice_child.zig"); | 58 | _ = @import("behavior/const_slice_child.zig"); |
| 59 | _ = @import("behavior/defer.zig"); | 59 | _ = @import("behavior/defer.zig"); |
| 60 | _ = @import("behavior/enum.zig"); | 60 | _ = @import("behavior/enum.zig"); |
| ... | @@ -81,9 +81,9 @@ comptime { | ... | @@ -81,9 +81,9 @@ comptime { |
| 81 | _ = @import("behavior/muladd.zig"); | 81 | _ = @import("behavior/muladd.zig"); |
| 82 | _ = @import("behavior/namespace_depends_on_compile_var.zig"); | 82 | _ = @import("behavior/namespace_depends_on_compile_var.zig"); |
| 83 | _ = @import("behavior/new_stack_call.zig"); | 83 | _ = @import("behavior/new_stack_call.zig"); |
| 84 | //_ = @import("behavior/null.zig"); | 84 | _ = @import("behavior/null.zig"); |
| 85 | //_ = @import("behavior/optional.zig"); | 85 | //_ = @import("behavior/optional.zig"); |
| 86 | //_ = @import("behavior/pointers.zig"); | 86 | _ = @import("behavior/pointers.zig"); |
| 87 | _ = @import("behavior/popcount.zig"); | 87 | _ = @import("behavior/popcount.zig"); |
| 88 | _ = @import("behavior/ptrcast.zig"); | 88 | _ = @import("behavior/ptrcast.zig"); |
| 89 | _ = @import("behavior/pub_enum.zig"); | 89 | _ = @import("behavior/pub_enum.zig"); |