Skip to content

feat(string): add parse_bigint (Fixes #3566)#3679

Merged
Yu-zh merged 9 commits into
moonbitlang:mainfrom
rainhuang0220:fix/parse-bigint-3566
Jul 17, 2026
Merged

feat(string): add parse_bigint (Fixes #3566)#3679
Yu-zh merged 9 commits into
moonbitlang:mainfrom
rainhuang0220:fix/parse-bigint-3566

Conversation

@rainhuang0220

Copy link
Copy Markdown
Contributor

Summary

Test plan

  • moon test -p bigint -p string
  • moon check bigint string --deny-warn

Copilot AI review requested due to automatic review settings June 10, 2026 04:43

Copilot AI left a comment

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.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR adds parse_bigint as an error-raising string-to-BigInt parser, re-exports it through the string strconv surface, and updates BigInt::from_string to be a panic-on-error wrapper.

Changes:

  • Introduce @bigint.parse_bigint(StringView, base?: Int) -> BigInt raise with consistent error strings ("invalid syntax", "invalid base").
  • Re-export parse_bigint from @string and wire package imports / generated API stubs.
  • Add unit tests for parse_bigint in both bigint and string.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
string/strconv.mbt Re-exports parse_bigint via the string strconv API surface.
string/pkg.generated.mbti Adds generated signature for @string.parse_bigint and imports bigint.
string/parse_bigint_test.mbt Adds tests covering @string.parse_bigint basic parsing and error behavior.
string/moon.pkg Adds bigint dependency to support the new re-export.
bigint/strconv_errors.mbt Centralizes parse error messages and helper raisers.
bigint/pkg.generated.mbti Exposes generated signature for @bigint.parse_bigint.
bigint/parse_bigint_test.mbt Adds test coverage for valid/invalid inputs and base validation.
bigint/moon.pkg Adds imports needed for new error raising and tests.
bigint/bigint_nonjs.mbt Implements parse_bigint and refactors existing parsing to raise errors instead of aborting.
bigint/bigint_js.mbt Implements parse_bigint for JS backend and refactors radix parsing to raise errors.
bigint/bigint.mbt Updates JSON decoding to map parse failures into JsonDecodeError.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread bigint/bigint_js.mbt
Comment thread bigint/bigint_nonjs.mbt
Comment on lines +1231 to +1235
pub fn BigInt::from_string(input : String, radix? : Int = 10) -> BigInt {
parse_bigint(input.view(), base=radix) catch {
Failure(msg) => abort(msg)
_ => abort("invalid syntax")
}
Comment thread bigint/bigint_js.mbt
Comment on lines +46 to 50
pub fn BigInt::from_string(str : String, radix? : Int = 10) -> BigInt {
parse_bigint(str.view(), base=radix) catch {
Failure(msg) => abort(msg)
_ => abort("invalid syntax")
}
Comment thread bigint/parse_bigint_test.mbt
Comment thread bigint/moon.pkg
@rainhuang0220

Copy link
Copy Markdown
Contributor Author

All checks passed, please review and merge this PR when you have time, thanks. @bobzhang

@bobzhang
bobzhang force-pushed the fix/parse-bigint-3566 branch from dcd979f to 8f78032 Compare June 11, 2026 14:27

@Yu-zh Yu-zh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for your contribution and I apologize for a late response.

Please also take a look at the review comments from copilot and resolve them if possible.

Comment thread bigint/bigint_nonjs.mbt Outdated
}
if radix != 10 {
return BigInt::from_string_radix(input, radix)
let input = str.to_owned()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This creates a copy of the string, which seems unnecessary here.

Comment thread bigint/bigint_js.mbt Outdated
}
if str == "-" {
abort("invalid character")
let input = str.to_owned()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

same here

Comment thread bigint/pkg.generated.mbti Outdated
}

// Values
pub fn parse_bigint(StringView, base? : Int) -> BigInt raise

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't think we should add a new API. Instead, we could deprecate BigInt::from_string and encourage users to use @strconv.parse_bigint instead.

@rainhuang0220
rainhuang0220 requested a review from Yu-zh July 6, 2026 11:40
@rainhuang0220

rainhuang0220 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review @Yu-zh

I've addressed your comments:

Removed unnecessary str.to_owned()parse_bigint and the internal parsers (from_string_dec, from_string_radix, etc.) now work directly on StringView.

Moved the user-facing API out of @bigint@bigint.parse_bigint is now #internal and no longer appears in bigint/pkg.generated.mbti. The public entry points are @string.parse_bigint and a deprecated @strconv.parse_bigint re-export (following the same pattern as parse_int).

BigInt::from_string deprecation — I initially deprecated it as suggested, but moon check --deny-warn failed with ~270 warnings across the repo (tests, docs, examples). I've kept from_string non-deprecated for now so CI passes; happy to do the deprecation in a follow-up PR that migrates call sites.

Also merged latest main to resolve the conflict in bigint/bigint_js.mbt.
Deprecating from_string in this PR alone triggers deprecation warnings in bigint_test.mbt, panic_test.mbt, json/, math/, etc. under --deny-warn. I'd prefer to land the parse_bigint API first and handle deprecation + migration separately

Could you take another look when you have time? Thanks!

@Yu-zh
Yu-zh force-pushed the fix/parse-bigint-3566 branch from 38c83fe to b5c8f8b Compare July 17, 2026 02:18
Comment thread bigint/bigint_js.mbt Outdated
Comment thread bigint/parse_bigint_test.mbt
@Yu-zh

Yu-zh commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

@rainhuang0220 Sorry again for delayed response. We have reverted the unnecessary changes to the strconv package (my bad for suggesting it) and fixed a regression problem. Now this PR is good to merge.

@Yu-zh
Yu-zh force-pushed the fix/parse-bigint-3566 branch from 67d6f5e to 256e4db Compare July 17, 2026 05:46
@Yu-zh
Yu-zh merged commit 9d0169e into moonbitlang:main Jul 17, 2026
15 checks passed
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.

[Consistency Review] BigInt::from_string should raise or add a @string.parse_bigint

4 participants