diff options
author | John Hodge <tpg@mutabah.net> | 2018-05-25 19:52:39 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2018-05-25 19:52:39 +0800 |
commit | c9475a45f05f73fc669d784c1ca48c720077af31 (patch) | |
tree | fcedef8d900479dd2b74f4ffdf5716845cc80582 | |
parent | 704bb17db9a9610b409d729ac511976ea42514c5 (diff) | |
download | mrust-c9475a45f05f73fc669d784c1ca48c720077af31.tar.gz |
HIR - No more name in lifetime params
-rw-r--r-- | src/hir/deserialise.cpp | 2 | ||||
-rw-r--r-- | src/hir/path.hpp | 1 | ||||
-rw-r--r-- | src/hir/serialise.cpp | 2 | ||||
-rw-r--r-- | src/hir/type.cpp | 8 | ||||
-rw-r--r-- | src/hir/type.hpp | 42 | ||||
-rw-r--r-- | src/hir_typeck/helpers.cpp | 15 |
6 files changed, 56 insertions, 14 deletions
diff --git a/src/hir/deserialise.cpp b/src/hir/deserialise.cpp index 902799c3..6ff1988b 100644 --- a/src/hir/deserialise.cpp +++ b/src/hir/deserialise.cpp @@ -721,7 +721,7 @@ namespace { ::HIR::LifetimeRef HirDeserialiser::deserialise_lifetimeref() { - return { m_in.read_string() }; + return { m_in.read_count() }; } ::HIR::TypeRef HirDeserialiser::deserialise_type() diff --git a/src/hir/path.hpp b/src/hir/path.hpp index addfba05..206b5d5b 100644 --- a/src/hir/path.hpp +++ b/src/hir/path.hpp @@ -97,6 +97,7 @@ struct SimplePath struct PathParams { + //::std::vector<LifetimeRef> m_lifetimes; ::std::vector<TypeRef> m_types; PathParams(); diff --git a/src/hir/serialise.cpp b/src/hir/serialise.cpp index c0b4a082..b244764b 100644 --- a/src/hir/serialise.cpp +++ b/src/hir/serialise.cpp @@ -89,7 +89,7 @@ namespace { void serialise(const ::HIR::LifetimeRef& lr) { - m_out.write_string(lr.name); + m_out.write_count(lr.binding); } void serialise_type(const ::HIR::TypeRef& ty) { diff --git a/src/hir/type.cpp b/src/hir/type.cpp index 0f3ee835..6f826111 100644 --- a/src/hir/type.cpp +++ b/src/hir/type.cpp @@ -112,8 +112,8 @@ void ::HIR::TypeRef::fmt(::std::ostream& os) const } for(const auto& tr : e.m_markers) os << "+" << tr; - if( e.m_lifetime.name != "" ) - os << "+ '" << e.m_lifetime.name; + if( e.m_lifetime != LifetimeRef::new_static() ) + os << "+" << e.m_lifetime; os << ")"; ), (ErasedType, @@ -123,8 +123,8 @@ void ::HIR::TypeRef::fmt(::std::ostream& os) const os << "+"; os << tr; } - if( e.m_lifetime.name != "" ) - os << "+ '" << e.m_lifetime.name; + if( e.m_lifetime != LifetimeRef::new_static() ) + os << "+ '" << e.m_lifetime; os << "/*" << e.m_origin << "#" << e.m_index << "*/"; ), (Array, diff --git a/src/hir/type.hpp b/src/hir/type.hpp index 652abfa8..480b32c4 100644 --- a/src/hir/type.hpp +++ b/src/hir/type.hpp @@ -84,11 +84,47 @@ extern ::std::ostream& operator<<(::std::ostream& os, const BorrowType& bt); struct LifetimeRef { - // Can either reference a named parameter, or an inferred region - ::std::string name; + static const uint32_t UNKNOWN = 0; + static const uint32_t STATIC = 0xFFFF; + + // Values below 2^16 are parameters/static, values above are per-function region IDs allocated during region inferrence. + uint32_t binding = UNKNOWN; + + static LifetimeRef new_static() { + LifetimeRef rv; + rv.binding = STATIC; + return rv; + } bool operator==(const LifetimeRef& x) const { - return name == x.name; + return binding == x.binding; + } + bool operator!=(const LifetimeRef& x) const { + return !(*this == x); + } + friend ::std::ostream& operator<<(::std::ostream& os, const LifetimeRef& x) { + if( x.binding == UNKNOWN ) + { + os << "'_"; + } + else if( x.binding == STATIC ) + { + os << "'static"; + } + else if( x.binding < 0xFFFF ) + { + switch( x.binding & 0xFF00 ) + { + case 0: os << "'I" << (x.binding & 0xFF); break; + case 1: os << "'M" << (x.binding & 0xFF); break; + default: os << "'unk" << x.binding; break; + } + } + else + { + os << "'_" << (x.binding - 0x1000); + } + return os; } }; diff --git a/src/hir_typeck/helpers.cpp b/src/hir_typeck/helpers.cpp index 1a9382b6..22291123 100644 --- a/src/hir_typeck/helpers.cpp +++ b/src/hir_typeck/helpers.cpp @@ -246,11 +246,14 @@ void HMTypeInferrence::print_type(::std::ostream& os, const ::HIR::TypeRef& tr) ) ), (Borrow, + os << "&"; + if(e.lifetime != ::HIR::LifetimeRef()) + os << e.lifetime << " "; switch(e.type) { - case ::HIR::BorrowType::Shared: os << "&"; break; - case ::HIR::BorrowType::Unique: os << "&mut "; break; - case ::HIR::BorrowType::Owned: os << "&move "; break; + case ::HIR::BorrowType::Shared: os << ""; break; + case ::HIR::BorrowType::Unique: os << "mut "; break; + case ::HIR::BorrowType::Owned: os << "move "; break; } this->print_type(os, *e.inner); ), @@ -302,6 +305,8 @@ void HMTypeInferrence::print_type(::std::ostream& os, const ::HIR::TypeRef& tr) os << "+" << marker.m_path; this->print_pathparams(os, marker.m_params); } + if( e.m_lifetime != ::HIR::LifetimeRef::new_static() ) + os << "+ '" << e.m_lifetime; os << ")"; ), (ErasedType, @@ -312,8 +317,8 @@ void HMTypeInferrence::print_type(::std::ostream& os, const ::HIR::TypeRef& tr) os << "+"; os << tr; } - if( e.m_lifetime.name != "" ) - os << "+ '" << e.m_lifetime.name; + if( e.m_lifetime != ::HIR::LifetimeRef::new_static() ) + os << "+ '" << e.m_lifetime; os << "/*" << e.m_origin << "*/"; ), (Tuple, |