dillon1000/react

Commit

[rust] Initial translation of HIR and related types

This is an initial translation of HIR (minus the ReactiveFunction bits). It's 
mostly a straightforward translation. A few differences: 

* Instead of Effect having an Unknown variant, we type `Place.effect: 
Option<Effect>`. Maybe i'll revert that but it seems right. 

* Terminal is divided into `Terminal { id: InstructionId, value: TerminalValue 
}` and `enum TerminalValue { ... }`, so that we can reference the terminal's id 
without caring about which kind of terminal it is. 

* Each instruction value variant gets a named struct, whereas in JS we had lots 
of anonymous InstructionValue variants. 

* Rust generators are still an unstable nightly feature and likely to change 
syntax enough that it seems safer not to rely on them. So 
`eachTerminalSuccessor()` returns a `Vec<BlockId>`. If the perf of this is bad 
enough we can switch to something like SmallVec (a popular crate) which stores a 
few elements inline on the stack to optimize for small vecs (which our case 
should be). 

Perhaps more importantly, what's _not different_: I kept the existing approach 
of BasicBlocks having a Vec of owned instruction instances, with 
InstructionValue variant operands as Places rather than indices into a shared 
instruction array. If this works out it will make porting straightforward. 

However there's one aspect of this that is incorrect: right now each `Place` 
owns its `Identifier`, whereas in JS the Identifier instances are shared mutable 
references. I'll definitely need to refactor the data structures to allow 
sharing Identifiers in some form, at which point we may want to change other 
things too.
Browse files
Changed paths19 files
First-parent comparison
M compiler/forget/Cargo.lock ModifiedM compiler/forget/Cargo.toml ModifiedA compiler/forget/crates/build-hir/Cargo.toml AddedA compiler/forget/crates/build-hir/README.md AddedA compiler/forget/crates/build-hir/src/build.rs AddedA compiler/forget/crates/build-hir/src/builder.rs AddedA compiler/forget/crates/build-hir/src/lib.rs AddedA compiler/forget/crates/hir/Cargo.toml AddedA compiler/forget/crates/hir/README.md AddedA compiler/forget/crates/hir/src/basic_block.rs AddedA compiler/forget/crates/hir/src/environment.rs AddedA compiler/forget/crates/hir/src/features.rs AddedA compiler/forget/crates/hir/src/function.rs AddedA compiler/forget/crates/hir/src/id_types.rs AddedA compiler/forget/crates/hir/src/instruction.rs AddedA compiler/forget/crates/hir/src/lib.rs AddedA compiler/forget/crates/hir/src/registry.rs AddedA compiler/forget/crates/hir/src/terminal.rs AddedA compiler/forget/crates/hir/src/types.rs Added
Patch

Files changed

Rendering syntax-highlighted changes…