154 points · by Leotard6963 · 3y ago · 82 comments
We are building `pcz` to provide a reimagination of Go the language, in an effort to make it suitable for all kinds of programming tasks, and currently you can use it to build efficient web applications in Go using the generated Web SDK (as shown with the live web demo[1]).
The journey is just starting, any suggestions? or any critics?
"Non-Goals"
"Change the way the Go team works or make them change their decisions."
Not every project (and very much not every fork) is a political statement against the original. Sometimes people are glad what others do and want them to continue. Still, wanting their own different version to coexist is completely OK.
Were the confusion caused by the choice of project name `pcz` instead of `xxxstd`? or any suggestion for us to improve?
This comment is the first time I realised it was not intended to be a drop-in replacement for the Go standard library (in a musl - glibc kind of relationship).
The fact that requires a different standard library seems like a consequence of the first decision but it's unclear.
As a Go developer, can I expect to be able to build modules that will work both with both Go's stdlib and pcz std (maybe using build tag guards) ?
Are you building a completely separate ecosystem or can we expect some overlap?
The problem is, in order to build a std, we have to use a lot of <ABIInternal> stuff in assembly, and use internal/abi.FuncPCABIInternal in Go, so we can not make any promise regarding to the inter-std-compatibility for the time being, unless the Go project decided to make these features stable.
I have certainly encountered issues where Go is hiding the platform from me and this is very annoying. This was only ever a real problem on Windows though, the "virtual platform" that Go provides is generally fine for Linux IMO. Is this mainly about non-Linux platforms? (Which would be perfectly reasonable, BTW. Linux is not the only platform )
Meanwhile, I can see why someone would be interested in no-GC. But this seems orthogonal to the goal of "adapting to the platform" - am I missing something there?
And on the no-go routines thing, what's the motivation for wanting that? Does their presence in the language have some related impact on it? Or is it just that you don't think they're useful and dropping them lets you focus on the other stuff?
re: goroutines
the official go runtime spawns goroutines during program startup, which makes the usage of M:N goruntine mandatory, and they have to call lockOSThread()[1] before initializing packages for certain applications (mostly GUI application).
We like the design of goroutines (especially the idea of a `g` register), but `pcz` currently doesn't have goroutine support, and we are making it possible to spawn goroutines with custom allocator (with or without gc) and scheduler attached, so you can chose 1:1, M:N model for goroutines on your own (as decided by the scheduler attached).
you can find more details in the project ROADMAP.md[2]
[1]: https://github.com/golang/go/blob/352c8835e7609ad72872b5a63b... [2]: https://github.com/primecitizens/pcz/blob/master/ROADMAP.md
Neither, though the final result can be similar, but at project level, tinygo and pcz has very different approaches to achieve the final result:
- tinygo chose the hard path to write a llvm backed toolchain with some custom behavior that compiles Go code (using official std) to llvm targets.
- pcz chose the easy path to write a stdlib from scratch that compiles to desired targets using the official Go toolchain.
One major benefit of pcz's approach is you can import packages from the pcz std module like you do with any other Go package, the development experience can remain unchanged.
Zig is much more complex than go, I’m sure there are a lot of people who don’t want to put the time in to learn it.
- better js/wasm support
- "platform native sdk" (I don't know what this is)
- cross platform GUI
- Better FFI support
- Kernel support
While all these goals seem cool on their own, they also seem completely unrelated. It makes it a bit hard to understand what this project actually is.The project is to build a stdlib, and by its nature is to be used by developers to build applications just like the official Go std.
The feature of generating go packages from C in `ffigen` still needs significant work to be done (mostly dealing with C calling conventions on different platforms), and the generated go package only works with dynamic libraries (as it uses the pragma `go:cgo_import_dynamic`).
I wonder how the authors plan to accomplish a similar thing while remaining fully FFI-compatible.
Precondition: in Go, each goroutine has its own `g` structure (like TCB, but for controlling goroutines) and its address is stored in the `g` register, which is reserved by the go compiler, active goroutines can call a function runtime.getg() to obtain the value of the `g` register.
In the official runtime, the `g` structure is a concrete type and the scheduler is implemented globally in the runtime package.
But we have made the `g` structure customizable (still requires a fixed header expected by the function prologue & epilogue and linker), so custom g implementations may contain a link to a custom scheduler, and the scheduler can decide how to handle an active goroutine.
> "goroutines" that automatically suspend themselves
The automatic suspend and resume happens by
- calling `runtime.entersyscall` from a running goroutine - and calling `runtime.exitsyscall` from an finished systemstack
all these operations can interact with the custom `g`, thus can interact with the custom scheduler.
And Yes, we are defining brand new interfaces as well, in order to improve usability and fix inconsistent user experience.
For your specific example `os.WriteFile` (names mentioned below may subject to change):
The api won't make it inside the std, because the local filesystem will be implemented as a `fs.FS` (concrete type `*sysfs.FS`), so you can have multiple `sysfs.FS` instances each at its own working directory, and the `os.WriteFile` will be replaced with `fs.WriteFile(fsys fs.FS, path *fs.PathBuf, wctx *io.WriteContext) io.Status`, where `fs.PathBuf` is our solution to handle all kinds of path styles (windows, unix, cygwin, utf8, utf16, end-null) and operations (join, base, dir).
You're taking away what makes Go Go - you're now building something that turns Go into Pascal, perhaps unwittingly? Curly braces are what's left, basically.
For variables you are sure living on the stack, you can use `mark.NoEscape(&v)` to obtain its pointer (a hack to cheat escape analysis found in the official runtime & reflect package), and the variable will be freed on function return.
For variables you want to control lifecycle, call `alloc.New` or `alloc.Make` with a explicit allocator, which can be an allocator whose storage is on the previous call stack (and there is a default goroutine local allocator thread.G().G().DefaultAlloc()) to allocate a non-stack-local variable, and call `alloc.Free` with the same allocator to free that variable.
The use of `make` is discouraged as go compiler does mid-stack inlining and escape analysis, so the return value of a `make` can be either on stack or on heap, thus to free it, the allocator needs to compare the address to thread.G().Stack.Lo and thread.G().Stack.Hi.
In fact, I have worked with a number of codebases where I was the one who deployed that, because the app process could already do the relevant level of restart without dropping a request, and the leak was slow enough and hard enough to find that I couldn't justify keeping going until I -did- find it.
This continues to annoy me, but having made sure the leakiness wasn't able to -increase- over time without us spotting it immediately, I'm still convinced it was the business-correct decision.
(but, still, sulk)
We did find and fix the leak the following week once the event completed and traffic dropped to normal levels. But sometimes, you got to do what you got to do to keep the app running.
About GC, I would say: if you implement C++'s RAII mechanism to replace garbage collection, then I believe this project will have a bright future.
My final question is the following: how `pcz` compares to V language, from a syntax's perspective [1]?
The GOPROXY protocol is quite small to allow to implement such a relay: https://go.dev/ref/mod#goproxy-protocol
Permission denied.
Please contact the administrator.
https://cs.opensource.google/go/go/+/go1.21.1:src/strings/cl...
I don't know what causes this, but is seems to be related to my Firefox, because in Chromium I can see that page. I just wonder, what on earth makes it so hard to serve a documentation in a way that is available to all browsers.
Why can't they use the github.com/golang/go link instead? (no pun, genuinely wondering)
2. GitHub.com is Microsoft infrastructure. cs.opensource.google is Google infrastructure.
I still wonder why there is both cs.opensource.google and go.googlesource.com.
Thanks so much for your time, and for sharing the issue.
We don't like it as well, just do not enable it :^
re: RAII
It is not possible to add RAII support without updating the compiler to call specific methods automatically, so currently it is not an option (as we are using unmodified official toolchain).
But the `g` register defined in Go is of great value, and we are making use of it to provide custom goroutine support, which means you can have custom allocator and scheduler for specific goroutines, so that you can have some of them with GC enabled and others not.
re: compare to V
pcz is a stdlib (plus a cli tool to build), not a new language, you still write Go code but in a slightly different style.
And in brief introduction, the `g` register is a non-scratch register, and is preserved by the go compiler, it stores the poitner to current goroutine (type `g` in the official runtime, a structure serves the similar purpose of TCB), and since all general purpose registers are thread local, the goroutine may enjoy some thread-local features without any thread-local requirements to the running environment.
[1]: https://github.com/golang/go/blob/master/src/cmd/compile/abi...
Also go has a -lot- fewer sharp edges than C.
It's an (extremely) ambitious goal, and skepticism is warranted, but I think their desire for such a thing to exist does actually make sense.
TL;DR it keeps having advantages over C even if you takeaway GC and goroutines.
If you’re dropping GC, then RAII is extremely useful (which Go doesn’t have). If you’re dropping runtime concurrency, Go’s (subjectively) strong multitasking, cancelation, timeouts go away. And finally, if you’re dropping std, which is perhaps the strongest suit of Go, then what are the remaining strengths of Go vs Rust? Tooling? Compile time speed?
TLDR a simple subset of Rust (enums, pattern matching, RAII, etc) sounds appealing, but a simple subset of Go seems quite… limiting. That said, I’m not an embedded programmer.
Making GC/goroutine optional & customizable requires building a std works with no GC/goroutine.
> dropping std
relax, this is a new std, let's spare the baby some hope?
Isn’t there a big difference between customizable, ie changing the runtime backend, vs NO runtime where goroutines and GC don’t work at all? In the latter case, you’d have to write very different, restricted Go code, no? And you’d even have to add some new features for manual memory reclaim?
> relax, this is a new std, let's spare the baby some hope?
Yeah, depends on what hat you put on. I wrote it wearing the “when would someone use something like this?”-hat. I don’t claim to know one way or the other.
Right.
You've picked a goal that require you to do some hard things to make that goal even possible.
OTOH even if you never reach the -final- goal, making any of those hard things work would be an achievement.
The only way to find out is to try. So: Good luck!