Skip to content

Commit c871374

Browse files
committed
* new AList.sub implementation
* fixed ref-warnings with `:=` and `!` * updated test/demo to net6.0
1 parent afc550a commit c871374

20 files changed

Lines changed: 284 additions & 173 deletions

File tree

.config/dotnet-tools.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"isRoot": true,
44
"tools": {
55
"paket": {
6-
"version": "5.257.0",
6+
"version": "7.0.2",
77
"commands": [
88
"paket"
99
]

.vscode/launch.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"type": "coreclr",
1010
"request": "launch",
1111
"preLaunchTask": "build",
12-
"program": "${workspaceFolder}/bin/Debug/netcoreapp3.0/EventInterop.dll",
12+
"program": "${workspaceFolder}/bin/Debug/net6.0/EventInterop.dll",
1313
"args": [],
1414
"cwd": "${workspaceFolder}",
1515
"console": "integratedTerminal",
@@ -20,7 +20,18 @@
2020
"type": "coreclr",
2121
"request": "launch",
2222
"preLaunchTask": "build",
23-
"program": "${workspaceFolder}/bin/Debug/netcoreapp3.0/CSharpInterop.dll",
23+
"program": "${workspaceFolder}/bin/Debug/net6.0/CSharpInterop.dll",
24+
"args": [],
25+
"cwd": "${workspaceFolder}",
26+
"console": "integratedTerminal",
27+
"stopAtEntry": false
28+
},
29+
{
30+
"name": "Tests",
31+
"type": "coreclr",
32+
"request": "launch",
33+
"preLaunchTask": "build",
34+
"program": "${workspaceFolder}/bin/Debug/net6.0/FSharp.Data.Adaptive.Tests.dll",
2435
"args": [],
2536
"cwd": "${workspaceFolder}",
2637
"console": "integratedTerminal",

paket.lock

Lines changed: 83 additions & 83 deletions
Large diffs are not rendered by default.

src/Demo/CSharpInterop/CSharpInterop.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<LangVersion>8</LangVersion>
6-
<TargetFramework>netcoreapp3.1</TargetFramework>
6+
<TargetFramework>net6.0</TargetFramework>
77
</PropertyGroup>
88
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
99
<OutputPath>..\..\..\bin\Release\</OutputPath>

src/Demo/EventInterop/EventInterop.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project Sdk="Microsoft.NET.Sdk">
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
<TargetFramework>net6.0</TargetFramework>
66
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
77
</PropertyGroup>
88
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

src/Demo/FileSystem/FileSystem.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project Sdk="Microsoft.NET.Sdk">
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
<TargetFramework>net6.0</TargetFramework>
66
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
77
</PropertyGroup>
88
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">

src/FSharp.Data.Adaptive/AdaptiveHashMap/AdaptiveHashMap.fs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -660,13 +660,13 @@ module AdaptiveHashMapImplementation =
660660
let lv =
661661
match lop with
662662
| ValueSome (Set lv) -> ValueSome lv
663-
| ValueSome (Remove) -> ValueNone
663+
| ValueSome Remove -> ValueNone
664664
| ValueNone -> lReader.State.TryFindV key
665665

666666
let rv =
667667
match rop with
668668
| ValueSome (Set rv) -> ValueSome rv
669-
| ValueSome (Remove) -> ValueNone
669+
| ValueSome Remove -> ValueNone
670670
| ValueNone -> rReader.State.TryFindV key
671671

672672
match lv, rv with
@@ -678,6 +678,7 @@ module AdaptiveHashMapImplementation =
678678

679679
HashMap.choose2V merge lops.Store rops.Store |> HashMapDelta
680680

681+
681682
/// Reader for mapA operations.
682683
[<Sealed>]
683684
type MapAReader<'k, 'a, 'b>(input : amap<'k, 'a>, mapping : 'k -> 'a -> aval<'b>) =
@@ -1395,16 +1396,16 @@ module AMap =
13951396
let set =
13961397
ofReader (fun () ->
13971398
let r = new MapUseReader<'K, 'A, 'B>(map, mapping)
1398-
reader := Some r
1399+
reader.Value <- Some r
13991400
r
14001401
)
14011402
let disp =
14021403
{ new System.IDisposable with
14031404
member x.Dispose() =
1404-
match !reader with
1405+
match reader.Value with
14051406
| Some r ->
14061407
r.Dispose()
1407-
reader := None
1408+
reader.Value <- None
14081409
| None ->
14091410
()
14101411
}

src/FSharp.Data.Adaptive/AdaptiveHashSet/AdaptiveHashSet.fs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ module AdaptiveHashSetImplementation =
966966
let v = m.GetValue token
967967
match cache.TryGetValue m with
968968
| (true, r) ->
969-
r := (fst !r + 1, v)
969+
r.Value <- (fst r.Value + 1, v)
970970
| _ ->
971971
let r = ref (1, v)
972972
cache.[m] <- r
@@ -976,23 +976,23 @@ module AdaptiveHashSetImplementation =
976976
member x.Invoke2(token : AdaptiveToken, m : aval<'B>) =
977977
let r = cache.[m]
978978
let v = m.GetValue token
979-
let (rc, o) = !r
980-
r := (rc, v)
979+
let (rc, o) = r.Value
980+
r.Value <- (rc, v)
981981
o, v
982982

983983
member x.Revoke(v : 'A, dirty : System.Collections.Generic.HashSet<_>) =
984984
let m = mapping.Revoke v
985985

986986
match cache.TryGetValue m with
987987
| (true, r) ->
988-
let (cnt, v) = !r
988+
let (cnt, v) = r.Value
989989
if cnt = 1 then
990990
cache.Remove m |> ignore
991991
dirty.Remove m |> ignore
992992
lock m (fun () -> m.Outputs.Remove x |> ignore )
993993
v
994994
else
995-
r := (cnt - 1, v)
995+
r.Value <- (cnt - 1, v)
996996
v
997997
| _ ->
998998
failwith "[ASet] cannot remove unknown object"
@@ -1031,7 +1031,7 @@ module AdaptiveHashSetImplementation =
10311031

10321032
match cache.TryGetValue m with
10331033
| (true, r) ->
1034-
r := (fst !r + 1, v)
1034+
r.Value <- (fst r.Value + 1, v)
10351035
| _ ->
10361036
let r = ref (1, v)
10371037
cache.[m] <- r
@@ -1042,9 +1042,9 @@ module AdaptiveHashSetImplementation =
10421042
member x.Invoke2(token : AdaptiveToken, m : aval<option<'B>>) =
10431043
match cache.TryGetValue m with
10441044
| (true, r) ->
1045-
let (rc, o) = !r
1045+
let (rc, o) = r.Value
10461046
let v = m.GetValue token
1047-
r := (rc, v)
1047+
r.Value <- (rc, v)
10481048
o, v
10491049
| _ ->
10501050
None, None
@@ -1053,12 +1053,12 @@ module AdaptiveHashSetImplementation =
10531053
let m = f.Revoke v
10541054
match cache.TryGetValue m with
10551055
| (true, r) ->
1056-
let (rc, v) = !r
1056+
let (rc, v) = r.Value
10571057
if rc = 1 then
10581058
cache.Remove m |> ignore
10591059
lock m (fun () -> m.Outputs.Remove x |> ignore )
10601060
else
1061-
r := (rc - 1, v)
1061+
r.Value <- (rc - 1, v)
10621062
v
10631063
| _ ->
10641064
failwith "[ASet] cannot remove unknown object"
@@ -1356,16 +1356,16 @@ module ASet =
13561356
let set =
13571357
ofReader (fun () ->
13581358
let r = new MapUseReader<'A, 'B>(set, mapping)
1359-
reader := Some r
1359+
reader.Value <- Some r
13601360
r
13611361
)
13621362
let disp =
13631363
{ new System.IDisposable with
13641364
member x.Dispose() =
1365-
match !reader with
1365+
match reader.Value with
13661366
| Some r ->
13671367
r.Dispose()
1368-
reader := None
1368+
reader.Value <- None
13691369
| None ->
13701370
()
13711371
}

src/FSharp.Data.Adaptive/AdaptiveIndexList/AdaptiveIndexList.fs

Lines changed: 98 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,6 +1193,100 @@ module internal AdaptiveIndexListImplementation =
11931193

11941194
delta
11951195

1196+
[<Sealed>]
1197+
type NewSubReader<'a>(input : alist<'a>, offset : aval<int>, count : aval<int>) =
1198+
inherit AbstractReader<IndexListDelta<'a>>(IndexListDelta.empty)
1199+
1200+
let reader = input.GetReader()
1201+
let mutable state = MapExt.empty
1202+
let mutable minIndex = Index.zero
1203+
let mutable maxIndex = Index.zero
1204+
1205+
override x.Compute(token) =
1206+
let ops = reader.GetChanges token
1207+
let offset = offset.GetValue token
1208+
let count = count.GetValue token
1209+
1210+
let newMinIndex = reader.State.TryGetIndexV offset
1211+
let newMaxIndex = reader.State.TryGetIndexV (offset + count - 1)
1212+
if ValueOption.isSome newMinIndex then
1213+
let newMinIndex = ValueOption.get newMinIndex
1214+
let newMaxIndex =
1215+
match newMaxIndex with
1216+
| ValueSome i -> i
1217+
| ValueNone -> reader.State.MaxIndex
1218+
1219+
if MapExt.isEmpty state then
1220+
let resultRange = reader.State.Content.[newMinIndex .. newMaxIndex]
1221+
let delta = resultRange |> MapExt.map (fun _ v -> Set v) |> IndexListDelta
1222+
state <- resultRange
1223+
minIndex <- newMinIndex
1224+
maxIndex <- newMaxIndex
1225+
delta
1226+
elif newMinIndex > maxIndex || newMaxIndex < minIndex then
1227+
let resultRange = reader.State.Content.[newMinIndex .. newMaxIndex]
1228+
let delta =
1229+
IndexListDelta (
1230+
MapExt.union
1231+
(state |> MapExt.map (fun _ _ -> Remove))
1232+
(resultRange |> MapExt.map (fun _ v -> Set v))
1233+
)
1234+
state <- resultRange
1235+
minIndex <- newMinIndex
1236+
maxIndex <- newMaxIndex
1237+
delta
1238+
1239+
else
1240+
let mutable delta = ops.Content.Slice(minIndex, maxIndex)
1241+
let l, d = IndexList.applyDelta (IndexList(minIndex, maxIndex, state)) (IndexListDelta delta)
1242+
state <- l.Content
1243+
delta <- d.Content
1244+
minIndex <- l.MinIndex
1245+
maxIndex <- l.MaxIndex
1246+
1247+
if minIndex > newMinIndex then
1248+
let newBefore = reader.State.Content.Slice(newMinIndex, true, minIndex, false)
1249+
delta <- MapExt.union (newBefore |> MapExt.map (fun _ v -> Set v)) delta
1250+
state <- MapExt.union newBefore state
1251+
minIndex <- newMinIndex
1252+
elif newMinIndex > minIndex then
1253+
let (dropFront, s, newState) = state.Split newMinIndex
1254+
let newState =
1255+
match s with
1256+
| Some v -> MapExt.add newMinIndex v newState
1257+
| None -> newState
1258+
1259+
delta <- MapExt.union (dropFront |> MapExt.map (fun _ _ -> Remove)) delta
1260+
state <- newState
1261+
minIndex <- newMinIndex
1262+
1263+
1264+
if maxIndex > newMaxIndex then
1265+
let (newState, s, dropBack) = state.Split newMaxIndex
1266+
let newState =
1267+
match s with
1268+
| Some v -> MapExt.add newMaxIndex v newState
1269+
| None -> newState
1270+
1271+
delta <- MapExt.union (dropBack |> MapExt.map (fun _ _ -> Remove)) delta
1272+
state <- newState
1273+
maxIndex <- newMaxIndex
1274+
elif newMaxIndex > maxIndex then
1275+
let newAfter = reader.State.Content.Slice(maxIndex, false, newMaxIndex, true)
1276+
delta <- MapExt.union (newAfter |> MapExt.map (fun _ v -> Set v)) delta
1277+
state <- MapExt.union newAfter state
1278+
maxIndex <- newMaxIndex
1279+
1280+
IndexListDelta delta
1281+
elif not (MapExt.isEmpty state) then
1282+
let delta = state |> MapExt.map (fun _ _ -> Remove) |> IndexListDelta.ofMap
1283+
state <- MapExt.empty
1284+
minIndex <- Index.zero
1285+
maxIndex <- Index.zero
1286+
delta
1287+
else
1288+
IndexListDelta.empty
1289+
11961290
[<Sealed>]
11971291
type SubReader<'a>(input : alist<'a>, offset : aval<int>, count : aval<int>) =
11981292
inherit AbstractReader<IndexListDelta<'a>>(IndexListDelta.empty)
@@ -1582,16 +1676,16 @@ module AList =
15821676
let set =
15831677
ofReader (fun () ->
15841678
let r = new MapUseReader<'A, 'B>(list, mapping)
1585-
reader := Some r
1679+
reader.Value <- Some r
15861680
r
15871681
)
15881682
let disp =
15891683
{ new System.IDisposable with
15901684
member x.Dispose() =
1591-
match !reader with
1685+
match reader.Value with
15921686
| Some r ->
15931687
r.Dispose()
1594-
reader := None
1688+
reader.Value <- None
15951689
| None ->
15961690
()
15971691
}
@@ -1672,7 +1766,7 @@ module AList =
16721766
let count = AVal.force count
16731767
constant (fun () -> (force list).Content.SliceAt(offset, offset + count - 1) |> IndexList.ofMap)
16741768
else
1675-
ofReader (fun () -> SubReader(list, offset, count))
1769+
ofReader (fun () -> NewSubReader(list, offset, count))
16761770

16771771
let sub (offset: int) (count: int) (list: alist<'T>) =
16781772
subA (AVal.constant offset) (AVal.constant count) list

0 commit comments

Comments
 (0)