Skip to content

Commit d176882

Browse files
David, Mark Hstylewarning
David, Mark H
authored andcommitted
fix COMPILATION-TOLERANCE slot missing error, resolves: #736
Error processing code accessed slots of the condition using WITH-SLOTS macro and erroneously supplied slot names in the wrong package -- CL-QUIL-TESTS, not QUIL. Rewrote to access slots using full accessor forms, properly package qualified. Note that the compiler does not normally complain when WITH-SLOTS uses slot names that do not pertain to the given class. It should be a bit safer now that we're using the normal full accessors, since if these slot accessors were ever to become invalid, it would be flagged at compile time. Also added a new test for this machinery: test-%with-loose-state-prep-compression-736
1 parent 846f816 commit d176882

File tree

1 file changed

+39
-6
lines changed

1 file changed

+39
-6
lines changed

tests/compiler-hook-tests.lisp

+39-6
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,47 @@ JUMP @a")))
118118
`(progn
119119
(handler-bind ((quil::state-prep-compression-tolerance-error
120120
(lambda (c)
121-
(with-slots (compilation-tolerance compilation-precision) c
122-
(when (< compilation-tolerance
123-
compilation-precision
124-
quil::+double-comparison-threshold-loose+)
125-
(let ((r (find-restart 'continue c)))
126-
(when r (invoke-restart r))))))))
121+
(when (< (quil::state-prep-compression-tolerance-error-tolerance c)
122+
(quil::state-prep-compression-tolerance-error-precision c)
123+
quil::+double-comparison-threshold-loose+)
124+
(let ((r (find-restart 'continue c)))
125+
(when r (invoke-restart r)))))))
127126
,@body)))
128127

128+
(deftest test-%with-loose-state-prep-compression-736 ()
129+
"Test macro %with-loose-state-prep-compression macro. Note that this
130+
macro is actually part of the test machinery, not quil code to be
131+
tested per se."
132+
;; For issue: "compiler hook test gets 2nd-level error:
133+
;; COMPILATION-TOLERANCE slot missing #736"
134+
(labels ((test-continue-restart (tolerance precision)
135+
(let ((continue-happened nil))
136+
(multiple-value-bind (result condition)
137+
(ignore-errors
138+
(restart-case
139+
(%with-loose-state-prep-compression
140+
(error 'quil::state-prep-compression-tolerance-error
141+
:compilation-tolerance tolerance
142+
:compilation-precision precision))
143+
(continue ()
144+
(setq continue-happened t))))
145+
(declare (ignore result))
146+
(values continue-happened condition)))))
147+
(multiple-value-bind (continue-happened condition)
148+
(test-continue-restart -2 -1)
149+
(is continue-happened)
150+
(is (null condition)))
151+
(multiple-value-bind (continue-happened condition)
152+
(test-continue-restart 2 1)
153+
(is (not continue-happened))
154+
(is (not (null condition)))
155+
(is (typep condition 'QUIL::STATE-PREP-COMPRESSION-TOLERANCE-ERROR))
156+
(is (= (quil::state-prep-compression-tolerance-error-tolerance condition)
157+
2))
158+
(is (= (quil::state-prep-compression-tolerance-error-precision condition)
159+
1)))))
160+
161+
129162
(deftest test-compiler-hook (&key print-stats)
130163
"Test whether the compiler hook preserves semantic equivalence for
131164
some test programs."

0 commit comments

Comments
 (0)