diff options
author | John Hodge <tpg@mutabah.net> | 2018-05-24 21:07:31 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2018-05-24 21:07:31 +0800 |
commit | 704bb17db9a9610b409d729ac511976ea42514c5 (patch) | |
tree | ae000fe6f06b4b58c1ca51824d359eade00f2edb | |
parent | f360a87c6c44f1f32c21b64c7a8a6e530737cbb0 (diff) | |
download | mrust-704bb17db9a9610b409d729ac511976ea42514c5.tar.gz |
HIR - Borrow lifetime annotations included (not actually used or valid)
-rw-r--r-- | src/hir/deserialise.cpp | 11 | ||||
-rw-r--r-- | src/hir/expr.hpp | 12 | ||||
-rw-r--r-- | src/hir/serialise.cpp | 8 | ||||
-rw-r--r-- | src/hir/type.cpp | 2 | ||||
-rw-r--r-- | src/hir/type.hpp | 4 |
5 files changed, 24 insertions, 13 deletions
diff --git a/src/hir/deserialise.cpp b/src/hir/deserialise.cpp index 326debd7..902799c3 100644 --- a/src/hir/deserialise.cpp +++ b/src/hir/deserialise.cpp @@ -114,6 +114,7 @@ namespace { } + ::HIR::LifetimeRef deserialise_lifetimeref(); ::HIR::TypeRef deserialise_type(); ::HIR::SimplePath deserialise_simplepath(); ::HIR::PathParams deserialise_pathparams(); @@ -718,6 +719,11 @@ namespace { template<> DEF_D( ::HIR::ExternLibrary, return d.deserialise_extlib(); ) + ::HIR::LifetimeRef HirDeserialiser::deserialise_lifetimeref() + { + return { m_in.read_string() }; + } + ::HIR::TypeRef HirDeserialiser::deserialise_type() { ::HIR::TypeRef rv; @@ -741,13 +747,13 @@ namespace { _(TraitObject, { deserialise_traitpath(), deserialise_vec< ::HIR::GenericPath>(), - "" // TODO: m_lifetime + deserialise_lifetimeref() }) _(ErasedType, { deserialise_path(), static_cast<unsigned int>(m_in.read_count()), deserialise_vec< ::HIR::TraitPath>(), - "" // TODO: m_lifetime + deserialise_lifetimeref() }) _(Array, { deserialise_ptr< ::HIR::TypeRef>(), @@ -761,6 +767,7 @@ namespace { deserialise_vec< ::HIR::TypeRef>() ) _(Borrow, { + deserialise_lifetimeref(), static_cast< ::HIR::BorrowType>( m_in.read_tag() ), deserialise_ptr< ::HIR::TypeRef>() }) diff --git a/src/hir/expr.hpp b/src/hir/expr.hpp index 3069ae1d..33726093 100644 --- a/src/hir/expr.hpp +++ b/src/hir/expr.hpp @@ -620,16 +620,12 @@ struct ExprNode_Literal: m_res_type = ::HIR::TypeRef::Data::make_Primitive( ::HIR::CoreType::Bool ); ), (String, - m_res_type = ::HIR::TypeRef::Data::make_Borrow({ - ::HIR::BorrowType::Shared, - box$( ::HIR::TypeRef( ::HIR::TypeRef::Data::make_Primitive(::HIR::CoreType::Str) ) ) - }); + // TODO: &'static + m_res_type = ::HIR::TypeRef::new_borrow( ::HIR::BorrowType::Shared, ::HIR::TypeRef(::HIR::CoreType::Str) ); ), (ByteString, - m_res_type = ::HIR::TypeRef::Data::make_Borrow({ - ::HIR::BorrowType::Shared, - box$( ::HIR::TypeRef::new_array( ::HIR::CoreType::U8, e.size() ) ) - }); + // TODO: &'static + m_res_type = ::HIR::TypeRef::new_borrow( ::HIR::BorrowType::Shared, ::HIR::TypeRef::new_array(::HIR::CoreType::U8, e.size()) ); ) ) } diff --git a/src/hir/serialise.cpp b/src/hir/serialise.cpp index f1398aa3..c0b4a082 100644 --- a/src/hir/serialise.cpp +++ b/src/hir/serialise.cpp @@ -87,6 +87,10 @@ namespace { void serialise(uint64_t v) { m_out.write_u64c(v); }; void serialise(int64_t v) { m_out.write_i64c(v); }; + void serialise(const ::HIR::LifetimeRef& lr) + { + m_out.write_string(lr.name); + } void serialise_type(const ::HIR::TypeRef& ty) { m_out.write_tag( ty.m_data.tag() ); @@ -111,7 +115,7 @@ namespace { m_out.write_count(e.m_markers.size()); for(const auto& m : e.m_markers) serialise_genericpath(m); - //write_string(e.lifetime); // TODO: Need a better type + serialise(e.m_lifetime); ), (ErasedType, serialise_path(e.m_origin); @@ -120,6 +124,7 @@ namespace { m_out.write_count(e.m_traits.size()); for(const auto& t : e.m_traits) serialise_traitpath(t); + serialise(e.m_lifetime); ), (Array, assert(e.size_val != ~0u); @@ -135,6 +140,7 @@ namespace { serialise_type(st); ), (Borrow, + serialise(e.lifetime); m_out.write_tag(static_cast<int>(e.type)); serialise_type(*e.inner); ), diff --git a/src/hir/type.cpp b/src/hir/type.cpp index 033e7bf5..0f3ee835 100644 --- a/src/hir/type.cpp +++ b/src/hir/type.cpp @@ -860,7 +860,7 @@ bool ::HIR::TypeRef::match_test_generics(const Span& sp, const ::HIR::TypeRef& x return ::HIR::TypeRef( Data::make_Tuple(mv$(types)) ); ), (Borrow, - return ::HIR::TypeRef( Data::make_Borrow({e.type, box$(e.inner->clone())}) ); + return ::HIR::TypeRef( Data::make_Borrow({e.lifetime, e.type, box$(e.inner->clone())}) ); ), (Pointer, return ::HIR::TypeRef( Data::make_Pointer({e.type, box$(e.inner->clone())}) ); diff --git a/src/hir/type.hpp b/src/hir/type.hpp index 329af650..652abfa8 100644 --- a/src/hir/type.hpp +++ b/src/hir/type.hpp @@ -84,6 +84,7 @@ 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; bool operator==(const LifetimeRef& x) const { @@ -178,6 +179,7 @@ public: }), (Tuple, ::std::vector<TypeRef>), (Borrow, struct { + ::HIR::LifetimeRef lifetime; ::HIR::BorrowType type; ::std::unique_ptr<TypeRef> inner; }), @@ -234,7 +236,7 @@ public: return TypeRef(Data::make_Infer({idx, ty_class})); } static TypeRef new_borrow(BorrowType bt, TypeRef inner) { - return TypeRef(Data::make_Borrow({bt, box$(mv$(inner))})); + return TypeRef(Data::make_Borrow({ ::HIR::LifetimeRef(), bt, box$(mv$(inner)) })); } static TypeRef new_pointer(BorrowType bt, TypeRef inner) { return TypeRef(Data::make_Pointer({bt, box$(mv$(inner))})); |