parity-wasm icon indicating copy to clipboard operation
parity-wasm copied to clipboard

Add newtypes for indices

Open fitzgen opened this issue 7 years ago • 1 comments

There are different index spaces, and it would be awesome to have newtypes for each kind of index, to help folks write more correct code.

Would have been awesome if creating bugs like https://github.com/fitzgen/svelte/issues/24 weren't possible (unless you incorrectly construct an invalid index).

Ideally also have (fallible?) conversions from global indices into function indices, etc.

fitzgen avatar Mar 28 '18 08:03 fitzgen

Yeah, that's sounds cool, here are some problems I encountered when thought about it

  1. Sections publish Vec in it's API to allow the user to manipulate the entries. Users still have to use the raw indices to manipulate vec.
  2. There is no way for users to get function by funcidx in parity-wasm. However, it's used everywhere to index entities.

These are solvable, for (1) we can publish some generaly useful subset of vector operations that would be indexable with newtypes and for (2) we can either provide some utilities which will return FuncOrImport if given functions (and/or code) and imports sections or leave it up to the user.

But my personal opinion is that wasm code manipulation analysis requires more high-level API than that provided by parity-wasm.

pepyakin avatar Mar 28 '18 10:03 pepyakin