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

cleavir-kildall-type-inference passes cleavir environments to CL:TYPE and CL:SUBTYPEP #116

Open
3b opened this issue Aug 6, 2018 · 0 comments

Comments

@3b
Copy link

3b commented Aug 6, 2018

possibly not using things correctly yet, but with following code:

;;; define enough of an env to build ast/hir

(defclass env (sicl-simple-environment:simple-environment) ())
(defmethod cleavir-compilation-policy:compute-policy-quality
    (name optimize (env env))
  ;; avoid errors about CLEAVIR-ESCAPE:TRUST-DYNAMIC-EXTENT and CLEAVIR-KILDALL-TYPE-INFERENCE:INSERT-TYPE-CHECKS
  1)

(defmethod cleavir-env:function-info ((env env) name)
  (or (call-next-method)
      (when (symbolp name)
        (cond
          ((special-operator-p name)
           (make-instance 'cleavir-env:special-operator-info
                          :name name))
          ((eq (symbol-package name) (find-package 'cleavir-primop))
           (make-instance 'cleavir-env:special-operator-info
                          :name name))
          ((member name '(error))
           (make-instance 'cleavir-env:global-function-info
                          :name name))))))

(defmethod cleavir-env:has-extended-char-p ((env env))
  nil)
(defmethod cleavir-env:float-types ((env env))
  '(single-float double-float))
(defmethod cleavir-env:upgraded-array-element-types ((env env))
  '(single-float double-float character (unsigned-byte 8) (unsigned-byte 32)))
(defmethod cleavir-env:upgraded-complex-part-types ((env env))
  '(single-float double-float))

;;; try to compile something
(let* ((cleavir-generate-ast:*compiler* 'cl:compile)
       (sys t)
       (env (make-instance 'env))
       (ast (cleavir-generate-ast:generate-ast
             '#'(lambda (object)
                  (declare (type cons object))
                  (if (cleavir-primop:typeq object cons)
                      (cleavir-primop:car object)
                      (if (cleavir-primop:typeq object null)
                          nil
                          (error 'type-error :datum object
                                             :expected-type '(or cons null)))))
             env sys))
       (hir (cleavir-ast-to-hir:compile-toplevel-unhoisted ast)))
  (cleavir-kildall-type-inference:infer-types hir env :prune t)
  hir)

I get a type error :

The value
  #<ENV {1002EDB663}>
is not of type
  (OR SB-C::ABSTRACT-LEXENV NULL)
when binding SB-KERNEL::ENVIRONMENT

from the call to cl:subtypep in specifier->ltype. Similarly, object-ltype passes the cleavir environment to cl:typep.

As a temporary workaround I seem to get reasonable results if I don't pass the environment to the CL functions, though I assume that won't work for real code (leaking float types from host system if nothing else). I couldn't find anything that looked like a 'correct' solution though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant