summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-12-31 14:07:45 +0800
committerJohn Hodge <tpg@mutabah.net>2016-12-31 14:07:45 +0800
commit5deed177a5a6fcd7bad86c8dd4f5866f7b578de3 (patch)
tree5e5ed81e55a0c6a89ab51ff5127adb0ae5607357
parent7ef1d63e51f4fa14def0a1fabe7a988e5d50ec82 (diff)
downloadmrust-5deed177a5a6fcd7bad86c8dd4f5866f7b578de3.tar.gz
MIR - Fix a bit of invalid MIR
-rw-r--r--src/mir/check.cpp2
-rw-r--r--src/mir/cleanup.cpp24
-rw-r--r--src/mir/from_hir.cpp2
-rw-r--r--src/mir/from_hir_match.cpp4
-rw-r--r--src/trans/codegen_c.cpp8
5 files changed, 31 insertions, 9 deletions
diff --git a/src/mir/check.cpp b/src/mir/check.cpp
index 9e83df8c..382694a7 100644
--- a/src/mir/check.cpp
+++ b/src/mir/check.cpp
@@ -543,10 +543,12 @@ void MIR_Validate(const StaticTraitResolve& resolve, const ::HIR::ItemPath& path
),
(DstMeta,
// TODO: Ensure that the input type is a: Generic, Array, or DST
+ MIR_ASSERT(state, e.val.is_Deref(), "DstMeta requires a deref as input");
// TODO: Check return type
),
(DstPtr,
// TODO: Ensure that the input type is a DST
+ MIR_ASSERT(state, e.val.is_Deref(), "DstPtr requires a deref as input");
// TODO: Check return type
),
(MakeDst,
diff --git a/src/mir/cleanup.cpp b/src/mir/cleanup.cpp
index 8a5ee1dc..f790c78a 100644
--- a/src/mir/cleanup.cpp
+++ b/src/mir/cleanup.cpp
@@ -120,13 +120,33 @@ const ::HIR::Literal* MIR_Cleanup_GetConstant(const Span& sp, const StaticTraitR
if( best_impl )
{
- out_ty = best_impl->m_constants.find(pe.item)->second.data.m_type.clone();
+ const auto& val = best_impl->m_constants.find(pe.item)->second.data;
+ out_ty = val.m_type.clone();
// TODO: Obtain `out_ty` by monomorphising the type in the trait.
- return &best_impl->m_constants.find(pe.item)->second.data.m_value_res;
+ return &val.m_value_res;
}
),
(UfcsInherent,
+ const ::HIR::TypeImpl* best_impl = nullptr;
// TODO: Associated constants (inherent)
+ resolve.m_crate.find_type_impls(*pe.type, [&](const auto& ty)->const auto& { return ty; },
+ [&](const auto& impl) {
+ auto it = impl.m_constants.find(pe.item);
+ if( it == impl.m_constants.end() )
+ return false;
+ // TODO: Bounds checks.
+ // TODO: Impl specialisation?
+ best_impl = &impl;
+ return it->second.is_specialisable;
+ });
+ if( best_impl )
+ {
+ const auto& val = best_impl->m_constants.find(pe.item)->second.data;
+ if( monomorphise_type_needed(val.m_type) )
+ TODO(sp, "Monomorphise constant type - " << val.m_type << " for " << path);
+ out_ty = val.m_type.clone();
+ return &val.m_value_res;
+ }
)
)
return nullptr;
diff --git a/src/mir/from_hir.cpp b/src/mir/from_hir.cpp
index 4f72099d..60084e3d 100644
--- a/src/mir/from_hir.cpp
+++ b/src/mir/from_hir.cpp
@@ -1181,7 +1181,7 @@ namespace {
{
// HACK: FixedSizeArray uses `A: Unsize<[T]>` which will lead to the above code not working (as the size isn't known).
// - Maybe _Meta on the `&A` would work as a stopgap (since A: Sized, it won't collide with &[T] or similar)
- auto size_lval = m_builder.lvalue_or_temp( node.span(), ::HIR::TypeRef(::HIR::CoreType::Usize), ::MIR::RValue::make_DstMeta({ ptr_lval.clone() }) );
+ auto size_lval = m_builder.lvalue_or_temp( node.span(), ::HIR::TypeRef(::HIR::CoreType::Usize), ::MIR::RValue::make_DstMeta({ ::MIR::LValue::make_Deref({ box$(ptr_lval.clone()) }) }) );
m_builder.set_result( node.span(), ::MIR::RValue::make_MakeDst({ mv$(ptr_lval), mv$(size_lval) }) );
}
else
diff --git a/src/mir/from_hir_match.cpp b/src/mir/from_hir_match.cpp
index 183d6418..008bef0c 100644
--- a/src/mir/from_hir_match.cpp
+++ b/src/mir/from_hir_match.cpp
@@ -3677,6 +3677,8 @@ void DecisionTreeGen::generate_branches_Slice(
ERROR(sp, E0000, "Non-exhaustive match over " << ty);
}
+ auto val_len = m_builder.lvalue_or_temp(sp, ::HIR::CoreType::Usize, ::MIR::RValue::make_DstMeta({ val.clone() }));
+
// NOTE: Un-deref the slice
ASSERT_BUG(sp, val.is_Deref(), "slice matches must be passed a deref");
auto tmp = mv$( *val.as_Deref().val );
@@ -3689,8 +3691,6 @@ void DecisionTreeGen::generate_branches_Slice(
// - Binary search
// - Sequential comparisons
- auto val_len = m_builder.lvalue_or_temp(sp, ::HIR::CoreType::Usize, ::MIR::RValue::make_DstMeta({ val.clone() }));
-
// TODO: Binary search instead.
for( const auto& branch : branches.fixed_arms )
{
diff --git a/src/trans/codegen_c.cpp b/src/trans/codegen_c.cpp
index 3f6c69be..e29f2a40 100644
--- a/src/trans/codegen_c.cpp
+++ b/src/trans/codegen_c.cpp
@@ -1453,17 +1453,17 @@ namespace {
TU_MATCHA( (path.m_data), (pe),
(Generic,
if( pe.m_params.m_types.size() > 0 )
- MIR_TODO(*m_mir_res, "Paths with generics " << path);
+ MIR_TODO(*m_mir_res, "get_literal_for_const - Paths with generics " << path);
return m_crate.get_constant_by_path(Span(), pe.m_path).m_value_res;
),
(UfcsUnknown,
- MIR_BUG(*m_mir_res, "UfcsUnknown " << path);
+ MIR_BUG(*m_mir_res, "get_literal_for_const - UfcsUnknown " << path);
),
(UfcsKnown,
- MIR_TODO(*m_mir_res, "UfcsKnown " << path);
+ MIR_TODO(*m_mir_res, "get_literal_for_const - UfcsKnown " << path);
),
(UfcsInherent,
- MIR_TODO(*m_mir_res, "UfcsInherent " << path);
+ MIR_TODO(*m_mir_res, "get_literal_for_const - UfcsInherent " << path);
)
)
throw "";