Skip to content

incremental: more progress#21135

Merged
mlugg merged 7 commits intoziglang:masterfrom
mlugg:incremental
Aug 21, 2024
Merged

incremental: more progress#21135
mlugg merged 7 commits intoziglang:masterfrom
mlugg:incremental

Conversation

@mlugg
Copy link
Member

@mlugg mlugg commented Aug 19, 2024

Two main things:

  • Handle eval branch quota properly when memoizing calls. This is actually a bugfix to non- incremental, which brings it in line with incremental. This bugfix is a breaking change.
  • Incorporate extra information into AstGen source hashes; most notably, the line and column of @src() calls. This solidifies the language change implemented by Sema: make @src().line comptime-known #17688; see commit message for details.

I added a new incremental compilation test for the @src() stuff; it passes with the C backend.

@Vexu, this PR (first commit) required correcting some eval branch quotas in Aro. One of the changes I made was to aro/Builtins/Builtin.zig, which is a generated file, but the file used to generate it isn't included downstream. Upstream Aro should make whatever the actual required change is.

@mlugg mlugg added breaking Implementing this issue could cause existing code to no longer compile or have different behavior. release notes This PR should be mentioned in the release notes. labels Aug 19, 2024
@mlugg
Copy link
Member Author

mlugg commented Aug 19, 2024

Release notes:

Memoized Calls Use Branch Quota

As an optimization, the Zig compiler memoizes the results of comptime function calls. Previous releases of the Zig compiler had a bug where memoized calls would not subtract from the eval branch quota, meaning @setEvalBranchQuota values could be lower than the language spec will dictate. This bug has been fixed in Zig 0.14.0. Unfortunately, this bugfix is a breaking change, which may cause errors in some cases:

error: evaluation exceeded 1000 backwards branches
note: use @setEvalBranchQuota() to raise the branch limit from 1000

The fix is simple: introduce calls to @setEvalBranchQuota, or increase the value of its argument, where necessary.

@mlugg mlugg force-pushed the incremental branch 2 times, most recently from 4e72fb1 to 222081f Compare August 19, 2024 13:04
In a `memoized_call`, store how many backwards braches the call
performs. Add this to `sema.branch_count` when using a memoized call. If
this exceeds the quota, perform a non-memoized call to get a correct
"exceeded X backwards branches" error.

Also, do not memoize calls which do `@setEvalBranchQuota` or similar, as
this affects global state which must apply to the caller.

Change some eval branch quotas so that the compiler itself still builds correctly.

This commit manually changes a file in Aro which is automatically
generated. The sources which generate the file are not in this repo.
Upstream Aro should make the suitable changes on their end before the
next sync of Aro sources into the Zig repo.
mlugg added 6 commits August 21, 2024 01:30
* Indices of referenced captures
* Line and column of `@src()`

The second point aligns with a reversal of the "incremental compilation"
section of ziglang#2029 (comment).
This reversal was already done as ziglang#17688 (46a6d50), with the idea to
push incremental compilation down the line. My proposal is to keep it as
comptime-known, and simply re-analyze uses of `@src()` whenever their
line/column change.

I think this decision is reasonable for a few reasons:

* The Zig compiler is quite fast. Occasionally re-analyzing a few
  functions containing `@src()` calls is perfectly acceptable and won't
  noticably impact update times.
* The system described by Andrew in ziglang#2029 is currently vaporware.
* The system described by Andrew in ziglang#2029 is non-trivial to implement.
  In particular, it requires some way to have backends update a single
  global in certain cases, without re-doing semantic analysis. There is
  no other part of incremental compilation which requires this.
* Having `@src().line` be comptime-known is useful. For instance, ziglang#17688
  was justified by broken Tracy integration because the source line
  couldn't be comptime-known.
Also, update `std.math.Log2Int[Ceil]` to more efficient implementations
that don't use up so much damn quota!
And add a corresponding test case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking Implementing this issue could cause existing code to no longer compile or have different behavior. release notes This PR should be mentioned in the release notes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants