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

cohttp: move new client and server modules into a generic module #1003

Merged
merged 2 commits into from
Nov 1, 2023

Conversation

mseri
Copy link
Collaborator

@mseri mseri commented Oct 31, 2023

to avoid shadowing Client and Server modules when opening Cohttp.

This preserves backward compatibility for a very small price and improves library ergonomics since right now many project tend to open Cohttp to have the Headers and Response modules directly accessible.

to avoid shadowing Client and Server modules when opening Cohttp.

This preserves backward compatibility for a very small price
and improves library ergonomics since right now many project tend to
open Cohttp to have the Headers and Response modules directly
accessible.

Signed-off-by: Marcello Seri <[email protected]>
Signed-off-by: Marcello Seri <[email protected]>
@mseri
Copy link
Collaborator Author

mseri commented Oct 31, 2023

Ping @samoht @mefyl @talex5.
It makes sense to have them as Cohttp.Client and Cohttp.Server, but it is true that I also have a number of scripts which open Cohttp for convenience. What do you think?

I have seen this failure in the opam-repository revdeps:

#=== ERROR while compiling prometheus-app.1.2 =================================#
# context              2.2.0~alpha3~dev | linux/x86_64 | ocaml-base-compiler.4.14.1 | file:///home/opam/opam-repository
# path                 ~/.opam/4.14/.opam-switch/build/prometheus-app.1.2
# command              ~/.opam/opam-init/hooks/sandbox.sh build dune build -p prometheus-app -j 255
# exit-code            1
# env-file             ~/.opam/log/prometheus-app-7-9681f8.env
# output-file          ~/.opam/log/prometheus-app-7-9681f8.out
### output ###
# (cd _build/default && /home/opam/.opam/4.14/bin/ocamlopt.opt -w -40 -g -I app/.prometheus_app.objs/byte -I app/.prometheus_app.objs/native -I /home/opam/.opam/4.14/lib/angstrom -I /home/opam/.opam/4.14/lib/asetmap -I /home/opam/.opam/4.14/lib/astring -I /home/opam/.opam/4.14/lib/base64 -I /home/opam/.opam/4.14/lib/bigstringaf -I /home/opam/.opam/4.14/lib/cohttp -I /home/opam/.opam/4.14/lib/cohttp-lwt -I /home/opam/.opam/4.14/lib/fmt -I /home/opam/.opam/4.14/lib/http -I /home/opam/.opam/4.14/lib/http/__private__/http_bytebuffer -I /home/opam/.opam/4.14/lib/logs -I /home/opam/.opam/4.14/lib/lwt -I /home/opam/.opam/4.14/lib/ppx_sexp_conv/runtime-lib -I /home/opam/.opam/4.14/lib/prometheus -I /home/opam/.opam/4.14/lib/re -I /home/opam/.opam/4.14/lib/seq -I /home/opam/.opam/4.14/lib/sexplib0 -I /home/opam/.opam/4.14/lib/stringext -I /home/opam/.opam/4.14/lib/uri -I /home/opam/.opam/4.14/lib/uri-sexp -intf-suffix .ml -no-alias-deps -o app/.prometheus_app.objs/native/prometheus_app.cmx -c -impl app/prometheus_app.ml)
# File "app/prometheus_app.ml", line 157, characters 6-27:
# 157 |       Server.respond_string ~status:`OK ~headers ~body ()
#             ^^^^^^^^^^^^^^^^^^^^^
# Error: Unbound value Server.respond_string
# (cd _build/default && /home/opam/.opam/4.14/bin/ocamlc.opt -w -40 -g -bin-annot -I app/.prometheus_app.objs/byte -I /home/opam/.opam/4.14/lib/angstrom -I /home/opam/.opam/4.14/lib/asetmap -I /home/opam/.opam/4.14/lib/astring -I /home/opam/.opam/4.14/lib/base64 -I /home/opam/.opam/4.14/lib/bigstringaf -I /home/opam/.opam/4.14/lib/cohttp -I /home/opam/.opam/4.14/lib/cohttp-lwt -I /home/opam/.opam/4.14/lib/fmt -I /home/opam/.opam/4.14/lib/http -I /home/opam/.opam/4.14/lib/logs -I /home/opam/.opam/4.14/lib/lwt -I /home/opam/.opam/4.14/lib/ppx_sexp_conv/runtime-lib -I /home/opam/.opam/4.14/lib/prometheus -I /home/opam/.opam/4.14/lib/re -I /home/opam/.opam/4.14/lib/seq -I /home/opam/.opam/4.14/lib/sexplib0 -I /home/opam/.opam/4.14/lib/stringext -I /home/opam/.opam/4.14/lib/uri -I /home/opam/.opam/4.14/lib/uri-sexp -intf-suffix .ml -no-alias-deps -o app/.prometheus_app.objs/byte/prometheus_app.cmo -c -impl app/prometheus_app.ml)
# File "app/prometheus_app.ml", line 157, characters 6-27:
# 157 |       Server.respond_string ~status:`OK ~headers ~body ()
#             ^^^^^^^^^^^^^^^^^^^^^
# Error: Unbound value Server.respond_string

Copy link
Contributor

@talex5 talex5 left a comment

Choose a reason for hiding this comment

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

Fine with me. The cohttp README itself uses open cohttp in the examples, and presumably only works now because of the order of the opens.

@mseri
Copy link
Collaborator Author

mseri commented Oct 31, 2023

We don't test the readme directly afaik, so it may as well be broken

@mefyl
Copy link
Contributor

mefyl commented Oct 31, 2023

tldr: IMO fine in 6.0.0

AFAIK there is no consensus in the Ocaml community regarding backward compatibility and versioning and in my opinion we really need one. Some developers / company have their own approach, but most of the time I don't feel like there is any guarantee as to what package versions to pin to avoid breakage, and I tend to err on the paranoid side.

My personal take on this that the absolute worse thing is compilation and CIs breaking one morning because a new version of an external dependency was released. More so since this often does not happen immediately because build images are often cached or use lockfile, and will happen randomly when the image or lockfile is regenated. It follows that we need a clear guarantee of no API breakage depending on the versionning, and if we're going with semver, which is not perfect but is the most universally adopted thing, that means no API breakage except for major updates, so my opinion on that is that this is fine for cohttp 5 only. I think it's reasonable to expect some possible breakage if you jump major versions, and if you don't want that you can (should) (cohttp (and (>= 5.0.0) (< 6.0.0))).

On another note there are ways to have API change on minor versions while providing backward compatibility modules, having the better of both worlds provided some additional work for the maintainer. We do this internally quite successfully, and I've seen other do. I don't know if anyone ever wrote down a ruleset, but I'd be happy to submit how we proceed for comments.

Edit: fixed versions

@mseri
Copy link
Collaborator Author

mseri commented Oct 31, 2023

@mefyl I see your point but I am not sure how it applies here.

We don't give any guarantee across major versions in cohttp either, and in fact most projects in the opam-repository are already incompatible with 6.0.0 due to the many internal changes.

When I reviewed the original PR it made sense to have client and server directly as toplevel modules in cohttp, but when testing it became inconvenient because it plays badly with open Cohttp often shadowing the actual client or server you want to use, which is an extremely common pattern.

We are releasing alphas and betas to check the effects of the API changes on the ecosystem and discuss in anything in the api needs improvement, so I think the revdeps and going through the failures there are useful. In this case I think it is worth making this change because it is more annoying to have to figure out the shadowed module failure all over the place or having to call server with some other name to avoid it.

@mefyl
Copy link
Contributor

mefyl commented Oct 31, 2023

I botched the versioning in my message, I meant fine in 6.0.0. We agree then, and alpha/betas are of course fine, the name imply you will encounter rough edges.

@mseri
Copy link
Collaborator Author

mseri commented Oct 31, 2023

We agree then, and alpha/betas are of course fine, the name imply you will encounter rough edges.

Absolutely! I suggested this change since I think it is a usability improvement, I didn't mean to suggest that we had to keep backward compatibility at all costs

@mseri mseri merged commit e5a66f1 into mirage:master Nov 1, 2023
17 of 19 checks passed
@mseri mseri deleted the cohttp6-usability branch November 1, 2023 08:34
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.

3 participants