Skip to content

fix: unify macro call type with actual type in comptime blocks#11411

Merged
asterite merged 4 commits intomasterfrom
ab/comptime-macro-call-unification-and-undoing
Feb 2, 2026
Merged

fix: unify macro call type with actual type in comptime blocks#11411
asterite merged 4 commits intomasterfrom
ab/comptime-macro-call-unification-and-undoing

Conversation

@asterite
Copy link
Copy Markdown
Collaborator

@asterite asterite commented Jan 30, 2026

Description

Problem

Resolves #11409

Summary

This is a follow-up to #6105

#6105 is good but because we don't unify types, some type variables end up unbound. That's why #11409 was failing.

The solution here is:

  • To unify the types
  • We store the bindings that resulted from that unification. We associate those to the macro expression (an ExprId)
  • If we bump into that macro expression again, we first undo those bindings

This allows a variable to change types across macro loop iterations.

For this I also had to relax the checking of unbound generics when a function context is popped, only in comptime code. The reason is that in the new test here, in foo.len() we end up with foo without a known N, but it's fine because it's that N that we want to infer later on. In this case, if N ends up being used when interpreting the block and it's not bound, we'll get an error anyway.

Additional Context

User Documentation

Check one:

  • No user documentation needed.
  • Changes in docs/ included in this PR.
  • [For Experimental Features] Changes in docs/ to be submitted in a separate PR.

PR Checklist

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt on default settings.

@asterite asterite requested a review from a team January 30, 2026 19:50
Copy link
Copy Markdown
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Test Suite Duration'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.

Benchmark suite Current: ecabab9 Previous: 8d91700 Ratio
test_report_zkpassport_noir-ecdsa_ 3 s 2 s 1.50

This comment was automatically generated by workflow using github-action-benchmark.

CC: @TomAFrench

Copy link
Copy Markdown
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Brillig Execution Time'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.

Benchmark suite Current: ecabab9 Previous: 8d91700 Ratio
rollup-block-root 0.004 s 0.003 s 1.33

This comment was automatically generated by workflow using github-action-benchmark.

CC: @TomAFrench

Copy link
Copy Markdown
Contributor

@jfecher jfecher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somewhat of a complex interaction between comptime & the type system but the old behavior with not unifying was also unexpected and this reigns that in.

@asterite asterite added this pull request to the merge queue Feb 2, 2026
Merged via the queue into master with commit 091e39d Feb 2, 2026
137 checks passed
@asterite asterite deleted the ab/comptime-macro-call-unification-and-undoing branch February 2, 2026 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generic not found after unquote, inside comptime block

2 participants