Ensure top-level binders in scope in SetLevels
Ticket #20200 (closed) (the Agda failure) showed another case in which
lookupIdSubst
would fail to find a local Id in the InScopeSet
.
This time it was because SetLevels
was given a program in which
the top-level bindings were not in dependency order.
The Simplifier
(see Note [Glomming] in GHC.Core.Opt.Occuranal) and
the specialiser (see Note [Top level scope] in GHC.Core.Opt.Specialise)
may both produce top-level bindings where an early binding refers
to a later one.
One solution would be to run the occurrence analyser again to
put them all in the right order. But a simpler one is to make
SetLevels
OK with this input by bringing all top-level binders into
scope at the start. That's what this patch does.