-
Notifications
You must be signed in to change notification settings - Fork 17
Closed
Labels
type: bugSomething that should function correctly isn't.Something that should function correctly isn't.
Description
First of all, thanks for all your work on keeping the PureScript ecosystem up and running!
We recently upgraded from PS 0.11 to 0.12 and ran into the following regression Foreign.Object.fromFoldable
(vs the old Data.StrMap.fromFoldable
) causes a stack overflow for large inputs in Google Chrome (Safari and FF seemed to have higher limits):
❌ Repro: PureScript 0.12
module Main where
import Prelude
import Effect (Effect)
import Effect.Console (log)
import Data.Array ((..))
import Data.Tuple (Tuple(..))
import Foreign.Object as Object
main :: Effect Unit
main = do
let m = Object.fromFoldable $ do
x <- 1 .. 10000
pure $ Tuple (show x) x
log $ show m
Error
foreign.js:22 Uncaught RangeError: Maximum call stack size exceeded
at foreign.js:22
at foreign.js:6
at foreign.js:20
at foreign.js:20
at foreign.js:20
at foreign.js:20
at foreign.js:20
at foreign.js:20
at foreign.js:20
at foreign.js:20
✅ PureScript 0.11
Paste this into Try PureScript and observe that there is no stack overflow:
module Main where
import Prelude
import Control.Monad.Eff (Eff)
import Data.Array ((..))
import Data.Tuple (Tuple(..))
import Data.Foldable (fold)
import TryPureScript (DOM, h1, h2, p, text, list, indent, link, render, code)
import Data.StrMap as SM
main :: Eff (dom :: DOM) Unit
main = do
let m = SM.fromFoldable $ do
x <- 1 .. 10000
pure $ Tuple (show x) x
render $ fold
[ p (text $ show m) ]
Observations
Superficially the two implementations look the same except the addition of Array.fromFoldable
, but I confirmed removing it doesn’t change the outcome:
- PS 0.11: https://github.com/purescript-deprecated/purescript-maps/blob/c1a826b13ae681f523dcd0f93c5ee422b1e49072/src/Data/StrMap.purs#L195-L200
- PS 0.12:
purescript-foreign-object/src/Foreign/Object.purs
Lines 212 to 217 in 6c5c386
-- | Create a map from a foldable collection of key/value pairs fromFoldable :: forall f a. Foldable f => f (Tuple String a) -> Object a fromFoldable l = runST do s <- OST.new for_ (A.fromFoldable l) \(Tuple k v) -> OST.poke k v s pure s
mcordova47, justinwoo, CristhianMotoche and garyb
Metadata
Metadata
Assignees
Labels
type: bugSomething that should function correctly isn't.Something that should function correctly isn't.