0.6.11.11:
authorWilliam Harold Newman <william.newman@airmail.net>
Sat, 3 Mar 2001 18:25:29 +0000 (18:25 +0000)
committerWilliam Harold Newman <william.newman@airmail.net>
Sat, 3 Mar 2001 18:25:29 +0000 (18:25 +0000)
reduced code duplication code in FDEFINITION-OBJECT
defined *XTYPE?* to help support ongoing type experiments
started conditionally fully enabling INTERSECTION-TYPE
allowed HAIRY-TYPE elements in INTERSECTION-TYPEs after all,
since otherwise INTERSECTION-TYPE can't fix bug 12
redefined KEYWORD type as (AND SYMBOL (SATISFIES KEYWORDP))
added tests for bug 12 fixedness

src/code/deftypes-for-target.lisp
src/code/early-type.lisp
src/code/fdefinition.lisp
src/code/late-type.lisp
src/code/random.lisp
src/code/target-random.lisp
src/compiler/typetran.lisp
tests/type.impure.lisp
version.lisp-expr

index 20f9a7a..63574ff 100644 (file)
     #\n #\o #\p #\q #\r #\s #\t #\u #\v #\w #\x #\y #\z #\{
     #\| #\} #\~))
 
-;;; FIXME: Would type inference be able to get more traction on this
-;;; if it were defined as (AND SYMBOL (SATISFIES KEYWORDP))?
 (sb!xc:deftype keyword ()
-  #!+sb-doc
-  "Type for any keyword symbol."
-  '(satisfies keywordp))
+  ;; Defining this as (AND SYMBOL ..) lets (SUBTYPEP 'KEYWORD 'SYMBOL)=>T,T.
+  '(and symbol (satisfies keywordp)))
 
 (sb!xc:deftype eql (n) `(member ,n))
 
index 6d18adc..ff5252d 100644 (file)
 ;;; Has the type system been properly initialized? (I.e. is it OK to
 ;;; use it?)
 (defvar *type-system-initialized* #+sb-xc-host nil) ; (set in cold load)
+
+;;; Use experimental type functionality?
+;;;
+;;; REMOVEME: Eventually the new type functionality should be stable
+;;; enough that nothing depends on this, and we can remove it again.
+(defvar *xtype?*)
+(!cold-init-forms (setf *xtype?* nil))
 \f
 ;;; Return the type structure corresponding to a type specifier. We
 ;;; pick off structure types as a special case.
index 30bab6f..5be9930 100644 (file)
   "Return the fdefn object for NAME. If it doesn't already exist and CREATE
    is non-NIL, create a new (unbound) one."
   (declare (values (or fdefn null)))
-  (unless (or (symbolp name)
-             (and (consp name)
-                  (eq (car name) 'setf)
-                  (let ((cdr (cdr name)))
-                    (and (consp cdr)
-                         (symbolp (car cdr))
-                         (null (cdr cdr))))))
+  (unless (legal-function-name-p name)
     (error 'simple-type-error
           :datum name
           :expected-type '(or symbol list)
index dbeff6a..edd81f7 100644 (file)
         (first types))
        (;; if potentially too hairy
         (some (lambda (type)
-                (or (union-type-p type)
-                    (hairy-type-p type)))
+                ;; Allowing irreducible union types into intersection
+                ;; types leads to issues of canonicalization. Those might
+                ;; be soluble but it would be nicer just to avoid them
+                ;; entirely by punting to HAIRY-TYPE. -- WHN 2001-03-02
+                (union-type-p type))
               types)
         ;; (CMU CL punted to HAIRY-TYPE like this for all AND-based
         ;; types. We don't want to do that for simple intersection
      (append (type-components type1)
             (type-components type2)))))
 
-(!def-type-translator foo-type (&rest type-specifiers)
+(!def-type-translator and (&whole whole &rest type-specifiers)
   ;; Note: Between the behavior of SIMPLIFY-INTERSECTION-TYPE (which
   ;; will reduce to a 1-element list any list of types which CMU CL
   ;; could've represented) and MAKE-INTERSECTION-TYPE-OR-SOMETHING
   ;; (which knows to treat a 1-element intersection as the element
   ;; itself) we should recover CMU CL's behavior for anything which it
   ;; could handle usefully (i.e. could without punting to HAIRY-TYPE).
-  (/show0 "entering type translator for AND/FOO-TYPE")
-  (make-intersection-type-or-something
-   (mapcar #'specifier-type type-specifiers)))
-;;; (REMOVEME once INTERSECTION-TYPE works.)
-
-(!def-type-translator and (&whole spec &rest types)
-  (let ((res *wild-type*))
-    (dolist (type types res)
-      (let ((ctype (specifier-type type)))
-        (multiple-value-bind (int win) (type-intersection res ctype)
-          (unless win
-            (return (make-hairy-type :specifier spec)))
-          (setq res int))))))
+  (/show0 "entering type translator for AND")
+  (if *xtype?* 
+      (make-intersection-type-or-something
+       (mapcar #'specifier-type type-specifiers))
+      (let ((res *wild-type*))
+       (dolist (type-specifier type-specifiers res)
+         (let ((ctype (specifier-type type-specifier)))
+           (multiple-value-bind (int win) (type-intersection res ctype)
+             (unless win
+               (return (make-hairy-type :specifier whole)))
+             (setq res int)))))))
 \f
 ;;;; union types
 
index 863b5cc..d0d672d 100644 (file)
@@ -24,5 +24,6 @@
 (defconstant random-fixnum-max
   (1- (ash 1 (- random-chunk-length random-integer-extra-bits))))
 
-(sb!xc:defstruct (random-state (:constructor %make-random-state))
+(sb!xc:defstruct (random-state (:constructor %make-random-state)
+                              (:copier nil)) ; since shallow copy is wrong
   (state (init-random-state) :type (simple-array (unsigned-byte 32) (627))))
index 46b33d7..9937cd7 100644 (file)
   of the default random state. If STATE is a random state, then return a
   copy of it. If STATE is T then return a random state generated from
   the universal time."
+  (/show0 "entering !RANDOM-COLD-INIT")
   (flet ((copy-random-state (state)
+          (/show0 "entering COPY-RANDOM-STATE")
           (let ((state (random-state-state state))
                 (new-state
                  (make-array 627 :element-type '(unsigned-byte 32))))
+            (/show0 "made NEW-STATE, about to DOTIMES")
             (dotimes (i 627)
               (setf (aref new-state i) (aref state i)))
+            (/show0 "falling through to %MAKE-RANDOM-STATE")
             (%make-random-state :state new-state))))
-    (cond ((not state) (copy-random-state *random-state*))
-         ((random-state-p state) (copy-random-state state))
-         ((eq state t)
-          (%make-random-state :state (init-random-state
-                                      (logand (get-universal-time)
-                                              #xffffffff))))
-         ;; FIXME: should be TYPE-ERROR?
-         (t (error "Argument is not a RANDOM-STATE, T or NIL: ~S" state)))))
+    (/show0 "at head of ETYPECASE in MAKE-RANDOM-STATE")
+    (etypecase state
+      (null
+       (/show0 "NULL case")
+       (copy-random-state *random-state*))
+      (random-state
+       (/show0 "RANDOM-STATE-P clause")
+       (copy-random-state state))
+      ((member t)
+       (/show0 "T clause")
+       (%make-random-state :state (init-random-state
+                                  (logand (get-universal-time)
+                                          #xffffffff)))))))
 \f
 ;;;; random entries
 
index f5ade91..276aa8c 100644 (file)
@@ -12,6 +12,9 @@
 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
 ;;;; files for more information.
 
+;;; FIXME: Many of the functions in this file could probably be
+;;; byte-compiled, since they're one-pass, cons-heavy code.
+
 (in-package "SB!C")
 \f
 ;;;; type predicate translation
                                (member ,@(remove nil members))))))))
          (t
           (once-only ((n-obj object))
-            `(or ,@(mapcar #'(lambda (x)
-                               `(typep ,n-obj ',(type-specifier x)))
+            `(or ,@(mapcar (lambda (x)
+                             `(typep ,n-obj ',(type-specifier x)))
                            types)))))))
 
 ;;; Do source transformation for TYPEP of a known intersection type.
 (defun source-transform-intersection-typep (object type)
-  ;; FIXME: This is just a placeholder; we should define a better
-  ;; version by analogy with SOURCE-TRANSFORM-UNION-TYPEP.
-  (declare (ignore object type))
-  nil)
+  (once-only ((n-obj object))
+    `(and ,@(mapcar (lambda (x)
+                     `(typep ,n-obj ',(type-specifier x)))
+                   (intersection-type-types type)))))
 
 ;;; If necessary recurse to check the cons type.
 (defun source-transform-cons-typep (object type)
index 6ec22b9..1dbf49c 100644 (file)
 (assert (typep 11 '(and)))
 (assert (not (typep 11 '(or))))
 
+;;; bug 12: type system didn't grok nontrivial intersections
+(assert (subtypep '(and symbol (satisfies keywordp)) 'symbol))
+(assert (not (subtypep '(and symbol (satisfies keywordp)) 'null)))
+#| ; "we gotta target, but you gotta be patient": 0.6.11.11 work in progress 
+(assert (subtypep 'keyword 'symbol))
+(assert (not (subtypep 'symbol 'keyword)))
+(assert (subtypep 'ratio 'real))
+(assert (subtypep 'ratio 'number))
+|#
+
 ;;; success
 (quit :unix-status 104)
index 917aaac..086487c 100644 (file)
@@ -15,4 +15,4 @@
 ;;; versions, and a string like "0.6.5.12" is used for versions which
 ;;; aren't released but correspond only to CVS tags or snapshots.
 
-"0.6.11.10"
+"0.6.11.11"