Open honggyukim opened 5 years ago
You don't need to use xargs
since it reads from stdin if no arg is given. :)
Anyway I also think it needs to simplify symbol like we do in C++. Following is some of my idea.
A::foo<T>
--> A::foo
_<impl foo for bar>
--> foo
_<foo as bar>
--> bar
..
to ::
in _<...>
But I'm not 100% sure for this. Thoughts?
Looks better but not sure about it as I'm not familiar with Rust lang as of yet.
@quark-zju @ParkHanbum @taeguk Could you give us some thoughts for Rust symbol demangling as above?
- remove former in "as":
_<foo as bar>
-->bar
About this idea, there are some problematic things:
// except.rs
trait Trait {
fn new() -> Self;
fn foo(&self) {
println!("Trait::foo()");
}
fn bar(&self);
}
struct Struct {
var1: i32,
var2: bool
}
impl Struct {
fn method(&self) {
println!("Struct::method()");
}
}
impl Trait for Struct {
fn new() -> Struct {
println!("Struct::new()");
Struct { var1: 3, var2: true }
}
fn bar(&self) {
println!("Struct::bar()");
}
}
fn main() {
let s: Struct = Trait::new(); // Struct::new()
s.foo(); // Trait::foo()
s.bar(); // Struct::bar()
s.method(); // Struct::method()
}
$ rustc -Z instrument-mcount -g -A dead_code except.rs
$ uftrace ./except
Struct::new()
Trait::foo()
Struct::bar()
Struct::method()
# DURATION TID FUNCTION
[ 80895] | std::rt::lang_start() {
[ 80895] | std::rt::lang_start::_{{closure}}() {
[ 80895] | except::main() {
[ 80895] | _<except..Struct as except..Trait>::new() {
0.092 us [ 80895] | core::fmt::Arguments::new_v1();
95.423 us [ 80895] | } /* _<except..Struct as except..Trait>::new */
[ 80895] | except::Trait::foo() {
0.081 us [ 80895] | core::fmt::Arguments::new_v1();
3.435 us [ 80895] | } /* except::Trait::foo */
[ 80895] | _<except..Struct as except..Trait>::bar() {
0.070 us [ 80895] | core::fmt::Arguments::new_v1();
1.467 us [ 80895] | } /* _<except..Struct as except..Trait>::bar */
[ 80895] | except::Struct::method() {
0.075 us [ 80895] | core::fmt::Arguments::new_v1();
1.367 us [ 80895] | } /* except::Struct::method */
102.681 us [ 80895] | } /* except::main */
[ 80895] | _<() as std..process..Termination>::report() {
[ 80895] | _<std..process..ExitCode as std..process..Termination>::report() {
0.064 us [ 80895] | std::sys::unix::process::process_common::ExitCode::as_i32();
0.399 us [ 80895] | } /* _<std..process..ExitCode as std..process..Termination>::report */
0.592 us [ 80895] | } /* _<() as std..process..Termination>::report */
103.621 us [ 80895] | } /* std::rt::lang_start::_{{closure}} */
379.175 us [ 80895] | } /* std::rt::lang_start */
If applying @namhyung's suggestion to
_<except..Struct as except..Trait>::new()
and _<except..Struct as except..Trait>::bar()
, then they become except::Trait::new()
and except::Trait::bar()
.
But I think it is bad because these results are different to the functions which actually called.
I'm not an expert in this area. But the current Rust symbols are kind of Rust implementation details. See https://github.com/rust-lang/rfcs/pull/2603. Things might change rapidly. I think it makes sense to not spend too much effort on things to be changed, and wait for the new, more standardized schema.
Hi @taeguk @quark-zju, thanks very much for your feedback. It seems to be more complicated than we thought. It'd be better to take time what to do after v0.9.2 release. Thanks a lot for your help!
@taeguk do you think _<foo as bar>
-> foo
is more appropriate?
@quark-zju I don't know when it's finished but I think we still need to support older versions anyway. I agree that it should not spend too much effort but I'd like to make it more readable with a slight simplification if possible..
There is rust-demangle that could be used for a more accurate demangling.
@lu-zero thanks for the comment. We have two demangler - 'simple' demangler shows more compact, readable name while 'full' demangler shows accurate name. I'm talking about the simple demangler here how we can improve readability.
Based on the observation above, I think it'd be better using _<foo as bar>
-> foo
unless it's not ()
.
Please notice that mangling rules will change soon
There is rust-demangle that could be used for a more accurate demangling.
As @lu-zero suggested, we can get some reference to implement rust demangler.
rustfilt also uses the same demangler.
Current output is like below. And #1626 was filed for the new mangling scheme.
$ cat rust-symbols.txt | misc/demangler
rustc_driver::driver::phase_2_configure_and_expand_inner::_{{closure}}
rustc_resolve::macros::_<impl syntax::ext::base::Resolver for rustc_resolve::Resolver<'a>>::visit_ast_fragment_with_placeholders
_<rustc_resolve::build_reduced_graph::BuildReducedGraphVisitor<'a, 'b>>::visit_item
_<alloc::vec::Vec<T>>::from_iter
rustc_resolve::build_reduced_graph::_<impl rustc_resolve::Resolver<'a>>::populate_module_if_necessary
rustc_resolve::macros::_<impl syntax::ext::base::Resolver for rustc_resolve::Resolver<'a>>::resolve_imports
rustc_driver::driver::phase_3_run_analysis_passes
core::ptr::real_drop_in_place
_<rustc_codegen_llvm::LlvmCodegenBackend>::join_codegen_and_link
_<F>::call_box
rustc_resolve::build_reduced_graph::_<impl rustc_resolve::Resolver<'a>>::populate_module_if_necessary
rustc_metadata::cstore_impl::_<impl rustc_metadata::cstore::CStore>::item_children_untracked
rustc_metadata::decoder::_<impl rustc_metadata::cstore::CrateMetadata>::each_child_of_item
_<rustc_metadata::decoder::DecodeContext<'a, 'tcx>>::specialized_decode
rustc_metadata::decoder::_<impl rustc_metadata::cstore::CrateMetadata>::imported_source_files
_<alloc::vec::Vec<T>>::from_iter
_<core::iter::Map<I, F>>::fold
rustc_resolve::macros::_<impl syntax::ext::base::Resolver for rustc_resolve::Resolver<'a>>::resolve_imports
rustc_resolve::resolve_imports::ImportResolver::resolve_imports
rustc_resolve::build_reduced_graph::_<impl rustc_resolve::Resolver<'a>>::populate_module_if_necessary
rustc_metadata::cstore_impl::_<impl rustc_metadata::cstore::CStore>::item_children_untracked
rustc_metadata::decoder::_<impl rustc_metadata::cstore::CrateMetadata>::each_child_of_item
_<rustc_metadata::decoder::DecodeContext<'a, 'tcx>>::specialized_decode
rustc_metadata::decoder::_<impl rustc_metadata::cstore::CrateMetadata>::imported_source_files
_<alloc::vec::Vec<T>>::from_iter
_<core::iter::Map<I, F>>::fold
_<std::thread::local::LocalKey<T>>::with
rustc_typeck::check_crate
rustc::util::common::time
rustc::ty::query::plumbing::_<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_get_with
rustc::dep_graph::graph::DepGraph::with_task_impl
rustc::ty::query::_<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::typeck_item_bodies<'tcx>>::compute
rustc::ty::query::__query_compute::typeck_item_bodies
rustc_typeck::check::typeck_item_bodies
rustc::session::Session::track_errors
rustc::ty::query::_<impl rustc::ty::query::queries::typeck_tables_of<'tcx>>::ensure
rustc::ty::query::plumbing::_<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::ensure_query
rustc::ty::query::plumbing::_<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_get_with
rustc::dep_graph::graph::DepGraph::with_task_impl
rustc::ty::query::_<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::typeck_tables_of<'tcx>>::compute
Looks good! I'd avoid adding the _
maybe though.
Yeah, now it shows _<foo as bar>
as _<foo>
, maybe we can convert _<
to <
.
I've found some symbols from Rust that are not human friendly. Please see.
The demangling output looks as follows:
They might look okay but just uploaded if there's any chance to improve.