mirror of
https://github.com/ziglang/zig.git
synced 2026-02-13 04:48:20 +00:00
parent
c18059a3dd
commit
49c3922037
@ -49,6 +49,7 @@ struct IrExecutable {
|
||||
size_t backward_branch_quota;
|
||||
bool invalid;
|
||||
bool is_inline;
|
||||
bool is_generic_instantiation;
|
||||
FnTableEntry *fn_entry;
|
||||
Buf *c_import_buf;
|
||||
AstNode *source_node;
|
||||
|
||||
@ -12127,6 +12127,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
|
||||
impl_fn->ir_executable.parent_exec = ira->new_irb.exec;
|
||||
impl_fn->analyzed_executable.source_node = call_instruction->base.source_node;
|
||||
impl_fn->analyzed_executable.parent_exec = ira->new_irb.exec;
|
||||
impl_fn->analyzed_executable.is_generic_instantiation = true;
|
||||
|
||||
ira->codegen->fn_defs.append(impl_fn);
|
||||
}
|
||||
@ -15234,7 +15235,7 @@ static TypeTableEntry *ir_analyze_instruction_type_id(IrAnalyze *ira,
|
||||
static TypeTableEntry *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ira,
|
||||
IrInstructionSetEvalBranchQuota *instruction)
|
||||
{
|
||||
if (ira->new_irb.exec->parent_exec != nullptr) {
|
||||
if (ira->new_irb.exec->parent_exec != nullptr && !ira->new_irb.exec->is_generic_instantiation) {
|
||||
ir_add_error(ira, &instruction->base,
|
||||
buf_sprintf("@setEvalBranchQuota must be called from the top of the comptime stack"));
|
||||
return ira->codegen->builtin_types.entry_invalid;
|
||||
|
||||
@ -448,3 +448,24 @@ test "comptime function with mutable pointer is not memoized" {
|
||||
fn increment(value: &i32) void {
|
||||
*value += 1;
|
||||
}
|
||||
|
||||
fn generateTable(comptime T: type) [1010]T {
|
||||
var res : [1010]T = undefined;
|
||||
var i : usize = 0;
|
||||
while (i < 1010) : (i += 1) {
|
||||
res[i] = T(i);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
fn doesAlotT(comptime T: type, value: usize) T {
|
||||
@setEvalBranchQuota(5000);
|
||||
const table = comptime blk: {
|
||||
break :blk generateTable(T);
|
||||
};
|
||||
return table[value];
|
||||
}
|
||||
|
||||
test "@setEvalBranchQuota at same scope as generic function call" {
|
||||
assert(doesAlotT(u32, 2) == 2);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user