summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-10-22 13:38:27 +0800
committerJohn Hodge <tpg@mutabah.net>2016-10-22 16:00:27 +0800
commit2a3fe3be8373594fcd7e46fd4d9c151c28317c9e (patch)
tree7e0557337ef10bc870d2a243b61dd3d9af65e6cd
parent5a20d91b53d7889a5be8ed9dabeccbac0371f121 (diff)
downloadmrust-2a3fe3be8373594fcd7e46fd4d9c151c28317c9e.tar.gz
HIR - Allow (partial) TraitObject with no data trait, better logging of ItemPath
-rw-r--r--src/hir/from_ast.cpp6
-rw-r--r--src/hir/hir.hpp73
-rw-r--r--src/hir/visitor.cpp14
-rw-r--r--src/hir/visitor.hpp9
-rw-r--r--src/hir_typeck/outer.cpp1
-rw-r--r--src/hir_typeck/static.cpp2
6 files changed, 26 insertions, 79 deletions
diff --git a/src/hir/from_ast.cpp b/src/hir/from_ast.cpp
index 3c7215f4..cd8be320 100644
--- a/src/hir/from_ast.cpp
+++ b/src/hir/from_ast.cpp
@@ -13,6 +13,7 @@
#include "from_ast.hpp"
#include "visitor.hpp"
#include <macro_rules/macro_rules.hpp>
+#include <hir/item_path.hpp>
::HIR::Module LowerHIR_Module(const ::AST::Module& module, ::HIR::ItemPath path, ::std::vector< ::HIR::SimplePath> traits = {});
::HIR::Function LowerHIR_Function(::HIR::ItemPath path, const ::AST::Function& f, const ::HIR::TypeRef& self_type);
@@ -724,7 +725,8 @@
v.m_trait = LowerHIR_TraitPath(ty.span(), t);
}
}
- ASSERT_BUG(ty.span(), v.m_trait.m_path.m_path.m_components.size() > 0, "TraitObject type didn't contain a data trait - " << ty);
+ // TODO: This is possible - &Send is for some reason a valid trait object
+ //ASSERT_BUG(ty.span(), v.m_trait.m_path.m_path != ::HIR::SimplePath(), "TraitObject type didn't contain a data trait - " << ty);
return ::HIR::TypeRef( ::HIR::TypeRef::Data::make_TraitObject( mv$(v) ) );
),
(Function,
@@ -1164,7 +1166,7 @@ void LowerHIR_Module_Impls(const ::AST::Module& ast_mod, ::HIR::Crate& hir_crat
{
auto type = LowerHIR_Type(impl.def().type());
- ::HIR::ItemPath path(type, trait_name);
+ ::HIR::ItemPath path(type, trait_name, trait_args);
DEBUG(path);
::std::map< ::std::string, ::HIR::TraitImpl::ImplEnt< ::HIR::Function> > methods;
diff --git a/src/hir/hir.hpp b/src/hir/hir.hpp
index 061c929b..60d0012b 100644
--- a/src/hir/hir.hpp
+++ b/src/hir/hir.hpp
@@ -390,77 +390,4 @@ public:
bool find_type_impls(const ::HIR::TypeRef& type, t_cb_resolve_type ty_res, ::std::function<bool(const ::HIR::TypeImpl&)> callback) const;
};
-class ItemPath
-{
- const ItemPath* parent;
- const ::HIR::TypeRef* ty;
- const ::HIR::SimplePath* trait;
- const char* name;
-
-public:
- ItemPath(): parent(nullptr), ty(nullptr), trait(nullptr), name(nullptr) {}
- ItemPath(const ItemPath& p, const char* n):
- parent(&p),
- ty(nullptr), trait(nullptr),
- name(n)
- {}
- ItemPath(const ::HIR::TypeRef& type):
- parent(nullptr),
- ty(&type),
- trait(nullptr),
- name(nullptr)
- {}
- ItemPath(const ::HIR::TypeRef& type, const ::HIR::SimplePath& path):
- parent(nullptr),
- ty(&type),
- trait(&path),
- name(nullptr)
- {}
- ItemPath(const ::HIR::SimplePath& path):
- parent(nullptr),
- ty(nullptr),
- trait(&path),
- name(nullptr)
- {}
-
- ::HIR::SimplePath get_simple_path() const {
- if( parent ) {
- assert(name);
- return parent->get_simple_path() + name;
- }
- else {
- assert(!name);
- return ::HIR::SimplePath();
- }
- }
- const char* get_name() const {
- return name ? name : "";
- }
-
- ItemPath operator+(const ::std::string& name) const {
- return ItemPath(*this, name.c_str());
- }
-
- friend ::std::ostream& operator<<(::std::ostream& os, const ItemPath& x) {
- if( x.parent ) {
- os << *x.parent;
- }
- if( x.name ) {
- os << "::" << x.name;
- }
- else if( x.ty ) {
- os << "<" << *x.ty;
- if( x.trait )
- os << " as " << *x.trait;
- os << ">";
- }
- else if( x.trait ) {
- os << "<* as " << *x.trait << ">";
- }
- else {
- }
- return os;
- }
-};
-
} // namespace HIR
diff --git a/src/hir/visitor.cpp b/src/hir/visitor.cpp
index 88b1be22..05e99734 100644
--- a/src/hir/visitor.cpp
+++ b/src/hir/visitor.cpp
@@ -1,4 +1,10 @@
-
+/*
+ * MRustC - Rust Compiler
+ * - By John Hodge (Mutabah/thePowersGang)
+ *
+ * hir/visitor.cpp
+ * - HIR Visitor default implementation
+ */
#include <hir/hir.hpp>
#include <hir/visitor.hpp>
@@ -104,7 +110,7 @@ void ::HIR::Visitor::visit_type_impl(::HIR::TypeImpl& impl)
}
void ::HIR::Visitor::visit_trait_impl(const ::HIR::SimplePath& trait_path, ::HIR::TraitImpl& impl)
{
- ::HIR::ItemPath p( impl.m_type, trait_path );
+ ::HIR::ItemPath p( impl.m_type, trait_path, impl.m_trait_args );
TRACE_FUNCTION_F(p);
this->visit_params(impl.m_params);
// - HACK: Create a generic path to visit (so that proper checks are performed)
@@ -282,7 +288,9 @@ void ::HIR::Visitor::visit_type(::HIR::TypeRef& ty)
(Generic,
),
(TraitObject,
- this->visit_trait_path(e.m_trait);
+ if( e.m_trait.m_path != ::HIR::SimplePath() ) {
+ this->visit_trait_path(e.m_trait);
+ }
for(auto& trait : e.m_markers) {
this->visit_generic_path(trait, ::HIR::Visitor::PathContext::TYPE);
}
diff --git a/src/hir/visitor.hpp b/src/hir/visitor.hpp
index c250bd4a..b101cbe4 100644
--- a/src/hir/visitor.hpp
+++ b/src/hir/visitor.hpp
@@ -1,8 +1,17 @@
/*
+ * MRustC - Rust Compiler
+ * - By John Hodge (Mutabah/thePowersGang)
+ *
+ * hir/visitor.hpp
+ * - HIR Outer Visitor
+ *
+ * Calls methods on each item type in the HIR (and on paths/types/patterns)
+ * Does NOT visit expression nodes
*/
#pragma once
#include <hir/hir.hpp>
+#include <hir/item_path.hpp>
namespace HIR {
diff --git a/src/hir_typeck/outer.cpp b/src/hir_typeck/outer.cpp
index c3b96036..175188ea 100644
--- a/src/hir_typeck/outer.cpp
+++ b/src/hir_typeck/outer.cpp
@@ -219,6 +219,7 @@ namespace {
(TraitBound,
// TODO: Check for an implementation of this trait
DEBUG("TODO: Check bound " << e.type << " : " << e.trait.m_path);
+ //DEBUG("- " << monomorph_type_with(sp, e.type, monomorph_cb) << " : " << monomorphise_traitpath_with(sp, e.trait, monomorph_cb));
),
(TypeEquality,
// TODO: Check that two types are equal in this case
diff --git a/src/hir_typeck/static.cpp b/src/hir_typeck/static.cpp
index a9ccad78..f6a41972 100644
--- a/src/hir_typeck/static.cpp
+++ b/src/hir_typeck/static.cpp
@@ -338,7 +338,7 @@ bool StaticTraitResolve::find_impl__check_crate(
}
if( match != ::HIR::Compare::Equal ) {
DEBUG(" > Type mismatch");
- // TODO: Support fuzzy matches for some edge cases
+ // TODO: Support fuzzy matches for some edge cases. E.g. in parts of outer typecheck?
return false;
}