Skip to content

Commit

Permalink
wit, testdata: OwnHandle -> OwnedHandle, BorrowHandle -> BorrowedHandle
Browse files Browse the repository at this point in the history
  • Loading branch information
ydnar committed Sep 20, 2023
1 parent 3ba5058 commit 200b796
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 43 deletions.
2 changes: 1 addition & 1 deletion testdata/cross-package-resource.wit.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
},
"t": &wit.TypeDef{
Name: &"t",
Kind: &wit.OwnHandle{
Kind: &wit.OwnedHandle{
Type: &wit.TypeDef{...},
},
Owner: &wit.Interface{...},
Expand Down
4 changes: 2 additions & 2 deletions testdata/name-both-resource-and-type.wit.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
},
"t2": &wit.TypeDef{
Name: &"t2",
Kind: &wit.BorrowHandle{
Kind: &wit.BorrowedHandle{
Type: &wit.TypeDef{...},
},
Owner: &wit.Interface{...},
Expand All @@ -63,7 +63,7 @@
},
"t3": &wit.TypeDef{
Name: &"t3",
Kind: &wit.BorrowHandle{
Kind: &wit.BorrowedHandle{
Type: &wit.TypeDef{...},
},
Owner: &wit.Interface{...},
Expand Down
4 changes: 2 additions & 2 deletions testdata/resources-empty.wit.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
Name: "a",
Type: &wit.TypeDef{
Name: (*string)(nil),
Kind: &wit.OwnHandle{
Kind: &wit.OwnedHandle{
Type: &wit.TypeDef{...},
},
Owner: nil,
Expand All @@ -45,7 +45,7 @@
Name: "a",
Type: &wit.TypeDef{
Name: (*string)(nil),
Kind: &wit.BorrowHandle{
Kind: &wit.BorrowedHandle{
Type: &wit.TypeDef{...},
},
Owner: nil,
Expand Down
2 changes: 1 addition & 1 deletion testdata/resources-multiple-returns-borrow.wit.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
Name: "self",
Type: &wit.TypeDef{
Name: (*string)(nil),
Kind: &wit.BorrowHandle{
Kind: &wit.BorrowedHandle{
Type: &wit.TypeDef{...},
},
Owner: nil,
Expand Down
4 changes: 2 additions & 2 deletions testdata/resources-multiple-returns-own.wit.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
Name: "self",
Type: &wit.TypeDef{
Name: (*string)(nil),
Kind: &wit.BorrowHandle{
Kind: &wit.BorrowedHandle{
Type: &wit.TypeDef{...},
},
Owner: nil,
Expand All @@ -43,7 +43,7 @@
Name: "handle",
Type: &wit.TypeDef{
Name: (*string)(nil),
Kind: &wit.OwnHandle{
Kind: &wit.OwnedHandle{
Type: &wit.TypeDef{...},
},
Owner: nil,
Expand Down
4 changes: 2 additions & 2 deletions testdata/resources-multiple.wit.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
Name: "self",
Type: &wit.TypeDef{
Name: (*string)(nil),
Kind: &wit.BorrowHandle{
Kind: &wit.BorrowedHandle{
Type: &wit.TypeDef{...},
},
Owner: nil,
Expand Down Expand Up @@ -290,7 +290,7 @@
Name: "a",
Type: &wit.TypeDef{
Name: (*string)(nil),
Kind: &wit.OwnHandle{
Kind: &wit.OwnedHandle{
Type: &wit.TypeDef{...},
},
Owner: nil,
Expand Down
2 changes: 1 addition & 1 deletion testdata/resources-return-borrow.wit.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
Name: "self",
Type: &wit.TypeDef{
Name: (*string)(nil),
Kind: &wit.BorrowHandle{
Kind: &wit.BorrowedHandle{
Type: &wit.TypeDef{...},
},
Owner: nil,
Expand Down
4 changes: 2 additions & 2 deletions testdata/resources-return-own.wit.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
Name: "self",
Type: &wit.TypeDef{
Name: (*string)(nil),
Kind: &wit.BorrowHandle{
Kind: &wit.BorrowedHandle{
Type: &wit.TypeDef{...},
},
Owner: nil,
Expand All @@ -39,7 +39,7 @@
Name: "",
Type: &wit.TypeDef{
Name: (*string)(nil),
Kind: &wit.OwnHandle{
Kind: &wit.OwnedHandle{
Type: &wit.TypeDef{...},
},
Owner: nil,
Expand Down
18 changes: 9 additions & 9 deletions testdata/resources.wit.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
Name: "",
Type: &wit.TypeDef{
Name: (*string)(nil),
Kind: &wit.OwnHandle{
Kind: &wit.OwnedHandle{
Type: &wit.TypeDef{...},
},
Owner: nil,
Expand Down Expand Up @@ -117,7 +117,7 @@
Name: "",
Type: &wit.TypeDef{
Name: (*string)(nil),
Kind: &wit.OwnHandle{
Kind: &wit.OwnedHandle{
Type: &wit.TypeDef{...},
},
Owner: nil,
Expand Down Expand Up @@ -147,7 +147,7 @@
Name: "",
Type: &wit.TypeDef{
Name: (*string)(nil),
Kind: &wit.OwnHandle{
Kind: &wit.OwnedHandle{
Type: &wit.TypeDef{...},
},
Owner: nil,
Expand Down Expand Up @@ -177,7 +177,7 @@
Name: "",
Type: &wit.TypeDef{
Name: (*string)(nil),
Kind: &wit.OwnHandle{
Kind: &wit.OwnedHandle{
Type: &wit.TypeDef{...},
},
Owner: nil,
Expand All @@ -201,7 +201,7 @@
Name: "other",
Type: &wit.TypeDef{
Name: (*string)(nil),
Kind: &wit.OwnHandle{
Kind: &wit.OwnedHandle{
Type: &wit.TypeDef{...},
},
Owner: nil,
Expand All @@ -214,7 +214,7 @@
Name: "other2",
Type: &wit.TypeDef{
Name: (*string)(nil),
Kind: &wit.BorrowHandle{
Kind: &wit.BorrowedHandle{
Type: &wit.TypeDef{...},
},
Owner: nil,
Expand Down Expand Up @@ -244,7 +244,7 @@
Name: "self",
Type: &wit.TypeDef{
Name: (*string)(nil),
Kind: &wit.BorrowHandle{
Kind: &wit.BorrowedHandle{
Type: &wit.TypeDef{...},
},
Owner: nil,
Expand Down Expand Up @@ -324,7 +324,7 @@
},
"t2": &wit.TypeDef{
Name: &"t2",
Kind: &wit.BorrowHandle{
Kind: &wit.BorrowedHandle{
Type: &wit.TypeDef{...},
},
Owner: &wit.Interface{...},
Expand All @@ -334,7 +334,7 @@
},
"t3": &wit.TypeDef{
Name: &"t3",
Kind: &wit.BorrowHandle{
Kind: &wit.BorrowedHandle{
Type: &wit.TypeDef{...},
},
Owner: &wit.Interface{...},
Expand Down
4 changes: 2 additions & 2 deletions testdata/resources1.wit.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
Name: "self",
Type: &wit.TypeDef{
Name: (*string)(nil),
Kind: &wit.BorrowHandle{
Kind: &wit.BorrowedHandle{
Type: &wit.TypeDef{...},
},
Owner: nil,
Expand Down Expand Up @@ -61,7 +61,7 @@
Name: "a",
Type: &wit.TypeDef{
Name: (*string)(nil),
Kind: &wit.OwnHandle{
Kind: &wit.OwnedHandle{
Type: &wit.TypeDef{...},
},
Owner: nil,
Expand Down
12 changes: 6 additions & 6 deletions testdata/world-top-level-resources.wit.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
Name: "self",
Type: &wit.TypeDef{
Name: (*string)(nil),
Kind: &wit.BorrowHandle{
Kind: &wit.BorrowedHandle{
Type: &wit.TypeDef{...},
},
Owner: nil,
Expand Down Expand Up @@ -88,7 +88,7 @@
Name: "self",
Type: &wit.TypeDef{
Name: (*string)(nil),
Kind: &wit.BorrowHandle{
Kind: &wit.BorrowedHandle{
Type: &wit.TypeDef{...},
},
Owner: nil,
Expand Down Expand Up @@ -160,7 +160,7 @@
Name: "some",
Type: &wit.TypeDef{
Name: (*string)(nil),
Kind: &wit.BorrowHandle{
Kind: &wit.BorrowedHandle{
Type: &wit.TypeDef{...},
},
Owner: nil,
Expand All @@ -175,7 +175,7 @@
Name: "",
Type: &wit.TypeDef{
Name: (*string)(nil),
Kind: &wit.BorrowHandle{
Kind: &wit.BorrowedHandle{
Type: &wit.TypeDef{...},
},
Owner: nil,
Expand All @@ -197,7 +197,7 @@
Name: "some",
Type: &wit.TypeDef{
Name: (*string)(nil),
Kind: &wit.OwnHandle{
Kind: &wit.OwnedHandle{
Type: &wit.TypeDef{...},
},
Owner: nil,
Expand All @@ -212,7 +212,7 @@
Name: "",
Type: &wit.TypeDef{
Name: (*string)(nil),
Kind: &wit.OwnHandle{
Kind: &wit.OwnedHandle{
Type: &wit.TypeDef{...},
},
Owner: nil,
Expand Down
4 changes: 2 additions & 2 deletions wit/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,10 @@ func (c *handleCodec) DecodeField(dec codec.Decoder, name string) error {
var err error
switch name {
case "own":
v := &OwnHandle{}
v := &OwnedHandle{}
*c.v, err = v, dec.Decode(&v.Type)
case "borrow":
v := &BorrowHandle{}
v := &BorrowedHandle{}
*c.v, err = v, dec.Decode(&v.Type)
}
return err
Expand Down
31 changes: 20 additions & 11 deletions wit/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type World struct {
// currently either an [Interface], [TypeDef], or [Function].
type WorldItem interface{ isWorldItem() }

// _worldItem is an embeddable type that conforms to the WorldItem interface.
// _worldItem is an embeddable type that conforms to the [WorldItem] interface.
type _worldItem struct{}

func (_worldItem) isWorldItem() {}
Expand Down Expand Up @@ -87,14 +87,14 @@ func (t *TypeDef) TypeName() string {
// [Option], [Result], [List], [Future], [Stream], or [Type].
type TypeDefKind interface{ isTypeDefKind() }

// _typeDefKind is an embeddable type that conforms to the TypeDefKind interface.
// _typeDefKind is an embeddable type that conforms to the [TypeDefKind] interface.
type _typeDefKind struct{}

func (_typeDefKind) isTypeDefKind() {}

// Record represents a WIT [record type], akin to a struct.
//
// [record type]: https://component-model.bytecodealliance.org/wit-overview.html#records
// [record type]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/WIT.md#item-record-bag-of-named-fields
type Record struct {
Fields []Field
_typeDefKind
Expand All @@ -107,29 +107,38 @@ type Field struct {
Docs Docs
}

// Resource represents a WIT resource type.
// Resource represents a WIT [resource type].
//
// [resource type]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/WIT.md#item-resource
type Resource struct{ _typeDefKind }

func (Resource) UnmarshalText() ([]byte, error) { return []byte("resource"), nil }

// Handle represents a WIT handle type.
// Handle represents a WIT [handle type].
//
// [handle type]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/WIT.md#handles
type Handle interface {
isHandle()
TypeDefKind
}

// _handle is an embeddable type that conforms to the [Handle] interface.
type _handle struct{ _typeDefKind }

func (_handle) isHandle() {}

// OwnHandle represents an owned WIT handle type.
type OwnHandle struct {
// OwnedHandle represents an WIT [owned handle].
//
// [owned handle]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/WIT.md#handles
type OwnedHandle struct {
Type *TypeDef
_handle
}

// BorrowHandle represents an borrowed WIT handle type.
type BorrowHandle struct {
// BorrowedHandle represents a WIT [borrowed handle].
//
// [borrowed handle]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/WIT.md#handles
type BorrowedHandle struct {
Type *TypeDef
_handle
}
Expand Down Expand Up @@ -256,7 +265,7 @@ type Type interface {
TypeDefKind
}

// _type is an embeddable type that conforms to the Type interface.
// _type is an embeddable type that conforms to the [Type] interface.
type _type struct{ _typeDefKind }

func (_type) isType() {}
Expand Down Expand Up @@ -466,7 +475,7 @@ type FunctionKind interface {
isFunctionKind()
}

// _functionKind is an embeddable type that conforms to the FunctionKind interface.
// _functionKind is an embeddable type that conforms to the [FunctionKind] interface.
type _functionKind struct{}

func (_functionKind) isFunctionKind() {}
Expand Down

0 comments on commit 200b796

Please sign in to comment.