Skip to content

refactor: make show implement one of the methods#3402

Draft
peter-jerry-ye wants to merge 5 commits intomainfrom
zihang/adjust-show
Draft

refactor: make show implement one of the methods#3402
peter-jerry-ye wants to merge 5 commits intomainfrom
zihang/adjust-show

Conversation

@peter-jerry-ye
Copy link
Copy Markdown
Collaborator

@peter-jerry-ye peter-jerry-ye commented Mar 31, 2026

We are going to change the behavior of Show so that it is purely for displaying. So there will not be special handling for String or Char any more. As a result, the output and to_string would behave the same. Thus people only need to implement one of the methods.

This PR also migrates some of the builtin types' implementations to to_string, because use output would forcefully upcast StringBuider to &Logger, which will increase code in some cases.

@peter-jerry-ye
Copy link
Copy Markdown
Collaborator Author

Note : it seems that this requires compiler fix for the display of errors

Comment thread builtin/traits.mbt
output(Self, &Logger) -> Unit
// By default `output` is implemented using `to_string`,
// but some types, such as `String` and `Char`, may override `output`,
// for different (escaped) behavior when composed into larger structures.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is no longer the case? we have two purely for efficiency?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It depends on how we are going to phase out the transition.

@coveralls
Copy link
Copy Markdown
Collaborator

Coverage Report for CI Build 3723

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Coverage decreased (-0.03%) to 94.994%

Details

  • Coverage decreased (-0.03%) from the base build.
  • Patch coverage: 15 of 15 lines across 6 files are fully covered (100%).
  • 19 coverage regressions across 5 files.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

19 previously-covered lines in 5 files lost coverage.

File Lines Losing Coverage Coverage
builtin/double_ryu_nonjs.mbt 5 97.08%
immut/array/tree.mbt 5 92.92%
immut/vector/tree.mbt 4 77.83%
encoding/ascii/decode.mbt 3 85.0%
argparse/error.mbt 2 80.95%

Coverage Stats

Coverage Status
Relevant Lines: 15382
Covered Lines: 14612
Line Coverage: 94.99%
Coverage Strength: 220706.99 hits per line

💛 - Coveralls

Comment thread error/error.mbt
Comment on lines +16 to +18
fn Error::to_string(self : Error) -> String {
@debug.to_string(self)
}
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

We are using debug.to_string to display. But this can cause major breakage for errors that have display, such as the errors in the argparse. Users might find that the program no longer prints the errors well. Though no one should depend on the error message's content.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants