Copy-and-Patch: A Copy-and-Patch Tutorial
11–20 of 22 posts
Re: Copy-and-Patch: A Copy-and-Patch Tutorial
#12There are some experiments in using copy-and-patch for the R language (after Python): https://dl.acm.org/doi/10.1145/3759548.3763370 From a master thesis: https://www.itspy.cz/wp-content/uploads/2025/09/it_spy_2025_...
Re: Copy-and-Patch: A Copy-and-Patch Tutorial
#13Re: Copy-and-Patch: A Copy-and-Patch Tutorial
#14I think WASM, but could be for a custom byte code? and more importantly, for a set of host-native functions (like I make some rust functions that somehow exploit this idea?)
Re: Copy-and-Patch: A Copy-and-Patch Tutorial
#15Earlier quoted context omitted.
My understanding is that e-graphs take care of selecting the best patch (by examining many options in parallel) but fundamentally it is still copy-and-patch.
Could you elaborate more on "fundamentally it is still copy-and-patch"? From what I can recall when I had first read about copy-and-patch a not-uncommon comparison was against Cranelift, which to me would imply that different approaches were taken. I don't recall any discussion about Cranelift's use of the technique, either, so your claim that it's at the heart of Cranelift is new information to me. Has Cranelift ado…
Re: Copy-and-Patch: A Copy-and-Patch Tutorial
#16This blog goes from 0 to 100 really, really quickly. I have no idea what I am looking. I suppose it is not meant for beginners but it claims to be a tutorial.
This is, but only for someone who wants to do JIT work without writing assembly code, but can read assembly code back into C (or can automate that part).
Instead of doing all manual register allocations in the JIT, you get to fill in the blanks with the actual inputs after a more (maybe) diligent compiler has allocated the registers, pushed them and all that.
There's a similar set of implementation techniques in Apache Impala, where the JIT only invokes the library functions when generating JIT code, instead of writing inline JIT operations, so that they can rely on shorter compile times for the JIT and deeper optimization passes for the called functions.
Re: Copy-and-Patch: A Copy-and-Patch Tutorial
#17I think this technique also lies at the heart of the Cranelift project. https://cranelift.dev/
Copy-and-patch is a technique for reducing the amount of effort it takes to write a JIT by leaning on an existing AOT compiler's code generator. Instead of generating machine code yourself, you can get LLVM (or another compiler) to generate a small snippet of code for each operation in your internal IR. Then codegen is simply a matter of copying the precompiled snippet and patching up the references.
The more resources are poured into a JIT, the less it is likely to use copy-and-patch. You get more control/flexibility doing codegen yourself.
But see also Deegen for a pretty cool example of trying to push this approach as far as possible: https://aha.stanford.edu/deegen-meta-compiler-approach-high-...
Re: Copy-and-Patch: A Copy-and-Patch Tutorial
#18Re: Copy-and-Patch: A Copy-and-Patch Tutorial
#19Earlier quoted context omitted.
Could you elaborate more on "fundamentally it is still copy-and-patch"? From what I can recall when I had first read about copy-and-patch a not-uncommon comparison was against Cranelift, which to me would imply that different approaches were taken. I don't recall any discussion about Cranelift's use of the technique, either, so your claim that it's at the heart of Cranelift is new information to me. Has Cranelift ado…
[flagged]
Re: Copy-and-Patch: A Copy-and-Patch Tutorial
#20This blog goes from 0 to 100 really, really quickly. I have no idea what I am looking. I suppose it is not meant for beginners but it claims to be a tutorial.