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 https://github.com/Clozure/ccl/issues/350 : set lfun-bits inside set-funcallable-instance-function #369

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

digikar99
Copy link

Please review if the bits set in the commit are the relevant ones.

@phoe
Copy link
Contributor

phoe commented May 17, 2021

What is the root cause of the error? Why does this particular case of bit-setting fix it?

@digikar99
Copy link
Author

digikar99 commented May 17, 2021

The most I have been able to figure out so far is that the warning comes from compile-named-function (and nx1-check-call-args, which calls innermost-lfun-bits-keyvect -> lfun-bits, so I presumed the bits themselves are not being set anywhere.)

However, specialization-store does not still work well with this:

(in-package :specialization-store)

(defstore foo (x))
(defspecialization foo (x) t
  x)

(defun foo-caller (x)
  (foo x))

Compiling the last form still yields:

;   In FOO-CALLER: In the call to FOO with arguments (X),
;     1 argument was provided, but at most 0 are accepted
;     by the current global definition of FOO

@phoe
Copy link
Contributor

phoe commented May 17, 2021

Is the logand required? Are the bits allowed to be longer than 16 bits?

@digikar99
Copy link
Author

digikar99 commented May 17, 2021

The logand is required, because at least the first few bits are relevant for the type. If those bits are set, the object no longer remains a adhoc-polymorphic-functions:adhoc-polymorphic-function.

(lfun-bits funcallable-instance (lfun-bits function)) definitely results in a type-error

And the following works, but I'm not sure why it should work:

(lfun-bits funcallable-instance
           (logior (lfun-bits funcallable-instance)
                   (lfun-bits function)))

Change in required arguments seems to change the last 10 bits - or, no...? Something elaborate:

;;; Ignoring the warnings; and using https://www.rapidtables.com/convert/number/decimal-to-binary.html with 2s complement
;;; Is there a CL tool for the same?
CCL> (lfun-bits (lambda (a)))
-528482048 ;=> 11100000100000000000000100000000
CCL> (lfun-bits (lambda (a b)))
-528481792 ;=> 11100000100000000000001000000000
CCL> (lfun-bits (lambda (a b c d)))
-528481280 ;=> 11100000100000000000010000000000
CCL> (lfun-bits (lambda (&key a)))
-528482302 ;=> 11100000100000000000000000000010
CCL> (lfun-bits (lambda (&key a b)))
-528482302 ;=> 11100000100000000000000000000010
CCL> (lfun-bits (lambda (&optional a)))
-528482300 ;=> 11100000100000000000000000000100
CCL> (lfun-bits (lambda (&optional a b)))
-528482296 ;=> 11100000100000000000000000001000
CCL> (lfun-bits (lambda (&optional a b c d)))
-528482288 ;=> 11100000100000000000000000010000
CCL> (lfun-bits (lambda (&rest a)))
-528449536 ;=> 11100000100000001000000000000000
CCL> (lfun-bits (lambda (a &rest a)))
-528449280 ;=> 11100000100000001000000100000000
CCL>                  (length "1000000100000000")
16



@phoe
Copy link
Contributor

phoe commented May 17, 2021

;;; Is there a CL tool for the same?

Yes, format ~b:

CL-USER> (format nil "~32,'0B" (mod -528482288 (ash 1 32)))
"11100000100000000000000000010000"

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

Successfully merging this pull request may close these issues.

2 participants