summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2018-03-03 21:43:39 +0800
committerJohn Hodge <tpg@mutabah.net>2018-03-03 21:43:39 +0800
commit5c1cc3810b0256f295ef7e838b1874731ec0e1e0 (patch)
tree824633d53ab495395c1e5ee0d05f3bfeb2a1cb45 /src
parente44cf19bbf20ff3715ffa3e5c8d4fd4e92617825 (diff)
downloadmrust-5c1cc3810b0256f295ef7e838b1874731ec0e1e0.tar.gz
Trans Enumerate - Some work on doing selective library enumeration (has some holes, so is still disabled)
Diffstat (limited to 'src')
-rw-r--r--src/trans/codegen.cpp2
-rw-r--r--src/trans/enumerate.cpp95
2 files changed, 54 insertions, 43 deletions
diff --git a/src/trans/codegen.cpp b/src/trans/codegen.cpp
index f008a2b3..12252465 100644
--- a/src/trans/codegen.cpp
+++ b/src/trans/codegen.cpp
@@ -102,7 +102,7 @@ void Trans_Codegen(const ::std::string& outfile, const TransOptions& opt, const
codegen->emit_function_proto(ent.first, fcn, ent.second->pp, is_extern);
}
}
-
+ // - External functions
for(const auto& ent : list.m_functions)
{
//DEBUG("FUNCTION " << ent.first);
diff --git a/src/trans/enumerate.cpp b/src/trans/enumerate.cpp
index b1774041..4c91f5f3 100644
--- a/src/trans/enumerate.cpp
+++ b/src/trans/enumerate.cpp
@@ -91,53 +91,64 @@ TransList Trans_Enumerate_Main(const ::HIR::Crate& crate)
}
namespace {
- void Trans_Enumerate_Public_Mod(EnumState& state, ::HIR::Module& mod, ::HIR::SimplePath mod_path, bool is_visible)
+ void Trans_Enumerate_ValItem(EnumState& state, const ::HIR::ValueItem& vi, bool is_visible, ::std::function<::HIR::SimplePath()> get_path)
{
- // TODO: Make this configurable, and debug cases where it breaks
- // (needs to be `true` currently)
- // - Errors likely caused by re-exports making items visible that
- // aren't otherwise.
- const bool EMIT_ALL = true;
- for(auto& vi : mod.m_value_items)
+ switch(vi.tag())
{
- TU_MATCHA( (vi.second->ent), (e),
- (Import,
- // TODO: If visible, ensure that target is visited.
- ),
- (StructConstant,
- ),
- (StructConstructor,
- ),
- (Constant,
- ),
- (Static,
- if( EMIT_ALL || (is_visible && vi.second->is_public) )
- {
- // HACK: Refuse to emit unused generated statics
- // - Needed because all items are visited (regardless of
- // visibility)
- if(e.m_type.m_data.is_Infer())
- continue ;
- //state.enum_static(mod_path + vi.first, *e);
- auto* ptr = state.rv.add_static(mod_path + vi.first);
- if(ptr)
- Trans_Enumerate_FillFrom(state, e, *ptr);
- }
- ),
- (Function,
- if( e.m_params.m_types.size() == 0 )
+ case ::HIR::ValueItem::TAGDEAD: throw "";
+ TU_ARM(vi, Import, e) {
+ // TODO: If visible, ensure that target is visited.
+ if( is_visible )
+ {
+ if( ! e.is_variant && e.path.m_crate_name == state.crate.m_crate_name )
{
- if( EMIT_ALL || (is_visible && vi.second->is_public) ) {
- state.enum_fcn(mod_path + vi.first, e, {});
- }
+ const auto& vi2 = state.crate.get_valitem_by_path(Span(), e.path, false);
+ Trans_Enumerate_ValItem(state, vi2, is_visible, [&](){ return e.path; });
}
- else
- {
- const_cast<::HIR::Function&>(e).m_save_code = true;
- // TODO: If generic, enumerate concrete functions used
+ }
+ } break;
+ TU_ARM(vi, StructConstant, e) {
+ } break;
+ TU_ARM(vi, StructConstructor, e) {
+ } break;
+ TU_ARM(vi, Constant, e) {
+ } break;
+ TU_ARM(vi, Static, e) {
+ if( is_visible )
+ {
+ // HACK: Refuse to emit unused generated statics
+ // - Needed because all items are visited (regardless of
+ // visibility)
+ if(e.m_type.m_data.is_Infer())
+ continue ;
+ //state.enum_static(mod_path + vi.first, *e);
+ auto* ptr = state.rv.add_static( get_path() );
+ if(ptr)
+ Trans_Enumerate_FillFrom(state, e, *ptr);
+ }
+ } break;
+ TU_ARM(vi, Function, e) {
+ if( e.m_params.m_types.size() == 0 )
+ {
+ if( is_visible ) {
+ state.enum_fcn(get_path(), e, {});
}
- )
- )
+ }
+ else
+ {
+ const_cast<::HIR::Function&>(e).m_save_code = true;
+ // TODO: If generic, enumerate concrete functions used
+ }
+ } break;
+ }
+ }
+ void Trans_Enumerate_Public_Mod(EnumState& state, ::HIR::Module& mod, ::HIR::SimplePath mod_path, bool is_visible)
+ {
+ // TODO: Fix the TODO in Function above (scan generics for the concretes they use) and set this to false again
+ const bool EMIT_ALL = true;
+ for(auto& vi : mod.m_value_items)
+ {
+ Trans_Enumerate_ValItem(state, vi.second->ent, EMIT_ALL || (is_visible && vi.second->is_public), [&](){ return mod_path + vi.first; });
}
for(auto& ti : mod.m_mod_items)