Repository navigation
main: add tinygo fix - #5992
main: add tinygo fix#5992
Conversation
|
This is mostly working now. It has some usability issues compared to regular More than modernising existing tinygo code, it unlocks the |
|
example one ./build/tinygo fix -target pico -diff -rangeint ./src/internal/reflectlite-for i := uintptr(0); i < size; i++ {
+for range size {example two ./build/tinygo fix -target pico -diff -rangeint ./src/machine/usb/msc-for i := 0; i < length; i++ {
+for i := range length {example three ./build/tinygo fix -C ~/devel/drivers -target pico -diff -rangeint ./ssd1289-for i := uint8(0); i < 16; i++ {
+for i := range uint8(16) {
pin := machine.Pin(i + uint8(firstPin))
pin.Configure(machine.PinConfig{Mode: machine.PinOutput})
}example four; interface{} -> any ./build/tinygo fix -C ~/devel/drivers -target pico -diff -any ./tester- Fatalf(f string, a ...interface{})
+ Fatalf(f string, a ...any)#5966 adds TINYGOROOT=<rename-branch-sources> ./build/tinygo fix \
-C <caller-module> -target pico -inline -diff .-value, err := machine.GetRNG()
+value, err := machine.RandomUint32() |
b0b5d18 to
0f4e85c
Compare
|
The test failure is karma for fixing the tests so they actually run on windows :) |
0f4e85c to
fb7ea26
Compare
fb7ea26 to
5b0b244
Compare
|
@davecheney thanks for working on fixing fix. I checked out this PR and ran the tests locally. Here are some notes edited from an automated review:
What do you think? Thanks! |
Thanks for the feedback. I'll take another pass at this in the morning. buenas noches |
|
Thanks for the examples. I’ve addressed points 1 and 2.
tinygo fix -target pico -diff -rangeint ./src/internal/...@@ -10,7 +10,7 @@
- for i := uintptr(0); i < size; i++ {
+ for range size {
@@ -108,7 +108,7 @@
- for i := 0; i < 16; i++ {
+ for i := range 16 {
@@ -118,7 +118,7 @@The package-pattern and diff tests pass. Points 3 and 4 remain open. |
5b0b244 to
0f1232a
Compare
|
Thanks for the suggestions. I’ve addressed points 3 and 4.
tinygo fix -target pico -tests=false -diff -rangeint ./src/machine/usb/...This now produces 4 hunks across 3 files.
const MinimumGoMinorVersion = 25Both the builder’s compatibility check and the loader’s language-version setting use it. The focused tests and vet checks pass. |
0f1232a to
0adef1f
Compare
|
@deadprogram PTAL. Should be close now |
The standard go fix command cannot analyze TinyGo source packages and target-specific code. Make fix output practical for TinyGo sources and easier to review.
0adef1f to
3918697
Compare
deadprogram
left a comment
There was a problem hiding this comment.
Thanks @davecheney for the updates. Edited from an automated review.
I rebuilt at 3918697 and reran the earlier examples against the pico target.
./src/internal/...now findsinternal/reflectliteand prints its hunks. Running./internal/...from insidesrcworks too.-diffnow prints separate hunks per change, for example two inmachine_rp2040_usb.go.-tests=falselets./src/os/...run cleanly, and./src/machine/usb/...gives 4 hunks.MinimumGoMinorVersionis now used in both the builder check and the loader.
The fix, internal/diff and loader tests pass, plus the Fix tests in the main package.
One small optional idea. The diff headers use absolute paths, so git apply will not take the output directly. Paths relative to the current directory might be easier to use, but this could be a follow-up.
Looks good to me. Thanks for getting us fixed up!
-diff is probably only useful in a dry run mode, I'm not sure, and i certainly haven't used it as an actual tool to two step {tiny,}go fix. The diff code is copied from biggo, so that limitation might exist upstream. I'm happy to keep working on this and polishing it over time. btw, here's a teaser of what tinygo fix can do beyond rewriting old syntax, tinygo-org/drivers#936 |
go fix cannot load TinyGo's src packages or target-specific code because it does not know TinyGo's overlays and build tags.
Instead, tinygo fix runs the go fix analyzers through TinyGo's loader, so the same modernizations can be applied to TinyGo itself and to programs built for a TinyGo target.
/ht to @dgryski for the suggestion