summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-08-01 12:43:13 +0800
committerJohn Hodge <tpg@mutabah.net>2016-08-01 12:43:13 +0800
commite90c190be7c3f62e666618de9a75ae3da4325763 (patch)
tree3173cd945264bd8a06083f498e6b113fe1335770
parent4326517b27cc4492aed4145c4c855e4991740e33 (diff)
downloadmrust-e90c190be7c3f62e666618de9a75ae3da4325763.tar.gz
HIR - Include specialisable marker in impls
-rw-r--r--src/hir/from_ast.cpp14
-rw-r--r--src/hir/hir.hpp21
-rw-r--r--src/hir/visitor.cpp8
-rw-r--r--src/hir_conv/constant_evaluation.cpp4
-rw-r--r--src/hir_typeck/expr_cs.cpp4
-rw-r--r--src/hir_typeck/expr_simple.cpp6
-rw-r--r--src/hir_typeck/helpers.cpp5
-rw-r--r--src/hir_typeck/static.cpp7
8 files changed, 42 insertions, 27 deletions
diff --git a/src/hir/from_ast.cpp b/src/hir/from_ast.cpp
index 30b23900..c0954507 100644
--- a/src/hir/from_ast.cpp
+++ b/src/hir/from_ast.cpp
@@ -969,9 +969,9 @@ void LowerHIR_Module_Impls(const ::AST::Module& ast_mod, ::HIR::Crate& hir_crat
}
else
{
- ::std::map< ::std::string, ::HIR::Function> methods;
- ::std::map< ::std::string, ::HIR::ExprPtr> constants;
- ::std::map< ::std::string, ::HIR::TypeRef> types;
+ ::std::map< ::std::string, ::HIR::TraitImpl::ImplEnt< ::HIR::Function> > methods;
+ ::std::map< ::std::string, ::HIR::TraitImpl::ImplEnt< ::HIR::ExprPtr> > constants;
+ ::std::map< ::std::string, ::HIR::TraitImpl::ImplEnt< ::HIR::TypeRef> > types;
for(const auto& item : impl.items())
{
@@ -981,10 +981,10 @@ void LowerHIR_Module_Impls(const ::AST::Module& ast_mod, ::HIR::Crate& hir_crat
),
// TODO: Associated constants
(Type,
- types.insert( ::std::make_pair(item.name, LowerHIR_Type(e.type())) );
+ types.insert( ::std::make_pair(item.name, ::HIR::TraitImpl::ImplEnt< ::HIR::TypeRef> { item.is_specialisable, LowerHIR_Type(e.type()) }) );
),
(Function,
- methods.insert( ::std::make_pair(item.name, LowerHIR_Function(e)) );
+ methods.insert( ::std::make_pair(item.name, ::HIR::TraitImpl::ImplEnt< ::HIR::Function> { item.is_specialisable, LowerHIR_Function(e) }) );
)
)
}
@@ -1005,7 +1005,7 @@ void LowerHIR_Module_Impls(const ::AST::Module& ast_mod, ::HIR::Crate& hir_crat
else
{
// Inherent impls
- ::std::map< ::std::string, ::HIR::Function> methods;
+ ::std::map< ::std::string, ::HIR::TypeImpl::VisImplEnt< ::HIR::Function> > methods;
for(const auto& item : impl.items())
{
@@ -1014,7 +1014,7 @@ void LowerHIR_Module_Impls(const ::AST::Module& ast_mod, ::HIR::Crate& hir_crat
ERROR(item.data->span, E0000, "Unexpected item type in inherent impl");
),
(Function,
- methods.insert( ::std::make_pair(item.name, LowerHIR_Function(e)) );
+ methods.insert( ::std::make_pair(item.name, ::HIR::TypeImpl::VisImplEnt< ::HIR::Function> { item.is_pub, item.is_specialisable, LowerHIR_Function(e) } ) );
)
)
}
diff --git a/src/hir/hir.hpp b/src/hir/hir.hpp
index e733f1c6..408b6390 100644
--- a/src/hir/hir.hpp
+++ b/src/hir/hir.hpp
@@ -213,10 +213,17 @@ TAGGED_UNION(ValueItem, Import,
class TypeImpl
{
public:
+ template<typename T>
+ struct VisImplEnt {
+ bool is_pub;
+ bool is_specialisable;
+ T data;
+ };
+
::HIR::GenericParams m_params;
::HIR::TypeRef m_type;
- ::std::map< ::std::string, ::HIR::Function> m_methods;
+ ::std::map< ::std::string, VisImplEnt< ::HIR::Function> > m_methods;
::HIR::SimplePath m_src_module;
@@ -229,13 +236,19 @@ public:
class TraitImpl
{
public:
+ template<typename T>
+ struct ImplEnt {
+ bool is_specialisable;
+ T data;
+ };
+
::HIR::GenericParams m_params;
::HIR::PathParams m_trait_args;
::HIR::TypeRef m_type;
- ::std::map< ::std::string, ::HIR::Function> m_methods;
- ::std::map< ::std::string, ::HIR::ExprPtr> m_constants;
- ::std::map< ::std::string, ::HIR::TypeRef> m_types;
+ ::std::map< ::std::string, ImplEnt< ::HIR::Function> > m_methods;
+ ::std::map< ::std::string, ImplEnt< ::HIR::ExprPtr> > m_constants;
+ ::std::map< ::std::string, ImplEnt< ::HIR::TypeRef> > m_types;
::HIR::SimplePath m_src_module;
diff --git a/src/hir/visitor.cpp b/src/hir/visitor.cpp
index 6d3e7f9a..7c2a1245 100644
--- a/src/hir/visitor.cpp
+++ b/src/hir/visitor.cpp
@@ -95,7 +95,7 @@ void ::HIR::Visitor::visit_type_impl(::HIR::TypeImpl& impl)
for(auto& method : impl.m_methods) {
DEBUG("method " << method.first);
- this->visit_function(p + method.first, method.second);
+ this->visit_function(p + method.first, method.second.data);
}
}
void ::HIR::Visitor::visit_trait_impl(const ::HIR::SimplePath& trait_path, ::HIR::TraitImpl& impl)
@@ -113,15 +113,15 @@ void ::HIR::Visitor::visit_trait_impl(const ::HIR::SimplePath& trait_path, ::HIR
for(auto& ent : impl.m_methods) {
DEBUG("method " << ent.first);
- this->visit_function(p + ent.first, ent.second);
+ this->visit_function(p + ent.first, ent.second.data);
}
for(auto& ent : impl.m_constants) {
DEBUG("const " << ent.first);
- this->visit_expr(ent.second);
+ this->visit_expr(ent.second.data);
}
for(auto& ent : impl.m_types) {
DEBUG("type " << ent.first);
- this->visit_type(ent.second);
+ this->visit_type(ent.second.data);
}
}
void ::HIR::Visitor::visit_marker_impl(const ::HIR::SimplePath& trait_path, ::HIR::MarkerImpl& impl)
diff --git a/src/hir_conv/constant_evaluation.cpp b/src/hir_conv/constant_evaluation.cpp
index 286981f7..c5d9029c 100644
--- a/src/hir_conv/constant_evaluation.cpp
+++ b/src/hir_conv/constant_evaluation.cpp
@@ -127,7 +127,7 @@ namespace {
auto fit = impl.m_methods.find(e.item);
if( fit == impl.m_methods.end() )
continue ;
- return &fit->second;
+ return &fit->second.data;
} break;
case EntType::Struct:
break;
@@ -364,7 +364,7 @@ namespace {
// ERROR(node.span(), E0000, "Calling non-const function in const context - " << node.m_path);
//}
if( fcn.m_args.size() != node.m_args.size() ) {
- ERROR(node.span(), E0000, "Incorrect argument count for " << node.m_path);
+ ERROR(node.span(), E0000, "Incorrect argument count for " << node.m_path << " - expected " << fcn.m_args.size() << ", got " << node.m_args.size());
}
for(unsigned int i = 0; i < fcn.m_args.size(); i ++ )
{
diff --git a/src/hir_typeck/expr_cs.cpp b/src/hir_typeck/expr_cs.cpp
index 72b4e9a8..431e8807 100644
--- a/src/hir_typeck/expr_cs.cpp
+++ b/src/hir_typeck/expr_cs.cpp
@@ -232,7 +232,7 @@ namespace {
auto it = impl.m_methods.find(e.item);
if( it == impl.m_methods.end() )
return false;
- fcn_ptr = &it->second;
+ fcn_ptr = &it->second.data;
impl_ptr = &impl;
return true;
});
@@ -1159,7 +1159,7 @@ namespace {
auto it = impl.m_methods.find(e.item);
if( it == impl.m_methods.end() )
return false;
- fcn_ptr = &it->second;
+ fcn_ptr = &it->second.data;
impl_ptr = &impl;
return true;
});
diff --git a/src/hir_typeck/expr_simple.cpp b/src/hir_typeck/expr_simple.cpp
index 5b6c40b9..49bfdccc 100644
--- a/src/hir_typeck/expr_simple.cpp
+++ b/src/hir_typeck/expr_simple.cpp
@@ -818,7 +818,7 @@ namespace typeck {
if( impl_ptr )
{
assert(impl_ptr->m_types.count("Output") != 0);
- const auto& type = impl_ptr->m_types.at("Output");
+ const ::HIR::TypeRef& type = impl_ptr->m_types.at("Output").data;
if( monomorphise_type_needed(type) ) {
TODO(node.span(), "BinOp output = " << type);
}
@@ -1281,7 +1281,7 @@ namespace typeck {
auto it = impl.m_methods.find(e.item);
if( it == impl.m_methods.end() )
return false;
- fcn_ptr = &it->second;
+ fcn_ptr = &it->second.data;
impl_ptr = &impl;
return true;
});
@@ -1702,7 +1702,7 @@ namespace typeck {
auto it = impl.m_methods.find(e.item);
if( it == impl.m_methods.end() )
return false;
- fcn_ptr = &it->second;
+ fcn_ptr = &it->second.data;
impl_ptr = &impl;
return true;
});
diff --git a/src/hir_typeck/helpers.cpp b/src/hir_typeck/helpers.cpp
index a4cdccda..a19a9761 100644
--- a/src/hir_typeck/helpers.cpp
+++ b/src/hir_typeck/helpers.cpp
@@ -1922,7 +1922,7 @@ bool TraitResolution::find_trait_impls_crate(const Span& sp,
::std::map< ::std::string, ::HIR::TypeRef> types;
for( const auto& aty : impl.m_types )
{
- types.insert( ::std::make_pair(aty.first, this->expand_associated_types(sp, monomorphise_type_with(sp, aty.second, monomorph))) );
+ types.insert( ::std::make_pair(aty.first, this->expand_associated_types(sp, monomorphise_type_with(sp, aty.second.data, monomorph))) );
}
// TODO: Ensure that there are no-longer any magic params
@@ -2161,7 +2161,8 @@ bool TraitResolution::find_method(const Span& sp, const HIR::t_trait_list& trait
auto it = impl.m_methods.find( method_name );
if( it == impl.m_methods.end() )
continue ;
- if( it->second.m_args.size() > 0 && it->second.m_args[0].first.m_binding.m_name == "self" ) {
+ const ::HIR::Function& fcn = it->second.data;
+ if( fcn.m_args.size() > 0 && fcn.m_args[0].first.m_binding.m_name == "self" ) {
DEBUG("Matching `impl" << impl.m_params.fmt_args() << " " << impl.m_type << "`"/* << " - " << top_ty*/);
fcn_path = ::HIR::Path( ::HIR::Path::Data::make_UfcsInherent({
box$(ty.clone()),
diff --git a/src/hir_typeck/static.cpp b/src/hir_typeck/static.cpp
index a3bd3b27..7b5e5cd8 100644
--- a/src/hir_typeck/static.cpp
+++ b/src/hir_typeck/static.cpp
@@ -682,7 +682,8 @@ bool ImplRef::type_is_specializable(const char* name) const
auto it = e.impl->m_types.find(name);
if( it == e.impl->m_types.end() )
return ::HIR::TypeRef();
- if( monomorphise_type_needed(it->second) ) {
+ const ::HIR::TypeRef& tpl_ty = it->second.data;
+ if( monomorphise_type_needed(tpl_ty) ) {
auto cb_monomorph = [&](const auto& gt)->const auto& {
const auto& ge = gt.m_data.as_Generic();
assert(ge.binding < 256);
@@ -697,10 +698,10 @@ bool ImplRef::type_is_specializable(const char* name) const
BUG(Span(), "Param #" << ge.binding << " " << ge.name << " isn't constrained for " << *this);
}
};
- return monomorphise_type_with(sp, it->second, cb_monomorph);
+ return monomorphise_type_with(sp, tpl_ty, cb_monomorph);
}
else {
- return it->second.clone();
+ return tpl_ty.clone();
}
),
(BoundedPtr,