Skip to content

Commit 6b5257d

Browse files
committed
Cache.Revoke -> Cache.TryRevoke
1 parent 32da777 commit 6b5257d

File tree

7 files changed

+185
-124
lines changed

7 files changed

+185
-124
lines changed

RELEASE_NOTES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
### 1.2.25
2+
- Cache.Revoke -> Cache.TryRevoke
3+
14
### 1.2.24
25
- [ShallowEquality] fixed ShallowEqualityComparer union type jump table construction (true case)
36

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

Lines changed: 52 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ module internal MapReductions =
149149
()
150150
| _ ->
151151
match HashMap.tryFind index state with
152-
| Some (oa, ob) -> sum <- sub sum ob
152+
| Some (_oa, ob) -> sum <- sub sum ob
153153
| None -> ()
154154

155155
let b = mapping index a
@@ -236,7 +236,7 @@ module internal MapReductions =
236236

237237
let removeIndex (x : AdaptiveReduceByValue<_,_,_,_,_>) (i : 'k) =
238238
match HashMap.tryRemove i state with
239-
| Some ((oa, ov, o), newState) ->
239+
| Some ((_oa, ov, o), newState) ->
240240
state <- newState
241241
sum <- sub sum o
242242
let rem, newTargets = MultiSetMap.remove ov i targets
@@ -461,7 +461,7 @@ module AdaptiveHashMapImplementation =
461461
Set res
462462
| Remove ->
463463
match HashMap.tryFind k oldState with
464-
| Some value -> cache.RevokeAndGetDeleted value |> ignore
464+
| Some value -> cache.TryRevoke value |> ignore
465465
| None -> () // strange
466466
Remove
467467
)
@@ -477,7 +477,7 @@ module AdaptiveHashMapImplementation =
477477
Set res
478478
| Remove ->
479479
match HashMap.tryFind k oldState with
480-
| Some value -> cache.RevokeAndGetDeleted value |> ignore
480+
| Some value -> cache.TryRevoke value |> ignore
481481
| None -> () // strange
482482
Remove
483483
) |> HashMapDelta
@@ -609,7 +609,7 @@ module AdaptiveHashMapImplementation =
609609
match HashMap.tryFind k oldState with
610610
| Some ov ->
611611
livingKeys.Remove k |> ignore
612-
cache.Revoke ov |> ignore
612+
cache.TryRevoke ov |> ignore
613613
Some Remove
614614
| _ ->
615615
None
@@ -634,7 +634,7 @@ module AdaptiveHashMapImplementation =
634634
match HashMap.tryFind k oldState with
635635
| Some ov ->
636636
livingKeys.Remove k |> ignore
637-
cache.Revoke ov |> ignore
637+
cache.TryRevoke ov |> ignore
638638
Some Remove
639639
| _ ->
640640
None
@@ -728,10 +728,13 @@ module AdaptiveHashMapImplementation =
728728
| Set v ->
729729
match HashMap.tryFind i old with
730730
| Some o ->
731-
let o = cache.Revoke(i, o)
732-
let rem, rest = MultiSetMap.remove o i targets
733-
targets <- rest
734-
if rem then o.Outputs.Remove x |> ignore
731+
match cache.TryRevoke(i, o) with
732+
| ValueSome o ->
733+
let rem, rest = MultiSetMap.remove o i targets
734+
targets <- rest
735+
if rem then o.Outputs.Remove x |> ignore
736+
| ValueNone ->
737+
()
735738
| None ->
736739
()
737740

@@ -742,11 +745,14 @@ module AdaptiveHashMapImplementation =
742745
| Remove ->
743746
match HashMap.tryFind i old with
744747
| Some v ->
745-
let o = cache.Revoke(i, v)
746-
let rem, r = MultiSetMap.remove o i targets
747-
targets <- r
748-
if rem then o.Outputs.Remove x |> ignore
749-
Some Remove
748+
match cache.TryRevoke(i, v) with
749+
| ValueSome o ->
750+
let rem, r = MultiSetMap.remove o i targets
751+
targets <- r
752+
if rem then o.Outputs.Remove x |> ignore
753+
Some Remove
754+
| ValueNone ->
755+
None
750756
| None ->
751757
None
752758
)
@@ -806,10 +812,13 @@ module AdaptiveHashMapImplementation =
806812
| Set v ->
807813
match HashMap.tryFind i old with
808814
| Some o ->
809-
let o = cache.Revoke(i, o)
810-
let rem, rest = MultiSetMap.remove o i targets
811-
targets <- rest
812-
if rem then o.Outputs.Remove x |> ignore
815+
match cache.TryRevoke(i, o) with
816+
| ValueSome o ->
817+
let rem, rest = MultiSetMap.remove o i targets
818+
targets <- rest
819+
if rem then o.Outputs.Remove x |> ignore
820+
| ValueNone ->
821+
()
813822
| None ->
814823
()
815824

@@ -826,13 +835,16 @@ module AdaptiveHashMapImplementation =
826835
| Remove ->
827836
match HashMap.tryFind i old with
828837
| Some v ->
829-
let o = cache.Revoke(i, v)
830-
let rem, rest = MultiSetMap.remove o i targets
831-
targets <- rest
832-
if rem then o.Outputs.Remove x |> ignore
833-
834-
if keys.Remove i then Some Remove
835-
else None
838+
match cache.TryRevoke(i, v) with
839+
| ValueSome o ->
840+
let rem, rest = MultiSetMap.remove o i targets
841+
targets <- rest
842+
if rem then o.Outputs.Remove x |> ignore
843+
844+
if keys.Remove i then Some Remove
845+
else None
846+
| ValueNone ->
847+
None
836848
| None ->
837849
None
838850
)
@@ -1128,17 +1140,20 @@ module AdaptiveHashMapImplementation =
11281140
state.[k] <- newSet
11291141
delta <- MapNode.addInPlace' cmp k (Set (view newSet)) delta
11301142
elif d.Count = -1 then // <= -1 ??
1131-
let k = cache.Revoke v
1132-
match state.TryGetValue k with
1133-
| (true, set) ->
1134-
let newSet = HashSet.remove v set
1135-
if newSet.IsEmpty then
1136-
state.Remove k |> ignore
1137-
delta <- MapNode.addInPlace' cmp k (Remove : ElementOperation<'View>) delta
1138-
else
1139-
state.[k] <- newSet
1140-
delta <- MapNode.addInPlace' cmp k (Set (view newSet)) delta
1141-
| _ ->
1143+
match cache.TryRevoke v with
1144+
| ValueSome k ->
1145+
match state.TryGetValue k with
1146+
| (true, set) ->
1147+
let newSet = HashSet.remove v set
1148+
if newSet.IsEmpty then
1149+
state.Remove k |> ignore
1150+
delta <- MapNode.addInPlace' cmp k (Remove : ElementOperation<'View>) delta
1151+
else
1152+
state.[k] <- newSet
1153+
delta <- MapNode.addInPlace' cmp k (Set (view newSet)) delta
1154+
| _ ->
1155+
()
1156+
| ValueNone ->
11421157
()
11431158
else
11441159
unexpected()

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

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ module SetReductions =
236236
| None ->
237237
()
238238

239-
override x.InputChangedObject(t, o) =
239+
override x.InputChangedObject(_t, o) =
240240
if isNull o.Tag then
241241
#if FABLE_COMPILER
242242
let o = unbox<aval<'b>> o
@@ -369,7 +369,7 @@ module AdaptiveHashSetImplementation =
369369
type EmptySet<'T> private() =
370370
static let instance = EmptySet<'T>() :> aset<_>
371371
let content = AVal.constant HashSet.empty
372-
let reader = new History.Readers.EmptyReader<CountingHashSet<'T>, HashSetDelta<'T>>(CountingHashSet.trace) :> IHashSetReader<'T>
372+
let reader = History.Readers.EmptyReader<CountingHashSet<'T>, HashSetDelta<'T>>(CountingHashSet.trace) :> IHashSetReader<'T>
373373
static member Instance = instance
374374

375375
member x.Content = content
@@ -389,7 +389,7 @@ module AdaptiveHashSetImplementation =
389389
member x.Content = value
390390

391391
member x.GetReader() =
392-
new History.Readers.ConstantReader<_,_>(
392+
History.Readers.ConstantReader<_,_>(
393393
CountingHashSet.trace,
394394
lazy (HashSet.addAll content.Value),
395395
lazy (CountingHashSet.ofHashSet content.Value)
@@ -415,15 +415,15 @@ module AdaptiveHashSetImplementation =
415415
HashSetDelta.map (fun d ->
416416
let v = d.Value
417417
if d.Count = 1 then Add(cache.Invoke v)
418-
elif d.Count = -1 then Rem(cache.Revoke v)
418+
elif d.Count = -1 then Rem(cache.RevokeUnsafe v)
419419
else unexpected()
420420
)
421421

422422
override x.Compute(token) =
423423
reader.GetChanges token |> HashSetDelta.map (fun d ->
424424
let v = d.Value
425425
if d.Count = 1 then Add(cache.Invoke v)
426-
elif d.Count = -1 then Rem(cache.Revoke v)
426+
elif d.Count = -1 then Rem(cache.RevokeUnsafe v)
427427
else unexpected()
428428
)
429429

@@ -463,7 +463,7 @@ module AdaptiveHashSetImplementation =
463463
if d.Count = 1 then
464464
Add(cache.Invoke v) |> Some
465465
elif d.Count = -1 then
466-
match cache.RevokeAndGetDeletedTotal v with
466+
match cache.TryRevokeAndGetDeleted v with
467467
| ValueSome (del, v) ->
468468
if del then (v :> IDisposable).Dispose()
469469
Rem v |> Some
@@ -487,15 +487,15 @@ module AdaptiveHashSetImplementation =
487487
HashSetDelta.collect (fun d ->
488488
match d with
489489
| Add(1, v) -> HashSet.computeDelta HashSet.empty (cache.Invoke v)
490-
| Rem(1, v) -> HashSet.computeDelta (cache.Revoke v) HashSet.empty
490+
| Rem(1, v) -> HashSet.computeDelta (cache.RevokeUnsafe v) HashSet.empty
491491
| _ -> unexpected()
492492
)
493493

494494
override x.Compute(token) =
495495
reader.GetChanges token |> HashSetDelta.collect (fun d ->
496496
match d with
497497
| Add(1, v) -> HashSet.computeDelta HashSet.empty (cache.Invoke v)
498-
| Rem(1, v) -> HashSet.computeDelta (cache.Revoke v) HashSet.empty
498+
| Rem(1, v) -> HashSet.computeDelta (cache.RevokeUnsafe v) HashSet.empty
499499
| _ -> unexpected()
500500
)
501501

@@ -516,9 +516,9 @@ module AdaptiveHashSetImplementation =
516516
| Some v -> Some (Add v)
517517
| None -> None
518518
elif d.Count = -1 then
519-
match cache.Revoke v with
520-
| Some v -> Some (Rem v)
521-
| None -> None
519+
match cache.TryRevoke v with
520+
| ValueSome (Some v) -> Some (Rem v)
521+
| _ -> None
522522
else
523523
unexpected()
524524
)
@@ -531,9 +531,9 @@ module AdaptiveHashSetImplementation =
531531
| Some v -> Some (Add v)
532532
| None -> None
533533
elif d.Count = -1 then
534-
match cache.Revoke v with
535-
| Some v -> Some (Rem v)
536-
| None -> None
534+
match cache.TryRevoke v with
535+
| ValueSome (Some v) -> Some (Rem v)
536+
| _ -> None
537537
else
538538
unexpected()
539539
)
@@ -551,15 +551,15 @@ module AdaptiveHashSetImplementation =
551551
HashSetDelta.filter (fun d ->
552552
let v = d.Value
553553
if d.Count = 1 then cache.Invoke v
554-
elif d.Count = -1 then cache.Revoke v
554+
elif d.Count = -1 then cache.RevokeUnsafe v
555555
else unexpected()
556556
)
557557

558558
override x.Compute(token) =
559559
r.GetChanges token |> HashSetDelta.filter (fun d ->
560560
let v = d.Value
561561
if d.Count = 1 then cache.Invoke v
562-
elif d.Count = -1 then cache.Revoke v
562+
elif d.Count = -1 then cache.RevokeUnsafe v
563563
else unexpected()
564564
)
565565

@@ -588,7 +588,7 @@ module AdaptiveHashSetImplementation =
588588

589589
elif d.Count = -1 then
590590
// r is no longer dirty since we either pull or destroy it here.
591-
let struct(deleted, r) = cache.RevokeAndGetDeleted v
591+
let struct(deleted, r) = cache.RevokeAndGetDeletedUnsafe v
592592
dirty.Remove r |> ignore
593593
if deleted then
594594
// in case r was not dirty we need to explicitly remove ourselves
@@ -843,7 +843,7 @@ module AdaptiveHashSetImplementation =
843843
r.GetChanges token
844844

845845
elif d.Count = -1 then
846-
match cache.RevokeAndGetDeletedTotal value with
846+
match cache.TryRevokeAndGetDeleted value with
847847
| ValueSome (deleted, r) ->
848848
// r is no longer dirty since we either pull or destroy it here.
849849
dirty.Remove r |> ignore
@@ -933,7 +933,6 @@ module AdaptiveHashSetImplementation =
933933
let r = input.GetReader()
934934
do r.Tag <- "Input"
935935

936-
let mutable initial = true
937936
let cache = DefaultDictionary.create<aval<'T>, 'T>()
938937

939938
member x.Invoke(token : AdaptiveToken, m : aval<'T>) =
@@ -997,21 +996,24 @@ module AdaptiveHashSetImplementation =
997996

998997

999998
member x.Revoke(v : 'A, dirty : System.Collections.Generic.HashSet<_>) =
1000-
let m = mapping.Revoke v
1001-
1002-
match cache.TryGetValue m with
1003-
| (true, r) ->
1004-
let struct(cnt, v) = r.Value
1005-
if cnt = 1 then
1006-
cache.Remove m |> ignore
1007-
dirty.Remove m |> ignore
1008-
lock m (fun () -> m.Outputs.Remove x |> ignore )
1009-
v
1010-
else
1011-
r.Value <- (cnt - 1, v)
1012-
v
1013-
| _ ->
999+
match mapping.TryRevoke v with
1000+
| ValueSome m ->
1001+
match cache.TryGetValue m with
1002+
| (true, r) ->
1003+
let struct(cnt, v) = r.Value
1004+
if cnt = 1 then
1005+
cache.Remove m |> ignore
1006+
dirty.Remove m |> ignore
1007+
lock m (fun () -> m.Outputs.Remove x |> ignore )
1008+
v
1009+
else
1010+
r.Value <- (cnt - 1, v)
1011+
v
1012+
| _ ->
1013+
failwith "[ASet] cannot remove unknown object"
1014+
| ValueNone ->
10141015
failwith "[ASet] cannot remove unknown object"
1016+
10151017

10161018
override x.Compute(token, dirty) =
10171019
let mutable deltas =
@@ -1072,7 +1074,7 @@ module AdaptiveHashSetImplementation =
10721074
None, None
10731075

10741076
member x.Revoke(v : 'A) =
1075-
let m = f.Revoke v
1077+
let m = f.RevokeUnsafe v
10761078
match cache.TryGetValue m with
10771079
| (true, r) ->
10781080
let struct(rc, v) = r.Value
@@ -1205,7 +1207,7 @@ module AdaptiveHashSetImplementation =
12051207
let struct(first, other) = pp
12061208
match state.TryGetValue first with
12071209
| (true, x) ->
1208-
let struct(v, p) = x
1210+
let struct(_v, p) = x
12091211
if pNew <> p then
12101212
state.[first] <- (d, pNew)
12111213
if pNew then
@@ -1219,7 +1221,7 @@ module AdaptiveHashSetImplementation =
12191221
for m in other do
12201222
match state.TryGetValue m with
12211223
| (true, x) ->
1222-
let struct(v, p) = x
1224+
let struct(_v, p) = x
12231225
if pNew <> p then
12241226
state.[m] <- (d, pNew)
12251227
if pNew then

0 commit comments

Comments
 (0)