-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[query] refactor BaseIR so children only exposes iterable interface (#…
…13214) This is a simple tidying refactoring to hide the `children` array from consumers of `BaseIR`. My main motivation is to make it easier to explore other ir data structure designs, and to migrate to a new design in the future, e.g. to allow for in-place mutation without requiring large-scale changes to every compiler pass, and to simplify how we encode binding structure.
- Loading branch information
1 parent
3160473
commit 3f4c39a
Showing
32 changed files
with
219 additions
and
235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,53 @@ | ||
package is.hail.expr.ir | ||
|
||
import is.hail.types.BaseType | ||
import is.hail.utils.StackSafe._ | ||
import is.hail.utils._ | ||
|
||
abstract class BaseIR { | ||
def typ: BaseType | ||
|
||
def children: IndexedSeq[BaseIR] | ||
protected def childrenSeq: IndexedSeq[BaseIR] | ||
|
||
def copy(newChildren: IndexedSeq[BaseIR]): BaseIR | ||
def children: Iterable[BaseIR] = childrenSeq | ||
|
||
def deepCopy(): this.type = copy(newChildren = children.map(_.deepCopy())).asInstanceOf[this.type] | ||
protected def copy(newChildren: IndexedSeq[BaseIR]): BaseIR | ||
|
||
def deepCopy(): this.type = copy(newChildren = childrenSeq.map(_.deepCopy())).asInstanceOf[this.type] | ||
|
||
lazy val noSharing: this.type = if (HasIRSharing(this)) this.deepCopy() else this | ||
|
||
def mapChildrenWithIndex(f: (BaseIR, Int) => BaseIR): BaseIR = { | ||
val newChildren = childrenSeq.view.zipWithIndex.map(f.tupled).toArray | ||
if (childrenSeq.elementsSameObjects(newChildren)) | ||
this | ||
else | ||
copy(newChildren) | ||
} | ||
|
||
def mapChildren(f: (BaseIR) => BaseIR): BaseIR = { | ||
val newChildren = children.map(f) | ||
if ((children, newChildren).zipped.forall(_ eq _)) | ||
val newChildren = childrenSeq.map(f) | ||
if (childrenSeq.elementsSameObjects(newChildren)) | ||
this | ||
else | ||
copy(newChildren) | ||
} | ||
|
||
def mapChildrenWithIndexStackSafe(f: (BaseIR, Int) => StackFrame[BaseIR]): StackFrame[BaseIR] = { | ||
call(childrenSeq.iterator.zipWithIndex.map(f.tupled).collectRecur).map { newChildren => | ||
if (childrenSeq.elementsSameObjects(newChildren)) | ||
this | ||
else | ||
copy(newChildren) | ||
} | ||
} | ||
|
||
def mapChildrenStackSafe(f: BaseIR => StackFrame[BaseIR]): StackFrame[BaseIR] = { | ||
call(childrenSeq.mapRecur(f)).map { newChildren => | ||
if (childrenSeq.elementsSameObjects(newChildren)) | ||
this | ||
else | ||
copy(newChildren) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.