Gradualizer icon indicating copy to clipboard operation
Gradualizer copied to clipboard

Don't let normalize recurse into element types

Open zuiderkwast opened this issue 3 years ago • 4 comments

... or "Make normalize head normal form again"

zuiderkwast avatar Feb 01 '22 17:02 zuiderkwast

Hmm, I don't think it's as simple as that. What about https://github.com/josefs/Gradualizer/blob/0657d76e7de893a2bd7e49e0fac186b732fea434/src/typechecker.erl#L799-L800 https://github.com/josefs/Gradualizer/blob/0657d76e7de893a2bd7e49e0fac186b732fea434/src/typechecker.erl#L802 https://github.com/josefs/Gradualizer/blob/0657d76e7de893a2bd7e49e0fac186b732fea434/src/typechecker.erl#L805 to name a few? I think all of these will lead to broken test cases, though I haven't checked.

erszcz avatar Feb 01 '22 19:02 erszcz

You're right, I've lost it. :sob: I'll have to study this source code from scratch.

Anyway, Head Normal Form is about not recursing fully down the tree. I'm pretty sure it was like that once upon a time, but I don't know since when and why it's not the case anymore.

zuiderkwast avatar Feb 01 '22 20:02 zuiderkwast

It seems I have found a convincing argument not to expand builtin types eagerly and possibly also not to recurse down into element types in normalize - we definitely don't want expected to have type [0..1114111] displayed to the users:

/Users/erszcz/work/jesperes/aoc_erlang/_build/default/lib/aoc_erlang/ebin/aoc_nifs.beam: The function call on line 12 at column 13 is expected to have type [0..1114111] but it has type file:filename_all()

        filename:join("/Users/erszcz/work/jesperes/aoc_erlang/c_src",
                      "aoc_nifs.so"),
    ok = erlang:load_nif(filename:rootname(File), 0).
                         ^^^^^^^^^^^^^^^^^^^^^^^

The above message was caught when revisiting https://github.com/josefs/Gradualizer/issues/360, specifically my fork with fixes for macOS using my Gradualizer master (which incorporates #359 and #380).

erszcz avatar Feb 10 '22 17:02 erszcz

https://github.com/josefs/Gradualizer/blob/0657d76e7de893a2bd7e49e0fac186b732fea434/src/typechecker.erl#L802

https://github.com/josefs/Gradualizer/blob/0657d76e7de893a2bd7e49e0fac186b732fea434/src/typechecker.erl#L805

Apparently, the above can be removed with no tests breaking. It's not that nice with this one, though:

https://github.com/josefs/Gradualizer/blob/0657d76e7de893a2bd7e49e0fac186b732fea434/src/typechecker.erl#L799-L800

Quite a lot started failing when I tried that :/

erszcz avatar Feb 22 '22 08:02 erszcz

I think this can be closed now, WDYT @zuiderkwast?

erszcz avatar Sep 26 '22 09:09 erszcz