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. Go


    Akatsuki Geek Live
    @sachaos

    View full-size slide

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

    – *B8 #%

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

    View full-size slide

  3. Go 1.13 error



    View full-size slide

  4. "
    !$
    github.com/pkg/errors #
    !
    &'!%
    :smile:

    View full-size slide

  5. ==
    • ==
    xerrors.Is

    View full-size slide

  6. Wrap
    • Wrap

    View full-size slide


  7. Wrap
    • Wrap

    View full-size slide

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

    • ("$ ! ")

    View full-size slide

  9. ($'" )
    '"!#%
    & &

    '"&
    Wikipedia

    View full-size slide

  10. 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
    –


    View full-size slide

  11. github.com/sachaos/xerrchk
    == !
    Wrap


    View full-size slide

  12. ==

    1. AST (go/ast)
    2. error interface
    (go/types)

    View full-size slide

  13. 0" Wrap '.
    • /) error #! *(return)1
    Wrap (xerrors.Errorf(“wrap: %w”, err))
    3-
    • ,+&2
    – <= Wrap Wrap
    error interface
    $%(

    View full-size slide

  14. return
    Wrap
    • MayFail1() err
    • MayFail2() err Wrap

    • MayFail3 error Wrap
    • return Wrap MayFail3 err
    Wrap

    MayFail2 err

    View full-size slide

  15. SSA
    • Static Single Assignment



    • golang.org/x/tools/go/ssa

    View full-size slide

  16. return
    Wrap
    • return t3 t2, t5 (φ)
    • t2 MayFail2 Wrap
    NG
    • t5 t4 Wrap
    OK

    View full-size slide

  17. SSA

    • AST

    "! #

    View full-size slide


  18. • Go 1.13 error $%')*("-, 8
    • xerrors "0/.7362"
    • 7362
    Go 4+
    • ! Qiita 1 4"5
    – https://qiita.com/sachaos/items/f6b3e66931d7f73dd68d

    View full-size slide