You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Insert a statement at top of a statement block (e.g. import React from 'react').
All of these cause us problems because the contents of Vec<Statement> needs to be shuffled up/down, which can be expensive, especially at top level where there may be many statements.
We currently have various workarounds for this, including delaying inserting statements until later in transform, or rebuilding the Vec<Statement>, copying all the contents. Multiple transforms may repeat this "shuffle" on the same set of statements.
Could we add a variant Statement::CompositeStatement?
During transform, you can perform any insert/replace/delete action by replacing a Statement with a CompositeStatement. Then when exiting the statement block, if it contains any CompositeStatements, the Vec<Statement> would be shuffled to flatten all the CompositeStatements. This could happen in place and in a single pass, enacting all the changes made by multiple transforms all in one go.
i.e. CompositeStatement would only be used temporarily in the transformer, and they'd be gone in final AST, when transformation is complete.
The other advantage is that we can keep AST and scopes tree in sync at all times. Currently we add bindings to scope tree for new insertions before the actual AST nodes which produce those bindings are inserted, so there's a period where the 2 are out of sync. This may cause us problems further down the line.
The downside of this idea is that whenever iterating over a Vec<Statement> in transformer, you now need to handle CompositeStatements and step into them.
The text was updated successfully, but these errors were encountered:
Replacing Vec<Statement> with a chunked linked list would be another way to solve these problems. Probably better than the CompositeStatement solution suggested above.
It's common in transformer that you need to:
import React from 'react'
).All of these cause us problems because the contents of
Vec<Statement>
needs to be shuffled up/down, which can be expensive, especially at top level where there may be many statements.We currently have various workarounds for this, including delaying inserting statements until later in transform, or rebuilding the
Vec<Statement>
, copying all the contents. Multiple transforms may repeat this "shuffle" on the same set of statements.Could we add a variant
Statement::CompositeStatement
?During transform, you can perform any insert/replace/delete action by replacing a
Statement
with aCompositeStatement
. Then when exiting the statement block, if it contains anyCompositeStatement
s, theVec<Statement>
would be shuffled to flatten all theCompositeStatement
s. This could happen in place and in a single pass, enacting all the changes made by multiple transforms all in one go.i.e.
CompositeStatement
would only be used temporarily in the transformer, and they'd be gone in final AST, when transformation is complete.The other advantage is that we can keep AST and scopes tree in sync at all times. Currently we add bindings to scope tree for new insertions before the actual AST nodes which produce those bindings are inserted, so there's a period where the 2 are out of sync. This may cause us problems further down the line.
The downside of this idea is that whenever iterating over a
Vec<Statement>
in transformer, you now need to handleCompositeStatement
s and step into them.The text was updated successfully, but these errors were encountered: