rusty icon indicating copy to clipboard operation
rusty copied to clipboard

`THIS` should not be in codegen

Open abroooo opened this issue 7 months ago • 4 comments

With the current implementation we create a pointer for THIS in codegen. While this works fine it just might be a bit overkill because we could also just resolve all references to THIS in the resolver.

The current implementation doesn't hurt though because the created pointer gets removed by llvm anyways. It just would be cleaner.

abroooo avatar May 09 '25 08:05 abroooo

There is no local variable for the %0 argument, we only allocate GEPs for members behind the pointer. Since this needs to be a pointer but %0 is a StructValue in codegen, we need this alloca. LLVM does not allow to take the address of a register value directly, so we need to allocate space in a register to store the address. If you can figure out a solution without the alloca, I'm all for it, but I haven't had success when I tried.

mhasel avatar May 12 '25 06:05 mhasel

The idea is that this is only a marker, there is no need for it to be part of codegen as far as I can tell, it should only help us find resolve the correct variable to resolve. Do you see it differently? The only thing I can think about is calling THIS^() within a method, but this is very specific. Adding the pattern to Codegen IMHO is not necessary at this point.

ghaith avatar May 12 '25 06:05 ghaith

So the idea is to scrap supporting THIS^()?

mhasel avatar May 12 '25 07:05 mhasel

No, but this is the only case, and for that we don't need to load the pointer in advance, if there's an annotated call statement here, we can load it. It felt strange seeing THIS leak into codegen

ghaith avatar May 12 '25 07:05 ghaith