Skip to content

Commit

Permalink
wit, wit/bindgen: correctly generate linker names for world-level fun…
Browse files Browse the repository at this point in the history
…ctions and interfaces (#176)

* testdata/issues: add test case for #175

* wit/bindgen: propagate TypeOwner (World or Interface)

* wit/bindgen: rename funcDecl fields

* wit/bindgen: embed original wit.Function, Direction, and owner in funcDecl

* wit/bindgen: use pointer to funcDecl

* wit/bindgen: use embedded fields in funcDecl

* wit/bindgen: constrain defined list to wit.Node

* wit/bindgen: use pointers to typeDecl

* wit, wit/bindgen: WITPackage() method

* wit/bindgen: correctly generate linker prefix for world-scoped functions

Fixes #175.

* testdata/issues: add world-scoped imported function that forces $root module

* wit/bindgen: start to scope Go packages by WorldItem, not Ident

* wit/bindgen: detect $root module name

* wit/bindgen: split out method newPackage

* wit/bindgen: remove calls to ownerIdent

* wit/bindgen: remove interfaceIDs map

* wit: update tests for interfaces with nil names

* wit: remove unused Indent methods

* wit, wit/bindgen: remove InterfaceName method, prepopulate generator.moduleNames map

* wit/bindgen: remove wit/bindgen prefix from generated Go packages in tests

* wit/bindgen: detect and return error from defineWorld

* wit/bindgen: correctly generate interfaces from other packages

* CHANGELOG: add link to #175
  • Loading branch information
ydnar authored Sep 24, 2024
1 parent b0ee41a commit c752574
Show file tree
Hide file tree
Showing 9 changed files with 457 additions and 244 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
- [#165](https://github.com/bytecodealliance/wasm-tools-go/issues/165): fixed use of imported types in exported functions.
- [#167](https://github.com/bytecodealliance/wasm-tools-go/issues/167): fixed a logic flaw in `TestHasBorrow`.
- [#170](https://github.com/bytecodealliance/wasm-tools-go/issues/170): resolve implied names for interface imports and exports in a world.
- [#175](https://github.com/bytecodealliance/wasm-tools-go/issues/175): generated correct symbol names for imported and exported functions in worlds (`$root`) or interfaces declared inline in worlds.

## [v0.2.0] — 2024-09-05

Expand Down
15 changes: 15 additions & 0 deletions testdata/issues/issue175.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package issues:issue175;

world w {
export example: interface {
f1: func() -> s32;
resource r {
constructor(a: f64);
get-a: func() -> f64;
set-a: func(a: f64);
add: static func(r: r, a: f64) -> r;
}
}
import f2: func() -> f32;
export f3: func() -> s64;
}
170 changes: 170 additions & 0 deletions testdata/issues/issue175.wit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
{
"worlds": [
{
"name": "w",
"imports": {
"f2": {
"function": {
"name": "f2",
"kind": "freestanding",
"params": [],
"results": [
{
"type": "f32"
}
]
}
}
},
"exports": {
"f3": {
"function": {
"name": "f3",
"kind": "freestanding",
"params": [],
"results": [
{
"type": "s64"
}
]
}
},
"example": {
"interface": {
"id": 0
}
}
},
"package": 0
}
],
"interfaces": [
{
"name": null,
"types": {
"r": 0
},
"functions": {
"f1": {
"name": "f1",
"kind": "freestanding",
"params": [],
"results": [
{
"type": "s32"
}
]
},
"[constructor]r": {
"name": "[constructor]r",
"kind": {
"constructor": 0
},
"params": [
{
"name": "a",
"type": "f64"
}
],
"results": [
{
"type": 2
}
]
},
"[method]r.get-a": {
"name": "[method]r.get-a",
"kind": {
"method": 0
},
"params": [
{
"name": "self",
"type": 1
}
],
"results": [
{
"type": "f64"
}
]
},
"[method]r.set-a": {
"name": "[method]r.set-a",
"kind": {
"method": 0
},
"params": [
{
"name": "self",
"type": 1
},
{
"name": "a",
"type": "f64"
}
],
"results": []
},
"[static]r.add": {
"name": "[static]r.add",
"kind": {
"static": 0
},
"params": [
{
"name": "r",
"type": 2
},
{
"name": "a",
"type": "f64"
}
],
"results": [
{
"type": 2
}
]
}
},
"package": 0
}
],
"types": [
{
"name": "r",
"kind": "resource",
"owner": {
"interface": 0
}
},
{
"name": null,
"kind": {
"handle": {
"borrow": 0
}
},
"owner": null
},
{
"name": null,
"kind": {
"handle": {
"own": 0
}
},
"owner": null
}
],
"packages": [
{
"name": "issues:issue175",
"interfaces": {},
"worlds": {
"w": 0
}
}
]
}
15 changes: 15 additions & 0 deletions testdata/issues/issue175.wit.json.golden.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package issues:issue175;

world w {
import f2: func() -> f32;
export f3: func() -> s64;
export example: interface {
resource r {
constructor(a: f64);
get-a: func() -> f64;
set-a: func(a: f64);
add: static func(r: r, a: f64) -> r;
}
f1: func() -> s32;
}
}
Loading

0 comments on commit c752574

Please sign in to comment.