Skip to content
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 testing for vanilla and ocamlcompatible serializers #4252

Merged
merged 49 commits into from
Jul 10, 2022

Conversation

pbiggar
Copy link
Member

@pbiggar pbiggar commented Jul 7, 2022

After many wrong paths, this adds testing to the Vanilla and OCamlCompatible serializers. This adds significant clarity about what kind of changes can be safely made to the serializers. It also adds some (indirect sorta) documentation to where the serializers are used.

The tests have three parts:

  • everywhere we use Vanilla and OCamlCompatible serializers I mark them as allowed by calling Json.Vanilla.allow<type> "reason" (or Json.OCamlCompatible) in new initialization functions
  • in non-production environment, we assert that these types are have test cases added in Serialization.Tests.fs
  • the serialized version of these tests cases are stored in backend/serialization, and are checked against them. Any changes cause these files to change (they are checked into git)

Most of the excitement here is in Serialization.Tests.fs

We now have a really good understanding of where the vanilla and ocamlcompatible serializers are used, which should make it much easier to eradicate the ocamlcompatible one (in some future PRs)

Some things I did to make this work:

  • move the meat of Analysis.fs into LibAnalysis.fs, which is not a wasm project and can be integrated directly into the Tests project more easily
  • Make the OCamlTypes more concrete by removing the polymorphism that always used fluidExpr
  • Removed Apiserver.Json which was a clone of the vanilla serializer. This was a different attempt to make the serializers less accident prone, but it's no longer necessary with this
  • Make UI.fs globals lazy (so they run after the initialization functions)
  • fixed running ./scripts/build/dotnet-fsi

@pbiggar pbiggar requested a review from StachuDotNet July 8, 2022 02:07
@pbiggar pbiggar marked this pull request as ready for review July 8, 2022 02:07
pbiggar added 28 commits July 8, 2022 02:08
The annotation didn't actually do this - it only runs when reflection functions are
called on the type, so we couldn't guarantee that all the serialized types were
made note of, preventing us from doing regression testing on them.
(users don't have characters anyway)
…alizer

This makes it much easier to debug why initializers are called
This allows the serializers initialization to run
docs/serialization.md Outdated Show resolved Hide resolved
docs/serialization.md Outdated Show resolved Hide resolved
docs/serialization.md Outdated Show resolved Hide resolved
let newValue = (name, f v) :: currentValue
data[key] <- newValue

let v<'t when 't : equality> (dataName : string) (data : 't) =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a marginal cost to rename these fns to vanilla and ocamlcompat for sake of legibility

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or better yet, genVanilla and genOcaml. Even genV and genO would be better

Copy link
Member

@StachuDotNet StachuDotNet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. I've noted various minor change requests, but barring those this makes me feel more secure in our serializers. (though naturally there's still work to be done for additional serializers)

@@ -307,6 +66,9 @@ type EvalWorker =
///
/// Once evaluated, an async call to `self.postMessage` will be made
static member OnMessage(input : string) =
// We'd like to only call this once on initialization, but I can't figure out how
Copy link
Member

@StachuDotNet StachuDotNet Jul 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's my idea:

  • define static member OnInit() = ... fn
  • create a binding to that exposed member, and call it right before the 2+3 warmup call, here:

const messageHandler = Module.mono_bind_static_method(

Or have you tried that and it doesn't work?

@pbiggar
Copy link
Member Author

pbiggar commented Jul 9, 2022

Adding the initializer to BlazorWorker/EvalWorker worked great, thanks!

@pbiggar pbiggar merged commit 4692ca0 into main Jul 10, 2022
@pbiggar pbiggar deleted the paul/test-serializers branch July 10, 2022 01:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants