Skip to content

Commit 9e24fc4

Browse files
authored
Merge branch 'main' into cassandra-key-value-storage-impl
2 parents 4139ab9 + 648cfce commit 9e24fc4

File tree

24 files changed

+2549
-766
lines changed

24 files changed

+2549
-766
lines changed

golem-api-grpc/proto/golem/rib/expr.proto

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ message Expr {
3535
GetTagExpr tag = 26;
3636
UnwrapExpr unwrap = 27;
3737
ThrowExpr throw = 28;
38+
OrExpr or = 29;
3839
}
3940
}
4041

@@ -126,6 +127,11 @@ message AndExpr {
126127
Expr right = 2;
127128
}
128129

130+
message OrExpr {
131+
Expr left = 1;
132+
Expr right = 2;
133+
}
134+
129135
message GreaterThanOrEqualToExpr {
130136
Expr left = 1;
131137
Expr right = 2;

golem-api-grpc/proto/golem/rib/ir.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ message RibIR {
4242
EnumConstructionInstruction enum_construction = 30;
4343
And and = 31;
4444
CreateFunctionNameInstruction create_function_name = 32;
45+
Or or = 33;
4546
}
4647
}
4748

@@ -114,6 +115,7 @@ message LessThanOrEqualTo {}
114115
message GetTag {}
115116
message Negate {}
116117
message And {}
118+
message Or {}
117119

118120
message FunctionReferenceType {
119121
oneof type {

golem-rib/src/compiler/byte_code.rs

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,42 @@ mod internal {
151151
instructions.push(RibIR::LessThanOrEqualTo);
152152
}
153153
Expr::And(lhs, rhs, _) => {
154-
stack.push(ExprState::from_expr(rhs.deref()));
155-
stack.push(ExprState::from_expr(lhs.deref()));
156-
instructions.push(RibIR::And);
154+
// This optimization isn't optional, it's required for the correct functioning of the interpreter
155+
let optimised_expr = Expr::cond(
156+
Expr::EqualTo(
157+
lhs.clone(),
158+
Box::new(Expr::Boolean(true, InferredType::Bool)),
159+
InferredType::Bool,
160+
),
161+
Expr::EqualTo(
162+
rhs.clone(),
163+
Box::new(Expr::Boolean(true, InferredType::Bool)),
164+
InferredType::Bool,
165+
),
166+
Expr::Boolean(false, InferredType::Bool),
167+
);
168+
169+
stack.push(ExprState::from_expr(&optimised_expr));
157170
}
171+
172+
Expr::Or(lhs, rhs, _) => {
173+
let optimised_expr = Expr::cond(
174+
Expr::EqualTo(
175+
lhs.clone(),
176+
Box::new(Expr::Boolean(true, InferredType::Bool)),
177+
InferredType::Bool,
178+
),
179+
Expr::Boolean(true, InferredType::Bool),
180+
Expr::EqualTo(
181+
rhs.clone(),
182+
Box::new(Expr::Boolean(true, InferredType::Bool)),
183+
InferredType::Bool,
184+
),
185+
);
186+
187+
stack.push(ExprState::from_expr(&optimised_expr));
188+
}
189+
158190
Expr::Record(fields, inferred_type) => {
159191
// Push field instructions in reverse order
160192
for (field_name, field_expr) in fields.iter().rev() {

0 commit comments

Comments
 (0)