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

Contributing to open source Swift

Contributing to open source Swift

Do you want to contribute to Swift? Not sure how or where to begin? It can be overwhelming! In this talk we'll explore the different parts of Swift, see how the various Swift projects are related, discuss the skills you need to get started, and learn the best ways to get your first fix accepted.

Video:
https://realm.io/news/tryswift-jesse-squires-contributing-open-source-swift/

Event:
http://www.tryswiftconf.com/en

Jesse Squires

March 04, 2016
Tweet

More Decks by Jesse Squires

Other Decks in Programming

Transcript

  1. SWIFT
    CONTRIBUTING
    JESSE SQUIRES
    TO OPEN SOURCE

    View full-size slide

  2. IN THIS TALK
    ‣ What are all the different parts of Swift?
    ‣ What does each part do?
    ‣ LLVM demystified
    ‣ What skills do you need?
    ‣ Contributing process
    ‣ Tips for getting accepted
    ‣ Why should you contribute?

    View full-size slide

  3. swift
    swift-lldb
    swift-clang
    swift-llvm
    corelibs-xctest
    corelibs-libdispatch
    corelibs-foundation
    swift-evolution
    swift-llbuild
    swift-package-manager
    stdlib

    View full-size slide

  4. WHERE DO YOU START?

    View full-size slide

  5. HOW DOES IT ALL
    WORK
    TOGETHER?

    View full-size slide

  6. WHAT HAPPENS WHEN
    YOU COMPILE
    YOUR CODE?

    View full-size slide

  7. LLVM COMPILER
    ARCHITECTURE
    Front
    end
    Back
    end
    LLVM
    IR
    Machine
    Code
    LLVM
    Optimizer
    C/C++
    Fortran
    Haskell
    Swift
    x86
    PowerPC
    ARM

    View full-size slide

  8. CLANG PIPELINE
    Parse
    AST AST*
    Sema CodeGen LLVM
    *.o
    LLVM
    IR
    *.c
    *.cpp
    *.m
    CFG
    Analysis -Wunreachable-code
    -Wuninitialized
    Static analyzer

    View full-size slide

  9. SWIFT PIPELINE
    *.swift
    Parse
    AST AST* SIL
    (raw)
    Sema SILGen Analysis &
    Optimization
    *.o
    LLVM
    IR
    SIL*
    (canonical)
    LLVM IRGen
    *.module
    map
    Clang
    Importer

    View full-size slide

  10. A BRIEF EXAMPLE

    View full-size slide

  11. // hello.swift
    print("hello swift!")
    *.swift

    View full-size slide

  12. >swiftc hello.swift
    >./hello
    hello swift!
    *.swift

    View full-size slide

  13. AST
    >swiftc -dump-ast hello.swift

    View full-size slide

  14. AST
    (source_file
    (top_level_code_decl
    (brace_stmt
    (call_expr type='()' location=hello.swift:4:1 range=[hello.swift:4:1 - line:4:21]
    nothrow
    (declref_expr type='(Any..., separator: String, terminator: String) -> ()'
    location=hello.swift:4:1 range=[hello.swift:4:1 - line:4:1] decl=Swift.
    (file).print(_:separator:terminator:) specialized=no)
    (tuple_shuffle_expr implicit type='(Any..., separator: String, terminator:
    String)' location=hello.swift:4:7 range=[hello.swift:4:6 - line:4:21] sourceIsScalar
    elements=[-2, -1, -1] variadic_sources=[0]
    (paren_expr type='Any' location=hello.swift:4:7 range=[hello.swift:4:6 - line:
    4:21]
    (erasure_expr implicit type='Any' location=hello.swift:4:7 range=[hello.swift:
    4:7 - line:4:7]
    (call_expr implicit type='String' location=hello.swift:4:7 range=[hello.swift:
    4:7 - line:4:7] nothrow
    (constructor_ref_call_expr implicit type='(_builtinStringLiteral: RawPointer,
    byteSize: Word, isASCII: Int1) -> String' location=hello.swift:4:7 range=[hello.swift:4:7 -
    line:4:7] nothrow
    (declref_expr implicit type='String.Type -> (_builtinStringLiteral:
    RawPointer, byteSize: Word, isASCII: Int1) -> String' location=hello.swift:4:7
    range=[hello.swift:4:7 - line:4:7] decl=Swift.
    (file).String.init(_builtinStringLiteral:byteSize:isASCII:) specialized=no)
    (type_expr implicit type='String.Type' location=hello.swift:4:7
    range=[hello.swift:4:7 - line:4:7] typerepr='<>'))
    (string_literal_expr type='(_builtinStringLiteral: Builtin.RawPointer,
    byteSize: Builtin.Word, isASCII: Builtin.Int1)' location=hello.swift:4:7 range=[hello.swift:
    4:7 - line:4:7] encoding=utf8 value="hello swift!"))))))))

    View full-size slide

  15. >swiftc -emit-silgen hello.swift
    | xcrun swift-demangle
    SIL
    (raw)

    View full-size slide

  16. sil_stage raw
    import Builtin
    import Swift
    import SwiftShims
    // main
    sil @main : $@convention(c) (Int32, UnsafeMutablePointer>) -> Int32 {
    bb0(%0 : $Int32, %1 : $UnsafeMutablePointer>):
    // function_ref Swift._didEnterMain (Swift.Int32, argv : Swift.UnsafeMutablePointer>) -> ()
    %2 = function_ref @Swift._didEnterMain (Swift.Int32, argv : Swift.UnsafeMutablePointer>) -> () : $@convention(thin) (Int32,
    UnsafeMutablePointer>) -> () // user: %3
    %3 = apply %2(%0, %1) : $@convention(thin) (Int32, UnsafeMutablePointer>) -> ()
    // function_ref Swift.print (Swift.Array>, separator : Swift.String, terminator : Swift.String) -> ()
    %4 = function_ref @Swift.print ([protocol<>], separator : Swift.String, terminator : Swift.String) -> () : $@convention(thin) (@owned Array>, @owned
    String, @owned String) -> () // user: %23
    %5 = integer_literal $Builtin.Word, 1 // user: %7
    // function_ref Swift._allocateUninitializedArray (Builtin.Word) -> (Swift.Array, Builtin.RawPointer)
    %6 = function_ref @Swift._allocateUninitializedArray (Builtin.Word) -> ([A], Builtin.RawPointer) : $@convention(thin) <τ_0_0> (Builtin.Word) -> @owned
    (Array<τ_0_0>, Builtin.RawPointer) // user: %7
    %7 = apply %6>(%5) : $@convention(thin) <τ_0_0> (Builtin.Word) -> @owned (Array<τ_0_0>, Builtin.RawPointer) // users: %8, %9
    %8 = tuple_extract %7 : $(Array>, Builtin.RawPointer), 0 // user: %23
    %9 = tuple_extract %7 : $(Array>, Builtin.RawPointer), 1 // user: %10
    %10 = pointer_to_address %9 : $Builtin.RawPointer to $*protocol<> // user: %11
    %11 = init_existential_addr %10 : $*protocol<>, $String // user: %18
    // function_ref Swift.String.init (Swift.String.Type)(_builtinStringLiteral : Builtin.RawPointer, byteSize : Builtin.Word, isASCII : Builtin.Int1) -> Swift.String
    %12 = function_ref @Swift.String.init (Swift.String.Type)(_builtinStringLiteral : Builtin.RawPointer, byteSize : Builtin.Word, isASCII : Builtin.Int1) ->
    Swift.String : $@convention(thin) (Builtin.RawPointer, Builtin.Word, Builtin.Int1, @thin String.Type) -> @owned String // user: %17
    %13 = metatype $@thin String.Type // user: %17
    %14 = string_literal utf8 "hello swift!" // user: %17
    %15 = integer_literal $Builtin.Word, 12 // user: %17
    %16 = integer_literal $Builtin.Int1, -1 // user: %17
    %17 = apply %12(%14, %15, %16, %13) : $@convention(thin) (Builtin.RawPointer, Builtin.Word, Builtin.Int1, @thin String.Type) -> @owned String // user: %18
    store %17 to %11 : $*String // id: %18
    // function_ref Swift.(print (Swift.Array>, separator : Swift.String, terminator : Swift.String) -> ()).(default argument 1)
    %19 = function_ref @Swift.(print ([protocol<>], separator : Swift.String, terminator : Swift.String) -> ()).(default argument 1) : $@convention(thin) () -> @owned
    String // user: %20
    %20 = apply %19() : $@convention(thin) () -> @owned String // user: %23
    // function_ref Swift.(print (Swift.Array>, separator : Swift.String, terminator : Swift.String) -> ()).(default argument 2)
    %21 = function_ref @Swift.(print ([protocol<>], separator : Swift.String, terminator : Swift.String) -> ()).(default argument 2) : $@convention(thin) () -> @owned
    String // user: %22
    %22 = apply %21() : $@convention(thin) () -> @owned String // user: %23
    %23 = apply %4(%8, %20, %22) : $@convention(thin) (@owned Array>, @owned String, @owned String) -> ()
    %24 = integer_literal $Builtin.Int32, 0 // user: %25
    %25 = struct $Int32 (%24 : $Builtin.Int32) // user: %26
    return %25 : $Int32 // id: %26
    }
    SIL
    (raw)

    View full-size slide

  17. LLVM
    IR
    >swiftc -emit-ir hello.swift

    View full-size slide

  18. >swiftc -emit-assembly hello.swift
    *.o

    View full-size slide

  19. PROJECTS AND
    REPOSITORIES

    View full-size slide

  20. SWIFT PIPELINE
    *.swift
    Parse
    AST AST* SIL
    (raw)
    Sema SILGen Analysis &
    Optimization
    *.o
    LLVM
    IR
    SIL*
    (canonical)
    LLVM IRGen
    *.module
    map
    Clang
    Importer

    View full-size slide

  21. github / apple / swift
    *.swift
    lib/Parse
    AST AST* SIL
    (raw)
    lib/Sema lib/SILGen
    lib/SILOptimizer
    *.o
    LLVM
    IR
    SIL*
    (canonical)
    lib/IRGen
    *.module
    map
    lib/
    ClangImporter
    swift-llvm
    swift-clang
    swift-lldb
    stdlib
    corelibs
    SPM

    View full-size slide

  22. SWIFT CORE
    Compiler stdlib
    • Hard
    • C++
    • High
    • Medium
    • Swift*
    • Medium
    SourceKit
    • Hard
    • C++
    • Low

    View full-size slide

  23. INFRA
    • LLVM Clones with Swift-specific changes
    • Very Hard
    • C++
    • Low
    • Upstream changes not Swift-specific
    • Governed by LLVM dev policies, license, etc. swift-lldb
    swift-clang
    swift-llvm

    View full-size slide

  24. PACKAGE MANAGER
    swift-llbuild
    swift
    package
    manager
    • Medium
    • Swift
    • High
    • Hard
    • C++
    • Low

    View full-size slide

  25. CORE LIBS
    Foundation XCTest
    libdispatch
    (GCD)
    • Easy
    • Swift, C
    • High
    • Easy
    • Swift
    • High
    • Hard
    • C
    • Low

    View full-size slide

  26. EVOLUTION
    Proposals
    Development
    Schedule
    Release
    Schedule

    View full-size slide

  27. CONTRIBUTING.md
    ✨ Do it right ✨
    swift.org/contributing

    View full-size slide

  28. contribute
    tests bug fixes
    documentation
    translations
    typos
    new features
    code clean up
    mailing lists
    proposals

    View full-size slide

  29. CONTRIBUTING.md
    #ProTips
    • Be kind, thoughtful
    • Ask for help
    • Follow best practices
    • Rejected? Don’t stop contributing!
    • Core team knows the big picture
    • CODE_OWNERS.txt
    • No one is an expert in everything!

    View full-size slide

  30. practicalswift
    @practicalswift
    compiler crashers
    Brian Gesiak
    @modocache
    corelibs-xctest
    Erica Sadun
    @ericasadun
    proposals
    Greg Titus
    @gregtitus
    parser, AST, sema
    AWESOME CONTRIBUTORS

    View full-size slide

  31. Making small improvements is the
    way everyone starts getting
    involved!
    Chris Lattner

    View full-size slide

  32. why contribute?

    View full-size slide

  33. SWIFTIS MORE
    PROGRAMMING
    LANGUAGE
    THAN A

    View full-size slide

  34. SWIFT
    COMMUNITY
    IS A

    View full-size slide

  35. DON’T BE AFRAID
    try! contribute()

    View full-size slide

  36. THANKS!
    JESSESQUIRES.COM • @JESSE_SQUIRES • @SWIFTLYBRIEF

    View full-size slide