From 0a9cd2a6b730ec3f0689fd17abb2fe11ff8cb813 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Thu, 27 Sep 2018 15:57:51 -0400 Subject: [PATCH] Well-known lambdas cannot be called from runtime --- scheme/cyclone/cps-optimizations.sld | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/scheme/cyclone/cps-optimizations.sld b/scheme/cyclone/cps-optimizations.sld index 49aab7ca..2a74fdf8 100644 --- a/scheme/cyclone/cps-optimizations.sld +++ b/scheme/cyclone/cps-optimizations.sld @@ -2029,6 +2029,15 @@ (hash-table-delete! scopes param-sym) ) + ;; Determine if the expression is a call to a primitive that receives + ;; a continuation. This is important since well-known functions cannot + ;; be passed as such a cont. + (define (prim-call/cont? exp) + (let ((result (and (app? exp) + (prim:cont? (car exp))))) + (trace:info `(prim-call/cont? ,exp ,result)) + result)) + (define (found exp . sym) (let ((lid (ast:lambda-id exp))) (if (null? sym) @@ -2062,11 +2071,15 @@ ((app? exp) (cond ((ast:lambda? (car exp)) - (found (car exp)) ;; We immediately know these lambdas are well-known + (when (not (any prim-call/cont? (cdr exp))) + (found (car exp))) ;; We immediately know these lambdas are well-known (let ((formals (ast:lambda-formals->list (car exp)))) (when (and (pair? formals) (pair? (cdr exp)) - (ast:lambda? (cadr exp))) + (ast:lambda? (cadr exp)) + ;; Lambda is not well-known when called from a runtime prim + ;;(not (any prim-call/cont? (cdr exp))) + ) (add-candidate! (cadr exp) (car exp) (car formals))) ) ;; Scan the rest of the args