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

Revert adding generic V: Ordinal parameter to succ, pred, inc, dec #22328

Merged
merged 3 commits into from
Aug 5, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions lib/std/private/digitsutils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ proc utoa2Digits*(buf: var openArray[char]; pos: int; digits: uint32) {.inline.}
buf[pos+1] = digits100[2 * digits + 1]
#copyMem(buf, unsafeAddr(digits100[2 * digits]), 2 * sizeof((char)))

proc trailingZeros2Digits*(digits: uint32): int32 {.inline.} =
return trailingZeros100[digits.int8]
proc trailingZeros2Digits*(digits: uint32): int {.inline.} =
trailingZeros100[digits]

when defined(js):
proc numToString(a: SomeInteger): cstring {.importjs: "((#) + \"\")".}
Expand Down
10 changes: 5 additions & 5 deletions lib/std/private/dragonbox.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ when false:
proc memset(x: cstring; ch: char; L: int) {.importc, nodecl.}
proc memmove(a, b: cstring; L: int) {.importc, nodecl.}

proc utoa8DigitsSkipTrailingZeros*(buf: var openArray[char]; pos: int; digits: uint32): int32 {.inline.} =
proc utoa8DigitsSkipTrailingZeros*(buf: var openArray[char]; pos: int; digits: uint32): int {.inline.} =
dragonbox_Assert(digits >= 1)
dragonbox_Assert(digits <= 99999999'u32)
let q: uint32 = digits div 10000
Expand All @@ -1070,12 +1070,12 @@ proc utoa8DigitsSkipTrailingZeros*(buf: var openArray[char]; pos: int; digits: u
utoa2Digits(buf, pos + 6, rL)
return trailingZeros2Digits(if rL == 0: rH else: rL) + (if rL == 0: 2 else: 0)

proc printDecimalDigitsBackwards*(buf: var openArray[char]; pos: int; output64: uint64): int32 {.inline.} =
proc printDecimalDigitsBackwards*(buf: var openArray[char]; pos: int; output64: uint64): int {.inline.} =
var pos = pos
var output64 = output64
var tz: int32 = 0
var tz = 0
## number of trailing zeros removed.
var nd: int32 = 0
var nd = 0
## number of decimal digits processed.
## At most 17 digits remaining
if output64 >= 100000000'u64:
Expand Down Expand Up @@ -1220,7 +1220,7 @@ proc formatDigits*[T: Ordinal](buffer: var openArray[char]; pos: T; digits: uint
## dE+123 or d.igitsE+123
decimalDigitsPosition = 1
var digitsEnd = pos + int(decimalDigitsPosition + numDigits)
let tz: int32 = printDecimalDigitsBackwards(buffer, digitsEnd, digits)
let tz = printDecimalDigitsBackwards(buffer, digitsEnd, digits)
dec(digitsEnd, tz)
dec(numDigits, tz)
## decimal_exponent += tz; // => decimal_point unchanged.
Expand Down
8 changes: 4 additions & 4 deletions lib/std/private/schubfach.nim
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,12 @@ proc toDecimal32(ieeeSignificand: uint32; ieeeExponent: uint32): FloatingDecimal
## ToChars
## ==================================================================================================

proc printDecimalDigitsBackwards[T: Ordinal](buf: var openArray[char]; pos: T; output: uint32): int32 {.inline.} =
proc printDecimalDigitsBackwards[T: Ordinal](buf: var openArray[char]; pos: T; output: uint32): int {.inline.} =
var output = output
var pos = pos
var tz: int32 = 0
var tz = 0
## number of trailing zeros removed.
var nd: int32 = 0
var nd = 0
## number of decimal digits processed.
## At most 9 digits remaining
if output >= 10000:
Expand Down Expand Up @@ -355,7 +355,7 @@ proc formatDigits[T: Ordinal](buffer: var openArray[char]; pos: T; digits: uint3
## dE+123 or d.igitsE+123
decimalDigitsPosition = 1
var digitsEnd = pos + decimalDigitsPosition + numDigits
let tz: int32 = printDecimalDigitsBackwards(buffer, digitsEnd, digits)
let tz = printDecimalDigitsBackwards(buffer, digitsEnd, digits)
dec(digitsEnd, tz)
dec(numDigits, tz)
## decimal_exponent += tz; // => decimal_point unchanged.
Expand Down
10 changes: 5 additions & 5 deletions lib/system/arithmetics.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
proc succ*[T, V: Ordinal](x: T, y: V = 1): T {.magic: "Succ", noSideEffect.} =
proc succ*[T: Ordinal](x: T, y: int = 1): T {.magic: "Succ", noSideEffect.} =
## Returns the `y`-th successor (default: 1) of the value `x`.
##
## If such a value does not exist, `OverflowDefect` is raised
Expand All @@ -7,7 +7,7 @@ proc succ*[T, V: Ordinal](x: T, y: V = 1): T {.magic: "Succ", noSideEffect.} =
assert succ(5) == 6
assert succ(5, 3) == 8

proc pred*[T, V: Ordinal](x: T, y: V = 1): T {.magic: "Pred", noSideEffect.} =
proc pred*[T: Ordinal](x: T, y: int = 1): T {.magic: "Pred", noSideEffect.} =
## Returns the `y`-th predecessor (default: 1) of the value `x`.
##
## If such a value does not exist, `OverflowDefect` is raised
Expand All @@ -16,7 +16,7 @@ proc pred*[T, V: Ordinal](x: T, y: V = 1): T {.magic: "Pred", noSideEffect.} =
assert pred(5) == 4
assert pred(5, 3) == 2

proc inc*[T, V: Ordinal](x: var T, y: V = 1) {.magic: "Inc", noSideEffect.} =
proc inc*[T: Ordinal](x: var T, y: int = 1) {.magic: "Inc", noSideEffect.} =
## Increments the ordinal `x` by `y`.
##
## If such a value does not exist, `OverflowDefect` is raised or a compile
Expand All @@ -28,7 +28,7 @@ proc inc*[T, V: Ordinal](x: var T, y: V = 1) {.magic: "Inc", noSideEffect.} =
inc(i, 3)
assert i == 6

proc dec*[T, V: Ordinal](x: var T, y: V = 1) {.magic: "Dec", noSideEffect.} =
proc dec*[T: Ordinal](x: var T, y: int = 1) {.magic: "Dec", noSideEffect.} =
## Decrements the ordinal `x` by `y`.
##
## If such a value does not exist, `OverflowDefect` is raised or a compile
Expand Down Expand Up @@ -93,7 +93,7 @@ proc `*`*(x, y: int16): int16 {.magic: "MulI", noSideEffect.}
proc `*`*(x, y: int32): int32 {.magic: "MulI", noSideEffect.}
proc `*`*(x, y: int64): int64 {.magic: "MulI", noSideEffect.}

proc `div`*(x, y: int): int {.magic: "DivI", noSideEffect.} =
proc `div`*(x, y: int): int {.magic: "DivI", noSideEffect.} =
## Computes the integer division.
##
## This is roughly the same as `math.trunc(x/y).int`.
Expand Down
2 changes: 1 addition & 1 deletion tests/varres/tprevent_forloopvar_mutations.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ discard """
errormsg: "type mismatch: got <int>"
nimout: '''tprevent_forloopvar_mutations.nim(16, 3) Error: type mismatch: got <int>
but expected one of:
proc inc[T, V: Ordinal](x: var T; y: V = 1)
proc inc[T: Ordinal](x: var T; y: int = 1)
first type mismatch at position: 1
required type for x: var T: Ordinal
but expression 'i' is immutable, not 'var'
Expand Down
Loading