Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Go の静的解析ツールの作成と活用

Go の静的解析ツールの作成と活用

Takumasa Sakao

February 22, 2019
Tweet

More Decks by Takumasa Sakao

Other Decks in Programming

Transcript

  1. >/=& • @sachaos ( @) – Twitter, GitHub  

     – *B8 #%  -  • 2.: 61'< – 4) 3 0; – 3?+:C9 – Go, GCP – % %"$!7 • 5A>(% %,
  2. 

  3. Go 714,  • 714,  parse  AST %)$52

    / *'3 • Go +08 • Go  '3 6#!"&( 8 – AST %) go/ast – $.- go/types – SSA golang.org/x/tools/go/ssa –  golang.org/x/tools/go/analysis –
  4. ==   1. AST   (go/ast) 2. 

    error interface    (go/types)
  5. 0" Wrap '. • /) error #! *(return)1 Wrap (xerrors.Errorf(“wrap:

    %w”, err))    3- • ,+&2 – <= Wrap   Wrap    error interface  $ %(  
  6. return   Wrap   • MayFail1() err 

     • MayFail2() err Wrap    • MayFail3 error Wrap   • return Wrap  MayFail3 err  Wrap    MayFail2 err 
  7. SSA  • Static Single Assignment  •  

       •  golang.org/x/tools/go/ssa  
  8. return  Wrap  • return  t3  t2,

    t5  (φ) • t2 MayFail2  Wrap    NG • t5 t4  Wrap   OK
  9.  • Go 1.13  error $%&#')*("-,  8 •

    xerrors "0/. 7362"  • 7362   Go 4+  • ! Qiita 1 4  "5  – https://qiita.com/sachaos/items/f6b3e66931d7f73dd68d
  10.