Skip to content

Splitting out AstNode to AstNode, Block, Pipeline, StatementNode, ExpressionNode.#68

Open
WindSoilder wants to merge 38 commits intonushell:mainfrom
WindSoilder:ast_nodes
Open

Splitting out AstNode to AstNode, Block, Pipeline, StatementNode, ExpressionNode.#68
WindSoilder wants to merge 38 commits intonushell:mainfrom
WindSoilder:ast_nodes

Conversation

@WindSoilder
Copy link
Copy Markdown
Contributor

@WindSoilder WindSoilder commented Mar 16, 2026

As title, this pr is a huge refactor of the codebase, it splits a general AstNode to different nodes.

- A BlockNode, it contains
- A list of StatementNode or ExpressionNode

We can look into enum StatementNode and enum ExpressionNode to see what they can be.

It's a little different to another pr #54 , this pr saves all these nodes into Compiler, so we have the following fields:

  • ast_nodes (It contains some smaller set of original AstNode)
  • expression_nodes
  • block_nodes
  • pipeline_nodes
  • name_nodes (explained in next paragraph)
  • string_nodes (explained in next paragraph)
  • variable_nodes (explained in next paragraph)

For Expression Node, I dupliated the storage of NameNode, StringNode and VariableNode to an individual place, because they can be re-used in many places, after that, we can define StatementNode::Let, StatementNode::Def easier.

After we pushing these node, we also put an Indexer into Compiler.indexer, we can still get all nodes sequentially from this field.

For every type of node, they have a new id type, for example:

  • NameNode: NameNodeId
  • StringNode: StringNodeId
  • VariableNode: VariableNodeId
    And here we define NodeIdGetter trait for NodeId and NodePush trait for Node. So we can push node to compiler and get node information from compiler easily.

What can we actheves after this pr:

  • A better runtime performance, because we don't need to check AstNode every time after we get a node, we are more likely to get right node when we get from a dedicated typed id.
  • Less possibility of bugs, because we can make use of Rust's type system to make sure we are using the right node in the right place.

Something might goes bad after this pr:

  • Some spaces overhead because we need to store more vectors to store these nodes.
  • More complicated output in display_state method, especially in Compiler, because it outputs the indirect NameNode, StringNode, VariableNode, Statement etc as well.

I had done manually tests for files under tests manually to update snapshot, but something might still broken

@WindSoilder WindSoilder marked this pull request as ready for review April 14, 2026 05:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant