authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-01-22 23:20:53-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-01-22 23:21:00-05:00
loge5b17580107ad0783b7f07de100aeb9ccf175603
treec91671f234ac448b22286aeb00946d319c8b5c05
parent201a3c121a5c28273138b1160c5aac4e24d619bd

remove staticEval builtin in favor of comptime expression


11 files changed, 16 insertions(+), 100 deletions(-)

doc/langref.md-7
...@@ -551,13 +551,6 @@ Build scripts can set additional compile variables of any name and type....@@ -551,13 +551,6 @@ Build scripts can set additional compile variables of any name and type.
551The result of this function is a compile time constant that is marked as551The result of this function is a compile time constant that is marked as
552depending on a compile variable.552depending on a compile variable.
553553
554### @staticEval(expression) -> @typeOf(expression)
555
556This function wraps an expression and generates a compile error if the
557expression is not known at compile time.
558
559The result of the function is the result of the expression.
560
561### @generatedCode(expression) -> @typeOf(expression)554### @generatedCode(expression) -> @typeOf(expression)
562555
563This function wraps an expression and returns the result of the expression556This function wraps an expression and returns the result of the expression
src/all_types.hpp+1-9
...@@ -1058,7 +1058,6 @@ enum BuiltinFnId {...@@ -1058,7 +1058,6 @@ enum BuiltinFnId {
1058 BuiltinFnIdCUndef,1058 BuiltinFnIdCUndef,
1059 BuiltinFnIdCompileVar,1059 BuiltinFnIdCompileVar,
1060 BuiltinFnIdCompileErr,1060 BuiltinFnIdCompileErr,
1061 BuiltinFnIdStaticEval,
1062 BuiltinFnIdGeneratedCode,1061 BuiltinFnIdGeneratedCode,
1063 BuiltinFnIdCtz,1062 BuiltinFnIdCtz,
1064 BuiltinFnIdClz,1063 BuiltinFnIdClz,
...@@ -1373,7 +1372,7 @@ struct ScopeLoop {...@@ -1373,7 +1372,7 @@ struct ScopeLoop {
1373};1372};
13741373
1375// This scope is created for a comptime expression.1374// This scope is created for a comptime expression.
1376// NodeTypeCompTime1375// NodeTypeCompTime, NodeTypeSwitchExpr
1377struct ScopeCompTime {1376struct ScopeCompTime {
1378 Scope base;1377 Scope base;
1379};1378};
...@@ -1454,7 +1453,6 @@ enum IrInstructionId {...@@ -1454,7 +1453,6 @@ enum IrInstructionId {
1454 IrInstructionIdEnumTag,1453 IrInstructionIdEnumTag,
1455 IrInstructionIdClz,1454 IrInstructionIdClz,
1456 IrInstructionIdCtz,1455 IrInstructionIdCtz,
1457 IrInstructionIdStaticEval,
1458 IrInstructionIdGeneratedCode,1456 IrInstructionIdGeneratedCode,
1459 IrInstructionIdImport,1457 IrInstructionIdImport,
1460 IrInstructionIdCImport,1458 IrInstructionIdCImport,
...@@ -1867,12 +1865,6 @@ struct IrInstructionEnumTag {...@@ -1867,12 +1865,6 @@ struct IrInstructionEnumTag {
1867 IrInstruction *value;1865 IrInstruction *value;
1868};1866};
18691867
1870struct IrInstructionStaticEval {
1871 IrInstruction base;
1872
1873 IrInstruction *value;
1874};
1875
1876struct IrInstructionGeneratedCode {1868struct IrInstructionGeneratedCode {
1877 IrInstruction base;1869 IrInstruction base;
18781870
src/analyze.cpp+1-1
...@@ -139,7 +139,7 @@ ScopeFnDef *create_fndef_scope(AstNode *node, Scope *parent, FnTableEntry *fn_en...@@ -139,7 +139,7 @@ ScopeFnDef *create_fndef_scope(AstNode *node, Scope *parent, FnTableEntry *fn_en
139}139}
140140
141Scope *create_comptime_scope(AstNode *node, Scope *parent) {141Scope *create_comptime_scope(AstNode *node, Scope *parent) {
142 assert(node->type == NodeTypeCompTime);142 assert(node->type == NodeTypeCompTime || node->type == NodeTypeSwitchExpr);
143 ScopeCompTime *scope = allocate<ScopeCompTime>(1);143 ScopeCompTime *scope = allocate<ScopeCompTime>(1);
144 init_scope(&scope->base, ScopeIdCompTime, node, parent);144 init_scope(&scope->base, ScopeIdCompTime, node, parent);
145 return &scope->base;145 return &scope->base;
src/codegen.cpp-2
...@@ -2261,7 +2261,6 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,...@@ -2261,7 +2261,6 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
2261 case IrInstructionIdCompileVar:2261 case IrInstructionIdCompileVar:
2262 case IrInstructionIdSizeOf:2262 case IrInstructionIdSizeOf:
2263 case IrInstructionIdSwitchTarget:2263 case IrInstructionIdSwitchTarget:
2264 case IrInstructionIdStaticEval:
2265 case IrInstructionIdContainerInitFields:2264 case IrInstructionIdContainerInitFields:
2266 case IrInstructionIdMinValue:2265 case IrInstructionIdMinValue:
2267 case IrInstructionIdMaxValue:2266 case IrInstructionIdMaxValue:
...@@ -3640,7 +3639,6 @@ static void define_builtin_fns(CodeGen *g) {...@@ -3640,7 +3639,6 @@ static void define_builtin_fns(CodeGen *g) {
3640 create_builtin_fn(g, BuiltinFnIdCDefine, "cDefine", 2);3639 create_builtin_fn(g, BuiltinFnIdCDefine, "cDefine", 2);
3641 create_builtin_fn(g, BuiltinFnIdCUndef, "cUndef", 1);3640 create_builtin_fn(g, BuiltinFnIdCUndef, "cUndef", 1);
3642 create_builtin_fn(g, BuiltinFnIdCompileVar, "compileVar", 1);3641 create_builtin_fn(g, BuiltinFnIdCompileVar, "compileVar", 1);
3643 create_builtin_fn(g, BuiltinFnIdStaticEval, "staticEval", 1);
3644 create_builtin_fn(g, BuiltinFnIdGeneratedCode, "generatedCode", 1);3642 create_builtin_fn(g, BuiltinFnIdGeneratedCode, "generatedCode", 1);
3645 create_builtin_fn(g, BuiltinFnIdCtz, "ctz", 1);3643 create_builtin_fn(g, BuiltinFnIdCtz, "ctz", 1);
3646 create_builtin_fn(g, BuiltinFnIdClz, "clz", 1);3644 create_builtin_fn(g, BuiltinFnIdClz, "clz", 1);
src/ir.cpp+7-59
...@@ -315,10 +315,6 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionEnumTag *) {...@@ -315,10 +315,6 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionEnumTag *) {
315 return IrInstructionIdEnumTag;315 return IrInstructionIdEnumTag;
316}316}
317317
318static constexpr IrInstructionId ir_instruction_id(IrInstructionStaticEval *) {
319 return IrInstructionIdStaticEval;
320}
321
322static constexpr IrInstructionId ir_instruction_id(IrInstructionGeneratedCode *) {318static constexpr IrInstructionId ir_instruction_id(IrInstructionGeneratedCode *) {
323 return IrInstructionIdGeneratedCode;319 return IrInstructionIdGeneratedCode;
324}320}
...@@ -1403,15 +1399,6 @@ static IrInstruction *ir_build_enum_tag_from(IrBuilder *irb, IrInstruction *old_...@@ -1403,15 +1399,6 @@ static IrInstruction *ir_build_enum_tag_from(IrBuilder *irb, IrInstruction *old_
1403 return new_instruction;1399 return new_instruction;
1404}1400}
14051401
1406static IrInstruction *ir_build_static_eval(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) {
1407 IrInstructionStaticEval *instruction = ir_build_instruction<IrInstructionStaticEval>(irb, scope, source_node);
1408 instruction->value = value;
1409
1410 ir_ref_instruction(value, irb->current_basic_block);
1411
1412 return &instruction->base;
1413}
1414
1415static IrInstruction *ir_build_generated_code(IrBuilder *irb, Scope *scope, AstNode *source_node,1402static IrInstruction *ir_build_generated_code(IrBuilder *irb, Scope *scope, AstNode *source_node,
1416 IrInstruction *value)1403 IrInstruction *value)
1417{1404{
...@@ -2300,13 +2287,6 @@ static IrInstruction *ir_instruction_ctz_get_dep(IrInstructionCtz *instruction,...@@ -2300,13 +2287,6 @@ static IrInstruction *ir_instruction_ctz_get_dep(IrInstructionCtz *instruction,
2300 }2287 }
2301}2288}
23022289
2303static IrInstruction *ir_instruction_staticeval_get_dep(IrInstructionStaticEval *instruction, size_t index) {
2304 switch (index) {
2305 case 0: return instruction->value;
2306 default: return nullptr;
2307 }
2308}
2309
2310static IrInstruction *ir_instruction_generatedcode_get_dep(IrInstructionGeneratedCode *instruction, size_t index) {2290static IrInstruction *ir_instruction_generatedcode_get_dep(IrInstructionGeneratedCode *instruction, size_t index) {
2311 switch (index) {2291 switch (index) {
2312 case 0: return instruction->value;2292 case 0: return instruction->value;
...@@ -2711,8 +2691,6 @@ static IrInstruction *ir_instruction_get_dep(IrInstruction *instruction, size_t...@@ -2711,8 +2691,6 @@ static IrInstruction *ir_instruction_get_dep(IrInstruction *instruction, size_t
2711 return ir_instruction_clz_get_dep((IrInstructionClz *) instruction, index);2691 return ir_instruction_clz_get_dep((IrInstructionClz *) instruction, index);
2712 case IrInstructionIdCtz:2692 case IrInstructionIdCtz:
2713 return ir_instruction_ctz_get_dep((IrInstructionCtz *) instruction, index);2693 return ir_instruction_ctz_get_dep((IrInstructionCtz *) instruction, index);
2714 case IrInstructionIdStaticEval:
2715 return ir_instruction_staticeval_get_dep((IrInstructionStaticEval *) instruction, index);
2716 case IrInstructionIdGeneratedCode:2694 case IrInstructionIdGeneratedCode:
2717 return ir_instruction_generatedcode_get_dep((IrInstructionGeneratedCode *) instruction, index);2695 return ir_instruction_generatedcode_get_dep((IrInstructionGeneratedCode *) instruction, index);
2718 case IrInstructionIdImport:2696 case IrInstructionIdImport:
...@@ -3727,15 +3705,6 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo...@@ -3727,15 +3705,6 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
37273705
3728 return ir_build_clz(irb, scope, node, arg0_value);3706 return ir_build_clz(irb, scope, node, arg0_value);
3729 }3707 }
3730 case BuiltinFnIdStaticEval:
3731 {
3732 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
3733 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
3734 if (arg0_value == irb->codegen->invalid_instruction)
3735 return arg0_value;
3736
3737 return ir_build_static_eval(irb, scope, node, arg0_value);
3738 }
3739 case BuiltinFnIdGeneratedCode:3708 case BuiltinFnIdGeneratedCode:
3740 {3709 {
3741 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);3710 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
...@@ -4731,6 +4700,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -4731,6 +4700,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
4731 ZigList<IrBasicBlock *> incoming_blocks = {0};4700 ZigList<IrBasicBlock *> incoming_blocks = {0};
4732 ZigList<IrInstructionCheckSwitchProngsRange> check_ranges = {0};4701 ZigList<IrInstructionCheckSwitchProngsRange> check_ranges = {0};
47334702
4703 Scope *comptime_scope = create_comptime_scope(node, scope);
4734 AstNode *else_prong = nullptr;4704 AstNode *else_prong = nullptr;
4735 for (size_t prong_i = 0; prong_i < prong_count; prong_i += 1) {4705 for (size_t prong_i = 0; prong_i < prong_count; prong_i += 1) {
4736 AstNode *prong_node = node->data.switch_expr.prongs.at(prong_i);4706 AstNode *prong_node = node->data.switch_expr.prongs.at(prong_i);
...@@ -4764,11 +4734,11 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -4764,11 +4734,11 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
4764 AstNode *start_node = item_node->data.switch_range.start;4734 AstNode *start_node = item_node->data.switch_range.start;
4765 AstNode *end_node = item_node->data.switch_range.end;4735 AstNode *end_node = item_node->data.switch_range.end;
47664736
4767 IrInstruction *start_value = ir_gen_node(irb, start_node, scope);4737 IrInstruction *start_value = ir_gen_node(irb, start_node, comptime_scope);
4768 if (start_value == irb->codegen->invalid_instruction)4738 if (start_value == irb->codegen->invalid_instruction)
4769 return irb->codegen->invalid_instruction;4739 return irb->codegen->invalid_instruction;
47704740
4771 IrInstruction *end_value = ir_gen_node(irb, end_node, scope);4741 IrInstruction *end_value = ir_gen_node(irb, end_node, comptime_scope);
4772 if (end_value == irb->codegen->invalid_instruction)4742 if (end_value == irb->codegen->invalid_instruction)
4773 return irb->codegen->invalid_instruction;4743 return irb->codegen->invalid_instruction;
47744744
...@@ -4776,13 +4746,10 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -4776,13 +4746,10 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
4776 check_range->start = start_value;4746 check_range->start = start_value;
4777 check_range->end = end_value;4747 check_range->end = end_value;
47784748
4779 IrInstruction *start_value_const = ir_build_static_eval(irb, scope, start_node, start_value);
4780 IrInstruction *end_value_const = ir_build_static_eval(irb, scope, start_node, end_value);
4781
4782 IrInstruction *lower_range_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpGreaterOrEq,4749 IrInstruction *lower_range_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpGreaterOrEq,
4783 target_value, start_value_const, false);4750 target_value, start_value, false);
4784 IrInstruction *upper_range_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpLessOrEq,4751 IrInstruction *upper_range_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpLessOrEq,
4785 target_value, end_value_const, false);4752 target_value, end_value, false);
4786 IrInstruction *both_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpBoolAnd,4753 IrInstruction *both_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpBoolAnd,
4787 lower_range_ok, upper_range_ok, false);4754 lower_range_ok, upper_range_ok, false);
4788 if (ok_bit) {4755 if (ok_bit) {
...@@ -4791,7 +4758,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -4791,7 +4758,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
4791 ok_bit = both_ok;4758 ok_bit = both_ok;
4792 }4759 }
4793 } else {4760 } else {
4794 IrInstruction *item_value = ir_gen_node(irb, item_node, scope);4761 IrInstruction *item_value = ir_gen_node(irb, item_node, comptime_scope);
4795 if (item_value == irb->codegen->invalid_instruction)4762 if (item_value == irb->codegen->invalid_instruction)
4796 return irb->codegen->invalid_instruction;4763 return irb->codegen->invalid_instruction;
47974764
...@@ -4833,7 +4800,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -4833,7 +4800,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
4833 AstNode *item_node = prong_node->data.switch_prong.items.at(item_i);4800 AstNode *item_node = prong_node->data.switch_prong.items.at(item_i);
4834 assert(item_node->type != NodeTypeSwitchRange);4801 assert(item_node->type != NodeTypeSwitchRange);
48354802
4836 IrInstruction *item_value = ir_gen_node(irb, item_node, scope);4803 IrInstruction *item_value = ir_gen_node(irb, item_node, comptime_scope);
4837 if (item_value == irb->codegen->invalid_instruction)4804 if (item_value == irb->codegen->invalid_instruction)
4838 return irb->codegen->invalid_instruction;4805 return irb->codegen->invalid_instruction;
48394806
...@@ -9660,22 +9627,6 @@ static TypeTableEntry *ir_analyze_instruction_enum_tag(IrAnalyze *ira, IrInstruc...@@ -9660,22 +9627,6 @@ static TypeTableEntry *ir_analyze_instruction_enum_tag(IrAnalyze *ira, IrInstruc
9660 return new_instruction->value.type;9627 return new_instruction->value.type;
9661}9628}
96629629
9663static TypeTableEntry *ir_analyze_instruction_static_eval(IrAnalyze *ira,
9664 IrInstructionStaticEval *static_eval_instruction)
9665{
9666 IrInstruction *value = static_eval_instruction->value->other;
9667 if (value->value.type->id == TypeTableEntryIdInvalid)
9668 return ira->codegen->builtin_types.entry_invalid;
9669
9670 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);
9671 if (!val)
9672 return ira->codegen->builtin_types.entry_invalid;
9673
9674 ConstExprValue *out_val = ir_build_const_from(ira, &static_eval_instruction->base, val->depends_on_compile_var);
9675 *out_val = *val;
9676 return value->value.type;
9677}
9678
9679static TypeTableEntry *ir_analyze_instruction_generated_code(IrAnalyze *ira, IrInstructionGeneratedCode *instruction) {9630static TypeTableEntry *ir_analyze_instruction_generated_code(IrAnalyze *ira, IrInstructionGeneratedCode *instruction) {
9680 IrInstruction *value = instruction->value->other;9631 IrInstruction *value = instruction->value->other;
9681 if (value->value.type->id == TypeTableEntryIdInvalid)9632 if (value->value.type->id == TypeTableEntryIdInvalid)
...@@ -11379,8 +11330,6 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi...@@ -11379,8 +11330,6 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi
11379 return ir_analyze_instruction_switch_var(ira, (IrInstructionSwitchVar *)instruction);11330 return ir_analyze_instruction_switch_var(ira, (IrInstructionSwitchVar *)instruction);
11380 case IrInstructionIdEnumTag:11331 case IrInstructionIdEnumTag:
11381 return ir_analyze_instruction_enum_tag(ira, (IrInstructionEnumTag *)instruction);11332 return ir_analyze_instruction_enum_tag(ira, (IrInstructionEnumTag *)instruction);
11382 case IrInstructionIdStaticEval:
11383 return ir_analyze_instruction_static_eval(ira, (IrInstructionStaticEval *)instruction);
11384 case IrInstructionIdGeneratedCode:11333 case IrInstructionIdGeneratedCode:
11385 return ir_analyze_instruction_generated_code(ira, (IrInstructionGeneratedCode *)instruction);11334 return ir_analyze_instruction_generated_code(ira, (IrInstructionGeneratedCode *)instruction);
11386 case IrInstructionIdImport:11335 case IrInstructionIdImport:
...@@ -11591,7 +11540,6 @@ bool ir_has_side_effects(IrInstruction *instruction) {...@@ -11591,7 +11540,6 @@ bool ir_has_side_effects(IrInstruction *instruction) {
11591 case IrInstructionIdSwitchVar:11540 case IrInstructionIdSwitchVar:
11592 case IrInstructionIdSwitchTarget:11541 case IrInstructionIdSwitchTarget:
11593 case IrInstructionIdEnumTag:11542 case IrInstructionIdEnumTag:
11594 case IrInstructionIdStaticEval:
11595 case IrInstructionIdGeneratedCode:11543 case IrInstructionIdGeneratedCode:
11596 case IrInstructionIdRef:11544 case IrInstructionIdRef:
11597 case IrInstructionIdMinValue:11545 case IrInstructionIdMinValue:
src/ir_print.cpp-9
...@@ -486,12 +486,6 @@ static void ir_print_enum_tag(IrPrint *irp, IrInstructionEnumTag *instruction) {...@@ -486,12 +486,6 @@ static void ir_print_enum_tag(IrPrint *irp, IrInstructionEnumTag *instruction) {
486 ir_print_other_instruction(irp, instruction->value);486 ir_print_other_instruction(irp, instruction->value);
487}487}
488488
489static void ir_print_static_eval(IrPrint *irp, IrInstructionStaticEval *instruction) {
490 fprintf(irp->f, "@staticEval(");
491 ir_print_other_instruction(irp, instruction->value);
492 fprintf(irp->f, ")");
493}
494
495static void ir_print_generated_code(IrPrint *irp, IrInstructionGeneratedCode *instruction) {489static void ir_print_generated_code(IrPrint *irp, IrInstructionGeneratedCode *instruction) {
496 fprintf(irp->f, "@generatedCode(");490 fprintf(irp->f, "@generatedCode(");
497 ir_print_other_instruction(irp, instruction->value);491 ir_print_other_instruction(irp, instruction->value);
...@@ -938,9 +932,6 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {...@@ -938,9 +932,6 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
938 case IrInstructionIdEnumTag:932 case IrInstructionIdEnumTag:
939 ir_print_enum_tag(irp, (IrInstructionEnumTag *)instruction);933 ir_print_enum_tag(irp, (IrInstructionEnumTag *)instruction);
940 break;934 break;
941 case IrInstructionIdStaticEval:
942 ir_print_static_eval(irp, (IrInstructionStaticEval *)instruction);
943 break;
944 case IrInstructionIdGeneratedCode:935 case IrInstructionIdGeneratedCode:
945 ir_print_generated_code(irp, (IrInstructionGeneratedCode *)instruction);936 ir_print_generated_code(irp, (IrInstructionGeneratedCode *)instruction);
946 break;937 break;
test/cases/array.zig+1-1
...@@ -49,7 +49,7 @@ fn arrayLiteral() {...@@ -49,7 +49,7 @@ fn arrayLiteral() {
49fn arrayDotLenConstExpr() {49fn arrayDotLenConstExpr() {
50 @setFnTest(this);50 @setFnTest(this);
5151
52 assert(@staticEval(some_array.len) == 4);52 assert(comptime {some_array.len == 4});
53}53}
5454
55const ArrayDotLenConstExpr = struct {55const ArrayDotLenConstExpr = struct {
test/cases/generics.zig+1-1
...@@ -13,7 +13,7 @@ fn max(comptime T: type, a: T, b: T) -> T {...@@ -13,7 +13,7 @@ fn max(comptime T: type, a: T, b: T) -> T {
13}13}
1414
15fn add(comptime a: i32, b: i32) -> i32 {15fn add(comptime a: i32, b: i32) -> i32 {
16 return @staticEval(a) + b;16 return comptime {a} + b;
17}17}
1818
19const the_max = max(u32, 1234, 5678);19const the_max = max(u32, 1234, 5678);
test/cases/math.zig+2-2
...@@ -172,8 +172,8 @@ const DivResult = struct {...@@ -172,8 +172,8 @@ const DivResult = struct {
172fn binaryNot() {172fn binaryNot() {
173 @setFnTest(this);173 @setFnTest(this);
174174
175 assert(@staticEval(~u16(0b1010101010101010) == 0b0101010101010101));175 assert(comptime {~u16(0b1010101010101010) == 0b0101010101010101});
176 assert(@staticEval(~u64(2147483647) == 18446744071562067968));176 assert(comptime {~u64(2147483647) == 18446744071562067968});
177 testBinaryNot(0b1010101010101010);177 testBinaryNot(0b1010101010101010);
178}178}
179179
test/cases/misc.zig+3-3
...@@ -174,8 +174,8 @@ fn memcpyAndMemsetIntrinsics() {...@@ -174,8 +174,8 @@ fn memcpyAndMemsetIntrinsics() {
174fn builtinStaticEval() {174fn builtinStaticEval() {
175 @setFnTest(this);175 @setFnTest(this);
176176
177 const x : i32 = @staticEval(1 + 2 + 3);177 const x : i32 = comptime {1 + 2 + 3};
178 assert(x == @staticEval(6));178 assert(x == comptime 6);
179}179}
180180
181fn slicing() {181fn slicing() {
...@@ -201,7 +201,7 @@ fn constantEqualFunctionPointers() {...@@ -201,7 +201,7 @@ fn constantEqualFunctionPointers() {
201 @setFnTest(this);201 @setFnTest(this);
202202
203 const alias = emptyFn;203 const alias = emptyFn;
204 assert(@staticEval(emptyFn == alias));204 assert(comptime {emptyFn == alias});
205}205}
206206
207fn emptyFn() {}207fn emptyFn() {}
test/run_tests.cpp-6
...@@ -1116,12 +1116,6 @@ const x = @compileVar("bogus");...@@ -1116,12 +1116,6 @@ const x = @compileVar("bogus");
1116 )SOURCE", 1, ".tmp_source.zig:2:23: error: unrecognized compile variable: 'bogus'");1116 )SOURCE", 1, ".tmp_source.zig:2:23: error: unrecognized compile variable: 'bogus'");
11171117
11181118
1119 add_compile_fail_case("@staticEval", R"SOURCE(
1120fn a(x: i32) {
1121 const y = @staticEval(x);
1122}
1123 )SOURCE", 1, ".tmp_source.zig:3:27: error: unable to evaluate constant expression");
1124
1125 add_compile_fail_case("non constant expression in array size outside function", R"SOURCE(1119 add_compile_fail_case("non constant expression in array size outside function", R"SOURCE(
1126const Foo = struct {1120const Foo = struct {
1127 y: [get()]u8,1121 y: [get()]u8,