Skip to content
This repository has been archived by the owner on Oct 18, 2021. It is now read-only.

Optimiser η-contraction makes mutual recursion too strict #286

Open
plt-amy opened this issue May 21, 2020 · 1 comment
Open

Optimiser η-contraction makes mutual recursion too strict #286

plt-amy opened this issue May 21, 2020 · 1 comment
Labels
Optimiser Issues and PRs relating to the optimiser X-soundness Soundness bugs.

Comments

@plt-amy
Copy link
Member

plt-amy commented May 21, 2020

let x <|> y =
  match x with
  | Some _ -> x
  | None -> y

let chainr1 p op =
  let rec scan =
    let! x = p
    rest x
  and rest x =
    ( let! f = op
      let! y = scan
      pure (f x y)
    ) <|> pure x
  scan

This code oughtta be compiled something like:

  local scan, rest
  scan = bind(dict)(p)(function(x)
     return rest(x)
  end)
  rest = ...

But, nah, amc eta-contracts the fun x -> rest x into just rest, which forces it early, which results in attempt to call nil.

      local scan, rest
      scan = _greater_greater_equals(p, rest)
      rest = function(x)
@plt-amy plt-amy added X-soundness Soundness bugs. Optimiser Issues and PRs relating to the optimiser labels May 21, 2020
@plt-amy
Copy link
Member Author

plt-amy commented May 21, 2020

Repro here

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Optimiser Issues and PRs relating to the optimiser X-soundness Soundness bugs.
Projects
None yet
Development

No branches or pull requests

1 participant