From a2f27418446bc69ae2995bed7674d785c2cf3aa5 Mon Sep 17 00:00:00 2001 From: Kinflou Date: Mon, 16 Nov 2026 11:12:03 +0800 Subject: [PATCH] compiler cases: the references decoy builds on its own; a type no protocol reaches has to be bounded The resolved-* cases' decoy Invoice (archive) held a string without a maximum and nothing marked it, so archive was refused on its own, whatever api wrote. The decoy now has a marked protocol Dump reaching it, as in bounded/other-schema-marked, and each case expects Dump's given-up bounded_size and acknowledgement. resolved-decoy still fails with bounds::unbounded. New bounded cases: unreached-unmarked, unreached-list-unmarked, unreached-allowed-still-unmarked, unreached-bounded. --- compiler/cases/bounded.json | 104 +++++++++++++++++++++++++++ compiler/cases/references.json | 124 ++++++++++++++++++++++++++++----- compiler/readme.md | 2 +- compiler/src/bounded.cue | 48 +++++++++++++ compiler/src/references.cue | 115 ++++++++++++++++++++++-------- 5 files changed, 345 insertions(+), 48 deletions(-) diff --git a/compiler/cases/bounded.json b/compiler/cases/bounded.json index b417922..86a8f45 100644 --- a/compiler/cases/bounded.json +++ b/compiler/cases/bounded.json @@ -371,6 +371,110 @@ "builds": true, "diagnostics": [] } + }, + { + "id": "bounded/unreached-unmarked", + "description": "a struct no protocol reaches, with a string without a maximum, is an error: it is a type another package can use", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\n", + "schemas": [ + { + "path": "src/models.ids", + "text": "struct Blob {\n data: string\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "builds": false, + "diagnostics": [ + { + "code": "bounds::unbounded", + "severity": "error" + } + ] + } + }, + { + "id": "bounded/unreached-list-unmarked", + "description": "a struct no protocol reaches, with a list without a maximum, is an error too", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\n", + "schemas": [ + { + "path": "src/models.ids", + "text": "struct Blob {\n data: u8[]\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "builds": false, + "diagnostics": [ + { + "code": "bounds::unbounded", + "severity": "error" + } + ] + } + }, + { + "id": "bounded/unreached-allowed-still-unmarked", + "description": "allowing @unverified in the package doesn't cover a type no protocol reaches: nothing marked it", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\nsettings = { annotations = { unverified = { allowed = true } } }\n", + "schemas": [ + { + "path": "src/models.ids", + "text": "struct Blob {\n data: string\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "builds": false, + "diagnostics": [ + { + "code": "bounds::unbounded", + "severity": "error" + } + ] + } + }, + { + "id": "bounded/unreached-bounded", + "description": "a struct no protocol reaches, bounded, gives nothing up and builds", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\n", + "schemas": [ + { + "path": "src/models.ids", + "text": "struct Blob {\n data: char[max 64]\n tags: u8[max 16]\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "protocols": [], + "builds": true, + "diagnostics": [] + } } ] } diff --git a/compiler/cases/references.json b/compiler/cases/references.json index 8f7675e..8e7a4f4 100644 --- a/compiler/cases/references.json +++ b/compiler/cases/references.json @@ -907,11 +907,11 @@ "packages": [ { "name": "app", - "config": "congregation app\nspecification_version = 1\n", + "config": "congregation app\nspecification_version = 1\nsettings = { annotations = { unverified = { allowed = true } } }\n", "schemas": [ { "path": "src/archive.ids", - "text": "struct Invoice {\n data: string\n}\n" + "text": "struct Invoice {\n data: string\n}\n\n@unverified = \"the archive keeps what it is given\"\nprotocol Dump {\n function put(i: Invoice);\n}\n" }, { "path": "src/billing/api.ids", @@ -928,13 +928,31 @@ "build": "app", "expect": { "protocols": [ + { + "name": "Dump", + "given_up": [ + "bounded_size" + ], + "acknowledged": [ + { + "guarantee": "bounded_size", + "scope": "protocol", + "reason": "the archive keeps what it is given" + } + ] + }, { "name": "Orders", "given_up": [] } ], "builds": true, - "diagnostics": [] + "diagnostics": [ + { + "code": "unverified::bounded-size", + "severity": "warning" + } + ] } }, { @@ -943,11 +961,11 @@ "packages": [ { "name": "app", - "config": "congregation app\nspecification_version = 1\n", + "config": "congregation app\nspecification_version = 1\nsettings = { annotations = { unverified = { allowed = true } } }\n", "schemas": [ { "path": "src/archive.ids", - "text": "struct Invoice {\n data: string\n}\n" + "text": "struct Invoice {\n data: string\n}\n\n@unverified = \"the archive keeps what it is given\"\nprotocol Dump {\n function put(i: Invoice);\n}\n" }, { "path": "src/billing/api.ids", @@ -964,13 +982,31 @@ "build": "app", "expect": { "protocols": [ + { + "name": "Dump", + "given_up": [ + "bounded_size" + ], + "acknowledged": [ + { + "guarantee": "bounded_size", + "scope": "protocol", + "reason": "the archive keeps what it is given" + } + ] + }, { "name": "Orders", "given_up": [] } ], "builds": true, - "diagnostics": [] + "diagnostics": [ + { + "code": "unverified::bounded-size", + "severity": "warning" + } + ] } }, { @@ -979,11 +1015,11 @@ "packages": [ { "name": "app", - "config": "congregation app\nspecification_version = 1\n", + "config": "congregation app\nspecification_version = 1\nsettings = { annotations = { unverified = { allowed = true } } }\n", "schemas": [ { "path": "src/archive.ids", - "text": "struct Invoice {\n data: string\n}\n" + "text": "struct Invoice {\n data: string\n}\n\n@unverified = \"the archive keeps what it is given\"\nprotocol Dump {\n function put(i: Invoice);\n}\n" }, { "path": "src/billing/api.ids", @@ -1000,13 +1036,31 @@ "build": "app", "expect": { "protocols": [ + { + "name": "Dump", + "given_up": [ + "bounded_size" + ], + "acknowledged": [ + { + "guarantee": "bounded_size", + "scope": "protocol", + "reason": "the archive keeps what it is given" + } + ] + }, { "name": "Orders", "given_up": [] } ], "builds": true, - "diagnostics": [] + "diagnostics": [ + { + "code": "unverified::bounded-size", + "severity": "warning" + } + ] } }, { @@ -1015,11 +1069,11 @@ "packages": [ { "name": "app", - "config": "congregation app\nspecification_version = 1\n", + "config": "congregation app\nspecification_version = 1\nsettings = { annotations = { unverified = { allowed = true } } }\n", "schemas": [ { "path": "src/archive.ids", - "text": "struct Invoice {\n data: string\n}\n" + "text": "struct Invoice {\n data: string\n}\n\n@unverified = \"the archive keeps what it is given\"\nprotocol Dump {\n function put(i: Invoice);\n}\n" }, { "path": "src/billing/api.ids", @@ -1036,13 +1090,31 @@ "build": "app", "expect": { "protocols": [ + { + "name": "Dump", + "given_up": [ + "bounded_size" + ], + "acknowledged": [ + { + "guarantee": "bounded_size", + "scope": "protocol", + "reason": "the archive keeps what it is given" + } + ] + }, { "name": "Orders", "given_up": [] } ], "builds": true, - "diagnostics": [] + "diagnostics": [ + { + "code": "unverified::bounded-size", + "severity": "warning" + } + ] } }, { @@ -1051,11 +1123,11 @@ "packages": [ { "name": "app", - "config": "congregation app\nspecification_version = 1\n", + "config": "congregation app\nspecification_version = 1\nsettings = { annotations = { unverified = { allowed = true } } }\n", "schemas": [ { "path": "src/archive.ids", - "text": "struct Invoice {\n data: string\n}\n" + "text": "struct Invoice {\n data: string\n}\n\n@unverified = \"the archive keeps what it is given\"\nprotocol Dump {\n function put(i: Invoice);\n}\n" }, { "path": "src/billing/api.ids", @@ -1072,13 +1144,31 @@ "build": "app", "expect": { "protocols": [ + { + "name": "Dump", + "given_up": [ + "bounded_size" + ], + "acknowledged": [ + { + "guarantee": "bounded_size", + "scope": "protocol", + "reason": "the archive keeps what it is given" + } + ] + }, { "name": "Orders", "given_up": [] } ], "builds": true, - "diagnostics": [] + "diagnostics": [ + { + "code": "unverified::bounded-size", + "severity": "warning" + } + ] } }, { @@ -1087,11 +1177,11 @@ "packages": [ { "name": "app", - "config": "congregation app\nspecification_version = 1\n", + "config": "congregation app\nspecification_version = 1\nsettings = { annotations = { unverified = { allowed = true } } }\n", "schemas": [ { "path": "src/archive.ids", - "text": "struct Invoice {\n data: string\n}\n" + "text": "struct Invoice {\n data: string\n}\n\n@unverified = \"the archive keeps what it is given\"\nprotocol Dump {\n function put(i: Invoice);\n}\n" }, { "path": "src/billing/api.ids", diff --git a/compiler/readme.md b/compiler/readme.md index 6dd0155..2dc6b06 100644 --- a/compiler/readme.md +++ b/compiler/readme.md @@ -133,7 +133,7 @@ cases with `dependencies`, which are in `acceptance` and `chain`. | `marker` | the gate (`annotations.unverified.allowed`); a marker required where a protocol gives something up (its own `@handshake`, the package's default); its reason; a marker where nothing is given up | | `keyed` | `@unverified = { = "" }`: the exact set, an unknown id, a missing one, one listed that isn't given up, one listed twice | | `package` | `unverified` in `config.idp`: the keyed and plain forms covering what a protocol takes from the package's settings; a protocol with its own `@handshake` not covered; `unverified::wrong-scope` for `bounded_size`; a guarantee no protocol gives up through it; the gate; a marker adding `bounded_size` | -| `bounded` | `bounded_size`: a string or list without a maximum, a type that contains itself without `@max_depth`, a type from another schema of the package that holds one, each unmarked (an error) and marked (given up), and the bounded variants | +| `bounded` | `bounded_size`: a string or list without a maximum, a type that contains itself without `@max_depth`, a type from another schema of the package that holds one, each unmarked (an error) and marked (given up), a type no protocol reaches (it has to be bounded: an error where it holds a string or list without a maximum, even where the package allows `@unverified`), and the bounded variants | | `acceptance` | a dependency's unverified protocols accepted under it in `config.idp`: not at all, exactly, for less, for more; the reasons the consumer is shown; the dependency judged by its own package | | `imports` | where a `use` path starts: a package's own schemas only through `package::`, `parent::` or `self::` (a bare path to one is `import::bare-own-schema-path`, in each form of a `use`), a dependency's and `std`'s paths as they were, a path matching nothing (`import::unresolved`), a schema named like a dependency, and the names a dependency can't have | | `references` | how a type is named once imported, the Rust model: a whole-namespace `use` brings in only its name (`types::User`, and a bare `User` is `reference::not-in-scope`); a `use` of an item, `{...}` or `*` brings in the names it lists (and `types::User` after it is `reference::qualifier-not-in-scope`); a full path (`package::`, `parent::`, `self::`, `std::`, a dependency's) in a type position with no `use`; a path going down from a name in scope, a dependency's name included; a name defined twice (`reference::defined-twice`) and an alias resolving it; each spelling reaching the same type, and a package written before the rule unchanged | diff --git a/compiler/src/bounded.cue b/compiler/src/bounded.cue index 98e6333..3323943 100644 --- a/compiler/src/bounded.cue +++ b/compiler/src/bounded.cue @@ -219,4 +219,52 @@ groups: bounded: { warnings: [] } } + + // A position no protocol reaches is a type another package can use, and + // has to be bounded. Only a marked protocol that reaches the type gives + // it up (`other-schema-marked`), and a type nothing reaches has none. + "unreached-unmarked": { + about: "a struct no protocol reaches, with a string without a maximum, is an error: it is a type another package can use" + packages: app: schemas: models: """ + struct Blob { + data: string + } + """ + build: "app" + expect: {builds: false, errors: ["bounds::unbounded"]} + } + "unreached-list-unmarked": { + about: "a struct no protocol reaches, with a list without a maximum, is an error too" + packages: app: schemas: models: """ + struct Blob { + data: u8[] + } + """ + build: "app" + expect: {builds: false, errors: ["bounds::unbounded"]} + } + "unreached-allowed-still-unmarked": { + about: "allowing @unverified in the package doesn't cover a type no protocol reaches: nothing marked it" + packages: app: { + config: [_allow] + schemas: models: """ + struct Blob { + data: string + } + """ + } + build: "app" + expect: {builds: false, errors: ["bounds::unbounded"]} + } + "unreached-bounded": { + about: "a struct no protocol reaches, bounded, gives nothing up and builds" + packages: app: schemas: models: """ + struct Blob { + data: char[max 64] + tags: u8[max 16] + } + """ + build: "app" + expect: {builds: true, protocols: {}} + } } diff --git a/compiler/src/references.cue b/compiler/src/references.cue index 4bd80c6..94c1cc2 100644 --- a/compiler/src/references.cue +++ b/compiler/src/references.cue @@ -65,13 +65,30 @@ _refBilling: """ } """ -// The decoy: another `Invoice`, in a schema that sorts before `billing`. +// The decoy: another `Invoice`, in a schema that sorts before `billing`. Its +// string has no maximum, so the schema builds on its own only because its own +// marked protocol reaches the type and gives bounded size up (a position no +// protocol reaches has to be bounded); the protocol is in the expected +// outcome of every case. A spelling that wrongly reaches it from an unmarked +// protocol is `bounds::unbounded`. +_refDumps: "the archive keeps what it is given" _refArchive: """ struct Invoice { data: string } + + @unverified = "\(_refDumps)" + protocol Dump { + function put(i: Invoice); + } """ +// What the decoy's package expects of `Dump`, beside `Orders`. +_refDump: { + given_up: ["bounded_size"] + acknowledged: bounded_size: {scope: "protocol", reason: _refDumps} +} + _refGreeting: """ struct Greeting { text: char[max 64] @@ -377,60 +394,98 @@ groups: references: { // which an unmarked protocol using it can't give up. "resolved-item": { about: "use package::billing::api::Invoice, then Invoice, reaches billing::api::Invoice" - packages: app: schemas: { - "archive": _refArchive - "billing/api": _refBilling - "api": "use package::billing::api::Invoice\n\n" + (_refOrders & {_ref: "Invoice"}).text + packages: app: { + config: [_allow] + schemas: { + "archive": _refArchive + "billing/api": _refBilling + "api": "use package::billing::api::Invoice\n\n" + (_refOrders & {_ref: "Invoice"}).text + } } build: "app" - expect: {builds: true, protocols: Orders: given_up: [], warnings: []} + expect: { + builds: true + protocols: {Dump: _refDump, Orders: given_up: []} + warnings: ["unverified::bounded-size"] + } } "resolved-namespace": { about: "use package::billing::api, then api::Invoice, reaches billing::api::Invoice" - packages: app: schemas: { - "archive": _refArchive - "billing/api": _refBilling - "api": "use package::billing::api\n\n" + (_refOrders & {_ref: "api::Invoice"}).text + packages: app: { + config: [_allow] + schemas: { + "archive": _refArchive + "billing/api": _refBilling + "api": "use package::billing::api\n\n" + (_refOrders & {_ref: "api::Invoice"}).text + } } build: "app" - expect: {builds: true, protocols: Orders: given_up: [], warnings: []} + expect: { + builds: true + protocols: {Dump: _refDump, Orders: given_up: []} + warnings: ["unverified::bounded-size"] + } } "resolved-descent": { about: "use package::billing, then billing::api::Invoice, reaches billing::api::Invoice" - packages: app: schemas: { - "archive": _refArchive - "billing/api": _refBilling - "api": "use package::billing\n\n" + (_refOrders & {_ref: "billing::api::Invoice"}).text + packages: app: { + config: [_allow] + schemas: { + "archive": _refArchive + "billing/api": _refBilling + "api": "use package::billing\n\n" + (_refOrders & {_ref: "billing::api::Invoice"}).text + } } build: "app" - expect: {builds: true, protocols: Orders: given_up: [], warnings: []} + expect: { + builds: true + protocols: {Dump: _refDump, Orders: given_up: []} + warnings: ["unverified::bounded-size"] + } } "resolved-alias": { about: "use package::billing::api as b, then b::Invoice, reaches billing::api::Invoice" - packages: app: schemas: { - "archive": _refArchive - "billing/api": _refBilling - "api": "use package::billing::api as b\n\n" + (_refOrders & {_ref: "b::Invoice"}).text + packages: app: { + config: [_allow] + schemas: { + "archive": _refArchive + "billing/api": _refBilling + "api": "use package::billing::api as b\n\n" + (_refOrders & {_ref: "b::Invoice"}).text + } } build: "app" - expect: {builds: true, protocols: Orders: given_up: [], warnings: []} + expect: { + builds: true + protocols: {Dump: _refDump, Orders: given_up: []} + warnings: ["unverified::bounded-size"] + } } "resolved-full-path": { about: "package::billing::api::Invoice with no use reaches billing::api::Invoice" - packages: app: schemas: { - "archive": _refArchive - "billing/api": _refBilling - "api": (_refOrders & {_ref: "package::billing::api::Invoice"}).text + packages: app: { + config: [_allow] + schemas: { + "archive": _refArchive + "billing/api": _refBilling + "api": "" + (_refOrders & {_ref: "package::billing::api::Invoice"}).text + } } build: "app" - expect: {builds: true, protocols: Orders: given_up: [], warnings: []} + expect: { + builds: true + protocols: {Dump: _refDump, Orders: given_up: []} + warnings: ["unverified::bounded-size"] + } } "resolved-decoy": { about: "use package::archive, then archive::Invoice, reaches the unbounded Invoice, which an unmarked protocol can't use: the other cases reached billing's" - packages: app: schemas: { - "archive": _refArchive - "billing/api": _refBilling - "api": "use package::archive\n\n" + (_refOrders & {_ref: "archive::Invoice"}).text + packages: app: { + config: [_allow] + schemas: { + "archive": _refArchive + "billing/api": _refBilling + "api": "use package::archive\n\n" + (_refOrders & {_ref: "archive::Invoice"}).text + } } build: "app" expect: {builds: false, errors: ["bounds::unbounded"]}