Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type inference crashes on large pattern (mis)match #54

Open
siddharth-krishna opened this issue Jul 11, 2023 · 0 comments
Open

Type inference crashes on large pattern (mis)match #54

siddharth-krishna opened this issue Jul 11, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@siddharth-krishna
Copy link
Collaborator

let foo =
  fun input0 input1 input2 input3 input4 input5 input6 input7 input8 input9 input10 ->
    let latestValue = fun i -> Some 0.0 in
    match (latestValue input0, latestValue input1, latestValue input2, latestValue input3, latestValue input4, latestValue input5, latestValue input6, latestValue input7, latestValue input8, latestValue input9, latestValue input10, latestValue input0) with {
      | (Some x0, Some x1, Some x2, Some x3, Some x4, Some x5, Some x6, Some x7, Some x8, Some x9, Some x10) ->
        Some (truncateTo 2 (x0 + x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10))
      | _ -> None }
in foo 0 0 0 0 0 0 0 0 0 0 0

This script results in:

inferno: Prelude.undefined
CallStack (from HasCallStack):
  error, called at libraries/base/GHC/Err.hs:74:14 in base:GHC.Err
  undefined, called at src/Inferno/Infer/Error.hs:75:12 in inferno-core-0.3.1-inplace:Inferno.Infer.Error

This only happens when you try to match a 11-tuple with a 12-tuple. For smaller numbers you get the correct type error.

Here's a script to generate such examples:

script = '''
let foo =
fun {funArgs} ->
let latestValue = fun i -> Some 0.0 in
match ({matchArgs}) with {{
| ({pat}) ->
Some (truncateTo 2 ({sum}))
| _ -> None }}
in foo {callArgs}'''
def mk_script(n):
    args = [f'input{i}' for i in range(n)]
    with open('big-match.inferno', 'w') as f:
        f.write(script.format(
            funArgs=' '.join(args),
            matchArgs=', '.join((f'latestValue {i}' for i in args + args[0:1])),
            pat=', '.join((f'Some x{i}' for i in range(n))),
            sum=' + '.join(f'x{i}' for i in range(n)),
            callArgs=' '.join(('0' for i in range(n)))
        ))
mk_script(11)
@siddharth-krishna siddharth-krishna added the bug Something isn't working label Jul 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant