[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-janitors] #1619: Specialization ignores fixnum mode, leadin
From: |
Chicken Trac |
Subject: |
Re: [Chicken-janitors] #1619: Specialization ignores fixnum mode, leading to suboptimal code |
Date: |
Wed, 29 May 2019 16:10:42 -0000 |
#1619: Specialization ignores fixnum mode, leading to suboptimal code
---------------------------------+-------------------
Reporter: sjamaan | Owner:
Type: defect | Status: new
Priority: minor | Milestone: 5.2
Component: compiler | Version: 5.0.0
Resolution: | Keywords:
Estimated difficulty: |
---------------------------------+-------------------
Comment (by sjamaan):
We could maintain a second types.db file that gets used in fixnum mode,
but keeping two types.db files in sync is hard. Even if the second one
just contains overrides for fixnum mode. Ideally, we'd have something
automatic. Because AFAIK we can just assume that all numeric arguments are
fixnums and all returned values are fixnums, so we could skip any rewrite
that involves any other numeric types, either in the arguments or in the
results. Your example would then automatically "fall out of" the current
types.db:
{{{
(scheme#+ (#(procedure #:clean #:enforce #:foldable) scheme#+ (#!rest
number) number)
(() (fixnum) '0) ;; kept
((fixnum) (fixnum) #(1)) ;; kept
((float) (float) #(1)) ;; dropped: float is not supported
((integer) (integer) #(1)) ;; dropped: "integer" includes
bignum
((ratnum) (ratnum) #(1)) ;; dropped: ratnum is not supported
((cplxnum) (cplxnum) #(1)) ;; dropped: cplxnum is not supported
((number) (number) #(1)) ;; dropped: number includes other
things than just fixnum
((float fixnum) (float) ;; dropped: float
(##core#inline_allocate
("C_a_i_flonum_plus" 4)
#(1)
(##core#inline_allocate ("C_a_i_fix_to_flo" 4) #(2))))
((fixnum float) ;; dropped: float
(float)
(##core#inline_allocate
("C_a_i_flonum_plus" 4)
(##core#inline_allocate ("C_a_i_fix_to_flo" 4) #(1))
#(2)))
((float float) (float) ;; dropped: float
(##core#inline_allocate ("C_a_i_flonum_plus" 4) #(1) #(2)))
((fixnum fixnum) (integer) ;; dropped (because return type is
integer)
(##core#inline_allocate ("C_a_i_fixnum_plus" 5) #(1) #(2)))
((integer integer) (integer);; dropped: bignum
(##core#inline_allocate ("C_s_a_u_i_integer_plus" 5) #(1)
#(2)))
((* *) (number) ;; dropped: anything else
(##core#inline_allocate ("C_s_a_i_plus" 29) #(1) #(2))))
}}}
We could even add warnings when calling something that returns something
that doesn't include fixnum, like "exact->inexact" (note: what
'''should''' happen when doing that?). But that's maybe overkill.
--
Ticket URL: <https://bugs.call-cc.org/ticket/1619#comment:2>
CHICKEN Scheme <https://www.call-cc.org/>
CHICKEN Scheme is a compiler for the Scheme programming language.