Skip to content

Commit

Permalink
Insert fixed-to-multiple in optimizations to preserve semantics
Browse files Browse the repository at this point in the history
Without this, optimization leads to alien behavior like
((lambda (x) x) (values 1 2 3)) => 1 2 3 (instead of 1)
  • Loading branch information
Bike committed May 14, 2021
1 parent 383277d commit 38b03b7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
14 changes: 13 additions & 1 deletion BIR-transformations/interpolate-function.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,25 @@
;; The stuff in the AFTER block is now unreachable.
(cleavir-bir:delete-iblock after)
(let ((call-arguments (rest (cleavir-bir:inputs call)))
(ftmd-arguments
(loop for datum in (rest (cleavir-bir:inputs call))
collect (make-instance 'cleavir-bir:output
:name (cleavir-bir:name datum)
:derived-type (cleavir-bir:ctype datum))))
(inputs '()))
;; Remove the local call.
(cleavir-bir:delete-instruction call)
;; Insert fixed-to-multiple instructions to ensure only primary values
;; of the call arguments are used.
(loop for arg in call-arguments for ftm-out in ftmd-arguments
for ftm = (make-instance 'cleavir-bir:fixed-to-multiple
:inputs (list arg) :outputs (list ftm-out))
do (cleavir-bir:insert-instruction-before ftm jump))
;; Compute inputs to the jump.
(cleavir-bir:map-lambda-list
(lambda (state item index)
(declare (ignore index))
(let ((arg (pop call-arguments)))
(let ((arg (pop ftmd-arguments)))
(ecase state
(:required
(push arg inputs))
Expand Down
9 changes: 7 additions & 2 deletions BIR-transformations/meta-evaluate.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,14 @@
(cleavir-bir:function reader))
#+(or)
(format t "~&meta-evaluate: substituting single read binding of ~a" variable)
(let ((input (cleavir-bir:input binder)))
(let* ((input (cleavir-bir:input binder))
(fout (make-instance 'cleavir-bir:output))
(ftm (make-instance 'cleavir-bir:fixed-to-multiple
:outputs (list fout))))
(setf (cleavir-bir:inputs binder) nil)
(cleavir-bir:replace-uses input reader-out))
(cleavir-bir:insert-instruction-before ftm reader)
(cleavir-bir:replace-uses fout reader-out)
(setf (cleavir-bir:inputs ftm) (list input)))
(cleavir-bir:delete-instruction reader)
t)))))

Expand Down

0 comments on commit 38b03b7

Please sign in to comment.