Skip to content
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

fix: Keep format string literal when converting comptime value to HIR expression #6994

Closed
wants to merge 2 commits into from

Conversation

vezenovm
Copy link
Contributor

@vezenovm vezenovm commented Jan 8, 2025

Description

Problem*

Resolves #6990

Summary*

Go to the issue for the initial context. What I did is a little bit hack-y, but it seemed like the simplest way to prevent this panic without making significant changes to how we monomorphize.

Format strings are the only comptime type which we lower into a different type (in this case a string literal). I changed the Value::FormatString case in into_hir_expression to return a HirLiteral::FmtStr in the format that the type is expected to be. This required creating a new placeholder expression. In this case I used a string with a single whitespace character as this required minimal changes and does not change the functionality of fmt strings which are entirely used for logging.

I added some global fmt strings to the debug_logs test:
These prints:

global A: Field = 50;
global B: Field = 100;
global GLOBAL_FMT_STR: fmtstr<14, (Field, Field)> = f"i: {A}, j: {B}";
global GLOBAL_FMT_STR_BIG: fmtstr<22, (Field, Field, Field)> = f"i: {A}, j: {B}, k: {A}";

fn main(..) {
    println(GLOBAL_FMT_STR);
    println(GLOBAL_FMT_STR_BIG);
}

Give this output:

i: 50, j: 100
i: 50, j: 100, k: 50

Additional Context

We do not currently allow nested format strings. Having this extra whitespace may cause some difficulty if we ever activate the ability to have nested format strings.

Documentation*

Check one:

  • No documentation needed.
  • Documentation included in this PR.
  • [For Experimental Features] Documentation 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.

@vezenovm vezenovm requested a review from a team January 8, 2025 22:41
Copy link
Contributor

github-actions bot commented Jan 8, 2025

Changes to Brillig bytecode sizes

Generated at commit: 193d910dc1ee23fa9e5e7a2457e9ae24a0bfdb3d, compared to commit: 8d7f1f909c50887bca6ff1243d70622c2a3b3ec8

🧾 Summary (10% most significant diffs)

Program Brillig opcodes (+/-) %
debug_logs +157 ❌ +3.06%

Full diff report 👇
Program Brillig opcodes (+/-) %
debug_logs 5,281 (+157) +3.06%

Copy link
Contributor

github-actions bot commented Jan 8, 2025

Changes to number of Brillig opcodes executed

Generated at commit: 193d910dc1ee23fa9e5e7a2457e9ae24a0bfdb3d, compared to commit: 8d7f1f909c50887bca6ff1243d70622c2a3b3ec8

🧾 Summary (10% most significant diffs)

Program Brillig opcodes (+/-) %
debug_logs +160 ❌ +3.12%

Full diff report 👇
Program Brillig opcodes (+/-) %
debug_logs 5,296 (+160) +3.12%

Copy link
Contributor

github-actions bot commented Jan 8, 2025

Changes to circuit sizes

Generated at commit: 193d910dc1ee23fa9e5e7a2457e9ae24a0bfdb3d, compared to commit: 8d7f1f909c50887bca6ff1243d70622c2a3b3ec8

🧾 Summary (10% most significant diffs)

Program ACIR opcodes (+/-) % Circuit size (+/-) %
debug_logs +3 ❌ +6.52% 0 ➖ 0.00%

Full diff report 👇
Program ACIR opcodes (+/-) % Circuit size (+/-) %
debug_logs 49 (+3) +6.52% 73 (0) 0.00%

Copy link
Contributor

github-actions bot commented Jan 8, 2025

Compilation Report

Program Compilation Time %
sha256_regression 1.028s -15%
regression_4709 0.763s -11%
ram_blowup_regression 14.720s -5%
rollup-root 4.050s 8%
rollup-block-merge 4.050s 15%
rollup-base-public 30.000s -5%
rollup-base-private 11.300s -5%
private-kernel-tail 1.021s -1%
private-kernel-reset 8.614s -1%
private-kernel-inner 2.036s -4%

Copy link
Contributor

github-actions bot commented Jan 8, 2025

Execution Report

Program Execution Time %
sha256_regression 0.054s 0%
regression_4709 0.001s 0%
ram_blowup_regression 0.576s 0%
rollup-root 0.105s 0%
rollup-block-merge 0.106s 0%
rollup-base-public 1.320s 0%
rollup-base-private 0.523s 1%
private-kernel-tail 0.022s 0%
private-kernel-reset 0.384s 0%
private-kernel-inner 0.097s 0%

Copy link
Contributor

github-actions bot commented Jan 8, 2025

Compilation Memory Report

Program Peak Memory
keccak256 78.55M
workspace 123.62M
regression_4709 422.96M
ram_blowup_regression 1.58G
rollup-base-public 2.55G
rollup-base-private 1.24G
private-kernel-tail 200.40M
private-kernel-reset 728.14M
private-kernel-inner 290.46M

Copy link
Contributor

github-actions bot commented Jan 8, 2025

Execution Memory Report

Program Peak Memory
keccak256 74.65M
workspace 123.89M
regression_4709 315.98M
ram_blowup_regression 512.41M
rollup-base-public 492.17M
rollup-base-private 332.25M
private-kernel-tail 181.08M
private-kernel-reset 254.94M
private-kernel-inner 212.77M

@vezenovm vezenovm marked this pull request as draft January 9, 2025 03:55
@vezenovm
Copy link
Contributor Author

vezenovm commented Jan 9, 2025

Going to close this PR as the correct solution is to accurately monomorphize the functions based off of the new lowered type. This hack is insufficient anyway for the general use case.

@vezenovm vezenovm closed this Jan 9, 2025
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.

Cannot print global fmtstr
2 participants