Use fixed slots for the children #1721
Replies: 4 comments 6 replies
-
I think I finally got my head around how this could work:
One thing left to verify is if |
Beta Was this translation helpful? Give feedback.
-
I took a look at how and when rowan computes the Let's have a look at how child if (true) {
console.log("Test");
} This parses to (ignoring the if's body as we're only looking at the if statement) if-stmt
- if-token
- (
- bool-literal
- true-kw
- )
- block
- {
- list
- stmt(...)
- } A consumer could use the if as follow let if_stmt = ...;
match if_stmt.condition() {
...
}
match if_stmt.cons() {
..
} Current rowan uses iteration to find a child. That means that rowan iterates over the
That means, that we create Now, what about the offsets? My initial fear was that the rowan computes the tools/crates/rome_rowan/src/green/node.rs Lines 225 to 232 in 6799f74 Does that mean it's a happy ending after all? Indeed, it is! Retrieving a slot at position I would recommend that we rename Note: And how does it work in Roslyn? Roslyn caches most Their algorithm computes the relative offset from the parent and starts from one slot before the queried slot:
This works relatively well if you look at the if stmt example from aboth because passes tend to visit the children in the execution order (from left to right, or from lowest to highest index).
Neat, isn't it. However, adopting this approach would require to cache our |
Beta Was this translation helpful? Give feedback.
-
OK, implementing this change turned out to be a bit more complicated than I expected. Or more precisely, we have multiple options, all coming with different ups and downs. Option A: Transparent List NodeThis is what Roslyn's doing. It uses a special
Advantages
Disadvantages
Option B: Non-transparent
|
Beta Was this translation helpful? Give feedback.
-
The parser knows and the AST nodes know as well. I guess we could just define another |
Beta Was this translation helpful? Give feedback.
-
Thread to discuss the change around using fixed slots to store the children.
From #1718
Beta Was this translation helpful? Give feedback.
All reactions