Sunday 29 November 2020

Rustc 読み会最終日

なんか立命館の学生も参加してくれたみたい。今日はastとcodegenで、かろうじて code 生成まで行き着いた感じです。

code 生成は Thread pool に投げてて、素直にトレースできない。で、しばらく迷走したんですが、

#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

みたいに捕まえられました。ast -> hir -> mir -> llvm-ir みたいに生成するらしい。

40万ですが、今まで見たコンパイラのソースの方では良い感じ。特に smart pointer とかexceptionとかの処理が Rust はスムーズ。

ただ、Thread pool は微妙な感じね。Pthead だし。この辺は golang の方ができが良いかな。iterator が並列化されるみたいな方が自然で良いかも。

No comments: