diff --git a/doc/langref.md b/doc/langref.md index 283ca9d91450ab725efba883dd0f04faaf54f8a2..097f1b650c5c3a73ae638241e1efa392a6551d0e 100644 --- a/doc/langref.md +++ b/doc/langref.md @@ -616,3 +616,7 @@ or `switch` with compile time constants, and inline functions. ### @intType(inline is_signed: bool, inline bit_count: u8) -> type This function returns an integer type with the given signness and bit count. + +### @setFnTest(func) + +Makes the target function a test function. diff --git a/src/all_types.hpp b/src/all_types.hpp index 1fd22d650beb951f95fbaa62c401ab593f69ff9e..cfc35dd6dbfd9be1c0e4449d99dba534d14092d9 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -987,7 +987,6 @@ struct FnTableEntry { AstNode *fn_no_inline_set_node; AstNode *fn_export_set_node; - AstNode *fn_test_set_node; AstNode *fn_static_eval_set_node; ZigList alloca_list; @@ -1674,7 +1673,6 @@ struct IrInstructionSetFnTest { IrInstruction base; IrInstruction *fn_value; - IrInstruction *is_test; }; struct IrInstructionSetFnVisible { diff --git a/src/codegen.cpp b/src/codegen.cpp index 8106b9f33aa37204997f1299c0651aff8f22a200..00f81a3bf70000eac8e73c3721e714b5fe700f50 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -3083,7 +3083,7 @@ static void define_builtin_fns(CodeGen *g) { create_builtin_fn_with_arg_count(g, BuiltinFnIdCompileErr, "compileError", 1); create_builtin_fn_with_arg_count(g, BuiltinFnIdIntType, "intType", 2); create_builtin_fn_with_arg_count(g, BuiltinFnIdUnreachable, "unreachable", 0); - create_builtin_fn_with_arg_count(g, BuiltinFnIdSetFnTest, "setFnTest", 2); + create_builtin_fn_with_arg_count(g, BuiltinFnIdSetFnTest, "setFnTest", 1); create_builtin_fn_with_arg_count(g, BuiltinFnIdSetFnVisible, "setFnVisible", 2); create_builtin_fn_with_arg_count(g, BuiltinFnIdSetFnNoInline, "setFnNoInline", 2); create_builtin_fn_with_arg_count(g, BuiltinFnIdSetDebugSafety, "setDebugSafety", 2); diff --git a/src/ir.cpp b/src/ir.cpp index 9bde6c149a9166b21f46c35bbbec91f8cb6b1bdd..5869d2d3e10b08a93e3ca230722b8ea9d21435a9 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -934,15 +934,13 @@ static IrInstruction *ir_build_ptr_type_child(IrBuilder *irb, Scope *scope, AstN return &instruction->base; } -static IrInstruction *ir_build_set_fn_test(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *fn_value, - IrInstruction *is_test) +static IrInstruction *ir_build_set_fn_test(IrBuilder *irb, Scope *scope, AstNode *source_node, + IrInstruction *fn_value) { IrInstructionSetFnTest *instruction = ir_build_instruction(irb, scope, source_node); instruction->fn_value = fn_value; - instruction->is_test = is_test; ir_ref_instruction(fn_value); - ir_ref_instruction(is_test); return &instruction->base; } @@ -1786,12 +1784,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo if (arg0_value == irb->codegen->invalid_instruction) return arg0_value; - AstNode *arg1_node = node->data.fn_call_expr.params.at(1); - IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope); - if (arg1_value == irb->codegen->invalid_instruction) - return arg1_value; - - return ir_build_set_fn_test(irb, scope, node, arg0_value, arg1_value); + return ir_build_set_fn_test(irb, scope, node, arg0_value); } case BuiltinFnIdSetFnVisible: { @@ -5680,26 +5673,15 @@ static TypeTableEntry *ir_analyze_instruction_set_fn_test(IrAnalyze *ira, IrInstructionSetFnTest *set_fn_test_instruction) { IrInstruction *fn_value = set_fn_test_instruction->fn_value->other; - IrInstruction *is_test_value = set_fn_test_instruction->is_test->other; FnTableEntry *fn_entry = ir_resolve_fn(ira, fn_value); if (!fn_entry) return ira->codegen->builtin_types.entry_invalid; - if (!ir_resolve_bool(ira, is_test_value, &fn_entry->is_test)) - return ira->codegen->builtin_types.entry_invalid; - - AstNode *source_node = set_fn_test_instruction->base.source_node; - if (fn_entry->fn_test_set_node) { - ErrorMsg *msg = add_node_error(ira->codegen, source_node, - buf_sprintf("function test attribute set twice")); - add_error_note(ira->codegen, msg, fn_entry->fn_test_set_node, buf_sprintf("first set here")); - return ira->codegen->builtin_types.entry_invalid; - } - fn_entry->fn_test_set_node = source_node; - - if (fn_entry->is_test) + if (!fn_entry->is_test) { + fn_entry->is_test = true; ira->codegen->test_fn_count += 1; + } ir_build_const_from(ira, &set_fn_test_instruction->base, false); return ira->codegen->builtin_types.entry_void; diff --git a/src/ir_print.cpp b/src/ir_print.cpp index 7f27ab104b83e7cc72ecf66dde4b8309ea7cae43..16a0ae3c786e67cea8aecdde059685095ae454cb 100644 --- a/src/ir_print.cpp +++ b/src/ir_print.cpp @@ -491,8 +491,6 @@ static void ir_print_enum_field_ptr(IrPrint *irp, IrInstructionEnumFieldPtr *ins static void ir_print_set_fn_test(IrPrint *irp, IrInstructionSetFnTest *instruction) { fprintf(irp->f, "@setFnTest("); ir_print_other_instruction(irp, instruction->fn_value); - fprintf(irp->f, ", "); - ir_print_other_instruction(irp, instruction->is_test); fprintf(irp->f, ")"); }