zig icon indicating copy to clipboard operation
zig copied to clipboard

`@setEvalBranchQuota` does not behave as expected

Open rockorager opened this issue 1 year ago • 2 comments

Zig Version

0.12.0-dev.3437+af0668d6c

Steps to Reproduce and Observed Behavior

@setEvalBranchQuota(2000);
@setEvalbranchQuota(1000);

Expected Behavior

In the above example, the resultant quota is 2000, which is counterintuitive given the name of the builtin.

The docs for @setEvalBranchQuota state:

Increase the maximum number of backwards branches that compile-time code execution can use before giving up and making a compile error.

If the new_quota is smaller than the default quota (1000) or a previously explicitly set quota, it is ignored. 

The naming suggests that the eval quota is set to the last called value. This causes confusion when perusing source code (ie std.ComptimeStringMapWithEql) which sets the value to some n. It's not clear that setting it higher before this call will be of any use.

Perhaps a name like @increaseEvalBranchQuotaTo(n) would be more clear as to what the builtin actually does.

rockorager avatar Apr 03 '24 17:04 rockorager

Running into https://github.com/ziglang/zig/issues/19803 again. @setEvalBranchQuota should be replaced with @increaseEvalBranchQuotaBy.

Then,

@increaseEvalBranchQuotaBy(2000);
@increaseEvalBranchQuotaBy(1000);
// eval branch quota now default + 2000 + 1000

Pyrolistical avatar May 19 '24 00:05 Pyrolistical

No, increasing the quota by an amount rather than setting the max upper bound will lead to infinite compilation loops.

andrewrk avatar May 19 '24 06:05 andrewrk

Rejecting the proposal to rename the builtin to "increaseEvalBranchQuotaTo" because I think it is not any clearer.

andrewrk avatar Aug 15 '24 07:08 andrewrk