Skip to content

Commit

Permalink
Merge branch 'lighter-deps' of https://github.com/golemcloud/golem-se…
Browse files Browse the repository at this point in the history
…rvices into lighter-deps
  • Loading branch information
vigoo committed Dec 12, 2024
2 parents a616b59 + a7924aa commit c66512b
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 11 deletions.
4 changes: 2 additions & 2 deletions golem-rib/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -798,9 +798,9 @@ impl Number {
AnalysedType::U32(_) => self.value.to_u32().map(|v| v.into_value_and_type()),
AnalysedType::S32(_) => self.value.to_i32().map(|v| v.into_value_and_type()),
AnalysedType::S64(_) => self.value.to_i64().map(|v| v.into_value_and_type()),
AnalysedType::U8(_) => self.value.to_u32().map(|v| v.into_value_and_type()),
AnalysedType::U8(_) => self.value.to_u8().map(|v| v.into_value_and_type()),
AnalysedType::S8(_) => self.value.to_i32().map(|v| v.into_value_and_type()),
AnalysedType::U16(_) => self.value.to_u32().map(|v| v.into_value_and_type()),
AnalysedType::U16(_) => self.value.to_u16().map(|v| v.into_value_and_type()),
AnalysedType::S16(_) => self.value.to_i32().map(|v| v.into_value_and_type()),
_ => None,
}
Expand Down
2 changes: 1 addition & 1 deletion golem-rib/src/interpreter/interpreter_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::collections::HashMap;
use golem_wasm_rpc::ValueAndType;
use std::collections::HashMap;

// Acts as the structure to hold the global input values
#[derive(Debug, Default, Clone)]
Expand Down
51 changes: 50 additions & 1 deletion golem-rib/src/interpreter/interpreter_stack_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::CoercedNumericValue;
use golem_wasm_ast::analysis::AnalysedType;
use golem_wasm_rpc::{IntoValueAndType, Value, ValueAndType};
use std::fmt;
use std::ops::Deref;

// A result of a function can be unit, which is not representable using type_annotated_value
// A result can be a type_annotated_value
Expand Down Expand Up @@ -121,7 +122,55 @@ impl RibInterpreterStackValue {

pub fn unwrap(&self) -> Option<ValueAndType> {
match self {
RibInterpreterStackValue::Val(val) => Some(val.clone()),
RibInterpreterStackValue::Val(val) => match (val.value.clone(), val.typ.clone()) {
(Value::Option(Some(option)), AnalysedType::Option(option_type)) => {
let inner_value = option.deref().clone();
let inner_type = option_type.inner.deref().clone();
Some(ValueAndType {
value: inner_value,
typ: inner_type,
})
}

(Value::Result(Ok(Some(ok))), AnalysedType::Result(result_type)) => {
let ok_value = ok.deref().clone();
let ok_type = result_type.ok.as_ref()?.deref().clone();
Some(ValueAndType {
value: ok_value,
typ: ok_type,
})
}

(Value::Result(Err(Some(err))), AnalysedType::Result(result_type)) => {
let err_value = err.deref().clone();
let err_type = result_type.err.as_ref()?.deref().clone();
Some(ValueAndType {
value: err_value,
typ: err_type,
})
}

(
Value::Variant {
case_value: Some(case_value),
case_idx,
},
AnalysedType::Variant(variant_type),
) => {
let case_type = variant_type
.cases
.get(case_idx as usize)?
.typ
.as_ref()?
.clone();
Some(ValueAndType {
value: case_value.deref().clone(),
typ: case_type,
})
}

_ => None,
},
RibInterpreterStackValue::Unit => None,
RibInterpreterStackValue::Iterator(_) => None,
RibInterpreterStackValue::Sink(_, _) => None,
Expand Down
4 changes: 2 additions & 2 deletions golem-rib/src/interpreter/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ impl InterpreterStack {
.iter()
.position(|case| case.name == variant_name)
.unwrap() as u32; // TODO: return error
let case_value = optional_variant_value.map(|value| Box::new(value));
let case_value = optional_variant_value.map(Box::new);
self.push_val(ValueAndType::new(
Value::Variant {
case_idx,
Expand All @@ -212,7 +212,7 @@ impl InterpreterStack {
self.push_val(ValueAndType::new(
Value::Enum(idx),
AnalysedType::Enum(TypeEnum {
cases: cases.into_iter().map(|x| x.into()).collect(),
cases: cases.into_iter().collect(),
}),
));
}
Expand Down
9 changes: 6 additions & 3 deletions golem-rib/src/interpreter/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2045,11 +2045,11 @@ mod comprehensive_test {
use crate::interpreter::rib_interpreter::Interpreter;
use crate::interpreter::tests::comprehensive_test::{mock_data, test_utils};
use crate::{RibFunctionInvoke, RibInput};
use golem_wasm_ast::analysis::analysed_type::tuple;
use golem_wasm_ast::analysis::{AnalysedType, TypeStr};
use golem_wasm_rpc::{Value, ValueAndType};
use std::collections::HashMap;
use std::sync::Arc;
use golem_wasm_ast::analysis::analysed_type::tuple;
use golem_wasm_rpc::{Value, ValueAndType};

pub(crate) fn interpreter() -> Interpreter {
let functions_and_results: Vec<(&str, Option<ValueAndType>)> = vec![
Expand Down Expand Up @@ -2254,7 +2254,10 @@ mod comprehensive_test {

async move {
if let Some(value) = value {
Ok(ValueAndType::new(Value::Tuple(vec![value.value]), tuple(vec![value.typ])))
Ok(ValueAndType::new(
Value::Tuple(vec![value.value]),
tuple(vec![value.typ]),
))
} else {
// Representing Unit
Ok(ValueAndType::new(Value::Tuple(vec![]), tuple(vec![])))
Expand Down
2 changes: 1 addition & 1 deletion golem-rib/src/type_inference/rib_output_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use golem_wasm_ast::analysis::AnalysedType;
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[cfg_attr(feature="poem", derive(poem_openapi::Object))]
#[cfg_attr(feature = "poem", derive(poem_openapi::Object))]
pub struct RibOutputTypeInfo {
pub analysed_type: AnalysedType,
}
Expand Down
2 changes: 1 addition & 1 deletion golem-rib/src/type_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,8 @@ mod internal {
#[cfg(feature = "protobuf")]
mod protobuf {

use golem_api_grpc::proto::golem::rib::registry_key::KeyType;
use crate::RegistryKey;
use golem_api_grpc::proto::golem::rib::registry_key::KeyType;

impl TryFrom<golem_api_grpc::proto::golem::rib::RegistryKey> for RegistryKey {
type Error = String;
Expand Down

0 comments on commit c66512b

Please sign in to comment.