chitralverma opened a new pull request, #9378:
URL: https://github.com/apache/opendal/pull/9378

   # Which issue does this PR close?
   
   Part of #9324 (tracker #9320).
   
   # Rationale for this change
   
   #9331, #9361, and #9366 generate the C++ `ListOptions`, `StatOptions`, and 
`DeleteOptions` from `core/core/src/types/options.rs`. This PR generates the 
existing `ReadOptions` the same way, reusing their table, templates, and tests. 
It exposes no new option.
   
   # What changes are included in this PR?
   
   - `dev/src/generate/cpp.rs`: `OPTIONS` lists the 13 `ReadOptions` members 
with their core kinds, in their released order. Three kinds are new to the 
bridge, and each keeps the type and conversion from `main`:
     - `concurrent` (`Usize`) is `std::size_t concurrent{0}` and crosses 
unchanged.
     - `content_length_hint` (`OptionU64`) is `std::optional<std::uint64_t>` 
and crosses as a new `OptionalU64`.
     - `range` (`BytesRange`) is the C++ `ReadRange` and crosses as 
`FfiBytesRange{type, start, end}`. `bytes_range` keeps `main`'s mapping: `FULL` 
and undeclared types read the whole file, `OFFSET` reads from `start`, `RANGE` 
reads `end - start` bytes from `start` (saturating, so an `end` before `start` 
reads nothing), and `SUFFIX` reads the last `end` bytes.
   
     Core's `limit`, `if_version_match`, `if_version_not_match`, and `checksum` 
stay unexposed and keep their core defaults, as `main`'s `..Default::default()` 
did; the generated conversion lists them under `// Not exposed in C++ yet:`. 
Timestamps can fail to convert, so the conversion is a `TryFrom`, as for 
`StatOptions`.
   - `ReadRange` moves verbatim into the generated `include/options.hpp`, ahead 
of the options structs, because `ReadOptions::range` needs it. `options.hpp` 
gains `#include <cstdint>`.
   - `data_structure.hpp`, `src/lib.rs`, and `src/operator.cpp` drop the 
hand-written `ReadRange`, `ReadOptions`, `FfiBytesRange`, `FfiReadOptions`, 
`bytes_range`, `read_options`, `ToFfiBytesRange`, and `ToFfiOptions(const 
ReadOptions &)`. `Operator::Read(path, options)` and the `read_options` bridge 
function keep their signatures.
   - Docs, rendered by #9361's rules from core's `ReadOptions` docs as of 
#9375, with C++ forms where core's text names something C++ lacks:
     - `OptionsSpec` gains `cpp_member_docs`, which replaces a member's core 
doc, and `cpp_rewrites`, which replaces core text in a struct's docs, as #9375 
does for Node.js. Generation fails when a rewrite matches nothing, when a 
`BytesRange` member has no C++ doc, or when a C++ member doc names no listed 
member.
     - `range` describes `ReadRange::Full()`, `Offset`, `Range`, and `Suffix` 
instead of Rust range syntax, and says that a `ReadRange::Range` whose `end` is 
past the end of the file fails the read.
     - `gap` reads "Each call to `opendal::Operator::Read` reads a single byte 
range, so `gap` has no effect." Core documents how `Reader::fetch` merges 
ranges, and C++ has no `fetch`.
     - In the struct doc, "A read with a zero limit or an empty range" reads "A 
read with an empty range, such as `ReadRange::Range(0, 0)`", because C++ does 
not expose `limit`.
     - The three `override_*` docs end at "from services that support it.", 
without core's "including for presigned read requests", because C++ has no 
presign API.
     - For every struct, "`Some(0)` has the same behavior as `None`" reads "`0` 
has the same behavior as `std::nullopt`", and core's exact "Refer to the 
performance guide for more details." paragraph is dropped, because that guide 
covers the Rust API only. A reworded paragraph would stay and fail the doc 
test. Only `ReadOptions` has such text today, so the `ListOptions`, 
`StatOptions`, and `DeleteOptions` output is unchanged.
     - Every other member doc is core's full text with C++ names.
   - Tests:
     - `dev`: the `ReadRange` and `ReadOptions` texts copied from `main`'s 
`data_structure.hpp` must appear in the generated header once comments are 
removed, with `ReadRange` first. The doc test from #9361 now compares each 
`ReadOptions` member doc and the struct doc with core's full doc, paragraph by 
paragraph, after applying the C++ member docs and rewrites, which the test 
holds as literals. It also checks that the `ReadOptions` docs never mention 
presign, that each `ReadRange::` factory the docs name is declared, and that 
`opendal.hpp` declares `Read(std::string_view path, const ReadOptions 
&options)`. Generation fails when core changes the kind of `range`, 
`content_length_hint`, `concurrent`, or `chunk`, or drops `range`. New unit 
tests cover the two rules for every struct and the rewrite step.
     - `src/options_test.rs`: every bridge field reaches core, each 
`ReadRange::Type` (and an undeclared one) converts as on `main`, explicit zeros 
stay `Some(0)`, absent values stay absent, and out-of-range timestamps fail 
before the read.
     - `tests/options_test.cpp`:
       - A positional initializer in `main`'s member order reaches the bridge.
       - Structured bindings bind the 13 members in order.
       - A default `const ReadOptions` reaches the bridge absent.
       - On `memory`, each `ReadRange` reads the documented bytes. 
`Suffix(1024)` of a 10-byte file reads it whole, `Range(5, 3)` reads nothing, 
and `Range(0, 11)` throws.
       - On `memory`, `content_length_hint`, `chunk` with `concurrent`, `gap`, 
and the overrides return the file. `chunk` reaches core: an offset past the end 
returns an empty string without `chunk` or with `chunk = 0`, and fails with 
`RangeNotSatisfied` with `chunk = 4`.
       - On `memory`, a missing file fails with `NotFound` with default options 
and with the overrides, and an empty range returns an empty string for it. Each 
of `version`, `if_match`, `if_none_match`, `if_modified_since`, and 
`if_unmodified_since` throws with `what()` starting with `Unsupported` and 
naming the option, for an existing and a missing file, with the full and an 
empty range.
   
     Scratch mutations confirmed that each new test can fail:
     - Generator: changing the empty-range example, dropping either rewrite, 
keeping "presigned requests" in the override rewrite, dropping the `gap` doc, 
writing `[0, 1024]` in the `range` doc, dropping the `Some(0)` rule, keeping 
the performance guide paragraph, or rendering the `ReadOptions` member docs 
from the same-named fields of core `ReaderOptions` fails the doc test. Swapping 
`if_match` and `if_none_match`, adding `limit`, dropping the `{0}` initializer 
of `concurrent`, removing `ReadRange::Suffix`, or dropping `<cstdint>` fails 
the declaration test. Skipping the kind check, the `BytesRange` doc check, the 
stale member doc check, or the stale rewrite check, or not counting rewrite 
matches in member docs, fails a spec test.
     - Core: changing `concurrent` to `Option<usize>`, `content_length_hint` to 
`Option<usize>`, or `chunk` to `Option<u64>`, removing `range`, or rewording "a 
zero limit or an empty range validates" makes `generate -l cpp` exit with an 
error. Rewording the presign clause of one `override_*` doc fails the doc test. 
Adding a field to core `ReadOptions` only adds it to the `// Not exposed in C++ 
yet:` list.
     - Binding: in the generated Rust conversion, reading `RANGE` as `end` 
bytes, dropping `version`, dropping `content_length_hint`, or ignoring 
`has_value` for `chunk` fails a Rust test. The first two also fail C++ tests. 
The other two cannot be observed on `memory`: it ignores the hint, and an 
absent `chunk` reaches core as `Some(0)`, which reads like `None`. In the 
generated C++ converter, sending `concurrent` as 0, `range` as `FULL`, the two 
overrides swapped, or `content_length_hint` as present fails C++ tests.
   
   Verification of the generated doc claims, through this binding on `memory`, 
`fs`, and versioned Silo S3 (the CI fixture image), with Silo's request trace 
(`mc admin trace`) for what the reads send:
   
   - Ranges: `Full`, `Offset`, `Range`, and `Suffix` read the documented bytes 
on all three. `Range(0, 1024)` of a 10-byte file fails on all three. 
`Suffix(1024)` returns the whole file.
   - Conditions: on `memory`, each of the five conditions fails with 
`Unsupported`, and on `fs`, `version` and `if_match` do, for an existing and a 
missing file. On Silo, `version` reads that version, and an unknown version 
fails with `NotFound`. A matching or failing `if_match`, `if_none_match`, 
`if_modified_since`, or `if_unmodified_since` returns the data or 
`ConditionNotMatch`, on Silo for all four and on `fs` for the two time 
conditions, and a missing file then fails with `NotFound`.
   - Empty ranges: `Range(0, 0)` returns an empty string for an existing and a 
missing file on all three, also with a condition that would fail on `fs` and 
Silo, and `Suffix(0)` does too on `memory` and `fs`. On Silo, `Suffix(0)` with 
`chunk = 4` and `if_modified_since` returns an empty string without sending a 
request. With a condition that `memory` lacks, an empty range fails with 
`Unsupported`.
   - `chunk` and `concurrent`: without `chunk`, or with `chunk = 0`, Silo gets 
one `GetObject`, also with `concurrent = 3`. With `chunk = 4`, an open-ended 
read or `Suffix(6)` gets a `HeadObject` first, then ranged `GetObject`s; 
`Range(0, 8)` or `content_length_hint` skips the `HeadObject`. With `chunk = 
128` on a 4096-byte file, `concurrent = 1` sends the ranges in order and 
`concurrent = 8` out of order. On `fs`, which has `read_with_if_modified_since` 
but not `stat_with_if_modified_since`, `chunk = 2` with `Full`, `Offset(3)`, or 
`Suffix(3)` and `if_modified_since` fails with `Unsupported` at `stat`, for an 
existing and a missing file; with `content_length_hint` set, the existing file 
reads.
   - `override_*`: an ordinary read on Silo sends `GetObject` with 
`response-content-disposition`, `response-content-type`, and 
`response-cache-control`.
   - `gap`: core reads it only when merging the ranges of `Reader::fetch`, 
while `Operator::Read` reads a single range.
   
   # Are there any user-facing changes?
   
   None in the API. `ReadRange` and `ReadOptions` move from 
`data_structure.hpp` to `options.hpp`, which `data_structure.hpp` includes, so 
code that includes either header sees the same declarations. With comments 
removed, the headers in `include/` have the same lines as on `main` except for 
`#include <cstdint>` in `options.hpp`, and all 28 struct, class, and enum class 
definitions match; `ReadRange` and `ReadOptions` are the only ones that moved. 
`ReadOptions` gains doc comments, which it had none of on `main`.
   
   A probe compiled against `main`'s and this PR's headers printed identical 
output: `sizeof`, `alignof`, and aggregate status of all eight options structs 
and `ReadRange`, the offset and type of every `ReadOptions` and `ReadRange` 
member, default values, and the values from full and partial positional 
initialization, C++20 designated initialization, and structured bindings. 
Compiler warnings were identical too. This held on Linux x86-64 with GCC 13.3 
and clang 18.1.3, in C++17 and C++20. `ReadOptions` stays 352 bytes with 8-byte 
alignment, and `ReadRange` 24 bytes.
   
   # Breaking changes
   
   None
   
   # AI Usage Statement
   
   - Harness: Claude Code via T3 Code. Model: Claude Opus 5.5 
(`claude-opus-5-5`). Effort: xhigh. Role: implemented the generator table 
entry, the new bridge kinds, the C++ doc forms, the binding wiring, and the 
tests; ran the doc-claim checks on `memory`, `fs`, and Silo S3, plus the 
mutation, layout, and Linux container checks; drafted this description. The 
author reviews every change and claim.
   - Decisions for review:
     - `ReadRange` lives in the generated header, because it must precede 
`ReadOptions` and `data_structure.hpp` includes `options.hpp`. The generator 
emits it verbatim; it is not derived from core.
     - The C++ `range` and `gap` docs replace core's, and two rewrites replace 
core text that names `limit` and presign, which C++ lacks. Everything else is 
core's text.
     - Dropping the performance guide paragraph and the `Some(0)` wording are 
rules for every struct, as #9375 does for Node.js, so later structs inherit 
them.
     - The C++ `StatOptions` override docs from #9361 still say "including for 
presigned stat requests"; this PR leaves them unchanged.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to