Skip to content

optimizer misses flonum opportunities in (apply + ...) and foldl #76

Open
@mbutterick

Description

@mbutterick

The optimizer will use unsafe-fl+ for direct uses of + with flonums. Very nice. Even better, it even works variadically (which unsafe-fl+ ordinarily does not).

But when you change to (apply + ...) or foldl, you lose the optimization:

#lang typed/racket
(require math)

(+ 1.0 2.0) ; optimized
(+ 1.0 2.0 3.0) ; optimized
(apply + '(1.0 2.0 3.0)) ; not optimized
(foldl + 0.0 '(1.0 2.0 3.0)) ; not optimized
(foldl fl+ 0.0 '(1.0 2.0 3.0)) ; not optimized

The lower three lines could be better expanded to either

(unsafe-fl+ (unsafe-fl+ 1.0 2.0) 3.0)

or

(foldl unsafe-fl+ 0.0 '(1.0 2.0 3.0))

Though I think the apply form is the worthiest one to optimize, because it’s the more common idiom, and would subsume the foldl versions.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions