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

   # Which issue does this PR close?
   
   Part of #9323 (tracker #9320).
   
   # Rationale for this change
   
   #9335, #9350, #9368, and #9379 generated the C and Go `ListOptions`, 
`StatOptions`, `DeleteOptions`, and `ReadOptions` from core. This PR generates 
the existing `ReaderOptions` the same way, with the same table, templates, and 
tests. It exposes no new option: core's `if_version_match`, 
`if_version_not_match`, and `checksum` keep their defaults in the conversion. 
The write and copy option structs stay hand-written.
   
   # What changes are included in this PR?
   
   - `dev/src/generate/c/options.rs`: the released-options table gains 
`ReaderOptions` in its C member order. It reuses existing representations, and 
each pins one core kind, so generation fails when an exposed field leaves core 
or changes its kind:
   
     | Fields | Representation | C | Go |
     |---|---|---|---|
     | `version`, `if_match`, `if_none_match` | `BorrowedString` | the setter 
stores the caller's pointer; `_free` leaves it | skips `""`, keeps the bytes 
alive until the C call returns |
     | `if_modified_since`, `if_unmodified_since` | `FlaggedMillis` | 
`has_<name>` and Unix milliseconds | skips a nil time, passes `UnixMilli()` |
     | `content_length_hint` | `FlaggedU64` | `has_<name>` and `u64` | 
`*uint64`; any value set reaches C, including `0` |
     | `concurrent`, `prefetch` | `Usize` | `usize` | `uint`; `0` is skipped, 
which is also C's default |
     | `chunk`, `gap` | `FlaggedUsize` | `has_<name>` and `usize` | `uint`; `0` 
is skipped |
   
   - Docs come from core under the #9350, #9368, and #9379 rules (C and Go 
names, error kinds as `opendal_code` and Go `ErrorCode`, the Rust performance 
guide paragraph dropped, `Some(0)` read as `0`). C and Go readers read the 
whole file, have no suffix range or `Reader::fetch`, and do have 
`content_length_hint`, so:
     - The struct doc's "Creating the reader checks the options and 
capabilities without accessing storage, so a missing file or a failed condition 
surfaces when reading from it" now reads: without a positive `chunk`, or with 
`content_length_hint` set, `opendal_operator_reader_with()` (Go: 
`Operator.Reader`) checks the options and capabilities without accessing 
storage, so a missing file or a failed condition surfaces when reading from the 
returned reader. With a positive `chunk` and no `content_length_hint`, it first 
stats the file, so either can fail `opendal_operator_reader_with()` (Go: 
`Operator.Reader`) instead.
     - `chunk`: core's open-ended or suffix range sentence, with its 
earlier-read and `ReadOptions::chunk` clauses, becomes 
"`opendal_operator_reader_with()` with a positive `chunk` first stats the file 
to learn its length, unless `content_length_hint` is set." The stat-capability 
sentence that follows now ends "otherwise `opendal_operator_reader_with()` 
returns `OPENDAL_UNSUPPORTED`" (Go: `Operator.Reader` and `CodeUnsupported`) 
instead of "otherwise the read returns".
     - `concurrent`: "Without `chunk`, only `crate::Reader::fetch` reads 
concurrently, with one request per merged range" becomes "Without `chunk`, a 
reader from `opendal_operator_reader_with()` does not read concurrently" (Go: 
"a `Reader` from `Operator.Reader`").
     - `gap`: core documents how `Reader::fetch` merges ranges, so 
`OptionsSpec::docs` replaces it with "The reader reads the whole file as one 
range, so `gap`, which merges nearby ranges, has no effect."
     - `prefetch`: "concurrent reads with `Reader`" names the Rust type, so C 
reads "with an `opendal_reader`" and Go "with a `Reader`".
   
     Generation fails when core stops containing the rewritten text. The 
generator now checks rewrites after the released fields, so a released field 
that leaves core fails as missing rather than as a stale rewrite. The other 
generated files are byte-identical to `main`.
   - C: the generated file now holds `opendal_reader_options`, `_new`, the 10 
setters, `_free`, and a crate-private `unsafe fn to_core(&self) -> 
opendal::Result<options::ReaderOptions>`. It replaces the safe 
`TryFrom<&opendal_reader_options>` impl, which read the raw string pointers. 
`opendal_operator_reader_with_cancel` calls it with a `// SAFETY:` comment, and 
the `# Safety` sections of `opendal_operator_reader_with` and 
`opendal_operator_reader_with_cancel` state the contract, as #9379 did for read 
options. The conversion sets the same fields as `main`'s, and 
`..Default::default()` is spelled out.
   - Go: `WithReaderFn`, the 10 `ReaderWith*` options, `readerOptions`, 
`parseReaderOptions`, `newOpendalReaderOptions`, and the 12 reader option FFI 
declarations move from `reader.go` to the generated `options.go`. They keep 
their signatures, private field names, nil handling, and call order. Three 
private details change as in #9379: the timestamps are stored as `*time.Time` 
and converted with `UnixMilli()` when the C options are built, the returned 
keep-alive is `[][]byte` (so `readerOptionsKeepAlive` is gone), and the shared 
`newReaderOptionsSetStringFFI` helper becomes one declaration per string 
setter. `TestReaderWithOptions` compares the timestamps through `UnixMilli()`.
   - Tests:
     - `bindings/c/tests/reader_options.cpp` (new): `static_assert`s pin the 15 
member types, exactly 15 members, the 64-bit `sizeof` (120) and every offset, 
and the 12 option prototypes plus `opendal_operator_reader_with` and 
`_with_cancel`, all copied from `opendal.h` on `main`. At runtime, the setters 
store the caller's string pointers and set their `has_*` members, and NULL 
options are a no-op. On a memory operator: creating a reader without `chunk`, 
or with `chunk` 0, succeeds for a missing path and the first read fails with 
`NOT_FOUND`; a positive `chunk` fails creation with `NOT_FOUND` unless 
`content_length_hint` is set; a chunked reader with `concurrent`, `prefetch`, 
and `gap` reads the whole file, and with a hint of 8 reads 8 bytes; `version` 
and each condition fail creation with `UNSUPPORTED` on an existing and a 
missing path, and an out-of-range time with `CONFIG_INVALID`.
     - `bindings/c/src/types.rs`: `test_reader_options_to_core` checks the 
defaults, every setter through the conversion (including the three defaulted 
core fields), and that a zero `chunk`, `gap`, and hint stay set.
     - `bindings/go/options_test.go`: compile-time assignments pin 
`WithReaderFn` and the 10 option signatures from `main`, and a test requires 
exactly these 10 exported `ReaderWith*` functions. A memory operator creates 
and reads readers through the live C library with each option, as the C test 
does, including which call fails for a missing path with and without `chunk`. A 
stub test checks that each option reaches its C setter with its value, that 
times arrive in Unix milliseconds, that `""` and zero counts reach no setter 
while a zero hint does, and that the three strings are kept alive. Another stub 
test passes each string option a NUL byte and invalid UTF-8: `Operator.Reader` 
fails before any C setter or the C reader runs, and frees the C options once.
     - `dev`: `test_docs_come_from_core` covers `ReaderOptions` like the other 
structs: full paragraphs of each C member, C setter, Go option, the C struct, 
and the Go function type, computed from core's docs with the rewrites written 
as literals in the test, and `gap`'s replaced doc as a literal. The surface, 
string ownership, conversion, stale-rewrite, and kind tests cover the reader 
fields, and the surface test checks that `Operator.Reader`, `Reader`, 
`opendal_reader`, and `opendal_operator_reader_with()` exist.
   
   Each new test fails under a mutation (scratch edits on the committed tree):
   
   - `dev`: dropping or rewording any of the five rewrites (struct doc, 
`concurrent`, the `chunk` stat sentence, "otherwise ... returns", `prefetch`), 
claiming that `gap` has an effect, exposing `checksum`, storing reader strings 
as copies, documenting a zero hint as unset, skipping the kind check or the 
rewrite check, and checking rewrites before the fields. With core `prefetch` or 
`concurrent` changed to `Option<usize>`, `prefetch` removed, or the rewritten 
creation or `chunk` text reworded, `generate -l c` exits with an error naming 
the field or the rewrite.
   - `tests/reader_options.cpp` fails to compile when the generated struct puts 
`prefetch` before `has_gap` (offsets), or when the header gains a member after 
`prefetch` (member count and `sizeof`) or declares `prefetch` as `uint32_t`. It 
fails at runtime when the conversion drops `chunk`, `content_length_hint`, or 
`if_match`, `_set_version` stores nothing, or `_set_chunk` leaves `has_chunk` 
false. `test_reader_options_to_core` fails under each of these conversion and 
setter mutations, and when the conversion drops `prefetch`. Dropping `chunk` 
also hangs `cancel.rs`'s test that cancels reader creation during its stat.
   - `options_test.go` fails when Go skips a zero hint, passes a zero chunk, 
drops a string's keep-alive, never calls the prefetch setter, passes times in 
seconds, `ReaderWithChunk` sets nothing, `ReaderWithContentLengthHint` takes a 
`uint`, or `ReaderWithChecksum` is exported. The invalid-string test fails when 
a string branch skips the free or ignores the error.
   
   Doc claims, checked through the C library and the Go package on builds of 
this branch:
   
   - On `memory` and `fs`, without `chunk` (or with `chunk` 0), creating a 
reader for a missing path succeeds and the first read fails with 
`OPENDAL_NOT_FOUND` (Go: `CodeNotFound`). With a positive `chunk`, creation 
fails with `OPENDAL_NOT_FOUND`, unless `content_length_hint` is set. `version` 
and `if_match` fail creation with `OPENDAL_UNSUPPORTED` on both services, for 
existing and missing paths, and so do both time conditions on `memory`.
   - `fs` has `read_with_if_modified_since` but not 
`stat_with_if_modified_since`. Without `chunk`, `if_modified_since` reads the 
file for an old time and fails the read with `OPENDAL_CONDITION_NOT_MATCH` for 
a future one. With `chunk` 4, creation fails with `OPENDAL_UNSUPPORTED` for an 
existing and a missing file, and with `content_length_hint` 16 the reader 
returns the 16 bytes. Go returns the same codes from `Operator.Reader` and the 
read.
   - Against Silo S3 behind a logging proxy, creating a reader without `chunk` 
sends no request, and reading it sends one `GET` without a `Range`, also with 
`concurrent` 3, `prefetch` 2, or `gap` 0 or 1 MiB. With `chunk` 4, creation 
sends `HEAD` and reading sends four ranged `GET`s, issued out of order with 
`concurrent` 3; `gap` 0 sends the same requests. With `content_length_hint` 16, 
creation sends no `HEAD`. A failing `If-Match` or a future `If-Modified-Since` 
fails the first read with `OPENDAL_CONDITION_NOT_MATCH` (412 and 304 on the 
`GET`); with `chunk` 4, they fail creation instead, at the `HEAD`. With `chunk` 
4 and `content_length_hint` 16, the future `If-Modified-Since` again fails the 
first read, at the first ranged `GET`.
   
   # Are there any user-facing changes?
   
   Doc comments only. No API, ABI, or behavior change.
   
   - C and Zig: with comments removed, `opendal.h` has exactly the same lines 
as `main`, and the `opendal_reader_options` definition is identical. The only 
difference is order: the 12 reader option prototypes now follow the read option 
prototypes instead of the write option prototypes, and 
`opendal_reader_options_free` follows the setters, because cbindgen writes 
prototypes in source order. `opendal_reader_options` is 120 bytes with the same 
offsets on macOS arm64 and on Linux x86-64 and arm64. The library exports the 
same 201 `opendal_*` symbols as `main`.
   - A C program compiled with `-Wall -Wextra -Werror` against `main`'s header 
prints the same 157 lines on macOS arm64 with `main`'s library and with this 
branch's. It prints the size and offsets, initializes the struct by position 
and by designators, calls every setter (including on NULL options), and creates 
and reads readers on `memory` and `fs` with 32 option cases, for an existing 
and a missing path, plus stack and NULL options.
   - A reader option string that is not valid UTF-8 still panics; the message 
now names the field (`malformed version: …` instead of `malformed option`), as 
in #9350 and #9379.
   - Go: `go doc -short` is identical to `main`, and `go doc -all` has the same 
declarations; only the docs of `WithReaderFn` and the 10 `ReaderWith*` options 
differ. `main`'s Go package passes its 89 tests against this branch's library, 
and this branch's Go package passes its 93 tests (`main`'s 89 plus 4 new) 
against `main`'s library.
   
   # Breaking changes
   
   None.
   
   # AI Usage Statement
   
   - **Harness:** Claude Code via T3 Code | **Model:** Claude Opus 5.5 | 
**Effort:** xhigh | **Role:** Implemented the generator entry, doc rewrites, 
and tests. Ran the surface diffs, compatibility probes, mutation checks, and 
doc-claim checks on `memory`, `fs`, and Silo S3 behind a logging proxy, plus 
the C, Go, and `odev` CI steps on macOS arm64 and in Linux containers. Drafted 
this description. The human author reviews the change and is responsible for it.
   


-- 
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