summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-12-01 19:05:14 +0800
committerJohn Hodge <tpg@mutabah.net>2016-12-01 19:05:14 +0800
commit35142acbe2deacf0cee3f92ed28e3beb01c22cd5 (patch)
tree87d07ea761ce4f4c973c417e8b0f4a6bbb1d13e0 /src
parent264bb4feab3e128db025a77f127b256ebf4f0e49 (diff)
downloadmrust-35142acbe2deacf0cee3f92ed28e3beb01c22cd5.tar.gz
Trans - Enumeration work structured out, vtables hacked in
Diffstat (limited to 'src')
-rw-r--r--src/hir/deserialise.cpp14
-rw-r--r--src/hir/from_ast.cpp3
-rw-r--r--src/hir/path.cpp20
-rw-r--r--src/hir/path.hpp7
-rw-r--r--src/hir/serialise.cpp2
-rw-r--r--src/hir/type.cpp6
-rw-r--r--src/hir/type.hpp2
-rw-r--r--src/hir_expand/main_bindings.hpp1
-rw-r--r--src/hir_expand/vtable.cpp140
-rw-r--r--src/hir_typeck/common.cpp6
-rw-r--r--src/hir_typeck/expr_cs.cpp2
-rw-r--r--src/main.cpp6
-rw-r--r--src/trans/enumerate.cpp121
-rw-r--r--src/trans/trans_list.cpp16
-rw-r--r--src/trans/trans_list.hpp4
15 files changed, 302 insertions, 48 deletions
diff --git a/src/hir/deserialise.cpp b/src/hir/deserialise.cpp
index 1880b660..649d97fd 100644
--- a/src/hir/deserialise.cpp
+++ b/src/hir/deserialise.cpp
@@ -710,19 +710,21 @@ namespace {
return ::HIR::Path( deserialise_genericpath() );
case 1:
DEBUG("Inherent");
- return ::HIR::Path {
- deserialise_type(),
+ return ::HIR::Path( ::HIR::Path::Data::Data_UfcsInherent {
+ box$( deserialise_type() ),
m_in.read_string(),
+ deserialise_pathparams(),
deserialise_pathparams()
- };
+ } );
case 2:
DEBUG("Known");
- return ::HIR::Path {
- deserialise_type(),
+ return ::HIR::Path( ::HIR::Path::Data::Data_UfcsKnown {
+ box$( deserialise_type() ),
deserialise_genericpath(),
m_in.read_string(),
+ deserialise_pathparams(),
deserialise_pathparams()
- };
+ } );
default:
throw "";
}
diff --git a/src/hir/from_ast.cpp b/src/hir/from_ast.cpp
index f03f2000..5a758354 100644
--- a/src/hir/from_ast.cpp
+++ b/src/hir/from_ast.cpp
@@ -1002,6 +1002,9 @@ namespace {
)
}
+ // TODO: If this trait is object safe, build up the vtable (and vtable type)
+ // - Or do it in a pass?
+
rv.m_is_marker = f.is_marker();
return rv;
diff --git a/src/hir/path.cpp b/src/hir/path.cpp
index 7f9d2fc9..1f80204d 100644
--- a/src/hir/path.cpp
+++ b/src/hir/path.cpp
@@ -87,10 +87,10 @@ namespace HIR {
return os << e;
),
(UfcsInherent,
- return os << "<" << *e.type << ">::" << e.item << e.params;
+ return os << "<" << *e.type << " /*- " << e.impl_params << "*/>::" << e.item << e.params;
),
(UfcsKnown,
- return os << "<" << *e.type << " as " << e.trait << ">::" << e.item << e.params;
+ return os << "<" << *e.type << " as " << e.trait << " /*- " << e.impl_params << "*/>::" << e.item << e.params;
),
(UfcsUnknown,
return os << "<" << *e.type << " as _>::" << e.item << e.params;
@@ -255,6 +255,22 @@ bool ::HIR::TraitPath::operator==(const ::HIR::TraitPath& x) const
}
return rv;
}
+::HIR::Compare HIR::PathParams::match_test_generics_fuzz(const Span& sp, const PathParams& x, t_cb_resolve_type resolve_placeholder, t_cb_match_generics match) const
+{
+ using ::HIR::Compare;
+ auto rv = Compare::Equal;
+
+ if( this->m_types.size() != x.m_types.size() ) {
+ return Compare::Unequal;
+ }
+ for( unsigned int i = 0; i < x.m_types.size(); i ++ )
+ {
+ rv &= this->m_types[i].match_test_generics_fuzz( sp, x.m_types[i], resolve_placeholder, match );
+ if( rv == Compare::Unequal )
+ return Compare::Unequal;
+ }
+ return rv;
+}
::HIR::Compare HIR::GenericPath::compare_with_placeholders(const Span& sp, const ::HIR::GenericPath& x, ::HIR::t_cb_resolve_type resolve_placeholder) const
{
using ::HIR::Compare;
diff --git a/src/hir/path.hpp b/src/hir/path.hpp
index af07e453..4e8eaef3 100644
--- a/src/hir/path.hpp
+++ b/src/hir/path.hpp
@@ -18,12 +18,15 @@ namespace HIR {
struct Trait;
-typedef ::std::function<const ::HIR::TypeRef&(const ::HIR::TypeRef&)> t_cb_resolve_type;
enum Compare {
Equal,
Fuzzy,
Unequal,
};
+
+typedef ::std::function<const ::HIR::TypeRef&(const ::HIR::TypeRef&)> t_cb_resolve_type;
+typedef ::std::function< ::HIR::Compare(unsigned int, const ::HIR::TypeRef&) > t_cb_match_generics;
+
static inline ::std::ostream& operator<<(::std::ostream& os, const Compare& x) {
switch(x)
{
@@ -105,6 +108,7 @@ struct PathParams
PathParams& operator=(PathParams&&) = default;
Compare compare_with_placeholders(const Span& sp, const PathParams& x, t_cb_resolve_type resolve_placeholder) const;
+ Compare match_test_generics_fuzz(const Span& sp, const PathParams& x, t_cb_resolve_type resolve_placeholder, t_cb_match_generics) const;
bool operator==(const PathParams& x) const;
bool operator!=(const PathParams& x) const { return !(*this == x); }
@@ -215,6 +219,7 @@ public:
bool operator==(const Path& x) const;
bool operator!=(const Path& x) const { return !(*this == x); }
+ bool operator<(const Path& x) const { return ord(x) == OrdLess; }
friend ::std::ostream& operator<<(::std::ostream& os, const Path& x);
};
diff --git a/src/hir/serialise.cpp b/src/hir/serialise.cpp
index bf28a53f..d372585c 100644
--- a/src/hir/serialise.cpp
+++ b/src/hir/serialise.cpp
@@ -169,6 +169,7 @@ namespace {
serialise_type(*e.type);
m_out.write_string(e.item);
serialise_pathparams(e.params);
+ serialise_pathparams(e.impl_params);
),
(UfcsKnown,
m_out.write_tag(2);
@@ -176,6 +177,7 @@ namespace {
serialise_genericpath(e.trait);
m_out.write_string(e.item);
serialise_pathparams(e.params);
+ serialise_pathparams(e.impl_params);
),
(UfcsUnknown,
DEBUG("-- UfcsUnknown - " << path);
diff --git a/src/hir/type.cpp b/src/hir/type.cpp
index 1e67d60c..c5e1984a 100644
--- a/src/hir/type.cpp
+++ b/src/hir/type.cpp
@@ -581,17 +581,17 @@ bool ::HIR::TypeRef::match_test_generics(const Span& sp, const ::HIR::TypeRef& x
// HACK: If the path is Opaque, return a fuzzy match.
// - This works around an impl selection bug.
if( v.m_data.is_Path() && v.m_data.as_Path().binding.is_Opaque() ) {
- DEBUG("- Fuzzy match due to opaque");
+ DEBUG("- Fuzzy match due to opaque - " << v << " = " << x);
return Compare::Fuzzy;
}
// HACK: If RHS is unbound, fuzz it
if( x.m_data.is_Path() && x.m_data.as_Path().binding.is_Unbound() ) {
- DEBUG("- Fuzzy match due to unbound");
+ DEBUG("- Fuzzy match due to unbound - " << v << " = " << x);
return Compare::Fuzzy;
}
// HACK: If the RHS is a placeholder generic, allow it.
if( x.m_data.is_Generic() && (x.m_data.as_Generic().binding >> 8) == 2 ) {
- DEBUG("- Fuzzy match due to placeholder");
+ DEBUG("- Fuzzy match due to placeholder - " << v << " = " << x);
return Compare::Fuzzy;
}
DEBUG("- Tag mismatch " << v << " and " << x);
diff --git a/src/hir/type.hpp b/src/hir/type.hpp
index 52c77fc5..d7436607 100644
--- a/src/hir/type.hpp
+++ b/src/hir/type.hpp
@@ -23,8 +23,6 @@ struct ExprNode_Closure;
class TypeRef;
-typedef ::std::function< ::HIR::Compare(unsigned int, const ::HIR::TypeRef&) > t_cb_match_generics;
-
enum class InferClass
{
None,
diff --git a/src/hir_expand/main_bindings.hpp b/src/hir_expand/main_bindings.hpp
index 8d495c19..4a3ac160 100644
--- a/src/hir_expand/main_bindings.hpp
+++ b/src/hir_expand/main_bindings.hpp
@@ -12,6 +12,7 @@ namespace HIR {
};
extern void HIR_Expand_AnnotateUsage(::HIR::Crate& crate);
+extern void HIR_Expand_VTables(::HIR::Crate& crate);
extern void HIR_Expand_Closures(::HIR::Crate& crate);
extern void HIR_Expand_UfcsEverything(::HIR::Crate& crate);
extern void HIR_Expand_Reborrows(::HIR::Crate& crate);
diff --git a/src/hir_expand/vtable.cpp b/src/hir_expand/vtable.cpp
new file mode 100644
index 00000000..41869397
--- /dev/null
+++ b/src/hir_expand/vtable.cpp
@@ -0,0 +1,140 @@
+/*
+ * MRustC - Rust Compiler
+ * - By John Hodge (Mutabah/thePowersGang)
+ *
+ * hir_expand/vtable.cpp
+ * - VTable Generation
+ */
+#include "main_bindings.hpp"
+#include <hir/hir.hpp>
+#include <hir/visitor.hpp>
+#include <hir_typeck/common.hpp> // visit_ty_with
+#include <algorithm> // ::std::any_of
+
+namespace {
+ class OuterVisitor:
+ public ::HIR::Visitor
+ {
+ //StaticTraitResolve m_resolve;
+ ::std::function<::HIR::SimplePath(bool, ::std::string, ::HIR::Struct)> m_new_type;
+ ::HIR::SimplePath m_lang_Sized;
+ public:
+ OuterVisitor(const ::HIR::Crate& crate)//:
+ //m_resolve(crate)
+ {
+ m_lang_Sized = crate.get_lang_item_path_opt("sized");
+ }
+
+ void visit_module(::HIR::ItemPath p, ::HIR::Module& mod) override
+ {
+ auto saved_nt = mv$(m_new_type);
+
+ ::std::vector< decltype(mod.m_mod_items)::value_type> new_types;
+ m_new_type = [&](bool pub, auto name, auto s)->auto {
+ auto boxed = box$( (::HIR::VisEnt< ::HIR::TypeItem> { pub, ::HIR::TypeItem( mv$(s) ) }) );
+ auto ret = (p + name).get_simple_path();
+ new_types.push_back( ::std::make_pair( mv$(name), mv$(boxed)) );
+ return ret;
+ };
+
+ ::HIR::Visitor::visit_module(p, mod);
+ for(auto& i : new_types )
+ mod.m_mod_items.insert( mv$(i) );
+
+ m_new_type = mv$(saved_nt);
+ }
+
+ void visit_trait(::HIR::ItemPath p, ::HIR::Trait& tr) override
+ {
+ TRACE_FUNCTION_F(p);
+
+ ::HIR::t_struct_fields fields;
+ for(const auto& vi : tr.m_values)
+ {
+ TU_MATCHA( (vi.second), (ve),
+ (Function,
+ if( ve.m_receiver == ::HIR::Function::Receiver::Free ) {
+ DEBUG("- '" << vi.first << "' Skip free function"); // ?
+ continue ;
+ }
+ if( ::std::any_of(ve.m_params.m_bounds.begin(), ve.m_params.m_bounds.end(), [&](const auto& b){
+ return b.is_TraitBound() && b.as_TraitBound().type == ::HIR::TypeRef("Self", 0xFFFF) && b.as_TraitBound().trait.m_path.m_path == m_lang_Sized;
+ }) )
+ {
+ DEBUG("- '" << vi.first << "' Skip where `Self: Sized`");
+ continue ;
+ }
+ if( ve.m_params.m_types.size() > 0 ) {
+ DEBUG("- '" << vi.first << "' NOT object safe (generic), not creating vtable");
+ return ;
+ }
+
+ ::HIR::FunctionType ft;
+ ft.is_unsafe = ve.m_unsafe;
+ ft.m_abi = ve.m_abi;
+ ft.m_rettype = box$( ve.m_return.clone() );
+ for(const auto& t : ve.m_args)
+ ft.m_arg_types.push_back( t.second.clone() );
+ ft.m_arg_types[0] = ::HIR::TypeRef(); // Clear the first argument (the receiver)
+ ::HIR::TypeRef fcn_type( mv$(ft) );
+
+ // Detect use of `Self`
+ if( visit_ty_with(fcn_type, [&](const auto& t){
+ if( t == ::HIR::TypeRef("Self", 0xFFFF) )
+ return true;
+ return false;
+ })
+ )
+ {
+ DEBUG("- '" << vi.first << "' NOT object safe (Self), not creating vtable");
+ return ;
+ }
+
+ fields.push_back( ::std::make_pair(
+ vi.first,
+ ::HIR::VisEnt< ::HIR::TypeRef> { true, mv$(fcn_type) }
+ ) );
+ ),
+ (Static,
+ TODO(Span(), "Associated static in vtable");
+ ),
+ (Constant,
+ //TODO(Span(), "Associated const in vtable");
+ )
+ )
+ }
+
+ ::HIR::PathParams params;
+ ::HIR::GenericParams args;
+ // TODO: Would like to have access to the publicity marker
+ auto item_path = m_new_type(true, FMT(p.get_name() << "#vtable"), ::HIR::Struct {
+ mv$(args),
+ ::HIR::Struct::Repr::Rust,
+ ::HIR::Struct::Data(mv$(fields)),
+ {}
+ });
+ DEBUG("Vtable structure created - " << item_path);
+ ::HIR::GenericPath path( mv$(item_path), mv$(params) );
+
+ tr.m_values.insert( ::std::make_pair(
+ "#vtable",
+ ::HIR::TraitValueItem(::HIR::Static { false, ::HIR::TypeRef( mv$(path) ), {},{} })
+ ) );
+ }
+
+ void visit_trait_impl(const ::HIR::SimplePath& trait_path, ::HIR::TraitImpl& impl) override
+ {
+ TRACE_FUNCTION_F("impl " << trait_path << " for " << impl.m_type);
+ //auto _ = this->m_resolve.set_impl_generics(impl.m_params);
+
+ ::HIR::Visitor::visit_trait_impl(trait_path, impl);
+ }
+ };
+}
+
+void HIR_Expand_VTables(::HIR::Crate& crate)
+{
+ OuterVisitor ov(crate);
+ ov.visit_crate( crate );
+}
+
diff --git a/src/hir_typeck/common.cpp b/src/hir_typeck/common.cpp
index 742f22c4..865604d8 100644
--- a/src/hir_typeck/common.cpp
+++ b/src/hir_typeck/common.cpp
@@ -177,7 +177,8 @@ bool monomorphise_type_needed(const ::HIR::TypeRef& tpl)
box$( clone_ty_with(sp, *e2.type, callback) ),
clone_ty_with__generic_path(sp, e2.trait, callback),
e2.item,
- clone_ty_with__path_params(sp, e2.params, callback)
+ clone_ty_with__path_params(sp, e2.params, callback),
+ clone_ty_with__path_params(sp, e2.impl_params, callback)
});
),
(UfcsUnknown,
@@ -191,7 +192,8 @@ bool monomorphise_type_needed(const ::HIR::TypeRef& tpl)
return ::HIR::Path::Data::make_UfcsInherent({
box$( clone_ty_with(sp, *e2.type, callback) ),
e2.item,
- clone_ty_with__path_params(sp, e2.params, callback)
+ clone_ty_with__path_params(sp, e2.params, callback),
+ clone_ty_with__path_params(sp, e2.impl_params, callback)
});
)
)
diff --git a/src/hir_typeck/expr_cs.cpp b/src/hir_typeck/expr_cs.cpp
index 98dcada2..22a30977 100644
--- a/src/hir_typeck/expr_cs.cpp
+++ b/src/hir_typeck/expr_cs.cpp
@@ -1732,7 +1732,7 @@ namespace {
// If the impl block has parameters, figure out what types they map to
// - The function params are already mapped (from fix_param_count)
- ::HIR::PathParams impl_params;
+ auto& impl_params = e.impl_params;
if( impl_ptr->m_params.m_types.size() > 0 ) {
impl_params.m_types.resize( impl_ptr->m_params.m_types.size() );
impl_ptr->m_type.match_generics(sp, *e.type, this->context.m_ivars.callback_resolve_infer(), [&](auto idx, const auto& ty) {
diff --git a/src/main.cpp b/src/main.cpp
index 530717ae..23593abd 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -22,6 +22,7 @@
#include "hir_typeck/main_bindings.hpp"
#include "hir_expand/main_bindings.hpp"
#include "mir/main_bindings.hpp"
+#include "trans/main_bindings.hpp"
#include "expand/cfg.hpp"
@@ -340,6 +341,8 @@ int main(int argc, char *argv[])
CompilePhaseV("Expand HIR Closures", [&]() {
HIR_Expand_Closures(*hir_crate);
});
+ // - Construct VTables for all traits and impls.
+ CompilePhaseV("Expand HIR VTables", [&]() { HIR_Expand_VTables(*hir_crate); });
// - And calls can be turned into UFCS
CompilePhaseV("Expand HIR Calls", [&]() {
HIR_Expand_UfcsEverything(*hir_crate);
@@ -420,6 +423,9 @@ int main(int argc, char *argv[])
break;
case ::AST::Crate::Type::Executable:
// Generate a binary
+ CompilePhaseV("Trans Enumerate", [&]() {
+ Trans_Enumerate_Main(*hir_crate);
+ });
//HIR_Codegen_Main(params.outfile + ".o", *hir_crate);
break;
}
diff --git a/src/trans/enumerate.cpp b/src/trans/enumerate.cpp
index 33a9867c..677b0634 100644
--- a/src/trans/enumerate.cpp
+++ b/src/trans/enumerate.cpp
@@ -17,6 +17,7 @@ struct Params {
Span sp;
::HIR::PathParams pp_method;
::HIR::PathParams pp_impl;
+ ::HIR::TypeRef self_type;
t_cb_generic get_cb() const;
::HIR::TypeRef monomorph(const ::HIR::TypeRef& p) const;
@@ -126,7 +127,7 @@ namespace {
)
BUG(sp, "Path " << path << " pointed to a invalid item - " << it->second->ent.tag_str());
}
- EntPtr get_ent_fullpath(const Span& sp, const ::HIR::Crate& crate, const ::HIR::Path& path)
+ EntPtr get_ent_fullpath(const Span& sp, const ::HIR::Crate& crate, const ::HIR::Path& path, ::HIR::PathParams& impl_pp)
{
TU_MATCH(::HIR::Path::Data, (path.m_data), (e),
(Generic,
@@ -159,29 +160,94 @@ namespace {
),
(UfcsKnown,
EntPtr rv;
+
+ // Obtain trait pointer (for default impl and to know what the item type is)
+ const auto& trait_ref = crate.get_trait_by_path(sp, e.trait.m_path);
+ auto trait_vi_it = trait_ref.m_values.find(e.item);
+ ASSERT_BUG(sp, trait_vi_it != trait_ref.m_values.end(), "Couldn't find item " << e.item << " in trait " << e.trait.m_path);
+ const auto& trait_vi = trait_vi_it->second;
+
+
+ if( e.item == "#vtable" ) {
+ return EntPtr{};
+ }
+
+ ::std::vector<const ::HIR::TypeRef*> best_impl_params;
+ const ::HIR::TraitImpl* best_impl = nullptr;
crate.find_trait_impls(e.trait.m_path, *e.type, [](const auto&x)->const auto& { return x; }, [&](const auto& impl) {
- // Hacky selection of impl.
- // - TODO: Specialisation
- {
- auto fit = impl.m_methods.find(e.item);
- if( fit != impl.m_methods.end() )
- {
- DEBUG("Found impl" << impl.m_params.fmt_args() << " " << impl.m_type);
- rv = EntPtr { &fit->second.data };
- return true;
+
+ ::std::vector<const ::HIR::TypeRef*> impl_params;
+
+ auto cb_ident = [](const auto& t)->const auto& { return t; };
+ auto cb = [&impl_params,&sp,cb_ident](auto idx, const auto& ty) {
+ assert( idx < impl_params.size() );
+ if( ! impl_params[idx] ) {
+ impl_params[idx] = &ty;
+ return ::HIR::Compare::Equal;
}
+ else {
+ return impl_params[idx]->compare_with_placeholders(sp, ty, cb_ident);
+ }
+ };
+ impl_params.resize(impl.m_params.m_types.size());
+ auto match = impl.m_type.match_test_generics_fuzz(sp, *e.type, cb_ident, cb);
+ match &= impl.m_trait_args.match_test_generics_fuzz(sp, e.trait.m_params, cb_ident, cb);
+ if( match != ::HIR::Compare::Equal )
+ return false;
+
+ if( best_impl == nullptr || impl.more_specific_than(*best_impl) ) {
+ best_impl = &impl;
+ bool is_spec = false;
+ TU_MATCHA( (trait_vi), (ve),
+ (Constant, ),
+ (Static,
+ //auto it = impl.m_statics.find(e.item);
+ //if( it == impl.m_statics.end() ) {
+ // DEBUG("Static " << e.item << " missing in trait " << e.trait << " for " << *e.type);
+ // return false;
+ //}
+ //is_spec = it->second.is_specialisable;
+ ),
+ (Function,
+ auto fit = impl.m_methods.find(e.item);
+ if( fit == impl.m_methods.end() ) {
+ DEBUG("Method " << e.item << " missing in trait " << e.trait << " for " << *e.type);
+ return false;
+ }
+ is_spec = fit->second.is_specialisable;
+ )
+ )
+ best_impl_params = mv$( impl_params );
+ return !is_spec;
}
- //{
- // auto it = impl.m_constants.find(e.item);
- // if( it != impl.m_constants.end() )
- // {
- // rv = EntPtr { &it->second.data };
- // return true;
- // }
- //}
return false;
});
- return rv;
+ if( !best_impl )
+ return EntPtr {};
+ const auto& impl = *best_impl;
+
+ for(const auto* ty_ptr : best_impl_params) {
+ assert( ty_ptr );
+ impl_pp.m_types.push_back( ty_ptr->clone() );
+ }
+
+ TU_MATCHA( (trait_vi), (ve),
+ (Constant, TODO(sp, "Associated constant"); ),
+ (Static,
+ TODO(sp, "Associated static - " << path);
+ ),
+ (Function,
+ auto fit = impl.m_methods.find(e.item);
+ if( fit != impl.m_methods.end() )
+ {
+ DEBUG("Found impl" << impl.m_params.fmt_args() << " " << impl.m_type);
+ return EntPtr { &fit->second.data };
+ }
+ impl_pp = e.trait.m_params.clone();
+ return EntPtr { &ve };
+ )
+ )
+ BUG(sp, "");
),
(UfcsUnknown,
// TODO: Are these valid at this point in compilation?
@@ -202,10 +268,10 @@ void Trans_Enumerate_FillFrom_Path(TransList& out, const ::HIR::Crate& crate, co
sub_pp = Params { sp, pe.m_params.clone() };
),
(UfcsKnown,
- sub_pp = Params { sp, pe.params.clone(), pe.impl_params.clone() };
+ sub_pp = Params { sp, pe.params.clone(), pe.impl_params.clone(), pe.type->clone() };
),
(UfcsInherent,
- sub_pp = Params { sp, pe.params.clone(), pe.impl_params.clone() };
+ sub_pp = Params { sp, pe.params.clone(), pe.impl_params.clone(), pe.type->clone() };
),
(UfcsUnknown,
BUG(sp, "UfcsUnknown - " << path);
@@ -213,9 +279,10 @@ void Trans_Enumerate_FillFrom_Path(TransList& out, const ::HIR::Crate& crate, co
)
// Get the item type
// - Valid types are Function and Static
- auto item_ref = get_ent_fullpath(sp, crate, path_mono);
+ auto item_ref = get_ent_fullpath(sp, crate, path_mono, sub_pp.pp_impl);
TU_MATCHA( (item_ref), (e),
(NotFound,
+ // TODO: This should be an error... but vtable generation?
),
(Function,
// Add this path (monomorphised) to the queue
@@ -360,16 +427,20 @@ void Trans_Enumerate_FillFrom_MIR(TransList& out, const ::HIR::Crate& crate, con
void Trans_Enumerate_FillFrom(TransList& out, const ::HIR::Crate& crate, const ::HIR::Function& function, Params pp)
{
- Trans_Enumerate_FillFrom_MIR(out, crate, *function.m_code.m_mir, pp);
+ TRACE_FUNCTION_F("Function pp=" << pp.pp_method<<"+"<<pp.pp_impl);
+ if( function.m_code.m_mir )
+ Trans_Enumerate_FillFrom_MIR(out, crate, *function.m_code.m_mir, pp);
}
void Trans_Enumerate_FillFrom(TransList& out, const ::HIR::Crate& crate, const ::HIR::Static& item, Params pp)
{
- Trans_Enumerate_FillFrom_MIR(out, crate, *item.m_value.m_mir, pp);
+ TRACE_FUNCTION;
+ if( item.m_value.m_mir )
+ Trans_Enumerate_FillFrom_MIR(out, crate, *item.m_value.m_mir, pp);
}
t_cb_generic Params::get_cb() const
{
- return monomorphise_type_get_cb(sp, nullptr, &pp_impl, &pp_method);
+ return monomorphise_type_get_cb(sp, &self_type, &pp_impl, &pp_method);
}
::HIR::Path Params::monomorph(const ::HIR::Path& p) const
{
diff --git a/src/trans/trans_list.cpp b/src/trans/trans_list.cpp
index 4df20373..460a0e56 100644
--- a/src/trans/trans_list.cpp
+++ b/src/trans/trans_list.cpp
@@ -9,11 +9,19 @@
bool TransList::add_function(::HIR::Path p, const ::HIR::Function& f)
{
- TODO(Span(), "");
- return false;
+ auto rv = m_functions.insert( ::std::make_pair(mv$(p), &f) );
+ if( rv.second )
+ {
+ DEBUG("Function " << rv.first->first);
+ }
+ return rv.second;
}
bool TransList::add_static(::HIR::Path p, const ::HIR::Static& f)
{
- TODO(Span(), "");
- return false;
+ auto rv = m_statics.insert( ::std::make_pair(mv$(p), &f) );
+ if( rv.second )
+ {
+ DEBUG("Static " << rv.first->first);
+ }
+ return rv.second;
}
diff --git a/src/trans/trans_list.hpp b/src/trans/trans_list.hpp
index 9e2476b2..6feadb05 100644
--- a/src/trans/trans_list.hpp
+++ b/src/trans/trans_list.hpp
@@ -17,8 +17,8 @@ class Static;
class TransList
{
- ::std::vector< ::std::pair<::HIR::Path, const ::HIR::Function*> > m_functions;
- ::std::vector< ::std::pair<::HIR::Path, const ::HIR::Static*> > m_statics;
+ ::std::map< ::HIR::Path, const ::HIR::Function* > m_functions;
+ ::std::map< ::HIR::Path, const ::HIR::Static* > m_statics;
public:
bool add_function(::HIR::Path p, const ::HIR::Function& f);
bool add_static(::HIR::Path p, const ::HIR::Static& s);