-
Notifications
You must be signed in to change notification settings - Fork 398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(gnovm): improve interface/func/struct type String
methods
#3875
feat(gnovm): improve interface/func/struct type String
methods
#3875
Conversation
🛠 PR Checks SummaryAll Automated Checks passed. ✅ Manual Checks (for Reviewers):
Read More🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers. ✅ Automated Checks (for Contributors):🟢 Maintainers must be able to edit this pull request (more info) ☑️ Contributor Actions:
☑️ Reviewer Actions:
📚 Resources:Debug
|
Codecov ReportAttention: Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Not blocking: I would prefer to comply with the go fmt
rules when printing struct
or interface
on single line (see inline comments).
@mvertes I noticed that Go error messages don't actually put a space between the I think having error messages more consistent is more important, so I reverted it back. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LTGM.
This PR removes `fmt` from being implemented using NativeValue / NativeType, and implements a mostly pure-Gno implementation which uses an initial, rudimentary implementation of Gno reflection for `fmt`. This PR is ready for review, but some of its related work has been broken out in separate PR to aid reviewing and create atomic PRs. - Blocks #3677 - Relates to #1361 - Depends on #3861 - Depends on #3862 - Depends on #3875 ## Summary of changes ### addition of `gnovm/tests/stdlibs/fmt` The main addition is of this set of files, which comprises the bulk of the added lines of this PR. Most of this is a copy of Go's `fmt`. Changes are mostly in `errors.gno` and `format.gno` - the other files are left mostly intact. At the end of `print.gno`, there is an added section containing a set of native functions which form the "reflection" needed to implement the `fmt` package in a manner that is similar to Go's. The implementation is not meant to be a public API and is meant to serve initially only for usage by `fmt`; we can use this as sketch to then implement a proper `reflect` package. Attention in reviewing should mostly go to this `print.gno` and its `print.go` counterpart, especially for any missed cases or potential bugs. ### addition of `gnovm/tests/stdlibs/os` Complementary to the above, to avoid some problems that were arising due to the handling of os.Stdin, Stdout and Stderr, I also removed the NativeValue / NativeType in `os` and replaced them with a native binding alternative. To avoid having both an `Output` and `ErrorOutput` on the machine, this package supports an additional method on the `Machine.Output`, `StderrWrite`, which is implemented by writers who wish to differentiate between the two. ### other - `gnovm/pkg/test` - added support for `StderrWrite` in its writers - removed native values for `os` and `fmt` - combine `stdin`, `stdout`, `stderr` into a single `output` parameter in the related functions. - `gnovm/pkg/gnolang` - support testing `gnovm/tests/stdlibs`, by only testing stdlibs that exist there and not in the official stdlibs. - `gnovm/cmd/gno` - fix tests which needed the `fmt` package. - `gnovm/tests/files` - most changed tests are result of the improved functionality of the `fmt` package, allowing for instance to show declared types correctly. - `gnovm/stdlibs/bufio` - due to the removal of `os.Stdin`, this example had to be changed. - `misc/genstd` - added a flag `-skip-init-order` when creating it could cause problems, like the testing stdlibs; fixed a bug when using `TypedValue`.
extracted from #3847.
This blocks #3847 because for simplicity, we use the type String() methods for syntaxes like
%#v
and%T
which show the type. Making these match Go's avoids us modifying some types, and I think it's a nice addition in making us more consistent with Go.