Skip to content

Commit

Permalink
[ruby] Re-implemented "Ignore "Throwaway" AST Structures (#4982)"
Browse files Browse the repository at this point in the history
This correctly prevents re-use of nodes that are already being used elsewhere by ensuring deep copies.
  • Loading branch information
DavidBakerEffendi committed Oct 2, 2024
1 parent 8df04c0 commit 13caf05
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ import scala.collection.mutable

trait AstForFunctionsCreator(implicit withSchemaValidation: ValidationMode) { this: AstCreator =>

/** As expressions may be discarded, we cannot store closure ASTs in the diffgraph at the point of creation. We need
* to only write these at the end.
/** As expressions may be discarded, we cannot store closure ASTs in the diffgraph at the point of creation. So we
* assume every reference to this map means that the closure AST was successfully propagated.
*/
protected val closureToRefs = mutable.Map.empty[RubyExpression, Seq[Ast]]
protected val closureToRefs = mutable.Map.empty[RubyExpression, Seq[NewNode]]

/** Creates method declaration related structures.
* @param node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,18 @@ trait AstForStatementsCreator(implicit withSchemaValidation: ValidationMode) { t
protected def astForDoBlock(block: Block & RubyExpression): Seq[Ast] = {
// Create closure structures: [MethodDecl, TypeRef, MethodRef]
if (closureToRefs.contains(block)) {
closureToRefs(block)
closureToRefs(block).map(x => Ast(x.copy))
} else {
val methodName = nextClosureName()

val methodAstsWithRefs = block.body match {
val methodRefAsts = block.body match {
case x: Block =>
astForMethodDeclaration(x.toMethodDeclaration(methodName, Option(block.parameters)), isClosure = true)
case _ =>
astForMethodDeclaration(block.toMethodDeclaration(methodName, Option(block.parameters)), isClosure = true)
}
closureToRefs.put(block, methodAstsWithRefs)
methodAstsWithRefs
closureToRefs.put(block, methodRefAsts.flatMap(_.root))
methodRefAsts
}
}

Expand Down

0 comments on commit 13caf05

Please sign in to comment.