Skip to content

Commit 05edec3

Browse files
committed
Updated documentation of UseParentValue stating that it's not needed in most cases.
1 parent dae8a0c commit 05edec3

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

pkg/stablehlo/function.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,14 @@ func (fn *Function) Closure() *Function {
372372
}
373373

374374
// UseParentValue creates a reference in this closure to a value from the parent function.
375-
// This allows closure functions (like If branches) to use values computed in the parent scope.
375+
// This forces the scope of the operation to the closure (fn).
376376
//
377-
// At the StableHLO/MLIR level, closures can reference SSA (Static Single Assignment) values from their parent scope directly.
377+
// Notice, the default for most ops is already to use the deepest (innermost) scope, so
378+
// if one of the operands of an op (like Add) is from a closure, the op will use the closure's scope.
379+
// So this is rarely needed.
380+
//
381+
// At the StableHLO/MLIR level, closures can reference SSA (Static Single Assignment) values from their parent
382+
// scope directly.
378383
// This method enables that by creating a Value in the closure that references the same SSA name.
379384
//
380385
// Returns an error if:
@@ -385,11 +390,13 @@ func (fn *Function) Closure() *Function {
385390
//
386391
// // In parent function
387392
// x := fn.ConstantFromScalar(5.0)
393+
// y := fn.ConstantFromScalar(10.0)
388394
//
389395
// // In closure (e.g., If branch)
390396
// closureFn := fn.Closure()
391397
// xInClosure := closureFn.UseParentValue(x)
392-
// result, _ := stablehlo.Add(xInClosure, closureFn.ConstantFromScalar(1.0))
398+
// yInClosure := closureFn.UseParentValue(y)
399+
// result, _ := stablehlo.Add(xInClosure, yInClosure)
393400
// closureFn.Return(result)
394401
func (fn *Function) UseParentValue(parentValue *Value) (*Value, error) {
395402
if fn.Parent == nil {

0 commit comments

Comments
 (0)