freenode/lisp - IRC Chatlog
Search
6:12:44
mfiano
Implementation must only obey the declaration identifiers NOTINLINE, SPECIAL, and conform to some OPTIMIZE/SAFETY rules
6:17:23
aeth
This is why I'm going to eventually put in the work to change the default behavior of my DEFINE-FUNCTION macro to be implementation-specific: i.e. DECLARE when it works (* unfortunately in SBCL with (safety 0) imo it doesn't "work" and I don't think there's a way to detect that) and CHECK-TYPE when DECLARE is ignored
6:17:57
aeth
But short of putting in too much effort writing a macro that does both DECLARE and CHECK-TYPE, if you must have it checked as a priority use CHECK-TYPE and assume DECLARE is for optional performance.
6:31:08
jackdaniel
sbcl adds declare /type/ and check-type are independent spec wise. sbcl indeed usually adds check-type, but that's its custom safety policy
6:32:45
aeth
SBCL's DECLARE (when not (safety 0)) has afaik two distinctions from CHECK-TYPE. (1) you cannot provide an object at runtime that satisfies the type if you give an object of the wrong type, which probably speeds things up a tiny bit; and, (2) it gives information for type inference and a bit of static checking
6:33:23
aeth
(with CHECK-TYPE, it infers that the object in the variable before that point is of type T since it can be anything and the user can just provide something of the correct type after that point)
6:36:21
aeth
It's a bit confusing, but beyond this, SBCL internally distinguishes between an inferred type and a declared type, which can differ. The only place where this is really exposed in a convenient way is in SLIME's debugger, but there are probably some internal functions for that.
6:43:38
aeth
Oh, and it also does the DECLARE type check at a different point in the function, before the output of the standard DISASSEMBLE, which you can only see with sb-disassem:disassemble-code-component.
6:43:56
aeth
This is its typecheck for LIST when doing CAR... notice how it's only in the second disassemble:
6:44:00
aeth
(format t "Standard disassemble of CAR~%~%") (disassemble #'car) (format t "~%Full disassemble of CAR~%~%") (sb-disassem:disassemble-code-component #'car)
7:48:54
aeth
I wonder if inserting CHECK-TYPES for (safety 0) and slowing down code would be what users want, though.
7:52:11
aeth
Unrelated, but I found a small bug in my DEFINE-FUNCTION while writing a bunch of simple REPL cases because of this conversation, which I guess is one of the reasons why I don't recommend anyone should use it yet. There's a lot of surface area to cover.
8:02:08
phoe
if I explicitly tell the compiler to use no safety, then I'd expect the compiler to use no safety
8:08:33
aeth
phoe: The problem is that SBCL's (safety 0) is essentially semantically broken and is even less safe than C. It removes runtime checks like a lot of languages can do, as expected, but it also removes static checking that the compiler can do, making bugs way easier to write.
8:09:39
aeth
There are very few reasons to use it, and those can all be inside of LOCALLY, not done globally or per-function.
8:10:28
aeth
But, I mean, if that's what they want, then I guess I shouldn't undermine that in a macro by adding CHECK-TYPEs.
8:12:28
aeth
(Okay, the reason to use it globally is benchmarks, I guess, but it's not a useful benchmark mode if the only acceptable time to run it is in benchmarks.)
9:25:55
phoe
restrict-compiler-policy without arguments returns some meaningful Lisp values... but I wonder if/how that is usable in macroexpansion time
9:27:01
jdz
I was trying to point to a place where the distinctions between DECLARE of SAFETY and CHECK-TYPE might be found.