Skip to content

Add APIs to lookup values in Linker#1480

Merged
alexcrichton merged 2 commits intobytecodealliance:masterfrom
alexcrichton:linker-get
Apr 7, 2020
Merged

Add APIs to lookup values in Linker#1480
alexcrichton merged 2 commits intobytecodealliance:masterfrom
alexcrichton:linker-get

Conversation

@alexcrichton
Copy link
Copy Markdown
Member

This commit adds three new methods to Linker in order to inspect it
after values have been inserted:

  • Linker::iter - iterates over all defined values
  • Linker::get - lookup a value by its ImportType
  • Linker::get_by_name - lookup values based on their name

Closes #1454

This commit adds three new methods to `Linker` in order to inspect it
after values have been inserted:

* `Linker::iter` - iterates over all defined values
* `Linker::get` - lookup a value by its `ImportType`
* `Linker::get_by_name` - lookup values based on their name

Closes bytecodealliance#1454
@github-actions github-actions bot added the wasmtime:api Related to the API of the `wasmtime` crate itself label Apr 7, 2020
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 7, 2020

Subscribe to Label Action

This issue or pull request has been labeled: "wasmtime:api"

Users Subscribed to "wasmtime:api"

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

Comment thread crates/api/src/linker.rs
Comment thread crates/wast/src/wast.rs
Comment thread crates/wast/src/wast.rs Outdated
.collect::<Vec<_>>();
for (name, item) in items {
self.linker.define(as_name, &name, item)?;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we factor out this logic too, with something like self.linker.alias(name, as_name) or so?

Comment thread crates/wast/src/wast.rs Outdated
if items.next().is_some() {
bail!("too many items named `{}` in `{}`", name, module);
}
return Ok(ret);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we factor this out into a method on Linker, something like self.linker.get_one_by_name(module, name) or so? I realize it'll require a special error type to be able to report both "no item named {}" and "too many items named {}", but this seems like it'll be a common use case -- I'm even picturing something like the wasmtime CLI but backed by a Linker so that you can provide multiple modules and then do --invoke.

@alexcrichton
Copy link
Copy Markdown
Member Author

All sounds reasonable to me, updated now!

Copy link
Copy Markdown
Member

@sunfishcode sunfishcode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool!

@alexcrichton alexcrichton merged commit 328de8b into bytecodealliance:master Apr 7, 2020
@alexcrichton alexcrichton deleted the linker-get branch September 9, 2021 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wasmtime:api Related to the API of the `wasmtime` crate itself

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a new method Linker::get_export(module,name).

2 participants