-
Notifications
You must be signed in to change notification settings - Fork 847
Add debug visualiser for 'dict' and implement IReadOnlyDictionary/IReadOnlyCollection #3988
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add debug visualiser for 'dict' and implement IReadOnlyDictionary/IReadOnlyCollection #3988
Conversation
|
@cartermp this can be merged |
|
While you're at it, can you also implement |
|
@saul @0x53A does this work with the following program? [<EntryPoint>]
let main argv =
let d = dict [("uh",1);("uhhh",2);("uhhhhhhhhhh",3)]
let d2 = dict [("hello", 15); ("Wow", 10)]
(d, d2) |> ignore // breakpoint here
0 // return an integer exit codePerhaps it's environmental, but when I install this PR into VS 15.5 Preview 4 I still see the old behavior. |
|
Can’t test it at the moment - my screenshot is from manually linking the new FSharp.Core into my project. |
|
@cartermp I've downloaded FSharp.Core.dll from https://ci2.dot.net/job/Microsoft_visualfsharp/job/master/job/release_net40_no_vs_windows_nt_prtest/4613/artifact/release/net40/bin/ Since this is part of FSharp.Core, not the VF#Tools, this would need a new nuget release. |
|
I did a |
| [<DebuggerBrowsable(DebuggerBrowsableState.RootHidden)>] | ||
| member x.Items = Array.ofSeq d | ||
|
|
||
| let dictImpl (comparer:IEqualityComparer<'SafeKey>) (makeSafeKey : 'Key->'SafeKey) (getKey : 'SafeKey->'Key) (l:seq<'Key*'T>) : IDictionary<'Key,'T> = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer inlined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, fixed
|
Implemented IReadOnlyDictionary and IReadOnlyCollection - I'll go around adding them to list, Map and Set (for a separate PR). |
dsyme
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please
- fix bug in TryGetValue mentioned above
- add testing for all of IReadOnlyDictionary and IReadOnlyCollection,
- review all existing testing for
dictinterfaces
thanks!
| interface IReadOnlyDictionary<'Key, 'T> with | ||
| member __.Item with get key = t.[makeSafeKey key] | ||
| member __.Keys = t.Keys |> Seq.map getKey | ||
| member __.TryGetValue(key, value) = t.TryGetValue(makeSafeKey key, ref value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ref value is incorrect here - please use &value. Please also add a test for this and review all testing as there must be a test hole here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ref seems to work fine for me? I've added tests to validate it - I'll use the & instead though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is my understanding that ref will not copy-out the resulting value to the byref passed as an argument
|
@dsyme there's a bit of a hiccup - How do you want to proceed? |
My assumption was that for now the return type should be only If you want to add |
|
Makes sense - will update the RFC tonight and use this PR as its implementation. |
|
@KevinRansom it's not quite ready yet - I started writing tests and fell down the rabbit hole of adding support for IEnumerable.Reset on |
|
Pushed tests and new |
|
Hmm not sure why the CI is failing... I've added that file to source control? cc @KevinRansom |
|
@saul what do you think of creating an additional project just for debugger visualizers? (not necessarily in this PR, but something to consider for the future) |
|
Visualizer in that sense is completely different to debug type proxies that are used in FSharp.Core. |
|
Yes, I still believe this line is buggy: https://github.com/Microsoft/visualfsharp/pull/3988/files#diff-cf1d05f204f61f31020312fcec812dbaR84. That |
|
Yeah @dsyme I’m happy to change it, but the TryGetValue tests pass (if you try it locally, the CI is failing) |
| Assert.AreEqual(irod.Values, [| 1; 4; 9|]) | ||
|
|
||
| Assert.IsTrue(irod.TryGetValue(1, ref 1)) | ||
| Assert.IsFalse(irod.TryGetValue(100, ref 1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I read it, the test only verifies that the key is found, not that the correct value is returned. That may explain why it passes even though @dsyme is sure that the ref is incorrect.
A better test may be
let b,i = irod.TryGetValue(2)
Assert.AreEqual(true, b)
Assert.AreEqual(2, i)|
(For posterity, since the jenkins servers to wipe results after a time) |
|
At least it builds now :) the problem here is that seq computation expressions / Seq.map etc don’t support IEnumerable.Reset(). I just need to refactor the tests keeping this in mind |
|
Scratch that, no it’s not. It’s the TryGetValue issue dsyme raised and the surface area change. |
|
Okay, I think I've fixed the broken tests here. Sorry for the delay - my laptop makes it impossible to do dev work and I've just fixed my workstation after 3 months of it being broken 😄 |
|
@dotnet-bot test Ubuntu14.04 Release_default please |
No worries at all! |
|
@dsyme can you re-review? Thanks! |
|
LGTM |
|
@dotnet-bot test Windows_NT Release_ci_part3 Build please |
|
The issue is this: an unexpected new public API: |
|
@dotnet-bot test this please |
…aul/visualfsharp into 3981-add-dict-debug-visualiser
|
@KevinRansom @cartermp this is ready to merge |
|
Thanks for this. Kevin |

Fixes #3981, cc @0x53A