Skip to content

Propagate functions as constants #1444

Open
@YarinHeffes

Description

@YarinHeffes

In the following block, > gets specialized as single-float->, but then, single-float-> does not get inlined,

(monomorphize)
(define (test)
  (let ((arr (as (array:LispArray Single-Float) (make-list 4f0 3f0 2f0))))
    (loops:besttimes (i 3 >) (array:aref arr i))))

However, it does inline when > is replaced by (fn (x y) (> x y)).

(monomorphize)
(define (test)
  (let ((arr (as (array:LispArray Single-Float) (make-list 4f0 3f0 2f0))))
    (loops:besttimes (i 3 (fn (x y) (> x y))) (array:aref arr i))))

besttimes is defined like this:

(inline)
(declare ...)
(define (%besttimes n better? func)
  ... (if (better? candidate best) ...) ...)

I understand that this happens because we only inline functions when they are fully applied.

However, %besttimes is inlined, so constant propagation should allow single-float-> to be inlined as well.

So, the request is for code like this:

(let ((f >))
  (f x y))

to simplify to

(> x y)

Metadata

Metadata

Assignees

No one assigned

    Labels

    codegenCode generation matters (Coalton -> Lisp)enhancementNew feature or requestperformance

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions