[pro] [imp-hackers] Declarations in compilers (feedback welcome)

Nikodemus Siivola nikodemus at random-state.net
Thu Dec 29 15:08:20 UTC 2011


On 29 December 2011 16:04, Juan Jose Garcia-Ripoll
<juanjose.garciaripoll at googlemail.com> wrote:

> Conceptually, in the model above, I do not see the THE as a loophole, but
> rather as two different things: variable declarations = type checked
> assignments, value declarations = compiler hints.

Fair enough. SBCL disagrees, but it and CMUCL stand apart from most
implementations when it comes to handling of types.

> For instance, if I invoke
> a function with a THE argument, SBCL will not generate a check: (FOO (THE
> FIXNUM X)) is just (FOO X), am I wrong? (I just checked in Ubuntu's SBCL)

Actually, SBCL /should/ generate the check, unless you are using the
interpreter. If it didn't then I'm guessing the Ubuntu version is an
old one:

CL-USER> (defun foo (x) x)
CL-USER> (foo (the fixnum t))
; in: FOO (THE FIXNUM T)
;     (THE FIXNUM T)
;
; caught WARNING:
;   Constant T conflicts with its asserted type FIXNUM.
;   See also:
;     The SBCL Manual, Node "Handling of Types"
;
; compilation unit finished
;   caught 1 WARNING condition
; Evaluation aborted on #<SIMPLE-TYPE-ERROR expected-type: FIXNUM datum: T>.

...plus entry to debugger is the expected behaviour.

Both THE generates and and assignment to a variable whose type has
been declared generates a identical cast node in SBCL's IR.

Cheers,

 -- Nikodemus




More information about the pro mailing list