>From 928670f9fbc1b37c03a48ce9a2aa621c7a0d5aec Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Wed, 5 Jul 2017 13:29:23 +0200 Subject: [PATCH] Elide pointless type checks in the lfa2 pass The C_i_foreign_*_argumentp functions can be safely elided if we can prove the arguments have the correct type. --- lfa2.scm | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lfa2.scm b/lfa2.scm index e53ffe37..8d055113 100644 --- a/lfa2.scm +++ b/lfa2.scm @@ -117,6 +117,14 @@ ("C_i_portp" port) ("C_i_nullp" null))) +;; Maps foreign type checks to types + +(define +ffi-type-check-map+ + '(("C_i_foreign_fixnum_argumentp" fixnum) + ("C_i_foreign_char_argumentp" char) + ("C_i_foreign_flonum_argumentp" flonum) + ("C_i_foreign_string_argumentp" string) + ("C_i_foreign_symbol_argumentp" symbol))) ;; Maps constructors to types @@ -313,6 +321,17 @@ ((member r1 (cdr a)) (extinguish! n "C_i_noop"))) '*))) + ((assoc (first params) +ffi-type-check-map+) => + (lambda (a) + (let ((arg (first subs)) + (r1 (walk (first subs) te ae))) + (when (eq? r1 (cadr a)) + (node-class-set! n (node-class arg)) + (node-parameters-set! n (node-parameters arg)) + (node-subexpressions-set! n (node-subexpressions arg))) + ; the ffi checks are enforcing so we always end up with + ; the correct type + r1))) ((assoc (first params) +predicate-map+) => (lambda (a) (let ((arg (first subs))) -- 2.11.0