Skip to content

Add proof of concept for T.Output() #1

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

Closed
wants to merge 28 commits into from
Closed

Conversation

suntala
Copy link
Owner

@suntala suntala commented Sep 26, 2023

return OutputWriter{c}
}

type OutputWriter struct {
Copy link

Choose a reason for hiding this comment

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

unexport

parent.mu.Lock()
defer parent.mu.Unlock()
if !parent.done {
parent.output = append(parent.output, parent.decorate(str, depth+1)...)
Copy link

Choose a reason for hiding this comment

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

This Write method is at a lower level than logDepth. It isn't responsible for adding line info or a final newline, so it shouldn't call decorate. It does need to handle indentation, though. I'm not sure where that happens.

@suntala suntala force-pushed the suntala/t-output-poc branch from f8a90ab to 61379e3 Compare October 20, 2023 19:13
@suntala suntala closed this Jan 15, 2025
@suntala suntala reopened this Jan 25, 2025
suntala and others added 4 commits January 25, 2025 10:39
Co-authored-by: Aleks Fazlieva <[email protected]>
Co-authored-by: Aleks Fazlieva <[email protected]>
Co-authored-by: Aleks Fazlieva <[email protected]>
@suntala suntala force-pushed the suntala/t-output-poc branch from 3fc09b7 to c949982 Compare January 30, 2025 17:35
@jba
Copy link

jba commented Jan 31, 2025

I took another careful look at this. I do think you're on the right track: outputWriter.Write should buffer lines, direct the output to the right place (this test, parent test, etc.) and prepend four spaces. Here is what I think needs to be done:

  • Move to gerrit so we can have a better review experience, others can comment, and your CL will be linked from the proposal issue. Gerrit also allows having multiple CLs stacked on top of one another, which I think will be valuable. See https://golang.org/doc/contribute.html.

  • My gut tells me that you should have a function outputWriter.writeLine([]byte). Ultimately all output is a line at a time, so that will be a useful building block. I think you might want it to rewrite the exising code (see below). If you want the arg to be string instead of []byte, that's fine to start. I'm not sure if the arg should include the newline or not; you decide.

  • Rewrite logDepth and decorate to use outputWriter. In fact, I think the first CL should do that rewrite and make sure all tests pass. It wouldn't even expose t.Output. It would just be an internal change. I think that would increase confidence that you're on the right track, and you could temporarily defer handling various edge cases.

  • The second CL would export t.Output and add tests for things that can't happen with t.Log, which I think all have to do with partial lines. For example, what happens if you have an incomplete line and the test ends? You'll need to flush the buffer (adding a final newline).

@suntala
Copy link
Owner Author

suntala commented Feb 3, 2025

@jba thank you so much for the guidance. Doing this in two CLs, with the first one being a rewrite of the log/logDepth is a good idea. Since your message, we did the refactor and got tests working. Next steps are going to be cleaning up the code and moving to gerrit. We're aiming to get them done in the next couple of days.

@jba
Copy link

jba commented Feb 3, 2025

Sounds good. I'll hold off reviewing until it's on gerrit.

@suntala suntala force-pushed the suntala/t-output-poc branch from b98c1b4 to 7648014 Compare February 4, 2025 22:03
@suntala suntala force-pushed the suntala/t-output-poc branch 4 times, most recently from d865109 to 820826a Compare February 5, 2025 10:21
Co-authored-by: Aleks Fazlieva <[email protected]>
@suntala suntala force-pushed the suntala/t-output-poc branch from 820826a to 00014da Compare February 5, 2025 10:24
suntala pushed a commit that referenced this pull request May 13, 2025
…of variable-sized makeslice

CL 653856 enabled stack allocation of variable-sized makeslice results.

This CL adds debug hashing of that change, plus a debug flag
to control the byte threshold used.

The debug hashing machinery means we also now have a way to disable just
the CL 653856 optimization by doing -gcflags='all=-d=variablemakehash=n'
or similar, though the stderr output will then typically have many
lines of debug hash output.

Using this CL plus the bisect command, I was able to retroactively
find one of the lines of code responsible for golang#73199:

  $ bisect -compile=variablemake go test -skip TestListWireGuardDrivers
  [...]
  bisect: FOUND failing change set
  --- change set #1 (enabling changes causes failure)
  ./security_windows.go:1321:38 (variablemake)
  ./security_windows.go:1321:38 (variablemake)
  ---

Previously, I had tracked down those lines by diffing '-gcflags=-m=1'
output and brief code inspection, but seeing the bisect was very nice.

This CL also adds a compiler debug flag to control the threshold for
stack allocation of variably sized make results. This can help
us identify more code that is relying on certain stack allocations.
This might be a temporary flag that we delete prior to Go 1.25
(given we would not want people to rely on it), or maybe it
might make sense to keep it for some period of time beyond the release
of Go 1.25 to help the ecosystem shake out other bugs.

Using these two flags together (and picking a threshold of 64 rather
than the default of 32), it looks for example like this
x/sys/windows code might be relying on stack allocation of
a byte slice:

  $ bisect -compile=variablemake go test -gcflags=-d=variablemakethreshold=64 -skip TestListWireGuardDrivers
  [...]
  bisect: FOUND failing change set
  --- change set #1 (enabling changes causes failure)
  ./syscall_windows_test.go:1178:16 (variablemake)

Updates golang#73199
Fixes golang#73253

Change-Id: I160179a0e3c148c3ea86be5c9b6cea8a52c3e5b7
Reviewed-on: https://go-review.googlesource.com/c/go/+/663795
Auto-Submit: Keith Randall <[email protected]>
Reviewed-by: Dmitri Shuralyov <[email protected]>
Reviewed-by: Keith Randall <[email protected]>
Reviewed-by: Keith Randall <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
@suntala
Copy link
Owner Author

suntala commented May 15, 2025

golang#73703 and golang#71575 are merged.

@suntala suntala closed this May 15, 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.

2 participants