Skip to content

Commit 361aaef

Browse files
committed
fix(stack-encrypt): address the review of the bytes order refusal
The engine change in the previous commit was sound. The review found text and tests that still described the old rule, or that no longer checked anything. - The declaration grammar's admission table said bytes admit `ore`, `ope` and `ore_block`. A runner written from it would admit a declaration the corpus refuses. The table now refuses them, and says why. - `coverage.md` listed the order index on bytes as a combination the corpora record. They no longer do. - The Go CHANGELOG named `index=ore_block` as a tag that is now refused. It is not a tag word, and stashgen refused it before this change. Only a hand-built plan with an `ore_block` output on bytes is newly refused. - The rustdoc for `Reason::IndexNotAdmitted` and `FieldPlan::with_type` lists the refused pairs. It now names an order index on bytes. - A stashgen test checked that no notice held a text the generator no longer writes, so it could not fail. It now checks that no notice names one of the test's fields. - The Go fake engine kept its own list of the kinds the orderings are answered over, beside `indexApplies`. That is the second list the previous commit removed from the engine. `answeredBy` now reads `indexApplies` alone, and the unused `logical` helper is removed.
1 parent 0c76d5c commit 361aaef

7 files changed

Lines changed: 28 additions & 31 deletions

File tree

‎conformance/stack-encrypt/coverage.md‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,10 @@ Each runs in native Rust and Go WASI under `test:conformance`.
143143
| Native `a_stored_record_that_does_not_fit`, the read profile | `shape-*`, `authenticated-*`, `success-*` | Mutation vocabulary over real ciphertext |
144144
| Guest `test_frame` and `last_error` tests | `transport-*`, `leaf-*` | Plan-frame boundary cases, ABI status mapping |
145145

146-
Unsupported combinations the corpora record rather than skip: the order
147-
index on `bytes` stores a term no operator reads; the typed chain refuses
148-
equality, order and block ORE value refusals only after its keyset loads,
149-
where the binding refuses before any; a repeated key in a stored record is
150-
a transport refusal in both decoders, and the engine's own `field_repeated`
146+
Unsupported combinations the corpora record rather than skip: the typed
147+
chain refuses equality, order and block ORE value refusals only after its
148+
keyset loads, where the binding refuses before any; a repeated key in a
149+
stored record is a transport refusal in both decoders, and the engine's own `field_repeated`
151150
and `repeated_key` guards are reached natively alone; the Go host refuses
152151
the zero `Date`, a decimal scale above 28, a timestamp outside the
153152
decoder's range and non-value Go types before the engine. `NaN` and

‎conformance/stack-encrypt/declaration-grammar.md‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,14 @@ select a different leaf encoding.
175175
| Other integer widths | Admitted | Refused | Admitted |
176176
| float32, float64, decimal, date, timestamp | Admitted | Refused | Admitted |
177177
| string | Admitted | Admitted | Admitted |
178-
| bytes | Admitted | Refused | Admitted |
178+
| bytes | Admitted | Refused | Refused |
179179
| array, object, json | Refused | Refused | Refused |
180180

181+
An index is admitted only over a kind one of its operators answers. The
182+
scheme defines an order term for bytes, but no ordering operator is answered
183+
over bytes, so the term would be stored and never queried. The order indexes
184+
are refused on bytes as `index_not_admitted`.
185+
181186
The corpus explicitly tests all 21 kinds against all five scalar indexes.
182187
`array` and `object` may still be sealed without indexes. A `json` field requires
183188
a document target. A raw `json` output has a recognized syntax but is refused as

‎languages/golang/CHANGELOG.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ listed under **Breaking**. Releases are tagged `languages/golang/vX.Y.Z`.
1313
### Breaking
1414

1515
- **An order index on bytes is refused** (#1577). A `[]byte` field tagged
16-
`index=ore`, `index=ope` or `index=ore_block` is now a field error from
17-
`stashgen`, and a plan built by hand with one is refused by the guest
18-
(`index_not_admitted`) before any key is requested. No ordering operator
16+
`index=ore` or `index=ope` is now a field error from `stashgen`. A plan
17+
built by hand with an `ore`, `ope` or `ore_block` output on a `bytes`
18+
field is refused by the guest (`index_not_admitted`) before any key is
19+
requested. No ordering operator
1920
is answered over bytes, so the field stored an order term that anyone
2021
who read the column could compare and that no query could use.
2122
`stashgen`'s notice for an index no generated method queries is gone

‎languages/golang/stashgen/enginetest/enginetest.go‎

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,10 @@ func (e Static) operators(ctx context.Context, d stashgen.Declaration) (map[stri
199199
// answeredBy mirrors Op::answered_by in stack-encrypt: eq through an
200200
// equality index, matches through a match index, and the orderings through
201201
// the one order index the field declares (ORE, block ORE or OPE; check
202-
// refused a field with two), over an integer of 16 bits or wider, a float,
203-
// text, a decimal, a date or a timestamp; each only where the index applies
204-
// to the type.
202+
// refused a field with two); each only where the index applies to the type
203+
// (indexApplies). There is no second list of the types the orderings are
204+
// answered over: an index that applies answers its operators, as in the
205+
// engine.
205206
func answeredBy(operator string, t stashgen.GoType, indexes []stashgen.IndexName) (stashgen.IndexName, bool) {
206207
declared := func(want stashgen.IndexName) bool {
207208
for _, idx := range indexes {
@@ -217,11 +218,6 @@ func answeredBy(operator string, t stashgen.GoType, indexes []stashgen.IndexName
217218
case "matches":
218219
return stashgen.IndexMatch, declared(stashgen.IndexMatch)
219220
}
220-
orderable := (integer(t) && !eightBit(t)) || logical(t) ||
221-
t.Kind == stashgen.KindFloat || t.Kind == stashgen.KindString
222-
if !orderable {
223-
return "", false
224-
}
225221
for _, index := range []stashgen.IndexName{stashgen.IndexOre, stashgen.IndexOreBlock} {
226222
if declared(index) {
227223
return index, true
@@ -239,15 +235,6 @@ func integer(t stashgen.GoType) bool {
239235
return false
240236
}
241237

242-
// logical reports whether the type is a decimal, a date or a timestamp.
243-
func logical(t stashgen.GoType) bool {
244-
switch t.Kind {
245-
case stashgen.KindDecimal, stashgen.KindDate, stashgen.KindTimestamp:
246-
return true
247-
}
248-
return false
249-
}
250-
251238
// eightBit reports whether the type is an 8-bit integer (int8, uint8 or
252239
// byte, or a type defined over one), which has no order term.
253240
func eightBit(t stashgen.GoType) bool {

‎languages/golang/stashgen/refusal_test.go‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,12 @@ func TestAnOrderIndexOnBytesIsRefused(t *testing.T) {
386386
if err != nil {
387387
t.Fatal(err)
388388
}
389-
if notices := strings.Join(file.Notices, "\n"); strings.Contains(notices, "no generated method queries") {
390-
t.Errorf("an index every field can query got a notice:\n%s", notices)
389+
// Every index here answers a query method, so no notice names a field.
390+
notices := strings.Join(file.Notices, "\n")
391+
for _, field := range []string{"User.Name", "User.Blob", "User.Score"} {
392+
if strings.Contains(notices, field) {
393+
t.Errorf("a field whose every index is queried got a notice (%s):\n%s", field, notices)
394+
}
391395
}
392396
if !strings.Contains(string(file.Content), "func (f NameField) Lt(") {
393397
t.Errorf("a text field with ope has no Lt:\n%s", file.Content)

‎packages/stack-encrypt/src/dynamic/mod.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,8 @@ reasons! {
558558
/// `"type"` is not a string naming a value type.
559559
UnknownType => "unknown_type", r#""type" does not name a value type"#;
560560
/// The field's declared type has no such index: match on an integer,
561-
/// equality or an order index on a boolean, any index on a composite.
561+
/// equality or an order index on a boolean, an order index on an
562+
/// 8-bit integer or on bytes, any index on a composite.
562563
IndexNotAdmitted => "index_not_admitted", "the declared type has no such index";
563564
/// The field declares the JSON index as an output. A data plan
564565
/// reaches the JSON index through a target that stores a document

‎packages/stack-encrypt/src/dynamic/record.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,8 @@ impl FieldPlan {
415415
/// [`Error::Plan`] if the field asks for an index the kind is not
416416
/// defined for ([`admits`](super::admits)), with the reason [`not_admitted`] gives:
417417
/// [`Reason::IndexNotAdmitted`] for match on an integer, equality or an
418-
/// order index on a boolean, an order index on an 8-bit integer, any
419-
/// index on a composite.
418+
/// order index on a boolean, an order index on an 8-bit integer or on
419+
/// bytes, any index on a composite.
420420
pub fn with_type(mut self, field_type: ValueKind) -> Result<Self, Error> {
421421
for output in &self.outputs {
422422
if let Output::Term(index) = output {

0 commit comments

Comments
 (0)