1
+ //!
2
+ //! This file implements the Intermediate Representation (IR) for Roc's parser.
3
+ //!
4
+ //! The IR provides a structured, tree-based representation of Roc source code after parsing
5
+ //!
6
+ //! The design uses an arena-based memory allocation strategy with a "multi-list" approach where nodes
7
+ //! are stored in a flat list but cross-referenced via indices rather than pointers. This improves
8
+ //! memory locality and efficiency.
9
+ //!
10
+ //! The implementation includes comprehensive facilities for building, manipulating, and traversing
11
+ //! the IR, as well as converting it to S-expressions for debugging and visualization.
12
+
1
13
const std = @import ("std" );
2
14
const base = @import ("../../base.zig" );
3
15
const sexpr = @import ("../../base/sexpr.zig" );
@@ -19,7 +31,6 @@ tokens: TokenizedBuffer,
19
31
store : NodeStore ,
20
32
errors : []const Diagnostic ,
21
33
22
- /// deinit the IR's memory
23
34
pub fn deinit (self : * IR ) void {
24
35
defer self .tokens .deinit ();
25
36
defer self .store .deinit ();
@@ -2706,8 +2717,15 @@ pub fn resolve(self: *IR, token: TokenIdx) []const u8 {
2706
2717
return self .source [@intCast (range .start .offset ).. @intCast (range .end .offset )];
2707
2718
}
2708
2719
2709
- /// todo -- I'm not sure what this is
2710
- pub const ImportRhs = packed struct { aliased : u1 , qualified : u1 , num_exposes : u30 };
2720
+ /// Contains properties of the thing to the right of the `import` keyword.
2721
+ pub const ImportRhs = packed struct {
2722
+ /// e.g. 1 in case `SomeModule` is an alias in `import SomeModule exposing [...]`
2723
+ aliased : u1 ,
2724
+ /// 1 in case the import is qualified, e.g. `pf` in `import pf.Stdout ...`
2725
+ qualified : u1 ,
2726
+ /// The number of things in the exposes list. e.g. 3 in `import SomeModule exposing [a1, a2, a3]`
2727
+ num_exposes : u30 ,
2728
+ };
2711
2729
2712
2730
// Check that all packed structs are 4 bytes size as they as cast to
2713
2731
// and from a u32
0 commit comments