More verbose -print-allocs messages. Initial commit.#5504
Conversation
dgryski
left a comment
There was a problem hiding this comment.
Seems good but someone else a bit more familiar with this code should take a look.
|
Now the messages from the I also executed this Of course it is far from being perfect, but probably there is more possibility for mining out the name and/or type of the escaped object from LLVM IR and this change could be a stub for that. |
| return | ||
| } | ||
|
|
||
| func dumpIR(hdr string, instCnt int, fstInst llvm.Value) { |
There was a problem hiding this comment.
Yes, anyone who touches this code can use it for debugging.
There was a problem hiding this comment.
Please remove test code like this, it leads to clutter.
aykevl
left a comment
There was a problem hiding this comment.
While I agree with the idea here, the PR does need some cleanup before merging (lots of debugging code, commented out code, etc).
Also, the values printed here are mostly internal compiler values that I'm afraid will mostly be confusing to users. I recommend instead to look into adding a string attribute to the runtime.alloc call, that can then be retrieved during the printing to get the type (and perhaps the reason why it was allocated, such as "making a slice"). I'd prefer if those internal values would stay internal and we show something actually useful to users. It would be nice to have a message like "[]byte slice allocated at line X" which would be possible this way.
| return | ||
| } | ||
|
|
||
| func dumpIR(hdr string, instCnt int, fstInst llvm.Value) { |
There was a problem hiding this comment.
Please remove test code like this, it leads to clutter.
| theErr := theError{} | ||
| var err error = theErr | ||
| theErr.set("hello") | ||
| println(err.Error()) |
There was a problem hiding this comment.
@aykevl, thanks for the advise. I made an initial implementation. Unfortunately not all alloc calls get the attributes.
I have found 2 places in compiler/compiler.go, where setting attributes are reflected in LLVM IR alloc calls. These places are in builder.createExpr(expr ssa.Value) in case *ssa.Alloc: and case *ssa.MakeSlice:.
I have also checked where builder.createAlloc() are used, but I haven't identified relevant places.
Now the test output looks like this:
allocs2.go:26: slice size is not constant
allocs2.go:28: slice [300]byte size 300 exceeds maximum stack allocation size 256
allocs2.go:31: slice [4]int escapes at line 32
allocs2.go:38: Arg 0 (type: basic:complex128) of main.useInterface() escapes at line 40 // --- Fallback
allocs2.go:43: Arg 0 (type: array:3:basic:int32) of main.useInterface() escapes at line 43 // --- Fallback
allocs2.go:50: varargs [3]int escapes at line 50
allocs2.go:52: slice [3]int escapes at line 53
allocs2.go:55: n4 escapes at line 57
allocs2.go:56: n5 escapes at line 57
allocs2.go:127: slice [3]int escapes at line 128
allocs2.go:134: b escapes at line 137
allocs2.go:143: main.vector3 escapes at line 144
allocs2.go:145: main.vector3 escapes at line 146
allocs2.go:145: main.vector3 escapes at line 146
allocs2.go:151: main.vector3 escapes at line 151
allocs2.go:151: main.vector3 escapes at line 151
allocs2.go:155: main.vector3 escapes at line 155
allocs2.go:155: main.vector3 escapes at line 155
allocs2.go:166: b escapes at unknown line
allocs2.go:174: varargs [1]any escapes at line 174
allocs2.go:179: main.theError escapes at line 179
allocs2.go:183: main.theError escapes at line 183
allocs2.go:188: array:3:basic:int32 escapes at line 188 // --- Fallback
Do you have idea for improvement?
This change intends to provide more verbose
-print-allocsmessages by naming the escaping intermediate variable or type.Currently it is tested only with the unit tests.
Here are the modified messages, generated by
allocs_test.go: