> the only question IMO is whether this would be more expensive (at CT) than 
> current TRW, but I don't see why.

It looks equally expensive to me, that's not an improvement. ;-)

In my opinion the optimization needs an explicit _anchor_ point. Like so:
    
    
    proc `*`(x, y: Matrix): Matrix {.anchor: matrixMul.} = ...
    proc `+`(x, y: Matrix): Matrix {.anchor: matrixAdd.} = ...
    
    macro matrixAdd(n: NimNode): NimNode =
      # turn (a * b) + c  into  `*+`(a, b, c)
      if n[0].matches(matrixMul):
        result = newCall("*+", a, b, c)
      else:
        result = nil # no match
    
    
    
    Run

Reply via email to