Skip to content

Remove generics from SupportedParameterType and SupportedReturnType traits #475

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

Merged
merged 1 commit into from
May 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/hyperlight_host/src/func/host_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ macro_rules! impl_host_function {
impl<R $(, $P)*, F> HostFunction<R, ($($P,)*)> for Arc<Mutex<F>>
where
F: FnMut($($P),*) -> Result<R> + Send + 'static,
$($P: SupportedParameterType<$P> + Clone,)*
R: SupportedReturnType<R>,
$($P: SupportedParameterType + Clone,)*
R: SupportedReturnType,
{
/// Register the host function with the given name in the sandbox.
#[instrument(
Expand Down Expand Up @@ -162,8 +162,8 @@ macro_rules! impl_host_function {
) -> Result<()>
where
T: FnMut($($P),*) -> Result<R> + Send + 'static,
$($P: SupportedParameterType<$P> + Clone,)*
R: SupportedReturnType<R>,
$($P: SupportedParameterType + Clone,)*
R: SupportedReturnType,
{
const N: usize = impl_host_function!(@count $($P),*);
let cloned = self_.clone();
Expand Down
20 changes: 10 additions & 10 deletions src/hyperlight_host/src/func/param_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ use crate::{log_then_return, Result};
/// valid Hyperlight parameter type.
///
/// For each parameter type Hyperlight supports in host functions, we
/// provide an implementation for `SupportedParameterType<SupportedType>`
pub trait SupportedParameterType<T> {
/// provide an implementation for `SupportedParameterType`
pub trait SupportedParameterType: Sized {
/// Get the underlying Hyperlight parameter type representing this
/// `SupportedParameterType`
fn get_hyperlight_type() -> ParameterType;
/// Get the underling Hyperlight parameter value representing this
/// `SupportedParameterType`
fn get_hyperlight_value(&self) -> ParameterValue;
/// Get the actual inner value of this `SupportedParameterType`
fn get_inner(a: ParameterValue) -> Result<T>;
fn get_inner(a: ParameterValue) -> Result<Self>;
}

// We can then implement these traits for each type that Hyperlight supports as a parameter or return type
impl SupportedParameterType<String> for String {
impl SupportedParameterType for String {
#[instrument(skip_all, parent = Span::current(), level= "Trace")]
fn get_hyperlight_type() -> ParameterType {
ParameterType::String
Expand All @@ -59,7 +59,7 @@ impl SupportedParameterType<String> for String {
}
}

impl SupportedParameterType<i32> for i32 {
impl SupportedParameterType for i32 {
#[instrument(skip_all, parent = Span::current(), level= "Trace")]
fn get_hyperlight_type() -> ParameterType {
ParameterType::Int
Expand All @@ -81,7 +81,7 @@ impl SupportedParameterType<i32> for i32 {
}
}

impl SupportedParameterType<u32> for u32 {
impl SupportedParameterType for u32 {
#[instrument(skip_all, parent = Span::current(), level= "Trace")]
fn get_hyperlight_type() -> ParameterType {
ParameterType::UInt
Expand All @@ -103,7 +103,7 @@ impl SupportedParameterType<u32> for u32 {
}
}

impl SupportedParameterType<i64> for i64 {
impl SupportedParameterType for i64 {
#[instrument(skip_all, parent = Span::current(), level= "Trace")]
fn get_hyperlight_type() -> ParameterType {
ParameterType::Long
Expand All @@ -125,7 +125,7 @@ impl SupportedParameterType<i64> for i64 {
}
}

impl SupportedParameterType<u64> for u64 {
impl SupportedParameterType for u64 {
#[instrument(skip_all, parent = Span::current(), level= "Trace")]
fn get_hyperlight_type() -> ParameterType {
ParameterType::ULong
Expand All @@ -147,7 +147,7 @@ impl SupportedParameterType<u64> for u64 {
}
}

impl SupportedParameterType<bool> for bool {
impl SupportedParameterType for bool {
#[instrument(skip_all, parent = Span::current(), level= "Trace")]
fn get_hyperlight_type() -> ParameterType {
ParameterType::Bool
Expand All @@ -169,7 +169,7 @@ impl SupportedParameterType<bool> for bool {
}
}

impl SupportedParameterType<Vec<u8>> for Vec<u8> {
impl SupportedParameterType for Vec<u8> {
#[instrument(skip_all, parent = Span::current(), level= "Trace")]
fn get_hyperlight_type() -> ParameterType {
ParameterType::VecBytes
Expand Down
20 changes: 10 additions & 10 deletions src/hyperlight_host/src/func/ret_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ use crate::HyperlightError::ReturnValueConversionFailure;
use crate::{log_then_return, Result};

/// This is a marker trait that is used to indicate that a type is a valid Hyperlight return type.
pub trait SupportedReturnType<T> {
pub trait SupportedReturnType: Sized {
/// Gets the return type of the supported return value
fn get_hyperlight_type() -> ReturnType;

/// Gets the value of the supported return value
fn get_hyperlight_value(&self) -> ReturnValue;

/// Gets the inner value of the supported return type
fn get_inner(a: ReturnValue) -> Result<T>;
fn get_inner(a: ReturnValue) -> Result<Self>;
}

impl SupportedReturnType<()> for () {
impl SupportedReturnType for () {
#[instrument(skip_all, parent = Span::current(), level= "Trace")]
fn get_hyperlight_type() -> ReturnType {
ReturnType::Void
Expand All @@ -54,7 +54,7 @@ impl SupportedReturnType<()> for () {
}
}

impl SupportedReturnType<String> for String {
impl SupportedReturnType for String {
#[instrument(skip_all, parent = Span::current(), level= "Trace")]
fn get_hyperlight_type() -> ReturnType {
ReturnType::String
Expand All @@ -76,7 +76,7 @@ impl SupportedReturnType<String> for String {
}
}

impl SupportedReturnType<i32> for i32 {
impl SupportedReturnType for i32 {
#[instrument(skip_all, parent = Span::current(), level= "Trace")]
fn get_hyperlight_type() -> ReturnType {
ReturnType::Int
Expand All @@ -98,7 +98,7 @@ impl SupportedReturnType<i32> for i32 {
}
}

impl SupportedReturnType<u32> for u32 {
impl SupportedReturnType for u32 {
#[instrument(skip_all, parent = Span::current(), level= "Trace")]
fn get_hyperlight_type() -> ReturnType {
ReturnType::UInt
Expand All @@ -120,7 +120,7 @@ impl SupportedReturnType<u32> for u32 {
}
}

impl SupportedReturnType<i64> for i64 {
impl SupportedReturnType for i64 {
#[instrument(skip_all, parent = Span::current(), level= "Trace")]
fn get_hyperlight_type() -> ReturnType {
ReturnType::Long
Expand All @@ -142,7 +142,7 @@ impl SupportedReturnType<i64> for i64 {
}
}

impl SupportedReturnType<u64> for u64 {
impl SupportedReturnType for u64 {
#[instrument(skip_all, parent = Span::current(), level= "Trace")]
fn get_hyperlight_type() -> ReturnType {
ReturnType::ULong
Expand All @@ -164,7 +164,7 @@ impl SupportedReturnType<u64> for u64 {
}
}

impl SupportedReturnType<bool> for bool {
impl SupportedReturnType for bool {
#[instrument(skip_all, parent = Span::current(), level= "Trace")]
fn get_hyperlight_type() -> ReturnType {
ReturnType::Bool
Expand All @@ -186,7 +186,7 @@ impl SupportedReturnType<bool> for bool {
}
}

impl SupportedReturnType<Vec<u8>> for Vec<u8> {
impl SupportedReturnType for Vec<u8> {
#[instrument(skip_all, parent = Span::current(), level= "Trace")]
fn get_hyperlight_type() -> ReturnType {
ReturnType::VecBytes
Expand Down
Loading