When `:set mono-binds=on`, any local definitions lacking type
signatures will not be generalized (i.e., will be monomorphic). This
reduces what is in most cases unnecessary polymorphism that can give
rise to constraints that are difficult to solve. This also improves
the performance of the Cryptol interpreter by lifting many polymorphic
type applications out of the inner loops that are commonly defined as
bindings in `where` clauses.
The flag is on by default in the Cryptol REPL, and in most cases makes
it possible to leave out more type signatures in `where` clauses than
before. However, some programs really do rely on inferring polymorphic
types for local variables; in this case adding an explicit polymorphic
type signature to the local binding in question will make the program
typecheck.
This makes it easier to get the behavior of the TVars instance under control,
as we can choose to only apply the substitution to the values of the map after
first applying it to the keys, and thus possibly removing redundant goals.
mono-binds/test03 is no longer a really relevant test since mono-binds
doesn't do any generalization. However I fixed up the type signature
and updated the output in case it becomes relevant again in the
future.
issues/issue225 is fine, but work on the master branch increased the
verbosity of constraint solver failures when mono-binds is off. It
still works fine when we monomorphize the local definition.
The Smtlib solver was translating Fin constraints to True, as it didn't know
how to handle them. They should have been skipped, and returned back as
unsolved goals instead.
Tracking the closed environment was tricky, and it wasn't clear how easy it
would be to find free type variables in bindings that lack signatures, as we
don't kind check the AST before making the decision about making it monomorphic.
It was possible to exploit shadowing to get a name into the closed environment
that wasn't actually closed. The change here is that `partitionClosed` now
returns a completely new closed environment with any shadowed names removed, and
that environment is used when checking the declarations it describes, instead.
Setting `mono-binds` to `yes` will cause bindings to be made monomorphic when
they don't refer to closed values, and setting `mono-binds` to no will cause
them to always be generalized.