-
Notifications
You must be signed in to change notification settings - Fork 909
Go pain points
Here are a few pain points of the Go language and standard library, as it is currently implemented. More details below.
- [high] The Go standard library is closely coupled with the runtime. This is very problematic, because it forces numerous hacks and workarounds to be able to use standard library packages from Go code.
- [high] Package initialization order forces sequential initialization of globals.
-
[medium] No support for volatile variables. This has been worked around with compiler pragma's (
//go:volatile
), but some sort of language support would be useful. Volatile variables are commonly used to directly access memory mapped peripherals. - [low] No support for bitfields. It would be useful to be able to split up a struct field into multiple pieces like in C, to reduce memory consumption and because some memory-mapped I/O is much easier to implement with this.
-
[low] No support for binary numbers. Bit twiddling is very common in embedded software. It would be useful to be able to write constant numbers with a
0b
prefix like in Python, for example0b11001010
(0xca
).
The current Go standard library is closely coupled with the runtime. This is fine for gc
and gccgo
, but it is problematic for tinygo
as it implements its own runtime.
A solution is to clearly separate the Go standard library from the Go runtime. Ian Lance Taylor has described this in his Go 2 transition proposal. It comes down to determining which packages are runtime bound and which are not, and distributing the latter as a separate Go module. Runtime-related packages are of course package runtime, but also packages like reflect and sync that must be closely coupled with the compiler and runtime for them to work. As an addition to Ian's proposal, some packages like time may need to be split into a runtime-independent part providing parsing/formatting of time strings and basic time calculations, and a runtime-dependent part providing functions like time.Now
and time.Sleep
.
An additional constraint for TinyGo is that this standard library package must be truly independent of the compiler and runtime and not just version-independent of the compiler and runtime. It is not enough to keep the compiler/runtime ABI-compatible with past and future versions of the standard library package, but every part of the API/ABI between the standard library and the compiler/runtime must be clearly specified.