+;;; global policy restrictions
+(defvar *policy-restrictions* nil)
+
+(defun restrict-compiler-policy (&optional quality (min 0))
+ #!+sb-doc
+ "Assing a minimum value to an optimization quality. QUALITY is the name of
+the optimization quality to restrict, and MIN (defaulting to zero) is the
+minimum allowed value.
+
+Returns the alist describing the current policy restrictions.
+
+If QUALITY is NIL or not given, nothing is done.
+
+Otherwise, if MIN is zero or not given, any existing restrictions of QUALITY
+are removed. If MIN is between one and three inclusive, it becomes the new
+minimum value for the optimization quality: any future proclamations or
+declarations of the quality with a value less then MIN behave as if the value
+was MIN instead.
+
+This is intended to be used interactively, to facilitate recompiling large
+bodies of code with eg. a known minimum safety.
+
+EXPERIMENTAL INTERFACE: Subject to change."
+ (declare (type policy-quality min))
+ (when quality
+ (aver (policy-quality-name-p quality))
+ (if (zerop min)
+ (setf *policy-restrictions*
+ (remove quality *policy-restrictions* :key #'car))
+ (let ((cell (assoc quality *policy-restrictions*)))
+ (if cell
+ (setf (cdr cell) min)
+ (push (cons quality min) *policy-restrictions*)))))
+ *policy-restrictions*)
+