Mercurial > hg > Document > Growi
view Events/srcread/compiler/rust-2020.md @ 17:4d2f07e4f23e
backup 2021-01-06
author | autobackup |
---|---|
date | Wed, 06 Jan 2021 00:10:03 +0900 |
parents | b6c284fd5ae4 |
children |
line wrap: on
line source
# Rustコンパイラ読み会 # 環境構築 - [singularityを使ったRustのデバッグビルド](https://scrapbox.io/cr-ryukyu/singularity%E3%82%92%E4%BD%BF%E3%81%A3%E3%81%9FRust%E3%81%AE%E3%83%87%E3%83%90%E3%83%83%E3%82%B0%E3%83%93%E3%83%AB%E3%83%89) - [singularityでRustコンパイラのデバッグ](https://scrapbox.io/cr-ryukyu/singularity%E3%82%92%E4%BD%BF%E3%81%A3%E3%81%9FRust%E3%81%AE%E3%83%87%E3%83%90%E3%83%83%E3%82%B0%E3%83%93%E3%83%AB%E3%83%89) # デバッグ方法 - コンパイル時に関数に型名を入れるので,nmで関数名を取り出す必要がある - `$nm /rust/rust/build/x86_64-unknown-linux-gnu/stage1/bin/../lib/librustc_driver-ce53599820ba664c.so | grep parse_expr` # compilerソースながめる - https://github.com/rust-lang/rust/tree/master/compiler - メイン部分 - https://github.com/rust-lang/rust/tree/master/compiler/rustc_driver - クレート寄せ集めっぽい - `run_compiler()` - `||` lambda式 - https://doc.rust-lang.org/rust-by-example/fn/closures.html#:~:text=Closures%20in%20Rust%2C%20also%20called,for%20on%20the%20fly%20usage - `FnOnce` - `rustc_interface::interface::create_compiler_and_run::hd06f00e0a4bf9137 at interface.rs:190:5` ## backtrace ```txt * thread #2, name = 'rustc', stop reason = breakpoint 2.1 * frame #0: 0x00007ffff41919fb librustc_driver-ce53599820ba664c.so`rustc_parse::parser::expr::_$LT$impl$u20$rustc_parse..parser..Parser$GT$::parse_expr_catch_underscore::h43010b29c3bbcd9b [inlined] rustc_parse::parser::Parser::with_res::hd719d9af60fa6475 at mod.rs:1025:19 frame #1: 0x00007ffff41919fb librustc_driver-ce53599820ba664c.so`rustc_parse::parser::expr::_$LT$impl$u20$rustc_parse..parser..Parser$GT$::parse_expr_catch_underscore::h43010b29c3bbcd9b [inlined] rustc_parse::parser::expr::_$LT$impl$u20$rustc_parse..parser..Parser$GT$::parse_expr_res::h5928421b15332eef at expr.rs:127 frame #2: 0x00007ffff41919fb librustc_driver-ce53599820ba664c.so`rustc_parse::parser::expr::_$LT$impl$u20$rustc_parse..parser..Parser$GT$::parse_expr_catch_underscore::h43010b29c3bbcd9b [inlined] rustc_parse::parser::expr::_$LT$impl$u20$rustc_parse..parser..Parser$GT$::parse_expr::h95dab2ee425c859e at expr.rs:91 frame #3: 0x00007ffff41919fb librustc_driver-ce53599820ba664c.so`rustc_parse::parser::expr::_$LT$impl$u20$rustc_parse..parser..Parser$GT$::parse_expr_catch_underscore::h43010b29c3bbcd9b at expr.rs:99 frame #4: 0x00007ffff41ecc6f librustc_driver-ce53599820ba664c.so`rustc_parse::parser::Parser::parse_seq_to_before_tokens::h4a23b282ffc32d65 [inlined] rustc_parse::parser::expr::_$LT$impl$u20$rustc_parse..parser..Parser$GT$::parse_paren_expr_seq::_$u7b$$u7b$closure$u7d$$u7d$::h9e07a7a5b55bc601 at expr.rs:117:40 frame #5: 0x00007ffff41ecc67 librustc_driver-ce53599820ba664c.so`rustc_parse::parser::Parser::parse_seq_to_before_tokens::h4a23b282ffc32d65 at mod.rs:721 frame #6: 0x00007ffff41f32c1 librustc_driver-ce53599820ba664c.so`rustc_parse::parser::Parser::parse_delim_comma_seq::h18ef14e316c0bef4 [inlined] rustc_parse::parser::Parser::parse_seq_to_before_end::h12b9e502ad9050a9 at mod.rs:737:9 frame #7: 0x00007ffff41f3293 librustc_driver-ce53599820ba664c.so`rustc_parse::parser::Parser::parse_delim_comma_seq::h18ef14e316c0bef4 [inlined] rustc_parse::parser::Parser::parse_seq_to_end::hc7808e14c4dd5e83 at mod.rs:749 frame #8: 0x00007ffff41f3293 librustc_driver-ce53599820ba664c.so`rustc_parse::parser::Parser::parse_delim_comma_seq::h18ef14e316c0bef4 [inlined] rustc_parse::parser::Parser::parse_unspanned_seq::ha6405b33d8be6d2b at mod.rs:767 frame #9: 0x00007ffff41f3286 librustc_driver-ce53599820ba664c.so`rustc_parse::parser::Parser::parse_delim_comma_seq::h18ef14e316c0bef4 at mod.rs:775 frame #10: 0x00007ffff419881a librustc_driver-ce53599820ba664c.so`rustc_parse::parser::expr::_$LT$impl$u20$rustc_parse..parser..Parser$GT$::parse_dot_or_call_expr_with_::h2fe7120292b29822 [inlined] rustc_parse::parser::Parser::parse_paren_comma_seq::h2172e4858f2fe322 at mod.rs:787:9 frame #11: 0x00007ffff419880a librustc_driver-ce53599820ba664c.so`rustc_parse::parser::expr::_$LT$impl$u20$rustc_parse..parser..Parser$GT$::parse_dot_or_call_expr_with_::h2fe7120292b29822 [inlined] rustc_parse::parser::expr::_$LT$impl$u20$rustc_parse..parser..Parser$GT$::parse_paren_expr_seq::h9867ea0ce8ef4b27 at expr.rs:117 frame #12: 0x00007ffff419880a librustc_driver-ce53599820ba664c.so`rustc_parse::parser::expr::_$LT$impl$u20$rustc_parse..parser..Parser$GT$::parse_dot_or_call_expr_with_::h2fe7120292b29822 [inlined] rustc_parse::parser::expr::_$LT$impl$u20$rustc_parse..parser..Parser$GT$::parse_fn_call_expr::hd0da9e0f8e9441b5 at expr.rs:961 frame #13: 0x00007ffff419880a librustc_driver-ce53599820ba664c.so`rustc_parse::parser::expr::_$LT$impl$u20$rustc_parse..parser..Parser$GT$::parse_dot_or_call_expr_with_::h2fe7120292b29822 at expr.rs:805 frame #14: 0x00007ffff4197fe6 librustc_driver-ce53599820ba664c.so`rustc_parse::parser::expr::_$LT$impl$u20$rustc_parse..parser..Parser$GT$::parse_dot_or_call_expr_with::h34aaddda78ce4242 at expr.rs:780:9 frame #15: 0x00007ffff41dba15 librustc_driver-ce53599820ba664c.so`rustc_parse::parser::stmt::_$LT$impl$u20$rustc_parse..parser..Parser$GT$::parse_stmt_without_recovery::h9aac38d541d3ee33 [inlined] rustc_parse::parser::stmt::_$LT$impl$u20$rustc_parse..parser..Parser$GT$::parse_stmt_path_start::_$u7b$$u7b$closure$u7d$$u7d$::h7e3aae8192395074 at stmt.rs:90:24 frame #16: 0x00007ffff41db9d6 librustc_driver-ce53599820ba664c.so`rustc_parse::parser::stmt::_$LT$impl$u20$rustc_parse..parser..Parser$GT$::parse_stmt_without_recovery::h9aac38d541d3ee33 [inlined] rustc_parse::parser::Parser::with_res::h54245f39af292c7a at mod.rs:1027 frame #17: 0x00007ffff41db9d6 librustc_driver-ce53599820ba664c.so`rustc_parse::parser::stmt::_$LT$impl$u20$rustc_parse..parser..Parser$GT$::parse_stmt_without_recovery::h9aac38d541d3ee33 [inlined] rustc_parse::parser::stmt::_$LT$impl$u20$rustc_parse..parser..Parser$GT$::parse_stmt_path_start::hf728862f2bc639f1 at stmt.rs:89 frame #18: 0x00007ffff41db9d6 librustc_driver-ce53599820ba664c.so`rustc_parse::parser::stmt::_$LT$impl$u20$rustc_parse..parser..Parser$GT$::parse_stmt_without_recovery::h9aac38d541d3ee33 at stmt.rs:56 frame #19: 0x00007ffff41dedbc librustc_driver-ce53599820ba664c.so`rustc_parse::parser::stmt::_$LT$impl$u20$rustc_parse..parser..Parser$GT$::parse_full_stmt::he7a0d36b0005f620 at stmt.rs:374:30 frame #20: 0x00007ffff41de908 librustc_driver-ce53599820ba664c.so`rustc_parse::parser::stmt::_$LT$impl$u20$rustc_parse..parser..Parser$GT$::parse_block_tail::h06bebcce30737a4d at stmt.rs:346:30 frame #21: 0x00007ffff41dde05 librustc_driver-ce53599820ba664c.so`rustc_parse::parser::stmt::_$LT$impl$u20$rustc_parse..parser..Parser$GT$::parse_block_common::h8e2ad585959efd9f at stmt.rs:328:13 frame #22: 0x00007ffff41a65ce librustc_driver-ce53599820ba664c.so`rustc_parse::parser::expr::_$LT$impl$u20$rustc_parse..parser..Parser$GT$::parse_block_expr::h9f26ea288236c2f2 at expr.rs:1564:34 frame #23: 0x00007ffff419be4c librustc_driver-ce53599820ba664c.so`rustc_parse::parser::expr::_$LT$impl$u20$rustc_parse..parser..Parser$GT$::parse_bottom_expr::hf1ab8a77513b78e0 at expr.rs:1035:13 frame #24: 0x00007ffff41957ea librustc_driver-ce53599820ba664c.so`rustc_parse::parser::expr::_$LT$impl$u20$rustc_parse..parser..Parser$GT$::parse_prefix_expr::_$u7b$$u7b$closure$u7d$$u7d$::ha8c245b3e504f09c [inlined] rustc_parse::parser::expr::_$LT$impl$u20$rustc_parse..parser..Parser$GT$::parse_dot_or_call_expr::h6aac50c8864667eb at expr.rs:766:20 frame #25: 0x00007ffff41957dd librustc_driver-ce53599820ba664c.so`rustc_parse::parser::expr::_$LT$impl$u20$rustc_parse..parser..Parser$GT$::parse_prefix_expr::_$u7b$$u7b$closure$u7d$$u7d$::ha8c245b3e504f09c at expr.rs:487 frame #26: 0x00007ffff4194b71 librustc_driver-ce53599820ba664c.so`rustc_parse::parser::expr::_$LT$impl$u20$rustc_parse..parser..Parser$GT$::parse_prefix_expr::h8ca59e1bc7493784 [inlined] rustc_parse::parser::expr::_$LT$impl$u20$rustc_parse..parser..Parser$GT$::maybe_collect_tokens::hb7156b7dc9c2c50a at expr.rs:1137:13 frame #27: 0x00007ffff419497d librustc_driver-ce53599820ba664c.so`rustc_parse::parser::expr::_$LT$impl$u20$rustc_parse..parser..Parser$GT$::parse_prefix_expr::h8ca59e1bc7493784 at expr.rs:474 frame #28: 0x00007ffff4191e3b librustc_driver-ce53599820ba664c.so`rustc_parse::parser::expr::_$LT$impl$u20$rustc_parse..parser..Parser$GT$::parse_assoc_expr_with::h022381be78dbbd0d at expr.rs:155:17 frame #29: 0x00007ffff41db216 librustc_driver-ce53599820ba664c.so`rustc_parse::parser::stmt::_$LT$impl$u20$rustc_parse..parser..Parser$GT$::parse_stmt_without_recovery::h9aac38d541d3ee33 [inlined] rustc_parse::parser::expr::_$LT$impl$u20$rustc_parse..parser..Parser$GT$::parse_assoc_expr::ha4c0ea088735151f at expr.rs:136:9 frame #30: 0x00007ffff41db206 librustc_driver-ce53599820ba664c.so`rustc_parse::parser::stmt::_$LT$impl$u20$rustc_parse..parser..Parser$GT$::parse_stmt_without_recovery::h9aac38d541d3ee33 [inlined] rustc_parse::parser::expr::_$LT$impl$u20$rustc_parse..parser..Parser$GT$::parse_expr_res::_$u7b$$u7b$closure$u7d$$u7d$::hbc4a592d9e915c57 at expr.rs:127 frame #31: 0x00007ffff41db206 librustc_driver-ce53599820ba664c.so`rustc_parse::parser::stmt::_$LT$impl$u20$rustc_parse..parser..Parser$GT$::parse_stmt_without_recovery::h9aac38d541d3ee33 [inlined] rustc_parse::parser::Parser::with_res::hd719d9af60fa6475 at mod.rs:1027 frame #32: 0x00007ffff41db1f5 librustc_driver-ce53599820ba664c.so`rustc_parse::parser::stmt::_$LT$impl$u20$rustc_parse..parser..Parser$GT$::parse_stmt_without_recovery::h9aac38d541d3ee33 [inlined] rustc_parse::parser::expr::_$LT$impl$u20$rustc_parse..parser..Parser$GT$::parse_expr_res::h5928421b15332eef at expr.rs:127 frame #33: 0x00007ffff41db1f5 librustc_driver-ce53599820ba664c.so`rustc_parse::parser::stmt::_$LT$impl$u20$rustc_parse..parser..Parser$GT$::parse_stmt_without_recovery::h9aac38d541d3ee33 at stmt.rs:66 frame #34: 0x00007ffff41dedbc librustc_driver-ce53599820ba664c.so`rustc_parse::parser::stmt::_$LT$impl$u20$rustc_parse..parser..Parser$GT$::parse_full_stmt::he7a0d36b0005f620 at stmt.rs:374:30 frame #35: 0x00007ffff400f96a librustc_driver-ce53599820ba664c.so`rustc_expand::expand::parse_ast_fragment::h88005342af03b165 at expand.rs:918:37 frame #36: 0x00007ffff3fdc20b librustc_driver-ce53599820ba664c.so`rustc_expand::mbe::macro_rules::ParserAnyMacro::make::ha84ea912487ab58f at macro_rules.rs:143:30 frame #37: 0x00007ffff3fe648a librustc_driver-ce53599820ba664c.so`rustc_expand::expand::_$LT$impl$u20$rustc_expand..base..MacResult$u20$for$u20$rustc_expand..mbe..macro_rules..ParserAnyMacro$GT$::make_stmts::hd01eb759776eb308 at expand.rs:141:22 frame #38: 0x00007ffff401a221 librustc_driver-ce53599820ba664c.so`rustc_expand::expand::AstFragmentKind::make_from::h312efd385e333563 at expand.rs:74:49 frame #39: 0x00007ffff400ae91 librustc_driver-ce53599820ba664c.so`rustc_expand::expand::MacroExpander::fully_expand_fragment::h21e2cb708bcabf6b [inlined] rustc_expand::expand::MacroExpander::expand_invoc::heb4508fe5dc7f59d at expand.rs:704:56 frame #40: 0x00007ffff400ad35 librustc_driver-ce53599820ba664c.so`rustc_expand::expand::MacroExpander::fully_expand_fragment::h21e2cb708bcabf6b at expand.rs:497 frame #41: 0x00007ffff4009e33 librustc_driver-ce53599820ba664c.so`rustc_expand::expand::MacroExpander::expand_crate::hdcbcbdbd5ffd9b81 at expand.rs:390:15 frame #42: 0x00007fffef8b3f0f librustc_driver-ce53599820ba664c.so`rustc_session::utils::_$LT$impl$u20$rustc_session..session..Session$GT$::time::h8f8d9b170ba156cc [inlined] rustc_interface::passes::configure_and_expand_inner::_$u7b$$u7b$closure$u7d$$u7d$::_$u7b$$u7b$closure$u7d$$u7d$::h89914587490008fa at passes.rs:301:50 frame #43: 0x00007fffef8b3e7c librustc_driver-ce53599820ba664c.so`rustc_session::utils::_$LT$impl$u20$rustc_session..session..Session$GT$::time::h8f8d9b170ba156cc [inlined] rustc_data_structures::profiling::VerboseTimingGuard::run::h1de2d120ce6be700 at profiling.rs:570 frame #44: 0x00007fffef8b3dd1 librustc_driver-ce53599820ba664c.so`rustc_session::utils::_$LT$impl$u20$rustc_session..session..Session$GT$::time::h8f8d9b170ba156cc [inlined] rustc_session::utils::_$LT$impl$u20$rustc_session..session..Session$GT$::time::hb61a37b80af8edf9 at utils.rs:9 frame #45: 0x00007fffef8b3db7 librustc_driver-ce53599820ba664c.so`rustc_session::utils::_$LT$impl$u20$rustc_session..session..Session$GT$::time::h8f8d9b170ba156cc [inlined] rustc_interface::passes::configure_and_expand_inner::_$u7b$$u7b$closure$u7d$$u7d$::h5baa5dc2d3b7d5ab at passes.rs:301 frame #46: 0x00007fffef8b3bba librustc_driver-ce53599820ba664c.so`rustc_session::utils::_$LT$impl$u20$rustc_session..session..Session$GT$::time::h8f8d9b170ba156cc [inlined] rustc_data_structures::profiling::VerboseTimingGuard::run::hac59221ea2999e1f at profiling.rs:570 frame #47: 0x00007fffef8b3b4c librustc_driver-ce53599820ba664c.so`rustc_session::utils::_$LT$impl$u20$rustc_session..session..Session$GT$::time::h8f8d9b170ba156cc at utils.rs:9 frame #48: 0x00007fffef916fe3 librustc_driver-ce53599820ba664c.so`rustc_interface::passes::configure_and_expand_inner::h6195e087ea984a0c at passes.rs:253:13 frame #49: 0x00007fffef8cade9 librustc_driver-ce53599820ba664c.so`rustc_interface::passes::configure_and_expand::_$u7b$$u7b$closure$u7d$$u7d$::h563ae5b7751e4716 at passes.rs:117:19 frame #50: 0x00007fffef8b758f librustc_driver-ce53599820ba664c.so`rustc_data_structures::box_region::PinnedGenerator$LT$I$C$A$C$R$GT$::new::hdf5326c16352d0b3 [inlined] alloc::boxed::_$LT$impl$u20$core..ops..generator..Generator$LT$R$GT$$u20$for$u20$core..pin..Pin$LT$alloc..boxed..Box$LT$G$C$A$GT$$GT$$GT$::resume::h6f486135a6884478 at boxed.rs:1434:9 frame #51: 0x00007fffef8b7574 librustc_driver-ce53599820ba664c.so`rustc_data_structures::box_region::PinnedGenerator$LT$I$C$A$C$R$GT$::new::hdf5326c16352d0b3 at box_region.rs:44 frame #52: 0x00007fffef915c7d librustc_driver-ce53599820ba664c.so`rustc_interface::passes::configure_and_expand::h744723d4f46c935b [inlined] rustc_interface::passes::BoxedResolver::new::hd2be0aaa3ed2ea85 at box_region.rs:101:41 frame #53: 0x00007fffef915bd6 librustc_driver-ce53599820ba664c.so`rustc_interface::passes::configure_and_expand::h744723d4f46c935b at passes.rs:113 frame #54: 0x00007fffef815d76 librustc_driver-ce53599820ba664c.so`rustc_interface::queries::Queries::expansion::h7ac3f5ba274aafbd [inlined] rustc_interface::queries::Queries::expansion::_$u7b$$u7b$closure$u7d$$u7d$::ha21385b576de40f8 at queries.rs:178:13 frame #55: 0x00007fffef81579a librustc_driver-ce53599820ba664c.so`rustc_interface::queries::Queries::expansion::h7ac3f5ba274aafbd [inlined] rustc_interface::queries::Query$LT$T$GT$::compute::ha966bf8cd6645071 at queries.rs:35 frame #56: 0x00007fffef81579a librustc_driver-ce53599820ba664c.so`rustc_interface::queries::Queries::expansion::h7ac3f5ba274aafbd at queries.rs:174 frame #57: 0x00007fffef58cb7b librustc_driver-ce53599820ba664c.so`rustc_interface::queries::_$LT$impl$u20$rustc_interface..interface..Compiler$GT$::enter::h745584ef9a1d214e [inlined] rustc_driver::run_compiler::_$u7b$$u7b$closure$u7d$$u7d$::_$u7b$$u7b$closure$u7d$$u7d$::hbfae80f2f337da53 at lib.rs:388:13 frame #58: 0x00007fffef58bffb librustc_driver-ce53599820ba664c.so`rustc_interface::queries::_$LT$impl$u20$rustc_interface..interface..Compiler$GT$::enter::h745584ef9a1d214e at queries.rs:415 frame #59: 0x00007fffef64d497 librustc_driver-ce53599820ba664c.so`rustc_span::with_source_map::hfa7e85594b278950 [inlined] rustc_driver::run_compiler::_$u7b$$u7b$closure$u7d$$u7d$::h453d29d790e8d9d5 at lib.rs:336:22 frame #60: 0x00007fffef64d398 librustc_driver-ce53599820ba664c.so`rustc_span::with_source_map::hfa7e85594b278950 [inlined] rustc_interface::interface::create_compiler_and_run::_$u7b$$u7b$closure$u7d$$u7d$::h1d7ed3cb14ac6d8d at interface.rs:196 frame #61: 0x00007fffef64d36c librustc_driver-ce53599820ba664c.so`rustc_span::with_source_map::hfa7e85594b278950 at lib.rs:764 frame #62: 0x00007fffef58ef94 librustc_driver-ce53599820ba664c.so`rustc_interface::interface::create_compiler_and_run::hd06f00e0a4bf9137 at interface.rs:190:5 frame #63: 0x00007fffef56d83f librustc_driver-ce53599820ba664c.so`scoped_tls::ScopedKey$LT$T$GT$::set::h30136cd23222a588 [inlined] rustc_interface::interface::run_compiler::_$u7b$$u7b$closure$u7d$$u7d$::h34c6c3f6e67ddbad at interface.rs:212:12 frame #64: 0x00007fffef56d823 librustc_driver-ce53599820ba664c.so`scoped_tls::ScopedKey$LT$T$GT$::set::h30136cd23222a588 [inlined] rustc_interface::util::setup_callbacks_and_run_in_thread_pool_with_globals::_$u7b$$u7b$closure$u7d$$u7d$::_$u7b$$u7b$closure$u7d$$u7d$::h9533cbdf934b5d95 at util.rs:152 frame #65: 0x00007fffef56d7df librustc_driver-ce53599820ba664c.so`scoped_tls::ScopedKey$LT$T$GT$::set::h30136cd23222a588 at lib.rs:137 frame #66: 0x00007fffef572e45 librustc_driver-ce53599820ba664c.so`std::sys_common::backtrace::__rust_begin_short_backtrace::h8544078baa633623 [inlined] rustc_span::with_session_globals::h88e1584ec43a0922 at lib.rs:93:5 frame #67: 0x00007fffef572e0b librustc_driver-ce53599820ba664c.so`std::sys_common::backtrace::__rust_begin_short_backtrace::h8544078baa633623 [inlined] rustc_interface::util::setup_callbacks_and_run_in_thread_pool_with_globals::_$u7b$$u7b$closure$u7d$$u7d$::h038aa08aaeb0992f at util.rs:150 frame #68: 0x00007fffef572ddb librustc_driver-ce53599820ba664c.so`std::sys_common::backtrace::__rust_begin_short_backtrace::h8544078baa633623 [inlined] rustc_interface::util::scoped_thread::_$u7b$$u7b$closure$u7d$$u7d$::h69fdee9624ece786 at util.rs:125 frame #69: 0x00007fffef572aa4 librustc_driver-ce53599820ba664c.so`std::sys_common::backtrace::__rust_begin_short_backtrace::h8544078baa633623 at backtrace.rs:125 frame #70: 0x00007fffef5bbd0f librustc_driver-ce53599820ba664c.so`core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h7aa107b39bcde6bb [inlined] std::thread::Builder::spawn_unchecked::_$u7b$$u7b$closure$u7d$$u7d$::_$u7b$$u7b$closure$u7d$$u7d$::h9f644a1ef9be9a42 at mod.rs:474:17 frame #71: 0x00007fffef5bbd0a librustc_driver-ce53599820ba664c.so`core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h7aa107b39bcde6bb [inlined] _$LT$std..panic..AssertUnwindSafe$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$$LP$$RP$$GT$$GT$::call_once::h6d5823d1b946d4ce at panic.rs:322 frame #72: 0x00007fffef5bbd0a librustc_driver-ce53599820ba664c.so`core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h7aa107b39bcde6bb [inlined] std::panicking::try::do_call::h09f3dccec07b571d at panicking.rs:379 frame #73: 0x00007fffef5bbce9 librustc_driver-ce53599820ba664c.so`core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h7aa107b39bcde6bb [inlined] std::panicking::try::h5e56e14357d67e8d at panicking.rs:343 frame #74: 0x00007fffef5bbce5 librustc_driver-ce53599820ba664c.so`core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h7aa107b39bcde6bb [inlined] std::panic::catch_unwind::h0523bb22b3f15298 at panic.rs:396 frame #75: 0x00007fffef5bbce5 librustc_driver-ce53599820ba664c.so`core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h7aa107b39bcde6bb [inlined] std::thread::Builder::spawn_unchecked::_$u7b$$u7b$closure$u7d$$u7d$::h0cd0077403ecd15a at mod.rs:473 frame #76: 0x00007fffef5bbc72 librustc_driver-ce53599820ba664c.so`core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h7aa107b39bcde6bb at function.rs:227 frame #77: 0x00007fffeea33488 libstd-1a656201d4f29b26.so`std::sys::unix::thread::Thread::new::thread_start::h755294a5ddedae4e [inlined] _$LT$alloc..boxed..Box$LT$F$C$A$GT$$u20$as$u20$core..ops..function..FnOnce$LT$Args$GT$$GT$::call_once::hef4c423c281428f6 at boxed.rs:1318:9 frame #78: 0x00007fffeea33482 libstd-1a656201d4f29b26.so`std::sys::unix::thread::Thread::new::thread_start::h755294a5ddedae4e [inlined] _$LT$alloc..boxed..Box$LT$F$C$A$GT$$u20$as$u20$core..ops..function..FnOnce$LT$Args$GT$$GT$::call_once::h95870f8c37e6568d at boxed.rs:1318 frame #79: 0x00007fffeea3347b libstd-1a656201d4f29b26.so`std::sys::unix::thread::Thread::new::thread_start::h755294a5ddedae4e at thread.rs:71 frame #80: 0x00007fffee74f609 libpthread.so.0`start_thread(arg=<unavailable>) at pthread_create.c:477:8 frame #81: 0x00007fffee891293 libc.so.6`__clone + 67 ``` - if let Some(stmt) = this.parse_full_stmt()? {} みたいな構文 - macro文 - https://doc.rust-lang.org/nightly/nightly-rustc/rustc_expand/mbe/index.html - 例 - https://doc.rust-lang.org/book/ch19-06-macros.html - walk_list - 引数がvisitor, method, list の3つで構成されている. - 引数3つ以上の場合もある. - visitorパターン - デザインパターンを読もう - https://www.amazon.co.jp/gp/product/B00I8ATHGW/ref=dbs_a_def_rwt_bibl_vppi_i0 `walk_list`はこのあたりで使われているらしい ```shell $ rg walk_list --files-with-matches rustc_lint/src/late.rs rustc_ast_lowering/src/lib.rs rustc_ast_passes/src/ast_validation.rs rustc_ast/src/visit.rs rustc_passes/src/region.rs rustc_hir/src/intravisit.rs rustc_save_analysis/src/dump_visitor.rs rustc_resolve/src/def_collector.rs rustc_resolve/src/late.rs rustc_resolve/src/late/lifetimes.rs ``` - passes - https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/passes/index.html - configure_and_expand() - https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/passes/fn.configure_and_expand.html - コンパイラの前処理的な - harness - importとかで指定されてるライブラリの読み込み - etc ## lldbのbreak pointをsaveする - lldbで - `br write -f /tmp/rust_breakpoint.txt` - jsonが書き込まれる ```json [ { "Breakpoint": { "BKPTOptions": { "AutoContinue": false, "ConditionText": "", "EnabledState": true, "IgnoreCount": 0, "OneShotState": false }, "BKPTResolver": { "Options": { "NameMask": [ 4 ], "Offset": 0, "SkipPrologue": true, "SymbolNames": [ "_ZN11rustc_parse6parser4expr45_$LT$impl$u20$rustc_parse..parser..Parser$GT$27parse_expr_catch_underscore17h43010b29c3bbcd9bE" ] }, "Type": "SymbolName" }, "Hardware": false, "SearchFilter": { "Options": {}, "Type": "Unconstrained" } } }, { "Breakpoint": { "BKPTOptions": { "AutoContinue": false, "ConditionText": "", "EnabledState": true, "IgnoreCount": 0, "OneShotState": false }, "BKPTResolver": { "Options": { "NameMask": [ 56 ], "Offset": 0, "SkipPrologue": true, "SymbolNames": [ "create_compiler_and_run" ] }, "Type": "SymbolName" }, "Hardware": false, "SearchFilter": { "Options": {}, "Type": "Unconstrained" } } }, { "Breakpoint": { "BKPTOptions": { "AutoContinue": false, "ConditionText": "", "EnabledState": true, "IgnoreCount": 0, "OneShotState": false }, "BKPTResolver": { "Options": { "NameMask": [ 24 ], "Offset": 0, "SkipPrologue": true, "SymbolNames": [ "rustc_interface::interface::create_compiler_and_run" ] }, "Type": "SymbolName" }, "Hardware": false, "SearchFilter": { "Options": {}, "Type": "Unconstrained" } } } ] ``` ## `/rust/rust/compiler/rustc` - src/main.rs - _F1~_F6という関数がある - `jmalloc_sys` - `rustc_driver`というのをrustcにしたかった. ## lldbがコンパイラのコードをうまく読み込めてないからブレークポイントがうまく立てられない感じ. - `parse_expr`で止められない! - `break point`がなんかよくわからないところについてる. ## もう少しbreakpointの問題を追求する - 関数のアドレスが実際のものとずれているのが問題 - シンボルファイルから正しいアドレスを特定できればそのアドレスを使ってブレークポイントを設定できるはず. - stage1のコンパイラを使ってやる. - ダイナミックリンキングライブラリ - `/rust/rust/build/x86_64-unknown-linux-gnu/stage1/bin/../lib/librustc_driver-ce53599820ba664c.so` ## 次はgdbでやってみる - `b main` , `run` をやるとダイナミックリンクが発動して行き先ができる. - gdbのほうが若干まし. ## `rustc_interface/src/callbacks.rs` - `span_debug()` - `struct Compiler` - pub(crate) - 自分のname spaceにしか公開しない. - `impl Compiler` (メソッド群) - `run_compiler()` - `R + Send` ## `rustc_interface/src/lib.rs` - passes ## `'a`(頭のシングルクオート) - ライフポインタパラメーター ## passesの終わったルーチンのところは正しくブレークポイントでとまる. - rustcはlldbを今はサポートしてないっぽい - 走らせてからbreakpointを付ければリンクがあるから行ける ## これでparse部分は止められた - `b rustc_interface::passes::parse` - `b parse_crate_from_file` - `backtrace` ## back trace - `/rust/rust/compiler/rustc_parse/src/parser/item.rs` ```text #0 rustc_parse::parser::item::<impl rustc_parse::parser::Parser>::parse_mod () at compiler/rustc_parse/src/parser/item.rs:58 #1 0x00007ffff426fd03 in rustc_parse::parser::item::<impl rustc_parse::parser::Parser>::parse_crate_mod () at compiler/rustc_parse/src/parser/item.rs:31 #2 rustc_parse::parse_crate_from_file () at compiler/rustc_parse/src/lib.rs:56 #3 0x00007fffef8b37ef in rustc_interface::passes::parse::{{closure}} () at compiler/rustc_interface/src/passes.rs:55 #4 rustc_data_structures::profiling::VerboseTimingGuard::run () at /rust/rust/compiler/rustc_data_structures/src/profiling.rs:570 #5 rustc_session::utils::<impl rustc_session::session::Session>::time () at /rust/rust/compiler/rustc_session/src/utils.rs:9 #6 0x00007fffef9157c1 in rustc_interface::passes::parse () at compiler/rustc_interface/src/passes.rs:54 #7 0x00007fffef81407d in rustc_interface::queries::Queries::parse::{{closure}} () at compiler/rustc_interface/src/queries.rs:125 #8 rustc_interface::queries::Query<T>::compute () at compiler/rustc_interface/src/queries.rs:35 #9 rustc_interface::queries::Queries::parse () at compiler/rustc_interface/src/queries.rs:124 #10 0x00007fffef58c004 in rustc_driver::run_compiler::{{closure}}::{{closure}} () at compiler/rustc_driver/src/lib.rs:338 #11 rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter () at /rust/rust/compiler/rustc_interface/src/queries.rs:415 #12 0x00007fffef64d497 in rustc_driver::run_compiler::{{closure}} () at compiler/rustc_driver/src/lib.rs:336 #13 rustc_interface::interface::create_compiler_and_run::{{closure}} () at /rust/rust/compiler/rustc_interface/src/interface.rs:196 #14 rustc_span::with_source_map () at /rust/rust/compiler/rustc_span/src/lib.rs:764 #15 0x00007fffef58ef94 in rustc_interface::interface::create_compiler_and_run () at /rust/rust/compiler/rustc_interface/src/interface.rs:190 #16 0x00007fffef56d83f in rustc_interface::interface::run_compiler::{{closure}} () at /rust/rust/compiler/rustc_interface/src/interface.rs:212 #17 rustc_interface::util::setup_callbacks_and_run_in_thread_pool_with_globals::{{closure}}::{{closure}} () at /rust/rust/compiler/rustc_interface/src/util.rs:152 #18 scoped_tls::ScopedKey<T>::set () at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/scoped-tls-1.0.0/src/lib.rs:137 #19 0x00007fffef572e45 in rustc_span::with_session_globals () at /rust/rust/compiler/rustc_span/src/lib.rs:93 #20 rustc_interface::util::setup_callbacks_and_run_in_thread_pool_with_globals::{{closure}} () at /rust/rust/compiler/rustc_interface/src/util.rs:150 #21 rustc_interface::util::scoped_thread::{{closure}} () at /rust/rust/compiler/rustc_interface/src/util.rs:125 #22 std::sys_common::backtrace::__rust_begin_short_backtrace () at /rust/rust/library/std/src/sys_common/backtrace.rs:125 #23 0x00007fffef5bbd0f in std::thread::Builder::spawn_unchecked::{{closure}}::{{closure}} () at /rust/rust/library/std/src/thread/mod.rs:474 #24 <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once () at /rust/rust/library/std/src/panic.rs:322 #25 std::panicking::try::do_call () at /rust/rust/library/std/src/panicking.rs:379 #26 std::panicking::try () at /rust/rust/library/std/src/panicking.rs:343 #27 std::panic::catch_unwind () at /rust/rust/library/std/src/panic.rs:396 #28 std::thread::Builder::spawn_unchecked::{{closure}} () at /rust/rust/library/std/src/thread/mod.rs:473 #29 core::ops::function::FnOnce::call_once{{vtable-shim}} () at /rust/rust/library/core/src/ops/function.rs:227 #30 0x00007fffeea33488 in <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once () at /rust/rust/library/alloc/src/boxed.rs:1318 #31 <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once () at /rust/rust/library/alloc/src/boxed.rs:1318 #32 std::sys::unix::thread::Thread::new::thread_start () at library/std/src/sys/unix/thread.rs:71 #33 0x00007fffee74f609 in start_thread (arg=<optimized out>) at pthread_create.c:477 #34 0x00007fffee891293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95 ``` - `compiler/rustc_parse/src/parser/item.rs` - parse_crate_mod() - parse_item() - parse_item_common() - Selfはキーワード - https://doc.rust-lang.org/beta/std/keyword.Self.html - collect_tokenがparse_itemを実行 - parse_item_kind() - check_fn_front_matter() - fnのパーサー(関数判定) - parse_ident() - 関数名が入るはず(pで中身見れないのつらいな.) - fn where構文 - parse_fn_body() ``` (gdb) b parse_fn_ rustc_parse::parser::expr::<impl rustc_parse::parser::Parser>::parse_fn_block_param rustc_parse::parser::item::<impl rustc_parse::parser::Parser>::parse_fn_decl rustc_parse::parser::item::<impl rustc_parse::parser::Parser>::parse_fn_front_matter rustc_parse::parser::item::<impl rustc_parse::parser::Parser>::parse_fn_params::{{closure}} (gdb) b parse_fn_body (gdb) b item.rs:1535 Continuing. [New Thread 0x7fffee3f1700 (LWP 2815433)] [Switching to Thread 0x7fffee3f1700 (LWP 2815433)] Thread 2 "rustc" hit Breakpoint 2, rustc_parse::parser::item::<impl rustc_parse::parser::Parser>::parse_fn_body () at compiler/rustc_parse/src/parser/item.rs:1535 1535 let (inner_attrs, body) = if self.eat(&token::Semi) { (gdb) l 1530 &mut self, 1531 attrs: &mut Vec<Attribute>, 1532 ident: &Ident, 1533 sig_hi: &mut Span, 1534 ) -> PResult<'a, Option<P<Block>>> { 1535 let (inner_attrs, body) = if self.eat(&token::Semi) { 1536 // Include the trailing semicolon in the span of the signature 1537 *sig_hi = self.prev_token.span; 1538 (Vec::new(), None) 1539 } else if self.check(&token::OpenDelim(token::Brace)) || self.token.is_whole_block() { (gdb) p token $1 = {fn () -> int} 0x7fffee8a8d20 <token> (gdb) p *token $2 = {fn () -> int} 0x7fffee8a8d20 <token> ``` # 2020/11/29 ## テストコード ```rust fn hugo(i: i64) -> i64 { return i * 2 + 1; } fn main() { let hoge = 1; println!("hello {:?}", hugo(hoge*2+1)); } ``` ## used with no filenames on the command line, reading from STDIN. ## compiler/rustc_ast - READMEにあったURL - https://rustc-dev-guide.rust-lang.org/the-parser.html - https://rustc-dev-guide.rust-lang.org/macro-expansion.html - マクロ展開系を書くのは新たに1言語書くのに等しい... - マクロルールで定義する方法 - src - ast.rs - trait - https://doc.rust-lang.org/rust-by-example/trait.html - lifetime - AngleBracketedArg - ParamKindOrd - 関数の中で関数を定義(nested function) - operator - Exprのspanの中身をみたい. - exprが1 + 1だったらspanには1が入っているはず - precedence - operationのオーダー - ExprKind::Binary # compiler/rustc_parse/src/parser/expr.rs周辺をトレース - used with no filenames on the command line, reading from STDIN. - mk_expr_opでexprのoperationを作るはず - bump() bump_with() - https://doc.rust-lang.org/nightly/nightly-rustc/rustc_parse/parser/struct.Parser.html#method.bump - advance the parser by one token - トークン一つ読み飛ばす...? - 1 + 1だったら1の次に1を読む感じか. - op.fixity() - 結合方向 - https://cgaebel.github.io/rispc/syntex_syntax/util/parser/enum.Fixity.html - 計算された値はrhsに入るはず(pで中身が見れないから全部"〜はず"になる...) - mk_expr_sp() - 計算の優先順位をみて順番を変える. - recursive descent - https://ie.u-ryukyu.ac.jp/~kono/lecture/compiler/c4/lecture.html#content008 # コード生成部分をみる - used with no filenames on the command line, reading from STDIN. - compiler/rustc_codegen_ssa/README.md - https://rustc-dev-guide.rust-lang.org/backend/backend-agnostic.html - LLVM IRを生成する前にMIRを生成する. - compiler/rustc_mirあたりを読む - compiler/rustc_middle - compiler/rustc_hir - high level IR - src - arena.rs - def.rs - DefKind - 定義できるものの種類をまとめた - rustcで生成後のものは見れる ```rust Singularity> rustc -Z unstable-options --pretty expanded,identified /tmp/test.rs #![feature(prelude_import)] #![no_std] #[prelude_import] use ::std::prelude::v1::*; /* 4 */ #[macro_use] extern crate std; /* 10 */ fn hugo(i /* pat 13 */: i64) -> i64 { (return (((i /* 20 */) * (2 /* 21 */) /* 22 */) + (1 /* 23 */) /* 24 */) /* 25 */); } /* block 18 */ /* 11 */ fn main() { let hoge /* pat 29 */ = (1 /* 30 */); ({ ((::std::io::_print /* 35 */)(((::core::fmt::Arguments::new_v1 /* 42 */)((&([("hello " /* 43 */), ("\n" /* 44 */)] /* 45 */) /* 46 */), (&(match (((&((hugo /* 48 */)((((hoge /* 50 */) * (2 /* 51 */) /* 52 */) + (1 /* 53 */) /* 54 */)) /* 55 */) /* 56 */),) /* 57 */) { (arg0 /* pat 60 */,) /* pat 59 */ => ([((::core::fmt::ArgumentV1::new /* 65 */)((arg0 /* 67 */), (::core::fmt::Debug::fmt /* 72 */)) /* 73 */)] /* 74 */), } /* 75 */) /* 76 */)) /* 77 */)) /* 36 */); } /* block 31 */ /* 37 */); } /* block 27 */ /* 26 */ ``` - used with no filenames on the command line, reading from STDIN. - rustc -Zunpretty=hir-tree /tmp/test.rs - こっちのほうが正解 - 実行してみるとめっちゃ長いHIRのコードが見れる. ## high level からじゃなくて low levelからアプローチしてみる? - rustc_passesからアプローチをかけるか. - public/rustc_mir_build/src/build/ - into.rs - into_expr() - codegenっぽいところ ``` #0 <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate () at compiler/rustc_codegen_llvm/src/lib.rs:270 #1 0x00007fffef91c75b in rustc_interface::passes::start_codegen::{{closure}} () at compiler/rustc_interface/src/passes.rs:996 #2 rustc_data_structures::profiling::VerboseTimingGuard::run () at /rust/rust/compiler/rustc_data_structures/src/profiling.rs:570 #3 rustc_session::utils::<impl rustc_session::session::Session>::time () at /rust/rust/compiler/rustc_session/src/utils.rs:9 #4 rustc_interface::passes::start_codegen () at compiler/rustc_interface/src/passes.rs:995 #5 rustc_interface::queries::Queries::ongoing_codegen::{{closure}}::{{closure}} () at compiler/rustc_interface/src/queries.rs:284 #6 rustc_interface::passes::QueryContext::enter::{{closure}} () at compiler/rustc_interface/src/passes.rs:725 #7 rustc_middle::ty::context::tls::enter_context::{{closure}} () at /rust/rust/compiler/rustc_middle/src/ty/context.rs:1739 #8 rustc_middle::ty::context::tls::set_tlv () at /rust/rust/compiler/rustc_middle/src/ty/context.rs:1723 #9 rustc_middle::ty::context::tls::enter_context () at /rust/rust/compiler/rustc_middle/src/ty/context.rs:1739 #10 rustc_interface::passes::QueryContext::enter () at compiler/rustc_interface/src/passes.rs:725 #11 0x00007fffef818cb5 in rustc_interface::queries::Queries::ongoing_codegen::{{closure}} () at compiler/rustc_interface/src/queries.rs:275 #12 rustc_interface::queries::Query<T>::compute () at compiler/rustc_interface/src/queries.rs:35 #13 rustc_interface::queries::Queries::ongoing_codegen () at compiler/rustc_interface/src/queries.rs:273 #14 0x00007fffef58d391 in rustc_driver::run_compiler::{{closure}}::{{closure}} () --Type <RET> for more, q to quit, c to continue without paging-- at compiler/rustc_driver/src/lib.rs:441 #15 rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter () at /rust/rust/compiler/rustc_interface/src/queries.rs:415 #16 0x00007fffef64d497 in rustc_driver::run_compiler::{{closure}} () at compiler/rustc_driver/src/lib.rs:336 #17 rustc_interface::interface::create_compiler_and_run::{{closure}} () at /rust/rust/compiler/rustc_interface/src/interface.rs:196 #18 rustc_span::with_source_map () at /rust/rust/compiler/rustc_span/src/lib.rs:764 #19 0x00007fffef58ef94 in rustc_interface::interface::create_compiler_and_run () at /rust/rust/compiler/rustc_interface/src/interface.rs:190 #20 0x00007fffef56d83f in rustc_interface::interface::run_compiler::{{closure}} () at /rust/rust/compiler/rustc_interface/src/interface.rs:212 #21 rustc_interface::util::setup_callbacks_and_run_in_thread_pool_with_globals::{{closure}}::{{closure}} () at /rust/rust/compiler/rustc_interface/src/util.rs:152 #22 scoped_tls::ScopedKey<T>::set () at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/scoped-tls-1.0.0/src/lib.rs:137 #23 0x00007fffef572e45 in rustc_span::with_session_globals () at /rust/rust/compiler/rustc_span/src/lib.rs:93 #24 rustc_interface::util::setup_callbacks_and_run_in_thread_pool_with_globals::{{closure}} () at /rust/rust/compiler/rustc_interface/src/util.rs:150 #25 rustc_interface::util::scoped_thread::{{closure}} () at /rust/rust/compiler/rustc_interface/src/util.rs:125 #26 std::sys_common::backtrace::__rust_begin_short_backtrace () at /rust/rust/library/std/src/sys_common/backtrace.rs:125 #27 0x00007fffef5bbd0f in std::thread::Builder::spawn_unchecked::{{closure}}::{{closure}} () at /rust/rust/library/std/src/thread/mod.rs:474 #28 <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once () at /rust/rust/library/std/src/panic.rs:322 --Type <RET> for more, q to quit, c to continue without paging-- #29 std::panicking::try::do_call () at /rust/rust/library/std/src/panicking.rs:379 #30 std::panicking::try () at /rust/rust/library/std/src/panicking.rs:343 #31 std::panic::catch_unwind () at /rust/rust/library/std/src/panic.rs:396 #32 std::thread::Builder::spawn_unchecked::{{closure}} () at /rust/rust/library/std/src/thread/mod.rs:473 #33 core::ops::function::FnOnce::call_once{{vtable-shim}} () at /rust/rust/library/core/src/ops/function.rs:227 #34 0x00007fffeea33488 in <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once () at /rust/rust/library/alloc/src/boxed.rs:1318 #35 <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once () at /rust/rust/library/alloc/src/boxed.rs:1318 #36 std::sys::unix::thread::Thread::new::thread_start () at library/std/src/sys/unix/thread.rs:71 #37 0x00007fffee74f609 in start_thread (arg=<optimized out>) at pthread_create.c:477 #38 0x00007fffee891293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95 ``` - rustでunicode使えるはず - https://doc.rust-lang.org/book/ch08-02-strings.html ## compiler/rustc_interface/src/queries.rs - lower_to_hir ## compiler/rustc_codegen_ssa - codegen_crate() - cgu_name_builder() - codegen_unit() - monomorphization - ポリモーフィズムなところをアセンブラ用にモノに直すこと - dep_graph - dependency graph - ongoing_codegen - パラレルコンパイル - LTO - linking最適化をしてスピードアップを図る - https://doc.rust-lang.org/rustc/linker-plugin-lto.html - generate_lto_work - WorkItem::CopyPostLtoArtifacts() - Itemは並列処理でスレッド処理していく単位 - codegen_statement ## rustc_codegen_llvm - https://rustc-dev-guide.rust-lang.org/backend/codegen.html - builder.rs - BuilderMethods - from_const - 実態はlayout - OperandValue::Immediate() - llvmのAPI - eval_mir_constant_to_operand ``` #0 <rustc_codegen_llvm::builder::Builder as rustc_target::abi::LayoutOf>::layout_of () at compiler/rustc_codegen_llvm/src/builder.rs:92 #1 rustc_codegen_ssa::mir::operand::OperandRef<V>::from_const () at /rust/rust/compiler/rustc_codegen_ssa/src/mir/operand.rs:74 #2 0x00007fffefab11c0 in rustc_codegen_ssa::mir::constant::<impl rustc_codegen_ssa::mir::FunctionCx<Bx>>::eval_mir_constant_to_operand () at /rust/rust/compiler/rustc_codegen_ssa/src/mir/constant.rs:20 #3 rustc_codegen_ssa::mir::operand::<impl rustc_codegen_ssa::mir::FunctionCx<Bx>>::codegen_operand () at /rust/rust/compiler/rustc_codegen_ssa/src/mir/operand.rs:442 #4 0x00007fffefaad25b in rustc_codegen_ssa::mir::rvalue::<impl rustc_codegen_ssa::mir::FunctionCx<Bx>>::codegen_rvalue_operand () at /rust/rust/compiler/rustc_codegen_ssa/src/mir/rvalue.rs:458 #5 0x00007fffefaa07c6 in rustc_codegen_ssa::mir::statement::<impl rustc_codegen_ssa::mir::FunctionCx<Bx>>::codegen_statement () at /rust/rust/compiler/rustc_codegen_ssa/src/mir/statement.rs:24 #6 rustc_codegen_ssa::mir::block::<impl rustc_codegen_ssa::mir::FunctionCx<Bx>>::codegen_block () at /rust/rust/compiler/rustc_codegen_ssa/src/mir/block.rs:939 #7 0x00007fffefa9db40 in rustc_codegen_ssa::mir::codegen_mir () at /rust/rust/compiler/rustc_codegen_ssa/src/mir/mod.rs:254 #8 0x00007fffefbda37a in rustc_codegen_ssa::base::codegen_instance () at /rust/rust/compiler/rustc_codegen_ssa/src/base.rs:358 #9 0x00007fffef9c6b44 in <rustc_middle::mir::mono::MonoItem as rustc_codegen_ssa::mono_item::MonoItemExt>::define () at /rust/rust/compiler/rustc_codegen_ssa/src/mono_item.rs:42 #10 0x00007fffefa6f39b in rustc_codegen_llvm::base::compile_codegen_unit::module_codegen () at compiler/rustc_codegen_llvm/src/base.rs:128 #11 0x00007fffefad280e in rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl () at /rust/rust/compiler/rustc_query_system/src/dep_graph/graph.rs:301 #12 rustc_query_system::dep_graph::graph::DepGraph<K>::with_task () --Type <RET> for more, q to quit, c to continue without paging-- at /rust/rust/compiler/rustc_query_system/src/dep_graph/graph.rs:200 #13 0x00007fffefa6ec9c in rustc_codegen_llvm::base::compile_codegen_unit () at compiler/rustc_codegen_llvm/src/base.rs:104 #14 0x00007fffefbd795d in <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::ExtraBackendMethods>::compile_codegen_unit () at compiler/rustc_codegen_llvm/src/lib.rs:106 #15 rustc_codegen_ssa::base::codegen_crate () at /rust/rust/compiler/rustc_codegen_ssa/src/base.rs:642 #16 0x00007fffefc11b95 in <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate () at compiler/rustc_codegen_llvm/src/lib.rs:267 #17 0x00007fffef91c75b in rustc_interface::passes::start_codegen::{{closure}} () at compiler/rustc_interface/src/passes.rs:996 #18 rustc_data_structures::profiling::VerboseTimingGuard::run () at /rust/rust/compiler/rustc_data_structures/src/profiling.rs:570 #19 rustc_session::utils::<impl rustc_session::session::Session>::time () at /rust/rust/compiler/rustc_session/src/utils.rs:9 #20 rustc_interface::passes::start_codegen () at compiler/rustc_interface/src/passes.rs:995 #21 rustc_interface::queries::Queries::ongoing_codegen::{{closure}}::{{closure}} () at compiler/rustc_interface/src/queries.rs:284 #22 rustc_interface::passes::QueryContext::enter::{{closure}} () at compiler/rustc_interface/src/passes.rs:725 #23 rustc_middle::ty::context::tls::enter_context::{{closure}} () at /rust/rust/compiler/rustc_middle/src/ty/context.rs:1739 #24 rustc_middle::ty::context::tls::set_tlv () at /rust/rust/compiler/rustc_middle/src/ty/context.rs:1723 #25 rustc_middle::ty::context::tls::enter_context () at /rust/rust/compiler/rustc_middle/src/ty/context.rs:1739 --Type <RET> for more, q to quit, c to continue without paging-- #26 rustc_interface::passes::QueryContext::enter () at compiler/rustc_interface/src/passes.rs:725 #27 0x00007fffef818cb5 in rustc_interface::queries::Queries::ongoing_codegen::{{closure}} () at compiler/rustc_interface/src/queries.rs:275 #28 rustc_interface::queries::Query<T>::compute () at compiler/rustc_interface/src/queries.rs:35 #29 rustc_interface::queries::Queries::ongoing_codegen () at compiler/rustc_interface/src/queries.rs:273 #30 0x00007fffef58d391 in rustc_driver::run_compiler::{{closure}}::{{closure}} () at compiler/rustc_driver/src/lib.rs:441 #31 rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter () at /rust/rust/compiler/rustc_interface/src/queries.rs:415 #32 0x00007fffef64d497 in rustc_driver::run_compiler::{{closure}} () at compiler/rustc_driver/src/lib.rs:336 #33 rustc_interface::interface::create_compiler_and_run::{{closure}} () at /rust/rust/compiler/rustc_interface/src/interface.rs:196 #34 rustc_span::with_source_map () at /rust/rust/compiler/rustc_span/src/lib.rs:764 #35 0x00007fffef58ef94 in rustc_interface::interface::create_compiler_and_run () at /rust/rust/compiler/rustc_interface/src/interface.rs:190 #36 0x00007fffef56d83f in rustc_interface::interface::run_compiler::{{closure}} () at /rust/rust/compiler/rustc_interface/src/interface.rs:212 #37 rustc_interface::util::setup_callbacks_and_run_in_thread_pool_with_globals::{{closure}}::{{closure}} () at /rust/rust/compiler/rustc_interface/src/util.rs:152 #38 scoped_tls::ScopedKey<T>::set () at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/scoped-tls-1.0.0/src/lib.rs:137 #39 0x00007fffef572e45 in rustc_span::with_session_globals () at /rust/rust/compiler/rustc_span/src/lib.rs:93 #40 rustc_interface::util::setup_callbacks_and_run_in_thread_pool_with_globals::{{clo--Type <RET> for more, q to quit, c to continue without paging-- sure}} () at /rust/rust/compiler/rustc_interface/src/util.rs:150 #41 rustc_interface::util::scoped_thread::{{closure}} () at /rust/rust/compiler/rustc_interface/src/util.rs:125 #42 std::sys_common::backtrace::__rust_begin_short_backtrace () at /rust/rust/library/std/src/sys_common/backtrace.rs:125 #43 0x00007fffef5bbd0f in std::thread::Builder::spawn_unchecked::{{closure}}::{{closure}} () at /rust/rust/library/std/src/thread/mod.rs:474 #44 <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once () at /rust/rust/library/std/src/panic.rs:322 #45 std::panicking::try::do_call () at /rust/rust/library/std/src/panicking.rs:379 #46 std::panicking::try () at /rust/rust/library/std/src/panicking.rs:343 #47 std::panic::catch_unwind () at /rust/rust/library/std/src/panic.rs:396 #48 std::thread::Builder::spawn_unchecked::{{closure}} () at /rust/rust/library/std/src/thread/mod.rs:473 #49 core::ops::function::FnOnce::call_once{{vtable-shim}} () at /rust/rust/library/core/src/ops/function.rs:227 #50 0x00007fffeea33488 in <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once () at /rust/rust/library/alloc/src/boxed.rs:1318 #51 <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once () at /rust/rust/library/alloc/src/boxed.rs:1318 #52 std::sys::unix::thread::Thread::new::thread_start () at library/std/src/sys/unix/thread.rs:71 #53 0x00007fffee74f609 in start_thread (arg=<optimized out>) at pthread_create.c:477 #54 0x00007fffee891293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95 ```