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

OpenSource Swift

OpenSource Swift

"Improving Your Developper Experience With Open-Source Swift " shows how you can download and compile the Swift project and start hacking inside it's internals for some fun & benefits in Xcode.

Presented on Sept 21st, 2018 at FrenchKit Conference (www.frenchkit.fr)
Video at www.youtube.com/watch?v=olS5w9fBxog

Dimitri Dupuis-Latour

September 21, 2018
Tweet

More Decks by Dimitri Dupuis-Latour

Other Decks in Programming

Transcript

  1. I m p r o v i n g y

    o u r Developer Experienc e with Open-Source Swift Dimitri Dupuis-Latour @dupuislatour 2018
  2. https://github.com/apple/swift README git clone 1 repository ./swift/utils/update-checkout 14 repositories 2GB

    source code ./swift/utils/build-script ≈1 hour (full build in debug) ≈70 GB of build artifacts
  3. Refactoring Engine RefactoringKinds.def : CURSOR_REFACTORING(Frenchify, "Frenchify", frenchify.expr) Refactoring.cpp : bool

    RefactoringActionFrenchify::isApplicable(ResolvedCursorInfo CursorInfo) { return true; }
  4. Refactoring Engine RefactoringKinds.def : CURSOR_REFACTORING(Frenchify, "Frenchify", frenchify.expr) Refactoring.cpp : bool

    RefactoringActionFrenchify::isApplicable(ResolvedCursorInfo CursorInfo) { return true; } bool RefactoringActionFrenchify::performChange() { return false; // Return true if code change aborted. }
  5. Refactoring Engine RefactoringKinds.def : CURSOR_REFACTORING(Frenchify, "Frenchify", frenchify.expr) Refactoring.cpp : bool

    RefactoringActionFrenchify::isApplicable(ResolvedCursorInfo CursorInfo) { return true; } bool RefactoringActionFrenchify::performChange() { EditConsumer.insert(SM, Cursor.TrailingExpr->getStartLoc(), "Le "); return false; // Return true if code change aborted. }
  6. Refactoring Engine RefactoringKinds.def : CURSOR_REFACTORING(Frenchify, "Frenchify", frenchify.expr) Refactoring.cpp : bool

    RefactoringActionFrenchify::isApplicable(ResolvedCursorInfo CursorInfo) { return true; } bool RefactoringActionFrenchify::performChange() { EditConsumer.insert(SM, Cursor.TrailingExpr->getStartLoc(), "Le "); EditConsumer.insertAfter(SM, Cursor.TrailingExpr->getEndLoc(), " "); return false; // Return true if code change aborted. }
  7. Bool.toggle() Swift 4.2, Chris Eidhof extension Bool { @_inlineable ///

    Toggles the value of the Boolean. /// /// Calling this method sets the variable to `true` if it was `false`, /// and sets it to `false` if it was `true`. For example: /// /// var bools = [true, false] /// /// bools[0].toggle() /// // bools now contains [false, false] public mutating func toggle() { self = !self } } [SE-0199] Adding toggle to Bool
  8. Dictionary.compactMapValues() Swift 5 /// Returns a new dictionary containing the

    keys of this dictionary with the /// values transformed by the given closure. /// - Parameter transform: A closure that transforms a value. `transform` /// accepts each value of the dictionary as its parameter and returns a /// transformed value of the same or of a different type. /// - Returns: A dictionary containing the keys and transformed values of /// this dictionary. @inlinable // FIXME(sil-serialize-all) public func compactMapValues<T>( _ transform: (Value) throws -> T? ) rethrows -> Dictionary<Key, T> { return try self.reduce(into: [Key: T](), { (result, x) in if let value = try transform(x.value) { result[x.key] = value } }) } [SE-0218] Introduce compactMapValues to Dictionary
  9. Sequence.countWhere() Swift 5 [SE-0220] count(where:) extension Sequence { /// Returns

    the number of elements in the sequence that satisfy the given /// predicate. /// /// […] /// - Parameter predicate: A closure that takes each element of the sequence /// as its argument and returns a Boolean value indicating whether /// the element should be included in the count. /// - Returns: The number of elements in the sequence that satisfy the given /// predicate. @inlinable public func count( where predicate: (Element) throws -> Bool ) rethrows -> Int { var count = 0 for e in self { if try predicate(e) { count += 1 } } return count } }