wasm-tools
wasm-tools copied to clipboard
wast: How do you look up function indices when `Id::new(...)` is not public?
If the following code is the idiomatic way to look up a function index then there's a problem. I can't create an Id:
let wat = "...";
let module = parse::<Wat>(&wat)?.module;
let names = module.resolve()?;
names.resolve_func(&mut Index::Id(
Id::new( // associated function `new` is private
"$my-name",
Span::from_offset(0)
)
));
Is there a better way to look up the $my-name function index?
Currently this was intended to help resolve other nodes that already had an Id, but exposing other methods seems fine by me!
Just stumbled over the same thing - I want to create AST nodes programatically, i.e. without parsing.
I see a couple of options:
pub new(name: &'a str, span: Span)->Id<'a>without any checks. This could cause downstream bugs, because i could e.g. provide an invalid name$fooorfoo bar.pub new(name: &'a str, span: Span)->Id<'a>and internally parse the name, panic if the name is not a valid identifier. However I think that might not be possible due to requirements with the parser buffer / parser.pub new(name: &'a str, span: Span)->Result<Id<'a>>as above, but instead of panic return the parse error.
I think this can be closed :) Thanks again @alexcrichton