Skip to content

Commit 706b791

Browse files
committed
Reapply "More runtime function replacements for Map, Set, Multimap"
This reverts commit 85df4de.
1 parent 55ff063 commit 706b791

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

unison-runtime/src/Unison/Runtime/Builtin.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,8 +1282,16 @@ declareForeigns = do
12821282
declareForeign Untracked 2 Map_lookup
12831283
declareForeign Untracked 1 Map_fromList
12841284
declareForeign Untracked 2 Map_eq
1285+
declareForeign Untracked 2 Map_union
1286+
declareForeign Untracked 2 Map_intersect
1287+
declareForeign Untracked 1 Map_toList
12851288
declareForeign Untracked 2 List_range
12861289
declareForeign Untracked 1 List_sort
1290+
declareForeign Untracked 1 Multimap_fromList
1291+
declareForeign Untracked 1 Set_fromList
1292+
declareForeign Untracked 2 Set_union
1293+
declareForeign Untracked 2 Set_intersect
1294+
declareForeign Untracked 1 Set_toList
12871295

12881296
foreignDeclResults :: (Map ForeignFunc (Sandbox, SuperNormal Symbol))
12891297
foreignDeclResults =

unison-runtime/src/Unison/Runtime/Foreign/Function.hs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -878,13 +878,18 @@ foreignCallHelper = \case
878878
evaluate $ Map.fromList l
879879
Map_eq -> mkForeign $ \(l :: Map Val Val, r :: Map Val Val) ->
880880
pure $ l == r
881+
Map_union -> mkForeign $ \(l :: Map Val Val, r :: Map Val Val) ->
882+
evaluate $ Map.union l r
883+
Map_intersect -> mkForeign $ \(l :: Map Val Val, r :: Map Val Val) ->
884+
evaluate $ Map.intersection l r
885+
Map_toList -> mkForeign $ \(m :: Map Val Val) ->
886+
evaluate . forceListSpine $ Map.toList m
881887
List_range -> mkForeign $ \(m :: Word64, n :: Word64) ->
882888
let sz
883889
| m < n = fromIntegral $ n - m
884890
| otherwise = 0
885891
mk i = NatVal $ m + fromIntegral i
886-
force s = foldl (\u x -> x `seq` u) s s
887-
in evaluate . force $ Sq.fromFunction sz mk
892+
in evaluate . forceListSpine $ Sq.fromFunction sz mk
888893
List_sort -> mkForeign $ \(l :: Seq Val) -> pure $ Sq.unstableSort l
889894
Multimap_fromList -> mkForeign $ \(l :: [(Val, Val)]) -> do
890895
let listVals = l <&> \(k, v) -> (k, Sq.singleton v)
@@ -912,6 +917,7 @@ foreignCallHelper = \case
912917
evaluate . forceListSpine $ Map.keys s
913918
_ -> die "Set.toList: bad closure"
914919
where
920+
forceListSpine xs = foldl (\u x -> x `seq` u) xs xs
915921
chop = reverse . dropWhile isPathSeparator . reverse
916922

917923
hostPreference :: Maybe Util.Text.Text -> SYS.HostPreference
@@ -2108,6 +2114,30 @@ functionReplacementList =
21082114
( "005mc1fq7ojq72c238qlm2rspjgqo2furjodf28icruv316odu6du",
21092115
Map_fromList
21102116
),
2117+
( "01qqpul0ttlgjhr5i2gtmdr2uarns2hbtnjpipmk1575ipkrlug42",
2118+
Map_union
2119+
),
2120+
( "00c363e340il8q0fai6peiv3586o931nojj98qfek09hg1tjkm9ma",
2121+
Map_intersect
2122+
),
2123+
( "03pjq0jijrr7ebf6s3tuqi4d5hi5mrv19nagp7ql2j9ltm55c32ek",
2124+
Map_toList
2125+
),
2126+
( "03putoun7i5n0lhf8iu990u9p08laklnp668i170dka2itckmadlq",
2127+
Multimap_fromList
2128+
),
2129+
( "03q6giac0qlva6u4mja29tr7mv0jqnsugk8paibatdrns8lhqqb92",
2130+
Set_fromList
2131+
),
2132+
( "03362vaalqq28lcrmmsjhha637is312j01jme3juj980ugd93up28",
2133+
Set_union
2134+
),
2135+
( "01lm6ejo31na1ti6u85bv0klliefll7q0c0da2qnefvcrq1l8rlqe",
2136+
Set_intersect
2137+
),
2138+
( "01p7ot36tg62na408mnk1psve6rc7fog30gv6n7thkrv6t3na2gdm",
2139+
Set_toList
2140+
),
21112141
( "03c559iihi2vj0qps6cln48nv31ajup2srhas4pd05b9k46ds8jvk",
21122142
Map_eq
21132143
),

unison-runtime/src/Unison/Runtime/Foreign/Function/Type.hs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,16 @@ data ForeignFunc
260260
| Map_lookup
261261
| Map_fromList
262262
| Map_eq
263+
| Map_union
264+
| Map_intersect
265+
| Map_toList
263266
| List_range
264267
| List_sort
268+
| Multimap_fromList
269+
| Set_fromList
270+
| Set_union
271+
| Set_intersect
272+
| Set_toList
265273
deriving (Show, Eq, Ord, Enum, Bounded)
266274

267275
foreignFuncBuiltinName :: ForeignFunc -> Text
@@ -518,5 +526,13 @@ foreignFuncBuiltinName = \case
518526
Map_lookup -> "Map.lookup"
519527
Map_fromList -> "Map.fromList"
520528
Map_eq -> "Map.=="
529+
Map_union -> "Map.union"
530+
Map_intersect -> "Map.intersect"
531+
Map_toList -> "Map.toList"
521532
List_range -> "List.range"
522533
List_sort -> "List.sort"
534+
Multimap_fromList -> "Multimap.fromList"
535+
Set_fromList -> "Set.fromList"
536+
Set_union -> "Set.union"
537+
Set_intersect -> "Set.intersect"
538+
Set_toList -> "Set.toList"

0 commit comments

Comments
 (0)