authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-15 12:28:21-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-15 12:28:21-04:00
log6bf193af192ffaf3465958a243ec8fc8941cfe4d
tree7271c30c7c6657765535002421c65a2377171477
parent60025a37045835c8bbf914eccdbeba6d6e2c275f
signaturelock-open Commit is signed but in an unrecognized format.

better result location semantics with optionals and return locations

somewhere along this branch, #1901 has been fixed.

14 files changed, 281 insertions(+), 169 deletions(-)

BRANCH_TODO+1-4
...@@ -4,10 +4,7 @@ Scratch pad for stuff to do before merging master...@@ -4,10 +4,7 @@ Scratch pad for stuff to do before merging master
4uncomment all the behavior tests4uncomment all the behavior tests
5diff master branch to make sure5diff master branch to make sure
66
7restore test_runner.zig to master branch7restore bootstrap.zig to master
8 - also the default panic function and unexpected_error_tracing. see the commit
9 that adds this text to BRANCH_TODO file.
10 - and std/specia/bootstrap.zig
118
12get an empty file compiling successfully (with no panic fn override)9get an empty file compiling successfully (with no panic fn override)
1310
src/all_types.hpp+21-3
...@@ -2257,7 +2257,8 @@ enum IrInstructionId {...@@ -2257,7 +2257,8 @@ enum IrInstructionId {
2257 IrInstructionIdHandle,2257 IrInstructionIdHandle,
2258 IrInstructionIdAlignOf,2258 IrInstructionIdAlignOf,
2259 IrInstructionIdOverflowOp,2259 IrInstructionIdOverflowOp,
2260 IrInstructionIdTestErr,2260 IrInstructionIdTestErrSrc,
2261 IrInstructionIdTestErrGen,
2261 IrInstructionIdUnwrapErrCode,2262 IrInstructionIdUnwrapErrCode,
2262 IrInstructionIdUnwrapErrPayload,2263 IrInstructionIdUnwrapErrPayload,
2263 IrInstructionIdErrWrapCode,2264 IrInstructionIdErrWrapCode,
...@@ -2292,6 +2293,7 @@ enum IrInstructionId {...@@ -2292,6 +2293,7 @@ enum IrInstructionId {
2292 IrInstructionIdAlignCast,2293 IrInstructionIdAlignCast,
2293 IrInstructionIdImplicitCast,2294 IrInstructionIdImplicitCast,
2294 IrInstructionIdResolveResult,2295 IrInstructionIdResolveResult,
2296 IrInstructionIdResultPtr,
2295 IrInstructionIdOpaqueType,2297 IrInstructionIdOpaqueType,
2296 IrInstructionIdSetAlignStack,2298 IrInstructionIdSetAlignStack,
2297 IrInstructionIdArgType,2299 IrInstructionIdArgType,
...@@ -3082,10 +3084,16 @@ struct IrInstructionAlignOf {...@@ -3082,10 +3084,16 @@ struct IrInstructionAlignOf {
3082};3084};
30833085
3084// returns true if error, returns false if not error3086// returns true if error, returns false if not error
3085struct IrInstructionTestErr {3087struct IrInstructionTestErrSrc {
3086 IrInstruction base;3088 IrInstruction base;
30873089
3088 IrInstruction *value;3090 IrInstruction *base_ptr;
3091};
3092
3093struct IrInstructionTestErrGen {
3094 IrInstruction base;
3095
3096 IrInstruction *err_union;
3089};3097};
30903098
3091// Takes an error union pointer, returns a pointer to the error code.3099// Takes an error union pointer, returns a pointer to the error code.
...@@ -3596,6 +3604,7 @@ struct IrInstructionImplicitCast {...@@ -3596,6 +3604,7 @@ struct IrInstructionImplicitCast {
3596 ResultLoc *result_loc;3604 ResultLoc *result_loc;
3597};3605};
35983606
3607// This one is for writing through the result pointer.
3599struct IrInstructionResolveResult {3608struct IrInstructionResolveResult {
3600 IrInstruction base;3609 IrInstruction base;
36013610
...@@ -3603,6 +3612,15 @@ struct IrInstructionResolveResult {...@@ -3603,6 +3612,15 @@ struct IrInstructionResolveResult {
3603 IrInstruction *ty;3612 IrInstruction *ty;
3604};3613};
36053614
3615// This one is when you want to read the value of the result.
3616// You have to give the value in case it is comptime.
3617struct IrInstructionResultPtr {
3618 IrInstruction base;
3619
3620 ResultLoc *result_loc;
3621 IrInstruction *result;
3622};
3623
3606struct IrInstructionPtrOfArrayToSlice {3624struct IrInstructionPtrOfArrayToSlice {
3607 IrInstruction base;3625 IrInstruction base;
36083626
src/codegen.cpp+25-11
...@@ -1323,7 +1323,9 @@ static LLVMValueRef get_add_error_return_trace_addr_fn(CodeGen *g) {...@@ -1323,7 +1323,9 @@ static LLVMValueRef get_add_error_return_trace_addr_fn(CodeGen *g) {
1323 LLVMBuildRetVoid(g->builder);1323 LLVMBuildRetVoid(g->builder);
13241324
1325 LLVMPositionBuilderAtEnd(g->builder, prev_block);1325 LLVMPositionBuilderAtEnd(g->builder, prev_block);
1326 LLVMSetCurrentDebugLocation(g->builder, prev_debug_location);1326 if (!g->strip_debug_symbols) {
1327 LLVMSetCurrentDebugLocation(g->builder, prev_debug_location);
1328 }
13271329
1328 g->add_error_return_trace_addr_fn_val = fn_val;1330 g->add_error_return_trace_addr_fn_val = fn_val;
1329 return fn_val;1331 return fn_val;
...@@ -1454,7 +1456,9 @@ static LLVMValueRef get_merge_err_ret_traces_fn_val(CodeGen *g) {...@@ -1454,7 +1456,9 @@ static LLVMValueRef get_merge_err_ret_traces_fn_val(CodeGen *g) {
1454 LLVMBuildBr(g->builder, loop_block);1456 LLVMBuildBr(g->builder, loop_block);
14551457
1456 LLVMPositionBuilderAtEnd(g->builder, prev_block);1458 LLVMPositionBuilderAtEnd(g->builder, prev_block);
1457 LLVMSetCurrentDebugLocation(g->builder, prev_debug_location);1459 if (!g->strip_debug_symbols) {
1460 LLVMSetCurrentDebugLocation(g->builder, prev_debug_location);
1461 }
14581462
1459 g->merge_err_ret_traces_fn_val = fn_val;1463 g->merge_err_ret_traces_fn_val = fn_val;
1460 return fn_val;1464 return fn_val;
...@@ -1510,7 +1514,9 @@ static LLVMValueRef get_return_err_fn(CodeGen *g) {...@@ -1510,7 +1514,9 @@ static LLVMValueRef get_return_err_fn(CodeGen *g) {
1510 LLVMBuildRetVoid(g->builder);1514 LLVMBuildRetVoid(g->builder);
15111515
1512 LLVMPositionBuilderAtEnd(g->builder, prev_block);1516 LLVMPositionBuilderAtEnd(g->builder, prev_block);
1513 LLVMSetCurrentDebugLocation(g->builder, prev_debug_location);1517 if (!g->strip_debug_symbols) {
1518 LLVMSetCurrentDebugLocation(g->builder, prev_debug_location);
1519 }
15141520
1515 g->return_err_fn = fn_val;1521 g->return_err_fn = fn_val;
1516 return fn_val;1522 return fn_val;
...@@ -1638,7 +1644,9 @@ static LLVMValueRef get_safety_crash_err_fn(CodeGen *g) {...@@ -1638,7 +1644,9 @@ static LLVMValueRef get_safety_crash_err_fn(CodeGen *g) {
1638 gen_panic(g, msg_slice, err_ret_trace_arg);1644 gen_panic(g, msg_slice, err_ret_trace_arg);
16391645
1640 LLVMPositionBuilderAtEnd(g->builder, prev_block);1646 LLVMPositionBuilderAtEnd(g->builder, prev_block);
1641 LLVMSetCurrentDebugLocation(g->builder, prev_debug_location);1647 if (!g->strip_debug_symbols) {
1648 LLVMSetCurrentDebugLocation(g->builder, prev_debug_location);
1649 }
16421650
1643 g->safety_crash_err_fn = fn_val;1651 g->safety_crash_err_fn = fn_val;
1644 return fn_val;1652 return fn_val;
...@@ -4353,7 +4361,9 @@ static LLVMValueRef get_enum_tag_name_function(CodeGen *g, ZigType *enum_type) {...@@ -4353,7 +4361,9 @@ static LLVMValueRef get_enum_tag_name_function(CodeGen *g, ZigType *enum_type) {
4353 g->cur_fn = prev_cur_fn;4361 g->cur_fn = prev_cur_fn;
4354 g->cur_fn_val = prev_cur_fn_val;4362 g->cur_fn_val = prev_cur_fn_val;
4355 LLVMPositionBuilderAtEnd(g->builder, prev_block);4363 LLVMPositionBuilderAtEnd(g->builder, prev_block);
4356 LLVMSetCurrentDebugLocation(g->builder, prev_debug_location);4364 if (!g->strip_debug_symbols) {
4365 LLVMSetCurrentDebugLocation(g->builder, prev_debug_location);
4366 }
43574367
4358 enum_type->data.enumeration.name_function = fn_val;4368 enum_type->data.enumeration.name_function = fn_val;
4359 return fn_val;4369 return fn_val;
...@@ -4880,10 +4890,10 @@ static LLVMValueRef ir_render_overflow_op(CodeGen *g, IrExecutable *executable,...@@ -4880,10 +4890,10 @@ static LLVMValueRef ir_render_overflow_op(CodeGen *g, IrExecutable *executable,
4880 return overflow_bit;4890 return overflow_bit;
4881}4891}
48824892
4883static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutable *executable, IrInstructionTestErr *instruction) {4893static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutable *executable, IrInstructionTestErrGen *instruction) {
4884 ZigType *err_union_type = instruction->value->value.type;4894 ZigType *err_union_type = instruction->err_union->value.type;
4885 ZigType *payload_type = err_union_type->data.error_union.payload_type;4895 ZigType *payload_type = err_union_type->data.error_union.payload_type;
4886 LLVMValueRef err_union_handle = ir_llvm_value(g, instruction->value);4896 LLVMValueRef err_union_handle = ir_llvm_value(g, instruction->err_union);
48874897
4888 LLVMValueRef err_val;4898 LLVMValueRef err_val;
4889 if (type_has_bits(payload_type)) {4899 if (type_has_bits(payload_type)) {
...@@ -5276,7 +5286,9 @@ static LLVMValueRef get_coro_alloc_helper_fn_val(CodeGen *g, LLVMTypeRef alloc_f...@@ -5276,7 +5286,9 @@ static LLVMValueRef get_coro_alloc_helper_fn_val(CodeGen *g, LLVMTypeRef alloc_f
5276 g->cur_fn = prev_cur_fn;5286 g->cur_fn = prev_cur_fn;
5277 g->cur_fn_val = prev_cur_fn_val;5287 g->cur_fn_val = prev_cur_fn_val;
5278 LLVMPositionBuilderAtEnd(g->builder, prev_block);5288 LLVMPositionBuilderAtEnd(g->builder, prev_block);
5279 LLVMSetCurrentDebugLocation(g->builder, prev_debug_location);5289 if (!g->strip_debug_symbols) {
5290 LLVMSetCurrentDebugLocation(g->builder, prev_debug_location);
5291 }
52805292
5281 g->coro_alloc_helper_fn_val = fn_val;5293 g->coro_alloc_helper_fn_val = fn_val;
5282 return fn_val;5294 return fn_val;
...@@ -5549,10 +5561,12 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,...@@ -5549,10 +5561,12 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
5549 case IrInstructionIdAllocaGen:5561 case IrInstructionIdAllocaGen:
5550 case IrInstructionIdImplicitCast:5562 case IrInstructionIdImplicitCast:
5551 case IrInstructionIdResolveResult:5563 case IrInstructionIdResolveResult:
5564 case IrInstructionIdResultPtr:
5552 case IrInstructionIdContainerInitList:5565 case IrInstructionIdContainerInitList:
5553 case IrInstructionIdSliceSrc:5566 case IrInstructionIdSliceSrc:
5554 case IrInstructionIdRef:5567 case IrInstructionIdRef:
5555 case IrInstructionIdBitCastSrc:5568 case IrInstructionIdBitCastSrc:
5569 case IrInstructionIdTestErrSrc:
5556 zig_unreachable();5570 zig_unreachable();
55575571
5558 case IrInstructionIdDeclVarGen:5572 case IrInstructionIdDeclVarGen:
...@@ -5635,8 +5649,8 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,...@@ -5635,8 +5649,8 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
5635 return ir_render_handle(g, executable, (IrInstructionHandle *)instruction);5649 return ir_render_handle(g, executable, (IrInstructionHandle *)instruction);
5636 case IrInstructionIdOverflowOp:5650 case IrInstructionIdOverflowOp:
5637 return ir_render_overflow_op(g, executable, (IrInstructionOverflowOp *)instruction);5651 return ir_render_overflow_op(g, executable, (IrInstructionOverflowOp *)instruction);
5638 case IrInstructionIdTestErr:5652 case IrInstructionIdTestErrGen:
5639 return ir_render_test_err(g, executable, (IrInstructionTestErr *)instruction);5653 return ir_render_test_err(g, executable, (IrInstructionTestErrGen *)instruction);
5640 case IrInstructionIdUnwrapErrCode:5654 case IrInstructionIdUnwrapErrCode:
5641 return ir_render_unwrap_err_code(g, executable, (IrInstructionUnwrapErrCode *)instruction);5655 return ir_render_unwrap_err_code(g, executable, (IrInstructionUnwrapErrCode *)instruction);
5642 case IrInstructionIdUnwrapErrPayload:5656 case IrInstructionIdUnwrapErrPayload:
src/ir.cpp+86-28
...@@ -756,8 +756,12 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionOverflowOp *) {...@@ -756,8 +756,12 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionOverflowOp *) {
756 return IrInstructionIdOverflowOp;756 return IrInstructionIdOverflowOp;
757}757}
758758
759static constexpr IrInstructionId ir_instruction_id(IrInstructionTestErr *) {759static constexpr IrInstructionId ir_instruction_id(IrInstructionTestErrSrc *) {
760 return IrInstructionIdTestErr;760 return IrInstructionIdTestErrSrc;
761}
762
763static constexpr IrInstructionId ir_instruction_id(IrInstructionTestErrGen *) {
764 return IrInstructionIdTestErrGen;
761}765}
762766
763static constexpr IrInstructionId ir_instruction_id(IrInstructionUnwrapErrCode *) {767static constexpr IrInstructionId ir_instruction_id(IrInstructionUnwrapErrCode *) {
...@@ -900,6 +904,10 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionResolveResult *)...@@ -900,6 +904,10 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionResolveResult *)
900 return IrInstructionIdResolveResult;904 return IrInstructionIdResolveResult;
901}905}
902906
907static constexpr IrInstructionId ir_instruction_id(IrInstructionResultPtr *) {
908 return IrInstructionIdResultPtr;
909}
910
903static constexpr IrInstructionId ir_instruction_id(IrInstructionPtrOfArrayToSlice *) {911static constexpr IrInstructionId ir_instruction_id(IrInstructionPtrOfArrayToSlice *) {
904 return IrInstructionIdPtrOfArrayToSlice;912 return IrInstructionIdPtrOfArrayToSlice;
905}913}
...@@ -2418,13 +2426,26 @@ static IrInstruction *ir_build_align_of(IrBuilder *irb, Scope *scope, AstNode *s...@@ -2418,13 +2426,26 @@ static IrInstruction *ir_build_align_of(IrBuilder *irb, Scope *scope, AstNode *s
2418 return &instruction->base;2426 return &instruction->base;
2419}2427}
24202428
2421static IrInstruction *ir_build_test_err(IrBuilder *irb, Scope *scope, AstNode *source_node,2429static IrInstruction *ir_build_test_err_src(IrBuilder *irb, Scope *scope, AstNode *source_node,
2422 IrInstruction *value)2430 IrInstruction *base_ptr)
2423{2431{
2424 IrInstructionTestErr *instruction = ir_build_instruction<IrInstructionTestErr>(irb, scope, source_node);2432 IrInstructionTestErrSrc *instruction = ir_build_instruction<IrInstructionTestErrSrc>(irb, scope, source_node);
2425 instruction->value = value;2433 instruction->base_ptr = base_ptr;
24262434
2427 ir_ref_instruction(value, irb->current_basic_block);2435 ir_ref_instruction(base_ptr, irb->current_basic_block);
2436
2437 return &instruction->base;
2438}
2439
2440static IrInstruction *ir_build_test_err_gen(IrAnalyze *ira, IrInstruction *source_instruction,
2441 IrInstruction *err_union)
2442{
2443 IrInstructionTestErrGen *instruction = ir_build_instruction<IrInstructionTestErrGen>(
2444 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
2445 instruction->base.value.type = ira->codegen->builtin_types.entry_bool;
2446 instruction->err_union = err_union;
2447
2448 ir_ref_instruction(err_union, ira->new_irb.current_basic_block);
24282449
2429 return &instruction->base;2450 return &instruction->base;
2430}2451}
...@@ -2844,6 +2865,18 @@ static IrInstruction *ir_build_resolve_result(IrBuilder *irb, Scope *scope, AstN...@@ -2844,6 +2865,18 @@ static IrInstruction *ir_build_resolve_result(IrBuilder *irb, Scope *scope, AstN
2844 return &instruction->base;2865 return &instruction->base;
2845}2866}
28462867
2868static IrInstruction *ir_build_result_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node,
2869 ResultLoc *result_loc, IrInstruction *result)
2870{
2871 IrInstructionResultPtr *instruction = ir_build_instruction<IrInstructionResultPtr>(irb, scope, source_node);
2872 instruction->result_loc = result_loc;
2873 instruction->result = result;
2874
2875 ir_ref_instruction(result, irb->current_basic_block);
2876
2877 return &instruction->base;
2878}
2879
2847static IrInstruction *ir_build_opaque_type(IrBuilder *irb, Scope *scope, AstNode *source_node) {2880static IrInstruction *ir_build_opaque_type(IrBuilder *irb, Scope *scope, AstNode *source_node) {
2848 IrInstructionOpaqueType *instruction = ir_build_instruction<IrInstructionOpaqueType>(irb, scope, source_node);2881 IrInstructionOpaqueType *instruction = ir_build_instruction<IrInstructionOpaqueType>(irb, scope, source_node);
28492882
...@@ -3531,7 +3564,9 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -3531,7 +3564,9 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
3531 ir_gen_defers_for_block(irb, scope, outer_scope, false);3564 ir_gen_defers_for_block(irb, scope, outer_scope, false);
3532 }3565 }
35333566
3534 IrInstruction *is_err = ir_build_test_err(irb, scope, node, return_value);3567 IrInstruction *ret_ptr = ir_build_result_ptr(irb, scope, node, &result_loc_ret->base,
3568 return_value);
3569 IrInstruction *is_err = ir_build_test_err_src(irb, scope, node, ret_ptr);
35353570
3536 bool should_inline = ir_should_inline(irb->exec, scope);3571 bool should_inline = ir_should_inline(irb->exec, scope);
3537 IrInstruction *is_comptime;3572 IrInstruction *is_comptime;
...@@ -3577,8 +3612,7 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -3577,8 +3612,7 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
3577 IrInstruction *err_union_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);3612 IrInstruction *err_union_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);
3578 if (err_union_ptr == irb->codegen->invalid_instruction)3613 if (err_union_ptr == irb->codegen->invalid_instruction)
3579 return irb->codegen->invalid_instruction;3614 return irb->codegen->invalid_instruction;
3580 IrInstruction *err_union_val = ir_build_load_ptr(irb, scope, node, err_union_ptr);3615 IrInstruction *is_err_val = ir_build_test_err_src(irb, scope, node, err_union_ptr);
3581 IrInstruction *is_err_val = ir_build_test_err(irb, scope, node, err_union_val);
35823616
3583 IrBasicBlock *return_block = ir_create_basic_block(irb, scope, "ErrRetReturn");3617 IrBasicBlock *return_block = ir_create_basic_block(irb, scope, "ErrRetReturn");
3584 IrBasicBlock *continue_block = ir_create_basic_block(irb, scope, "ErrRetContinue");3618 IrBasicBlock *continue_block = ir_create_basic_block(irb, scope, "ErrRetContinue");
...@@ -5940,8 +5974,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -5940,8 +5974,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
5940 LValPtr, nullptr);5974 LValPtr, nullptr);
5941 if (err_val_ptr == irb->codegen->invalid_instruction)5975 if (err_val_ptr == irb->codegen->invalid_instruction)
5942 return err_val_ptr;5976 return err_val_ptr;
5943 IrInstruction *err_val = ir_build_load_ptr(irb, scope, node->data.while_expr.condition, err_val_ptr);5977 IrInstruction *is_err = ir_build_test_err_src(irb, scope, node->data.while_expr.condition, err_val_ptr);
5944 IrInstruction *is_err = ir_build_test_err(irb, scope, node->data.while_expr.condition, err_val);
5945 IrBasicBlock *after_cond_block = irb->current_basic_block;5978 IrBasicBlock *after_cond_block = irb->current_basic_block;
5946 IrInstruction *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, scope, node));5979 IrInstruction *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, scope, node));
5947 IrInstruction *cond_br_inst;5980 IrInstruction *cond_br_inst;
...@@ -6722,7 +6755,7 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -6722,7 +6755,7 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *
6722 return err_val_ptr;6755 return err_val_ptr;
67236756
6724 IrInstruction *err_val = ir_build_load_ptr(irb, scope, node, err_val_ptr);6757 IrInstruction *err_val = ir_build_load_ptr(irb, scope, node, err_val_ptr);
6725 IrInstruction *is_err = ir_build_test_err(irb, scope, node, err_val);6758 IrInstruction *is_err = ir_build_test_err_src(irb, scope, node, err_val_ptr);
67266759
6727 IrBasicBlock *ok_block = ir_create_basic_block(irb, scope, "TryOk");6760 IrBasicBlock *ok_block = ir_create_basic_block(irb, scope, "TryOk");
6728 IrBasicBlock *else_block = ir_create_basic_block(irb, scope, "TryElse");6761 IrBasicBlock *else_block = ir_create_basic_block(irb, scope, "TryElse");
...@@ -7330,8 +7363,7 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode...@@ -7330,8 +7363,7 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode
7330 if (err_union_ptr == irb->codegen->invalid_instruction)7363 if (err_union_ptr == irb->codegen->invalid_instruction)
7331 return irb->codegen->invalid_instruction;7364 return irb->codegen->invalid_instruction;
73327365
7333 IrInstruction *err_union_val = ir_build_load_ptr(irb, parent_scope, node, err_union_ptr);7366 IrInstruction *is_err = ir_build_test_err_src(irb, parent_scope, node, err_union_ptr);
7334 IrInstruction *is_err = ir_build_test_err(irb, parent_scope, node, err_union_val);
73357367
7336 IrInstruction *is_comptime;7368 IrInstruction *is_comptime;
7337 if (ir_should_inline(irb->exec, parent_scope)) {7369 if (ir_should_inline(irb->exec, parent_scope)) {
...@@ -15010,7 +15042,9 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s...@@ -15010,7 +15042,9 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
15010 return result_loc;15042 return result_loc;
15011 ir_assert(result_loc->value.type->id == ZigTypeIdPointer, suspend_source_instr);15043 ir_assert(result_loc->value.type->id == ZigTypeIdPointer, suspend_source_instr);
15012 ZigType *actual_elem_type = result_loc->value.type->data.pointer.child_type;15044 ZigType *actual_elem_type = result_loc->value.type->data.pointer.child_type;
15013 if (actual_elem_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional) {15045 if (actual_elem_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional &&
15046 value_type->id != ZigTypeIdNull)
15047 {
15014 return ir_analyze_unwrap_optional_payload(ira, suspend_source_instr, result_loc, false, true);15048 return ir_analyze_unwrap_optional_payload(ira, suspend_source_instr, result_loc, false, true);
15015 } else if (actual_elem_type->id == ZigTypeIdErrorUnion && value_type->id != ZigTypeIdErrorUnion) {15049 } else if (actual_elem_type->id == ZigTypeIdErrorUnion && value_type->id != ZigTypeIdErrorUnion) {
15016 if (value_type->id == ZigTypeIdErrorSet) {15050 if (value_type->id == ZigTypeIdErrorSet) {
...@@ -22190,15 +22224,34 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr...@@ -22190,15 +22224,34 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr
22190 return result;22224 return result;
22191}22225}
2219222226
22193static IrInstruction *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstructionTestErr *instruction) {22227static IrInstruction *ir_analyze_instruction_result_ptr(IrAnalyze *ira, IrInstructionResultPtr *instruction) {
22194 IrInstruction *value = instruction->value->child;22228 IrInstruction *result = instruction->result->child;
22195 if (type_is_invalid(value->value.type))22229 if (type_is_invalid(result->value.type))
22230 return result;
22231
22232 if (instruction->result_loc->written && instruction->result_loc->resolved_loc != nullptr &&
22233 !instr_is_comptime(result))
22234 {
22235 IrInstruction *result_ptr = instruction->result_loc->resolved_loc;
22236 // Convert the pointer to the result type. They should be the same, except this will resolve
22237 // inferred error sets.
22238 ZigType *new_ptr_type = get_pointer_to_type(ira->codegen, result->value.type, true);
22239 return ir_analyze_ptr_cast(ira, &instruction->base, result_ptr, new_ptr_type, &instruction->base, false);
22240 }
22241 return ir_get_ref(ira, &instruction->base, result, true, false);
22242}
22243
22244static IrInstruction *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstructionTestErrSrc *instruction) {
22245 IrInstruction *base_ptr = instruction->base_ptr->child;
22246 if (type_is_invalid(base_ptr->value.type))
22196 return ira->codegen->invalid_instruction;22247 return ira->codegen->invalid_instruction;
2219722248
22249 IrInstruction *value = ir_get_deref(ira, &instruction->base, base_ptr, nullptr);
22198 ZigType *type_entry = value->value.type;22250 ZigType *type_entry = value->value.type;
22199 if (type_is_invalid(type_entry)) {22251 if (type_is_invalid(type_entry))
22200 return ira->codegen->invalid_instruction;22252 return ira->codegen->invalid_instruction;
22201 } else if (type_entry->id == ZigTypeIdErrorUnion) {22253
22254 if (type_entry->id == ZigTypeIdErrorUnion) {
22202 if (instr_is_comptime(value)) {22255 if (instr_is_comptime(value)) {
22203 ConstExprValue *err_union_val = ir_resolve_const(ira, value, UndefBad);22256 ConstExprValue *err_union_val = ir_resolve_const(ira, value, UndefBad);
22204 if (!err_union_val)22257 if (!err_union_val)
...@@ -22221,10 +22274,7 @@ static IrInstruction *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruct...@@ -22221,10 +22274,7 @@ static IrInstruction *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruct
22221 return ir_const_bool(ira, &instruction->base, false);22274 return ir_const_bool(ira, &instruction->base, false);
22222 }22275 }
2222322276
22224 IrInstruction *result = ir_build_test_err(&ira->new_irb,22277 return ir_build_test_err_gen(ira, &instruction->base, value);
22225 instruction->base.scope, instruction->base.source_node, value);
22226 result->value.type = ira->codegen->builtin_types.entry_bool;
22227 return result;
22228 } else if (type_entry->id == ZigTypeIdErrorSet) {22278 } else if (type_entry->id == ZigTypeIdErrorSet) {
22229 return ir_const_bool(ira, &instruction->base, true);22279 return ir_const_bool(ira, &instruction->base, true);
22230 } else {22280 } else {
...@@ -24343,6 +24393,7 @@ static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction...@@ -24343,6 +24393,7 @@ static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction
24343 case IrInstructionIdAllocaGen:24393 case IrInstructionIdAllocaGen:
24344 case IrInstructionIdSliceGen:24394 case IrInstructionIdSliceGen:
24345 case IrInstructionIdRefGen:24395 case IrInstructionIdRefGen:
24396 case IrInstructionIdTestErrGen:
24346 zig_unreachable();24397 zig_unreachable();
2434724398
24348 case IrInstructionIdReturn:24399 case IrInstructionIdReturn:
...@@ -24497,8 +24548,8 @@ static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction...@@ -24497,8 +24548,8 @@ static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction
24497 return ir_analyze_instruction_align_of(ira, (IrInstructionAlignOf *)instruction);24548 return ir_analyze_instruction_align_of(ira, (IrInstructionAlignOf *)instruction);
24498 case IrInstructionIdOverflowOp:24549 case IrInstructionIdOverflowOp:
24499 return ir_analyze_instruction_overflow_op(ira, (IrInstructionOverflowOp *)instruction);24550 return ir_analyze_instruction_overflow_op(ira, (IrInstructionOverflowOp *)instruction);
24500 case IrInstructionIdTestErr:24551 case IrInstructionIdTestErrSrc:
24501 return ir_analyze_instruction_test_err(ira, (IrInstructionTestErr *)instruction);24552 return ir_analyze_instruction_test_err(ira, (IrInstructionTestErrSrc *)instruction);
24502 case IrInstructionIdUnwrapErrCode:24553 case IrInstructionIdUnwrapErrCode:
24503 return ir_analyze_instruction_unwrap_err_code(ira, (IrInstructionUnwrapErrCode *)instruction);24554 return ir_analyze_instruction_unwrap_err_code(ira, (IrInstructionUnwrapErrCode *)instruction);
24504 case IrInstructionIdUnwrapErrPayload:24555 case IrInstructionIdUnwrapErrPayload:
...@@ -24543,6 +24594,8 @@ static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction...@@ -24543,6 +24594,8 @@ static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction
24543 return ir_analyze_instruction_implicit_cast(ira, (IrInstructionImplicitCast *)instruction);24594 return ir_analyze_instruction_implicit_cast(ira, (IrInstructionImplicitCast *)instruction);
24544 case IrInstructionIdResolveResult:24595 case IrInstructionIdResolveResult:
24545 return ir_analyze_instruction_resolve_result(ira, (IrInstructionResolveResult *)instruction);24596 return ir_analyze_instruction_resolve_result(ira, (IrInstructionResolveResult *)instruction);
24597 case IrInstructionIdResultPtr:
24598 return ir_analyze_instruction_result_ptr(ira, (IrInstructionResultPtr *)instruction);
24546 case IrInstructionIdOpaqueType:24599 case IrInstructionIdOpaqueType:
24547 return ir_analyze_instruction_opaque_type(ira, (IrInstructionOpaqueType *)instruction);24600 return ir_analyze_instruction_opaque_type(ira, (IrInstructionOpaqueType *)instruction);
24548 case IrInstructionIdSetAlignStack:24601 case IrInstructionIdSetAlignStack:
...@@ -24672,6 +24725,9 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_...@@ -24672,6 +24725,9 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
24672 continue;24725 continue;
24673 }24726 }
2467424727
24728 if (ira->codegen->verbose_ir) {
24729 fprintf(stderr, "analyze #%zu\n", old_instruction->debug_id);
24730 }
24675 IrInstruction *new_instruction = ir_analyze_instruction_base(ira, old_instruction);24731 IrInstruction *new_instruction = ir_analyze_instruction_base(ira, old_instruction);
24676 if (new_instruction != nullptr) {24732 if (new_instruction != nullptr) {
24677 ir_assert(new_instruction->value.type != nullptr || new_instruction->value.type != nullptr, old_instruction);24733 ir_assert(new_instruction->value.type != nullptr || new_instruction->value.type != nullptr, old_instruction);
...@@ -24808,7 +24864,8 @@ bool ir_has_side_effects(IrInstruction *instruction) {...@@ -24808,7 +24864,8 @@ bool ir_has_side_effects(IrInstruction *instruction) {
24808 case IrInstructionIdReturnAddress:24864 case IrInstructionIdReturnAddress:
24809 case IrInstructionIdFrameAddress:24865 case IrInstructionIdFrameAddress:
24810 case IrInstructionIdHandle:24866 case IrInstructionIdHandle:
24811 case IrInstructionIdTestErr:24867 case IrInstructionIdTestErrSrc:
24868 case IrInstructionIdTestErrGen:
24812 case IrInstructionIdFnProto:24869 case IrInstructionIdFnProto:
24813 case IrInstructionIdTestComptime:24870 case IrInstructionIdTestComptime:
24814 case IrInstructionIdPtrCastSrc:24871 case IrInstructionIdPtrCastSrc:
...@@ -24860,6 +24917,7 @@ bool ir_has_side_effects(IrInstruction *instruction) {...@@ -24860,6 +24917,7 @@ bool ir_has_side_effects(IrInstruction *instruction) {
24860 case IrInstructionIdHasDecl:24917 case IrInstructionIdHasDecl:
24861 case IrInstructionIdAllocaSrc:24918 case IrInstructionIdAllocaSrc:
24862 case IrInstructionIdAllocaGen:24919 case IrInstructionIdAllocaGen:
24920 case IrInstructionIdResultPtr:
24863 return false;24921 return false;
2486424922
24865 case IrInstructionIdAsm:24923 case IrInstructionIdAsm:
src/ir_print.cpp+25-8
...@@ -961,9 +961,15 @@ static void ir_print_overflow_op(IrPrint *irp, IrInstructionOverflowOp *instruct...@@ -961,9 +961,15 @@ static void ir_print_overflow_op(IrPrint *irp, IrInstructionOverflowOp *instruct
961 fprintf(irp->f, ")");961 fprintf(irp->f, ")");
962}962}
963963
964static void ir_print_test_err(IrPrint *irp, IrInstructionTestErr *instruction) {964static void ir_print_test_err_src(IrPrint *irp, IrInstructionTestErrSrc *instruction) {
965 fprintf(irp->f, "@testError(");965 fprintf(irp->f, "@testError(");
966 ir_print_other_instruction(irp, instruction->value);966 ir_print_other_instruction(irp, instruction->base_ptr);
967 fprintf(irp->f, ")");
968}
969
970static void ir_print_test_err_gen(IrPrint *irp, IrInstructionTestErrGen *instruction) {
971 fprintf(irp->f, "@testError(");
972 ir_print_other_instruction(irp, instruction->err_union);
967 fprintf(irp->f, ")");973 fprintf(irp->f, ")");
968}974}
969975
...@@ -976,10 +982,7 @@ static void ir_print_unwrap_err_code(IrPrint *irp, IrInstructionUnwrapErrCode *i...@@ -976,10 +982,7 @@ static void ir_print_unwrap_err_code(IrPrint *irp, IrInstructionUnwrapErrCode *i
976static void ir_print_unwrap_err_payload(IrPrint *irp, IrInstructionUnwrapErrPayload *instruction) {982static void ir_print_unwrap_err_payload(IrPrint *irp, IrInstructionUnwrapErrPayload *instruction) {
977 fprintf(irp->f, "ErrorUnionFieldPayload(");983 fprintf(irp->f, "ErrorUnionFieldPayload(");
978 ir_print_other_instruction(irp, instruction->value);984 ir_print_other_instruction(irp, instruction->value);
979 fprintf(irp->f, ")");985 fprintf(irp->f, ")safety=%d,init=%d",instruction->safety_check_on, instruction->initializing);
980 if (!instruction->safety_check_on) {
981 fprintf(irp->f, " // no safety");
982 }
983}986}
984987
985static void ir_print_optional_wrap(IrPrint *irp, IrInstructionOptionalWrap *instruction) {988static void ir_print_optional_wrap(IrPrint *irp, IrInstructionOptionalWrap *instruction) {
...@@ -1301,6 +1304,14 @@ static void ir_print_resolve_result(IrPrint *irp, IrInstructionResolveResult *in...@@ -1301,6 +1304,14 @@ static void ir_print_resolve_result(IrPrint *irp, IrInstructionResolveResult *in
1301 fprintf(irp->f, ")");1304 fprintf(irp->f, ")");
1302}1305}
13031306
1307static void ir_print_result_ptr(IrPrint *irp, IrInstructionResultPtr *instruction) {
1308 fprintf(irp->f, "ResultPtr(");
1309 ir_print_result_loc(irp, instruction->result_loc);
1310 fprintf(irp->f, ",");
1311 ir_print_other_instruction(irp, instruction->result);
1312 fprintf(irp->f, ")");
1313}
1314
1304static void ir_print_opaque_type(IrPrint *irp, IrInstructionOpaqueType *instruction) {1315static void ir_print_opaque_type(IrPrint *irp, IrInstructionOpaqueType *instruction) {
1305 fprintf(irp->f, "@OpaqueType()");1316 fprintf(irp->f, "@OpaqueType()");
1306}1317}
...@@ -1837,8 +1848,11 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {...@@ -1837,8 +1848,11 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
1837 case IrInstructionIdOverflowOp:1848 case IrInstructionIdOverflowOp:
1838 ir_print_overflow_op(irp, (IrInstructionOverflowOp *)instruction);1849 ir_print_overflow_op(irp, (IrInstructionOverflowOp *)instruction);
1839 break;1850 break;
1840 case IrInstructionIdTestErr:1851 case IrInstructionIdTestErrSrc:
1841 ir_print_test_err(irp, (IrInstructionTestErr *)instruction);1852 ir_print_test_err_src(irp, (IrInstructionTestErrSrc *)instruction);
1853 break;
1854 case IrInstructionIdTestErrGen:
1855 ir_print_test_err_gen(irp, (IrInstructionTestErrGen *)instruction);
1842 break;1856 break;
1843 case IrInstructionIdUnwrapErrCode:1857 case IrInstructionIdUnwrapErrCode:
1844 ir_print_unwrap_err_code(irp, (IrInstructionUnwrapErrCode *)instruction);1858 ir_print_unwrap_err_code(irp, (IrInstructionUnwrapErrCode *)instruction);
...@@ -1939,6 +1953,9 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {...@@ -1939,6 +1953,9 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
1939 case IrInstructionIdResolveResult:1953 case IrInstructionIdResolveResult:
1940 ir_print_resolve_result(irp, (IrInstructionResolveResult *)instruction);1954 ir_print_resolve_result(irp, (IrInstructionResolveResult *)instruction);
1941 break;1955 break;
1956 case IrInstructionIdResultPtr:
1957 ir_print_result_ptr(irp, (IrInstructionResultPtr *)instruction);
1958 break;
1942 case IrInstructionIdOpaqueType:1959 case IrInstructionIdOpaqueType:
1943 ir_print_opaque_type(irp, (IrInstructionOpaqueType *)instruction);1960 ir_print_opaque_type(irp, (IrInstructionOpaqueType *)instruction);
1944 break;1961 break;
std/os.zig+1-1
...@@ -2487,7 +2487,7 @@ pub fn toPosixPath(file_path: []const u8) ![PATH_MAX]u8 {...@@ -2487,7 +2487,7 @@ pub fn toPosixPath(file_path: []const u8) ![PATH_MAX]u8 {
2487/// if this happens the fix is to add the error code to the corresponding2487/// if this happens the fix is to add the error code to the corresponding
2488/// switch expression, possibly introduce a new error in the error set, and2488/// switch expression, possibly introduce a new error in the error set, and
2489/// send a patch to Zig.2489/// send a patch to Zig.
2490pub const unexpected_error_tracing = false;2490pub const unexpected_error_tracing = builtin.mode == .Debug;
24912491
2492pub const UnexpectedError = error{2492pub const UnexpectedError = error{
2493 /// The Operating System returned an undocumented error code.2493 /// The Operating System returned an undocumented error code.
std/special/panic.zig+19-4
...@@ -7,8 +7,23 @@ const builtin = @import("builtin");...@@ -7,8 +7,23 @@ const builtin = @import("builtin");
7const std = @import("std");7const std = @import("std");
88
9pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn {9pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn {
10 const stderr = std.io.getStdErr() catch std.process.abort();10 @setCold(true);
11 stderr.write("panic: ") catch std.process.abort();11 switch (builtin.os) {
12 stderr.write(msg) catch std.process.abort();12 .freestanding => {
13 std.process.abort();13 while (true) {}
14 },
15 .wasi => {
16 std.debug.warn("{}", msg);
17 _ = std.os.wasi.proc_raise(std.os.wasi.SIGABRT);
18 unreachable;
19 },
20 .uefi => {
21 // TODO look into using the debug info and logging helpful messages
22 std.os.abort();
23 },
24 else => {
25 const first_trace_addr = @returnAddress();
26 std.debug.panicExtra(error_return_trace, first_trace_addr, "{}", msg);
27 },
28 }
14}29}
std/special/test_runner.zig+8-14
...@@ -2,34 +2,28 @@ const std = @import("std");...@@ -2,34 +2,28 @@ const std = @import("std");
2const io = std.io;2const io = std.io;
3const builtin = @import("builtin");3const builtin = @import("builtin");
4const test_fn_list = builtin.test_functions;4const test_fn_list = builtin.test_functions;
5const warn = std.debug.warn;
56
6pub fn main() void {7pub fn main() !void {
7 const stderr = io.getStdErr() catch std.process.abort();
8
9 var ok_count: usize = 0;8 var ok_count: usize = 0;
10 var skip_count: usize = 0;9 var skip_count: usize = 0;
11 for (test_fn_list) |test_fn, i| {10 for (test_fn_list) |test_fn, i| {
12 stderr.write("test ") catch std.process.abort();11 warn("{}/{} {}...", i + 1, test_fn_list.len, test_fn.name);
13 stderr.write(test_fn.name) catch std.process.abort();
1412
15 if (test_fn.func()) |_| {13 if (test_fn.func()) |_| {
16 ok_count += 1;14 ok_count += 1;
17 stderr.write("...OK\n") catch std.process.abort();15 warn("OK\n");
18 } else |err| switch (err) {16 } else |err| switch (err) {
19 error.SkipZigTest => {17 error.SkipZigTest => {
20 skip_count += 1;18 skip_count += 1;
21 stderr.write("...SKIP\n") catch std.process.abort();19 warn("SKIP\n");
22 },
23 else => {
24 stderr.write("error: ") catch std.process.abort();
25 stderr.write(@errorName(err)) catch std.process.abort();
26 std.process.abort();
27 },20 },
21 else => return err,
28 }22 }
29 }23 }
30 if (ok_count == test_fn_list.len) {24 if (ok_count == test_fn_list.len) {
31 stderr.write("All tests passed.\n") catch std.process.abort();25 warn("All tests passed.\n");
32 } else {26 } else {
33 stderr.write("Some tests skipped.\n") catch std.process.abort();27 warn("{} passed; {} skipped.\n", ok_count, skip_count);
34 }28 }
35}29}
test/stage1/behavior.zig+9-9
...@@ -40,46 +40,46 @@ comptime {...@@ -40,46 +40,46 @@ comptime {
40 //_ = @import("behavior/bugs/920.zig");40 //_ = @import("behavior/bugs/920.zig");
41 _ = @import("behavior/byval_arg_var.zig");41 _ = @import("behavior/byval_arg_var.zig");
42 //_ = @import("behavior/cancel.zig");42 //_ = @import("behavior/cancel.zig");
43 _ = @import("behavior/cast.zig"); // TODO43 _ = @import("behavior/cast.zig");
44 _ = @import("behavior/const_slice_child.zig");44 _ = @import("behavior/const_slice_child.zig");
45 //_ = @import("behavior/coroutine_await_struct.zig");45 //_ = @import("behavior/coroutine_await_struct.zig");
46 //_ = @import("behavior/coroutines.zig");46 //_ = @import("behavior/coroutines.zig");
47 _ = @import("behavior/defer.zig");47 _ = @import("behavior/defer.zig");
48 _ = @import("behavior/enum.zig");48 _ = @import("behavior/enum.zig");
49 _ = @import("behavior/enum_with_members.zig");49 _ = @import("behavior/enum_with_members.zig");
50 //_ = @import("behavior/error.zig");50 _ = @import("behavior/error.zig"); // TODO
51 _ = @import("behavior/eval.zig"); // TODO51 _ = @import("behavior/eval.zig"); // TODO
52 _ = @import("behavior/field_parent_ptr.zig");52 _ = @import("behavior/field_parent_ptr.zig");
53 _ = @import("behavior/fn.zig");53 _ = @import("behavior/fn.zig");
54 _ = @import("behavior/fn_in_struct_in_comptime.zig");54 _ = @import("behavior/fn_in_struct_in_comptime.zig");
55 _ = @import("behavior/for.zig");55 _ = @import("behavior/for.zig");
56 _ = @import("behavior/generics.zig"); // TODO56 _ = @import("behavior/generics.zig");
57 _ = @import("behavior/hasdecl.zig");57 _ = @import("behavior/hasdecl.zig");
58 _ = @import("behavior/if.zig");58 _ = @import("behavior/if.zig");
59 //_ = @import("behavior/import.zig");59 _ = @import("behavior/import.zig");
60 _ = @import("behavior/incomplete_struct_param_tld.zig");60 _ = @import("behavior/incomplete_struct_param_tld.zig");
61 _ = @import("behavior/inttoptr.zig");61 _ = @import("behavior/inttoptr.zig");
62 _ = @import("behavior/ir_block_deps.zig");62 _ = @import("behavior/ir_block_deps.zig");
63 //_ = @import("behavior/math.zig");63 _ = @import("behavior/math.zig");
64 _ = @import("behavior/merge_error_sets.zig");64 _ = @import("behavior/merge_error_sets.zig");
65 _ = @import("behavior/misc.zig"); // TODO65 _ = @import("behavior/misc.zig"); // TODO
66 _ = @import("behavior/namespace_depends_on_compile_var.zig");66 _ = @import("behavior/namespace_depends_on_compile_var.zig");
67 _ = @import("behavior/new_stack_call.zig");67 _ = @import("behavior/new_stack_call.zig");
68 _ = @import("behavior/null.zig");68 _ = @import("behavior/null.zig");
69 _ = @import("behavior/optional.zig"); // TODO69 _ = @import("behavior/optional.zig"); // TODO
70 //_ = @import("behavior/pointers.zig");70 _ = @import("behavior/pointers.zig");
71 _ = @import("behavior/popcount.zig");71 _ = @import("behavior/popcount.zig");
72 _ = @import("behavior/ptrcast.zig"); // TODO72 _ = @import("behavior/ptrcast.zig"); // TODO
73 _ = @import("behavior/pub_enum.zig");73 _ = @import("behavior/pub_enum.zig");
74 _ = @import("behavior/ref_var_in_if_after_if_2nd_switch_prong.zig");74 _ = @import("behavior/ref_var_in_if_after_if_2nd_switch_prong.zig");
75 _ = @import("behavior/reflection.zig");75 _ = @import("behavior/reflection.zig");
76 _ = @import("behavior/sizeof_and_typeof.zig");76 _ = @import("behavior/sizeof_and_typeof.zig");
77 //_ = @import("behavior/slice.zig");77 _ = @import("behavior/slice.zig");
78 _ = @import("behavior/slicetobytes.zig");78 _ = @import("behavior/slicetobytes.zig");
79 //_ = @import("behavior/struct.zig");79 //_ = @import("behavior/struct.zig");
80 _ = @import("behavior/struct_contains_null_ptr_itself.zig");80 _ = @import("behavior/struct_contains_null_ptr_itself.zig");
81 _ = @import("behavior/struct_contains_slice_of_itself.zig");81 _ = @import("behavior/struct_contains_slice_of_itself.zig");
82 //_ = @import("behavior/switch.zig");82 _ = @import("behavior/switch.zig");
83 //_ = @import("behavior/switch_prong_err_enum.zig");83 //_ = @import("behavior/switch_prong_err_enum.zig");
84 _ = @import("behavior/switch_prong_implicit_cast.zig");84 _ = @import("behavior/switch_prong_implicit_cast.zig");
85 _ = @import("behavior/syntax.zig");85 _ = @import("behavior/syntax.zig");
...@@ -87,7 +87,7 @@ comptime {...@@ -87,7 +87,7 @@ comptime {
87 _ = @import("behavior/truncate.zig");87 _ = @import("behavior/truncate.zig");
88 _ = @import("behavior/try.zig");88 _ = @import("behavior/try.zig");
89 _ = @import("behavior/type_info.zig");89 _ = @import("behavior/type_info.zig");
90 //_ = @import("behavior/typename.zig");90 _ = @import("behavior/typename.zig");
91 _ = @import("behavior/undefined.zig");91 _ = @import("behavior/undefined.zig");
92 _ = @import("behavior/underscore.zig");92 _ = @import("behavior/underscore.zig");
93 _ = @import("behavior/union.zig");93 _ = @import("behavior/union.zig");
test/stage1/behavior/cast.zig+8-8
...@@ -124,14 +124,14 @@ fn returnNullLitFromOptionalTypeErrorRef() anyerror!?*A {...@@ -124,14 +124,14 @@ fn returnNullLitFromOptionalTypeErrorRef() anyerror!?*A {
124 return null;124 return null;
125}125}
126126
127//test "peer type resolution: ?T and T" {127test "peer type resolution: ?T and T" {
128// expect(peerTypeTAndOptionalT(true, false).? == 0);128 expect(peerTypeTAndOptionalT(true, false).? == 0);
129// expect(peerTypeTAndOptionalT(false, false).? == 3);129 expect(peerTypeTAndOptionalT(false, false).? == 3);
130// comptime {130 comptime {
131// expect(peerTypeTAndOptionalT(true, false).? == 0);131 expect(peerTypeTAndOptionalT(true, false).? == 0);
132// expect(peerTypeTAndOptionalT(false, false).? == 3);132 expect(peerTypeTAndOptionalT(false, false).? == 3);
133// }133 }
134//}134}
135fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize {135fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize {
136 if (c) {136 if (c) {
137 return if (b) null else usize(0);137 return if (b) null else usize(0);
test/stage1/behavior/error.zig+42-42
...@@ -249,48 +249,48 @@ fn intLiteral(str: []const u8) !?i64 {...@@ -249,48 +249,48 @@ fn intLiteral(str: []const u8) !?i64 {
249 return error.T;249 return error.T;
250}250}
251251
252test "nested error union function call in optional unwrap" {252//test "nested error union function call in optional unwrap" {
253 const S = struct {253// const S = struct {
254 const Foo = struct {254// const Foo = struct {
255 a: i32,255// a: i32,
256 };256// };
257257//
258 fn errorable() !i32 {258// fn errorable() !i32 {
259 var x: Foo = (try getFoo()) orelse return error.Other;259// var x: Foo = (try getFoo()) orelse return error.Other;
260 return x.a;260// return x.a;
261 }261// }
262262//
263 fn errorable2() !i32 {263// fn errorable2() !i32 {
264 var x: Foo = (try getFoo2()) orelse return error.Other;264// var x: Foo = (try getFoo2()) orelse return error.Other;
265 return x.a;265// return x.a;
266 }266// }
267267//
268 fn errorable3() !i32 {268// fn errorable3() !i32 {
269 var x: Foo = (try getFoo3()) orelse return error.Other;269// var x: Foo = (try getFoo3()) orelse return error.Other;
270 return x.a;270// return x.a;
271 }271// }
272272//
273 fn getFoo() anyerror!?Foo {273// fn getFoo() anyerror!?Foo {
274 return Foo{ .a = 1234 };274// return Foo{ .a = 1234 };
275 }275// }
276276//
277 fn getFoo2() anyerror!?Foo {277// fn getFoo2() anyerror!?Foo {
278 return error.Failure;278// return error.Failure;
279 }279// }
280280//
281 fn getFoo3() anyerror!?Foo {281// fn getFoo3() anyerror!?Foo {
282 return null;282// return null;
283 }283// }
284 };284// };
285 expect((try S.errorable()) == 1234);285// expect((try S.errorable()) == 1234);
286 expectError(error.Failure, S.errorable2());286// expectError(error.Failure, S.errorable2());
287 expectError(error.Other, S.errorable3());287// expectError(error.Other, S.errorable3());
288 comptime {288// comptime {
289 expect((try S.errorable()) == 1234);289// expect((try S.errorable()) == 1234);
290 expectError(error.Failure, S.errorable2());290// expectError(error.Failure, S.errorable2());
291 expectError(error.Other, S.errorable3());291// expectError(error.Other, S.errorable3());
292 }292// }
293}293//}
294294
295test "widen cast integer payload of error union function call" {295test "widen cast integer payload of error union function call" {
296 const S = struct {296 const S = struct {
test/stage1/behavior/generics.zig+13-13
...@@ -80,19 +80,19 @@ test "function with return type type" {...@@ -80,19 +80,19 @@ test "function with return type type" {
80 expect(list2.prealloc_items.len == 8);80 expect(list2.prealloc_items.len == 8);
81}81}
8282
83//test "generic struct" {83test "generic struct" {
84// var a1 = GenNode(i32){84 var a1 = GenNode(i32){
85// .value = 13,85 .value = 13,
86// .next = null,86 .next = null,
87// };87 };
88// var b1 = GenNode(bool){88 var b1 = GenNode(bool){
89// .value = true,89 .value = true,
90// .next = null,90 .next = null,
91// };91 };
92// expect(a1.value == 13);92 expect(a1.value == 13);
93// expect(a1.value == a1.getVal());93 expect(a1.value == a1.getVal());
94// expect(b1.getVal());94 expect(b1.getVal());
95//}95}
96fn GenNode(comptime T: type) type {96fn GenNode(comptime T: type) type {
97 return struct {97 return struct {
98 value: T,98 value: T,
test/stage1/behavior/optional.zig+1-2
...@@ -76,6 +76,5 @@ test "unwrap function call with optional pointer return value" {...@@ -76,6 +76,5 @@ test "unwrap function call with optional pointer return value" {
76 }76 }
77 };77 };
78 S.entry();78 S.entry();
79 // TODO https://github.com/ziglang/zig/issues/190179 comptime S.entry();
80 //comptime S.entry();
81}80}
test/stage1/behavior/while.zig+22-22
...@@ -82,28 +82,28 @@ test "while with else" {...@@ -82,28 +82,28 @@ test "while with else" {
82 expect(got_else == 1);82 expect(got_else == 1);
83}83}
8484
85//test "while with optional as condition" {85test "while with optional as condition" {
86// numbers_left = 10;86 numbers_left = 10;
87// var sum: i32 = 0;87 var sum: i32 = 0;
88// while (getNumberOrNull()) |value| {88 while (getNumberOrNull()) |value| {
89// sum += value;89 sum += value;
90// }90 }
91// expect(sum == 45);91 expect(sum == 45);
92//}92}
93//93
94//test "while with optional as condition with else" {94test "while with optional as condition with else" {
95// numbers_left = 10;95 numbers_left = 10;
96// var sum: i32 = 0;96 var sum: i32 = 0;
97// var got_else: i32 = 0;97 var got_else: i32 = 0;
98// while (getNumberOrNull()) |value| {98 while (getNumberOrNull()) |value| {
99// sum += value;99 sum += value;
100// expect(got_else == 0);100 expect(got_else == 0);
101// } else {101 } else {
102// got_else += 1;102 got_else += 1;
103// }103 }
104// expect(sum == 45);104 expect(sum == 45);
105// expect(got_else == 1);105 expect(got_else == 1);
106//}106}
107107
108test "while with error union condition" {108test "while with error union condition" {
109 numbers_left = 10;109 numbers_left = 10;