-
Notifications
You must be signed in to change notification settings - Fork 40
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
microlens-th is not deterministic #83
Comments
microlens-th uses code from lens, and so this issue applies to lens too. I can fix it by pairing the set with a list or by implementing an ordered set in some other way, but then when lens fixes the issue as well I'd have to scrap my solution and copy theirs (because I want to keep my code in sync with lens's code for easier merging). @glguy (the author of the original TH code) is already aware of the issue, but I suggest you file an issue at lens's bug tracker anyway so that it wouldn't be forgotten accidentally. |
Thank you! |
Note: I'm doing creating this issue to raise awareness and to determine if this is something that could be fixed on microlens-th side.
Background: For various reasons it's desirable to have GHC produce ABI-compatible binaries given the same input, flags and the environment.
Now, TemplateHaskell gives no guarantees about this, you could generate different code depending on the phase of the moon.
As it turns out
microlens-th
is unintentionally nondeterministic. There's no code that accesses the environment nor does some suspect thing and yet, it will not always produce the same code in the same conditions.The core of the issue is that GHC exposes a bit more about the internals than it should. Its
Name
type holds aUnique
. For various reasonsUniques
are not stable across recompilations. As it happens theOrd
instance forName
is based onUnique
meaning that the relative orderNames
might change between compilations.As it happens
microlens-th
holds aSet/Map
of these names that later determines the order of type variables in the generated definition.There are multiple valid stances to take here:
Now I'm leaning towards 2., but the problem with that approach is that the soonest this can get fixed is for GHC 8.2, which is probably a year away.
Related discussions:
https://mail.haskell.org/pipermail/ghc-devs/2016-May/012163.html
https://mail.haskell.org/pipermail/ghc-devs/2016-June/012181.html
The text was updated successfully, but these errors were encountered: