(loc, cond_value, trueBranch, falseBranch)
| 17053 | return new torch._C.CondValue(expr_out, new torch._C.RefinementSet([], []), static_if); |
| 17054 | } |
| 17055 | emitIfElseBlocks(loc, cond_value, trueBranch, falseBranch) { |
| 17056 | if (cond_value.staticIf() !== null) { |
| 17057 | if (cond_value.staticIf()) { |
| 17058 | this.insertRefinements(loc, cond_value.refinements()); |
| 17059 | this.emitStatements(trueBranch); |
| 17060 | } else { |
| 17061 | this.insertRefinements(loc, cond_value.refinements().Not()); |
| 17062 | this.emitStatements(falseBranch); |
| 17063 | } |
| 17064 | return; |
| 17065 | } |
| 17066 | const n = this.graph.insertNode(this.create('prim::If', loc, 0)); |
| 17067 | n.addInput(cond_value.value()); |
| 17068 | const true_block = n.addBlock(); |
| 17069 | const false_block = n.addBlock(); |
| 17070 | const save_true = this.emitSingleIfBranch(true_block, trueBranch, cond_value.refinements()); |
| 17071 | const save_false = this.emitSingleIfBranch(false_block, falseBranch, cond_value.refinements().Not()); |
| 17072 | const true_exits = this.exit_blocks.has(true_block); |
| 17073 | const false_exits = this.exit_blocks.has(false_block); |
| 17074 | if (true_exits && false_exits) { |
| 17075 | this.exit_blocks.add(n.owningBlock()); |
| 17076 | } |
| 17077 | const mutated_variables = new Set(); |
| 17078 | for (const v of save_true.definedVariables()) { |
| 17079 | const insert = new torch._C.WithInsertPoint(false_block); |
| 17080 | if (save_false.findInAnyFrame(v) || false_exits) { |
| 17081 | mutated_variables.add(v); |
| 17082 | } else { |
| 17083 | this.environment_stack.setVariableTypeError(v, () => 'Value is not defined in the false branch.'); |
| 17084 | } |
| 17085 | insert.dispose(); |
| 17086 | } |
| 17087 | for (const v of save_false.definedVariables()) { |
| 17088 | const insert = new torch._C.WithInsertPoint(true_block); |
| 17089 | if (save_true.findInAnyFrame(v) || true_exits) { |
| 17090 | mutated_variables.add(v); |
| 17091 | } else { |
| 17092 | this.environment_stack.setVariableTypeError(v, () => 'Value is not defined in the true branch.'); |
| 17093 | } |
| 17094 | insert.dispose(); |
| 17095 | } |
| 17096 | for (const x of mutated_variables) { |
| 17097 | let tv = null; |
| 17098 | let fv = null; |
| 17099 | { |
| 17100 | const insert = new torch._C.WithInsertPoint(true_block); |
| 17101 | if (!true_exits) { |
| 17102 | tv = save_true.getVar(x, loc); |
| 17103 | } |
| 17104 | insert.dispose(); |
| 17105 | } |
| 17106 | { |
| 17107 | const insert = new torch._C.WithInsertPoint(false_block); |
| 17108 | if (!false_exits) { |
| 17109 | fv = save_false.getVar(x, loc); |
| 17110 | } |
| 17111 | insert.dispose(); |
| 17112 | } |
no test coverage detected