cs: force inline of applicable-struct support
When the schemify pass cannot determine that a call is to a primitive procedure, it generates an `#%app` form that expands to ((extract-procedure rator) rand ...) Force `extract-procedure` to be inlined (by making it a macro), so the expansion is (let ([tmp rator]) ((if (#%procedure? tmp) tmp (slow-extract-procedure tmp)) rand ...)) which is usefully faster in the common case that `rator` turns out to be a primitive procedure.
This commit is contained in:
parent
ae1bf1b9fc
commit
9d55443e23
|
@ -177,6 +177,11 @@
|
||||||
[(_ rator rand ...)
|
[(_ rator rand ...)
|
||||||
(with-syntax ([n-args (length #'(rand ...))])
|
(with-syntax ([n-args (length #'(rand ...))])
|
||||||
#'((extract-procedure rator n-args) rand ...))])))
|
#'((extract-procedure rator n-args) rand ...))])))
|
||||||
|
(eval '(define-syntax-rule (extract-procedure f n-args)
|
||||||
|
(let ([tmp f])
|
||||||
|
(if (#%procedure? tmp)
|
||||||
|
tmp
|
||||||
|
(slow-extract-procedure tmp n-args)))))
|
||||||
(eval '(define-syntax (|#%name| stx)
|
(eval '(define-syntax (|#%name| stx)
|
||||||
(syntax-case stx ()
|
(syntax-case stx ()
|
||||||
[(_ name val) #`(let ([name val]) name)])))
|
[(_ name val) #`(let ([name val]) name)])))
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
;; can be used in a linklet:
|
;; can be used in a linklet:
|
||||||
|
|
||||||
(define-primitive-table internal-table
|
(define-primitive-table internal-table
|
||||||
[extract-procedure (known-constant)]
|
|
||||||
[set-ctl-c-handler! (known-constant)]
|
[set-ctl-c-handler! (known-constant)]
|
||||||
[impersonator-val (known-constant)]
|
[impersonator-val (known-constant)]
|
||||||
[impersonate-ref (known-constant)]
|
[impersonate-ref (known-constant)]
|
||||||
|
|
|
@ -72,10 +72,11 @@
|
||||||
receiver
|
receiver
|
||||||
(lambda args (apply receiver args)))))))
|
(lambda args (apply receiver args)))))))
|
||||||
|
|
||||||
(define (extract-procedure f n-args)
|
(define-syntax-rule (extract-procedure f n-args)
|
||||||
(cond
|
(let ([tmp f])
|
||||||
[(#%procedure? f) f]
|
(if (#%procedure? tmp)
|
||||||
[else (slow-extract-procedure f n-args)]))
|
tmp
|
||||||
|
(slow-extract-procedure tmp n-args))))
|
||||||
|
|
||||||
(define (slow-extract-procedure f n-args)
|
(define (slow-extract-procedure f n-args)
|
||||||
(pariah ; => don't inline enclosing procedure
|
(pariah ; => don't inline enclosing procedure
|
||||||
|
|
15
racket/src/schemify/constructed-procedure.rkt
Normal file
15
racket/src/schemify/constructed-procedure.rkt
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
#lang racket/base
|
||||||
|
(require "match.rkt")
|
||||||
|
|
||||||
|
;; Recognize functions whose result is always a core procedure of a
|
||||||
|
;; known arity
|
||||||
|
|
||||||
|
(provide constructed-procedure-arity-mask)
|
||||||
|
|
||||||
|
(define (constructed-procedure-arity-mask v)
|
||||||
|
(match v
|
||||||
|
[`(make-struct-field-accessor . ,_)
|
||||||
|
1]
|
||||||
|
[`(make-struct-field-mutator . ,_)
|
||||||
|
2]
|
||||||
|
[`,_ #f]))
|
|
@ -5,6 +5,7 @@
|
||||||
"import.rkt"
|
"import.rkt"
|
||||||
"simple.rkt"
|
"simple.rkt"
|
||||||
"pthread-parameter.rkt"
|
"pthread-parameter.rkt"
|
||||||
|
"constructed-procedure.rkt"
|
||||||
"literal.rkt"
|
"literal.rkt"
|
||||||
"inline.rkt"
|
"inline.rkt"
|
||||||
"mutated-state.rkt"
|
"mutated-state.rkt"
|
||||||
|
@ -61,6 +62,8 @@
|
||||||
[else (known-copy rhs)])]
|
[else (known-copy rhs)])]
|
||||||
[(pthread-parameter? rhs prim-knowns knowns mutated)
|
[(pthread-parameter? rhs prim-knowns knowns mutated)
|
||||||
(known-procedure 3)]
|
(known-procedure 3)]
|
||||||
|
[(constructed-procedure-arity-mask rhs)
|
||||||
|
=> (lambda (m) (known-procedure m))]
|
||||||
[(and defn
|
[(and defn
|
||||||
(simple? rhs prim-knowns knowns imports mutated simples))
|
(simple? rhs prim-knowns knowns imports mutated simples))
|
||||||
a-known-constant]
|
a-known-constant]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user