effekt icon indicating copy to clipboard operation
effekt copied to clipboard

Perform polymorphism boxing after optimization

Open b-studios opened this issue 11 months ago • 8 comments

@phischu

b-studios avatar Jan 24 '25 10:01 b-studios

def foo[A](x: Int){ bar: Int => A }: A = {
  bar(x)
}

def baz(x: Int): Int = {
  if (x > 0) {
    foo(x - 1){baz}
  } else { 0 }
}

def main() = { 
  println(baz(10))
}

phischu avatar Jan 29 '25 09:01 phischu

This massively reduces the performance in some of our benchmarks, most notably list_tail. Polymorphism-boxing a match introduces a local binding for each clause that seems to not be inlined by llvm. We should avoid introducing a freshly-bound block when we are coercing a BlockLit

phischu avatar Mar 07 '25 15:03 phischu

Nice, looks like only the PolyBoxingTests need to be adjusted now. Good job!

b-studios avatar May 29 '25 12:05 b-studios

This seems to fix #1012 and #1030 and also comes with other improvements. It is not the end of the polymorphism story but I believe we should review and merge it eventually.

phischu avatar May 30 '25 11:05 phischu

As a follow-up it will also allow us to delete the special casing for LLVM in the optimizer here.

phischu avatar May 30 '25 11:05 phischu

@mattisboeckle please fix the failing tests by updating the expected values.

phischu avatar May 30 '25 11:05 phischu

While at it, maybe you can also add tests for #1012 and #1030 so we can immediately close them.

b-studios avatar May 30 '25 11:05 b-studios

The tests still fail. I get values are not equal even if they have the same toString() So some variable is not getting renamed. I could not figure out which one

mattisboeckle avatar Jun 08 '25 12:06 mattisboeckle

@marzipankaiser Pls take a look

marzipankaiser avatar Jun 30 '25 14:06 marzipankaiser

Super, now rebase this onto master (and force push to this branch).

phischu avatar Jul 03 '25 11:07 phischu