Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix BTB compiler problem #1651

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix BTB compiler problem
See test case. The annotation nesting was broken.
Bike committed Nov 18, 2024
commit 558b477c9361f2acd829be9805fc49c764567722
21 changes: 18 additions & 3 deletions src/lisp/kernel/cleavir/compile-bytecode.lisp
Original file line number Diff line number Diff line change
@@ -280,12 +280,27 @@
(loop for a in annotations
do (start-annotation a inserter context)))

(defun annotation< (annot1 annot2)
;; We keep ANNOTS sorted by end IP.
;; If they tie on end IP, we use the reverse order of the starts.
;; Imagine we have an annotation 5-13 and another 11-13.
;; We want to start the 5-13, then start the 11-13, then end the 11-13.
;; That's why we reverse order of the starts.
;; If two annotations start and end at the same point there may be a
;; problem. I don't think this can actually arise.
(let ((end1 (core:bytecode-debug-info/end annot1))
(end2 (core:bytecode-debug-info/end annot2)))
(cond ((< end1 end2) t)
((= end1 end2)
(> (core:bytecode-debug-info/start annot1)
(core:bytecode-debug-info/start annot2)))
(t nil))))

(defun add-annotations (annots next-annots)
;; We keep ANNOTS sorted by end IP.
;; FIXME? This could be done without consing, but it would be uglier.
(let ((sna (sort (copy-list next-annots) #'<
:key #'core:bytecode-debug-info/end)))
(merge 'list annots sna #'< :key #'core:bytecode-debug-info/end)))
(let ((sna (sort (copy-list next-annots) #'annotation<)))
(merge 'list annots sna #'annotation<)))

(defun end-annotations (ip annots inserter context)
;; ANNOTS are kept sorted by bdi/end, so this is easy.
14 changes: 14 additions & 0 deletions src/lisp/regression-tests/btb.lisp
Original file line number Diff line number Diff line change
@@ -121,3 +121,17 @@
(funcall cc) (funcall cc)
(values (funcall c) warningsp failurep)))
(3 nil nil))

;;; meister ran into this in some complex cando code
;;; errored out with #<VARIABLE R> fell through ETYPECASE expression.
;;; Wanted one of LINEAR-DATUM (CONS LINEAR-DATUM)
(test btb.misc-1
(let ((f (cmp:bytecompile
'(lambda ()
(let ((ef (let (r)
(flet ((f (a) (eql r a))) #'f))))
ef)))))
(multiple-value-bind (cc warningsp failurep) (compile nil f)
(declare (ignore cc))
(values warningsp failurep)))
(nil nil))