torque in V8

torque in V8

V8 javascript eingineのdslであるtorqueの話

Transcript

  1. V8 torque

  2. Name @brn (ꫬꅿ⨳ⵃ) Occupation ؿٗٝزؒٝسؒٝآص،٥ط؎ذ؍ـؒٝآص، Company Cyberagent ،سذؙأةآؔ AI Messenger

    OSS Contributor of V8 About http://info.b6n.ch
  3. What is torque? V8ⰻ鿇דⵃ欽ׅ׷׋׭ח⡲׵׸׋DSL TypeScript괏㄂ז俑岀ד葿ղ邌植ׅ׷

  4. How does it works? torqueכ؝ٝػ؎ׁٕ׸׷הCSA(CodeStubAssembler)ח㢌䳔ׁ׸ ׷կ CSAכفٓحزؿؓ٦يꬊ⣛㶷זIRד剑穄涸ח،إٝـٓח؝ٝػ ؎ׁٕ׸׷կ

  5. Why V8 need torque? CSAכ剅ְג׫׷ה׻ַ׷ָ穠圓הְֲַַז׶׃׿וְ -  ✲佦׶װְׅ -  僓כ㘗ָⰋגNode㘗׌׏׋ח׮ꟼ׻׵׆ⰻ鿇涸חכSmiהַ IntPtrהַ㘗ָאְגְגծ♶侭さؒٓ٦ָ⳿װַׅ׏׋կ

    -  ⵖ䖴圓俑ָ铣׫חְֻ
  6. function add100() {! let value = 0;! for (let i

    = 0; i < 100; i++) {! value += 1;! }! return value;! }!
  7. TNode<IntPtrT> Add100(TNode<Context> context) {! TVARIABLE(var_value, MachineType::PointerRepresentation(), IntPtrConstant(0));! TVARIABLE(var_index, MachineType::PointerRepresentation(), IntPtrConstant(0));!

    ! Label loop(this), after_loop(this);! ! Branch(IntPtrGreaterThan(IntPtrConstant(100), var_index), &loop, &after_loop);! BIND(&loop);! {! var_a.Bind(IntPtrAdd(var_a, IntPtrConstant(1)));! Increment(&var_index, 1);! Branch(IntPtrGreaterThan(IntPtrConstant(100), var_index),! &loop, &after_loop);! }! BIND(&after_loop);! return var_value.value;! }!
  8. macro Add100(): Smi {! let value: Smi = 0;! let

    len: Smi = 100;! ! for (let i: Smi = 0; k < len; i = i + 1) {! value = value + 1;! }! return value;! }!
  9. torque grammars 㛇劤涸חכ♧菙涸ז䩛竲ֹ㘗鎉铂הずׄ״ֲז俑岀 TypeScriptך㘗،ظذ٦ءّٝ׾⿫罋ח׃גְ׷ ָծDSLזךד׍׳׏ה暴婊ז俑岀׮㢳ְ

  10. Type Definition TypeScriptך䕎ؒ؎ٔ،أה⡂גְ׷ָծֿ׍׵כC++ך㘗ה torqueⰻ鿇ך䕎׾֮׻ׇ׷湡涸

  11. type Object generates 'TNode<Object>';! type int32 generates 'TNode<Int32T>';!

  12. External functions V8ⰻ鿇חכׅדח㣐ꆀךِ٦ذ؍ٔذ؍ꟼ侧ָ㹀纏ׁ׸גֶ׶ծ ׉׸׾ⵃ欽ׅ׷׋׭חextern䭷㹀㶨ָ㹀纏ׁ׸גְ׷ -  macro CSAⰻ鿇ד㹀纏ׁ׸גְ׷ِ٦ذ؍ٔذ؍وؙٗ -  builtin V8ךbuiltins⟃♴ח֮׷ꟼ侧纇

    -  runtime C++ד鎸鶢ׁ׸׋ًاحس
  13. extern macro Print(Object);! ! extern builtin ToObject(Context, Number): Object;! !

    extern runtime CreateDataProperty(! Context, Object, String, Object);!
  14. Operators torqueכoperator׮ꟼ侧ה׃ג㹀纏ׅ׷ֿהָדֹ׷

  15. extern operator "+" macro SmiAdd(Smi, Smi): Smi;! extern operator "-"

    macro SmiSub(Smi, Smi): Smi;!
  16. Cast CastכCSAךCast׾ⵃ欽ׅ׷ָծ㣟侁׃׋㜥さחכGotoדٓكٕפ 굲ע

  17. cast<Smi>(a) otherwise CastError!

  18. Labels CSAכ׮ה׮הַז׶⡚ٖكٕז邌植זךדծ if俑װfor俑瘝ךⵖ䖴圓俑׾׮׏גְזְկ ֿ׸׵׾邌植ׅ׷ךכׅץגLabelהGotoד֮׷կ

  19. Branch(var_a, label1, label2)! ! BIND(&label1);! Print("A");! ! BIND(&label2);! Print("B");!

  20. macro Foo(context: Context): Smi labels Bailout, CastError {! Goto Bailout;!

    }!
  21. compiler::TNode<Smi> FooFromDSLAssembler::Foo(! TNode<Context> p_context,! Label* label_Bailout_1,! Label* label_CastError_1) {! Goto(label_Bailout_1);!

    }!
  22. WriteBarrier V8כ؝ٖٝؕٝز٥؎ًؙٝٔٝةٕGC׾琎׿דְ׷ךדծ ؔـآؙؑزפך،ؙإأךꥷחכWriteBarrierָ䗳갭׌ָ ֿ׸׮CSAך㜥さחכ荈ⴓדWriteBarrier׾⢪ֲַNoBarrierד遤ֻ ַ鼅䫛׃זֽ׸לז׵זְկ torqueדכ㼛勻涸חֿֿ׮荈⹛⻉ׅ׷✮㹀׵׃ְ

  23. Compilation 植㖈ךהֿ׹ػ٦؟٦כAntlrד剅ַ׸גְ׷ 俑岀涸חכLL(1)דػ٦أ〳腉 㼛勻涸חכ䩛剅ֹךػ٦؟ח׃׋ְ׵׃ְ

  24. Compilation V8ךؽٕسفٗإأ⚥ח.tqؿ؋؎ٕךؽٕسָ饥׶ծ ׉ך穠卓 <ر؍ؙٖزٔせ>-<ؿ؋؎ٕせ>-from-dsl-gen.h/cc הְֲC++ؿ؋؎ָٕ欰䧭ׁ׸ ׁ׵ח׉ךؿ؋؎ָٕؽٕسׁ׸غ؎شٔך♧鿇חז׷

  25. .tq ~-from-dsl-gen.h/cc V8

  26. SourceMaps 植㖈ךהֿ׹فٗزة؎ف׌ָծ--gdbjit-fullؔفءّٝדا٦أ⡘ 縧ךوحؾؚٝ׾׃גְ׷׵׃ְ

  27. Summary ؝ٝػ؎ٓך⚥חDSL׾אֻ׷ךכ״ֻ֮׷鑧׌ָծ ֿֿתדֹ׏׍׶׃׋鎉铂כ穠圓棆׃ְ

  28. Reference -  https://docs.google.com/presentation/d/ 1PlQEjS5xyJA-0GY8mjB4wr-pLyzFtdMRfhXczJJ2wic/ edit#slide=id.g388aa7220e_2_348 -  https://github.com/v8/v8/blob/master/src/builtins/typed- array.tq