# What is the meaning of the @overlay macro?

**URL:** https://discourse.julialang.org/t/what-is-the-meaning-of-the-overlay-macro/103222
**Category:** General Usage
**Tags:** question
**Created:** [August 26, 2023, 2:39pm UTC](https://discourse.julialang.org/t/what-is-the-meaning-of-the-overlay-macro/103222 "2023-08-26T14:39:13Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [August 26, 2023, 2:39pm UTC](https://discourse.julialang.org/t/what-is-the-meaning-of-the-overlay-macro/103222/1 "2023-08-26T14:39:13Z")

</div>

I saw this here: [allow `@overlay` for methods with return type declaration by aviatesk · Pull Request #51054 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/pull/51054)

But I could not find any documentation about it. Does someone know?

---

<div class="post-metadata">

### Author: ![algunion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/algunion/32/51630_2.png) [@algunion](https://discourse.julialang.org/u/algunion)
#### Post date: [August 26, 2023, 7:03pm UTC](https://discourse.julialang.org/t/what-is-the-meaning-of-the-overlay-macro/103222/2 "2023-08-26T19:03:22Z")

</div>

From the source code docs:

> This can be used to implement a method override mechanism. Regular compilation will not  
> consider these methods, and you should customize the compilation flow to look in these  
> method tables.

Also - it makes a reference to [OverlayMethodTable](https://github.com/JuliaLang/julia/blob/5bc558c9cde5db6fa89b7b4d1d56bf3f8dbe8454/base/compiler/methodtable.jl#L35).

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [August 26, 2023, 7:09pm UTC](https://discourse.julialang.org/t/what-is-the-meaning-of-the-overlay-macro/103222/3 "2023-08-26T19:09:36Z")

</div>

But what would it be good for? Any example?

Or is it just for internal use?

---

<div class="post-metadata">

### Author: ![algunion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/algunion/32/51630_2.png) [@algunion](https://discourse.julialang.org/u/algunion)
#### Post date: [August 26, 2023, 8:03pm UTC](https://discourse.julialang.org/t/what-is-the-meaning-of-the-overlay-macro/103222/4 "2023-08-26T20:03:08Z")

</div>

I do not suggest I studied it or that I have a deep understanding - but from what I’ve searched so far, this seems a good place where you can find some use cases: [https://github.com/JuliaLang/julia/blob/master/test/compiler/AbstractInterpreter.jl](https://github.com/JuliaLang/julia/blob/master/test/compiler/AbstractInterpreter.jl)

Also - keep in mind that the PR referenced by you only extends the macro to work with methods with return types. `@overaly` has been part of the `experimental` for a pretty long time.

---

<div class="post-metadata">

### Author: ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)
#### Post date: [August 26, 2023, 8:04pm UTC](https://discourse.julialang.org/t/what-is-the-meaning-of-the-overlay-macro/103222/5 "2023-08-26T20:04:28Z")

</div>

It’s generally used for low level replacements of specific functions in the GPU ecosystem, with versions that e.g. don’t throw errors or have some other special GPU implementation.

---

<div class="post-metadata">

### Author: ![tshort](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tshort/32/43_2.png) [@tshort](https://discourse.julialang.org/u/tshort)
#### Post date: [August 26, 2023, 8:56pm UTC](https://discourse.julialang.org/t/what-is-the-meaning-of-the-overlay-macro/103222/6 "2023-08-26T20:56:22Z")

</div>

From userland, you can use the functionality via [GitHub - JuliaDebug/CassetteOverlay.jl: An experimental simple method overlay mechanism for Julia](https://github.com/JuliaDebug/CassetteOverlay.jl/).
