Slide 1

Slide 1 text

SWIFT CONTRIBUTING JESSE SQUIRES TO OPEN SOURCE

Slide 2

Slide 2 text

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?

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

WHERE DO YOU START?

Slide 5

Slide 5 text

HOW DOES IT ALL WORK TOGETHER?

Slide 6

Slide 6 text

WHAT HAPPENS WHEN YOU COMPILE YOUR CODE?

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

A BRIEF EXAMPLE

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

AST >swiftc -dump-ast hello.swift

Slide 15

Slide 15 text

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!"))))))))

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

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)

Slide 18

Slide 18 text

LLVM IR >swiftc -emit-ir hello.swift

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

PROJECTS AND REPOSITORIES

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

EVOLUTION Proposals Development Schedule Release Schedule

Slide 29

Slide 29 text

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

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

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!

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

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

Slide 34

Slide 34 text

why contribute?

Slide 35

Slide 35 text

SWIFTIS MORE PROGRAMMING LANGUAGE THAN A

Slide 36

Slide 36 text

SWIFT COMMUNITY IS A

Slide 37

Slide 37 text

DON’T BE AFRAID try! contribute()

Slide 38

Slide 38 text

THANKS! JESSESQUIRES.COM • @JESSE_SQUIRES • @SWIFTLYBRIEF