diff --git a/changelog.d/20260713_180352_st_clone.md b/changelog.d/20260713_180352_st_clone.md new file mode 100644 index 0000000..9d5ae27 --- /dev/null +++ b/changelog.d/20260713_180352_st_clone.md @@ -0,0 +1,7 @@ +### Fixed + +- `Data.Array.ST` exports `clone` again: upstream v7.3.0 declares + `clone`/`cloneImpl` (`STFn1`), but the fork carried neither, so code using + `Data.Array.ST.clone` failed to compile against the fork. The Lua module + now provides `cloneImpl`, the same independent copy the FFI already uses + for `thawImpl`/`freezeImpl`. diff --git a/src/Data/Array/ST.lua b/src/Data/Array/ST.lua index c92ddf3..011b5c7 100644 --- a/src/Data/Array/ST.lua +++ b/src/Data/Array/ST.lua @@ -73,6 +73,7 @@ return { unsafeThawImpl = (function(xs) return xs end), freezeImpl = (copyImpl), thawImpl = (copyImpl), + cloneImpl = (copyImpl), sortByImpl = ((function() local function rshift(x, by) return math.floor(x / 2 ^ by) end diff --git a/src/Data/Array/ST.purs b/src/Data/Array/ST.purs index 0e9370f..e1395a8 100644 --- a/src/Data/Array/ST.purs +++ b/src/Data/Array/ST.purs @@ -24,6 +24,7 @@ module Data.Array.ST , sortWith , freeze , thaw + , clone , unsafeFreeze , unsafeThaw , toAssocArray @@ -95,6 +96,15 @@ thaw = runSTFn1 thawImpl -- | Create a mutable copy of an immutable array. foreign import thawImpl :: forall h a. STFn1 (Array a) h (STArray h a) +-- | Make a mutable copy of a mutable array. +clone + :: forall h a + . STArray h a + -> ST h (STArray h a) +clone = runSTFn1 cloneImpl + +foreign import cloneImpl :: forall h a. STFn1 (STArray h a) h (STArray h a) + -- | Sort a mutable array in place. Sorting is stable: the order of equal -- | elements is preserved. sort :: forall a h. Ord a => STArray h a -> ST h (STArray h a) diff --git a/test/regression/array_st.lua b/test/regression/array_st.lua index 0172e65..f370935 100644 --- a/test/regression/array_st.lua +++ b/test/regression/array_st.lua @@ -69,6 +69,15 @@ do check("thawImpl is independent", copy[1] == 1, "copy mutated to " .. tostring(copy[1])) end +-- cloneImpl (the same move-to-fresh-table path) is an independent copy. +do + local xs = {1, 2, 3} + local copy = ST.cloneImpl(xs) + checkArray("cloneImpl copies", copy, {1, 2, 3}) + xs[1] = 99 + check("cloneImpl is independent", copy[1] == 1, "copy mutated to " .. tostring(copy[1])) +end + -- toAssocArrayImpl builds zero-based {index, value} records. do local r = ST.toAssocArrayImpl({"a", "b"})