Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

torch: [nfc] use WalkResult::isInterrupted() instead of booleans #1081

Merged
merged 1 commit into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 7 additions & 16 deletions lib/Dialect/Torch/Transforms/GlobalizeObjectGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,26 +464,17 @@ static LogicalResult verifyNnModuleValueUses(Value value) {
// Verify that `func` conforms to the subset of allowable method bodies
// that we can convert.
static LogicalResult verifyFuncConformsToSubset(func::FuncOp func) {
// TODO: Investingate why WalkResult::interrupt() doesn't propagate properly.
LogicalResult ret = success();
func.walk([&](Block *block) {
for (Value arg : block->getArguments()) {
if (failed(verifyNnModuleValueUses(arg))) {
ret = failure();
auto walkResult = func.walk([&](Block *block) {
for (Value arg : block->getArguments())
if (failed(verifyNnModuleValueUses(arg)))
return WalkResult::interrupt();
}
}
for (Operation &op : *block) {
for (Value result : op.getResults()) {
if (failed(verifyNnModuleValueUses(result))) {
ret = failure();
for (Operation &op : *block)
for (Value result : op.getResults())
if (failed(verifyNnModuleValueUses(result)))
return WalkResult::interrupt();
}
}
}
return WalkResult::advance();
});
return ret;
return success(!walkResult.wasInterrupted());
}

static LogicalResult
Expand Down
20 changes: 6 additions & 14 deletions lib/Dialect/Torch/Transforms/VerifyConversionToValueSemantics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,20 @@ class VerifyConversionToValueSemanticsPass
: public VerifyConversionToValueSemanticsBase<
VerifyConversionToValueSemanticsPass> {
void runOnOperation() override {
bool didFail = false;
auto walkResult = getOperation().walk([&](Block *block) {
for (BlockArgument arg : block->getArguments()) {
if (failed(checkValueType(block->getParentOp(), arg))) {
didFail = true;
for (BlockArgument arg : block->getArguments())
if (failed(checkValueType(block->getParentOp(), arg)))
return WalkResult::interrupt();
}
}

for (Operation &op : *block) {
for (OpResult result : op.getResults()) {
if (failed(checkValueType(&op, result))) {
didFail = true;
for (Operation &op : *block)
for (OpResult result : op.getResults())
if (failed(checkValueType(&op, result)))
return WalkResult::interrupt();
}
}
}

return WalkResult::advance();
});

if (didFail || walkResult.wasInterrupted())
if (walkResult.wasInterrupted())
signalPassFailure();
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,39 +42,30 @@ class VerifyInvariantsBeforeBackendLoweringPass
: public VerifyInvariantsBeforeBackendLoweringBase<
VerifyInvariantsBeforeBackendLoweringPass> {
void runOnOperation() override {
// TODO: It seems that the walkers over blocks are not correctly
// propagating `walkResult.wasInterrupted()` so use a manual `didFail`
// boolean.
bool didFail = false;
getOperation().walk([&](Block *block) {
auto walkResult = getOperation().walk([&](Block *block) {
// Check invariants on all the Value's in the program.
// That is, check all BlockArgument's and OpResult's.
for (BlockArgument arg : block->getArguments()) {
if (failed(checkValueInvariants(block->getParentOp(), arg))) {
didFail = true;
for (BlockArgument arg : block->getArguments())
if (failed(checkValueInvariants(block->getParentOp(), arg)))
return WalkResult::interrupt();
}
}

for (Operation &op : *block) {
if (isa<Torch::OperatorOp>(op)) {
op.emitError()
.append("unsupported by backend lowering: `torch.operator` op")
.attachNote()
.append("this is likely due to a missing op that needs to be "
"generated by torch_ods_gen.py");
didFail = true;
return WalkResult::interrupt();
}
for (OpResult result : op.getResults()) {
if (failed(checkValueInvariants(&op, result))) {
didFail = true;

for (OpResult result : op.getResults())
if (failed(checkValueInvariants(&op, result)))
return WalkResult::interrupt();
}
}
}
return WalkResult::advance();
});
if (didFail)
if (walkResult.wasInterrupted())
return signalPassFailure();
}
};
Expand Down