Skip to content

Allow the generalization of non-overloaded simple local binds#414

Open
arossato wants to merge 2 commits intoaugustss:masterfrom
arossato:monomorphism_restriction
Open

Allow the generalization of non-overloaded simple local binds#414
arossato wants to merge 2 commits intoaugustss:masterfrom
arossato:monomorphism_restriction

Conversation

@arossato
Copy link
Contributor

@arossato arossato commented Mar 1, 2026

With the second commit mhs will generalize non-overloaded simple binds like:

main =
  let f = id
  in print (f 5, f True)

I've already illustrated the reason of this proposal in a post, #413, in the discussion section.

This is going, obviously, to affect performance, in some ways. Taking the mhs code base as a reference, the calls to getMetaTyVars will increase from ~384 to ~1745, even though only ~68 will require the subsequent expensive test for type variables in the environment.

The recompilation time:

# Master:
$ ./rebuild.sh  # using gmhs 

real    0m8.018s
user    0m7.626s
sys     0m0.266s

# Generalizing non-overloaded simple binds
$ ./rebuild.sh   # using gmhs 
real    0m8.036s
user    0m7.589s
sys     0m0.289s

Recompiling with mhs doesn't change the numbers significantly, but I'm ashamed to show the numbers I get on my old laptop... ;-)

The first commit is a fix to a quite unnoticeable bug in tcBindGpr': the state is captured after new unification variables are created for the bind's identifiers. While these are nonetheless inserted into the environment, they get skipped by the null qvs check, which checks for meta variables created after the state was captured.

After applying the second commit, though, the bug would be visible in some corner cases in which a bind wouldn't be generalized even if expected, like:

let f = undefined
    x = x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant