microsoft / knossos-ksc

Compiler with automatic differentiation
Other
45 stars 10 forks source link

Do not generate structured bindings #984

Closed dcrc2 closed 2 years ago

dcrc2 commented 2 years ago

Replace structured bindings with explicit calls to ks::get. This should be exactly equivalent, and avoids compile errors when using nvcc (which incorrectly rejects lambdas which capture a structured binding).

Before:

ty$fwd$add$aff fwd$add$aff(ks::allocator * $alloc, ks::Tuple<ks::Float,ks::Float> xt, ks::Tuple<ks::Float,ks::Float> dxt) {
  auto [dx1, dx2] = dxt;
  ks::Float c$0 = add$aff($alloc, dx1, dx2);
  return (c$0);
}

After:

ty$fwd$add$aff fwd$add$aff(ks::allocator * $alloc, ks::Tuple<ks::Float,ks::Float> xt, ks::Tuple<ks::Float,ks::Float> dxt) {
  ks::Tuple<ks::Float,ks::Float> c$1 = dxt;
  auto dx1 = ks::get<0>(c$1);
  auto dx2 = ks::get<1>(c$1);
  ks::Float c$0 = add$aff($alloc, dx1, dx2);
  return (c$0);
}
dcrc2 commented 2 years ago

I don't feel I've written this very cleanly - any suggestions @toelli-msft ?

toelli-msft commented 2 years ago

Seems clear enough relative to the standards of Cgen.