Skip to content

Lua.fromIR: topLevelNames parameter is always empty, guarded branches are dead code #146

Description

@Unisay

Problem

Every production call of fromIR in fromUberModule (lib/Language/PureScript/Backend/Lua.hs) passes Set.empty for the topLevelNames parameter, so both branches guarded by Set.member ... topLevelNames (the special case in IR.Ref and the qualified local names in the Let/RecursiveGroup lowering) are dead code.

Beyond the noise, the dead Ref branch is a trap: it matches a Local name against top-level names while ignoring the reference's index, so if anyone ever passes a non-empty set, a local that shadows a top-level name would silently compile to an M.field access.

Approach

Remove the topLevelNames parameter and both guarded branches. This eliminates the trap and simplifies the fromIR signature.

Prerequisites / Relations

Dead-code / codegen cleanup, found during the 2026-07-02 backend audit. Independent. Resolves a hypothesis from the #37 session notes: the miscapture is not reachable today precisely because the set is always empty.

Verification / Measurement

The removal is behaviour-preserving — the structural and eval goldens are unchanged, confirming the branches were genuinely dead — and the Local-shadows-top-level miscompilation trap is no longer reachable because the code path no longer exists.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: codegenLua code generation / printingenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions