Closed aykevl closed 1 year ago
Looks like that assertion was added in CL 478919 (attn @griesemer @findleyr).
Change https://go.dev/cl/508821 mentions this issue: go/types, types2: remove unnecessary assert on pointer size
I think we can just remove this assertion. I grepped and believe this is the only such assertion, but @aykevl is that easy for you to confirm, by re-running your program without the problematic assertion?
Yes, this appears to be the only assert. My tests pass after I remove that assert.
Agreed that it's ok to remove this assert.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes, both on the master branch and on the latest release candidate (Go 1.21-rc2).
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I made a standalone reproducer here: https://github.com/aykevl/sandbox/tree/main/types2-avr Simply pull the repository and run it using
go run .
.(The code is a quick-n-dirty modification of an example in go/types with the
Sizes
implementation copied from TinyGo - just enough for a standalone demonstration of the bug).What did you expect to see?
It should parse the file correctly, like it did in Go 1.20.
What did you see instead?
While typechecking, the program crashes with the following stack trace:
stack trace
``` ~/src/ayke/sandbox/types2-avr$ ~/src/tinygo/go/bin/go run . panic: /home/ayke/src/tinygo/go/src/go/types/const.go:77: assertion failed [recovered] panic: /home/ayke/src/tinygo/go/src/go/types/const.go:77: assertion failed goroutine 1 [running]: go/types.(*Checker).handleBailout(0x4000148000, 0x4000147dc8) /home/ayke/src/tinygo/go/src/go/types/check.go:336 +0x9c panic({0x1f6960?, 0x4000010310?}) /home/ayke/src/tinygo/go/src/runtime/panic.go:914 +0x218 go/types.assert(0x70?) /home/ayke/src/tinygo/go/src/go/types/errors.go:28 +0x60 go/types.representableConst.func1({0x28ea70?, 0x3c36a0?}) /home/ayke/src/tinygo/go/src/go/types/const.go:77 +0xc0 go/types.representableConst({0x2904f0, 0x400000e7c0}, 0x4000148000, 0x3c36a0, 0x40001043e8) /home/ayke/src/tinygo/go/src/go/types/const.go:107 +0x2b0 go/types.(*Checker).conversion.func1({0x28ea70?, 0x3c36a0?}, 0x40001043e8) /home/ayke/src/tinygo/go/src/go/types/conversions.go:24 +0x74 go/types.(*Checker).conversion(0x4000148000, 0x40001043c0, {0x28ea70, 0x3c36a0}) /home/ayke/src/tinygo/go/src/go/types/conversions.go:44 +0x15c go/types.(*Checker).callExpr(0x4000148000, 0x40001043c0, 0x4000104240) /home/ayke/src/tinygo/go/src/go/types/call.go:222 +0xcf0 go/types.(*Checker).exprInternal(0x4000148000, {0x0, 0x0}, 0x40001043c0, {0x28fc70, 0x4000104240?}, {0x0?, 0x0?}) /home/ayke/src/tinygo/go/src/go/types/expr.go:1359 +0x12dc go/types.(*Checker).rawExpr(0x4000148000, {0x0, 0x0}, 0x40001043c0, {0x28fc70?, 0x4000104240?}, {0x0?, 0x0?}, 0x0) /home/ayke/src/tinygo/go/src/go/types/expr.go:965 +0x134 go/types.(*Checker).expr(0x4000146a58?, {0x0?, 0x0?}, 0x40001043c0?, {0x28fc70?, 0x4000104240?}) /home/ayke/src/tinygo/go/src/go/types/expr.go:1498 +0x40 go/types.(*Checker).callExpr(0x4000148000, 0x40001043c0, 0x4000104280) /home/ayke/src/tinygo/go/src/go/types/call.go:210 +0xa98 go/types.(*Checker).exprInternal(0x4000148000, {0x0, 0x0}, 0x40001043c0, {0x28fc70, 0x4000104280?}, {0x0?, 0x0?}) /home/ayke/src/tinygo/go/src/go/types/expr.go:1359 +0x12dc go/types.(*Checker).rawExpr(0x4000148000, {0x0, 0x0}, 0x40001043c0, {0x28fc70?, 0x4000104280?}, {0x0?, 0x0?}, 0x0) /home/ayke/src/tinygo/go/src/go/types/expr.go:965 +0x134 go/types.(*Checker).expr(0x40001479e8?, {0x0?, 0x0?}, 0x169270?, {0x28fc70?, 0x4000104280?}) /home/ayke/src/tinygo/go/src/go/types/expr.go:1498 +0x40 go/types.(*Checker).varDecl(0x200b20?, 0x400006aae0, {0x400004a0e0?, 0x1, 0x1}, {0x0, 0x0}, {0x28fc70, 0x4000104280}) /home/ayke/src/tinygo/go/src/go/types/decl.go:513 +0x130 go/types.(*Checker).objDecl(0x4000148000, {0x291718, 0x400006aae0}, 0x1636e8?) /home/ayke/src/tinygo/go/src/go/types/decl.go:194 +0x7ac go/types.(*Checker).packageObjects(0x4000148000) /home/ayke/src/tinygo/go/src/go/types/resolver.go:687 +0x3fc go/types.(*Checker).checkFiles(0x4000148000, {0x4000147ef8, 0x1, 0x1}) /home/ayke/src/tinygo/go/src/go/types/check.go:380 +0x1d8 go/types.(*Checker).Files(...) /home/ayke/src/tinygo/go/src/go/types/check.go:341 go/types.(*Config).Check(0x400006a5a0, {0x23b344?, 0xa?}, 0x40001041c0, {0x4000147ef8, 0x1, 0x1}, 0x0) /home/ayke/src/tinygo/go/src/go/types/api.go:425 +0x148 main.main() /home/ayke/src/ayke/sandbox/types2-avr/main.go:38 +0x1c4 exit status 2 ```Apparently the following assert is being hit:
https://github.com/golang/go/blob/5c154986094bcc2fb28909cc5f01c9ba1dd9ddd4/src/go/types/const.go#L77
I'd guess that the code assumes that pointers must always be either 4 or 8 bytes in size, while I'm compiling Go code for a system with 2-byte pointers (as crazy as that may sound, it does in fact work - in Go 1.20 at least). Specifically, this is for AVR microcontrollers which are mostly 8-bit but have 16-bit pointers.
Some more context: I'm in the process of making TinyGo work with Go 1.21 but this is one of various issues I'm hitting: https://github.com/tinygo-org/tinygo/pull/3824