Skip to content
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
10 changes: 10 additions & 0 deletions integration/tests/for.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def test_else_branch():
a = []
for el in ["a", "b", "c"]:
for _ in a:
pass
else:
a.append(el)
return a

assert test_else_branch() == ["a", "b", "c"]
Original file line number Diff line number Diff line change
Expand Up @@ -1272,6 +1272,11 @@ namespace py {
mlir::Block *end_block) const
{
return [this, &rewriter, condition_start, end_block](mlir::Operation *operation) {
auto parent_is_orelse = [](mlir::Operation *operation) {
auto forloop_op = operation->getParentOfType<mlir::py::ForLoopOp>();
if (!forloop_op) { return false; }
return &forloop_op.getOrelse() == operation->getParentRegion();
};
// llvm::outs() << "ForOpLowering 1:\n";
// operation->print(llvm::outs());
// llvm::outs() << '\n';
Expand Down Expand Up @@ -1308,6 +1313,9 @@ namespace py {
&& mlir::isa<TryOp, WithOp, TryHandlerScope>(yield_op->getParentOp())) {
return WalkResult::advance();
}
// is this hacky? maybe there is a better way of ignoring the else branch of
// a for loop
if (parent_is_orelse(operation)) { return WalkResult::advance(); }
rewriter.setInsertionPoint(yield_op);
if (!yield_op.getKind().has_value()
|| yield_op.getKind().value() == py::LoopOpKind::continue_) {
Expand Down Expand Up @@ -2215,6 +2223,11 @@ namespace py {
config.enableRegionSimplification = GreedySimplifyRegionLevel::Disabled;
config.useTopDownTraversal = true;
FrozenRewritePatternSet frozen_patterns{ std::move(patterns) };

// getOperation()->print(llvm::outs());
// llvm::outs() << "-----------------------------------------------\n\n\n";
// llvm::outs().flush();

// Currently ignoring the return value as it seems to always fail, even though the
// transformation seems to generate the expected output
(void)applyPatternsAndFoldGreedily(getOperation(), frozen_patterns, config);
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/PyObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,7 @@ PyResult<PyObject *> PyObject::__ne__(const PyObject *other) const
if (!type_prototype().__eq__.has_value()) { return Ok(not_implemented()); }
return call_slot(*type_prototype().__eq__, this, other).and_then([](PyObject *obj) {
return truthy(obj, VirtualMachine::the().interpreter()).and_then([](bool value) {
return Ok(value ? py_true() : py_false());
return Ok(value ? py_false() : py_true());
});
});
}
Expand Down
Loading