Skip to content

Minor improvements to printf#1642

Merged
OlivierBBB merged 2 commits intomainfrom
1641-minor-improvements-to-printf
Apr 9, 2026
Merged

Minor improvements to printf#1642
OlivierBBB merged 2 commits intomainfrom
1641-minor-improvements-to-printf

Conversation

@OlivierBBB
Copy link
Copy Markdown
Collaborator

@OlivierBBB OlivierBBB commented Apr 9, 2026

Note

Medium Risk
Changes printf/debug output formatting semantics by adding %b and altering %x to include a 0x prefix, which can break consumers or golden-output tests relying on prior string formats.

Overview
Extends printf format parsing to support %b for binary output.

Updates formatted word rendering to add 0b/0x prefixes for %b and %x respectively, changing the exact text produced by existing hex-formatted prints.

Reviewed by Cursor Bugbot for commit c893345. Bugbot is set up for automated code reviews on this repo. Configure here.

@OlivierBBB OlivierBBB linked an issue Apr 9, 2026 that may be closed by this pull request
Copilot AI review requested due to automatic review settings April 9, 2026 10:41
@OlivierBBB OlivierBBB self-assigned this Apr 9, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds binary formatting support to ZkC printf formatting and adjusts word formatting output for hex/binary.

Changes:

  • Introduced FORMAT_BIN / BinFormat() and added %b support in Format.String().
  • Updated FormatWord to emit 0x... for hex and 0b... for binary.
  • Extended the parser to recognize %b in printf format strings.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
pkg/zkc/util/formatted_text.go Adds binary format support and updates hex/binary string rendering in FormatWord.
pkg/zkc/compiler/parser/parser.go Allows %b as a valid printf format specifier during parsing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +38 to +39
// FORMAT_BIN indicates to format in hexadecimal
FORMAT_BIN
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

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

The doc comment for FORMAT_BIN is incorrect: it says the format is hexadecimal, but this constant represents binary output. Please update the comment to refer to binary formatting to avoid confusion for future readers.

Copilot uses AI. Check for mistakes.
return Format{FORMAT_HEX}
}

// BinFormat constructs a new hexadecimal format.
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

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

The BinFormat comment is a copy/paste error (it says it constructs a hexadecimal format). Since BinFormat returns FORMAT_BIN and String() maps that to "%b", the comment should describe constructing a binary format.

Suggested change
// BinFormat constructs a new hexadecimal format.
// BinFormat constructs a new binary format.

Copilot uses AI. Check for mistakes.
@OlivierBBB OlivierBBB enabled auto-merge (squash) April 9, 2026 10:45
@OlivierBBB OlivierBBB disabled auto-merge April 9, 2026 10:46
@OlivierBBB OlivierBBB requested a review from Copilot April 9, 2026 10:47
@OlivierBBB OlivierBBB force-pushed the 1641-minor-improvements-to-printf branch from 71652a1 to c893345 Compare April 9, 2026 10:50
@OlivierBBB OlivierBBB enabled auto-merge (squash) April 9, 2026 10:50
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 84 to +92
// FormatWord applies a given format to a given word to generate a formatted string.
func FormatWord[W word.Word[W]](format Format, word W) string {
switch format.Code {
case FORMAT_DEC:
return word.Text(10)
case FORMAT_HEX:
return word.Text(16)
return "0x" + word.Text(16)
case FORMAT_BIN:
return "0b" + word.Text(2)
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

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

New formatting semantics are introduced here (adding 0x/0b prefixes and base-2 formatting), but there are no Go tests covering FormatWord output. Consider adding a small unit test for util.FormatWord (and/or an integration test that asserts printf output) to lock in the expected strings for %x and %b.

Copilot uses AI. Check for mistakes.
Comment on lines 1041 to 1048
switch runes[index] {
case 'd':
return index + 1, zkc_util.DecimalFormat(), true
case 'x':
return index + 1, zkc_util.HexFormat(), true
case 'b':
return index + 1, zkc_util.BinFormat(), true
default:
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

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

Support for the new '%b' formatting token is added here, but there doesn't appear to be any parser/compile test that exercises it (e.g., a testdata ZkC file containing printf with %b). Adding such a test would prevent regressions where the token is accidentally dropped or changed.

Copilot uses AI. Check for mistakes.
@OlivierBBB OlivierBBB merged commit b7f2649 into main Apr 9, 2026
28 checks passed
@OlivierBBB OlivierBBB deleted the 1641-minor-improvements-to-printf branch April 9, 2026 11:07
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.

Minor improvements to printf

4 participants