Skip to content

Commit 003a1bf

Browse files
authored
repair fx-/wraparound with 0 first argument, allow one argument (#899)
The `fx-/wraparound` function was treated like R6RS `fx-` by cp0, which meant that it could reduce a 2-argument call with `0` as the first argument to a 1-argument call, even though `fx-/wraparound` was defined with only a 2-argument form. Making `fx-/wraparound` more like R6RS `fx-` seems like the path of least resistance and least likelihood of future bugs.
1 parent bf70250 commit 003a1bf

File tree

6 files changed

+32
-7
lines changed

6 files changed

+32
-7
lines changed

csug/numeric.stex

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,10 +338,11 @@ dividing \var{fixnum_1} by the product of the remaining arguments
338338

339339
%----------------------------------------------------------------------------
340340
\entryheader
341-
\formdef{fx+/wraparound}{\categoryprocedure}{(fx+/wraparound \var{fixnum} \dots)}
342-
\formdef{fx-/wraparound}{\categoryprocedure}{(fx-/wraparound \var{fixnum} \dots)}
343-
\formdef{fx*/wraparound}{\categoryprocedure}{(fx*/wraparound \var{fixnum} \dots)}
344-
\formdef{fxsll/wraparound}{\categoryprocedure}{(fxsll/wraparound \var{fixnum} \dots)}
341+
\formdef{fx+/wraparound}{\categoryprocedure}{(fx+/wraparound \var{fixnum} \var{fixnum})}
342+
\formdef{fx-/wraparound}{\categoryprocedure}{(fx-/wraparound \var{fixnum} \var{fixnum})}
343+
\formdef{fx-/wraparound}{\categoryprocedure}{(fx-/wraparound \var{fixnum})}
344+
\formdef{fx*/wraparound}{\categoryprocedure}{(fx*/wraparound \var{fixnum} \var{fixnum})}
345+
\formdef{fxsll/wraparound}{\categoryprocedure}{(fxsll/wraparound \var{fixnum} \var{fixnum})}
345346
\returns the arithmetic result, wrapping on overflow
346347
\listlibraries
347348
\endentryheader

mats/fx.ms

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,9 @@
564564
(mat fx-/wraparound
565565
(eqv? (fx-/wraparound 3 0) 3)
566566
(eqv? (fx-/wraparound 3 1) 2)
567+
(eqv? (fx-/wraparound 0 3) -3)
567568
(eqv? (fx-/wraparound -3 4) -7)
569+
(eqv? (fx-/wraparound 3) -3)
568570
(error? (fx-/wraparound '(a . b) 0))
569571
(error? (fx- (add1 (most-positive-fixnum)) 1))
570572
(error? (fx- 1 (add1 (most-positive-fixnum))))

release_notes/release_notes.stex

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ Online versions of both books can be found at
121121
The type recovery pass has improved support for \scheme{abs} with a fixnum argument
122122
and added support for \scheme{1+}, \scheme{1-}, and \scheme{-1+}.
123123

124+
\subsection{Single-argument \scheme{fx-/wraparound} (10.2.0)}
125+
126+
The \scheme{fx-/wraparound} function changed to accept a single
127+
argument, which makes it more consistent with the R6RS \scheme{fx-}
128+
function.
129+
124130
\subsection{Constrain signal delivery to the main thread (10.1.0)}
125131

126132
Signals are now always delivered to the main Scheme thread to avoid crashes when a signal
@@ -2769,6 +2775,13 @@ in fasl files does not generally make sense.
27692775
%-----------------------------------------------------------------------------
27702776
\section{Bug Fixes}\label{section:bugfixes}
27712777

2778+
\subsection{Fix \scheme{fx-/wraparound} with \scheme{0} first argument (10.2.0)}
2779+
2780+
When \scheme{fx-/wraparound} was called with \scheme{0} as its first
2781+
argument, the call could be rewritten to have a single argument, even though
2782+
\scheme{fx-/wraparound} required two arguments. As part of the repair,
2783+
\scheme{fx-/wraparound} changed to accept a single argument.
2784+
27722785
\subsection{Performance regression for \scheme{fxdiv-and-mod} at optimize-level 3 (10.2.0)}
27732786

27742787
At optimize-level 3, the source optimizer (cp0) could replace calls to

s/cpprim.ss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,6 +1796,7 @@
17961796
[(e) (%inline - (immediate 0) ,e)]
17971797
[(e1 e2) (%inline - ,e1 ,e2)])
17981798
(define-inline 3 fx-/wraparound
1799+
[(e) (%inline - (immediate 0) ,e)]
17991800
[(e1 e2) (%inline - ,e1 ,e2)])
18001801
(define-inline 3 fx1-
18011802
[(e) (%inline - ,e (immediate ,(fix 1)))])
@@ -1840,6 +1841,11 @@
18401841
[(e) (go src sexpr `(immediate ,(fix 0)) e)]
18411842
[(e1 e2) (go src sexpr e1 e2)])
18421843
(define-inline 2 fx-/wraparound
1844+
[(e)
1845+
(bind #t (e)
1846+
`(if ,(build-fixnums? (list e))
1847+
,(%inline - (immediate 0) ,e)
1848+
,(build-libcall #t src sexpr fx-/wraparound `(immediate 0) e)))]
18431849
[(e1 e2)
18441850
(bind #t (e1 e2)
18451851
`(if ,(build-fixnums? (list e1 e2))

s/mathprims.ss

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,11 @@
353353
(#2%fx+/wraparound x1 x2)))
354354

355355
(set-who! fx-/wraparound
356-
(lambda (x1 x2)
357-
(#2%fx-/wraparound x1 x2)))
356+
(case-lambda
357+
[(x)
358+
(#2%fx-/wraparound x)]
359+
[(x1 x2)
360+
(#2%fx-/wraparound x1 x2)]))
358361

359362
(set! fx1-
360363
(lambda (x)

s/primdata.ss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1389,7 +1389,7 @@
13891389
(fx+ [sig [(fixnum ...) -> (fixnum)]] [flags arith-op partial-folder]) ; not restricted to 2 arguments
13901390
(fx+/wraparound [sig [(fixnum fixnum) -> (fixnum)]] [flags arith-op partial-folder safeongoodargs])
13911391
(fx- [sig [(fixnum fixnum ...) -> (fixnum)]] [flags arith-op partial-folder]) ; not restricted to 1 or 2 arguments
1392-
(fx-/wraparound [sig [(fixnum fixnum) -> (fixnum)]] [flags arith-op partial-folder safeongoodargs])
1392+
(fx-/wraparound [sig [(fixnum) -> (fixnum)] [(fixnum fixnum) -> (fixnum)]] [flags arith-op partial-folder safeongoodargs])
13931393
(fx/ [sig [(fixnum fixnum ...) -> (fixnum)]] [flags arith-op partial-folder]) ; not restricted to 1 or 2 arguments
13941394
(fx1+ [sig [(fixnum) -> (fixnum)]] [flags arith-op cp02])
13951395
(fx1- [sig [(fixnum) -> (fixnum)]] [flags arith-op cp02])

0 commit comments

Comments
 (0)