diff options
| author | John Hodge <tpg@ucc.asn.au> | 2019-03-24 10:57:31 +0800 | 
|---|---|---|
| committer | John Hodge <tpg@ucc.asn.au> | 2019-03-24 10:58:24 +0800 | 
| commit | 866ae6ef036fe26026a0247decb2f8cd67aafcd9 (patch) | |
| tree | d32078c240938cf56ea9bacba4eebbccb776a8c8 | |
| parent | 5fd6eeedff9834ba03cffdb6a95d5a38b84eee12 (diff) | |
| download | mrust-866ae6ef036fe26026a0247decb2f8cd67aafcd9.tar.gz | |
HIR Macro Export - Hacky workarounds and defensive asserts with macro exports
| -rw-r--r-- | src/hir/from_ast.cpp | 6 | ||||
| -rw-r--r-- | src/hir/serialise.cpp | 1 | ||||
| -rw-r--r-- | src/macro_rules/eval.cpp | 6 | 
3 files changed, 12 insertions, 1 deletions
| diff --git a/src/hir/from_ast.cpp b/src/hir/from_ast.cpp index fb8096f7..014b744c 100644 --- a/src/hir/from_ast.cpp +++ b/src/hir/from_ast.cpp @@ -1834,6 +1834,9 @@ public:                      auto res = macros.insert( mv$(v) );                      DEBUG("- Import " << mac.name << "! (from \"" << res.first->second->m_source_crate << "\")");                  } +                else if( v.second->m_rules.empty() ) { +                    // Skip +                }                  else {                      DEBUG("- Replace " << mac.name << "! (from \"" << it->second->m_source_crate << "\") with one from \"" << v.second->m_source_crate << "\"");                      it->second = mv$( v.second ); @@ -1853,6 +1856,9 @@ public:                      auto res = macros.insert( mv$(v) );                      DEBUG("- Import " << mac.name << "! (from \"" << res.first->second->m_source_crate << "\")");                  } +                else if( v.second->m_rules.empty() ) { +                    // Skip +                }                  else {                      DEBUG("- Replace " << mac.name << "! (from \"" << it->second->m_source_crate << "\") with one from \"" << v.second->m_source_crate << "\"");                      it->second = mv$( v.second ); diff --git a/src/hir/serialise.cpp b/src/hir/serialise.cpp index e5fe8ed5..0d01ed25 100644 --- a/src/hir/serialise.cpp +++ b/src/hir/serialise.cpp @@ -400,6 +400,7 @@          void serialise(const ::MacroRules& mac)          {              //m_exported: IGNORE, should be set +            assert(mac.m_rules.size() > 0);              serialise_vec(mac.m_rules);              m_out.write_string(mac.m_source_crate);          } diff --git a/src/macro_rules/eval.cpp b/src/macro_rules/eval.cpp index 03c5609c..9caff7b8 100644 --- a/src/macro_rules/eval.cpp +++ b/src/macro_rules/eval.cpp @@ -352,8 +352,10 @@ void MacroPatternStream::if_succeeded()      TU_MATCH_HDRA( (m_simple_ents[m_cur_pos-1]), {)      default:          BUG(Span(), "Unexpected " << m_simple_ents[m_cur_pos-1]); -    TU_ARMA(If, e) +    TU_ARMA(If, e) { +        ASSERT_BUG(Span(), e.jump_target < m_simple_ents.size(), "Jump target " << e.jump_target << " out of range " << m_simple_ents.size());          m_cur_pos = e.jump_target; +        }      }      m_condition_met = true;  } @@ -1724,6 +1726,7 @@ namespace  unsigned int Macro_InvokeRules_MatchPattern(const Span& sp, const MacroRules& rules, TokenTree input, AST::Module& mod,  ParameterMappings& bound_tts)  {      TRACE_FUNCTION; +    ASSERT_BUG(sp, rules.m_rules.size() > 0, "Empty macro_rules set");      ::std::vector< ::std::pair<size_t, ::std::vector<bool>> >    matches;      for(size_t i = 0; i < rules.m_rules.size(); i ++) @@ -1812,6 +1815,7 @@ unsigned int Macro_InvokeRules_MatchPattern(const Span& sp, const MacroRules& ru      if( matches.size() == 0 )      {          // ERROR! +	// TODO: Keep track of where each arm failed.          TODO(sp, "No arm matched");      }      else | 
