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

Optimiser η-contraction makes mutual recursion too strict #286

@plt-amy

Description

@plt-amy
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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    OptimiserIssues and PRs relating to the optimiserX-soundnessSoundness bugs.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions