Skip to content

Commit

Permalink
Merge branch 'main' into vigoo/oplog-enumeration
Browse files Browse the repository at this point in the history
  • Loading branch information
vigoo committed Oct 9, 2024
2 parents 23d2099 + 666f93c commit 848bcee
Show file tree
Hide file tree
Showing 25 changed files with 2,550 additions and 767 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
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ALTER TABLE component_versions
ADD COLUMN IF NOT EXISTS component_type integer NOT NULL DEFAULT 0;
ADD COLUMN component_type integer NOT NULL DEFAULT 0;
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 848bcee

Please sign in to comment.