From e6ab489490bdba038dc4cc9435c393a3c351d4ed Mon Sep 17 00:00:00 2001 From: Ben Visness Date: Mon, 17 Aug 2026 17:10:57 -0500 Subject: [PATCH 01/10] Add getters and setters to WIT and AST --- design/mvp/Binary.md | 25 +++++++++++++----- design/mvp/Explainer.md | 57 ++++++++++++++++++++++++++--------------- design/mvp/WIT.md | 38 ++++++++++++++++++++------- 3 files changed, 84 insertions(+), 36 deletions(-) diff --git a/design/mvp/Binary.md b/design/mvp/Binary.md index 51a7f2e7..f8c55962 100644 --- a/design/mvp/Binary.md +++ b/design/mvp/Binary.md @@ -420,10 +420,10 @@ Notes: be [strongly-unique]; attributes are ignored. * The `externname`s of all exports in a given component, instance, component- type or instance-type must be [strongly-unique]; attributes are ignored. -* Validation requires that `[constructor]`, `[method]` and `[static]` annotated - `plainname`s only occur on `func` imports or exports and that the first label - of a `[constructor]`, `[method]` or `[static]` matches the `plainname` of a - preceding `resource` import or export, respectively, in the same scope +* Validation requires that `plainname`s annotated with `[constructor]`, + `[method]`, `[static]`, `[get]`, or `[set]` only occur on `func` imports or + exports and that the first `label` of such a name matches the `plainname` of + a preceding `resource` import or export, respectively, in the same scope (component, component type or instance type). * 🏷️ Validation requires that `implements`-annotated imports or exports are `instance`-typed and have a `plainname` name. @@ -433,10 +433,21 @@ Notes: `vec()`, this list is entirely ignored when validating the types of components and instances. * Validation of `[constructor]` names requires a `func` type whose result type - is either `(own $R)` or `(result (own $R) E?)` where `$R` is a resource type - labeled `r`. + is either `(own $R)` or `(result (own $R) E?)`, where `$R` is the named + resource type. * Validation of `[method]` names requires the first parameter of the function - to be `(param "self" (borrow $R))`, where `$R` is the resource labeled `r`. + to be `(param "self" (borrow $R))`, where `$R` is the named resource type. +* Validation of `[get]` names requires that the function have a single + parameter `(param "self" (borrow $R))`, where `$R` is the named resource + type, and that the function have a return type. +* Validation of `[set]` names requires that the function have exactly two + parameters, that the first parameter be `(param "self" (borrow $R))`, and + that the function have either no return type or `(result (error $E)?)`. +* If both a `[get]` and `[set]` are defined with the same name (that is, if + they have the same `label`s), and the setter's second parameter has type + `$T`, then the getter's result type must be either `$T` or + `(result $T (error $E)?)`. +* πŸ”€ Functions with `[get]` or `[set]` names must not be `async`. * πŸ”— Validation requires that `versionsuffix` is preceded by an `interfaceversion` matching `canonversion` and that the concatenation of the `canonversion` and the `versionsuffix` results in a `valid semver` as defined by diff --git a/design/mvp/Explainer.md b/design/mvp/Explainer.md index 3e7f8c95..e73c41dc 100644 --- a/design/mvp/Explainer.md +++ b/design/mvp/Explainer.md @@ -2711,6 +2711,8 @@ plainname ::=