summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-08-11 13:28:46 +0800
committerJohn Hodge <tpg@mutabah.net>2016-08-11 13:28:46 +0800
commite6bea49dc8da627e7672ca9ca9863c1bbbfade2d (patch)
tree801c0f28ba217f31c346d8a78635b60e4049a4e7
parent700863e90b9a6b648b007d2bc9e46f724d47ddab (diff)
downloadmrust-e6bea49dc8da627e7672ca9ca9863c1bbbfade2d.tar.gz
MIR - Match rule default other way too, comment about known codegen fail
-rw-r--r--src/mir/from_hir.cpp32
1 files changed, 29 insertions, 3 deletions
diff --git a/src/mir/from_hir.cpp b/src/mir/from_hir.cpp
index b9ecbe39..6420619e 100644
--- a/src/mir/from_hir.cpp
+++ b/src/mir/from_hir.cpp
@@ -383,16 +383,30 @@ namespace {
)
TU_IFLET(Branch, m_default, Subtree, be,
be->propagate_default();
+
+ if( be->m_default.is_Unset() ) {
+ // TODO: Propagate default from value branches
+ TU_MATCHA( (m_branches), (e),
+ (Unset,
+ ),
+ (Variant,
+ for(auto& branch : e) {
+ be->unify_from(branch.second);
+ }
+ )
+ )
+ }
)
}
void unify_from(const Branch& b)
{
- assert( m_default.is_Unset() );
TU_MATCHA( (b), (be),
(Unset,
),
(Terminal,
- m_default = Branch(be);
+ if( m_default.is_Unset() ) {
+ m_default = Branch(be);
+ }
),
(Subtree,
assert( be->m_branches.tag() == m_branches.tag() );
@@ -411,7 +425,9 @@ namespace {
}
)
)
- m_default = clone(be->m_default);
+ if( m_default.is_Unset() ) {
+ m_default = clone(be->m_default);
+ }
)
)
}
@@ -862,6 +878,16 @@ namespace {
TODO(node.span(), "Handle conditional match arms (ordering matters)");
}
}
+ // TODO: Detect if a rule is ordering-dependent.
+ // XXX XXX XXX: The current codegen (below) will generate incorrect code if ordering matters.
+ // ```
+ // match ("foo", "bar")
+ // {
+ // (_, "bar") => {}, // Expected
+ // ("foo", _) => {}, // Actual
+ // _ => {},
+ // }
+ // ```
// Generate arm code
DEBUG("- Generating arm code");