@@ -288,42 +288,43 @@ fromTypeVariableScheme scheme =
288288
289289
290290-- FROM MANY NAMES
291+--
292+-- Creating a unique name by combining all the subnames can create names
293+-- longer than 256 bytes relatively easily. So instead, the first given name
294+-- (e.g. foo) is prefixed chars that are valid in JS but not Elm (e.g. _M$foo)
295+--
296+-- This should be a unique name since 0.19 disallows shadowing. It would not
297+-- be possible for multiple top-level cycles to include values with the same
298+-- name, so the important thing is to make the cycle name distinct from the
299+-- normal name. Same logic for destructuring patterns like (x,y)
291300
292301
293302fromManyNames :: [Name] -> Name
294303fromManyNames names =
295− let
296− !(I# size#) = sum (map (\(Utf8.Utf8 ba#) -> I# (sizeofByteArray# ba# +# 1#)) names)
297− in
298− runST
299− (
300− ST $ \s ->
301− case newByteArray# size# s of
302− (# s, mba# #) ->
303− case writeNames mba# 0# names s of
304− s ->
305− case unsafeFreezeByteArray# mba# s of
306− (# s, ba# #) -> (# s, Utf8.Utf8 ba# #)
307− )
308−
309−
310−writeNames :: MutableByteArray# s -> Int# -> [Name] -> State# s -> State# s
311−writeNames mba# !offset# names s =
312304 case names of
313305 [] ->
314− s
315−
316− (Utf8.Utf8 ba#) : names ->
317− case writeWord8Array# mba# offset# 0x24## {- $ -} s of
318− s ->
319− let
320− !offset1# = offset# +# 1#
321− !len# = sizeofByteArray# ba#
322− !newOffset# = offset1# +# len#
323− in
324− case copyByteArray# ba# 0# mba# offset1# len# s of
325− s ->
326− writeNames mba# newOffset# names s
306+ error "trying to use fromManyNames on an empty list"
307+
308+ Utf8.Utf8 ba# : _ ->
309+ let
310+ len# = sizeofByteArray# ba#
311+ in
312+ runST
313+ (
314+ ST $ \s ->
315+ case newByteArray# (len# +# 3#) s of
316+ (# s, mba# #) ->
317+ case writeWord8Array# mba# 0# 0x5F## {-_-} s of
318+ s ->
319+ case writeWord8Array# mba# 1# 0x4D## {-M-} s of
320+ s ->
321+ case writeWord8Array# mba# 2# 0x24## {-$-} s of
322+ s ->
323+ case copyByteArray# ba# 0# mba# 3# len# s of
324+ s ->
325+ case unsafeFreezeByteArray# mba# s of
326+ (# s, ba# #) -> (# s, Utf8.Utf8 ba# #)
327+ )
327328
328329
329330