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

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

1514536d82df4b4a40628932c432a9c2?s=128

Takumasa Sakao

February 22, 2019
Tweet

Transcript

  1. Go    Akatsuki Geek Live @sachaos

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

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

  4. 

  5. Go 1.13 

  6. Go 1.13 

  7. " !$  github.com/pkg/errors #  !  &'!% 

    :smile:
  8. 

  9.   ==     Wrap 

  10. ==    • ==    xerrors.Is

     
  11.  Wrap  • Wrap  

  12.    Wrap  • Wrap   

     
  13. #* •  ) – => ' '&%'  

    • ("$ ! " )
  14. ($'" )   '"!# %  & & 

    '"&  Wikipedia
  15. 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 –
  16. github.com/sachaos/xerrchk ==  !   Wrap   

  17. ==   1. AST   (go/ast) 2. 

    error interface    (go/types)
  18. 1.   2. error  

  19. 

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

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

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

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

    t5  (φ) • t2 MayFail2  Wrap    NG • t5 t4  Wrap   OK
  24. SSA  • AST      "!

    # 
  25.  • Go 1.13  error $%&#')*("-,  8 •

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