Skip to content

Commit

Permalink
Merge branch 'main' into cassandra-key-value-storage-impl
Browse files Browse the repository at this point in the history
  • Loading branch information
irach-ramos authored Oct 8, 2024
2 parents 4139ab9 + 648cfce commit 9e24fc4
Show file tree
Hide file tree
Showing 24 changed files with 2,549 additions and 766 deletions.
6 changes: 6 additions & 0 deletions golem-api-grpc/proto/golem/rib/expr.proto
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ message Expr {
GetTagExpr tag = 26;
UnwrapExpr unwrap = 27;
ThrowExpr throw = 28;
OrExpr or = 29;
}
}

Expand Down Expand Up @@ -126,6 +127,11 @@ message AndExpr {
Expr right = 2;
}

message OrExpr {
Expr left = 1;
Expr right = 2;
}

message GreaterThanOrEqualToExpr {
Expr left = 1;
Expr right = 2;
Expand Down
2 changes: 2 additions & 0 deletions golem-api-grpc/proto/golem/rib/ir.proto
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ message RibIR {
EnumConstructionInstruction enum_construction = 30;
And and = 31;
CreateFunctionNameInstruction create_function_name = 32;
Or or = 33;
}
}

Expand Down Expand Up @@ -114,6 +115,7 @@ message LessThanOrEqualTo {}
message GetTag {}
message Negate {}
message And {}
message Or {}

message FunctionReferenceType {
oneof type {
Expand Down
38 changes: 35 additions & 3 deletions golem-rib/src/compiler/byte_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,42 @@ mod internal {
instructions.push(RibIR::LessThanOrEqualTo);
}
Expr::And(lhs, rhs, _) => {
stack.push(ExprState::from_expr(rhs.deref()));
stack.push(ExprState::from_expr(lhs.deref()));
instructions.push(RibIR::And);
// This optimization isn't optional, it's required for the correct functioning of the interpreter
let optimised_expr = Expr::cond(
Expr::EqualTo(
lhs.clone(),
Box::new(Expr::Boolean(true, InferredType::Bool)),
InferredType::Bool,
),
Expr::EqualTo(
rhs.clone(),
Box::new(Expr::Boolean(true, InferredType::Bool)),
InferredType::Bool,
),
Expr::Boolean(false, InferredType::Bool),
);

stack.push(ExprState::from_expr(&optimised_expr));
}

Expr::Or(lhs, rhs, _) => {
let optimised_expr = Expr::cond(
Expr::EqualTo(
lhs.clone(),
Box::new(Expr::Boolean(true, InferredType::Bool)),
InferredType::Bool,
),
Expr::Boolean(true, InferredType::Bool),
Expr::EqualTo(
rhs.clone(),
Box::new(Expr::Boolean(true, InferredType::Bool)),
InferredType::Bool,
),
);

stack.push(ExprState::from_expr(&optimised_expr));
}

Expr::Record(fields, inferred_type) => {
// Push field instructions in reverse order
for (field_name, field_expr) in fields.iter().rev() {
Expand Down
Loading

0 comments on commit 9e24fc4

Please sign in to comment.