racket / racket/typed-racket

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

Open
#76 6 comments 0 reactions 1 assignee View on GitHub

@stamourv is already working on this.

Since Apr 1, 2015.

enhancement optimizer
Dominant language
Racket
Stars
575
Forks
106
Avg merge
2h 1m
Merged PRs (30d)
2

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.