compiler: Add a DebugHook expression

You can not create this expression manually, but there
is a pass in the compiler that adds it to all set
properties in a compilation run.

All it does is basically associate an id with an expression,
so that we can then in a later step have the interpreter do
something with that information. Apart from that, it tries to
be as transparent as possible.

The LLR lowering removes that expression again, just so we can
be sure it does not end up in the generated live code.
This commit is contained in:
Tobias Hunger 2025-03-26 11:20:41 +00:00 committed by Tobias Hunger
parent e613ffb319
commit aaeb4a0df5
16 changed files with 147 additions and 23 deletions

View file

@ -716,6 +716,11 @@ pub enum Expression {
rhs: Box<Expression>,
},
DebugHook {
expression: Box<Expression>,
id: SmolStr,
},
EmptyComponentFactory,
}
@ -837,6 +842,7 @@ impl Expression {
Expression::SolveLayout(..) => Type::LayoutCache,
Expression::MinMax { ty, .. } => ty.clone(),
Expression::EmptyComponentFactory => Type::ComponentFactory,
Expression::DebugHook { expression, .. } => expression.ty(),
}
}
@ -931,6 +937,7 @@ impl Expression {
visitor(rhs);
}
Expression::EmptyComponentFactory => {}
Expression::DebugHook { expression, .. } => visitor(expression),
}
}
@ -1027,6 +1034,7 @@ impl Expression {
visitor(rhs);
}
Expression::EmptyComponentFactory => {}
Expression::DebugHook { expression, .. } => visitor(expression),
}
}
@ -1108,6 +1116,7 @@ impl Expression {
Expression::SolveLayout(..) => false,
Expression::MinMax { lhs, rhs, .. } => lhs.is_constant() && rhs.is_constant(),
Expression::EmptyComponentFactory => true,
Expression::DebugHook { .. } => false,
}
}
@ -1409,6 +1418,14 @@ impl Expression {
}
}
}
/// Unwrap DebugHook expressions to their contained sub-expression
pub fn ignore_debug_hooks(&self) -> &Expression {
match self {
Expression::DebugHook { expression, .. } => expression.as_ref(),
_ => return self,
}
}
}
fn model_inner_type(model: &Expression) -> Type {
@ -1738,5 +1755,10 @@ pub fn pretty_print(f: &mut dyn std::fmt::Write, expression: &Expression) -> std
write!(f, ")")
}
Expression::EmptyComponentFactory => write!(f, "<empty-component-factory>"),
Expression::DebugHook { expression, id } => {
write!(f, "debug-hook(")?;
pretty_print(f, expression)?;
write!(f, "\"{id}\")")
}
}
}