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/tests/stdlibs): add fmt #3847

Merged
merged 21 commits into from
Mar 7, 2025

Conversation

thehowl
Copy link
Member

@thehowl thehowl commented Feb 27, 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.

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.

@thehowl thehowl self-assigned this Feb 27, 2025
@github-actions github-actions bot added the 📦 🤖 gnovm Issues or PRs gnovm related label Feb 27, 2025
@Gno2D2
Copy link
Collaborator

Gno2D2 commented Feb 27, 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 Feb 27, 2025

Codecov Report

Attention: Patch coverage is 84.08163% with 39 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
gnovm/tests/stdlibs/fmt/print.go 82.14% 30 Missing and 5 partials ⚠️
misc/genstd/genstd.go 57.14% 3 Missing ⚠️
gnovm/pkg/test/test.go 95.23% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@thehowl

This comment was marked as outdated.

@github-actions github-actions bot added the 🧾 package/realm Tag used for new Realms or Packages. label Mar 2, 2025
@Gno2D2 Gno2D2 requested review from a team March 2, 2025 12:02
ltzmaxwell added a commit that referenced this pull request Mar 3, 2025
This exists in Go, and it's a pain to add it later as a global, so
making a PR to add this.

extracted from #3847.

---------

Co-authored-by: ltzmaxwell <[email protected]>
@github-actions github-actions bot added the 📦 ⛰️ gno.land Issues or PRs gno.land package related label Mar 3, 2025
@thehowl thehowl force-pushed the dev/morgan/fmt-testing-stdlib branch from cede3cb to 715d3ed Compare March 3, 2025 22:53
@thehowl thehowl marked this pull request as ready for review March 3, 2025 23:11
thehowl added a commit that referenced this pull request Mar 4, 2025
This used to return a weird panic, now it correctly panics with a nil
pointer dereference.

Extracted from #3847.

---------

Co-authored-by: ltzmaxwell <[email protected]>
wyhaines pushed a commit that referenced this pull request Mar 4, 2025
This exists in Go, and it's a pain to add it later as a global, so
making a PR to add this.

extracted from #3847.

---------

Co-authored-by: ltzmaxwell <[email protected]>
ltzmaxwell pushed a commit that referenced this pull request Mar 5, 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.
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.

After comparing with the native Go fmt, it follows the original design, and the mini reflection implemented through nativebinding is cleverly designed. LGTM.

@mvertes
Copy link
Contributor

mvertes commented Mar 7, 2025

Incidentally, I think that this PR may also solve #3687, through implementation of X_getAddr() in gnovm/tests/sdtlibs/fmt/print.go although I haven't yet verified it.

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.

LGTM

@thehowl
Copy link
Member Author

thehowl commented Mar 7, 2025

Incidentally, I think that this PR may also solve #3687, through implementation of X_getAddr() in gnovm/tests/sdtlibs/fmt/print.go although I haven't yet verified it.

That issue is still valid for println(), and the implementation of getAddr is actually non-deterministic; but it's fine because fmt can only be used off-chain.

When we move fmt on-chain (or better, when we make a proper reflect implementation), I'd like to figure out a way to make a proper deterministic getAddr implementation.

@thehowl thehowl merged commit a5e084c into gnolang:master Mar 7, 2025
79 of 80 checks passed
@thehowl thehowl deleted the dev/morgan/fmt-testing-stdlib branch March 7, 2025 14:13
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 🧾 package/realm Tag used for new Realms or Packages.
Projects
Development

Successfully merging this pull request may close these issues.

4 participants