Fix StgLint bound id check, generalize StgLint

Authored by osa1 on Dec 7 2018, 10:23 PM.

Description

Fix StgLint bound id check, generalize StgLint

StgLint was incorrectly using isLocalId for bound id check to see
whether an id is imported (in which case we don't expect it to be bound)
or local. The problem with isLocalId is that its semantics changes
after Core, as explained in the note: (last line)

Note [GlobalId/LocalId]
~~~~~~~~~~~~~~~~~~~~~~~
A GlobalId is
  * always a constant (top-level)
  * imported, or data constructor, or primop, or record selector
  * has a Unique that is globally unique across the whole
    GHC invocation (a single invocation may compile multiple
    modules)
  * never treated as a candidate by the free-variable finder;
        it's a constant!

A LocalId is
  * bound within an expression (lambda, case, local let(rec))
  * or defined at top level in the module being compiled
  * always treated as a candidate by the free-variable finder

After CoreTidy, top-level LocalIds are turned into GlobalIds

We now pass current module as a parameter to StgLint, which uses it to
see if an id should be bound (defined in the current module) or not
(imported).

Other changes:

  • Generalized StgLint to make it work on both StgTopBinding and CgStgTopBinding.
  • Bring all top-level binders into scope before linting top-level bindings to allow uses before definitions.

TODO: We should remove the binder from local vars when checking RHSs of
non-recursive bindings.

Test Plan: This validates.

Reviewers: simonpj, bgamari, sgraf

Reviewed By: simonpj, sgraf

Subscribers: rwbarton, carter

Differential Revision: https://phabricator.haskell.org/D5370

Details

Committed
bgamariDec 7 2018, 10:23 PM
Reviewer
simonpj
Differential Revision
D5370: Fix StgLint bound id check, generalize StgLint
Parents
rGHC57c9b1ae4caf: Fix #15369: GHCi doesn't honor :set +c when loading for a second time
Branches
Unknown
Tags
Unknown