on master help sign in
use alternate strategy for creating fake names
5a04e5dEvan Czaplicki
compiler/src/Data/Name.hs+31−30
@@ -288,42 +288,43 @@ fromTypeVariableScheme scheme =
288
288
289
289
290-- FROM MANY NAMES
290-- 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)
291
300
292
301
293fromManyNames :: [Name] -> Name
302fromManyNames :: [Name] -> Name
294fromManyNames names =
303fromManyNames 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 =
312 case names of
304 case names of
313 [] ->
305 [] ->
314− s
306+ error "trying to use fromManyNames on an empty list"
315−
307+
316− (Utf8.Utf8 ba#) : names ->
308+ Utf8.Utf8 ba# : _ ->
317− case writeWord8Array# mba# offset# 0x24## {- $ -} s of
318− s ->
319− let
309+ let
320− !offset1# = offset# +# 1#
321− !len# = sizeofByteArray# ba#
310+ len# = sizeofByteArray# ba#
322− !newOffset# = offset1# +# len#
323− in
311+ in
324− case copyByteArray# ba# 0# mba# offset1# len# s of
312+ runST
313+ (
314+ ST $ \s ->
315+ case newByteArray# (len# +# 3#) s of
325− s ->
316+ (# s, mba# #) ->
326− writeNames mba# newOffset# names s
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+ )
327
328
328
329
329
330