libera/#commonlisp - IRC Chatlog
Search
8:22:03
lucerne
What I’m wondering is if CL compiles specialized versions of each functions for each tuple of input argument types. (This trick is used to great effect in Julia.)
8:25:08
beach
lucerne: The language has no opinion about that. Can you give an example of what you mean?
8:26:19
hayley
It's possible to write a macro to do "type splitting", which achieves nearly the same effect (though the type is dispatched wholly at runtime with current implementations, whereas dispatch can be done at compile-time in Julia).
8:27:43
hayley
e.g. (defmacro split-on ((variable type) &body body) `(if (typep ,variable ',type) (progn ,@body) (progn ,@body))) and then (split-on (x fixnum) (+ x 2))
8:30:58
beach
lucerne: It would be uncommon for any Common Lisp implementation to compile a new version of a function when a new call to it is defined. But this technique: http://metamodular.com/SICL/call-site-optimization.pdf is meant to make similar optimizations possible.
8:32:21
beach
lucerne: I don't know Julia, but what is their type system like? I mean, if it has to compile a new function for each call site, inlining will work quite well.
8:35:39
beach
lucerne: Furthermore, it seems silly to make different versions of a function that does not depend on the "type" of its argument(s).
8:37:36
hayley
Doing type splitting (as I described) can be used to effectively hoist the dispatch on how to AREF and operate on the elements on an array. It can be useful for performance.
8:40:13
hayley
I am aware, thanks. Is that code silly to you? I think it's a pretty reasonable optimization, though I vaguely recall you mentioning that the SICL compiler should do some sort of hoisting automatically.
8:40:40
hayley
(I think the term is "hoisting" some test out of a function, but I could be mistaken.)
8:41:03
beach
I see no point in compiling two different versions of f according to the type of the argument.
8:44:00
hayley
Yes, that sort of code would be pointless, but that is not what the SICL sequence functions do, nor is it what the Julia compiler does. I would say that the Julia compiler nearly does the same trick that you do with the sequence functions.
8:44:44
hayley
However, from memory, Julia only compiles specialised variants of a function when the compiler would find it useful to call a specialised variant.
8:46:15
hayley
You are referring to "What I’m wondering is if CL compiles specialized versions of each functions for each tuple of input argument types"?
8:48:12
hayley
Unless there is some very profitable constant folding to be done, I think a compiler would only bother to generate specialized code for what I called "layout times" in my regular expression compiler.
8:48:16
beach
And if Julia considers 2 and 3 to be the same "type" so that the same specialized function would be reused, then it would miss an opportunity for (defun f (x) (if (< x 3) <code-a> <code-b>))
8:50:38
pjb
Furthermore, it's also silly to compile different versions of a function when the different types have actually the same size. C++ does this (because "type-safety"), thus duplicating a lot of code uselessly. You may need a function working on 8-bit types, one on 16-bit types, one on 32-bit types, and nowadays one on 64-bit types, but not care if it's an int or a char*…
8:51:10
pjb
Of course, in the case of lisp, all the values are references, so they're all the same width, and a single function is needed.
8:51:12
hayley
I have a list of useful types like (simple-array character 1) and (simple-array base-char 1), which I know the Lisp compiler can handle specially.
8:51:45
hayley
pjb: Hence why I call them "layout types", as opposed to more abstract (and useful) types like STRING.
8:55:41
hayley
There is probably a better name for such types, but I intend to draw attention to how the type is used for optimization rather than, say, proving properties of a program.
9:02:11
beach
lucerne: Another question: If Julia compiles a different version of some callee for each combination of argument "types" on call sites, what happens when the callee is then redefined? Does it find all call sites to determine how many versions of the new callee to compile?
9:03:33
lucerne
beach: I am not at all an expert on this subject. I basically know the highlevel concepts: dynamic languages are slow as they need to have runtime checks and can use less assumptions to hardcode optimizations, so Julia uses some heuristics to compile type-specialized versions of functions to overcome this limitation. Regarding constant folding (2
9:03:33
lucerne
vs 3), I know Julia sometimes does that, but I don’t the specifics. I think it would only do this if is inlining the function anyway. (Julia has some concept of recompiling functions when their dependencies change, so it can inline functions and still support live coding. I a, again not at all an expert. Use their docs, they are one of the best.
9:04:27
lucerne
The recompiling, btw, happens when the function is to be used, I think. They use the term “invalidated method.”
9:05:46
beach
lucerne: I am not interested enough to go read up on Julia. I thought since you had opinions about how Common Lisp should do things, you might know.
9:07:37
beach
lucerne: Recompiling as dependencies change is very iffy. If you have mutual recursion for instance. Also, you can't fully recompile in Common Lisp. You would need to keep a minimally compiled version around. Even so, the amount of recompilation could be massive.
9:07:39
lucerne
Btw, can you elaborate on what you mean by a layout type? The layout of the data in the memory?
9:08:03
beach
lucerne: Common Lisp is a language. Julia is a programming system. You can't compare the two.
9:09:03
beach
lucerne: So Common Lisp does not "do any optimizations". Some implementations do of course.
9:11:31
beach
lucerne: A language specification or standard should just define what conforming code looks like and the semantics of such code.
9:12:30
gin
is there a substitute function that can replace multiple characters with multiple characters? like (multi-substitute "abc" "ABC" "carbon") => "CArBon"
9:55:34
Guest-liao
We have a plan for meta information for the document of Common Lisp. Like we have srfi-data.scm file for the signature of proc and macro
9:58:27
Guest-liao
Then we can proposal a s-expression of common signature of proc and macro for lisp different implementation community and different scheme community .
10:03:19
beach
Guest-liao: There is just too much stuff in what you are saying for me to deal with right now. Maybe others can answer. I need a lunch break myself.
10:05:59
Guest-liao
Basic idea is that centralize the meta information in Common Lisp, and rich s-expression for both of Common lisp and scheme.
10:25:58
Guest-liao
Basic idea is that centralize the meta information of Common Lisp, and rich s-expression for both of Common lisp and scheme.
10:34:25
Guest-liao
Like (def (sig (procedure "(toplevel-command SYMBOL PROC [HELPSTRING])" (id toplevel-command)))
10:34:25
Guest-liao
(p "Defines or redefines a toplevel interpreter command which can be invoked by entering " (tt ",SYMBOL") ". " (tt "PROC") " will be invoked when the command is entered and may read any required argument via " (tt "read") " (or " (tt "read-line") "). If the optional argument " (tt "HELPSTRING") " is given, it will be listed by the " (tt ",?") "
11:03:15
trevlif
What is DEFTYPE used for? Is it just something that defclass uses or is it used elsewhere also?
11:11:23
trevlif
Seems like one can implement CLOS using types? Is that a fair comment? For example, instead of using generic functions, have a typecase within a defun
11:22:06
frgo
JeromeLon: I just checked myself. Expiry date shows as 2022-10-09T15:20:41Z. So it will expire next year.
11:24:38
edgar-rft
Xach is logged in but might be still asleep (in the USA it's early in the morning).
11:24:46
JeromeLon
frgo: you are right, it was updated a few hours ago. It looks like some whois mirrors are not up to date yet
15:47:42
gin
what does that mean? my projects relying on quicklisp would fail if I were to redo its setup?
15:52:58
frgo
gin: Well, yes. As quicklisp.org can't be resolved to an IP address the quickload of any package that's not already downloaded would fail - that's what I experience here.
15:54:55
gin
that's too bad. I will make sure I don't re-create my project setups until quicklisp.org comes back up
20:09:21
Arcsech
Just discovered https://github.com/marcoheisig/the-cost-of-nothing and spent a few minutes running the standard suite across (sbcl/ccl/abcl/ecl/clisp)
20:09:59
Arcsech
Sample:... (full message at https://libera.ems.host/_matrix/media/r0/download/libera.chat/94b3ea570a9b93202b7564de62678c44cfad3dd3)
20:16:25
Arcsech
The order goes very roughly from slow to fast: clisp, ecl, abcl, ccl, sbcl, with ccl and sbcl being much faster than any of the others (for this super limited benchmark). Might do a bit more exploration along these lines.