-
Notifications
You must be signed in to change notification settings - Fork 211
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!: several format string fixes and improvements #6703
Conversation
We should definitely error here eventually, it's quite an annoyance while writing format strings |
Awesome! I'll tackle that next, it should be relatively easy to do. I also noticed that if you write |
Peak Memory Sample
|
Oooh... a test is failing because it has this: let s1 = f"x is {x}, fake interpolation: \{y}, y is {y}"; I guess |
Let's stick with Rust in this case |
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 👍
Changes to Brillig bytecode sizes
🧾 Summary (10% most significant diffs)
Full diff report 👇
|
Changes to number of Brillig opcodes executed
🧾 Summary (10% most significant diffs)
Full diff report 👇
|
Asking for a re-review because this PR now does a lot more than what I originally planned. |
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.
Looks good!
…#6650) fix: git dependency trailing slash (noir-lang/noir#6725) chore: optimise older opcodes in reverse order (noir-lang/noir#6476) chore: add script to check for critical libraries supporting a given Noir version (noir-lang/noir#6697) fix!: several format string fixes and improvements (noir-lang/noir#6703) fix: print ssa blocks without recursion (noir-lang/noir#6715) chore: redo typo PR by Madmaxs2 (noir-lang/noir#6721) chore: add a few regression tests for #6674 (noir-lang/noir#6687)
fix: git dependency trailing slash (noir-lang/noir#6725) chore: optimise older opcodes in reverse order (noir-lang/noir#6476) chore: add script to check for critical libraries supporting a given Noir version (noir-lang/noir#6697) fix!: several format string fixes and improvements (noir-lang/noir#6703) fix: print ssa blocks without recursion (noir-lang/noir#6715) chore: redo typo PR by Madmaxs2 (noir-lang/noir#6721) chore: add a few regression tests for #6674 (noir-lang/noir#6687)
Description
Problem
Resolves #4642
Summary
This PR includes several fixes and improvements to format strings:
f"..."
), as tokens, are now represented as fragments which can either be strings or interpolated pieces. The interpolated pieces also have a Span to know where they are. The advantage of this is that we don't need to use a regex to find the interpolations and we can provide better error messages when, for example, the interpolated variable doesn't exist. That said, the print oracle gets the raw string and needs to do the interpolation, and that still uses regex (but at least compile-time code won't need to do regex matching each time it finds a fmtstr).\n
and\t
are now allowed inside format strings.{
and}
and we do that just like in Rust:{{
to mean{
,}}
to mean}
.}
but there was no single{
before it (we were not in an interpolation) you get an error that says you must use}}
to write}
.Because
{{
now means to write{
, I had to slightly change the print oracle to understand this.Additional Context
I'm marking this PR as a breaking change because it could break someone's code if they had incorrect interpolations, or if they had
\n
inside a format string and wanted to actually print "\" and "n" separately.I left LSP features as a follow-up PR, mainly because I realized autocompletion doesn't automatically kick in when you are typing inside a string literal, so implementing completion there doesn't seem very useful. What we could do is at least implement "hover" in these pieces (go-to-definition already works).
A question: do print oracles exist somewhere else? For example in a web context (what I'm saying might not make sense, sorry). I'm just wondering if the print oracle logic of handling interpolations must be updated somewhere else too.
Documentation
This PR might need to document format string escape sequences... but I couldn't find this explained for strings so maybe all of that could be done in one go in a separate PR (if really needed now).
Check one:
PR Checklist
cargo fmt
on default settings.