Skip to content

transform: add -print-allocs-cover and restore -print-allocs reason output#5460

Open
b0ch3nski wants to merge 1 commit into
tinygo-org:devfrom
b0ch3nski:print-allocs-dual
Open

transform: add -print-allocs-cover and restore -print-allocs reason output#5460
b0ch3nski wants to merge 1 commit into
tinygo-org:devfrom
b0ch3nski:print-allocs-dual

Conversation

@b0ch3nski

Copy link
Copy Markdown
Contributor

Fixes #5355.

PR #5220 changed -print-allocs output to the go coverage tool format, which replaced the original human-readable explanation of why each object had to be heap allocated. That explanation is useful on its own, so this restores it as the default behavior of -print-allocs and moves the coverage format behind a -print-allocs-cover flag.

I've also moved the expected allocations to the golden files for easier maintenance.

CC @applejag @digitalentity @deadprogram @soypat

@b0ch3nski b0ch3nski marked this pull request as ready for review June 11, 2026 15:19
@b0ch3nski b0ch3nski force-pushed the print-allocs-dual branch from 0409b9b to 81666c4 Compare June 11, 2026 18:32
Comment thread transform/allocs.go Outdated

// FormatAlloc renders the message printed for a heap allocation that could not
// be stack allocated, or "" when nothing should be printed.
func FormatAlloc(pos token.Position, reason string, cover bool) string {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this should be split into two routines rather than a single routine with a bool argument, and then at the call site you decide which formatter to call.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good idea, done 🙌

…utput

PR tinygo-org#5220 changed -print-allocs output to the go coverage tool format, which
replaced the original human-readable explanation of why each object had to be
heap allocated. That explanation is useful on its own, so this restores it as
the default behavior of -print-allocs and moves the coverage format behind a
-print-allocs-cover flag.

Signed-off-by: Piotr Bocheński <piotr@bochen.ski>
@b0ch3nski b0ch3nski force-pushed the print-allocs-dual branch from 81666c4 to 76bb4db Compare June 11, 2026 19:33
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.

Bring back printing reason with -print-allocs

2 participants