Problem
Found while linting pslua-generated Lua in a downstream application (OpenResty, with luacheck and lua-language-server). Cosmetic only: the code runs and passes luac -p. Re-confirmed on current main.
pslua correctly narrows a foreign module's exported table to the fields actually used, but the top-level local function helpers in the FFI file body are emitted verbatim even when only the dropped exports referenced them. A module that uses only Data.Int.toNumber emits:
local Data_Int_foreign = (function()
local function toInt32(n) … end -- dead: only fromStringAsImpl/toStringAs used it
local function digitValue(c) … end -- dead: same
return { toNumber = function(n) return n end } -- export table narrowed to the one used field
end)()
The return table is narrowed (good), but toInt32 and digitValue are now unreachable and still shipped. Root cause: export-table narrowing does not drive a DCE pass over the foreign body's own local bindings.
Approach
After narrowing the export table, drop foreign-body locals unreachable from the retained exports.
Prerequisites / Relations
None. Extends the existing foreign export-table narrowing.
Verification / Measurement
The Data.Int example ships without toInt32/digitValue when only toNumber is used; generated output is smaller and still passes luac -p. Low priority: dead code plus a little size bloat, not incorrect.
Problem
Found while linting pslua-generated Lua in a downstream application (OpenResty, with luacheck and lua-language-server). Cosmetic only: the code runs and passes
luac -p. Re-confirmed on currentmain.pslua correctly narrows a foreign module's exported table to the fields actually used, but the top-level
local functionhelpers in the FFI file body are emitted verbatim even when only the dropped exports referenced them. A module that uses onlyData.Int.toNumberemits:The return table is narrowed (good), but
toInt32anddigitValueare now unreachable and still shipped. Root cause: export-table narrowing does not drive a DCE pass over the foreign body's ownlocalbindings.Approach
After narrowing the export table, drop foreign-body locals unreachable from the retained exports.
Prerequisites / Relations
None. Extends the existing foreign export-table narrowing.
Verification / Measurement
The
Data.Intexample ships withouttoInt32/digitValuewhen onlytoNumberis used; generated output is smaller and still passesluac -p. Low priority: dead code plus a little size bloat, not incorrect.