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

Invoke Testing extension through ExtensionHandle #2660

Merged
merged 5 commits into from
Apr 5, 2022

Conversation

mariaschett
Copy link
Contributor

@mariaschett mariaschett commented Apr 4, 2022

  • add ExtensionHandle and get_handle() for every extension
  • invoke testing extension with a handle

@mariaschett mariaschett marked this pull request as ready for review April 4, 2022 15:45
@tiziano88 tiziano88 requested review from a team, andrisaar and tiziano88 and removed request for a team and tiziano88 April 4, 2022 15:46
@@ -109,7 +109,7 @@ where
Ok(extension_result)
}

fn get_metadata(&self) -> (String, wasmi::Signature) {
fn get_metadata(&self) -> (String, wasmi::Signature, ExtensionHandle) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it might be worth defining a struct rather than using a tuple with 3 elements to improve clarity.

Copy link
Collaborator

Choose a reason for hiding this comment

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

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, that's true! Instead of adding a struct, I added a new get_handle function to the trait. I believe we'll remove get_metadata eventually, so that makes more sense.

let handle: ExtensionHandle =
ExtensionHandle::from_i32(handle).expect("Fail to parse handle.");

// Quick solution following impelementation of invoking an extension in `invoke_index`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am unsure what the intention of this comment is. Does it mean this is a temporary solution that will be replaced with something better?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, updated comment. Thank you!

// Then we get the extension which has the given handle by looking at the values of the
// extension_indices.
let extension = extensions_indices
.iter_mut()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is a mutable iterator needed? It seems weird that this requires taking the extension indicices and then putting them back when nothing seems to be actually mutated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because extension.invoke(self, ...) in line 369 needs a mutable WasmState and extension_indices are part of WasmState.

With #2664 we can simplify this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, I see. I guess part of the weirdness it that an Option is used rather than a RefCell to implement interior mutability, but this is preexisting so can be fixed later as part of #2664 and other refactoring.

@@ -109,7 +109,7 @@ where
Ok(extension_result)
}

fn get_metadata(&self) -> (String, wasmi::Signature) {
fn get_metadata(&self) -> (String, wasmi::Signature, ExtensionHandle) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

+1

let request_len: AbiPointerOffset = args.nth_checked(1)?;
let response_ptr_ptr: AbiPointer = args.nth_checked(2)?;
let response_len_ptr: AbiPointer = args.nth_checked(3)?;
// We still read the args after the ExtensionHandle at position 0.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe add let _handle = args.nth_checked(0); for consistency and future proof.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@mariaschett mariaschett self-assigned this Apr 5, 2022
Copy link
Contributor Author

@mariaschett mariaschett left a comment

Choose a reason for hiding this comment

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

Thank you!

@@ -109,7 +109,7 @@ where
Ok(extension_result)
}

fn get_metadata(&self) -> (String, wasmi::Signature) {
fn get_metadata(&self) -> (String, wasmi::Signature, ExtensionHandle) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, that's true! Instead of adding a struct, I added a new get_handle function to the trait. I believe we'll remove get_metadata eventually, so that makes more sense.

let handle: ExtensionHandle =
ExtensionHandle::from_i32(handle).expect("Fail to parse handle.");

// Quick solution following impelementation of invoking an extension in `invoke_index`.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, updated comment. Thank you!

// Then we get the extension which has the given handle by looking at the values of the
// extension_indices.
let extension = extensions_indices
.iter_mut()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because extension.invoke(self, ...) in line 369 needs a mutable WasmState and extension_indices are part of WasmState.

With #2664 we can simplify this.

let request_len: AbiPointerOffset = args.nth_checked(1)?;
let response_ptr_ptr: AbiPointer = args.nth_checked(2)?;
let response_len_ptr: AbiPointer = args.nth_checked(3)?;
// We still read the args after the ExtensionHandle at position 0.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

let handle: ExtensionHandle =
ExtensionHandle::from_i32(handle).expect("Fail to parse handle.");

// TODO(#2664) Quick solution following impelementation of invoking an extension in
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: I think a : is required after the TODO().

// Then we get the extension which has the given handle by looking at the values of the
// extension_indices.
let extension = extensions_indices
.iter_mut()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, I see. I guess part of the weirdness it that an Option is used rather than a RefCell to implement interior mutability, but this is preexisting so can be fixed later as part of #2664 and other refactoring.

@mariaschett mariaschett merged commit 20c4ca2 into project-oak:main Apr 5, 2022
@mariaschett mariaschett deleted the add-handle-for-testing branch April 5, 2022 11:56
@github-actions
Copy link

github-actions bot commented Apr 5, 2022

Reproducibility Index:

d4b7228fb9f2bdb5a85593815a44be6ac8ab9e745c8352869a8bd7e815b18a92  ./target/x86_64-unknown-linux-musl/release/oak_functions_loader_base
969ca18c94fbd6e9b852ede7819a893194228316b49d09dc315e02a35cb88d93  ./target/x86_64-unknown-linux-musl/release/oak_functions_loader_unsafe

Reproducibility Index diff:

diff --git a/reproducibility_index b/reproducibility_index
index f6358ab..a7663eb 100644
--- a/reproducibility_index
+++ b/reproducibility_index
@@ -1,2 +1,2 @@
-96fb21e31e8cf9b36cfa3a60d9755b30b0032f4e232e322341b9f731879c6471  ./target/x86_64-unknown-linux-musl/release/oak_functions_loader_base
-b9fd6e9df8799c1d2465bcfcaecb4c6e5df266e1488700135112f9080be138aa  ./target/x86_64-unknown-linux-musl/release/oak_functions_loader_unsafe
+d4b7228fb9f2bdb5a85593815a44be6ac8ab9e745c8352869a8bd7e815b18a92  ./target/x86_64-unknown-linux-musl/release/oak_functions_loader_base
+969ca18c94fbd6e9b852ede7819a893194228316b49d09dc315e02a35cb88d93  ./target/x86_64-unknown-linux-musl/release/oak_functions_loader_unsafe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants