diff options
author | John Hodge <tpg@ucc.asn.au> | 2019-07-20 14:36:57 +0800 |
---|---|---|
committer | John Hodge <tpg@ucc.asn.au> | 2019-07-20 14:36:57 +0800 |
commit | 49a3ab205b9fc5b6ae64c928071cb40ca1b0ce50 (patch) | |
tree | c8e45b3a5730dd6ff8416bfd6422ab31309b62db | |
parent | f55a585d6896182910b00f68b12aee780b91c9be (diff) | |
download | mrust-49a3ab205b9fc5b6ae64c928071cb40ca1b0ce50.tar.gz |
Codegen C - Fix Box drop impl not being overridden
-rw-r--r-- | Notes/BugStories.txt | 22 | ||||
-rw-r--r-- | src/trans/codegen_c.cpp | 30 |
2 files changed, 43 insertions, 9 deletions
diff --git a/Notes/BugStories.txt b/Notes/BugStories.txt index 0e2ca1dd..b7437fb6 100644 --- a/Notes/BugStories.txt +++ b/Notes/BugStories.txt @@ -22,5 +22,27 @@ librustc takes ~20mins to recompile, and that's just one crate out of ~80 in rus - Enable optimisation debug and rebuild libcore - Oh look, `sizeof<*const T>` where `T: ?Sized` is returning 16 instead of returning "I don't know yet" + +2019-07-20: Leaking MPSC handles +================================ + +- rustc just stopping after codegen +- gdb backtrace shows only one thread, waiting on a MPSC receiver +- add debugging for MPSC Shared handles for that specific type, LOOTS of them being made (testing on a 14 core machine) +- Turn down codegen units to 1, now a total of 6 handles (much easier) +- Check all allocation paths, looks like all of them should call the destructor on the returned handle... + - One path hands a handle to a thread, let's chase that down + - Nope... that destuctor does get called... hmm... +- Break down (after two weekends) and hack in handle indexes to mpsc::Shared + (on clone, allocate a unique ID and store that in the handle). +- Re-run, printing the handle indexes - Notice that one code path (two + handles) leaks its handles +- Re-check, the destructor is called... but I can't break on it? +- Chase down the call chain, reach a Box drop impl (wait... that exists, I + thought the compiler made a custom one) + - It does absolutely nothing. No free, no destructor... oops +- Turns out that 1.29 added a no-op Drop impl for Box (1.19 didn't have one), which + caused mrustc's magic Drop impl to not be created. + <!-- vim: ft=markdown --> diff --git a/src/trans/codegen_c.cpp b/src/trans/codegen_c.cpp index 8b3b43ba..da9d5167 100644 --- a/src/trans/codegen_c.cpp +++ b/src/trans/codegen_c.cpp @@ -1015,9 +1015,16 @@ namespace { // Emit a call to box_free for the type if( run_destructor ) { - auto inner_ptr = ::HIR::TypeRef::new_pointer( ::HIR::BorrowType::Unique, inner_type.clone() ); - m_of << indent; emit_ctype(inner_ptr, FMT_CB(ss, ss << "i"; )); m_of << " = "; emit_lvalue(slot); m_of << "._0._0._0;\n"; - emit_destructor_call( ::MIR::LValue::new_Local(::MIR::LValue::Storage::MAX_ARG), inner_type, true, indent_level ); + auto inner_ptr = + ::MIR::LValue::new_Field( + ::MIR::LValue::new_Field( + ::MIR::LValue::new_Field( + slot.clone() + ,0) + ,0) + ,0) + ; + emit_destructor_call( ::MIR::LValue::new_Deref(mv$(inner_ptr)), inner_type, true, indent_level ); } // TODO: This is specific to the official liballoc's owned_box ::HIR::GenericPath box_free { m_crate.get_lang_item_path(sp, "box_free"), { inner_type.clone() } }; @@ -1371,7 +1378,15 @@ namespace { // - Drop Glue ::std::vector< ::std::pair<::HIR::Pattern,::HIR::TypeRef> > args; - if( item.m_markings.has_drop_impl ) { + // NOTE: 1.29 has Box impl Drop, but as a no-op - override that here. + // - TODO: This override/definition should be done by the caller + if( m_resolve.is_type_owned_box(struct_ty) ) + { + m_box_glue_todo.push_back( ::std::make_pair( mv$(struct_ty.m_data.as_Path().path.m_data.as_Generic()), &item ) ); + m_of << "static void " << Trans_Mangle(drop_glue_path) << "("; emit_ctype(struct_ty_ptr, FMT_CB(ss, ss << "rv";)); m_of << ");\n"; + return ; + } + else if( item.m_markings.has_drop_impl ) { // If the type is defined outside the current crate, define as static (to avoid conflicts when we define it) if( p.m_path.m_crate_name != m_crate.m_crate_name ) { @@ -1384,11 +1399,8 @@ namespace { } m_of << "void " << Trans_Mangle( ::HIR::Path(struct_ty.clone(), m_resolve.m_lang_Drop, "drop") ) << "("; emit_ctype(struct_ty_ptr, FMT_CB(ss, ss << "rv";)); m_of << ");\n"; } - else if( m_resolve.is_type_owned_box(struct_ty) ) - { - m_box_glue_todo.push_back( ::std::make_pair( mv$(struct_ty.m_data.as_Path().path.m_data.as_Generic()), &item ) ); - m_of << "static void " << Trans_Mangle(drop_glue_path) << "("; emit_ctype(struct_ty_ptr, FMT_CB(ss, ss << "rv";)); m_of << ");\n"; - return ; + else { + // No drop impl (magic or no) } ::MIR::TypeResolve mir_res { sp, m_resolve, FMT_CB(ss, ss << drop_glue_path;), struct_ty_ptr, args, empty_fcn }; |