diff options
-rw-r--r-- | src/hir/deserialise.cpp | 2 | ||||
-rw-r--r-- | src/hir/serialise.cpp | 2 | ||||
-rw-r--r-- | src/hir_conv/bind.cpp | 2 | ||||
-rw-r--r-- | src/hir_conv/constant_evaluation.cpp | 4 | ||||
-rw-r--r-- | src/mir/dump.cpp | 2 | ||||
-rw-r--r-- | src/mir/from_hir.cpp | 2 | ||||
-rw-r--r-- | src/mir/helpers.cpp | 2 | ||||
-rw-r--r-- | src/mir/mir.cpp | 4 | ||||
-rw-r--r-- | src/mir/mir.hpp | 58 | ||||
-rw-r--r-- | src/mir/mir_builder.cpp | 8 | ||||
-rw-r--r-- | src/mir/optimise.cpp | 2 | ||||
-rw-r--r-- | src/trans/codegen_c.cpp | 2 | ||||
-rw-r--r-- | src/trans/codegen_mmir.cpp | 2 | ||||
-rw-r--r-- | src/trans/enumerate.cpp | 4 | ||||
-rw-r--r-- | src/trans/monomorphise.cpp | 2 |
15 files changed, 77 insertions, 21 deletions
diff --git a/src/hir/deserialise.cpp b/src/hir/deserialise.cpp index 9933255f..cd25a3cb 100644 --- a/src/hir/deserialise.cpp +++ b/src/hir/deserialise.cpp @@ -423,7 +423,7 @@ _(Return, {}) _(Argument, { static_cast<unsigned int>(m_in.read_count()) } ) _(Local, static_cast<unsigned int>(m_in.read_count()) ) - _(Static, deserialise_path() ) + _(Static, box$(deserialise_path()) ) _(Field, { box$( deserialise_mir_lvalue() ), static_cast<unsigned int>(m_in.read_count()) diff --git a/src/hir/serialise.cpp b/src/hir/serialise.cpp index dd81596f..e90cf995 100644 --- a/src/hir/serialise.cpp +++ b/src/hir/serialise.cpp @@ -689,7 +689,7 @@ m_out.write_count(e); ), (Static, - serialise_path(e); + serialise_path(*e); ), (Field, serialise(e.val); diff --git a/src/hir_conv/bind.cpp b/src/hir_conv/bind.cpp index a3b0041b..940b2cab 100644 --- a/src/hir_conv/bind.cpp +++ b/src/hir_conv/bind.cpp @@ -712,7 +712,7 @@ namespace { (Argument, ), (Static, - upper_visitor.visit_path(e, ::HIR::Visitor::PathContext::VALUE); + upper_visitor.visit_path(*e, ::HIR::Visitor::PathContext::VALUE); ), (Field, H::visit_lvalue(upper_visitor, *e.val); diff --git a/src/hir_conv/constant_evaluation.cpp b/src/hir_conv/constant_evaluation.cpp index 6049056c..6838e186 100644 --- a/src/hir_conv/constant_evaluation.cpp +++ b/src/hir_conv/constant_evaluation.cpp @@ -319,7 +319,7 @@ namespace { return args[e.idx]; ), (Static, - MIR_TODO(state, "LValue::Static - " << e); + MIR_TODO(state, "LValue::Static - " << *e); ), (Field, auto& val = get_lval(*e.val); @@ -495,7 +495,7 @@ namespace { } else if( const auto* p = e.val.opt_Static() ) { // Borrow of a static, emit BorrowPath with the same path - val = ::HIR::Literal::make_BorrowPath( p->clone() ); + val = ::HIR::Literal::make_BorrowPath( (*p)->clone() ); } else { auto inner_val = local_state.read_lval(e.val); diff --git a/src/mir/dump.cpp b/src/mir/dump.cpp index 90b81d5d..ffce8abb 100644 --- a/src/mir/dump.cpp +++ b/src/mir/dump.cpp @@ -187,7 +187,7 @@ namespace { os << "_$" << e; ), (Static, - os << e; + os << *e; ), (Field, os << "("; diff --git a/src/mir/from_hir.cpp b/src/mir/from_hir.cpp index a2d0c790..912b8c78 100644 --- a/src/mir/from_hir.cpp +++ b/src/mir/from_hir.cpp @@ -2195,7 +2195,7 @@ namespace { m_builder.set_result( node.span(), mv$(tmp) ); ), (Static, - m_builder.set_result( node.span(), ::MIR::LValue::make_Static(node.m_path.clone()) ); + m_builder.set_result( node.span(), ::MIR::LValue::make_Static(box$(node.m_path.clone())) ); ), (StructConstant, // TODO: Why is this still a PathValue? diff --git a/src/mir/helpers.cpp b/src/mir/helpers.cpp index 38380fed..38388aed 100644 --- a/src/mir/helpers.cpp +++ b/src/mir/helpers.cpp @@ -82,7 +82,7 @@ const ::HIR::TypeRef& ::MIR::TypeResolve::get_lvalue_type(::HIR::TypeRef& tmp, c return m_fcn.locals.at(e); ), (Static, - return get_static_type(tmp, e); + return get_static_type(tmp, *e); ), (Field, const auto& ty = this->get_lvalue_type(tmp, *e.val); diff --git a/src/mir/mir.cpp b/src/mir/mir.cpp index ee6c1a6c..657e695d 100644 --- a/src/mir/mir.cpp +++ b/src/mir/mir.cpp @@ -104,7 +104,7 @@ namespace MIR { os << "Local(" << e << ")"; ), (Static, - os << "Static(" << e << ")"; + os << "Static(" << *e << ")"; ), (Field, os << "Field(" << e.field_index << ", " << *e.val << ")"; @@ -543,7 +543,7 @@ namespace MIR { (Return, return LValue(e); ), (Argument, return LValue(e); ), (Local, return LValue(e); ), - (Static, return LValue(e.clone()); ), + (Static, return LValue(box$(e->clone())); ), (Field, return LValue::make_Field({ box$( e.val->clone() ), e.field_index diff --git a/src/mir/mir.hpp b/src/mir/mir.hpp index 31eb9cd7..6969225d 100644 --- a/src/mir/mir.hpp +++ b/src/mir/mir.hpp @@ -17,6 +17,62 @@ namespace MIR { typedef unsigned int RegionId; typedef unsigned int BasicBlockId; +#if 0 +// TODO: Store LValues as: +// - A packed root value (one word, using the low bits as an enum descriminator) +// - A list of (inner to outer) wrappers +struct LValue +{ + class Storage + { + uintptr_t val; + public: + ~Storage() + { + if( is_Static() ) { + delete reinterpret_cast<::HIR::Path*>(val & ~3u); + val = 0; + } + } + bool is_Argument() const { return val != (MAX_ARG << 2) && (val & 3) == 0; } + bool is_Return() const { return val == (MAX_ARG << 2); } + bool is_Local() const { return (val & 3) == 1; } + bool is_Static() const { return (val & 3) == 2; } + + const ::HIR::Path& as_Static() const { assert(is_Static()); return *reinterpret_cast<const ::HIR::Path*>(val & ~3u); } + }; + class Wrapper + { + uintptr_t val; + public: + bool is_Deref() const { return (val & 3) == 0; } + // Stores the field index + bool is_Field() const { return (val & 3) == 1; } + // Stores the variant index + bool is_Downcast() const { return (val & 3) == 2; } + // Stores a Local index + bool is_Index() const { return (val & 3) == 3; } + + const unsigned as_Field() const { assert(is_Field()); return (val >> 2); } + const unsigned as_Index() const { assert(is_Index()); return (val >> 2); } + }; + + Storage m_root; + ::std::vector<Wrapper> m_wrappers; + + LValue clone() const; + + class Ref + { + LValue& r; + size_t wrapper_idx; + public:: + LValue clone() const; + void replace(LValue x) const; + }; +}; +#endif + // "LVALUE" - Assignable values TAGGED_UNION_EX(LValue, (), Return, ( // Function return @@ -26,7 +82,7 @@ TAGGED_UNION_EX(LValue, (), Return, ( // Variable/Temporary (Local, unsigned int), // `static` or `static mut` - (Static, ::HIR::Path), + (Static, ::std::unique_ptr<::HIR::Path>), // Field access (tuple, struct, tuple struct, enum field, ...) // NOTE: Also used to index an array/slice by a compile-time known index (e.g. in destructuring) (Field, struct { diff --git a/src/mir/mir_builder.cpp b/src/mir/mir_builder.cpp index ac1b7650..81816535 100644 --- a/src/mir/mir_builder.cpp +++ b/src/mir/mir_builder.cpp @@ -1622,20 +1622,20 @@ void MirBuilder::with_val_type(const Span& sp, const ::MIR::LValue& val, ::std:: cb( m_output.locals.at(e) ); ), (Static, - TU_MATCHA( (e.m_data), (pe), + TU_MATCHA( (e->m_data), (pe), (Generic, ASSERT_BUG(sp, pe.m_params.m_types.empty(), "Path params on static"); const auto& s = m_resolve.m_crate.get_static_by_path(sp, pe.m_path); cb( s.m_type ); ), (UfcsKnown, - TODO(sp, "Static - UfcsKnown - " << e); + TODO(sp, "Static - UfcsKnown - " << *e); ), (UfcsUnknown, - BUG(sp, "Encountered UfcsUnknown in Static - " << e); + BUG(sp, "Encountered UfcsUnknown in Static - " << *e); ), (UfcsInherent, - TODO(sp, "Static - UfcsInherent - " << e); + TODO(sp, "Static - UfcsInherent - " << *e); ) ) ), diff --git a/src/mir/optimise.cpp b/src/mir/optimise.cpp index 67a5d4a4..b7e63deb 100644 --- a/src/mir/optimise.cpp +++ b/src/mir/optimise.cpp @@ -1159,7 +1159,7 @@ bool MIR_Optimise_Inlining(::MIR::TypeResolve& state, ::MIR::Function& fcn, bool return ::MIR::LValue::make_Local(this->var_base + se); ), (Static, - return this->monomorph( se ); + return box$(this->monomorph( *se )); ), (Deref, return ::MIR::LValue::make_Deref({ box$(this->clone_lval(*se.val)) }); diff --git a/src/trans/codegen_c.cpp b/src/trans/codegen_c.cpp index 98d0d3de..373a36a8 100644 --- a/src/trans/codegen_c.cpp +++ b/src/trans/codegen_c.cpp @@ -5522,7 +5522,7 @@ namespace { m_of << "var" << e; ), (Static, - m_of << Trans_Mangle(e); + m_of << Trans_Mangle(*e); ), (Field, ::HIR::TypeRef tmp; diff --git a/src/trans/codegen_mmir.cpp b/src/trans/codegen_mmir.cpp index b2c5282a..4867cf6f 100644 --- a/src/trans/codegen_mmir.cpp +++ b/src/trans/codegen_mmir.cpp @@ -52,7 +52,7 @@ namespace os << "arg" << e.idx; break; TU_ARM(x.e, Static, e) - os << e; + os << *e; break; TU_ARM(x.e, Deref, e) os << "*" << fmt(*e.val); diff --git a/src/trans/enumerate.cpp b/src/trans/enumerate.cpp index afdbd626..da11386c 100644 --- a/src/trans/enumerate.cpp +++ b/src/trans/enumerate.cpp @@ -735,7 +735,7 @@ void Trans_Enumerate_Types(EnumState& state) ), (Static, if( tmp_ty_ptr ) { - const auto& path = e; + const auto& path = *e; TU_MATCHA( (path.m_data), (pe), (Generic, ASSERT_BUG(Span(), pe.m_params.m_types.empty(), "Path params on static - " << path); @@ -1495,7 +1495,7 @@ void Trans_Enumerate_FillFrom_MIR_LValue(EnumState& state, const ::MIR::LValue& (Local, ), (Static, - Trans_Enumerate_FillFrom_Path(state, e, pp); + Trans_Enumerate_FillFrom_Path(state, *e, pp); ), (Field, Trans_Enumerate_FillFrom_MIR_LValue(state, *e.val, pp); diff --git a/src/trans/monomorphise.cpp b/src/trans/monomorphise.cpp index 3b958fec..0a0b43b5 100644 --- a/src/trans/monomorphise.cpp +++ b/src/trans/monomorphise.cpp @@ -19,7 +19,7 @@ namespace { (Argument, return e; ), (Local, return e; ), (Static, - return params.monomorph(resolve, e); + return box$(params.monomorph(resolve, *e)); ), (Field, return ::MIR::LValue::make_Field({ |