Skip to content
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

Merged
merged 11 commits into from
Mar 5, 2025

Conversation

thehowl
Copy link
Member

@thehowl thehowl commented Mar 3, 2025

  • only show the types in the parameters and results for functions, matching go's reflect.Type.String
  • match field list to go's

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.

@thehowl thehowl self-assigned this Mar 3, 2025
@github-actions github-actions bot added 📦 🤖 gnovm Issues or PRs gnovm related 📦 ⛰️ gno.land Issues or PRs gno.land package related labels Mar 3, 2025
@Gno2D2
Copy link
Collaborator

Gno2D2 commented Mar 3, 2025

🛠 PR Checks Summary

All Automated Checks passed. ✅

Manual Checks (for Reviewers):
  • IGNORE the bot requirements for this PR (force green CI check)
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:
  1. Fix any issues flagged by automated checks.
  2. Follow the Contributor Checklist to ensure your PR is ready for review.
    • Add new tests, or document why they are unnecessary.
    • Provide clear examples/screenshots, if necessary.
    • Update documentation, if required.
    • Ensure no breaking changes, or include BREAKING CHANGE notes.
    • Link related issues/PRs, where applicable.
☑️ Reviewer Actions:
  1. Complete manual checks for the PR, including the guidelines and additional checks if applicable.
📚 Resources:
Debug
Automated Checks
Maintainers must be able to edit this pull request (more info)

If

🟢 Condition met
└── 🟢 And
    ├── 🟢 The base branch matches this pattern: ^master$
    └── 🟢 The pull request was created from a fork (head branch repo: thehowl/gno)

Then

🟢 Requirement satisfied
└── 🟢 Maintainer can modify this pull request

Manual Checks
**IGNORE** the bot requirements for this PR (force green CI check)

If

🟢 Condition met
└── 🟢 On every pull request

Can be checked by

  • Any user with comment edit permission

Copy link

codecov bot commented Mar 3, 2025

Codecov Report

Attention: Patch coverage is 92.30769% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
gnovm/pkg/gnolang/values_string.go 0.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Contributor

@mvertes mvertes left a 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).

@thehowl
Copy link
Member Author

thehowl commented Mar 4, 2025

@mvertes I noticed that Go error messages don't actually put a space between the interface / struct and the respective bracket, in general, so I removed the bracket to revert to the previous state more generally.

I think having error messages more consistent is more important, so I reverted it back.

Copy link
Contributor

@ltzmaxwell ltzmaxwell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LTGM.

@ltzmaxwell ltzmaxwell merged commit ac16580 into gnolang:master Mar 5, 2025
68 checks passed
thehowl added a commit that referenced this pull request Mar 7, 2025
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`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 ⛰️ gno.land Issues or PRs gno.land package related 📦 🤖 gnovm Issues or PRs gnovm related
Projects
Development

Successfully merging this pull request may close these issues.

4 participants