-
Notifications
You must be signed in to change notification settings - Fork 223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: SSA globals in monomorphization and SSA gen #6985
Conversation
Changes to Brillig bytecode sizes
🧾 Summary (10% most significant diffs)
Full diff report 👇
|
Execution Report
|
Compilation Report
|
Compilation Memory Report
|
Execution Memory Report
|
I'm sure you're thinking about this but looks like we don't have global arrays yet which I expect would be the biggest contributor here. |
Are you looking at just |
Ah gotcha, I'm jumping the gun in that case. |
test_programs/execution_success/global_var_regression_simple/src/main.nr
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
test_programs/execution_success/global_var_regression_simple/src/main.nr
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly minor comments but the main item is avoiding duplication of codegen functions
Co-authored-by: jfecher <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for the ssa-gen change
…ang/noir#6985) feat!: disallow calling unconstrained functions outside of `unsafe` blocks and passing unconstrained functions in place of constrained functions (noir-lang/noir#6938) chore: simplify a couple of enum variants (noir-lang/noir#7025) chore: disallow inserting ACIR-only instructions into brillig functions (noir-lang/noir#7017) feat: unchecked math operations in SSA (noir-lang/noir#7011) chore: delete docs for versions which aren't used (noir-lang/noir#7020) feat!: Disable mocks in `execute` (noir-lang/noir#6869) chore(docs): backport 1.0.0-beta.0 doc fixes (noir-lang/noir#7014) feat(cli): Add CLI option to filter by contract function name (noir-lang/noir#7018) chore: Add more Field use info (noir-lang/noir#7019) fix: let static_assert fail with the provided message (noir-lang/noir#7005) chore: mark `aztec-nr` as expected to compile (noir-lang/noir#7015) chore: clarity fix in docs (noir-lang/noir#7016) fix: require generic trait impls to be in scope to call them (noir-lang/noir#6913) feat!: require trait primitive functions/calls to have their trait in scope (noir-lang/noir#6901) feat(lsp): use trait method docs for trait impl method docs on hover (noir-lang/noir#7003) chore: turn on averaging for protocol circuits metrics in CI (noir-lang/noir#6999) feat(comptime): Implement to_be_bits and to_le_bits in the interpreter (noir-lang/noir#7008) chore: Add short circuit in ssa-gen for known if conditions (noir-lang/noir#7007) chore: Only resolved globals monomorphization (noir-lang/noir#7006) chore: Remove resolve_is_unconstrained pass (noir-lang/noir#7004) chore: require safety doc comment for unsafe instead of `//@safety` (noir-lang/noir#6992) fix: Reproduce and fix bytecode blowup (noir-lang/noir#6972) chore: mark casts as able to be deduplicated (noir-lang/noir#6996) fix: return trait impl method as FuncId if there's only one (noir-lang/noir#6989) chore(ci): fail properly in `external-repo-checks` (noir-lang/noir#6988) fix: allow multiple trait impls for the same trait as long as one is in scope (noir-lang/noir#6987) chore: Use DFG in SSA printer (noir-lang/noir#6986) chore!: Reserve `enum` and `match` keywords (noir-lang/noir#6961)
feat!: disallow calling unconstrained functions outside of `unsafe` blocks and passing unconstrained functions in place of constrained functions (noir-lang/noir#6938) chore: simplify a couple of enum variants (noir-lang/noir#7025) chore: disallow inserting ACIR-only instructions into brillig functions (noir-lang/noir#7017) feat: unchecked math operations in SSA (noir-lang/noir#7011) chore: delete docs for versions which aren't used (noir-lang/noir#7020) feat!: Disable mocks in `execute` (noir-lang/noir#6869) chore(docs): backport 1.0.0-beta.0 doc fixes (noir-lang/noir#7014) feat(cli): Add CLI option to filter by contract function name (noir-lang/noir#7018) chore: Add more Field use info (noir-lang/noir#7019) fix: let static_assert fail with the provided message (noir-lang/noir#7005) chore: mark `aztec-nr` as expected to compile (noir-lang/noir#7015) chore: clarity fix in docs (noir-lang/noir#7016) fix: require generic trait impls to be in scope to call them (noir-lang/noir#6913) feat!: require trait primitive functions/calls to have their trait in scope (noir-lang/noir#6901) feat(lsp): use trait method docs for trait impl method docs on hover (noir-lang/noir#7003) chore: turn on averaging for protocol circuits metrics in CI (noir-lang/noir#6999) feat(comptime): Implement to_be_bits and to_le_bits in the interpreter (noir-lang/noir#7008) chore: Add short circuit in ssa-gen for known if conditions (noir-lang/noir#7007) chore: Only resolved globals monomorphization (noir-lang/noir#7006) chore: Remove resolve_is_unconstrained pass (noir-lang/noir#7004) chore: require safety doc comment for unsafe instead of `//@safety` (noir-lang/noir#6992) fix: Reproduce and fix bytecode blowup (noir-lang/noir#6972) chore: mark casts as able to be deduplicated (noir-lang/noir#6996) fix: return trait impl method as FuncId if there's only one (noir-lang/noir#6989) chore(ci): fail properly in `external-repo-checks` (noir-lang/noir#6988) fix: allow multiple trait impls for the same trait as long as one is in scope (noir-lang/noir#6987) chore: Use DFG in SSA printer (noir-lang/noir#6986) chore!: Reserve `enum` and `match` keywords (noir-lang/noir#6961)
Description
Problem*
Working towards #6801
Summary*
This PR does the initial work to move towards handling globals in SSA. Actually utilizing globals in Brillig gen will come in a follow-up PR. I wanted to split out this work for easier reviewing as all the globals work together will be a good amount of code.
I wanted to add globals to SSA without any major changes to our existing data structures and or having to thread lifetimes throughout our structures. In follow-up work we most likely will want to further abstract some our concepts such as the
DataFlowGraph
or pass a global context into all SSA functions. For now, I wanted to focus on minimal changes without causing regressions.The main changes:
Definition::Global
. If we have a new global we monomorphize the global's expression but then wrap it in an ident with aDefinition::Global
. For closures we keep the old strategy of inlining the global during monomorphization.SharedContext
now contains aGlobalsContext
GlobalsContext
re-uses theDataFlowGraph
to build globals. The newly built globals are stored in aglobals: BTreeMap<monomorphization::ast::GlobalId, Values>
map to be accessed by theFunctionContext
.Value::Global
. When we seeValue::Global
it indicates we have a reserved value id and that we need to access some separate global context for the actual value. Currently, the only pass that makes use of this isinlining
. We are currently still inlining all globals so that the globals work can be split up for easier reviewing.Example SSA for the new
global_var_regression_simple
test (commenting outassert(!acc.lt(x))
for a simpler SSA):SSA output with globals
Additional Context
Actual implementation of globals and handling them as we do existing constants will come in followups. It may be helpful to wait for the PR with the Brillig gen implementation to see how globals will actually be used.
Documentation*
Check one:
PR Checklist*
cargo fmt
on default settings.