[rust] Sketch of ReactiveIR (prev ReactiveFunction)

Initial data types for `forget_reactive_ir`, which is the Rust analogue of 
`ReactiveFunction` in the TS compiler. I'm renaming here for clarity, though 
naming suggestions are very welcome!
This commit is contained in:
Joe Savona
2023-08-10 10:59:51 -04:00
parent 7c38b15078
commit ee13c30d10
5 changed files with 95 additions and 0 deletions
+7
View File
@@ -271,6 +271,13 @@ dependencies = [
"thiserror",
]
[[package]]
name = "forget_reactive_ir"
version = "0.1.0"
dependencies = [
"forget_hir",
]
[[package]]
name = "forget_semantic_analysis"
version = "0.1.0"
+1
View File
@@ -21,6 +21,7 @@ forget_fixtures = { path = "crates/forget_fixtures" }
forget_hermes_parser = { path = "crates/forget_hermes_parser" }
forget_hir = { path = "crates/forget_hir" }
forget_optimization = { path = "crates/forget_optimization" }
forget_reactive_ir = { path = "crates/forget_reactive_ir" }
forget_semantic_analysis = { path = "crates/forget_semantic_analysis" }
forget_ssa = { path = "crates/forget_ssa" }
forget_utils = { path = "crates/forget_utils" }
@@ -0,0 +1,16 @@
[package]
name = "forget_reactive_ir"
version = "0.1.0"
publish = false
authors.workspace = true
description.workspace = true
edition.workspace = true
homepage.workspace = true
keywords.workspace = true
license.workspace = true
repository.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
forget_hir = { workspace = true }
@@ -0,0 +1,6 @@
# forget_reactive_ir
The Reactive IR is an intermediate representation used to encode reactivity information, used for later stages of analysis focused on memoization/reactivity.
Unlike HIR's "flat" control-flow-graph style representation, Reactive IR is tree-shaped. Blocks can contain HIR instructions as well as additional nested
statements (used for all expressions that have control-flow semantics), and terminals such as if or for have blocks rather than pointing to them indirectly by block id.
@@ -0,0 +1,65 @@
use forget_hir::{IdentifierOperand, Instruction, InstructionId, ReactiveScope};
#[derive(Debug)]
pub struct ReactiveFunction {
pub id: Option<String>,
pub body: Block,
pub params: Vec<IdentifierOperand>,
pub is_async: bool,
pub is_generator: bool,
}
#[derive(Debug)]
pub struct Block {
pub statements: Vec<ReactiveStatement>,
}
#[derive(Debug)]
pub enum ReactiveStatement {
Instruction(Instruction),
ControlFlow(ControlFlow),
ReactiveBlock(ReactiveBlock),
}
#[derive(Debug)]
pub struct ReactiveBlock {
pub scope: ReactiveScope,
pub block: Block,
}
#[derive(Debug)]
pub struct ControlFlow {
pub id: InstructionId,
pub value: ControlFlowValue,
}
#[derive(Debug)]
pub enum ControlFlowValue {
// Logical(LogicalInstruction),
// Sequence(SequenceInstruction),
// Ternary(TernaryInstruction),
// Optional(OptionalInstruction),
// Break(BreakInstruction),
// Continue(ContinueInstruction),
Return(ReturnInstruction),
// Throw(ThrowInstruction),
// Switch(SwitchInstruction),
// DoWhile(DoWhileInstruction),
// While(WhileInstruction),
// For(ForInstruction),
// ForOf(ForOfInstruction),
If(IfInstruction),
// Label(LabelInstruction),
}
#[derive(Debug)]
pub struct ReturnInstruction {
pub value: IdentifierOperand,
}
#[derive(Debug)]
pub struct IfInstruction {
pub test: IdentifierOperand,
pub consequent: Block,
pub alternate: Option<Block>,
}