Skip to content

Commit 96b4e3f

Browse files
Remove use of the obsolete handle keyword (#343)
1 parent 621f0ed commit 96b4e3f

19 files changed

+59
-98
lines changed

crates/wit-parser/src/ast.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ enum Type<'a> {
8787
Float64,
8888
Char,
8989
String,
90-
Handle(Id<'a>),
9190
Name(Id<'a>),
9291
List(Box<Type<'a>>),
9392
Record(Record<'a>),
@@ -494,10 +493,6 @@ impl<'a> Type<'a> {
494493
Some((_span, Token::Float32)) => Ok(Type::Float32),
495494
Some((_span, Token::Float64)) => Ok(Type::Float64),
496495
Some((_span, Token::Char)) => Ok(Type::Char),
497-
Some((_span, Token::Handle)) => {
498-
let name = parse_id(tokens)?;
499-
Ok(Type::Handle(name))
500-
}
501496

502497
// tuple<T, U, ...>
503498
Some((_span, Token::Tuple)) => {
@@ -592,7 +587,7 @@ impl<'a> Type<'a> {
592587
name: tokens.parse_id(span)?.into(),
593588
span,
594589
})),
595-
// `@foo`
590+
// `%foo`
596591
Some((span, Token::ExplicitId)) => Ok(Type::Name(Id {
597592
name: tokens.parse_explicit_id(span)?.into(),
598593
span,

crates/wit-parser/src/ast/lex.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ pub enum Token {
6161
Float32,
6262
Float64,
6363
Char,
64-
Handle,
6564
Record,
6665
Flags,
6766
Variant,
@@ -250,7 +249,6 @@ impl<'a> Tokenizer<'a> {
250249
"float32" => Float32,
251250
"float64" => Float64,
252251
"char" => Char,
253-
"handle" => Handle,
254252
"record" => Record,
255253
"flags" => Flags,
256254
"variant" => Variant,
@@ -513,7 +511,6 @@ impl Token {
513511
Float32 => "keyword `float32`",
514512
Float64 => "keyword `float64`",
515513
Char => "keyword `char`",
516-
Handle => "keyword `handle`",
517514
Record => "keyword `record`",
518515
Flags => "keyword `flags`",
519516
Variant => "keyword `variant`",

crates/wit-parser/src/ast/resolve.rs

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -379,31 +379,25 @@ impl Resolver {
379379
super::Type::Float64 => TypeDefKind::Type(Type::Float64),
380380
super::Type::Char => TypeDefKind::Type(Type::Char),
381381
super::Type::String => TypeDefKind::Type(Type::String),
382-
super::Type::Handle(resource) => {
383-
let id = match self.resource_lookup.get(&*resource.name) {
384-
Some(id) => *id,
385-
None => {
386-
return Err(Error {
387-
span: resource.span,
388-
msg: format!("no resource named `{}`", resource.name),
389-
}
390-
.into())
391-
}
392-
};
393-
TypeDefKind::Type(Type::Handle(id))
394-
}
395382
super::Type::Name(name) => {
396-
let id = match self.type_lookup.get(&*name.name) {
397-
Some(id) => *id,
398-
None => {
399-
return Err(Error {
400-
span: name.span,
401-
msg: format!("no type named `{}`", name.name),
383+
// Because resources are referred to directly by name,
384+
// first check to see if we can look up this name as a
385+
// resource.
386+
if let Some(id) = self.resource_lookup.get(&*name.name) {
387+
TypeDefKind::Type(Type::Handle(*id))
388+
} else {
389+
let id = match self.type_lookup.get(&*name.name) {
390+
Some(id) => *id,
391+
None => {
392+
return Err(Error {
393+
span: name.span,
394+
msg: format!("no type named `{}`", name.name),
395+
}
396+
.into())
402397
}
403-
.into())
404-
}
405-
};
406-
TypeDefKind::Type(Type::Id(id))
398+
};
399+
TypeDefKind::Type(Type::Id(id))
400+
}
407401
}
408402
super::Type::List(list) => {
409403
let ty = self.resolve_type(list)?;

crates/wit-parser/tests/ui/comments.wit

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
type /* foo */ bar /* baz */ = //
10-
handle //
10+
stream < //
1111
//
1212
//
1313

@@ -16,4 +16,6 @@ handle //
1616

1717
x
1818

19+
>
20+
1921
resource /* x */ x // ...

crates/wit-parser/tests/ui/comments.wit.result

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
{
99
"idx": 0,
1010
"name": "bar",
11-
"primitive": "handle-0"
11+
"stream": {
12+
"element": "handle-0",
13+
"end": null
14+
}
1215
},
1316
{
1417
"idx": 1,

crates/wit-parser/tests/ui/import-me-too.wit.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ resource x
1818
## `handle`
1919
```wit
2020
/// This is handle.
21-
type %handle = handle x
21+
type handle = x
2222
```
2323

2424
## `some-record`

crates/wit-parser/tests/ui/import-me.wit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ type foo = u32
22

33
resource x
44

5-
type %handle = handle x
5+
type handle = x
66

77
type some-record = tuple<u32, u64, float32>

crates/wit-parser/tests/ui/imports-from-wit-md.wit

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ use { x as import-me-x } from import-me-too
77

88
type x = foo
99
type y = bar
10-
type z1 = import-me-x
11-
type z2 = handle import-me-x
10+
type z = import-me-x
1211

13-
use { %handle } from import-me-too
12+
use { handle } from import-me-too
1413
resource xyz
15-
type my-handle = handle xyz
16-
type my-handle2 = xyz
14+
type my-handle = xyz
1715

1816
use { some-record } from import-me-too

crates/wit-parser/tests/ui/imports-from-wit-md.wit.result

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,27 +50,17 @@
5050
},
5151
{
5252
"idx": 6,
53-
"name": "z1",
54-
"primitive": "type-1"
55-
},
56-
{
57-
"idx": 7,
58-
"name": "z2",
53+
"name": "z",
5954
"primitive": "handle-0"
6055
},
6156
{
62-
"idx": 8,
57+
"idx": 7,
6358
"primitive": "handle-1"
6459
},
6560
{
66-
"idx": 9,
61+
"idx": 8,
6762
"name": "my-handle",
6863
"primitive": "handle-1"
69-
},
70-
{
71-
"idx": 10,
72-
"name": "my-handle2",
73-
"primitive": "type-8"
7464
}
7565
]
7666
}

crates/wit-parser/tests/ui/imports.wit

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ use { x as import-me-x } from import-me
55
type x = foo
66
type y = bar
77
type z1 = import-me-x
8-
type z2 = handle import-me-x
98

10-
use { %handle } from import-me
9+
use { handle } from import-me
1110
resource xyz
12-
type my-handle = handle xyz
13-
type my-handle2 = xyz
11+
type my-handle = xyz
1412

1513
use { some-record } from import-me

crates/wit-parser/tests/ui/imports.wit.result

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,16 @@
5151
{
5252
"idx": 6,
5353
"name": "z1",
54-
"primitive": "type-1"
55-
},
56-
{
57-
"idx": 7,
58-
"name": "z2",
5954
"primitive": "handle-0"
6055
},
6156
{
62-
"idx": 8,
57+
"idx": 7,
6358
"primitive": "handle-1"
6459
},
6560
{
66-
"idx": 9,
61+
"idx": 8,
6762
"name": "my-handle",
6863
"primitive": "handle-1"
69-
},
70-
{
71-
"idx": 10,
72-
"name": "my-handle2",
73-
"primitive": "type-8"
7464
}
7565
]
7666
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
use * from import-me
22

3-
type my-handle = handle x
4-
type my-handle2 = x
3+
type my-handle = x

crates/wit-parser/tests/ui/imports2.wit.result

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@
3939
"idx": 4,
4040
"name": "my-handle",
4141
"primitive": "handle-0"
42-
},
43-
{
44-
"idx": 5,
45-
"name": "my-handle2",
46-
"primitive": "type-3"
4742
}
4843
]
4944
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// parse-fail
2+
type foo = bar
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
no type named `bar`
2+
--> tests/ui/parse-fail/alias-no-type.wit:2:12
3+
|
4+
2 | type foo = bar
5+
| ^--

crates/wit-parser/tests/ui/parse-fail/handle-no-resource.wit

Lines changed: 0 additions & 2 deletions
This file was deleted.

crates/wit-parser/tests/ui/parse-fail/handle-no-resource.wit.result

Lines changed: 0 additions & 5 deletions
This file was deleted.

crates/wit-parser/tests/ui/types.wit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type t15 = result<u32, u32>
1818
type t16 = result<_, u32>
1919
type t17 = result<u32>
2020
type t18 = result
21-
type t19 = handle x
21+
type t19 = x
2222
record t20 {}
2323
record t21 { a: u32 }
2424
record t22 { a: u32, }

crates/wit-parser/tests/ui/wasi-http.wit

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@
3131
//
3232
// Note: the `blocking` attribute means that different lowering can be generated for this
3333
// function, either based on synchronous, blocking calls, or on a callback-style interface.
34-
fetch: /*blocking*/ func(req: handle request) -> handle response
34+
fetch: /*blocking*/ func(req: request) -> response
3535

3636
/// A request resource, with lots of things missing for now.
3737
// Note: `resource` blocks serve two purposes:
3838
// 1. namespacing the definition of a Handle type with functions for operating on that handle
3939
// 2. providing a way to define said functions such that they implicitly take the handle itself as
4040
// the first argument. E.g., `method` in `request` is roughly equivalent to
41-
// `request::method: func(self: handle request) -> (string)`
41+
// `request::method: func(self: request) -> (string)`
4242
// ("Roughly" because the `resource` semantics allow us to generate better bindings for languages
4343
// that have a concept of implicit receivers, such as `this` in JS.)
4444
resource request {
@@ -47,26 +47,26 @@ resource request {
4747
/// @return req - returns a new `request`
4848
// Note: `static` here simply means that no implicit receiver argument will be passed.
4949
// I.e., this is ~roughly~ analogous to a top-level definition of
50-
// `request::request: func() -> (req: handle request)`
50+
// `request::request: func() -> (req: request)`
5151
// whereas without `static`, it'd be analogous to
52-
// `request::request: func(self: handle<request>) -> (req: handle<request>)`
53-
static request: func() -> handle request
52+
// `request::request: func(self: request) -> (req: request)`
53+
static request: func() -> request
5454

5555
method: func() -> string
5656

5757
// Note: We could consider allowing the parens to be omitted for single return values, like so:
58-
headers: func() -> handle headers
58+
headers: func() -> headers
5959

6060
// Note: Or we could even allow leaving off the return value identifier, making it use the
6161
// function name, like so:
62-
body: func() -> handle body // This return type would be shorthand for `(body: body)`
62+
body: func() -> body // This return type would be shorthand for `(body: body)`
6363
}
6464

6565
/// A response resource, with lots of things missing for now.
6666
resource response {
6767
status: func() -> u16
68-
headers: func() -> handle headers
69-
body: func() -> handle body
68+
headers: func() -> headers
69+
body: func() -> body
7070
}
7171

7272
/// A headers resource, with lots of things missing for now.
@@ -101,13 +101,13 @@ interface nested-interface1 {
101101
resource better-request {
102102
// TODO: do we need to have a ctor with special semantics? E.g. to generate actual
103103
// constructors for languages that have them, such as JS?
104-
new: func(request: handle<request>) -> handle<better-request>
104+
new: func(request: request) -> better-request
105105
// Note: sadly, the sauce better-request uses must remain secret, so it doesn't actually
106106
// expose any of its functionality, and hence doesn't need any other methods.
107107
}
108108
/// Maps a request to an even better request.
109109
// Note: the containing scope's members are in scope in a nested interface
110-
fun: func(request: handle<request>) -> handle<response>
110+
fun: func(request: request) -> response
111111
}
112112
113113
/// Another nested interface, doing something even more neat and elaborate.
@@ -127,7 +127,7 @@ interface nested-interface2 {
127127
/// @return response - a boring, normal response
128128
/// @return added-shiny - the shiny!
129129
// Note: this just exists to demonstrate multiple return values, including their documentation
130-
fun: func(request: better-request) -> tuple<handle<response>, handle<the-thiny>>
130+
fun: func(request: better-request) -> tuple<response, the-shiny>
131131
}
132132
*/
133133

@@ -155,4 +155,4 @@ record timestamp {
155155
my-int: u32
156156

157157
/// A handle to a request
158-
my-request: handle request
158+
my-request: request

0 commit comments

Comments
 (0)