package ppx_update
All checked builds passInstall
dune-project
Dependency
Authors
Maintainers
Sources
md5=494f7e6c72d76c96b5be41b655a44dae
sha512=55c7cbbeebf089daadd69115278c114339dd6c5f80c02dde71066da70a7b68b5962ab7978891ed70ea4c261d755528dbdbf9b5c5106c3b15416eb6d8b1e0d8e1
Description
ppx_update optimizes away record updates when new record contents match old ones
README
ppx_update
ppx_update is a small utility ppx for optimizing record updates with certain patterns.
A pattern one comes across when writing certain kinds of OCaml programs is:
type a = {...}
type b = {...}
type c = {a:a; b:b; ...}
let update c =
let a' = ... in
let b' = ... in
{c with a'; b'; ... }Now, if a' and b' are the same as c's previous values a and b, what we want to do for efficiency is this:
let update c =
let a' = ... in
let b' = ... in
if c.a == a' && c.b == b' then
c
else
{c with a'; b'; ... }Physical equality is a very quick check that helps us avoid allocation when it's not needed. ppx_update lets you do this more easily:
let update c =
let a' = ... in
let b' = ... in
[%up {c with a'; b'; ... }] (* will automatically take care of comparisons *)Similarly, if b is mutable:
type a = {...}
type c = {mutable a:a; ...}
let update c =
let b' = ... in
c.b <- b'In this case, we want to try and avoid the write barrier in case b' == b, which we can check for with
let update c =
let b' = ... in
if c.b == b' then
()
else
c.b <- b'With ppx_update:
let update c =
let b' = ... in
[%upf c.b <- b'] (* will only update if there's no physical address match *)Using with dune
Simply add to your preprocessing sections in dune
; In your library or executable section
(libraries ppx_update)
(preprocess (ppx ppx_update))Commands
Two extensions are currently supported:
%up(forupdate): handles record update. Will only work if you have a record that is functionally updated using thewithkeyword.%upf(forupdate_field): handles mutable field updates.
Note that ppx_update is simple, so if you update with a long expression, that expression will be computed twice. For example, this is good:
c.foo <- foo';but this is not a good idea:
c.foo <- long_computation a b c;since the long computation will be performed twice.
Dev Dependencies (1)
-
odoc
with-doc
Optional Dependencies
None
Used by
None
Conflicts
None
Build status
Results of building ppx_update with each compiler on check.ci.ocaml.org, run of against opam-repository 78c202b. All results for this package.
Each result links to its build log. To keep crawlers from overloading the site, build logs require a GitHub sign-in (see ocurrent/opam-health-check). On your first log, GitHub asks you to “Authorize opam-health-check”, the OCurrent app that runs these checks; it sees only your public profile, not your repositories. The sign-in lasts 30 days.
| Version | OCaml 4.11 | OCaml 4.14 | OCaml 5.2 | OCaml 5.4 | OCaml 5.5 |
|---|---|---|---|---|---|
| 0.81 (this version) | n/a | good | good | good | good |
- good Package successfully built
- partial One of the dependencies failed to build
- bad Package failed to build
- n/a Package is not available in this environment
- internal Internal failure