├── .github └── workflows │ ├── main.yml │ ├── publish-binaries.yml │ └── publish-to-crates-io.yml ├── .gitignore ├── CODE_OF_CONDUCT.md ├── Cargo.lock ├── Cargo.toml ├── Cross.toml ├── LANGUAGE.md ├── LICENSE ├── ORG_CODE_OF_CONDUCT.md ├── README.md ├── ci └── publish.rs ├── crates ├── wac-graph │ ├── Cargo.toml │ ├── src │ │ ├── encoding.rs │ │ ├── graph.rs │ │ ├── lib.rs │ │ └── plug.rs │ └── tests │ │ ├── encoding.rs │ │ └── graphs │ │ ├── argument-already-satisfied │ │ ├── error.txt │ │ ├── foo.wat │ │ └── graph.json │ │ ├── argument-type-mismatch │ │ ├── error.txt │ │ ├── foo.wat │ │ └── graph.json │ │ ├── contains-cycle │ │ ├── error.txt │ │ ├── foo.wat │ │ └── graph.json │ │ ├── duplicate-imports │ │ ├── encoded.wat │ │ ├── foo.wit │ │ │ ├── deps │ │ │ │ └── shared │ │ │ │ │ └── shared.wit │ │ │ └── package.wit │ │ └── graph.json │ │ ├── export-already-exists │ │ ├── error.txt │ │ ├── foo.wat │ │ └── graph.json │ │ ├── export-missing │ │ ├── error.txt │ │ ├── foo.wat │ │ └── graph.json │ │ ├── implicit-import-conflict │ │ ├── error.txt │ │ ├── foo.wat │ │ └── graph.json │ │ ├── implicit-resource-import │ │ ├── bar │ │ │ ├── deps │ │ │ │ └── types.wit │ │ │ └── world.wit │ │ ├── baz │ │ │ ├── deps │ │ │ │ └── types.wit │ │ │ └── world.wit │ │ ├── encoded.wat │ │ ├── graph.json │ │ └── import │ │ │ ├── deps │ │ │ └── types.wit │ │ │ └── world.wit │ │ ├── import-already-exists │ │ ├── error.txt │ │ ├── foo.wat │ │ └── graph.json │ │ ├── import-resource-alias │ │ ├── encoded.wat │ │ ├── graph.json │ │ └── world.wit │ │ ├── invalid-export-name │ │ ├── error.txt │ │ ├── foo.wat │ │ └── graph.json │ │ ├── invalid-import-name │ │ ├── error.txt │ │ ├── foo.wat │ │ └── graph.json │ │ ├── merged-func-results │ │ ├── component1.wat │ │ ├── component2.wat │ │ ├── description.txt │ │ ├── encoded.wat │ │ └── graph.json │ │ ├── merged-usings │ │ ├── component.wit │ │ ├── encoded.wat │ │ └── graph.json │ │ ├── merging-import-dependencies │ │ ├── component │ │ │ ├── deps │ │ │ │ └── types.wit │ │ │ └── world.wit │ │ ├── encoded.wat │ │ ├── graph.json │ │ └── import │ │ │ ├── deps │ │ │ └── types.wit │ │ │ └── world.wit │ │ ├── missing-argument │ │ ├── error.txt │ │ ├── foo.wat │ │ └── graph.json │ │ ├── not-an-instance │ │ ├── error.txt │ │ ├── foo.wat │ │ └── graph.json │ │ ├── not-instantiation │ │ ├── error.txt │ │ ├── foo.wat │ │ └── graph.json │ │ ├── package-already-registered │ │ ├── error.txt │ │ ├── foo.wat │ │ └── graph.json │ │ ├── simple │ │ ├── bar.wat │ │ ├── encoded.wat │ │ ├── foo.wat │ │ └── graph.json │ │ ├── type-aggregation-error │ │ ├── bar.wat │ │ ├── error.txt │ │ ├── foo.wat │ │ └── graph.json │ │ └── used-resource │ │ ├── encoded.wat │ │ ├── foo.wit │ │ └── graph.json ├── wac-parser │ ├── Cargo.toml │ ├── src │ │ ├── ast.rs │ │ ├── ast │ │ │ ├── export.rs │ │ │ ├── expr.rs │ │ │ ├── import.rs │ │ │ ├── let.rs │ │ │ ├── printer.rs │ │ │ └── type.rs │ │ ├── lexer.rs │ │ ├── lib.rs │ │ └── resolution.rs │ └── tests │ │ ├── encoding.rs │ │ ├── encoding │ │ ├── fail │ │ │ ├── arg-merge-failure.wac │ │ │ ├── arg-merge-failure.wac.result │ │ │ ├── arg-merge-failure │ │ │ │ ├── bar │ │ │ │ │ └── baz.wat │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── implicit-arg-conflict.wac │ │ │ ├── implicit-arg-conflict.wac.result │ │ │ ├── implicit-arg-conflict │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── import-conflict.wac │ │ │ ├── import-conflict.wac.result │ │ │ ├── import-conflict │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── unmergeable-args.wac │ │ │ ├── unmergeable-args.wac.result │ │ │ └── unmergeable-args │ │ │ │ ├── bar │ │ │ │ └── baz.wat │ │ │ │ └── foo │ │ │ │ └── bar.wat │ │ ├── include-resource.wac │ │ ├── include-resource.wac.result │ │ ├── include-resource │ │ │ └── foo │ │ │ │ └── bar.wat │ │ ├── instantiation.wac │ │ ├── instantiation.wac.result │ │ ├── instantiation │ │ │ ├── bar │ │ │ │ └── baz.wat │ │ │ └── foo │ │ │ │ └── bar.wat │ │ ├── merged-functions.wac │ │ ├── merged-functions.wac.result │ │ ├── merged-functions │ │ │ └── foo │ │ │ │ ├── bar.wat │ │ │ │ └── baz.wat │ │ ├── resources.wac │ │ ├── resources.wac.result │ │ ├── resources │ │ │ └── foo │ │ │ │ └── bar.wat │ │ ├── types.wac │ │ └── types.wac.result │ │ ├── parser.rs │ │ ├── parser │ │ ├── export.wac │ │ ├── export.wac.result │ │ ├── fail │ │ │ ├── bad-alias.wac │ │ │ ├── bad-alias.wac.result │ │ │ ├── duplicate-package-decl.wac │ │ │ ├── duplicate-package-decl.wac.result │ │ │ ├── empty-enum.wac │ │ │ ├── empty-enum.wac.result │ │ │ ├── empty-flags.wac │ │ │ ├── empty-flags.wac.result │ │ │ ├── empty-record.wac │ │ │ ├── empty-record.wac.result │ │ │ ├── empty-variant.wac │ │ │ ├── empty-variant.wac.result │ │ │ ├── expected-multiple.wac │ │ │ ├── expected-multiple.wac.result │ │ │ ├── expected-two.wac │ │ │ ├── expected-two.wac.result │ │ │ ├── invalid-path-semver.wac │ │ │ ├── invalid-path-semver.wac.result │ │ │ ├── invalid-semver.wac │ │ │ ├── invalid-semver.wac.result │ │ │ ├── missing-package-decl.wac │ │ │ ├── missing-package-decl.wac.result │ │ │ ├── missing-semi.wac │ │ │ └── missing-semi.wac.result │ │ ├── import.wac │ │ ├── import.wac.result │ │ ├── let.wac │ │ ├── let.wac.result │ │ ├── resource.wac │ │ ├── resource.wac.result │ │ ├── type-alias.wac │ │ ├── type-alias.wac.result │ │ ├── types.wac │ │ ├── types.wac.result │ │ ├── use.wac │ │ └── use.wac.result │ │ ├── resolution.rs │ │ ├── resolution │ │ ├── alias.wac │ │ ├── alias.wac.result │ │ ├── duplicate-world-item.wac │ │ ├── duplicate-world-item.wac.result │ │ ├── fail │ │ │ ├── borrow-in-func-result.wac │ │ │ ├── borrow-in-func-result.wac.result │ │ │ ├── duplicate-enum-case.wac │ │ │ ├── duplicate-enum-case.wac.result │ │ │ ├── duplicate-export.wac │ │ │ ├── duplicate-export.wac.result │ │ │ ├── duplicate-flag.wac │ │ │ ├── duplicate-flag.wac.result │ │ │ ├── duplicate-func-param.wac │ │ │ ├── duplicate-func-param.wac.result │ │ │ ├── duplicate-import.wac │ │ │ ├── duplicate-import.wac.result │ │ │ ├── duplicate-inst-args.wac │ │ │ ├── duplicate-inst-args.wac.result │ │ │ ├── duplicate-inst-args │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── duplicate-interface-export.wac │ │ │ ├── duplicate-interface-export.wac.result │ │ │ ├── duplicate-name-in-include.wac │ │ │ ├── duplicate-name-in-include.wac.result │ │ │ ├── duplicate-record-field.wac │ │ │ ├── duplicate-record-field.wac.result │ │ │ ├── duplicate-resource-constructor-param.wac │ │ │ ├── duplicate-resource-constructor-param.wac.result │ │ │ ├── duplicate-resource-constructor.wac │ │ │ ├── duplicate-resource-constructor.wac.result │ │ │ ├── duplicate-resource-method.wac │ │ │ ├── duplicate-resource-method.wac.result │ │ │ ├── duplicate-use-in-interface.wac │ │ │ ├── duplicate-use-in-interface.wac.result │ │ │ ├── duplicate-use-in-world.wac │ │ │ ├── duplicate-use-in-world.wac.result │ │ │ ├── duplicate-variant-case.wac │ │ │ ├── duplicate-variant-case.wac.result │ │ │ ├── duplicate-world-export.wac │ │ │ ├── duplicate-world-export.wac.result │ │ │ ├── duplicate-world-import.wac │ │ │ ├── duplicate-world-import.wac.result │ │ │ ├── expected-result-named.wac │ │ │ ├── expected-result-named.wac.result │ │ │ ├── expected-result-named │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── expected-result-scalar.wac │ │ │ ├── expected-result-scalar.wac.result │ │ │ ├── expected-result-scalar │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── export-conflict-alias.wac │ │ │ ├── export-conflict-alias.wac.result │ │ │ ├── export-conflict-interface.wac │ │ │ ├── export-conflict-interface.wac.result │ │ │ ├── export-conflict-type.wac │ │ │ ├── export-conflict-type.wac.result │ │ │ ├── export-conflict-world.wac │ │ │ ├── export-conflict-world.wac.result │ │ │ ├── export-dep-name.wac │ │ │ ├── export-dep-name.wac.result │ │ │ ├── export-duplicate-name.wac │ │ │ ├── export-duplicate-name.wac.result │ │ │ ├── export-hash-name.wac │ │ │ ├── export-hash-name.wac.result │ │ │ ├── export-invalid-name.wac │ │ │ ├── export-invalid-name.wac.result │ │ │ ├── export-needs-with.wac │ │ │ ├── export-needs-with.wac.result │ │ │ ├── export-needs-with │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── export-url-name.wac │ │ │ ├── export-url-name.wac.result │ │ │ ├── fill-not-last.wac │ │ │ ├── fill-not-last.wac.result │ │ │ ├── fill-not-last │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── func-results-not-present.wac │ │ │ ├── func-results-not-present.wac.result │ │ │ ├── func-results-not-present │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── func-results-present.wac │ │ │ ├── func-results-present.wac.result │ │ │ ├── func-results-present │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── import-duplicate-name.wac │ │ │ ├── import-duplicate-name.wac.result │ │ │ ├── import-id-span.wac │ │ │ ├── import-id-span.wac.result │ │ │ ├── import-id-span │ │ │ │ └── wasi │ │ │ │ │ └── cli │ │ │ │ │ └── package.wit │ │ │ ├── import-invalid-name.wac │ │ │ ├── import-invalid-name.wac.result │ │ │ ├── inaccessible.wac │ │ │ ├── inaccessible.wac.result │ │ │ ├── invalid-alias.wac │ │ │ ├── invalid-alias.wac.result │ │ │ ├── invalid-borrow.wac │ │ │ ├── invalid-borrow.wac.result │ │ │ ├── invalid-func-type-ref.wac │ │ │ ├── invalid-func-type-ref.wac.result │ │ │ ├── invalid-use-alias.wac │ │ │ ├── invalid-use-alias.wac.result │ │ │ ├── invalid-use.wac │ │ │ ├── invalid-use.wac.result │ │ │ ├── invalid-value-type.wac │ │ │ ├── invalid-value-type.wac.result │ │ │ ├── invalid-world-export.wac │ │ │ ├── invalid-world-export.wac.result │ │ │ ├── invalid-world-import.wac │ │ │ ├── invalid-world-import.wac.result │ │ │ ├── invalid-world-include.wac │ │ │ ├── invalid-world-include.wac.result │ │ │ ├── invalid-world-interface-export.wac │ │ │ ├── invalid-world-interface-export.wac.result │ │ │ ├── invalid-world-interface-import.wac │ │ │ ├── invalid-world-interface-import.wac.result │ │ │ ├── mismatched-enum-cases.wac │ │ │ ├── mismatched-enum-cases.wac.result │ │ │ ├── mismatched-enum-cases │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── mismatched-enum-count.wac │ │ │ ├── mismatched-enum-count.wac.result │ │ │ ├── mismatched-enum-count │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── mismatched-err-result-type.wac │ │ │ ├── mismatched-err-result-type.wac.result │ │ │ ├── mismatched-err-result-type │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── mismatched-flags-count.wac │ │ │ ├── mismatched-flags-count.wac.result │ │ │ ├── mismatched-flags-count │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── mismatched-flags.wac │ │ │ ├── mismatched-flags.wac.result │ │ │ ├── mismatched-flags │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── mismatched-func-param-name.wac │ │ │ ├── mismatched-func-param-name.wac.result │ │ │ ├── mismatched-func-param-name │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── mismatched-func-param-type.wac │ │ │ ├── mismatched-func-param-type.wac.result │ │ │ ├── mismatched-func-param-type │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── mismatched-func-params.wac │ │ │ ├── mismatched-func-params.wac.result │ │ │ ├── mismatched-func-params │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── mismatched-func-scalar-result.wac │ │ │ ├── mismatched-func-scalar-result.wac.result │ │ │ ├── mismatched-func-scalar-result │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── mismatched-kind.wac │ │ │ ├── mismatched-kind.wac.result │ │ │ ├── mismatched-kind │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── mismatched-list-element.wac │ │ │ ├── mismatched-list-element.wac.result │ │ │ ├── mismatched-list-element │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── mismatched-ok-result-type.wac │ │ │ ├── mismatched-ok-result-type.wac.result │ │ │ ├── mismatched-ok-result-type │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── mismatched-option.wac │ │ │ ├── mismatched-option.wac.result │ │ │ ├── mismatched-option │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── mismatched-record-field-count.wac │ │ │ ├── mismatched-record-field-count.wac.result │ │ │ ├── mismatched-record-field-count │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── mismatched-record-field-name.wac │ │ │ ├── mismatched-record-field-name.wac.result │ │ │ ├── mismatched-record-field-name │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── mismatched-record-field-type.wac │ │ │ ├── mismatched-record-field-type.wac.result │ │ │ ├── mismatched-record-field-type │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── mismatched-resource-types.wac │ │ │ ├── mismatched-resource-types.wac.result │ │ │ ├── mismatched-resource-types │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── mismatched-tuple-size.wac │ │ │ ├── mismatched-tuple-size.wac.result │ │ │ ├── mismatched-tuple-size │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── mismatched-tuple-type.wac │ │ │ ├── mismatched-tuple-type.wac.result │ │ │ ├── mismatched-tuple-type │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── mismatched-variant-case-count.wac │ │ │ ├── mismatched-variant-case-count.wac.result │ │ │ ├── mismatched-variant-case-count │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── mismatched-variant-case-name.wac │ │ │ ├── mismatched-variant-case-name.wac.result │ │ │ ├── mismatched-variant-case-name │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── mismatched-variant-case-type.wac │ │ │ ├── mismatched-variant-case-type.wac.result │ │ │ ├── mismatched-variant-case-type │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── missing-access-export.wac │ │ │ ├── missing-access-export.wac.result │ │ │ ├── missing-constructor.wac │ │ │ ├── missing-constructor.wac.result │ │ │ ├── missing-constructor │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── missing-err-result-type.wac │ │ │ ├── missing-err-result-type.wac.result │ │ │ ├── missing-err-result-type │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── missing-inst-arg.wac │ │ │ ├── missing-inst-arg.wac.result │ │ │ ├── missing-inst-arg │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── missing-interface-export.wac │ │ │ ├── missing-interface-export.wac.result │ │ │ ├── missing-interface-export │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── missing-method.wac │ │ │ ├── missing-method.wac.result │ │ │ ├── missing-method │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── missing-ok-result-type.wac │ │ │ ├── missing-ok-result-type.wac.result │ │ │ ├── missing-ok-result-type │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── missing-static-method.wac │ │ │ ├── missing-static-method.wac.result │ │ │ ├── missing-static-method │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── missing-target-export.wac │ │ │ ├── missing-target-export.wac.result │ │ │ ├── missing-target-export │ │ │ │ └── foo │ │ │ │ │ └── bar │ │ │ │ │ └── bar.wit │ │ │ ├── missing-type-in-use.wac │ │ │ ├── missing-type-in-use.wac.result │ │ │ ├── missing-world-include-name.wac │ │ │ ├── missing-world-include-name.wac.result │ │ │ ├── no-err-result-type.wac │ │ │ ├── no-err-result-type.wac.result │ │ │ ├── no-err-result-type │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── no-import.wac │ │ │ ├── no-import.wac.result │ │ │ ├── no-import │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── no-ok-result-type.wac │ │ │ ├── no-ok-result-type.wac.result │ │ │ ├── no-ok-result-type │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── non-instance-spread.wac │ │ │ ├── non-instance-spread.wac.result │ │ │ ├── non-instance-spread │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── package-invalid-wasm.wac │ │ │ ├── package-invalid-wasm.wac.result │ │ │ ├── package-invalid-wasm │ │ │ │ └── foo │ │ │ │ │ └── bar.wasm │ │ │ ├── package-not-component.wac │ │ │ ├── package-not-component.wac.result │ │ │ ├── package-not-component │ │ │ │ └── foo │ │ │ │ │ └── bar.wasm │ │ │ ├── package-not-wasm.wac │ │ │ ├── package-not-wasm.wac.result │ │ │ ├── package-not-wasm │ │ │ │ └── foo │ │ │ │ │ └── bar.wasm │ │ │ ├── redefined-name.wac │ │ │ ├── redefined-name.wac.result │ │ │ ├── self-instantiation.wac │ │ │ ├── self-instantiation.wac.result │ │ │ ├── spread-export-no-effect.wac │ │ │ ├── spread-export-no-effect.wac.result │ │ │ ├── spread-instantiation-no-match.wac │ │ │ ├── spread-instantiation-no-match.wac.result │ │ │ ├── spread-instantiation-no-match │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── target-export-mismatch.wac │ │ │ ├── target-export-mismatch.wac.result │ │ │ ├── target-extraneous-import.wac │ │ │ ├── target-extraneous-import.wac.result │ │ │ ├── target-import-mismatch-resource.wac │ │ │ ├── target-import-mismatch-resource.wac.result │ │ │ ├── target-import-mismatch.wac │ │ │ ├── target-import-mismatch.wac.result │ │ │ ├── target-import-param-name-mismatch.wac │ │ │ ├── target-import-param-name-mismatch.wac.result │ │ │ ├── target-import-param-type-mismatch.wac │ │ │ ├── target-import-param-type-mismatch.wac.result │ │ │ ├── target-import-unexpected-method.wac │ │ │ ├── target-import-unexpected-method.wac.result │ │ │ ├── target-is-not-a-world.wac │ │ │ ├── target-is-not-a-world.wac.result │ │ │ ├── targets-interface-use.wac │ │ │ ├── targets-interface-use.wac.result │ │ │ ├── targets-interface-use │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── targets-world-use.wac │ │ │ ├── targets-world-use.wac.result │ │ │ ├── targets-world-use │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── type-decl-conflict.wac │ │ │ ├── type-decl-conflict.wac.result │ │ │ ├── undefined-name.wac │ │ │ ├── undefined-name.wac.result │ │ │ ├── unknown-package.wac │ │ │ ├── unknown-package.wac.result │ │ │ ├── unknown-target-path.wac │ │ │ ├── unknown-target-path.wac.result │ │ │ ├── unknown-targets-path.wac │ │ │ ├── unknown-targets-path.wac.result │ │ │ ├── variant-case-typed.wac │ │ │ ├── variant-case-typed.wac.result │ │ │ ├── variant-case-typed │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── variant-case-untyped.wac │ │ │ ├── variant-case-untyped.wac.result │ │ │ ├── variant-case-untyped │ │ │ │ └── foo │ │ │ │ │ └── bar.wat │ │ │ ├── windows-file.wac │ │ │ ├── windows-file.wac.result │ │ │ ├── world-include-conflict.wac │ │ │ ├── world-include-conflict.wac.result │ │ │ ├── world-include-with-conflict.wac │ │ │ └── world-include-with-conflict.wac.result │ │ ├── import.wac │ │ ├── import.wac.result │ │ ├── import │ │ │ └── foo │ │ │ │ └── bar │ │ │ │ └── package.wit │ │ ├── let-statements.wac │ │ ├── let-statements.wac.result │ │ ├── let-statements │ │ │ ├── foo │ │ │ │ └── bar.wat │ │ │ └── wasi │ │ │ │ └── io │ │ │ │ └── package.wit │ │ ├── no-imports.wac │ │ ├── no-imports.wac.result │ │ ├── no-imports │ │ │ └── foo │ │ │ │ └── bar.wat │ │ ├── package-import.wac │ │ ├── package-import.wac.result │ │ ├── package-import │ │ │ └── foo │ │ │ │ └── bar │ │ │ │ └── package.wit │ │ ├── package-use-item.wac │ │ ├── package-use-item.wac.result │ │ ├── package-use-item │ │ │ └── foo │ │ │ │ └── bar │ │ │ │ └── package.wit │ │ ├── package-world-include.wac │ │ ├── package-world-include.wac.result │ │ ├── package-world-include │ │ │ └── foo │ │ │ │ └── bar │ │ │ │ └── package.wit │ │ ├── package-world-item.wac │ │ ├── package-world-item.wac.result │ │ ├── package-world-item │ │ │ ├── bar │ │ │ │ └── baz │ │ │ │ │ └── package.wit │ │ │ └── foo │ │ │ │ └── bar │ │ │ │ └── package.wit │ │ ├── resource.wac │ │ ├── resource.wac.result │ │ ├── targets-empty-world.wac │ │ ├── targets-empty-world.wac.result │ │ ├── targets-world.wac │ │ ├── targets-world.wac.result │ │ ├── targets-world │ │ │ └── foo │ │ │ │ └── bar.wat │ │ ├── types.wac │ │ ├── types.wac.result │ │ └── types │ │ │ └── foo │ │ │ └── bar │ │ │ └── package.wit │ │ └── support │ │ └── mod.rs ├── wac-resolver │ ├── Cargo.toml │ ├── src │ │ ├── fs.rs │ │ ├── lib.rs │ │ ├── registry.rs │ │ └── visitor.rs │ └── tests │ │ ├── registry.rs │ │ └── support │ │ └── mod.rs └── wac-types │ ├── Cargo.toml │ └── src │ ├── aggregator.rs │ ├── checker.rs │ ├── component.rs │ ├── core.rs │ ├── lib.rs │ ├── package.rs │ └── targets.rs ├── examples ├── README.md ├── deps │ └── example │ │ ├── greeter.wasm │ │ └── hello.wasm ├── programmatic │ ├── Cargo.toml │ └── src │ │ └── main.rs └── script.wac └── src ├── bin └── wac.rs ├── commands.rs ├── commands ├── compose.rs ├── parse.rs ├── plug.rs ├── resolve.rs └── targets.rs ├── lib.rs └── progress.rs /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | push: 4 | branches: 5 | - main 6 | tags: ['[0-9]*'] 7 | pull_request: 8 | branches: 9 | - main 10 | 11 | jobs: 12 | test: 13 | name: Run tests 14 | runs-on: ${{ matrix.os }} 15 | strategy: 16 | matrix: 17 | os: [ubuntu-latest, macos-latest, windows-latest] 18 | steps: 19 | - uses: actions/checkout@v3 20 | - name: Install Rust 21 | run: | 22 | rustup update stable --no-self-update 23 | rustup default stable 24 | shell: bash 25 | - name: Run all tests 26 | run: cargo test --all 27 | 28 | check: 29 | name: Check feature combinations 30 | runs-on: ${{ matrix.os }} 31 | strategy: 32 | matrix: 33 | os: [ubuntu-latest, macos-latest, windows-latest] 34 | steps: 35 | - uses: actions/checkout@v3 36 | - name: Install Rust 37 | run: | 38 | rustup update stable --no-self-update 39 | rustup default stable 40 | shell: bash 41 | - name: Build without default features 42 | run: cargo check --no-default-features 43 | - name: Build the `wat` feature 44 | run: cargo check --no-default-features --features wat 45 | - name: Build the `wit` feature 46 | run: cargo check --no-default-features --features wit 47 | - name: Build the `registry` feature 48 | run: cargo check --no-default-features --features registry 49 | - name: Build all features 50 | run: cargo check --all-features 51 | 52 | rustfmt: 53 | name: Format source code 54 | runs-on: ubuntu-latest 55 | steps: 56 | - uses: actions/checkout@v3 57 | - name: Install Rust 58 | run: rustup update stable && rustup default stable && rustup component add rustfmt 59 | - name: Run `cargo fmt` 60 | run: cargo fmt -- --check 61 | -------------------------------------------------------------------------------- /.github/workflows/publish-to-crates-io.yml: -------------------------------------------------------------------------------- 1 | # The purpose of this workflow is to publish the workspace's crates 2 | # whenever a tag is created. This basically boils down to running 3 | # `scripts/publish.rs` at the right time. 4 | 5 | name: "Publish to crates.io" 6 | 7 | on: 8 | push: 9 | tags: 10 | - 'v*' 11 | 12 | jobs: 13 | publish: 14 | if: github.repository == 'bytecodealliance/wac' 15 | runs-on: ubuntu-latest 16 | steps: 17 | - uses: actions/checkout@v3 18 | - run: rustup update stable && rustup default stable 19 | - run: | 20 | rustc ci/publish.rs 21 | ./publish publish 22 | env: 23 | CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | debug/ 2 | target/ 3 | Cargo.lock 4 | **/*.rs.bk 5 | *.pdb 6 | publish 7 | *.swp 8 | -------------------------------------------------------------------------------- /Cross.toml: -------------------------------------------------------------------------------- 1 | [target.aarch64-unknown-linux-gnu] 2 | pre-build = [ 3 | "dpkg --add-architecture $CROSS_DEB_ARCH", 4 | "apt-get update && apt-get --assume-yes install libssl-dev:$CROSS_DEB_ARCH", 5 | ] 6 | env.passthrough = [ 7 | "OPENSSL_LIB_DIR=/usr/lib/aarch64-linux-gnu", 8 | "OPENSSL_INCLUDE_DIR=/usr/include/aarch64-linux-gnu/openssl", 9 | "OPENSSL_STATIC=yes" 10 | ] 11 | image = "ghcr.io/cross-rs/aarch64-unknown-linux-gnu:edge" 12 | -------------------------------------------------------------------------------- /crates/wac-graph/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "wac-graph" 3 | description = "A library for defining, encoding, and decoding WebAssembly composition graphs." 4 | version = { workspace = true } 5 | edition = { workspace = true } 6 | authors = { workspace = true } 7 | license = { workspace = true } 8 | categories = { workspace = true } 9 | keywords = { workspace = true } 10 | repository = { workspace = true } 11 | 12 | [dependencies] 13 | wac-types = { workspace = true } 14 | id-arena = { workspace = true } 15 | anyhow = { workspace = true } 16 | thiserror = { workspace = true } 17 | petgraph = { workspace = true } 18 | indexmap = { workspace = true } 19 | wasmparser = { workspace = true } 20 | semver = { workspace = true } 21 | serde = { workspace = true, optional = true } 22 | wasm-encoder = { workspace = true } 23 | log = { workspace = true } 24 | wasm-metadata = { workspace = true } 25 | 26 | [dev-dependencies] 27 | pretty_assertions = { workspace = true } 28 | wasmprinter = { workspace = true } 29 | wat = { workspace = true } 30 | serde = { workspace = true } 31 | serde_json = { workspace = true } 32 | wit-component = { workspace = true, features = ["dummy-module"] } 33 | wit-parser = { workspace = true } 34 | 35 | [features] 36 | serde = ["dep:serde", "wac-types/serde"] 37 | -------------------------------------------------------------------------------- /crates/wac-graph/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! A library for defining, encoding, and decoding WebAssembly composition graphs. 2 | //! 3 | //! An example of composing two components together using a `CompositionGraph`: 4 | //! 5 | //! ```rust,no_run 6 | //! use wac_graph::{CompositionGraph, EncodeOptions, types::Package}; 7 | //! 8 | //! # fn main() -> anyhow::Result<()> { 9 | //! let mut graph = CompositionGraph::new(); 10 | //! 11 | //! // Register the packages with the graph 12 | //! // It is assumed that `my:package1` exports a function named `a`, 13 | //! // while `my:package2` imports a function named `b`. 14 | //! let pkg = Package::from_file("my:package1", None, "package1.wasm", graph.types_mut())?; 15 | //! let package1 = graph.register_package(pkg)?; 16 | //! let pkg = Package::from_file("my:package2", None, "package2.wasm", graph.types_mut())?; 17 | //! let package2 = graph.register_package(pkg)?; 18 | //! 19 | //! // Instantiate package `my:package1` 20 | //! let instantiation1 = graph.instantiate(package1); 21 | //! 22 | //! // Alias the `a` export of the `my:package1` instance 23 | //! let a = graph.alias_instance_export(instantiation1, "a")?; 24 | //! 25 | //! // Instantiate package `my:package2` 26 | //! let instantiation2 = graph.instantiate(package2); 27 | //! 28 | //! // Set argument `b` of the instantiation of `my:package2` to `a` 29 | //! graph.set_instantiation_argument(instantiation2, "b", a)?; 30 | //! 31 | //! // Finally, encode the graph into a new component 32 | //! let bytes = graph.encode(EncodeOptions::default())?; 33 | //! 34 | //! # Ok(()) 35 | //! # } 36 | //! ```` 37 | 38 | #![deny(missing_docs)] 39 | 40 | pub(crate) mod encoding; 41 | mod graph; 42 | mod plug; 43 | 44 | pub use graph::*; 45 | pub use plug::*; 46 | pub use wac_types as types; 47 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/argument-already-satisfied/error.txt: -------------------------------------------------------------------------------- 1 | failed to add argument edge from source node 1 to target node 2 referenced in argument 1 for test case `argument-already-satisfied` 2 | 3 | Caused by: 4 | argument `a` has already been passed to the instantiation 5 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/argument-already-satisfied/foo.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (import "a" (func)) 3 | (type (export "bar") (func)) 4 | ) 5 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/argument-already-satisfied/graph.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": [ 3 | { 4 | "name": "test:foo", 5 | "path": "foo.wat" 6 | } 7 | ], 8 | "nodes": [ 9 | { 10 | "type": "import", 11 | "name": "foo", 12 | "package": 0, 13 | "export": "bar" 14 | }, 15 | { 16 | "type": "import", 17 | "name": "bar", 18 | "package": 0, 19 | "export": "bar" 20 | }, 21 | { 22 | "type": "instantiation", 23 | "package": 0 24 | } 25 | ], 26 | "arguments": [ 27 | { 28 | "source": 0, 29 | "target": 2, 30 | "name": "a" 31 | }, 32 | { 33 | "source": 1, 34 | "target": 2, 35 | "name": "a" 36 | } 37 | ] 38 | } -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/argument-type-mismatch/error.txt: -------------------------------------------------------------------------------- 1 | failed to add argument edge from source node 0 to target node 1 referenced in argument 0 for test case `argument-type-mismatch` 2 | 3 | Caused by: 4 | 0: mismatched instantiation argument `a` 5 | 1: expected instance, found function 6 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/argument-type-mismatch/foo.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (import "a" (instance)) 3 | (type (export "bar") (func)) 4 | ) 5 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/argument-type-mismatch/graph.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": [ 3 | { 4 | "name": "test:foo", 5 | "path": "foo.wat" 6 | } 7 | ], 8 | "nodes": [ 9 | { 10 | "type": "import", 11 | "name": "foo", 12 | "package": 0, 13 | "export": "bar" 14 | }, 15 | { 16 | "type": "instantiation", 17 | "package": 0 18 | } 19 | ], 20 | "arguments": [ 21 | { 22 | "source": 0, 23 | "target": 1, 24 | "name": "a" 25 | } 26 | ] 27 | } -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/contains-cycle/error.txt: -------------------------------------------------------------------------------- 1 | failed to encode the graph 2 | 3 | Caused by: 4 | the graph contains a cycle and cannot be encoded 5 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/contains-cycle/foo.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (import "i" (instance)) 3 | ) 4 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/contains-cycle/graph.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": [ 3 | { 4 | "name": "test:foo", 5 | "path": "foo.wat" 6 | } 7 | ], 8 | "nodes": [ 9 | { 10 | "type": "instantiation", 11 | "package": 0 12 | }, 13 | { 14 | "type": "instantiation", 15 | "package": 0 16 | } 17 | ], 18 | "arguments": [ 19 | { 20 | "source": 0, 21 | "target": 1, 22 | "name": "i" 23 | }, 24 | { 25 | "source": 1, 26 | "target": 0, 27 | "name": "i" 28 | } 29 | ] 30 | } -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/duplicate-imports/foo.wit/deps/shared/shared.wit: -------------------------------------------------------------------------------- 1 | package test:shared; 2 | 3 | interface types { 4 | resource x; 5 | } 6 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/duplicate-imports/foo.wit/package.wit: -------------------------------------------------------------------------------- 1 | package test:foo; 2 | 3 | interface i { 4 | use test:shared/types.{x}; 5 | f: func() -> x; 6 | } 7 | 8 | world w { 9 | import i; 10 | export i; 11 | } 12 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/duplicate-imports/graph.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": [ 3 | { 4 | "name": "test:foo", 5 | "path": "foo.wit" 6 | } 7 | ], 8 | "nodes": [ 9 | { 10 | "type": "instantiation", 11 | "package": 0 12 | }, 13 | { 14 | "type": "instantiation", 15 | "package": 0 16 | }, 17 | { 18 | "type": "alias", 19 | "source": 0, 20 | "export": "test:foo/i" 21 | } 22 | ], 23 | "arguments": [ 24 | { 25 | "source": 2, 26 | "target": 1, 27 | "name": "test:foo/i" 28 | } 29 | ] 30 | } -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/export-already-exists/error.txt: -------------------------------------------------------------------------------- 1 | failed to export node 0 in export 1 for test case `export-already-exists` 2 | 3 | Caused by: 4 | an export with the name `foo` already exists 5 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/export-already-exists/foo.wat: -------------------------------------------------------------------------------- 1 | (component) 2 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/export-already-exists/graph.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": [ 3 | { 4 | "name": "test:foo", 5 | "path": "foo.wat" 6 | } 7 | ], 8 | "nodes": [ 9 | { 10 | "type": "instantiation", 11 | "package": 0 12 | } 13 | ], 14 | "exports": [ 15 | { 16 | "node": 0, 17 | "name": "foo" 18 | }, 19 | { 20 | "node": 0, 21 | "name": "foo" 22 | } 23 | ] 24 | } -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/export-missing/error.txt: -------------------------------------------------------------------------------- 1 | failed to add alias node 1 for test case `export-missing` 2 | 3 | Caused by: 4 | instance does not have an export named `foo` 5 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/export-missing/foo.wat: -------------------------------------------------------------------------------- 1 | (component) 2 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/export-missing/graph.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": [ 3 | { 4 | "name": "test:foo", 5 | "path": "foo.wat" 6 | } 7 | ], 8 | "nodes": [ 9 | { 10 | "type": "instantiation", 11 | "package": 0 12 | }, 13 | { 14 | "type": "alias", 15 | "source": 0, 16 | "export": "foo" 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/implicit-import-conflict/error.txt: -------------------------------------------------------------------------------- 1 | failed to encode the graph 2 | 3 | Caused by: 4 | an instantiation of package `test:foo` implicitly imports an item named `foo`, but it conflicts with an explicit import of the same name 5 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/implicit-import-conflict/foo.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (import "foo" (func)) 3 | (type (export "bar") (func)) 4 | ) 5 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/implicit-import-conflict/graph.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": [ 3 | { 4 | "name": "test:foo", 5 | "path": "foo.wat" 6 | } 7 | ], 8 | "nodes": [ 9 | { 10 | "type": "import", 11 | "name": "foo", 12 | "package": 0, 13 | "export": "bar" 14 | }, 15 | { 16 | "type": "instantiation", 17 | "package": 0 18 | } 19 | ] 20 | } -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/implicit-resource-import/bar/deps/types.wit: -------------------------------------------------------------------------------- 1 | package foo:dependency; 2 | 3 | interface types { 4 | resource x; 5 | } 6 | 7 | world w { 8 | export types; 9 | } -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/implicit-resource-import/bar/world.wit: -------------------------------------------------------------------------------- 1 | package foo:bar; 2 | 3 | world w { 4 | export foo:dependency/types; 5 | } 6 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/implicit-resource-import/baz/deps/types.wit: -------------------------------------------------------------------------------- 1 | package foo:dependency; 2 | 3 | interface types { 4 | resource x; 5 | } 6 | 7 | world w { 8 | export types; 9 | } -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/implicit-resource-import/baz/world.wit: -------------------------------------------------------------------------------- 1 | package foo:baz; 2 | 3 | world w { 4 | use foo:dependency/types.{x}; 5 | import my-func: func() -> x; 6 | // The test will fail whether this is here or not 7 | import foo:dependency/types; 8 | } 9 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/implicit-resource-import/encoded.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (type (;0;) 3 | (instance 4 | (export (;0;) "x" (type (sub resource))) 5 | ) 6 | ) 7 | (import "foo:dependency/types" (instance (;0;) (type 0))) 8 | (alias export 0 "x" (type (;1;))) 9 | (import "x" (type (;2;) (eq 1))) 10 | (alias export 0 "x" (type (;3;))) 11 | (type (;4;) 12 | (instance 13 | (alias outer 1 3 (type (;0;))) 14 | (export (;1;) "x" (type (eq 0))) 15 | (type (;2;) (own 1)) 16 | (type (;3;) (func (result 2))) 17 | (export (;0;) "my-func" (func (type 3))) 18 | ) 19 | ) 20 | (import "foo:test-import/my-interface" (instance (;1;) (type 4))) 21 | (type (;5;) 22 | (component 23 | (type (;0;) 24 | (instance 25 | (export (;0;) "x" (type (sub resource))) 26 | ) 27 | ) 28 | (export (;0;) "foo:dependency/types" (instance (type 0))) 29 | ) 30 | ) 31 | (import "unlocked-dep=" (component (;0;) (type 5))) 32 | (instance (;2;) (instantiate 0)) 33 | (alias export 1 "my-func" (func (;0;))) 34 | (alias export 2 "foo:dependency/types" (instance (;3;))) 35 | (type (;6;) 36 | (component 37 | (type (;0;) 38 | (instance 39 | (export (;0;) "x" (type (sub resource))) 40 | ) 41 | ) 42 | (import "foo:dependency/types" (instance (;0;) (type 0))) 43 | (alias outer 1 3 (type (;1;))) 44 | (import "x" (type (;2;) (eq 1))) 45 | (type (;3;) (own 2)) 46 | (type (;4;) (func (result 3))) 47 | (import "my-func" (func (;0;) (type 4))) 48 | ) 49 | ) 50 | (import "unlocked-dep=" (component (;1;) (type 6))) 51 | (instance (;4;) (instantiate 1 52 | (with "foo:dependency/types" (instance 3)) 53 | (with "my-func" (func 0)) 54 | (with "x" (type 2)) 55 | ) 56 | ) 57 | ) 58 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/implicit-resource-import/graph.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": [ 3 | { 4 | "name": "foo:import", 5 | "path": "import" 6 | }, 7 | { 8 | "name": "test:bar", 9 | "path": "bar" 10 | }, 11 | { 12 | "name": "test:baz", 13 | "path": "baz" 14 | } 15 | ], 16 | "nodes": [ 17 | { 18 | "type": "import", 19 | "name": "foo:test-import/my-interface", 20 | "package": 0, 21 | "export": "foo:test-import/my-interface" 22 | }, 23 | { 24 | "type": "instantiation", 25 | "package": 1 26 | }, 27 | { 28 | "type": "alias", 29 | "source": 0, 30 | "export": "my-func" 31 | }, 32 | { 33 | "type": "alias", 34 | "source": 1, 35 | "export": "foo:dependency/types" 36 | }, 37 | { 38 | "type": "instantiation", 39 | "package": 2 40 | } 41 | ], 42 | "arguments": [ 43 | { 44 | "source": 2, 45 | "target": 4, 46 | "name": "my-func" 47 | }, 48 | { 49 | "source": 3, 50 | "target": 4, 51 | "name": "foo:dependency/types" 52 | } 53 | ] 54 | } -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/implicit-resource-import/import/deps/types.wit: -------------------------------------------------------------------------------- 1 | package foo:dependency; 2 | 3 | interface types { 4 | resource x; 5 | } 6 | 7 | world w { 8 | export types; 9 | } -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/implicit-resource-import/import/world.wit: -------------------------------------------------------------------------------- 1 | package foo:test-import; 2 | 3 | world w { 4 | export my-interface; 5 | } 6 | 7 | interface my-interface{ 8 | use foo:dependency/types.{x}; 9 | my-func: func() -> x; 10 | } -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/import-already-exists/error.txt: -------------------------------------------------------------------------------- 1 | failed to add import node 1 for test case `import-already-exists` 2 | 3 | Caused by: 4 | import name `foo` already exists in the graph 5 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/import-already-exists/foo.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (type (export "bar") (func)) 3 | ) 4 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/import-already-exists/graph.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": [ 3 | { 4 | "name": "test:foo", 5 | "path": "foo.wat" 6 | } 7 | ], 8 | "nodes": [ 9 | { 10 | "type": "import", 11 | "name": "foo", 12 | "package": 0, 13 | "export": "bar" 14 | }, 15 | { 16 | "type": "import", 17 | "name": "foo", 18 | "package": 0, 19 | "export": "bar" 20 | } 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/import-resource-alias/encoded.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (import "x" (type (;0;) (sub resource))) 3 | (import "y" (type (;1;) (eq 0))) 4 | (type (;2;) (own 0)) 5 | (type (;3;) (own 1)) 6 | (type (;4;) (func (param "x" 2) (result 3))) 7 | (import "f" (func (;0;) (type 4))) 8 | (type (;5;) 9 | (component 10 | (import "x" (type (;0;) (sub resource))) 11 | (import "y" (type (;1;) (eq 0))) 12 | (type (;2;) (own 0)) 13 | (type (;3;) (own 1)) 14 | (type (;4;) (func (param "x" 2) (result 3))) 15 | (import "f" (func (;0;) (type 4))) 16 | ) 17 | ) 18 | (import "unlocked-dep=" (component (;0;) (type 5))) 19 | (instance (;0;) (instantiate 0 20 | (with "x" (type 0)) 21 | (with "y" (type 1)) 22 | (with "f" (func 0)) 23 | ) 24 | ) 25 | ) 26 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/import-resource-alias/graph.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": [ 3 | { 4 | "name": "test:foo", 5 | "path": "world.wit" 6 | } 7 | ], 8 | "nodes": [ 9 | { 10 | "type": "instantiation", 11 | "package": 0 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/import-resource-alias/world.wit: -------------------------------------------------------------------------------- 1 | package example:foo; 2 | 3 | world w { 4 | resource x; 5 | type y = x; 6 | import f: func(x: x) -> y; 7 | } -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/invalid-export-name/error.txt: -------------------------------------------------------------------------------- 1 | failed to export node 0 in export 0 for test case `invalid-export-name` 2 | 3 | Caused by: 4 | 0: export name `!` is not valid 5 | 1: `!` is not in kebab case 6 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/invalid-export-name/foo.wat: -------------------------------------------------------------------------------- 1 | (component) 2 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/invalid-export-name/graph.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": [ 3 | { 4 | "name": "test:foo", 5 | "path": "foo.wat" 6 | } 7 | ], 8 | "nodes": [ 9 | { 10 | "type": "instantiation", 11 | "package": 0 12 | } 13 | ], 14 | "exports": [ 15 | { 16 | "node": 0, 17 | "name": "!" 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/invalid-import-name/error.txt: -------------------------------------------------------------------------------- 1 | failed to add import node 0 for test case `invalid-import-name` 2 | 3 | Caused by: 4 | 0: import name `NOT_VALID` is not valid 5 | 1: `NOT_VALID` is not in kebab case 6 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/invalid-import-name/foo.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (type (export "bar") (func)) 3 | ) 4 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/invalid-import-name/graph.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": [ 3 | { 4 | "name": "test:foo", 5 | "path": "foo.wat" 6 | } 7 | ], 8 | "nodes": [ 9 | { 10 | "type": "import", 11 | "name": "NOT_VALID", 12 | "package": 0, 13 | "export": "bar" 14 | } 15 | ] 16 | } -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/merged-func-results/component1.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (type (;0;) 3 | (instance 4 | (type (;0;) (record (field "foo" u8))) 5 | (export (;1;) "foo" (type (eq 0))) 6 | (type (;2;) (func (result 1))) 7 | (export (;0;) "my-func1" (func (type 2))) 8 | ) 9 | ) 10 | (import "example:example/my-interface" (instance (;0;) (type 0))) 11 | (core module (;0;) 12 | (type (;0;) (func (result i32))) 13 | (type (;1;) (func (param i32 i32 i32 i32) (result i32))) 14 | (import "example:example/my-interface" "my-func1" (func (;0;) (type 0))) 15 | (func (;1;) (type 1) (param i32 i32 i32 i32) (result i32) 16 | unreachable 17 | ) 18 | (memory (;0;) 0) 19 | (export "memory" (memory 0)) 20 | (export "cabi_realloc" (func 1)) 21 | ) 22 | (alias export 0 "my-func1" (func (;0;))) 23 | (core func (;0;) (canon lower (func 0))) 24 | (core instance (;0;) 25 | (export "my-func1" (func 0)) 26 | ) 27 | (core instance (;1;) (instantiate 0 28 | (with "example:example/my-interface" (instance 0)) 29 | ) 30 | ) 31 | ) 32 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/merged-func-results/description.txt: -------------------------------------------------------------------------------- 1 | During aggregation when merging the "source" interface into the aggregated "target" interface, 2 | we check whether for any given export from the source interface, if there is an export in the 3 | target types collection with the same name that is a subtype of that export (see here). If no, 4 | we can simply skip merging that export because it's equivalent already exists in the target collection. 5 | This should even work when there is a source function export that does not exist in the target 6 | collection but makes use of a type (either in params or results) that is already present in the 7 | target collection (i.e., its param/results are types that have equivalents in the target collection). -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/merged-func-results/graph.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": [ 3 | { 4 | "name": "example:component1", 5 | "path": "component1.wat" 6 | }, 7 | { 8 | "name": "example:component2", 9 | "path": "component2.wat" 10 | } 11 | ], 12 | "nodes": [ 13 | { 14 | "type": "instantiation", 15 | "package": 0 16 | }, 17 | { 18 | "type": "instantiation", 19 | "package": 1 20 | }, 21 | { 22 | "type": "alias", 23 | "source": 1, 24 | "export": "example:example/my-interface" 25 | } 26 | ], 27 | "exports": [ 28 | { 29 | "node": 2, 30 | "name": "example:example/my-interface" 31 | } 32 | ] 33 | } -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/merged-usings/component.wit: -------------------------------------------------------------------------------- 1 | package foo:bar; 2 | 3 | interface baz { 4 | resource x; 5 | } 6 | 7 | interface qux { 8 | use baz.{x}; 9 | f: func() -> x; 10 | } 11 | 12 | world w { 13 | import qux; 14 | export qux; 15 | } 16 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/merged-usings/graph.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": [ 3 | { 4 | "name": "test:foo", 5 | "path": "component.wit" 6 | }, 7 | { 8 | "name": "test:bar", 9 | "path": "component.wit" 10 | } 11 | ], 12 | "nodes": [ 13 | { 14 | "type": "instantiation", 15 | "package": 0 16 | }, 17 | { 18 | "type": "instantiation", 19 | "package": 1 20 | }, 21 | { 22 | "type": "alias", 23 | "source": 1, 24 | "export": "foo:bar/qux" 25 | }, 26 | { 27 | "type": "alias", 28 | "source": 0, 29 | "export": "foo:bar/qux" 30 | } 31 | ], 32 | "arguments": [ 33 | { 34 | "source": 2, 35 | "target": 0, 36 | "name": "foo:bar/qux" 37 | } 38 | ], 39 | "exports": [ 40 | { 41 | "node": 3, 42 | "name": "foo:bar/qux" 43 | } 44 | ], 45 | "names": [ 46 | { 47 | "node": 0, 48 | "name": "component1" 49 | }, 50 | { 51 | "node": 1, 52 | "name": "component2" 53 | }, 54 | { 55 | "node": 2, 56 | "name": "alias" 57 | }, 58 | { 59 | "node": 3, 60 | "name": "export" 61 | } 62 | ] 63 | } 64 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/merging-import-dependencies/component/deps/types.wit: -------------------------------------------------------------------------------- 1 | package foo:dependency; 2 | 3 | interface types { 4 | record my-record { 5 | foo: string 6 | } 7 | } 8 | 9 | world w { 10 | export types; 11 | } -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/merging-import-dependencies/component/world.wit: -------------------------------------------------------------------------------- 1 | package foo:component; 2 | 3 | world w { 4 | export my-interface; 5 | } 6 | 7 | interface my-interface{ 8 | use foo:dependency/types.{my-record}; 9 | my-func: func() -> my-record; 10 | } -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/merging-import-dependencies/encoded.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (type (;0;) 3 | (instance 4 | (type (;0;) (record (field "foo" string))) 5 | (export (;1;) "my-record" (type (eq 0))) 6 | (type (;2;) (variant (case "x"))) 7 | (export (;3;) "my-variant" (type (eq 2))) 8 | ) 9 | ) 10 | (import "foo:dependency/types" (instance (;0;) (type 0))) 11 | (alias export 0 "my-variant" (type (;1;))) 12 | (type (;2;) 13 | (instance 14 | (alias outer 1 1 (type (;0;))) 15 | (export (;1;) "my-variant" (type (eq 0))) 16 | (type (;2;) (func (result 1))) 17 | (export (;0;) "my-func" (func (type 2))) 18 | ) 19 | ) 20 | (import "foo:test-import/my-interface" (instance (;1;) (type 2))) 21 | (type (;3;) 22 | (component 23 | (type (;0;) 24 | (instance 25 | (type (;0;) (record (field "foo" string))) 26 | (export (;1;) "my-record" (type (eq 0))) 27 | ) 28 | ) 29 | (import "foo:dependency/types" (instance (;0;) (type 0))) 30 | (alias export 0 "my-record" (type (;1;))) 31 | (type (;2;) 32 | (instance 33 | (alias outer 1 1 (type (;0;))) 34 | (export (;1;) "my-record" (type (eq 0))) 35 | (type (;2;) (func (result 1))) 36 | (export (;0;) "my-func" (func (type 2))) 37 | ) 38 | ) 39 | (export (;1;) "foo:component/my-interface" (instance (type 2))) 40 | ) 41 | ) 42 | (import "unlocked-dep=" (component (;0;) (type 3))) 43 | (instance (;2;) (instantiate 0 44 | (with "foo:dependency/types" (instance 0)) 45 | ) 46 | ) 47 | ) 48 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/merging-import-dependencies/graph.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": [ 3 | { 4 | "name": "foo:import", 5 | "path": "import" 6 | }, 7 | { 8 | "name": "test:component", 9 | "path": "component" 10 | } 11 | ], 12 | "nodes": [ 13 | { 14 | "type": "import", 15 | "name": "foo:test-import/my-interface", 16 | "package": 0, 17 | "export": "foo:test-import/my-interface" 18 | }, 19 | { 20 | "type": "instantiation", 21 | "package": 1 22 | } 23 | ], 24 | "arguments": [] 25 | } -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/merging-import-dependencies/import/deps/types.wit: -------------------------------------------------------------------------------- 1 | package foo:dependency; 2 | 3 | interface types { 4 | variant my-variant { 5 | x 6 | } 7 | } 8 | 9 | world w { 10 | export types; 11 | } -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/merging-import-dependencies/import/world.wit: -------------------------------------------------------------------------------- 1 | package foo:test-import; 2 | 3 | world w { 4 | export my-interface; 5 | } 6 | 7 | interface my-interface{ 8 | use foo:dependency/types.{my-variant}; 9 | my-func: func() -> my-variant; 10 | } -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/missing-argument/error.txt: -------------------------------------------------------------------------------- 1 | failed to add argument edge from source node 0 to target node 1 referenced in argument 0 for test case `missing-argument` 2 | 3 | Caused by: 4 | argument name `foo` is not an import of package `test:foo` 5 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/missing-argument/foo.wat: -------------------------------------------------------------------------------- 1 | (component) 2 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/missing-argument/graph.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": [ 3 | { 4 | "name": "test:foo", 5 | "path": "foo.wat" 6 | } 7 | ], 8 | "nodes": [ 9 | { 10 | "type": "instantiation", 11 | "package": 0 12 | }, 13 | { 14 | "type": "instantiation", 15 | "package": 0 16 | } 17 | ], 18 | "arguments": [ 19 | { 20 | "source": 0, 21 | "target": 1, 22 | "name": "foo" 23 | } 24 | ] 25 | } -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/not-an-instance/error.txt: -------------------------------------------------------------------------------- 1 | failed to add alias node 1 for test case `not-an-instance` 2 | 3 | Caused by: 4 | expected source node to be an instance, but the node is a function 5 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/not-an-instance/foo.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (type (export "bar") (func)) 3 | ) 4 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/not-an-instance/graph.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": [ 3 | { 4 | "name": "test:foo", 5 | "path": "foo.wat" 6 | } 7 | ], 8 | "nodes": [ 9 | { 10 | "type": "import", 11 | "name": "foo", 12 | "package": 0, 13 | "export": "bar" 14 | }, 15 | { 16 | "type": "alias", 17 | "source": 0, 18 | "export": "nope" 19 | } 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/not-instantiation/error.txt: -------------------------------------------------------------------------------- 1 | failed to add argument edge from source node 0 to target node 1 referenced in argument 0 for test case `not-instantiation` 2 | 3 | Caused by: 4 | the specified node is not an instantiation 5 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/not-instantiation/foo.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (type (export "bar") (func)) 3 | ) 4 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/not-instantiation/graph.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": [ 3 | { 4 | "name": "test:foo", 5 | "path": "foo.wat" 6 | } 7 | ], 8 | "nodes": [ 9 | { 10 | "type": "import", 11 | "name": "foo", 12 | "package": 0, 13 | "export": "bar" 14 | }, 15 | { 16 | "type": "import", 17 | "name": "bar", 18 | "package": 0, 19 | "export": "bar" 20 | } 21 | ], 22 | "arguments": [ 23 | { 24 | "source": 0, 25 | "target": 1, 26 | "name": "nope" 27 | } 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/package-already-registered/error.txt: -------------------------------------------------------------------------------- 1 | failed to register package `tests/graphs/package-already-registered/foo.wat` for test case `package-already-registered` 2 | 3 | Caused by: 4 | package `test:foo` has already been registered in the graph 5 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/package-already-registered/foo.wat: -------------------------------------------------------------------------------- 1 | (component) 2 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/package-already-registered/graph.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": [ 3 | { 4 | "name": "test:foo", 5 | "path": "foo.wat" 6 | }, 7 | { 8 | "name": "test:foo", 9 | "path": "foo.wat" 10 | } 11 | ] 12 | } -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/simple/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (import "e" (func)) 3 | (import "i2" (instance)) 4 | (import "merged" (instance 5 | (export "a" (func)) 6 | )) 7 | (export "e" (func 0)) 8 | ) 9 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/simple/foo.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (type (export "f") (func)) 3 | (import "foo" (func)) 4 | (import "i1" (instance)) 5 | (import "merged" (instance 6 | (export "a" (func)) 7 | (export "b" (func)) 8 | )) 9 | (export "bar" (func 0)) 10 | ) 11 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/simple/graph.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": [ 3 | { 4 | "name": "test:foo", 5 | "path": "foo.wat" 6 | }, 7 | { 8 | "name": "test:bar", 9 | "path": "bar.wat" 10 | } 11 | ], 12 | "nodes": [ 13 | { 14 | "type": "import", 15 | "name": "my-foo", 16 | "package": 0, 17 | "export": "f" 18 | }, 19 | { 20 | "type": "instantiation", 21 | "package": 0 22 | }, 23 | { 24 | "type": "alias", 25 | "source": 1, 26 | "export": "bar" 27 | }, 28 | { 29 | "type": "instantiation", 30 | "package": 1 31 | }, 32 | { 33 | "type": "alias", 34 | "source": 3, 35 | "export": "e" 36 | } 37 | ], 38 | "arguments": [ 39 | { 40 | "source": 0, 41 | "target": 1, 42 | "name": "foo" 43 | }, 44 | { 45 | "source": 2, 46 | "target": 3, 47 | "name": "e" 48 | } 49 | ], 50 | "exports": [ 51 | { 52 | "node": 4, 53 | "name": "e2" 54 | } 55 | ], 56 | "names": [ 57 | { 58 | "node": 0, 59 | "name": "my-foo" 60 | }, 61 | { 62 | "node": 1, 63 | "name": "foo" 64 | }, 65 | { 66 | "node": 2, 67 | "name": "e" 68 | }, 69 | { 70 | "node": 3, 71 | "name": "bar" 72 | }, 73 | { 74 | "node": 4, 75 | "name": "e2" 76 | } 77 | ] 78 | } 79 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/type-aggregation-error/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (import "foo" (instance 3 | (export "baz" (func)) 4 | )) 5 | ) 6 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/type-aggregation-error/error.txt: -------------------------------------------------------------------------------- 1 | failed to encode the graph 2 | 3 | Caused by: 4 | 0: failed to merge the type definition for implicit import `foo` due to conflicting types 5 | 1: mismatched type for export `baz` 6 | 2: expected function, found instance 7 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/type-aggregation-error/foo.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (import "foo" (instance 3 | (export "baz" (instance)) 4 | )) 5 | ) 6 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/type-aggregation-error/graph.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": [ 3 | { 4 | "name": "test:foo", 5 | "path": "foo.wat" 6 | }, 7 | { 8 | "name": "test:bar", 9 | "path": "bar.wat" 10 | } 11 | ], 12 | "nodes": [ 13 | { 14 | "type": "instantiation", 15 | "package": 0 16 | }, 17 | { 18 | "type": "instantiation", 19 | "package": 1 20 | } 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/used-resource/encoded.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (type (;0;) 3 | (instance 4 | (export (;0;) "my-resource" (type (sub resource))) 5 | ) 6 | ) 7 | (import "test:foo/my-interface" (instance (;0;) (type 0))) 8 | (alias export 0 "my-resource" (type (;1;))) 9 | (import "my-resource" (type (;2;) (eq 1))) 10 | (import "my-resource2" (type (;3;) (eq 2))) 11 | (type (;4;) 12 | (component 13 | (type (;0;) 14 | (instance 15 | (export (;0;) "my-resource" (type (sub resource))) 16 | ) 17 | ) 18 | (import "test:foo/my-interface" (instance (;0;) (type 0))) 19 | (alias export 0 "my-resource" (type (;1;))) 20 | (import "my-resource" (type (;2;) (eq 1))) 21 | (import "my-resource2" (type (;3;) (eq 2))) 22 | (type (;4;) (own 3)) 23 | (type (;5;) (func (param "r" 4))) 24 | (export (;0;) "my-func" (func (type 5))) 25 | ) 26 | ) 27 | (import "unlocked-dep=" (component (;0;) (type 4))) 28 | (instance (;1;) (instantiate 0 29 | (with "test:foo/my-interface" (instance 0)) 30 | (with "my-resource" (type 2)) 31 | (with "my-resource2" (type 3)) 32 | ) 33 | ) 34 | (alias export 1 "my-func" (func (;0;))) 35 | (export (;1;) "my-func" (func 0)) 36 | ) 37 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/used-resource/foo.wit: -------------------------------------------------------------------------------- 1 | package test:foo; 2 | 3 | world my-world { 4 | use my-interface.{my-resource}; 5 | type my-resource2 = my-resource; 6 | 7 | export my-func: func(r: my-resource2); 8 | } 9 | 10 | interface my-interface { 11 | resource my-resource {} 12 | } 13 | -------------------------------------------------------------------------------- /crates/wac-graph/tests/graphs/used-resource/graph.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": [ 3 | { 4 | "name": "test:foo", 5 | "path": "foo.wit" 6 | } 7 | ], 8 | "nodes": [ 9 | { 10 | "type": "instantiation", 11 | "package": 0 12 | }, 13 | { 14 | "type": "alias", 15 | "source": 0, 16 | "export": "my-func" 17 | } 18 | ], 19 | "exports": [ 20 | { 21 | "node": 1, 22 | "name": "my-func" 23 | } 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /crates/wac-parser/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "wac-parser" 3 | description = "A library for parsing and encoding WebAssembly Composition (WAC) source files." 4 | version = { workspace = true } 5 | edition = { workspace = true } 6 | authors = { workspace = true } 7 | license = { workspace = true } 8 | categories = { workspace = true } 9 | keywords = { workspace = true } 10 | repository = { workspace = true } 11 | 12 | [dependencies] 13 | wac-graph = { workspace = true } 14 | anyhow = { workspace = true } 15 | logos = { workspace = true } 16 | thiserror = { workspace = true } 17 | semver = { workspace = true } 18 | log = { workspace = true } 19 | indexmap = { workspace = true } 20 | id-arena = { workspace = true } 21 | serde = { workspace = true } 22 | wasmparser = { workspace = true } 23 | wasm-encoder = { workspace = true } 24 | wasm-metadata = { workspace = true } 25 | miette = { workspace = true, features = ["serde"]} 26 | 27 | [dev-dependencies] 28 | wac-resolver = { workspace = true, default-features = false, features = ["wat", "wit"] } 29 | owo-colors = "4.0.0" 30 | pretty_assertions = { workspace = true } 31 | pretty_env_logger = { workspace = true } 32 | rayon = "1.10.0" 33 | tokio = { workspace = true } 34 | serde_json = { workspace = true } 35 | wasmprinter = { workspace = true } 36 | miette = { workspace = true, features = ["fancy", "serde"]} 37 | 38 | [[test]] 39 | name = "parser" 40 | harness = false 41 | 42 | [[test]] 43 | name = "resolution" 44 | harness = false 45 | 46 | [[test]] 47 | name = "encoding" 48 | harness = false 49 | -------------------------------------------------------------------------------- /crates/wac-parser/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! A library for encoding and decoding WebAssembly compositions. 2 | 3 | #![deny(missing_docs)] 4 | 5 | mod ast; 6 | pub mod lexer; 7 | pub mod resolution; 8 | 9 | pub use ast::*; 10 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/encoding/fail/arg-merge-failure.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | let a = new foo:bar { ... }; 4 | let b = new bar:baz { ... }; 5 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/encoding/fail/arg-merge-failure.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × failed to merge the type definition for implicit import `foo` due to conflicting types 4 | ╰─▶ instance cannot be merged with function 5 | ╭─[tests/encoding/fail/arg-merge-failure.wac:4:13] 6 | 2 │ 7 | 3 │ let a = new foo:bar { ... }; 8 | · ───┬─── 9 | · ╰── previous instantiation here 10 | 4 │ let b = new bar:baz { ... }; 11 | · ───┬─── 12 | · ╰── conflicting instantiation here 13 | ╰──── 14 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/encoding/fail/arg-merge-failure/bar/baz.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (import "foo" (func)) 3 | ) -------------------------------------------------------------------------------- /crates/wac-parser/tests/encoding/fail/arg-merge-failure/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (import "foo" (instance)) 3 | ) 4 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/encoding/fail/implicit-arg-conflict.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import foo: func(); 4 | 5 | let x = new foo:bar { ... }; 6 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/encoding/fail/implicit-arg-conflict.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × import `foo` conflicts with an item that was implicitly imported by an instantiation of `foo:bar` 4 | ╭─[tests/encoding/fail/implicit-arg-conflict.wac:3:8] 5 | 2 │ 6 | 3 │ import foo: func(); 7 | · ─┬─ 8 | · ╰── explicit import here 9 | 4 │ 10 | 5 │ let x = new foo:bar { ... }; 11 | · ───┬─── 12 | · ╰── conflicting instantiation here 13 | ╰──── 14 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/encoding/fail/implicit-arg-conflict/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (import "foo" (func)) 3 | ) 4 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/encoding/fail/import-conflict.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | let x = new foo:bar { ... }; 4 | 5 | import foo: func(); 6 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/encoding/fail/import-conflict.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × import `foo` conflicts with an item that was implicitly imported by an instantiation of `foo:bar` 4 | ╭─[tests/encoding/fail/import-conflict.wac:5:8] 5 | 2 │ 6 | 3 │ let x = new foo:bar { ... }; 7 | · ───┬─── 8 | · ╰── conflicting instantiation here 9 | 4 │ 10 | 5 │ import foo: func(); 11 | · ─┬─ 12 | · ╰── explicit import here 13 | ╰──── 14 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/encoding/fail/import-conflict/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (import "foo" (func)) 3 | ) -------------------------------------------------------------------------------- /crates/wac-parser/tests/encoding/fail/unmergeable-args.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | let a = new bar:baz { ... }; 4 | let b = new foo:bar { ... }; 5 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/encoding/fail/unmergeable-args.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × failed to merge the type definition for implicit import `foo` due to conflicting types 4 | ╰─▶ function cannot be merged with instance 5 | ╭─[tests/encoding/fail/unmergeable-args.wac:4:13] 6 | 2 │ 7 | 3 │ let a = new bar:baz { ... }; 8 | · ───┬─── 9 | · ╰── previous instantiation here 10 | 4 │ let b = new foo:bar { ... }; 11 | · ───┬─── 12 | · ╰── conflicting instantiation here 13 | ╰──── 14 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/encoding/fail/unmergeable-args/bar/baz.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (import "foo" (func)) 3 | ) -------------------------------------------------------------------------------- /crates/wac-parser/tests/encoding/fail/unmergeable-args/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (import "foo" (instance)) 3 | ) 4 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/encoding/include-resource.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | let x = new foo:bar { ... }; 4 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/encoding/include-resource.wac.result: -------------------------------------------------------------------------------- 1 | (component 2 | (type (;0;) 3 | (instance 4 | (export (;0;) "fields" (type (sub resource))) 5 | (export (;1;) "headers" (type (eq 0))) 6 | ) 7 | ) 8 | (import "test:comp/types" (instance (;0;) (type 0))) 9 | (alias export 0 "fields" (type (;1;))) 10 | (type (;2;) 11 | (instance 12 | (alias outer 1 1 (type (;0;))) 13 | (export (;1;) "headers" (type (eq 0))) 14 | (type (;2;) (own 1)) 15 | (type (;3;) (func (result 2))) 16 | (export (;0;) "get-headers" (func (type 3))) 17 | ) 18 | ) 19 | (import "test:comp/incoming-request" (instance (;1;) (type 2))) 20 | (type (;3;) 21 | (component 22 | (type (;0;) 23 | (instance 24 | (export (;0;) "fields" (type (sub resource))) 25 | (export (;1;) "headers" (type (eq 0))) 26 | ) 27 | ) 28 | (import "test:comp/types" (instance (;0;) (type 0))) 29 | (alias export 0 "fields" (type (;1;))) 30 | (type (;2;) 31 | (instance 32 | (alias outer 1 1 (type (;0;))) 33 | (export (;1;) "headers" (type (eq 0))) 34 | (type (;2;) (own 1)) 35 | (type (;3;) (func (result 2))) 36 | (export (;0;) "get-headers" (func (type 3))) 37 | ) 38 | ) 39 | (import "test:comp/incoming-request" (instance (;1;) (type 2))) 40 | ) 41 | ) 42 | (import "unlocked-dep=" (component (;0;) (type 3))) 43 | (instance $x (;2;) (instantiate 0 44 | (with "test:comp/types" (instance 0)) 45 | (with "test:comp/incoming-request" (instance 1)) 46 | ) 47 | ) 48 | (@producers 49 | (processed-by "wac-parser" "0.7.0-dev") 50 | ) 51 | ) 52 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/encoding/instantiation.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import i: interface { 4 | foo: func(); 5 | }; 6 | 7 | import i2: interface { 8 | baz: func(); 9 | }; 10 | 11 | import f: func(); 12 | 13 | let baz = f; 14 | let x1 = new foo:bar { ... }; 15 | let x2 = new foo:bar { baz: f }; 16 | let x3 = new foo:bar { baz }; 17 | let x4 = new foo:bar { ...i2, ... }; 18 | 19 | let y1 = new bar:baz { ... }; 20 | let y2 = new bar:baz { foo: i }; 21 | let y3 = new bar:baz { foo: x1 }; 22 | let y4 = new bar:baz { foo: x2 }; 23 | let y5 = new bar:baz { foo: x3 }; 24 | 25 | export x4...; 26 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/encoding/instantiation/bar/baz.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (import "foo" 3 | (instance 4 | (export "foo" (func)) 5 | ) 6 | ) 7 | ) -------------------------------------------------------------------------------- /crates/wac-parser/tests/encoding/instantiation/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (import "baz" (func)) 3 | (export "foo" (func 0)) 4 | ) -------------------------------------------------------------------------------- /crates/wac-parser/tests/encoding/merged-functions.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | let a = new foo:bar { 4 | ... 5 | }; 6 | 7 | let b = new foo:baz { 8 | ... 9 | }; 10 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/encoding/merged-functions.wac.result: -------------------------------------------------------------------------------- 1 | (component 2 | (type (;0;) 3 | (instance 4 | (type (;0;) (record (field "x" u32))) 5 | (export (;1;) "x" (type (eq 0))) 6 | (type (;2;) (func (param "x" 1))) 7 | (export (;0;) "y" (func (type 2))) 8 | (type (;3;) (func (param "x" 1))) 9 | (export (;1;) "z" (func (type 3))) 10 | ) 11 | ) 12 | (import "foo:bar/baz" (instance (;0;) (type 0))) 13 | (type (;1;) 14 | (component 15 | (type (;0;) 16 | (instance 17 | (type (;0;) (record (field "x" u32))) 18 | (export (;1;) "x" (type (eq 0))) 19 | (type (;2;) (func (param "x" 1))) 20 | (export (;0;) "y" (func (type 2))) 21 | ) 22 | ) 23 | (import "foo:bar/baz" (instance (;0;) (type 0))) 24 | ) 25 | ) 26 | (import "unlocked-dep=" (component (;0;) (type 1))) 27 | (instance $a (;1;) (instantiate 0 28 | (with "foo:bar/baz" (instance 0)) 29 | ) 30 | ) 31 | (type (;2;) 32 | (component 33 | (type (;0;) 34 | (instance 35 | (type (;0;) (record (field "x" u32))) 36 | (export (;1;) "x" (type (eq 0))) 37 | (type (;2;) (func (param "x" 1))) 38 | (export (;0;) "z" (func (type 2))) 39 | ) 40 | ) 41 | (import "foo:bar/baz" (instance (;0;) (type 0))) 42 | ) 43 | ) 44 | (import "unlocked-dep=" (component (;1;) (type 2))) 45 | (instance $b (;2;) (instantiate 1 46 | (with "foo:bar/baz" (instance 0)) 47 | ) 48 | ) 49 | (@producers 50 | (processed-by "wac-parser" "0.7.0-dev") 51 | ) 52 | ) 53 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/encoding/merged-functions/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (import "foo:bar/baz" (instance 3 | (type (record (field "x" u32))) 4 | (export "x" (type (eq 0))) 5 | (export "y" (func (param "x" 1))) 6 | )) 7 | ) 8 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/encoding/merged-functions/foo/baz.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (import "foo:bar/baz" (instance 3 | (type (record (field "x" u32))) 4 | (export "x" (type (eq 0))) 5 | (export "z" (func (param "x" 1))) 6 | )) 7 | ) 8 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/encoding/resources.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import foo: interface { 4 | resource r { 5 | constructor(); 6 | foo: func(); 7 | bar: static func(); 8 | } 9 | 10 | type r2 = r; 11 | 12 | bar: func(r: borrow, r2: borrow, r3: r, r4: r2) -> tuple; 13 | baz: func(); 14 | }; 15 | 16 | let x = new foo:bar { foo }; 17 | 18 | export x.foo; 19 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/encoding/resources/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (type (;0;) 3 | (instance 4 | (export (;0;) "r" (type (sub resource))) 5 | (type (;1;) (func)) 6 | (export (;0;) "[static]r.bar" (func (type 1))) 7 | (export (;2;) "r2" (type (eq 0))) 8 | (type (;3;) (borrow 0)) 9 | (type (;4;) (borrow 2)) 10 | (type (;5;) (own 0)) 11 | (type (;6;) (own 2)) 12 | (type (;7;) (tuple 5 6)) 13 | (type (;8;) (func (param "r" 3) (param "r2" 4) (param "r3" 5) (param "r4" 6) (result 7))) 14 | (export (;1;) "bar" (func (type 8))) 15 | ) 16 | ) 17 | (import "foo" (instance (;0;) (type 0))) 18 | (export "foo" (instance 0)) 19 | (@producers 20 | (processed-by "wac-parser" "0.7.0-dev") 21 | ) 22 | ) 23 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/parser/export.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | /// Export an item (default name) 4 | export e; 5 | 6 | /// Export an alias of an item (default name) 7 | export e["foo"]; 8 | 9 | /// Export an alias of an item with a different name with string 10 | export e["foo"] as "bar"; 11 | 12 | /// Export an alias of an item with a different name with identifier 13 | export e["foo"] as foo-bar; 14 | 15 | /// Export of an instance spread 16 | export i...; 17 | 18 | /// Export of an expression spread 19 | export new foo:bar { ... } ...; 20 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/parser/fail/bad-alias.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | type u32 = x; -------------------------------------------------------------------------------- /crates/wac-parser/tests/parser/fail/bad-alias.wac.result: -------------------------------------------------------------------------------- 1 | failed to parse document 2 | 3 | × expected identifier, found `u32` keyword 4 | ╭─[tests/parser/fail/bad-alias.wac:3:6] 5 | 2 │ 6 | 3 │ type u32 = x; 7 | · ─┬─ 8 | · ╰── unexpected `u32` keyword 9 | ╰──── 10 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/parser/fail/duplicate-package-decl.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | package test:comp; -------------------------------------------------------------------------------- /crates/wac-parser/tests/parser/fail/duplicate-package-decl.wac.result: -------------------------------------------------------------------------------- 1 | failed to parse document 2 | 3 | × expected either `import` keyword, `let` keyword, `export` keyword, `interface` keyword, `world` keyword, `variant` keyword, `record` keyword, `flags` keyword, `enum` keyword, or `type` keyword, 4 | │ found `package` keyword 5 | ╭─[tests/parser/fail/duplicate-package-decl.wac:2:1] 6 | 1 │ package test:comp; 7 | 2 │ package test:comp; 8 | · ───┬─── 9 | · ╰── unexpected `package` keyword 10 | ╰──── 11 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/parser/fail/empty-enum.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | enum e {} -------------------------------------------------------------------------------- /crates/wac-parser/tests/parser/fail/empty-enum.wac.result: -------------------------------------------------------------------------------- 1 | failed to parse document 2 | 3 | × enum must contain at least one case 4 | ╭─[tests/parser/fail/empty-enum.wac:3:9] 5 | 2 │ 6 | 3 │ enum e {} 7 | · ┬ 8 | · ╰── empty enum 9 | ╰──── 10 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/parser/fail/empty-flags.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | flags f {} -------------------------------------------------------------------------------- /crates/wac-parser/tests/parser/fail/empty-flags.wac.result: -------------------------------------------------------------------------------- 1 | failed to parse document 2 | 3 | × flags must contain at least one flag 4 | ╭─[tests/parser/fail/empty-flags.wac:3:10] 5 | 2 │ 6 | 3 │ flags f {} 7 | · ┬ 8 | · ╰── empty flags 9 | ╰──── 10 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/parser/fail/empty-record.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | record r {} -------------------------------------------------------------------------------- /crates/wac-parser/tests/parser/fail/empty-record.wac.result: -------------------------------------------------------------------------------- 1 | failed to parse document 2 | 3 | × record must contain at least one field 4 | ╭─[tests/parser/fail/empty-record.wac:3:11] 5 | 2 │ 6 | 3 │ record r {} 7 | · ┬ 8 | · ╰── empty record 9 | ╰──── 10 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/parser/fail/empty-variant.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | variant v {} -------------------------------------------------------------------------------- /crates/wac-parser/tests/parser/fail/empty-variant.wac.result: -------------------------------------------------------------------------------- 1 | failed to parse document 2 | 3 | × variant must contain at least one case 4 | ╭─[tests/parser/fail/empty-variant.wac:3:12] 5 | 2 │ 6 | 3 │ variant v {} 7 | · ┬ 8 | · ╰── empty variant 9 | ╰──── 10 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/parser/fail/expected-multiple.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | type x = -------------------------------------------------------------------------------- /crates/wac-parser/tests/parser/fail/expected-multiple.wac.result: -------------------------------------------------------------------------------- 1 | failed to parse document 2 | 3 | × expected either `func` keyword, `u8` keyword, `s8` keyword, `u16` keyword, `s16` keyword, `u32` keyword, `s32` keyword, `u64` keyword, `s64` keyword, `f32` keyword, or more..., found end of 4 | │ input 5 | ╭─[tests/parser/fail/expected-multiple.wac:3:8] 6 | 2 │ 7 | 3 │ type x = 8 | · ┬ 9 | · ╰── unexpected end of input 10 | ╰──── 11 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/parser/fail/expected-two.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | record foo { 4 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/parser/fail/expected-two.wac.result: -------------------------------------------------------------------------------- 1 | failed to parse document 2 | 3 | × expected `}` or identifier, found end of input 4 | ╭─[tests/parser/fail/expected-two.wac:3:12] 5 | 2 │ 6 | 3 │ record foo { 7 | · ┬ 8 | · ╰── unexpected end of input 9 | ╰──── 10 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/parser/fail/invalid-path-semver.wac: -------------------------------------------------------------------------------- 1 | package foo:bar; 2 | 3 | import i: foo:bar/baz@1; -------------------------------------------------------------------------------- /crates/wac-parser/tests/parser/fail/invalid-path-semver.wac.result: -------------------------------------------------------------------------------- 1 | failed to parse document 2 | 3 | × `1` is not a valid semantic version 4 | ╭─[tests/parser/fail/invalid-path-semver.wac:3:23] 5 | 2 │ 6 | 3 │ import i: foo:bar/baz@1; 7 | · ┬ 8 | · ╰── invalid version 9 | ╰──── 10 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/parser/fail/invalid-semver.wac: -------------------------------------------------------------------------------- 1 | package foo:bar@1; 2 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/parser/fail/invalid-semver.wac.result: -------------------------------------------------------------------------------- 1 | failed to parse document 2 | 3 | × `1` is not a valid semantic version 4 | ╭─[tests/parser/fail/invalid-semver.wac:1:17] 5 | 1 │ package foo:bar@1; 6 | · ┬ 7 | · ╰── invalid version 8 | ╰──── 9 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/parser/fail/missing-package-decl.wac: -------------------------------------------------------------------------------- 1 | import f: func(); 2 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/parser/fail/missing-package-decl.wac.result: -------------------------------------------------------------------------------- 1 | failed to parse document 2 | 3 | × expected `package` keyword, found `import` keyword 4 | ╭─[tests/parser/fail/missing-package-decl.wac:1:1] 5 | 1 │ import f: func(); 6 | · ───┬── 7 | · ╰── unexpected `import` keyword 8 | ╰──── 9 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/parser/fail/missing-semi.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | type x = u32 -------------------------------------------------------------------------------- /crates/wac-parser/tests/parser/fail/missing-semi.wac.result: -------------------------------------------------------------------------------- 1 | failed to parse document 2 | 3 | × expected `;`, found end of input 4 | ╭─[tests/parser/fail/missing-semi.wac:3:12] 5 | 2 │ 6 | 3 │ type x = u32 7 | · ┬ 8 | · ╰── unexpected end of input 9 | ╰──── 10 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/parser/import.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | /// Import by func type 4 | import a: func(); 5 | 6 | /// Import by ident 7 | import b: x; 8 | 9 | /// Import by package path 10 | import c: foo:bar/baz; 11 | 12 | /// Import by func type with kebab name string 13 | import d as "hello-world": func(name: string); 14 | 15 | /// Import by inline interface 16 | import e: interface { 17 | x: func(); 18 | }; 19 | 20 | /// Import by package path with version 21 | import f: foo:bar/baz@1.0.0; 22 | 23 | /// Import by func type with kebab name identifier 24 | import g as hello-world: func(name: string); 25 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/parser/let.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | /// Instantiate without args 4 | let a = new foo:bar {}; 5 | 6 | /// Instantiation with import-propagation. 7 | let b = new foo:bar@1.0.0 { ... }; 8 | 9 | /// Instantiation with arguments 10 | let c = new foo:bar@2.0.0 { a, b, "c": c, }; 11 | 12 | /// Instantiation with arguments and import-propagation. 13 | let d = new foo:bar@3.0.0 { a, "b": (new foo:bar { }), c: c, ... }; 14 | 15 | /// Nested expression 16 | let e = (b); 17 | 18 | /// Access expression 19 | let f = e["b-c"].c.d["foo:bar/baz"].e; 20 | 21 | /// Mix of instantiation arguments 22 | let h = new f:bar { inferred, ...a, b: c, ...d, ... }; 23 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/parser/resource.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | interface foo { 4 | /// Resource without methods 5 | resource r1; 6 | 7 | /// Resource with only constructor 8 | resource r2 { 9 | /// Constructor 10 | constructor(); 11 | } 12 | 13 | /// Resource with constructor, instance method, and static method 14 | resource r3 { 15 | /// Constructor 16 | constructor(a: u32); 17 | /// Method 18 | a: func(b: u32); 19 | /// Static method 20 | b: static func(c: u32); 21 | } 22 | } 23 | 24 | world bar { 25 | /// Resource without methods 26 | resource r1; 27 | 28 | /// Resource with only constructor 29 | resource r2 { 30 | /// Constructor 31 | constructor(); 32 | } 33 | 34 | /// Resource with constructor, instance method, and static method 35 | resource r3 { 36 | /// Constructor 37 | constructor(a: u32); 38 | /// Method 39 | a: func(b: u32); 40 | /// Static method 41 | b: static func(c: u32); 42 | } 43 | } -------------------------------------------------------------------------------- /crates/wac-parser/tests/parser/type-alias.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | /// u8 4 | type a = u8; 5 | /// s8 6 | type b = s8; 7 | /// u16 8 | type c = u16; 9 | /// s16 10 | type d = s16; 11 | /// u32 12 | type e = u32; 13 | /// s32 14 | type f = s32; 15 | /// u64 16 | type g = u64; 17 | /// s64 18 | type h = s64; 19 | /// f32 20 | type i = f32; 21 | /// f64 22 | type j = f64; 23 | /// bool 24 | type k = bool; 25 | /// char 26 | type l = char; 27 | /// string 28 | type m = string; 29 | /// tuple 30 | type n = tuple; 31 | /// list> 32 | type o = list>; 33 | /// option 34 | type p = option; 35 | /// result 36 | type q = result; 37 | /// result 38 | type r = result; 39 | /// result<_, s8> 40 | type s = result<_, s8>; 41 | /// result 42 | type t = result; 43 | /// borrow 44 | type u = borrow; 45 | /// x 46 | type v = x; 47 | /// keyword 48 | type %type = v; 49 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/parser/types.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | /// Defining an interface 4 | interface i { 5 | /// Defining a resource 6 | resource res { 7 | constructor(); 8 | } 9 | 10 | /// Type alias a 11 | type a = func(); 12 | /// Record type 13 | record r { 14 | x: u32 15 | } 16 | /// Export func 17 | x: func(); 18 | /// Export func of type a 19 | y: a; 20 | } 21 | 22 | /// Defining a second interface 23 | interface i2 { 24 | /// Use type r from i 25 | use i.{r}; 26 | 27 | /// Use type r from i with alias z 28 | use i.{r as z}; 29 | } 30 | 31 | /// Defining a world 32 | world w1 { 33 | /// Use type r from foo:bar/i 34 | use foo:bar/i.{r}; 35 | 36 | /// Import a function 37 | import a: func(); 38 | /// Import an interface 39 | import i; 40 | /// Import by name with type `c` 41 | import c: c; 42 | 43 | /// Export an inline interface 44 | export d: interface { 45 | x: func(); 46 | }; 47 | /// Export an interface 48 | export i2; 49 | /// Export by name with type `f` 50 | export f: f; 51 | } 52 | 53 | /// Defining a second world 54 | world w2 { 55 | /// Include the first world 56 | include w1; 57 | 58 | /// Include a world by path 59 | include foo:bar/baz; 60 | } 61 | 62 | /// Defining a variant 63 | variant v { 64 | a(x), 65 | b(string), 66 | c(u32), 67 | d, 68 | } 69 | 70 | /// Defining a record 71 | record r { 72 | x: u32, 73 | y: string, 74 | z: v, 75 | } 76 | 77 | /// Defining flags 78 | flags f { 79 | a, 80 | b, 81 | c, 82 | } 83 | 84 | /// Defining an enum 85 | enum e { 86 | a, 87 | b, 88 | c, 89 | } 90 | 91 | /// Type aliases 92 | type t = e; 93 | type t2 = string; 94 | type t3 = func(a: u32, b: r) -> u32; 95 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/parser/use.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | interface my-handler { 4 | use wasi:http/types@0.2.0.{incoming-request, response-outparam}; 5 | handle: func(request: incoming-request, response-out: response-outparam); 6 | } 7 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/alias.wac: -------------------------------------------------------------------------------- 1 | package test:comp@1.0.0; 2 | 3 | type a = u32; 4 | 5 | type b = string; 6 | 7 | type c = func(); 8 | 9 | export a as "a2"; 10 | export b as "b2"; 11 | export c as "c2"; 12 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/alias.wac.result: -------------------------------------------------------------------------------- 1 | digraph { 2 | 0 [ label = "type definition \"a2\""; kind = "u32"; export = "a2"] 3 | 1 [ label = "type definition \"b2\""; kind = "string"; export = "b2"] 4 | 2 [ label = "type definition \"c2\""; kind = "function type"; export = "c2"] 5 | } 6 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/duplicate-world-item.wac: -------------------------------------------------------------------------------- 1 | package test:comp@2.0.0; 2 | 3 | world w { 4 | import x: func(); 5 | export x: func(); 6 | } -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/duplicate-world-item.wac.result: -------------------------------------------------------------------------------- 1 | digraph { 2 | 0 [ label = "type definition \"w\""; kind = "world"; export = "w"] 3 | } 4 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/borrow-in-func-result.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | interface foo { 4 | resource x; 5 | type a = borrow; 6 | f: func() -> result; 7 | } 8 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/borrow-in-func-result.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × function result cannot recursively contain a borrow type 4 | ╭─[tests/resolution/fail/borrow-in-func-result.wac:6:18] 5 | 5 │ type a = borrow; 6 | 6 │ f: func() -> result; 7 | · ────┬──── 8 | · ╰── borrow type in result 9 | 7 │ } 10 | ╰──── 11 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/duplicate-enum-case.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | enum e { 4 | a, 5 | b, 6 | c, 7 | b, 8 | } -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/duplicate-enum-case.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × duplicate case `b` for enum type `e` 4 | ╭─[tests/resolution/fail/duplicate-enum-case.wac:7:5] 5 | 6 │ c, 6 | 7 │ b, 7 | · ┬ 8 | · ╰── duplicate case `b` 9 | 8 │ } 10 | ╰──── 11 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/duplicate-export.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import foo: func(); 4 | 5 | export foo as "foo"; 6 | export foo as foo; 7 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/duplicate-export.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × duplicate export `foo` 4 | ╭─[tests/resolution/fail/duplicate-export.wac:6:15] 5 | 4 │ 6 | 5 │ export foo as "foo"; 7 | · ──┬── 8 | · ╰── previous export here 9 | 6 │ export foo as foo; 10 | · ─┬─ 11 | · ╰── duplicate export name `foo` 12 | ╰──── 13 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/duplicate-flag.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | flags f { 4 | a, 5 | b, 6 | c, 7 | d, 8 | a, 9 | } -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/duplicate-flag.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × duplicate flag `a` for flags type `f` 4 | ╭─[tests/resolution/fail/duplicate-flag.wac:8:5] 5 | 7 │ d, 6 | 8 │ a, 7 | · ┬ 8 | · ╰── duplicate flag `a` 9 | 9 │ } 10 | ╰──── 11 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/duplicate-func-param.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | type f = func(x: u32, x: string); -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/duplicate-func-param.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × duplicate function parameter `x` 4 | ╭─[tests/resolution/fail/duplicate-func-param.wac:3:23] 5 | 2 │ 6 | 3 │ type f = func(x: u32, x: string); 7 | · ┬ 8 | · ╰── duplicate parameter `x` 9 | ╰──── 10 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/duplicate-import.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import foo as "foo": func(); 4 | import bar as foo: func(); 5 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/duplicate-import.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × duplicate import `foo` 4 | ╭─[tests/resolution/fail/duplicate-import.wac:4:15] 5 | 2 │ 6 | 3 │ import foo as "foo": func(); 7 | · ──┬── 8 | · ╰── previous import here 9 | 4 │ import bar as foo: func(); 10 | · ─┬─ 11 | · ╰── duplicate import name `foo` 12 | ╰──── 13 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/duplicate-inst-args.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import bar: func(); 4 | 5 | let x = new foo:bar { foo: bar, foo: bar }; 6 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/duplicate-inst-args.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × duplicate instantiation argument `foo` 4 | ╭─[tests/resolution/fail/duplicate-inst-args.wac:5:33] 5 | 4 │ 6 | 5 │ let x = new foo:bar { foo: bar, foo: bar }; 7 | · ─┬─ 8 | · ╰── duplicate argument `foo` 9 | ╰──── 10 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/duplicate-inst-args/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (import "foo" (func)) 3 | ) -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/duplicate-interface-export.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | interface x { 4 | x: func(); 5 | x: func(); 6 | } -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/duplicate-interface-export.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × duplicate interface export `x` for interface `x` 4 | ╭─[tests/resolution/fail/duplicate-interface-export.wac:5:5] 5 | 4 │ x: func(); 6 | 5 │ x: func(); 7 | · ┬ 8 | · ╰── duplicate export `x` 9 | 6 │ } 10 | ╰──── 11 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/duplicate-name-in-include.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | world w1 { 4 | 5 | } 6 | 7 | world w2 { 8 | include w1 with { a as b, a as c}; 9 | } -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/duplicate-name-in-include.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × duplicate `a` in world include `with` clause 4 | ╭─[tests/resolution/fail/duplicate-name-in-include.wac:8:31] 5 | 7 │ world w2 { 6 | 8 │ include w1 with { a as b, a as c}; 7 | · ┬ 8 | · ╰── duplicate name `a` 9 | 9 │ } 10 | ╰──── 11 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/duplicate-record-field.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | type x = string; 4 | 5 | record r { 6 | a: s8, 7 | b: u8, 8 | c: x, 9 | b: string, 10 | } -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/duplicate-record-field.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × duplicate field `b` for record type `r` 4 | ╭─[tests/resolution/fail/duplicate-record-field.wac:9:5] 5 | 8 │ c: x, 6 | 9 │ b: string, 7 | · ┬ 8 | · ╰── duplicate field `b` 9 | 10 │ } 10 | ╰──── 11 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/duplicate-resource-constructor-param.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | interface foo { 4 | resource x { 5 | constructor(a: u32, a: string); 6 | } 7 | } -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/duplicate-resource-constructor-param.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × duplicate constructor parameter `a` 4 | ╭─[tests/resolution/fail/duplicate-resource-constructor-param.wac:5:29] 5 | 4 │ resource x { 6 | 5 │ constructor(a: u32, a: string); 7 | · ┬ 8 | · ╰── duplicate parameter `a` 9 | 6 │ } 10 | ╰──── 11 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/duplicate-resource-constructor.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | interface foo { 4 | resource x { 5 | constructor(); 6 | constructor(x: u32); 7 | } 8 | } -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/duplicate-resource-constructor.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × duplicate constructor for resource `x` 4 | ╭─[tests/resolution/fail/duplicate-resource-constructor.wac:6:9] 5 | 5 │ constructor(); 6 | 6 │ constructor(x: u32); 7 | · ─────┬───── 8 | · ╰── duplicate constructor 9 | 7 │ } 10 | ╰──── 11 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/duplicate-resource-method.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | world foo { 4 | resource x { 5 | x: func(); 6 | x: static func(); 7 | } 8 | } -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/duplicate-resource-method.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × duplicate method `x` for resource `x` 4 | ╭─[tests/resolution/fail/duplicate-resource-method.wac:6:9] 5 | 5 │ x: func(); 6 | 6 │ x: static func(); 7 | · ┬ 8 | · ╰── duplicate method `x` 9 | 7 │ } 10 | ╰──── 11 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/duplicate-use-in-interface.wac: -------------------------------------------------------------------------------- 1 | package foo:bar; 2 | 3 | interface i { 4 | type x = u32; 5 | } 6 | 7 | interface i2 { 8 | x: func(); 9 | use i.{x}; 10 | } 11 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/duplicate-use-in-interface.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × use of type `x` conflicts with an export of the same name 4 | ╭─[tests/resolution/fail/duplicate-use-in-interface.wac:9:12] 5 | 8 │ x: func(); 6 | 9 │ use i.{x}; 7 | · ┬ 8 | · ╰── conflicting name `x` 9 | 10 │ } 10 | ╰──── 11 | help: consider using an `as` clause to use a different name 12 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/duplicate-use-in-world.wac: -------------------------------------------------------------------------------- 1 | package foo:bar; 2 | 3 | interface i { 4 | type x = u32; 5 | } 6 | 7 | world w { 8 | import x: func(); 9 | use i.{x}; 10 | } 11 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/duplicate-use-in-world.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × use of type `x` conflicts with an import of the same name 4 | ╭─[tests/resolution/fail/duplicate-use-in-world.wac:9:12] 5 | 8 │ import x: func(); 6 | 9 │ use i.{x}; 7 | · ┬ 8 | · ╰── conflicting name `x` 9 | 10 │ } 10 | ╰──── 11 | help: consider using an `as` clause to use a different name 12 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/duplicate-variant-case.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | type x = string; 4 | 5 | variant x { 6 | a(x), 7 | b, 8 | a, 9 | } -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/duplicate-variant-case.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × duplicate case `a` for variant type `x` 4 | ╭─[tests/resolution/fail/duplicate-variant-case.wac:8:5] 5 | 7 │ b, 6 | 8 │ a, 7 | · ┬ 8 | · ╰── duplicate case `a` 9 | 9 │ } 10 | ╰──── 11 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/duplicate-world-export.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | world w { 4 | export x: func(); 5 | export x: func(); 6 | } -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/duplicate-world-export.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × export `x` conflicts with existing export of the same name in world `w` 4 | ╭─[tests/resolution/fail/duplicate-world-export.wac:5:12] 5 | 4 │ export x: func(); 6 | 5 │ export x: func(); 7 | · ┬ 8 | · ╰── conflicting name `x` 9 | 6 │ } 10 | ╰──── 11 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/duplicate-world-import.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | world w { 4 | import x: func(); 5 | import x: func(); 6 | } -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/duplicate-world-import.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × import `x` conflicts with existing import of the same name in world `w` 4 | ╭─[tests/resolution/fail/duplicate-world-import.wac:5:12] 5 | 4 │ import x: func(); 6 | 5 │ import x: func(); 7 | · ┬ 8 | · ╰── conflicting name `x` 9 | 6 │ } 10 | ╰──── 11 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/expected-result-named.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import x: interface { 4 | f: func() -> string; 5 | }; 6 | 7 | let i = new foo:bar { x }; 8 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/expected-result-named.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × failed to resolve package `foo:bar` 4 | ╰─▶ unexpected token, expected one of: `bool`, `s8`, `u8`, `s16`, `u16`, `s32`, `u32`, `s64`, `u64`, `f32`, `f64`, `float32`, `float64`, `char`, `string`, `error-context` 5 | --> tests/resolution/fail/expected-result-named/foo/bar.wat:3:31 6 | | 7 | 3 | (export "f" (func (result "a" string))) 8 | | ^ 9 | ╭─[tests/resolution/fail/expected-result-named.wac:7:13] 10 | 6 │ 11 | 7 │ let i = new foo:bar { x }; 12 | · ───┬─── 13 | · ╰── package `foo:bar` failed to resolve 14 | ╰──── 15 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/expected-result-named/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (instance (import "x") 3 | (export "f" (func (result "a" string))) 4 | ) 5 | ) 6 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/expected-result-scalar.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import x: interface { 4 | f: func(); 5 | }; 6 | 7 | let i = new foo:bar { x }; 8 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/expected-result-scalar.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × mismatched instantiation argument `x` 4 | ├─▶ mismatched type for export `f` 5 | ╰─▶ expected function with a result, found function without a result 6 | ╭─[tests/resolution/fail/expected-result-scalar.wac:7:23] 7 | 6 │ 8 | 7 │ let i = new foo:bar { x }; 9 | · ┬ 10 | · ╰── mismatched argument `x` 11 | ╰──── 12 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/expected-result-scalar/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (instance (import "x") 3 | (export "f" (func (result string))) 4 | ) 5 | ) 6 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/export-conflict-alias.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import f as "x": func(); 4 | 5 | type x = u32; 6 | 7 | export f; 8 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/export-conflict-alias.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × export `x` conflicts with u32 definition 4 | ╭─[tests/resolution/fail/export-conflict-alias.wac:7:8] 5 | 4 │ 6 | 5 │ type x = u32; 7 | · ┬ 8 | · ╰── previous definition is here 9 | 6 │ 10 | 7 │ export f; 11 | · ┬ 12 | · ╰── conflicting export of `x` 13 | ╰──── 14 | help: consider using an `as` clause to use a different name 15 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/export-conflict-interface.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import f: func(); 4 | 5 | interface foo { 6 | 7 | } 8 | 9 | export f as "foo"; 10 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/export-conflict-interface.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × export `foo` conflicts with interface definition 4 | ╭─[tests/resolution/fail/export-conflict-interface.wac:9:13] 5 | 4 │ 6 | 5 │ interface foo { 7 | · ─┬─ 8 | · ╰── previous definition is here 9 | 6 │ 10 | 7 │ } 11 | 8 │ 12 | 9 │ export f as "foo"; 13 | · ──┬── 14 | · ╰── conflicting export of `foo` 15 | ╰──── 16 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/export-conflict-type.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import f as "x": func(); 4 | 5 | record x { 6 | a: u32 7 | } 8 | 9 | export f as "x"; 10 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/export-conflict-type.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × export `x` conflicts with record definition 4 | ╭─[tests/resolution/fail/export-conflict-type.wac:9:13] 5 | 4 │ 6 | 5 │ record x { 7 | · ┬ 8 | · ╰── previous definition is here 9 | 6 │ a: u32 10 | 7 │ } 11 | 8 │ 12 | 9 │ export f as "x"; 13 | · ─┬─ 14 | · ╰── conflicting export of `x` 15 | ╰──── 16 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/export-conflict-world.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import f: func(); 4 | 5 | world foo { 6 | 7 | } 8 | 9 | export f as "foo"; 10 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/export-conflict-world.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × export `foo` conflicts with world definition 4 | ╭─[tests/resolution/fail/export-conflict-world.wac:9:13] 5 | 4 │ 6 | 5 │ world foo { 7 | · ─┬─ 8 | · ╰── previous definition is here 9 | 6 │ 10 | 7 │ } 11 | 8 │ 12 | 9 │ export f as "foo"; 13 | · ──┬── 14 | · ╰── conflicting export of `foo` 15 | ╰──── 16 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/export-dep-name.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import f: func(); 4 | export f as "locked-dep="; -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/export-dep-name.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × export name `locked-dep=` is not valid 4 | ╰─▶ export name cannot be a hash, url, or dependency 5 | ╭─[tests/resolution/fail/export-dep-name.wac:4:13] 6 | 3 │ import f: func(); 7 | 4 │ export f as "locked-dep="; 8 | · ───────────┬────────── 9 | · ╰── invalid name `locked-dep=` 10 | ╰──── 11 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/export-duplicate-name.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import f: func(); 4 | export f as "x"; 5 | export f as "x"; 6 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/export-duplicate-name.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × duplicate export `x` 4 | ╭─[tests/resolution/fail/export-duplicate-name.wac:5:13] 5 | 3 │ import f: func(); 6 | 4 │ export f as "x"; 7 | · ─┬─ 8 | · ╰── previous export here 9 | 5 │ export f as "x"; 10 | · ─┬─ 11 | · ╰── duplicate export name `x` 12 | ╰──── 13 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/export-hash-name.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import f: func(); 4 | export f as "integrity="; -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/export-hash-name.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × export name `integrity=` is not valid 4 | ╰─▶ export name cannot be a hash, url, or dependency 5 | ╭─[tests/resolution/fail/export-hash-name.wac:4:13] 6 | 3 │ import f: func(); 7 | 4 │ export f as "integrity="; 8 | · ──────────────────────────────────────────┬────────────────────────────────────────── 9 | · ╰── invalid name `integrity=` 10 | ╰──── 11 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/export-invalid-name.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import f: func(); 4 | export f as "INVALID!"; -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/export-invalid-name.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × export name `INVALID!` is not valid 4 | ╰─▶ `INVALID!` is not in kebab case 5 | ╭─[tests/resolution/fail/export-invalid-name.wac:4:13] 6 | 3 │ import f: func(); 7 | 4 │ export f as "INVALID!"; 8 | · ─────┬──── 9 | · ╰── invalid name `INVALID!` 10 | ╰──── 11 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/export-needs-with.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | let i = new foo:bar {}; 4 | export i; 5 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/export-needs-with.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × export statement requires an `as` clause as the export name cannot be inferred 4 | ╭─[tests/resolution/fail/export-needs-with.wac:4:8] 5 | 3 │ let i = new foo:bar {}; 6 | 4 │ export i; 7 | · ┬ 8 | · ╰── an `as` clause is required 9 | ╰──── 10 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/export-needs-with/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component) -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/export-url-name.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import f: func(); 4 | export f as "url="; -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/export-url-name.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × export name `url=` is not valid 4 | ╰─▶ export name cannot be a hash, url, or dependency 5 | ╭─[tests/resolution/fail/export-url-name.wac:4:13] 6 | 3 │ import f: func(); 7 | 4 │ export f as "url="; 8 | · ───────────────┬─────────────── 9 | · ╰── invalid name `url=` 10 | ╰──── 11 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/fill-not-last.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | let x = new foo:bar { ..., a }; 4 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/fill-not-last.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × implicit import argument `...` must be the last argument 4 | ╭─[tests/resolution/fail/fill-not-last.wac:3:23] 5 | 2 │ 6 | 3 │ let x = new foo:bar { ..., a }; 7 | · ─┬─ 8 | · ╰── must be last argument 9 | ╰──── 10 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/fill-not-last/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component) 2 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/func-results-not-present.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import x: interface { 4 | f: func(); 5 | }; 6 | 7 | let i = new foo:bar { x }; 8 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/func-results-not-present.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × mismatched instantiation argument `x` 4 | ├─▶ mismatched type for export `f` 5 | ╰─▶ expected function with a result, found function without a result 6 | ╭─[tests/resolution/fail/func-results-not-present.wac:7:23] 7 | 6 │ 8 | 7 │ let i = new foo:bar { x }; 9 | · ┬ 10 | · ╰── mismatched argument `x` 11 | ╰──── 12 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/func-results-not-present/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (instance (import "x") 3 | (export "f" (func (result string))) 4 | ) 5 | ) 6 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/func-results-present.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import x: interface { 4 | f: func() -> string; 5 | }; 6 | 7 | let i = new foo:bar { x }; 8 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/func-results-present.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × mismatched instantiation argument `x` 4 | ├─▶ mismatched type for export `f` 5 | ╰─▶ expected function without a result, found function with a result 6 | ╭─[tests/resolution/fail/func-results-present.wac:7:23] 7 | 6 │ 8 | 7 │ let i = new foo:bar { x }; 9 | · ┬ 10 | · ╰── mismatched argument `x` 11 | ╰──── 12 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/func-results-present/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (instance (import "x") 3 | (export "f" (func)) 4 | ) 5 | ) 6 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/import-duplicate-name.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import x as "foo": func(); 4 | import y as "foo": interface {}; 5 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/import-duplicate-name.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × duplicate import `foo` 4 | ╭─[tests/resolution/fail/import-duplicate-name.wac:4:13] 5 | 2 │ 6 | 3 │ import x as "foo": func(); 7 | · ──┬── 8 | · ╰── previous import here 9 | 4 │ import y as "foo": interface {}; 10 | · ──┬── 11 | · ╰── duplicate import name `foo` 12 | ╰──── 13 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/import-id-span.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import env-foo: wasi:cli/environment; 4 | 5 | import env-bar: wasi:cli/environment; 6 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/import-id-span.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × duplicate import `wasi:cli/environment` 4 | ╭─[tests/resolution/fail/import-id-span.wac:5:17] 5 | 2 │ 6 | 3 │ import env-foo: wasi:cli/environment; 7 | · ──────────┬───────── 8 | · ╰── previous import here 9 | 4 │ 10 | 5 │ import env-bar: wasi:cli/environment; 11 | · ──────────┬───────── 12 | · ╰── duplicate import name `wasi:cli/environment` 13 | ╰──── 14 | help: consider using an `as` clause to use a different name 15 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/import-id-span/wasi/cli/package.wit: -------------------------------------------------------------------------------- 1 | package wasi:cli; 2 | 3 | interface environment { 4 | } 5 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/import-invalid-name.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import x as "NOT-VALID-NAME!": func(); 4 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/import-invalid-name.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × import name `NOT-VALID-NAME!` is not valid 4 | ╰─▶ `NOT-VALID-NAME!` is not in kebab case 5 | ╭─[tests/resolution/fail/import-invalid-name.wac:3:13] 6 | 2 │ 7 | 3 │ import x as "NOT-VALID-NAME!": func(); 8 | · ────────┬──────── 9 | · ╰── invalid name `NOT-VALID-NAME!` 10 | ╰──── 11 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/inaccessible.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import f: func(); 4 | 5 | let x = f.foo; 6 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/inaccessible.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × an instance is required to perform an access operation 4 | ╭─[tests/resolution/fail/inaccessible.wac:5:9] 5 | 4 │ 6 | 5 │ let x = f.foo; 7 | · ┬ 8 | · ╰── this evaluated to a function when an instance was expected 9 | ╰──── 10 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/invalid-alias.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | interface a { 4 | 5 | } 6 | 7 | type x = a; -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/invalid-alias.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × `a` (interface) cannot be used in a type alias 4 | ╭─[tests/resolution/fail/invalid-alias.wac:7:10] 5 | 6 │ 6 | 7 │ type x = a; 7 | · ┬ 8 | · ╰── `a` cannot be aliased 9 | ╰──── 10 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/invalid-borrow.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | type x = u32; 4 | 5 | type y = borrow; -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/invalid-borrow.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × `x` (u32) is not a resource type 4 | ╭─[tests/resolution/fail/invalid-borrow.wac:5:17] 5 | 4 │ 6 | 5 │ type y = borrow; 7 | · ┬ 8 | · ╰── `x` is not a resource type 9 | ╰──── 10 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/invalid-func-type-ref.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | interface i { 4 | type x = u32; 5 | 6 | x: x; 7 | } -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/invalid-func-type-ref.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × `x` (u32) is not a function type 4 | ╭─[tests/resolution/fail/invalid-func-type-ref.wac:6:8] 5 | 5 │ 6 | 6 │ x: x; 7 | · ┬ 8 | · ╰── `x` is not a function type 9 | 7 │ } 10 | ╰──── 11 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/invalid-use-alias.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | interface a { 4 | type a = u32; 5 | } 6 | 7 | interface b { 8 | type b = u32; 9 | use a.{a as b}; 10 | } -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/invalid-use-alias.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × use of type `b` conflicts with an export of the same name 4 | ╭─[tests/resolution/fail/invalid-use-alias.wac:9:17] 5 | 8 │ type b = u32; 6 | 9 │ use a.{a as b}; 7 | · ┬ 8 | · ╰── conflicting name `b` 9 | 10 │ } 10 | ╰──── 11 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/invalid-use.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | type x = u32; 4 | 5 | interface a { 6 | use x.{a}; 7 | } -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/invalid-use.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × `x` (u32) is not an interface 4 | ╭─[tests/resolution/fail/invalid-use.wac:6:9] 5 | 5 │ interface a { 6 | 6 │ use x.{a}; 7 | · ┬ 8 | · ╰── `x` is not an interface 9 | 7 │ } 10 | ╰──── 11 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/invalid-value-type.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | interface i { 4 | 5 | } 6 | 7 | type x = func(i: i); -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/invalid-value-type.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × `i` (interface) cannot be used as a value type 4 | ╭─[tests/resolution/fail/invalid-value-type.wac:7:18] 5 | 6 │ 6 | 7 │ type x = func(i: i); 7 | · ┬ 8 | · ╰── `i` not a value type 9 | ╰──── 10 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/invalid-world-export.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | type x = u32; 4 | 5 | world w { 6 | import x: x; 7 | } -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/invalid-world-export.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × `x` (u32) is not a function type or interface 4 | ╭─[tests/resolution/fail/invalid-world-export.wac:6:15] 5 | 5 │ world w { 6 | 6 │ import x: x; 7 | · ┬ 8 | · ╰── `x` is not a function type or interface 9 | 7 │ } 10 | ╰──── 11 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/invalid-world-import.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | type x = u32; 4 | 5 | world w { 6 | import x: x; 7 | } -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/invalid-world-import.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × `x` (u32) is not a function type or interface 4 | ╭─[tests/resolution/fail/invalid-world-import.wac:6:15] 5 | 5 │ world w { 6 | 6 │ import x: x; 7 | · ┬ 8 | · ╰── `x` is not a function type or interface 9 | 7 │ } 10 | ╰──── 11 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/invalid-world-include.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | type x = func(); 4 | 5 | world w { 6 | include x; 7 | } -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/invalid-world-include.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × `x` (function type) is not a world 4 | ╭─[tests/resolution/fail/invalid-world-include.wac:6:13] 5 | 5 │ world w { 6 | 6 │ include x; 7 | · ┬ 8 | · ╰── `x` is not a world 9 | 7 │ } 10 | ╰──── 11 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/invalid-world-interface-export.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | type x = u32; 4 | 5 | world w { 6 | export x; 7 | } -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/invalid-world-interface-export.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × `x` (u32) is not an interface 4 | ╭─[tests/resolution/fail/invalid-world-interface-export.wac:6:12] 5 | 5 │ world w { 6 | 6 │ export x; 7 | · ┬ 8 | · ╰── `x` is not an interface 9 | 7 │ } 10 | ╰──── 11 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/invalid-world-interface-import.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | type x = u32; 4 | 5 | world w { 6 | import x; 7 | } -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/invalid-world-interface-import.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × `x` (u32) is not an interface 4 | ╭─[tests/resolution/fail/invalid-world-interface-import.wac:6:12] 5 | 5 │ world w { 6 | 6 │ import x; 7 | · ┬ 8 | · ╰── `x` is not an interface 9 | 7 │ } 10 | ╰──── 11 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-enum-cases.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import x: interface { 4 | enum e { 5 | a, 6 | c, 7 | b, 8 | } 9 | }; 10 | 11 | let i = new foo:bar { x }; 12 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-enum-cases.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × mismatched instantiation argument `x` 4 | ├─▶ mismatched type for export `e` 5 | ╰─▶ expected enum case 1 to be named `b`, found an enum case named `c` 6 | ╭─[tests/resolution/fail/mismatched-enum-cases.wac:11:23] 7 | 10 │ 8 | 11 │ let i = new foo:bar { x }; 9 | · ┬ 10 | · ╰── mismatched argument `x` 11 | ╰──── 12 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-enum-cases/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (instance (import "x") 3 | (type (enum "a" "b" "c")) 4 | (export "e" (type (eq 0))) 5 | ) 6 | ) 7 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-enum-count.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import x: interface { 4 | enum e { 5 | a, 6 | b, 7 | c, 8 | d, 9 | } 10 | }; 11 | 12 | let i = new foo:bar { x }; 13 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-enum-count.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × mismatched instantiation argument `x` 4 | ├─▶ mismatched type for export `e` 5 | ╰─▶ expected an enum type case count of 3, found a count of 4 6 | ╭─[tests/resolution/fail/mismatched-enum-count.wac:12:23] 7 | 11 │ 8 | 12 │ let i = new foo:bar { x }; 9 | · ┬ 10 | · ╰── mismatched argument `x` 11 | ╰──── 12 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-enum-count/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (instance (import "x") 3 | (type (enum "a" "b" "c")) 4 | (export "e" (type (eq 0))) 5 | ) 6 | ) 7 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-err-result-type.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import x: interface { 4 | f: func() -> result<_, string>; 5 | }; 6 | 7 | let i = new foo:bar { x }; 8 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-err-result-type.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × mismatched instantiation argument `x` 4 | ├─▶ mismatched type for export `f` 5 | ├─▶ mismatched type for function result 6 | ├─▶ mismatched type for result `err` 7 | ╰─▶ expected u8, found string 8 | ╭─[tests/resolution/fail/mismatched-err-result-type.wac:7:23] 9 | 6 │ 10 | 7 │ let i = new foo:bar { x }; 11 | · ┬ 12 | · ╰── mismatched argument `x` 13 | ╰──── 14 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-err-result-type/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (instance (import "x") 3 | (export "f" (func (result (result (error u8))))) 4 | ) 5 | ) 6 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-flags-count.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import x: interface { 4 | flags f { 5 | a, 6 | b, 7 | c, 8 | d, 9 | } 10 | }; 11 | 12 | let i = new foo:bar { x }; 13 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-flags-count.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × mismatched instantiation argument `x` 4 | ├─▶ mismatched type for export `f` 5 | ╰─▶ expected a flags type flag count of 3, found a count of 4 6 | ╭─[tests/resolution/fail/mismatched-flags-count.wac:12:23] 7 | 11 │ 8 | 12 │ let i = new foo:bar { x }; 9 | · ┬ 10 | · ╰── mismatched argument `x` 11 | ╰──── 12 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-flags-count/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (instance (import "x") 3 | (type (flags "a" "b" "c")) 4 | (export "f" (type (eq 0))) 5 | ) 6 | ) 7 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-flags.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import x: interface { 4 | flags f { 5 | a, 6 | c, 7 | b, 8 | } 9 | }; 10 | 11 | let i = new foo:bar { x }; 12 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-flags.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × mismatched instantiation argument `x` 4 | ├─▶ mismatched type for export `f` 5 | ╰─▶ expected flag 1 to be named `b`, found a flag named `c` 6 | ╭─[tests/resolution/fail/mismatched-flags.wac:11:23] 7 | 10 │ 8 | 11 │ let i = new foo:bar { x }; 9 | · ┬ 10 | · ╰── mismatched argument `x` 11 | ╰──── 12 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-flags/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (instance (import "x") 3 | (type (flags "a" "b" "c")) 4 | (export "f" (type (eq 0))) 5 | ) 6 | ) 7 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-func-param-name.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import x: interface { 4 | f: func(b: u32); 5 | }; 6 | 7 | let i = new foo:bar { x }; 8 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-func-param-name.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × mismatched instantiation argument `x` 4 | ├─▶ mismatched type for export `f` 5 | ╰─▶ expected function parameter 0 to be named `a`, found name `b` 6 | ╭─[tests/resolution/fail/mismatched-func-param-name.wac:7:23] 7 | 6 │ 8 | 7 │ let i = new foo:bar { x }; 9 | · ┬ 10 | · ╰── mismatched argument `x` 11 | ╰──── 12 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-func-param-name/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (instance (import "x") 3 | (export "f" (func (param "a" u32))) 4 | ) 5 | ) 6 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-func-param-type.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import x: interface { 4 | resource r; 5 | f: func(r: string); 6 | }; 7 | 8 | let i = new foo:bar { x }; 9 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-func-param-type.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × mismatched instantiation argument `x` 4 | ├─▶ mismatched type for export `f` 5 | ├─▶ mismatched type for function parameter `r` 6 | ╰─▶ expected borrow, found string 7 | ╭─[tests/resolution/fail/mismatched-func-param-type.wac:8:23] 8 | 7 │ 9 | 8 │ let i = new foo:bar { x }; 10 | · ┬ 11 | · ╰── mismatched argument `x` 12 | ╰──── 13 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-func-param-type/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (instance (import "x") 3 | (export "r" (type (sub resource))) 4 | (type $own-r (borrow 0)) 5 | (export "f" (func (param "r" $own-r))) 6 | ) 7 | ) 8 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-func-params.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import x: interface { 4 | f: func(); 5 | }; 6 | 7 | let i = new foo:bar { x }; 8 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-func-params.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × mismatched instantiation argument `x` 4 | ├─▶ mismatched type for export `f` 5 | ╰─▶ expected function with parameter count 1, found parameter count 0 6 | ╭─[tests/resolution/fail/mismatched-func-params.wac:7:23] 7 | 6 │ 8 | 7 │ let i = new foo:bar { x }; 9 | · ┬ 10 | · ╰── mismatched argument `x` 11 | ╰──── 12 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-func-params/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (instance (import "x") 3 | (export "f" (func (param "x" u32))) 4 | ) 5 | ) 6 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-func-scalar-result.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import x: interface { 4 | f: func() -> string; 5 | }; 6 | 7 | let i = new foo:bar { x }; 8 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-func-scalar-result.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × mismatched instantiation argument `x` 4 | ├─▶ mismatched type for export `f` 5 | ├─▶ mismatched type for function result 6 | ╰─▶ expected u8, found string 7 | ╭─[tests/resolution/fail/mismatched-func-scalar-result.wac:7:23] 8 | 6 │ 9 | 7 │ let i = new foo:bar { x }; 10 | · ┬ 11 | · ╰── mismatched argument `x` 12 | ╰──── 13 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-func-scalar-result/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (instance (import "x") 3 | (export "f" (func (result u8))) 4 | ) 5 | ) 6 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-kind.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import x: interface { 4 | type x = u32; 5 | }; 6 | 7 | let i = new foo:bar { x }; 8 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-kind.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × mismatched instantiation argument `x` 4 | ├─▶ mismatched type for export `x` 5 | ╰─▶ expected function, found u32 6 | ╭─[tests/resolution/fail/mismatched-kind.wac:7:23] 7 | 6 │ 8 | 7 │ let i = new foo:bar { x }; 9 | · ┬ 10 | · ╰── mismatched argument `x` 11 | ╰──── 12 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-kind/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (instance (import "x") 3 | (export "x" (func)) 4 | ) 5 | ) 6 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-list-element.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import x: interface { 4 | f: func(l: list); 5 | }; 6 | 7 | let i = new foo:bar { x }; 8 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-list-element.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × mismatched instantiation argument `x` 4 | ├─▶ mismatched type for export `f` 5 | ├─▶ mismatched type for function parameter `l` 6 | ├─▶ mismatched type for list element 7 | ╰─▶ expected u8, found string 8 | ╭─[tests/resolution/fail/mismatched-list-element.wac:7:23] 9 | 6 │ 10 | 7 │ let i = new foo:bar { x }; 11 | · ┬ 12 | · ╰── mismatched argument `x` 13 | ╰──── 14 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-list-element/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (instance (import "x") 3 | (export "f" (func (param "l" (list u8)))) 4 | ) 5 | ) 6 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-ok-result-type.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import x: interface { 4 | f: func() -> result; 5 | }; 6 | 7 | let i = new foo:bar { x }; 8 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-ok-result-type.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × mismatched instantiation argument `x` 4 | ├─▶ mismatched type for export `f` 5 | ├─▶ mismatched type for function result 6 | ├─▶ mismatched type for result `ok` 7 | ╰─▶ expected u8, found string 8 | ╭─[tests/resolution/fail/mismatched-ok-result-type.wac:7:23] 9 | 6 │ 10 | 7 │ let i = new foo:bar { x }; 11 | · ┬ 12 | · ╰── mismatched argument `x` 13 | ╰──── 14 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-ok-result-type/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (instance (import "x") 3 | (export "f" (func (result (result u8)))) 4 | ) 5 | ) 6 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-option.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import x: interface { 4 | f: func(o: option); 5 | }; 6 | 7 | let i = new foo:bar { x }; 8 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-option.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × mismatched instantiation argument `x` 4 | ├─▶ mismatched type for export `f` 5 | ├─▶ mismatched type for function parameter `o` 6 | ├─▶ mismatched type for option 7 | ╰─▶ expected string, found u8 8 | ╭─[tests/resolution/fail/mismatched-option.wac:7:23] 9 | 6 │ 10 | 7 │ let i = new foo:bar { x }; 11 | · ┬ 12 | · ╰── mismatched argument `x` 13 | ╰──── 14 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-option/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (instance (import "x") 3 | (export "f" (func (param "o" (option string)))) 4 | ) 5 | ) 6 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-record-field-count.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import x: interface { 4 | record r { 5 | a: u8, 6 | b: u16, 7 | c: u32, 8 | d: u64, 9 | } 10 | }; 11 | 12 | let i = new foo:bar { x }; 13 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-record-field-count.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × mismatched instantiation argument `x` 4 | ├─▶ mismatched type for export `r` 5 | ╰─▶ expected a record field count of 3, found a count of 4 6 | ╭─[tests/resolution/fail/mismatched-record-field-count.wac:12:23] 7 | 11 │ 8 | 12 │ let i = new foo:bar { x }; 9 | · ┬ 10 | · ╰── mismatched argument `x` 11 | ╰──── 12 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-record-field-count/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (instance (import "x") 3 | (type (record (field "a" u8) (field "b" u16) (field "c" u32))) 4 | (export "r" (type (eq 0))) 5 | ) 6 | ) 7 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-record-field-name.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import x: interface { 4 | record r { 5 | a: u8, 6 | c: u16, 7 | b: u32, 8 | } 9 | }; 10 | 11 | let i = new foo:bar { x }; 12 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-record-field-name.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × mismatched instantiation argument `x` 4 | ├─▶ mismatched type for export `r` 5 | ╰─▶ expected record field 1 to be named `b`, found a field named `c` 6 | ╭─[tests/resolution/fail/mismatched-record-field-name.wac:11:23] 7 | 10 │ 8 | 11 │ let i = new foo:bar { x }; 9 | · ┬ 10 | · ╰── mismatched argument `x` 11 | ╰──── 12 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-record-field-name/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (instance (import "x") 3 | (type (record (field "a" u8) (field "b" u16) (field "c" u32))) 4 | (export "r" (type (eq 0))) 5 | ) 6 | ) 7 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-record-field-type.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import x: interface { 4 | record r { 5 | a: u8, 6 | b: string, 7 | c: u32, 8 | } 9 | }; 10 | 11 | let i = new foo:bar { x }; 12 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-record-field-type.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × mismatched instantiation argument `x` 4 | ├─▶ mismatched type for export `r` 5 | ├─▶ mismatched type for record field `b` 6 | ╰─▶ expected u16, found string 7 | ╭─[tests/resolution/fail/mismatched-record-field-type.wac:11:23] 8 | 10 │ 9 | 11 │ let i = new foo:bar { x }; 10 | · ┬ 11 | · ╰── mismatched argument `x` 12 | ╰──── 13 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-record-field-type/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (instance (import "x") 3 | (type (record (field "a" u8) (field "b" u16) (field "c" u32))) 4 | (export "r" (type (eq 0))) 5 | ) 6 | ) 7 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-resource-types.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import x: interface { 4 | resource x; 5 | resource y; 6 | f: func(x: y); 7 | }; 8 | 9 | let i = new foo:bar { x }; 10 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-resource-types.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × mismatched instantiation argument `x` 4 | ├─▶ mismatched type for export `f` 5 | ├─▶ mismatched type for function parameter `x` 6 | ╰─▶ expected resource `x`, found resource `y` 7 | ╭─[tests/resolution/fail/mismatched-resource-types.wac:9:23] 8 | 8 │ 9 | 9 │ let i = new foo:bar { x }; 10 | · ┬ 11 | · ╰── mismatched argument `x` 12 | ╰──── 13 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-resource-types/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (instance (import "x") 3 | (export "x" (type (sub resource))) 4 | (export "y" (type (sub resource))) 5 | (type $own-x (own 0)) 6 | (export "f" (func (param "x" $own-x))) 7 | ) 8 | ) 9 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-tuple-size.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import x: interface { 4 | type t = tuple, u16>; 5 | }; 6 | 7 | let i = new foo:bar { x }; 8 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-tuple-size.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × mismatched instantiation argument `x` 4 | ├─▶ mismatched type for export `t` 5 | ╰─▶ expected a tuple of size 3, found a tuple of size 4 6 | ╭─[tests/resolution/fail/mismatched-tuple-size.wac:7:23] 7 | 6 │ 8 | 7 │ let i = new foo:bar { x }; 9 | · ┬ 10 | · ╰── mismatched argument `x` 11 | ╰──── 12 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-tuple-size/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (instance (import "x") 3 | (type $t (tuple u8 string (tuple u32))) 4 | (export "t" (type (eq $t))) 5 | ) 6 | ) 7 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-tuple-type.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import x: interface { 4 | type t = tuple>; 5 | }; 6 | 7 | let i = new foo:bar { x }; 8 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-tuple-type.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × mismatched instantiation argument `x` 4 | ├─▶ mismatched type for export `t` 5 | ├─▶ mismatched type for tuple item 2 6 | ├─▶ mismatched type for tuple item 0 7 | ╰─▶ expected u32, found string 8 | ╭─[tests/resolution/fail/mismatched-tuple-type.wac:7:23] 9 | 6 │ 10 | 7 │ let i = new foo:bar { x }; 11 | · ┬ 12 | · ╰── mismatched argument `x` 13 | ╰──── 14 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-tuple-type/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (instance (import "x") 3 | (type $t (tuple u8 string (tuple u32))) 4 | (export "t" (type (eq $t))) 5 | ) 6 | ) 7 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-variant-case-count.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import x: interface { 4 | variant v { 5 | a, 6 | b(u16), 7 | c(tuple), 8 | d, 9 | } 10 | }; 11 | 12 | let i = new foo:bar { x }; 13 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-variant-case-count.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × mismatched instantiation argument `x` 4 | ├─▶ mismatched type for export `v` 5 | ╰─▶ expected a variant case count of 3, found a count of 4 6 | ╭─[tests/resolution/fail/mismatched-variant-case-count.wac:12:23] 7 | 11 │ 8 | 12 │ let i = new foo:bar { x }; 9 | · ┬ 10 | · ╰── mismatched argument `x` 11 | ╰──── 12 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-variant-case-count/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (instance (import "x") 3 | (type $v (variant (case "a") (case "b" u16) (case "c" (tuple string u16)))) 4 | (export "v" (type (eq $v))) 5 | ) 6 | ) 7 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-variant-case-name.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import x: interface { 4 | variant v { 5 | a, 6 | c(u16), 7 | b(tuple), 8 | } 9 | }; 10 | 11 | let i = new foo:bar { x }; 12 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-variant-case-name.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × mismatched instantiation argument `x` 4 | ├─▶ mismatched type for export `v` 5 | ╰─▶ expected variant case 1 to be named `b`, found a case named `c` 6 | ╭─[tests/resolution/fail/mismatched-variant-case-name.wac:11:23] 7 | 10 │ 8 | 11 │ let i = new foo:bar { x }; 9 | · ┬ 10 | · ╰── mismatched argument `x` 11 | ╰──── 12 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-variant-case-name/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (instance (import "x") 3 | (type $v (variant (case "a") (case "b" u16) (case "c" (tuple string u16)))) 4 | (export "v" (type (eq $v))) 5 | ) 6 | ) 7 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-variant-case-type.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import x: interface { 4 | variant v { 5 | a, 6 | b(u16), 7 | c(tuple), 8 | } 9 | }; 10 | 11 | let i = new foo:bar { x }; 12 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-variant-case-type.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × mismatched instantiation argument `x` 4 | ├─▶ mismatched type for export `v` 5 | ├─▶ mismatched type for variant case `c` 6 | ├─▶ mismatched type for tuple item 1 7 | ╰─▶ expected u16, found string 8 | ╭─[tests/resolution/fail/mismatched-variant-case-type.wac:11:23] 9 | 10 │ 10 | 11 │ let i = new foo:bar { x }; 11 | · ┬ 12 | · ╰── mismatched argument `x` 13 | ╰──── 14 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/mismatched-variant-case-type/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (instance (import "x") 3 | (type $v (variant (case "a") (case "b" u16) (case "c" (tuple string u16)))) 4 | (export "v" (type (eq $v))) 5 | ) 6 | ) 7 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/missing-access-export.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import i: interface { 4 | 5 | }; 6 | 7 | let x = i.foo; 8 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/missing-access-export.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × the instance has no export named `foo` 4 | ╭─[tests/resolution/fail/missing-access-export.wac:7:10] 5 | 6 │ 6 | 7 │ let x = i.foo; 7 | · ──┬─ 8 | · ╰── unknown export `foo` 9 | ╰──── 10 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/missing-constructor.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import x: interface { 4 | resource r; 5 | f: func(r: r); 6 | }; 7 | 8 | let i = new foo:bar { x }; 9 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/missing-constructor.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × mismatched instantiation argument `x` 4 | ╰─▶ instance is missing expected function export `[constructor]r` 5 | ╭─[tests/resolution/fail/missing-constructor.wac:8:23] 6 | 7 │ 7 | 8 │ let i = new foo:bar { x }; 8 | · ┬ 9 | · ╰── mismatched argument `x` 10 | ╰──── 11 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/missing-constructor/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (instance (import "x") 3 | (export "r" (type (sub resource))) 4 | (type $own-r (own 0)) 5 | (export "f" (func (param "r" $own-r))) 6 | (export "[constructor]r" (func (result $own-r))) 7 | ) 8 | ) 9 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/missing-err-result-type.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import x: interface { 4 | f: func() -> result; 5 | }; 6 | 7 | let i = new foo:bar { x }; 8 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/missing-err-result-type.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × mismatched instantiation argument `x` 4 | ├─▶ mismatched type for export `f` 5 | ├─▶ mismatched type for function result 6 | ╰─▶ expected an `err` for result type 7 | ╭─[tests/resolution/fail/missing-err-result-type.wac:7:23] 8 | 6 │ 9 | 7 │ let i = new foo:bar { x }; 10 | · ┬ 11 | · ╰── mismatched argument `x` 12 | ╰──── 13 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/missing-err-result-type/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (instance (import "x") 3 | (export "f" (func (result (result (error string))))) 4 | ) 5 | ) 6 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/missing-inst-arg.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | let x = new foo:bar {}; 4 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/missing-inst-arg.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × missing instantiation argument `foo` for package `foo:bar` 4 | ╭─[tests/resolution/fail/missing-inst-arg.wac:3:13] 5 | 2 │ 6 | 3 │ let x = new foo:bar {}; 7 | · ───┬─── 8 | · ╰── missing argument `foo` 9 | ╰──── 10 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/missing-inst-arg/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (import "foo" (func)) 3 | ) -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/missing-interface-export.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import x: interface { 4 | }; 5 | 6 | let i = new foo:bar { x }; 7 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/missing-interface-export.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × mismatched instantiation argument `x` 4 | ╰─▶ instance is missing expected function export `f` 5 | ╭─[tests/resolution/fail/missing-interface-export.wac:6:23] 6 | 5 │ 7 | 6 │ let i = new foo:bar { x }; 8 | · ┬ 9 | · ╰── mismatched argument `x` 10 | ╰──── 11 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/missing-interface-export/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (instance (import "x") 3 | (export "f" (func)) 4 | ) 5 | ) 6 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/missing-method.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import x: interface { 4 | resource r; 5 | f: func(r: r); 6 | }; 7 | 8 | let i = new foo:bar { x }; 9 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/missing-method.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × mismatched instantiation argument `x` 4 | ╰─▶ instance is missing expected function export `[method]r.foo` 5 | ╭─[tests/resolution/fail/missing-method.wac:8:23] 6 | 7 │ 7 | 8 │ let i = new foo:bar { x }; 8 | · ┬ 9 | · ╰── mismatched argument `x` 10 | ╰──── 11 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/missing-method/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (instance (import "x") 3 | (export "r" (type (sub resource))) 4 | (type $own-r (own 0)) 5 | (type $borrow-r (borrow 0)) 6 | (export "f" (func (param "r" $own-r))) 7 | (export "[method]r.foo" (func (param "self" $borrow-r))) 8 | ) 9 | ) 10 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/missing-ok-result-type.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import x: interface { 4 | f: func() -> result<_>; 5 | }; 6 | 7 | let i = new foo:bar { x }; 8 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/missing-ok-result-type.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × mismatched instantiation argument `x` 4 | ├─▶ mismatched type for export `f` 5 | ├─▶ mismatched type for function result 6 | ╰─▶ expected an `ok` for result type 7 | ╭─[tests/resolution/fail/missing-ok-result-type.wac:7:23] 8 | 6 │ 9 | 7 │ let i = new foo:bar { x }; 10 | · ┬ 11 | · ╰── mismatched argument `x` 12 | ╰──── 13 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/missing-ok-result-type/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (instance (import "x") 3 | (export "f" (func (result (result string)))) 4 | ) 5 | ) 6 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/missing-static-method.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import x: interface { 4 | resource r; 5 | f: func(r: r); 6 | }; 7 | 8 | let i = new foo:bar { x }; 9 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/missing-static-method.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × mismatched instantiation argument `x` 4 | ╰─▶ instance is missing expected function export `[static]r.foo` 5 | ╭─[tests/resolution/fail/missing-static-method.wac:8:23] 6 | 7 │ 7 | 8 │ let i = new foo:bar { x }; 8 | · ┬ 9 | · ╰── mismatched argument `x` 10 | ╰──── 11 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/missing-static-method/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (instance (import "x") 3 | (export "r" (type (sub resource))) 4 | (type $own-r (own 0)) 5 | (type $borrow-r (borrow 0)) 6 | (export "f" (func (param "r" $own-r))) 7 | (export "[static]r.foo" (func)) 8 | ) 9 | ) 10 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/missing-target-export.wac: -------------------------------------------------------------------------------- 1 | package test:comp targets foo:bar/baz; 2 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/missing-target-export.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × target world `foo:bar/baz` requires an export named `hello` 4 | ╭─[tests/resolution/fail/missing-target-export.wac:1:27] 5 | 1 │ package test:comp targets foo:bar/baz; 6 | · ─────┬───── 7 | · ╰── must export a function named `hello` to target this world 8 | ╰──── 9 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/missing-target-export/foo/bar/bar.wit: -------------------------------------------------------------------------------- 1 | package foo:bar; 2 | 3 | world baz { 4 | export hello: func() -> string; 5 | } 6 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/missing-type-in-use.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | interface a { 4 | 5 | } 6 | 7 | interface b { 8 | use a.{x}; 9 | } -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/missing-type-in-use.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × a type named `x` is not defined in interface `a` 4 | ╭─[tests/resolution/fail/missing-type-in-use.wac:8:12] 5 | 7 │ interface b { 6 | 8 │ use a.{x}; 7 | · ┬ 8 | · ╰── `x` is not a type in interface `a` 9 | 9 │ } 10 | ╰──── 11 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/missing-world-include-name.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | world w1 { 4 | 5 | } 6 | 7 | world w2 { 8 | include w1 with { a as b }; 9 | } -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/missing-world-include-name.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × world `w1` does not have an import or export named `a` 4 | ╭─[tests/resolution/fail/missing-world-include-name.wac:8:23] 5 | 7 │ world w2 { 6 | 8 │ include w1 with { a as b }; 7 | · ┬ 8 | · ╰── no import or export named `a` 9 | 9 │ } 10 | ╰──── 11 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/no-err-result-type.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import x: interface { 4 | f: func() -> result<_, string>; 5 | }; 6 | 7 | let i = new foo:bar { x }; 8 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/no-err-result-type.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × mismatched instantiation argument `x` 4 | ├─▶ mismatched type for export `f` 5 | ├─▶ mismatched type for function result 6 | ╰─▶ expected no `err` for result type 7 | ╭─[tests/resolution/fail/no-err-result-type.wac:7:23] 8 | 6 │ 9 | 7 │ let i = new foo:bar { x }; 10 | · ┬ 11 | · ╰── mismatched argument `x` 12 | ╰──── 13 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/no-err-result-type/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (instance (import "x") 3 | (export "f" (func (result (result)))) 4 | ) 5 | ) 6 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/no-import.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import x: interface {}; 4 | let i = new foo:bar { x }; 5 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/no-import.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × component `foo:bar` has no import named `x` 4 | ╭─[tests/resolution/fail/no-import.wac:4:23] 5 | 3 │ import x: interface {}; 6 | 4 │ let i = new foo:bar { x }; 7 | · ┬ 8 | · ╰── unknown import `x` 9 | ╰──── 10 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/no-import/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component) 2 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/no-ok-result-type.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import x: interface { 4 | f: func() -> result; 5 | }; 6 | 7 | let i = new foo:bar { x }; 8 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/no-ok-result-type.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × mismatched instantiation argument `x` 4 | ├─▶ mismatched type for export `f` 5 | ├─▶ mismatched type for function result 6 | ╰─▶ expected no `ok` for result type 7 | ╭─[tests/resolution/fail/no-ok-result-type.wac:7:23] 8 | 6 │ 9 | 7 │ let i = new foo:bar { x }; 10 | · ┬ 11 | · ╰── mismatched argument `x` 12 | ╰──── 13 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/no-ok-result-type/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (instance (import "x") 3 | (export "f" (func (result (result)))) 4 | ) 5 | ) 6 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/non-instance-spread.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import f: func(); 4 | 5 | let x = new foo:bar { ...f }; 6 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/non-instance-spread.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × an instance is required to perform a spread operation 4 | ╭─[tests/resolution/fail/non-instance-spread.wac:5:26] 5 | 4 │ 6 | 5 │ let x = new foo:bar { ...f }; 7 | · ┬ 8 | · ╰── this evaluated to a function when an instance was expected 9 | ╰──── 10 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/non-instance-spread/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component) 2 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/package-invalid-wasm.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import foo: foo:bar/qux; -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/package-invalid-wasm.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × failed to parse package `foo:bar` 4 | ╰─▶ unknown type 0: type index out of bounds (at offset 0xb) 5 | ╭─[tests/resolution/fail/package-invalid-wasm.wac:3:13] 6 | 2 │ 7 | 3 │ import foo: foo:bar/qux; 8 | · ───┬─── 9 | · ╰── package `foo:bar` failed to parse 10 | ╰──── 11 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/package-invalid-wasm/foo/bar.wasm: -------------------------------------------------------------------------------- 1 | asm  t -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/package-not-component.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import foo: foo:bar/qux; -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/package-not-component.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × failed to parse package `foo:bar` 4 | ╰─▶ package `foo:bar` is not a binary-encoded WebAssembly component 5 | ╭─[tests/resolution/fail/package-not-component.wac:3:13] 6 | 2 │ 7 | 3 │ import foo: foo:bar/qux; 8 | · ───┬─── 9 | · ╰── package `foo:bar` failed to parse 10 | ╰──── 11 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/package-not-component/foo/bar.wasm: -------------------------------------------------------------------------------- 1 | asm -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/package-not-wasm.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import foo: foo:bar/qux; -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/package-not-wasm.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × failed to parse package `foo:bar` 4 | ╰─▶ package `foo:bar` is not a binary-encoded WebAssembly component 5 | ╭─[tests/resolution/fail/package-not-wasm.wac:3:13] 6 | 2 │ 7 | 3 │ import foo: foo:bar/qux; 8 | · ───┬─── 9 | · ╰── package `foo:bar` failed to parse 10 | ╰──── 11 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/package-not-wasm/foo/bar.wasm: -------------------------------------------------------------------------------- 1 | this is not a wasm file 2 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/redefined-name.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | type x = u32; 4 | type x = string; -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/redefined-name.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × type declaration `x` conflicts with a previous export of the same name 4 | ╭─[tests/resolution/fail/redefined-name.wac:4:6] 5 | 2 │ 6 | 3 │ type x = u32; 7 | · ┬ 8 | · ╰── previous export is here 9 | 4 │ type x = string; 10 | · ┬ 11 | · ╰── conflicting type declaration `x` 12 | ╰──── 13 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/self-instantiation.wac: -------------------------------------------------------------------------------- 1 | package foo:bar; 2 | 3 | let i = new foo:bar {}; 4 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/self-instantiation.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × cannot instantiate the package being defined 4 | ╭─[tests/resolution/fail/self-instantiation.wac:3:13] 5 | 2 │ 6 | 3 │ let i = new foo:bar {}; 7 | · ───┬─── 8 | · ╰── cannot instantiate self 9 | ╰──── 10 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/spread-export-no-effect.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import i: interface {}; 4 | 5 | export i...; 6 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/spread-export-no-effect.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × instance has no exports or all exports of the instance match previously exported names 4 | ╭─[tests/resolution/fail/spread-export-no-effect.wac:5:8] 5 | 4 │ 6 | 5 │ export i...; 7 | · ┬ 8 | · ╰── spreading the exports of this instance has no effect 9 | ╰──── 10 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/spread-instantiation-no-match.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import i: interface { 4 | }; 5 | 6 | let x = new foo:bar { ...i }; 7 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/spread-instantiation-no-match.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × the instance has no matching exports for the remaining unsatisfied arguments 4 | ╭─[tests/resolution/fail/spread-instantiation-no-match.wac:6:26] 5 | 5 │ 6 | 6 │ let x = new foo:bar { ...i }; 7 | · ┬ 8 | · ╰── no matching exports for the instance 9 | ╰──── 10 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/spread-instantiation-no-match/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component) 2 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/target-export-mismatch.wac: -------------------------------------------------------------------------------- 1 | package test:comp targets test:comp/world; 2 | 3 | world %world { 4 | import foo: interface { 5 | foo: func(x: u32); 6 | }; 7 | export foo: interface { 8 | foo: func(x: string); 9 | }; 10 | } 11 | 12 | import foo: interface { 13 | foo: func(x: u32); 14 | }; 15 | export foo; 16 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/target-export-mismatch.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × export `foo` has a mismatched type for target world `test:comp/world` 4 | ├─▶ mismatched type for export `foo` 5 | ├─▶ mismatched type for function parameter `x` 6 | ╰─▶ expected string, found u32 7 | ╭─[tests/resolution/fail/target-export-mismatch.wac:15:8] 8 | 14 │ }; 9 | 15 │ export foo; 10 | · ─┬─ 11 | · ╰── mismatched type for export `foo` 12 | ╰──── 13 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/target-extraneous-import.wac: -------------------------------------------------------------------------------- 1 | package test:comp targets test:comp/foo; 2 | 3 | world foo { 4 | import foo: func(); 5 | } 6 | 7 | import bar: func(); 8 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/target-extraneous-import.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × target world `test:comp/foo` does not have an import named `bar` 4 | ╭─[tests/resolution/fail/target-extraneous-import.wac:7:8] 5 | 6 │ 6 | 7 │ import bar: func(); 7 | · ─┬─ 8 | · ╰── cannot have an import named `bar` 9 | ╰──── 10 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/target-import-mismatch-resource.wac: -------------------------------------------------------------------------------- 1 | package test:comp targets test:comp/foo; 2 | 3 | world foo { 4 | import foo: interface { 5 | resource x { 6 | constructor(); 7 | } 8 | }; 9 | } 10 | 11 | import foo2 as foo: interface { 12 | resource y { 13 | constructor(); 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/target-import-mismatch-resource.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × import `foo` has a mismatched type for target world `test:comp/foo` 4 | ╰─▶ instance has unexpected resource export `y` 5 | ╭─[tests/resolution/fail/target-import-mismatch-resource.wac:11:16] 6 | 10 │ 7 | 11 │ import foo2 as foo: interface { 8 | · ─┬─ 9 | · ╰── mismatched type for import `foo` 10 | 12 │ resource y { 11 | ╰──── 12 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/target-import-mismatch.wac: -------------------------------------------------------------------------------- 1 | package test:comp targets test:comp/foo; 2 | 3 | world foo { 4 | import foo: func(); 5 | } 6 | 7 | import foo2 as foo: interface { 8 | 9 | }; 10 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/target-import-mismatch.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × import `foo` has a mismatched type for target world `test:comp/foo` 4 | ╰─▶ expected function, found instance 5 | ╭─[tests/resolution/fail/target-import-mismatch.wac:7:16] 6 | 6 │ 7 | 7 │ import foo2 as foo: interface { 8 | · ─┬─ 9 | · ╰── mismatched type for import `foo` 10 | 8 │ 11 | ╰──── 12 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/target-import-param-name-mismatch.wac: -------------------------------------------------------------------------------- 1 | package test:comp targets test:comp/foo; 2 | 3 | world foo { 4 | import foo: interface { 5 | foo: func(a: string); 6 | }; 7 | } 8 | 9 | import foo2 as foo: interface { 10 | foo: func(x: u32); 11 | }; 12 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/target-import-param-name-mismatch.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × import `foo` has a mismatched type for target world `test:comp/foo` 4 | ├─▶ mismatched type for export `foo` 5 | ╰─▶ expected function parameter 0 to be named `a`, found name `x` 6 | ╭─[tests/resolution/fail/target-import-param-name-mismatch.wac:9:16] 7 | 8 │ 8 | 9 │ import foo2 as foo: interface { 9 | · ─┬─ 10 | · ╰── mismatched type for import `foo` 11 | 10 │ foo: func(x: u32); 12 | ╰──── 13 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/target-import-param-type-mismatch.wac: -------------------------------------------------------------------------------- 1 | package test:comp targets test:comp/foo; 2 | 3 | world foo { 4 | import foo: interface { 5 | foo: func(a: u32); 6 | }; 7 | } 8 | 9 | import foo2 as foo: interface { 10 | foo: func(a: string); 11 | }; 12 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/target-import-param-type-mismatch.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × import `foo` has a mismatched type for target world `test:comp/foo` 4 | ├─▶ mismatched type for export `foo` 5 | ├─▶ mismatched type for function parameter `a` 6 | ╰─▶ expected u32, found string 7 | ╭─[tests/resolution/fail/target-import-param-type-mismatch.wac:9:16] 8 | 8 │ 9 | 9 │ import foo2 as foo: interface { 10 | · ─┬─ 11 | · ╰── mismatched type for import `foo` 12 | 10 │ foo: func(a: string); 13 | ╰──── 14 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/target-import-unexpected-method.wac: -------------------------------------------------------------------------------- 1 | package test:comp targets test:comp/foo; 2 | 3 | world foo { 4 | import foo: interface { 5 | resource x { 6 | constructor(); 7 | } 8 | }; 9 | } 10 | 11 | import foo2 as foo: interface { 12 | resource x { 13 | constructor(); 14 | f: func(a: u32); 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/target-import-unexpected-method.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × import `foo` has a mismatched type for target world `test:comp/foo` 4 | ╰─▶ instance has unexpected function export `[method]x.f` 5 | ╭─[tests/resolution/fail/target-import-unexpected-method.wac:11:16] 6 | 10 │ 7 | 11 │ import foo2 as foo: interface { 8 | · ─┬─ 9 | · ╰── mismatched type for import `foo` 10 | 12 │ resource x { 11 | ╰──── 12 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/target-is-not-a-world.wac: -------------------------------------------------------------------------------- 1 | package test:comp targets test:comp/foo; 2 | 3 | interface foo { 4 | } -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/target-is-not-a-world.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × `test:comp/foo` (interface) is not a world 4 | ╭─[tests/resolution/fail/target-is-not-a-world.wac:1:27] 5 | 1 │ package test:comp targets test:comp/foo; 6 | · ──────┬────── 7 | · ╰── `test:comp/foo` is not a world 8 | 2 │ 9 | ╰──── 10 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/targets-interface-use.wac: -------------------------------------------------------------------------------- 1 | package test:comp targets test:comp/foo; 2 | 3 | interface indirect-dependency { 4 | variant my-variant { 5 | foo, 6 | // Extra variant that the instance does not have 7 | bar 8 | } 9 | } 10 | 11 | interface direct-dependency { 12 | use indirect-dependency.{my-variant}; 13 | 14 | fun: func() -> my-variant; 15 | } 16 | 17 | world foo { 18 | import direct-dependency; 19 | } 20 | 21 | 22 | let i = new foo:bar { ... }; 23 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/targets-interface-use.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × import `test:comp/indirect-dependency` has a mismatched type for target world `test:comp/foo` 4 | ├─▶ mismatched type for export `my-variant` 5 | ╰─▶ expected a variant case count of 2, found a count of 1 6 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/targets-interface-use/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (type (;0;) 3 | (instance 4 | (type (;0;) (variant (case "foo"))) 5 | (export (;1;) "my-variant" (type (eq 0))) 6 | ) 7 | ) 8 | (import "test:comp/indirect-dependency" (instance (;0;) (type 0))) 9 | (alias export 0 "my-variant" (type (;1;))) 10 | (type (;2;) 11 | (instance 12 | (alias outer 1 1 (type (;0;))) 13 | (export (;1;) "my-variant" (type (eq 0))) 14 | (type (;2;) (func (result 1))) 15 | (export (;0;) "fun" (func (type 2))) 16 | ) 17 | ) 18 | (import "test:comp/direct-dependency" (instance (;1;) (type 2))) 19 | ) 20 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/targets-world-use.wac: -------------------------------------------------------------------------------- 1 | package test:comp targets test:comp/foo; 2 | 3 | interface indirect-dependency { 4 | // The resource is actually named "other-resource" in the instance 5 | resource my-resource {} 6 | } 7 | 8 | world foo { 9 | use indirect-dependency.{my-resource}; 10 | import my-func: func() -> my-resource; 11 | } 12 | 13 | let i = new foo:bar { ... }; 14 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/targets-world-use.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × import `test:comp/indirect-dependency` has a mismatched type for target world `test:comp/foo` 4 | ╰─▶ instance has unexpected resource export `other-resource` 5 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/targets-world-use/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (type (;0;) 3 | (instance 4 | (export (;0;) "other-resource" (type (sub resource))) 5 | ) 6 | ) 7 | (import "test:comp/indirect-dependency" (instance (;0;) (type 0))) 8 | (alias export 0 "other-resource" (type (;1;))) 9 | (import "my-resource" (type (;2;) (eq 1))) 10 | (type (;3;) (own 2)) 11 | (type (;4;) (func (result 3))) 12 | (import "my-func" (func (;0;) (type 4))) 13 | (alias export 0 "other-resource" (type (;5;))) 14 | ) 15 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/type-decl-conflict.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import foo: func(); 4 | export foo as i; 5 | 6 | interface i { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/type-decl-conflict.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × type declaration `i` conflicts with a previous export of the same name 4 | ╭─[tests/resolution/fail/type-decl-conflict.wac:6:11] 5 | 3 │ import foo: func(); 6 | 4 │ export foo as i; 7 | · ┬ 8 | · ╰── previous export is here 9 | 5 │ 10 | 6 │ interface i { 11 | · ┬ 12 | · ╰── conflicting type declaration `i` 13 | 7 │ 14 | ╰──── 15 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/undefined-name.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | type x = x; -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/undefined-name.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × undefined name `x` 4 | ╭─[tests/resolution/fail/undefined-name.wac:3:10] 5 | 2 │ 6 | 3 │ type x = x; 7 | · ┬ 8 | · ╰── undefined name `x` 9 | ╰──── 10 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/unknown-package.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import foo: bar:baz/qux; -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/unknown-package.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × unknown package `bar:baz` 4 | ╭─[tests/resolution/fail/unknown-package.wac:3:13] 5 | 2 │ 6 | 3 │ import foo: bar:baz/qux; 7 | · ───┬─── 8 | · ╰── unknown package `bar:baz` 9 | ╰──── 10 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/unknown-target-path.wac: -------------------------------------------------------------------------------- 1 | package test:comp targets foo:bar/baz; 2 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/unknown-target-path.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × unknown package `foo:bar` 4 | ╭─[tests/resolution/fail/unknown-target-path.wac:1:27] 5 | 1 │ package test:comp targets foo:bar/baz; 6 | · ───┬─── 7 | · ╰── unknown package `foo:bar` 8 | ╰──── 9 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/unknown-targets-path.wac: -------------------------------------------------------------------------------- 1 | package test:comp targets test:comp/foo; 2 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/unknown-targets-path.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × undefined name `foo` 4 | ╭─[tests/resolution/fail/unknown-targets-path.wac:1:37] 5 | 1 │ package test:comp targets test:comp/foo; 6 | · ─┬─ 7 | · ╰── undefined name `foo` 8 | ╰──── 9 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/variant-case-typed.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import x: interface { 4 | variant v { 5 | a, 6 | b, 7 | c(tuple), 8 | } 9 | }; 10 | 11 | let i = new foo:bar { x }; 12 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/variant-case-typed.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × mismatched instantiation argument `x` 4 | ├─▶ mismatched type for export `v` 5 | ╰─▶ expected variant case `b` to be typed, found an untyped case 6 | ╭─[tests/resolution/fail/variant-case-typed.wac:11:23] 7 | 10 │ 8 | 11 │ let i = new foo:bar { x }; 9 | · ┬ 10 | · ╰── mismatched argument `x` 11 | ╰──── 12 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/variant-case-typed/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (instance (import "x") 3 | (type $v (variant (case "a") (case "b" u16) (case "c" (tuple string u16)))) 4 | (export "v" (type (eq $v))) 5 | ) 6 | ) 7 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/variant-case-untyped.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | import x: interface { 4 | variant v { 5 | a(string), 6 | b(u16), 7 | c(tuple), 8 | } 9 | }; 10 | 11 | let i = new foo:bar { x }; 12 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/variant-case-untyped.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × mismatched instantiation argument `x` 4 | ├─▶ mismatched type for export `v` 5 | ╰─▶ expected variant case `a` to be untyped, found a typed case 6 | ╭─[tests/resolution/fail/variant-case-untyped.wac:11:23] 7 | 10 │ 8 | 11 │ let i = new foo:bar { x }; 9 | · ┬ 10 | · ╰── mismatched argument `x` 11 | ╰──── 12 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/variant-case-untyped/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (instance (import "x") 3 | (type $v (variant (case "a") (case "b" u16) (case "c" (tuple string u16)))) 4 | (export "v" (type (eq $v))) 5 | ) 6 | ) 7 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/windows-file.wac: -------------------------------------------------------------------------------- 1 | package foo:bar; 2 | 3 | import x: func(); 4 | import x: func(); 5 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/windows-file.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × duplicate import `x` 4 | ╭─[tests/resolution/fail/windows-file.wac:4:8] 5 | 2 │ 6 | 3 │ import x: func(); 7 | · ┬ 8 | · ╰── previous import here 9 | 4 │ import x: func(); 10 | · ┬ 11 | · ╰── duplicate import name `x` 12 | ╰──── 13 | help: consider using an `as` clause to use a different name 14 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/world-include-conflict.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | world w1 { 4 | export a: func(); 5 | } 6 | 7 | world w2 { 8 | include w1; 9 | export a: interface { 10 | 11 | }; 12 | } -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/world-include-conflict.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × export `a` from world `w1` conflicts with export of the same name in world `w2` 4 | ╭─[tests/resolution/fail/world-include-conflict.wac:8:13] 5 | 7 │ world w2 { 6 | 8 │ include w1; 7 | · ─┬ 8 | · ╰── conflicting name `a` 9 | 9 │ export a: interface { 10 | ╰──── 11 | help: consider using a `with` clause to use a different name 12 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/world-include-with-conflict.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | world w1 { 4 | export a: func(); 5 | } 6 | 7 | world w2 { 8 | include w1 with { a as x }; 9 | export x: interface { 10 | 11 | }; 12 | } -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/fail/world-include-with-conflict.wac.result: -------------------------------------------------------------------------------- 1 | failed to resolve document 2 | 3 | × export `x` from world `w1` conflicts with export of the same name in world `w2` 4 | ╭─[tests/resolution/fail/world-include-with-conflict.wac:8:28] 5 | 7 │ world w2 { 6 | 8 │ include w1 with { a as x }; 7 | · ┬ 8 | · ╰── conflicting name `x` 9 | 9 │ export x: interface { 10 | ╰──── 11 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/import.wac: -------------------------------------------------------------------------------- 1 | package test:comp@0.0.1-beta; 2 | 3 | /// Import by func type 4 | import a: func(); 5 | 6 | /// Import by ident 7 | type x = func(); 8 | import b: x; 9 | 10 | /// Import by package path 11 | //import c: foo:bar/baz; 12 | 13 | /// Import by func type with kebab name 14 | import d as "hello-world": func(name: string); 15 | 16 | /// Import by inline interface 17 | import e: interface { 18 | x: func(); 19 | }; 20 | 21 | /// Import by package path with version 22 | import f: foo:bar/baz; 23 | 24 | export d; 25 | export e as "e"; 26 | export f; -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/import.wac.result: -------------------------------------------------------------------------------- 1 | digraph { 2 | 0 [ label = "import \"a\""; kind = "function"] 3 | 1 [ label = "type definition \"x\""; kind = "function type"; export = "x"] 4 | 2 [ label = "import \"b\""; kind = "function"] 5 | 3 [ label = "import \"hello-world\""; kind = "function"; export = "hello-world"] 6 | 4 [ label = "import \"e\""; kind = "instance"; export = "e"] 7 | 5 [ label = "import \"foo:bar/baz\""; kind = "instance"; export = "foo:bar/baz"] 8 | } 9 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/import/foo/bar/package.wit: -------------------------------------------------------------------------------- 1 | package foo:bar; 2 | 3 | interface baz { 4 | } -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/let-statements.wac: -------------------------------------------------------------------------------- 1 | package test:comp@1.0.0; 2 | 3 | import streams: wasi:io/streams; 4 | 5 | let i = new foo:bar { streams, baz: new foo:bar { streams, ... }.baz }; 6 | 7 | export i.baz; 8 | export i as "i"; 9 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/let-statements.wac.result: -------------------------------------------------------------------------------- 1 | digraph { 2 | 0 [ label = "import \"wasi:io/streams\""; kind = "instance"] 3 | 1 [ label = "instantiation of package \"foo:bar\""; kind = "instance"] 4 | 2 [ label = "alias of export \"foo:bar/baz@0.1.0\""; kind = "instance"] 5 | 3 [ label = "instantiation of package \"foo:bar\""; kind = "instance"; export = "i"] 6 | 4 [ label = "alias of export \"foo:bar/baz@0.1.0\""; kind = "instance"; export = "foo:bar/baz@0.1.0"] 7 | 0 -> 1 [ label = "argument to" ] 8 | 1 -> 2 [ label = "aliased export" ] 9 | 0 -> 3 [ label = "argument to" ] 10 | 2 -> 3 [ label = "argument to" ] 11 | 3 -> 4 [ label = "aliased export" ] 12 | } 13 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/let-statements/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (type 3 | (instance 4 | (export (;0;) "output-stream" (type (sub resource))) 5 | (type (;2;) (own 0)) 6 | (type (;3;) (enum "last-operation-failed" "closed")) 7 | (export (;4;) "write-error" (type (eq 2))) 8 | (export (;5;) "input-stream" (type (sub resource))) 9 | (type (;6;) (borrow 0)) 10 | (type (;7;) (result u64 (error 3))) 11 | (type (;8;) (func (param "self" 5) (result 6))) 12 | (export (;0;) "[method]output-stream.check-write" (func (type 7))) 13 | (type (;9;) (list u8)) 14 | (type (;10;) (result (error 3))) 15 | (type (;11;) (func (param "self" 5) (param "contents" 8) (result 9))) 16 | (export (;1;) "[method]output-stream.write" (func (type 10))) 17 | (export (;2;) "[method]output-stream.blocking-write-and-flush" (func (type 10))) 18 | (type (;12;) (func (param "self" 5) (result 9))) 19 | (export (;3;) "[method]output-stream.blocking-flush" (func (type 11))) 20 | ) 21 | ) 22 | (import (interface "wasi:io/streams@0.2.0-rc-2023-10-18") (instance (type 0))) 23 | (type 24 | (instance 25 | (export "f" (func)) 26 | ) 27 | ) 28 | (import (interface "foo:bar/baz@0.1.0") (instance (type 1))) 29 | (export (interface "foo:bar/baz@0.1.0") (instance 1)) 30 | ) -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/no-imports.wac: -------------------------------------------------------------------------------- 1 | package test:comp@0.3.0; 2 | 3 | let i = new foo:bar {}; 4 | 5 | export i as "i"; 6 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/no-imports.wac.result: -------------------------------------------------------------------------------- 1 | digraph { 2 | 0 [ label = "instantiation of package \"foo:bar\""; kind = "instance"; export = "i"] 3 | } 4 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/no-imports/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component) -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/package-import.wac: -------------------------------------------------------------------------------- 1 | package test:comp@1.0.0; 2 | 3 | import i: foo:bar/i; 4 | 5 | export i; 6 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/package-import.wac.result: -------------------------------------------------------------------------------- 1 | digraph { 2 | 0 [ label = "import \"foo:bar/i\""; kind = "instance"; export = "foo:bar/i"] 3 | } 4 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/package-import/foo/bar/package.wit: -------------------------------------------------------------------------------- 1 | package foo:bar; 2 | 3 | interface i { 4 | type x = string; 5 | 6 | resource r { 7 | x: func(r: r); 8 | } 9 | 10 | y: func(r: borrow); 11 | } -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/package-use-item.wac: -------------------------------------------------------------------------------- 1 | package test:comp@0.0.1; 2 | 3 | interface i { 4 | use foo:bar/baz.{a, b, c}; 5 | } 6 | 7 | world w { 8 | use foo:bar/qux.{x, y, z}; 9 | } 10 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/package-use-item.wac.result: -------------------------------------------------------------------------------- 1 | digraph { 2 | 0 [ label = "type definition \"i\""; kind = "interface"; export = "i"] 3 | 1 [ label = "type definition \"w\""; kind = "world"; export = "w"] 4 | } 5 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/package-use-item/foo/bar/package.wit: -------------------------------------------------------------------------------- 1 | package foo:bar; 2 | 3 | interface baz { 4 | type a = u8; 5 | type b = s64; 6 | type c = string; 7 | } 8 | 9 | interface qux { 10 | resource x; 11 | type y = borrow; 12 | use baz.{c as z}; 13 | } 14 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/package-world-include.wac: -------------------------------------------------------------------------------- 1 | package test:comp@1.2.3-prerelease; 2 | 3 | world w { 4 | include foo:bar/baz; 5 | } -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/package-world-include.wac.result: -------------------------------------------------------------------------------- 1 | digraph { 2 | 0 [ label = "type definition \"w\""; kind = "world"; export = "w"] 3 | } 4 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/package-world-include/foo/bar/package.wit: -------------------------------------------------------------------------------- 1 | package foo:bar; 2 | 3 | interface i { 4 | resource x { 5 | constructor(); 6 | a: func(); 7 | b: static func(); 8 | } 9 | } 10 | 11 | world baz { 12 | use i.{x}; 13 | import i; 14 | export i; 15 | } -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/package-world-item.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | world w { 4 | import foo:bar/baz; 5 | export bar:baz/qux; 6 | } 7 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/package-world-item.wac.result: -------------------------------------------------------------------------------- 1 | digraph { 2 | 0 [ label = "type definition \"w\""; kind = "world"; export = "w"] 3 | } 4 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/package-world-item/bar/baz/package.wit: -------------------------------------------------------------------------------- 1 | package bar:baz; 2 | 3 | interface qux { 4 | type x = string; 5 | } -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/package-world-item/foo/bar/package.wit: -------------------------------------------------------------------------------- 1 | package foo:bar; 2 | 3 | interface baz { 4 | resource z { 5 | constructor(); 6 | } 7 | 8 | x: func(); 9 | } -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/resource.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | interface foo { 4 | resource x; 5 | type f = func(x: borrow); 6 | f2: f; 7 | 8 | type x2 = x; 9 | f3: func(x: x, x2: x2, x3: borrow, x4: borrow); 10 | } 11 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/resource.wac.result: -------------------------------------------------------------------------------- 1 | digraph { 2 | 0 [ label = "type definition \"foo\""; kind = "interface"; export = "foo"] 3 | } 4 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/targets-empty-world.wac: -------------------------------------------------------------------------------- 1 | package test:comp targets test:comp/foo; 2 | 3 | world foo { 4 | } 5 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/targets-empty-world.wac.result: -------------------------------------------------------------------------------- 1 | digraph { 2 | 0 [ label = "type definition \"foo\""; kind = "world"; export = "foo"] 3 | } 4 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/targets-world.wac: -------------------------------------------------------------------------------- 1 | package test:comp targets test:comp/world; 2 | 3 | world %world { 4 | import f: func(); 5 | export i: interface { 6 | f: func(); 7 | }; 8 | } 9 | 10 | import f: func(); 11 | 12 | export new foo:bar { f } as i; 13 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/targets-world.wac.result: -------------------------------------------------------------------------------- 1 | digraph { 2 | 0 [ label = "type definition \"world\""; kind = "world"; export = "world"] 3 | 1 [ label = "import \"f\""; kind = "function"] 4 | 2 [ label = "instantiation of package \"foo:bar\""; kind = "instance"; export = "i"] 5 | 1 -> 2 [ label = "argument to" ] 6 | } 7 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/targets-world/foo/bar.wat: -------------------------------------------------------------------------------- 1 | (component 2 | (import "f" (func)) 3 | (export "f" (func 0)) 4 | ) -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/types.wac: -------------------------------------------------------------------------------- 1 | package test:comp; 2 | 3 | /// Defining an interface 4 | interface i { 5 | /// Type alias a 6 | type a = func(); 7 | /// Record type 8 | record r { 9 | x: u32 10 | } 11 | /// Export func 12 | x: func(); 13 | /// Export func of type a 14 | y: a; 15 | } 16 | 17 | /// Defining a second interface 18 | interface i2 { 19 | /// Use type r from i 20 | use i.{r}; 21 | 22 | /// Use type r from i as z 23 | use i.{r as z}; 24 | } 25 | 26 | type c = func(); 27 | type f = c; 28 | 29 | /// Defining a world 30 | world w1 { 31 | /// Use type r from foo:bar/i 32 | use foo:bar/i.{r}; 33 | 34 | /// Import a function 35 | import a: func(); 36 | /// Import an interface 37 | import i; 38 | /// Import by name with type `c` 39 | import c: c; 40 | 41 | /// Export an inline interface 42 | export d: interface { 43 | x: func(); 44 | }; 45 | /// Export an interface 46 | export i2; 47 | /// Export by name with type `f` 48 | export f: f; 49 | } 50 | 51 | /// Defining a second world 52 | world w2 { 53 | /// Include the first world 54 | include w1; 55 | 56 | /// Include a world by path 57 | include foo:bar/baz; 58 | 59 | /// Defining a resource 60 | 61 | resource res { 62 | constructor(); 63 | } 64 | } 65 | 66 | type x = u32; 67 | 68 | /// Defining a variant 69 | variant v { 70 | a(x), 71 | b(string), 72 | c(u32), 73 | d, 74 | } 75 | 76 | /// Defining a record 77 | record r { 78 | x: u32, 79 | y: string, 80 | z: v, 81 | } 82 | 83 | /// Defining flags 84 | flags %flags { 85 | a, 86 | b, 87 | c, 88 | } 89 | 90 | /// Defining an enum 91 | enum e { 92 | a, 93 | b, 94 | c, 95 | } 96 | 97 | /// Type aliases 98 | type t = e; 99 | type t2 = string; 100 | type t3 = func(a: u32, b: r) -> u32; 101 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/types.wac.result: -------------------------------------------------------------------------------- 1 | digraph { 2 | 0 [ label = "type definition \"i\""; kind = "interface"; export = "i"] 3 | 1 [ label = "type definition \"i2\""; kind = "interface"; export = "i2"] 4 | 2 [ label = "type definition \"c\""; kind = "function type"; export = "c"] 5 | 3 [ label = "type definition \"f\""; kind = "function type"; export = "f"] 6 | 4 [ label = "type definition \"w1\""; kind = "world"; export = "w1"] 7 | 5 [ label = "type definition \"w2\""; kind = "world"; export = "w2"] 8 | 6 [ label = "type definition \"x\""; kind = "u32"; export = "x"] 9 | 7 [ label = "type definition \"v\""; kind = "variant"; export = "v"] 10 | 8 [ label = "type definition \"r\""; kind = "record"; export = "r"] 11 | 9 [ label = "type definition \"flags\""; kind = "flags"; export = "flags"] 12 | 10 [ label = "type definition \"e\""; kind = "enum"; export = "e"] 13 | 11 [ label = "type definition \"t\""; kind = "enum"; export = "t"] 14 | 12 [ label = "type definition \"t2\""; kind = "string"; export = "t2"] 15 | 13 [ label = "type definition \"t3\""; kind = "function type"; export = "t3"] 16 | 6 -> 7 [ label = "dependency of" ] 17 | 7 -> 8 [ label = "dependency of" ] 18 | 8 -> 13 [ label = "dependency of" ] 19 | } 20 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/resolution/types/foo/bar/package.wit: -------------------------------------------------------------------------------- 1 | package foo:bar; 2 | 3 | interface i { 4 | resource r; 5 | } 6 | 7 | world baz { 8 | } 9 | -------------------------------------------------------------------------------- /crates/wac-parser/tests/support/mod.rs: -------------------------------------------------------------------------------- 1 | use miette::{GraphicalReportHandler, GraphicalTheme, NamedSource, Report}; 2 | use std::path::Path; 3 | 4 | pub fn fmt_err(e: impl Into, path: &Path, source: &str) -> String { 5 | let mut s = String::new(); 6 | let e = e.into(); 7 | GraphicalReportHandler::new() 8 | .with_cause_chain() 9 | .with_theme(GraphicalTheme::unicode_nocolor()) 10 | .render_report( 11 | &mut s, 12 | e.with_source_code(NamedSource::new(path.to_string_lossy(), source.to_string())) 13 | .as_ref(), 14 | ) 15 | .expect("failed to render diagnostic"); 16 | s 17 | } 18 | -------------------------------------------------------------------------------- /crates/wac-resolver/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "wac-resolver" 3 | description = "A library for package resolvers for WAC document resolution." 4 | version = { workspace = true } 5 | edition = { workspace = true } 6 | authors = { workspace = true } 7 | license = { workspace = true } 8 | categories = { workspace = true } 9 | keywords = { workspace = true } 10 | repository = { workspace = true } 11 | 12 | [dependencies] 13 | wac-types = { workspace = true } 14 | wac-parser = { workspace = true } 15 | semver = { workspace = true } 16 | thiserror = { workspace = true } 17 | anyhow = { workspace = true } 18 | log = { workspace = true } 19 | wit-component = { workspace = true } 20 | indexmap = { workspace = true } 21 | wat = { workspace = true, optional = true } 22 | wit-parser = { workspace = true, optional = true } 23 | miette = { workspace = true } 24 | warg-client = { workspace = true, optional = true } 25 | warg-protocol = { workspace = true, optional = true } 26 | warg-crypto = { workspace = true, optional = true } 27 | tokio = { workspace = true, optional = true } 28 | futures = { workspace = true, optional = true } 29 | 30 | [dev-dependencies] 31 | wac-graph = { workspace = true } 32 | wasmprinter = { workspace = true } 33 | warg-server = { workspace = true } 34 | pretty_assertions = { workspace = true } 35 | tokio-util = "0.7.10" 36 | tempdir = "0.3.7" 37 | tempfile = "3.2.0" 38 | 39 | [features] 40 | default = ["registry"] 41 | wat = ["dep:wat"] 42 | wit = ["dep:wit-parser"] 43 | registry = [ 44 | "dep:warg-client", 45 | "dep:warg-protocol", 46 | "dep:warg-crypto", 47 | "dep:tokio", 48 | "dep:futures", 49 | ] 50 | -------------------------------------------------------------------------------- /crates/wac-types/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "wac-types" 3 | description = "A library for the definition of WebAssembly component model types." 4 | version = { workspace = true } 5 | edition = { workspace = true } 6 | authors = { workspace = true } 7 | license = { workspace = true } 8 | categories = { workspace = true } 9 | keywords = { workspace = true } 10 | repository = { workspace = true } 11 | 12 | [dependencies] 13 | anyhow = { workspace = true } 14 | id-arena = { workspace = true } 15 | indexmap = { workspace = true } 16 | semver = { workspace = true } 17 | serde = { workspace = true, optional = true } 18 | wasmparser = { workspace = true } 19 | wasm-encoder = { workspace = true } 20 | 21 | [features] 22 | serde = ["dep:serde"] 23 | -------------------------------------------------------------------------------- /crates/wac-types/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! A library for the definition of WebAssembly component model types. 2 | 3 | #![deny(missing_docs)] 4 | 5 | mod aggregator; 6 | mod checker; 7 | mod component; 8 | mod core; 9 | mod package; 10 | mod targets; 11 | 12 | pub use aggregator::*; 13 | pub use checker::*; 14 | pub use component::*; 15 | pub use core::*; 16 | pub use package::*; 17 | pub use targets::*; 18 | -------------------------------------------------------------------------------- /examples/deps/example/greeter.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bytecodealliance/wac/9de558adfaee43d29b792bcef8a13e480cc2717d/examples/deps/example/greeter.wasm -------------------------------------------------------------------------------- /examples/deps/example/hello.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bytecodealliance/wac/9de558adfaee43d29b792bcef8a13e480cc2717d/examples/deps/example/hello.wasm -------------------------------------------------------------------------------- /examples/programmatic/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "programmatic-example" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | [dependencies] 7 | wac-graph = { path = "../../crates/wac-graph" } 8 | -------------------------------------------------------------------------------- /examples/programmatic/src/main.rs: -------------------------------------------------------------------------------- 1 | use wac_graph::{types::Package, CompositionGraph, EncodeOptions}; 2 | 3 | fn main() { 4 | let mut graph = CompositionGraph::new(); 5 | 6 | // Register the package dependencies into the graph 7 | let package = Package::from_file( 8 | "hello", 9 | None, 10 | "../deps/example/hello.wasm", 11 | graph.types_mut(), 12 | ) 13 | .unwrap(); 14 | let hello = graph.register_package(package).unwrap(); 15 | let package = Package::from_file( 16 | "greeter", 17 | None, 18 | "../deps/example/greeter.wasm", 19 | graph.types_mut(), 20 | ) 21 | .unwrap(); 22 | let greeter = graph.register_package(package).unwrap(); 23 | 24 | // Instantiate the hello instance which does not have any arguments 25 | let hello_instance = graph.instantiate(hello); 26 | 27 | // Instantiate the greeter instance which has a single argument "hello" which is exported by the hello instance 28 | let greeter_instance = graph.instantiate(greeter); 29 | let hello_export = graph 30 | .alias_instance_export(hello_instance, "hello") 31 | .unwrap(); 32 | graph 33 | .set_instantiation_argument(greeter_instance, "hello", hello_export) 34 | .unwrap(); 35 | 36 | // Alias the "greet" export from the greeter instance 37 | let greet_export = graph 38 | .alias_instance_export(greeter_instance, "greet") 39 | .unwrap(); 40 | // Export the "greet" function from the composition 41 | graph.export(greet_export, "greet").unwrap(); 42 | 43 | // Encode the graph into a WASM binary 44 | let encoding = graph.encode(EncodeOptions::default()).unwrap(); 45 | std::fs::write("composition.wasm", encoding).unwrap(); 46 | } 47 | -------------------------------------------------------------------------------- /examples/script.wac: -------------------------------------------------------------------------------- 1 | package example:composition; 2 | 3 | // Instantiate the `hello` component 4 | let hello = new example:hello {}; 5 | 6 | // Instantiate the `greeter` component plugging its one `hello` import with 7 | // the `hello` export of the `hello` component. 8 | let greeter = new example:greeter { 9 | hello: hello.hello, 10 | }; 11 | 12 | // Export the greet function from the greeter component 13 | export greeter.greet; 14 | -------------------------------------------------------------------------------- /src/bin/wac.rs: -------------------------------------------------------------------------------- 1 | use anyhow::Result; 2 | use clap::Parser; 3 | use owo_colors::{OwoColorize, Stream, Style}; 4 | use wac_cli::commands::{ 5 | ComposeCommand, ParseCommand, PlugCommand, ResolveCommand, TargetsCommand, 6 | }; 7 | 8 | fn version() -> &'static str { 9 | option_env!("CARGO_VERSION_INFO").unwrap_or(env!("CARGO_PKG_VERSION")) 10 | } 11 | 12 | /// Tool for working with WebAssembly compositions. 13 | #[derive(Parser)] 14 | #[clap( 15 | bin_name = "wac", 16 | version, 17 | propagate_version = true, 18 | arg_required_else_help = true 19 | )] 20 | #[command(version = version())] 21 | enum Wac { 22 | Plug(PlugCommand), 23 | Compose(ComposeCommand), 24 | Parse(ParseCommand), 25 | Resolve(ResolveCommand), 26 | Targets(TargetsCommand), 27 | } 28 | 29 | #[tokio::main] 30 | async fn main() -> Result<()> { 31 | pretty_env_logger::init(); 32 | 33 | if let Err(e) = match Wac::parse() { 34 | Wac::Parse(cmd) => cmd.exec().await, 35 | Wac::Resolve(cmd) => cmd.exec().await, 36 | Wac::Compose(cmd) => cmd.exec().await, 37 | Wac::Plug(cmd) => cmd.exec().await, 38 | Wac::Targets(cmd) => cmd.exec().await, 39 | } { 40 | eprintln!( 41 | "{error}: {e:?}", 42 | error = "error".if_supports_color(Stream::Stderr, |text| { 43 | text.style(Style::new().red().bold()) 44 | }) 45 | ); 46 | std::process::exit(1); 47 | } 48 | 49 | Ok(()) 50 | } 51 | -------------------------------------------------------------------------------- /src/commands.rs: -------------------------------------------------------------------------------- 1 | //! Module for CLI commands. 2 | 3 | mod compose; 4 | mod parse; 5 | mod plug; 6 | mod resolve; 7 | mod targets; 8 | 9 | pub use self::compose::*; 10 | pub use self::parse::*; 11 | pub use self::plug::*; 12 | pub use self::resolve::*; 13 | pub use self::targets::*; 14 | -------------------------------------------------------------------------------- /src/commands/parse.rs: -------------------------------------------------------------------------------- 1 | use crate::fmt_err; 2 | use anyhow::{Context, Result}; 3 | use clap::Args; 4 | use std::{fs, path::PathBuf}; 5 | use wac_parser::Document; 6 | 7 | /// Parses a WAC source file into a JSON AST representation. 8 | #[derive(Args)] 9 | #[clap(disable_version_flag = true)] 10 | pub struct ParseCommand { 11 | /// The path to the source WAC file. 12 | #[clap(value_name = "PATH")] 13 | pub path: PathBuf, 14 | } 15 | 16 | impl ParseCommand { 17 | /// Executes the command. 18 | pub async fn exec(self) -> Result<()> { 19 | log::debug!("executing parse command"); 20 | 21 | let contents = fs::read_to_string(&self.path) 22 | .with_context(|| format!("failed to read file `{path}`", path = self.path.display()))?; 23 | 24 | let document = Document::parse(&contents).map_err(|e| fmt_err(e, &self.path, &contents))?; 25 | 26 | serde_json::to_writer_pretty(std::io::stdout(), &document)?; 27 | println!(); 28 | 29 | Ok(()) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/progress.rs: -------------------------------------------------------------------------------- 1 | use indicatif::ProgressDrawTarget; 2 | use owo_colors::{OwoColorize, Stream}; 3 | 4 | pub struct ProgressBar(indicatif::ProgressBar); 5 | 6 | impl ProgressBar { 7 | pub fn new() -> Self { 8 | let pb = indicatif::ProgressBar::new(0); 9 | pb.set_draw_target(ProgressDrawTarget::stderr()); 10 | Self(pb) 11 | } 12 | } 13 | 14 | impl wac_resolver::ProgressBar for ProgressBar { 15 | fn init(&self, count: usize) { 16 | self.0.reset(); 17 | self.0.set_length(count as u64); 18 | } 19 | 20 | fn println(&self, status: &str, msg: &str) { 21 | self.0.suspend(|| { 22 | eprintln!( 23 | "{status:>12} {msg}", 24 | status = status.if_supports_color(Stream::Stderr, |text| text.bright_green()) 25 | ) 26 | }); 27 | } 28 | 29 | fn inc(&self, delta: usize) { 30 | self.0.inc(delta as u64); 31 | } 32 | 33 | fn finish(&self) { 34 | self.0.finish_and_clear(); 35 | } 36 | } 37 | --------------------------------------------------------------------------------