Invalid character in identifier '2'

Open
#371 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
38/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
go, wasm
Domain
tooling

Research direction

Start by reproducing wit-bindgen-go generate --world hayride:bindings/sdk --out ./go/internal/gen ./wit with v0.7.0 or the main branch, using the reported TinyGo and wasm-tools versions. Inspect how the bundled wasm-tools handles the generated WIT world name; done means bindings generate successfully for the wasi-nn import without the invalid identifier error.

Written by the indexing model from the issue text.

Description

Using wit-bindgen-go past version v0.6.2 results in the following error when generating bindings that import wasi-nn.

Error:

error: wasm-tools: error: invalid character in identifier '2'
     --> component.wit:155:7
      |
  155 | world wasi-nn-WORLD-ml-v020-rc-2024-10-28 {
      |       ^

Full message:

wit-bindgen-go generate --world hayride:bindings/sdk --out ./go/internal/gen ./wit
Generated WIT for custom section:
package wasi:nn@0.2.0-rc-2024-10-28;

/// All inputs and outputs to an ML inference are represented as `tensor`s.
interface tensor {
	/// The dimensions of a tensor.
	///
	/// The array length matches the tensor rank and each element in the array describes
	/// the size of
	/// each dimension
	type tensor-dimensions = list<u32>;

	/// The type of the elements in a tensor.
	enum tensor-type {
		FP16,
		FP32,
		FP64,
		BF16,
		U8,
		I32,
		I64
	}

	/// The tensor data.
	///
	/// Initially conceived as a sparse representation, each empty cell would be filled
	/// with zeros
	/// and the array length must match the product of all of the dimensions and the number
	/// of bytes
	/// in the type (e.g., a 2x2 tensor with 4-byte f32 elements would have a data array
	/// of length
	/// 16). Naturally, this representation requires some knowledge of how to lay out
	/// data in
	/// memory--e.g., using row-major ordering--and could perhaps be improved.
	type tensor-data = list<u8>;
	resource tensor {
		constructor(dimensions: tensor-dimensions, ty: tensor-type, data: tensor-data);

		/// Return the tensor data.
		data: func() -> tensor-data;

		/// Describe the size of the tensor (e.g., 2x2x2x2 -> [2, 2, 2, 2]). To represent
		/// a tensor
		/// containing a single value, use `[1]` for the tensor dimensions.
		dimensions: func() -> tensor-dimensions;

		/// Describe the type of element in the tensor (e.g., `f32`).
		ty: func() -> tensor-type;
	}
}

/// TODO: create function-specific errors (https://github.com/WebAssembly/wasi-nn/issues/42)
interface errors {
	enum error-code {
		/// Caller module passed an invalid argument.
		invalid-argument,
		/// Invalid encoding.
		invalid-encoding,
		/// The operation timed out.
		timeout,
		/// Runtime Error.
		runtime-error,
		/// Unsupported operation.
		unsupported-operation,
		/// Graph is too large.
		too-large,
		/// Graph not found.
		not-found,
		/// The operation is insecure or has insufficient privilege to be performed.
		/// e.g., cannot access a hardware feature requested
		security,
		/// The operation failed for an unspecified reason.
		unknown
	}
	resource error {

		/// Return the error code.
		code: func() -> error-code;

		/// Errors can propagated with backend specific status through a string value.
		data: func() -> string;
	}
}

/// An inference "session" is encapsulated by a `graph-execution-context`. This structure
/// binds a
/// `graph` to input tensors before `compute`-ing an inference:
interface inference {
	use errors.{error};
	use tensor.{tensor};

	/// Identify a tensor by name; this is necessary to associate tensors to
	/// graph inputs and outputs.
	type named-tensor = tuple<string, tensor>;

	/// Bind a `graph` to the input and output tensors for an inference.
	///
	/// TODO: this may no longer be necessary in WIT
	/// (https://github.com/WebAssembly/wasi-nn/issues/43)
	resource graph-execution-context {

		/// Compute the inference on the given inputs.
		compute: func(inputs: list<named-tensor>) -> result<list<named-tensor>, error>;
	}
}

/// A `graph` is a loaded instance of a specific ML model (e.g., MobileNet) for a
/// specific ML
/// framework (e.g., TensorFlow):
interface graph {
	use errors.{error};
	use tensor.{tensor};
	use inference.{graph-execution-context};

	/// An execution graph for performing inference (i.e., a model).
	resource graph {
		init-execution-context: func() -> result<graph-execution-context, error>;
	}

	/// Describes the encoding of the graph. This allows the API to be implemented by
	/// various
	/// backends that encode (i.e., serialize) their graph IR with different formats.
	enum graph-encoding {
		openvino,
		onnx,
		tensorflow,
		pytorch,
		tensorflowlite,
		ggml,
		autodetect
	}

	/// Define where the graph should be executed.
	enum execution-target { cpu, gpu, tpu }

	/// The graph initialization data.
	///
	/// This gets bundled up into an array of buffers because implementing backends may
	/// encode their
	/// graph IR in parts (e.g., OpenVINO stores its IR and weights separately).
	type graph-builder = list<u8>;

	/// Load a `graph` from an opaque sequence of bytes to use for inference.
	load: func(builder: list<graph-builder>, encoding: graph-encoding, target: execution-target) -> result<graph, error>;

	/// Load a `graph` by name.
	///
	/// How the host expects the names to be passed and how it stores the graphs for retrieval
	/// via
	/// this function is **implementation-specific**. This allows hosts to choose name
	/// schemes that
	/// range from simple to complex (e.g., URLs?) and caching mechanisms of various kinds.
	load-by-name: func(name: string) -> result<graph, error>;
}

world wasi-nn-WORLD-ml-v020-rc-2024-10-28 {
	import tensor;
	import errors;
	import inference;
	import graph;
}

error: wasm-tools: error: invalid character in identifier '2'
     --> component.wit:155:7
      |
  155 | world wasi-nn-WORLD-ml-v020-rc-2024-10-28 {
      |       ^

Using:
tinygo version 0.36.0-dev-4372dbdd darwin/arm64 (using go version go1.23.6 and LLVM version 19.1.7)
wasm-tools 1.235.0

Looking through the repo, it appears wasm-tools is bundled, but I have not confirmed.

Using wit-bindgen-go v0.6.2, I can generate bindings. However, using v0.7.0 and building off the main branch results in this error.

Dominant language
Go
Stars
148
Forks
20
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from bytecodealliance/go-modules

All issues in bytecodealliance/go-modules

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.