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

Crate features and dependency cleanup #1176

Merged
merged 15 commits into from
Dec 13, 2024
Prev Previous commit
Next Next commit
Fix more tests
afsalthaj committed Dec 12, 2024
commit 8a45a38f71c0e3437c3f93a904f528fce0c81040
4 changes: 3 additions & 1 deletion golem-rib/src/compiler/compiler_output.rs
Original file line number Diff line number Diff line change
@@ -30,8 +30,10 @@ pub struct CompilerOutput {

#[cfg(feature = "protobuf")]
mod protobuf {
use crate::{
CompilerOutput, RibByteCode, RibInputTypeInfo, RibOutputTypeInfo, WorkerFunctionsInRib,
};
use golem_api_grpc::proto::golem::rib::CompilerOutput as ProtoCompilerOutput;
use crate::{CompilerOutput, RibByteCode, RibInputTypeInfo, RibOutputTypeInfo, WorkerFunctionsInRib};

impl TryFrom<ProtoCompilerOutput> for CompilerOutput {
type Error = String;
2 changes: 1 addition & 1 deletion golem-rib/src/interpreter/interpreter_input.rs
Original file line number Diff line number Diff line change
@@ -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)]
61 changes: 60 additions & 1 deletion golem-rib/src/interpreter/interpreter_stack_value.rs
Original file line number Diff line number Diff line change
@@ -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
@@ -121,7 +122,65 @@ 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(option), AnalysedType::Option(option_type)) => {
Some(ValueAndType {
value: option.unwrap().deref().clone(),
typ: option_type.inner.deref().clone(),
})
}

(Value::Result(result), AnalysedType::Result(result_type)) => match result {
Ok(Some(ok)) => Some(ValueAndType {
value: ok.deref().clone(),
typ: result_type.ok.unwrap().deref().clone(),
}),

Err(Some(err)) => Some(ValueAndType {
value: err.deref().clone(),
typ: result_type.err.unwrap().deref().clone(),
}),
_ => None,
},

(
Value::Variant {
case_value,
case_idx,
},
AnalysedType::Variant(variant_type),
) => Some(ValueAndType {
value: case_value.unwrap().deref().clone(),
typ: variant_type.cases[case_idx as usize].clone().typ.unwrap(),
}),

_ => None,
}

// match val.value {
// Va:Option(option) => option
// .value
// .as_deref()
// .and_then(|x| x.type_annotated_value.clone()),
// TypeAnnotatedValue::Result(result) => {
// let result = match &result.result_value {
// Some(ResultValue::OkValue(ok)) => Some(ok.clone()),
// Some(ResultValue::ErrorValue(err)) => Some(err.clone()),
// None => None,
// };
//
// // GRPC wrapper
// result.and_then(|x| x.type_annotated_value)
// }
//
// TypeAnnotatedValue::Variant(variant) => variant
// .case_value
// .as_deref()
// .and_then(|x| x.type_annotated_value.clone()),
// _ => None,
// }
}
RibInterpreterStackValue::Unit => None,
RibInterpreterStackValue::Iterator(_) => None,
RibInterpreterStackValue::Sink(_, _) => None,
2 changes: 0 additions & 2 deletions golem-rib/src/interpreter/rib_interpreter.rs
Original file line number Diff line number Diff line change
@@ -1491,15 +1491,13 @@ mod interpreter_tests {

let compiled = compiler::compile(&expr, &vec![]).unwrap();


let result = interpreter
.run(compiled.byte_code)
.await
.unwrap()
.get_val()
.unwrap();


assert_eq!(result, 0u8.into_value_and_type());
}
}
9 changes: 6 additions & 3 deletions golem-rib/src/interpreter/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -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![
@@ -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![])))
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
@@ -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,
}
2 changes: 1 addition & 1 deletion golem-rib/src/type_registry.rs
Original file line number Diff line number Diff line change
@@ -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;