google-research / dex-lang

Research language for array processing in the Haskell/ML family
BSD 3-Clause "New" or "Revised" License
1.58k stars 107 forks source link

"Compiler bug, Unsupported newtype: Nat" when taking grad through `intpow` #1195

Closed emilyfertig closed 1 year ago

emilyfertig commented 1 year ago

I came across this when working on a gradient-based optimization example, using a function that called intpow as a test case.

def f (x:Float) : Float =
  intpow x 2

x = 3.1
f x
> 9.61
grad f x
> Compiler bug!
> Please report this at github.com/google-research/dex-lang/issues
>
> Unsupported newtype: Nat
> CallStack (from HasCallStack):
>   error, called at src/lib/Linearize.hs:515:10 in dex-0.1.0.0-56tlNzHvZd2Epf2TOu8iN7:Linearize
axch commented 1 year ago

Well, the mega-rewrite #1209 did eliminate whatever the Nat problem was, but that just exposed another problem. Fortunately, the other one is easy to work around, which #1210 does.