Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add APIs to lookup values in Linker #1480

Merged
merged 2 commits into from
Apr 7, 2020

Conversation

alexcrichton
Copy link
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

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.

crates/api/src/linker.rs Show resolved Hide resolved
crates/wast/src/wast.rs Show resolved Hide resolved
.collect::<Vec<_>>();
for (name, item) in items {
self.linker.define(as_name, &name, item)?;
}
Copy link
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?

if items.next().is_some() {
bail!("too many items named `{}` in `{}`", name, module);
}
return Ok(ret);
Copy link
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
Member Author

All sounds reasonable to me, updated now!

Copy link
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