Skip to content

fix: restore the STFn calling convention in the Data.Array.ST FFI - #3

Merged
Unisay merged 1 commit into
masterfrom
issue-186/st-ffi-names
Jul 13, 2026
Merged

fix: restore the STFn calling convention in the Data.Array.ST FFI#3
Unisay merged 1 commit into
masterfrom
issue-186/st-ffi-names

Conversation

@Unisay

Copy link
Copy Markdown
Collaborator

Problem

The .purs side has declared thawImpl/freezeImpl/toAssocArrayImpl (STFn1) since the upstream STFn migration, but Data/Array/ST.lua still exported only the pre-migration names thaw/freeze/toAssocArray, in the old curried+thunk shape. The declared foreigns were unbound, so thaw, freeze, withArray and toAssocArray crashed with "attempt to call … a nil value" in the released v7.4.1. In the same migration, peekImpl (declared STFn4) kept an inner thunk, so peek returned a function instead of the Maybe.

Found by the FFI audit in purescript-lua/purescript-lua#186. It stayed invisible because the regression guard called the stale ST.freeze(xs)() export directly, and no compiler golden exercises these functions.

Change

  • Data/Array/ST.lua: export thawImpl/freezeImpl (the existing copyImpl, now performing the copy directly) and toAssocArrayImpl; unwrap peekImpl so it returns its result on the 4-ary call; drop the stale thaw/freeze/toAssocArray entries.
  • test/regression/array_st.lua: the guard now drives all four entries through the STFn convention (n-ary call performs the effect, result returned directly, *Impl names). It was red against the old FFI (nil call on freezeImpl) and is green after the reshape.

Verification

scripts/test green (regression suites for ST and NonEmpty). Reproduction against the released code, exactly as a compiled program calls it: runSTFn1(ST.thawImpl)({1,2,3})() crashed before ("attempt to call upvalue 'fn' (a nil value)") and returns the copied table after; ST.peekImpl(just, nothing, 1, {10,20,30}) returned a function before and returns Just 20 after.

Suggested release: patch (v7.4.2) plus a package-set bump.

Refs purescript-lua/purescript-lua#186.

The PureScript side has declared thawImpl/freezeImpl/toAssocArrayImpl
(STFn1) since the upstream STFn migration, but the Lua module still
exported only the pre-migration names thaw/freeze/toAssocArray in the
curried+thunk shape, leaving the declared foreigns unbound: thaw,
freeze, withArray and toAssocArray crashed with a nil call. peekImpl
(STFn4) returned an inner thunk instead of its result, so peek produced
a function instead of the Maybe. Rename the exports to the *Impl names,
perform the effects directly on the n-ary call, and pin the STFn
convention in the regression guard.
Refs purescript-lua/purescript-lua#186.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@Unisay