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

TOML: Improve type-stability of BigInt/UInt support #53955

Merged
merged 2 commits into from
Apr 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions base/toml_parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ function parse_number_or_date_start(l::Parser)
ate, contains_underscore = @try accept_batch_underscore(l, isdigit, readed_zero)
read_underscore |= contains_underscore
if (read_digit || ate) && ok_end_value(peek(l))
return parse_int(l, contains_underscore)
return parse_integer(l, contains_underscore)
end
# Done with integers here

Expand Down Expand Up @@ -904,7 +904,18 @@ function parse_float(l::Parser, contains_underscore)::Err{Float64}
return v
end

for (name, T1, T2, n1, n2) in (("int", Int64, Int128, 17, 33),
function parse_int(l::Parser, contains_underscore, base=nothing)::Err{Int64}
s = take_string_or_substring(l, contains_underscore)
v = try
Base.parse(Int64, s; base=base)
catch e
e isa Base.OverflowError && return(ParserError(ErrOverflowError))
error("internal parser error: did not correctly discredit $(repr(s)) as an int")
end
return v
end

for (name, T1, T2, n1, n2) in (("integer", Int64, Int128, 17, 33),
("hex", UInt64, UInt128, 18, 34),
("oct", UInt64, UInt128, 24, 45),
("bin", UInt64, UInt128, 66, 130),
Expand Down Expand Up @@ -1103,7 +1114,7 @@ function _parse_local_time(l::Parser, skip_hour=false)::Err{NTuple{4, Int64}}
end
# DateTime in base only manages 3 significant digits in fractional
# second
fractional_second = parse_int(l, false)
fractional_second = parse_int(l, false)::Int64
# Truncate off the rest eventual digits
accept_batch(l, isdigit)
end
Expand Down