Skip to content

Conversation

ychenfo
Copy link
Member

@ychenfo ychenfo commented Mar 7, 2025

No description provided.

object A
object B

// TODO: should fuse `A` and `B` with the pattern match in `f`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any idea why this doesn't happen?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I was looking into the explanation for this I realized that this may not be the best example to illustrate the issue here. I think a better one looks like this:

fun f1(x) = if x is A then 1 else 2
fun f2(x) = if x is A then 2 else 3
fun f3(x) = if x is A then 3 else 4
let p = if true then AA(A) else BB(B)
if p is
  AA(x) then f1(x)
  BB(x) then f2(x) + f3(x)

The fusion doesn't happen now (but can happen some time before) is because now the symbol for the first pattern variable (x in the source program) in both branches (is AA(x) then ...; is BB(x) then ...) is shared, which means that the program after lowering looks like:

if p is
  AA then
    param0 = p.x
    x1 = param0
    f1(x1)
  BB then
    param0 = p.x
    x2 = param0
    f2(x2) + f3(x2)

The shared param0 in both branches leads to both A (in AA(A)) and B (in BB(B)) flowing into all f1, f2 and f3, causing clash. Before, param0 is not shared (the first branch uses param0 and the second branch uses param1), so that A in AA(A) could be fused, and only B in BB(B) couldn't get fused.

I said this program in the difftest file is not a good example because the fusion can also happen if we do not distinguish two call sites for the consumer f.

I am trying to address this issue by generating different type variables for the shared param0 in different branches.



// TODO: fusion opportunity is lost
// when instantiation ids of dtors are also tracked
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the comment. Care to explain?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, here I mean that if we do not distinguish different call sites for consumers, we may be able to fuse again. Now this cannot fuse because there are two call sites for the inner function (which turned out to be only a consumer), so two different inner functions are considered to be called at these two call sites, causing strategy clash. This may also be related to the merging of consumers (in the next program in new-todo.mls).

@ychenfo
Copy link
Member Author

ychenfo commented Sep 16, 2025

Superseded by #335

@ychenfo ychenfo closed this Sep 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants