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

Welcome to New SWIFT: Library Evolution and LS...

Welcome to New SWIFT: Library Evolution and LSP Support

Swift India

April 27, 2019
Tweet

More Decks by Swift India

Other Decks in Technology

Transcript

  1. What are we going to discuss • ABI Stability •

    Module Stability • Library Evolution Support • LSP Support
  2. How does a SWIFT file compile Swift Source Code Assembly

    Language AST SIL IR Parse Sema Clang Importer SIL Generation Optimisations and Analysis IR Gen
  3. What does an Assembly Language contain • Opcodes • Data

    layout • Type metadata • Functions respect calling conventions
  4. Application Binary Interface(ABI) • An interface that defines rules that

    compilers and linkers adhere to in order to compile your program and execute properly • Interface for app to use external library at OS at binary level • Specifies the calling conventions that the libraries should respect to • Specifies the in memory layout of data types, classes, structs, etc Binary 1 Binary 2
  5. When a language becomes ABI stable • The function interfaces

    shall not change i.e the order of arguments, return types, etc • Interface for a library should be forward compatible for future versions of the compiler • Stable definition of data type and data structures • Data structures should have a definite data layout • Application built with a specific swift version will be compatible with different Swift versions 5.0 6.x 5.0
  6. Swift ABI components • Types(structs and classes) must have a

    defined in-memory layout for instances • Type metadata must either have a defined memory layout, or have a set of defined APIs for querying the metadata of a type • Exported libraries need to have unique names which binaries should agree and this achieved via name mangling. • Calling conventions should be respected by every exposed functions of external libraries • Runtime API should be stable • Swift standard library should expose stable APIs
  7. Data Layout of Types • Specifies layout of objects of

    given type • Size, Offset and Alignment of an object in memory • Static and Opaque Layout • Eg - Non final Class Instances(Opaque) and Struct layout(Static) in memory
  8. Type Metadata • Contains information about the data itself •

    ABI is how to access this information • To stabilise metadata need to provide metadata read/write functions alongside the runtime to interact with the metadata • Eg. Function Metadata, Class Metadata(V tables)
  9. Name Mangling • Used to produce unique names of functions,

    properties, types, etc • ABI stability means a stable mangling scheme • Introduction of Compact Manglings
  10. Calling Convention • Implementation of how subroutines receive parameters from

    their caller • Says how are parameters, return values and return addresses placed on register • Order of argument passing • What metadata of arguments represents
  11. Module Stability • Deals with linking libraries at compile time

    • Swift module file - Binary equivalent of C or Obj C header file • Swift module is tied to current compiler version • Interface for a Swift 5 framework will work with >Swift 5 compiler • Includes API declaration and inlinable code • Swift Interface - Generated by Xcode if - enable-library-evolution flag is enabled 7.x 6.x 6.x
  12. Library Evolution Support • Shipping a new library without having

    to recompile its clients • Giving library authors the flexibility to add to their public interface and to change the implementation details • Eg of language features enabling these - @frozen enums and structs 6.x 7.x
  13. Language Server Protocol(LSP) What problem LSP aims to resolve •

    Editors supported compatibility for fewer languages • Integration code of specific languages are written down in IDEs • Implementation are different across different languages and IDEs • Performance of language varies from one IDE to another
  14. Language Server Protocol(LSP) How LSP would help? • No need

    to implement support for each language • Provides common set of functionality for supported languages • Provides language specific smarts inside a server that can communicate with development tool • Provide support for feature such as autocompletion, go-to definition, etc
  15. How are these gonna help • Make language changes more

    stable • Make build times faster with the help of module stability • Swift can readily be used for cross platform development • With LSP, Swift can be written on different IDEs
  16. References • https://github.com/apple/swift/blob/master/docs/ABIStabilityManifesto.md • https://github.com/apple/swift/blob/master/docs/CallingConvention.rst#high- level-semantic-conventions • https://en.wikipedia.org/wiki/Calling_convention • https://nshipster.com/language-server-protocol/

    • https://swift.org/blog/abi-stability-and-more/ • https://www.youtube.com/watch?v=a5-WaD8VV38 • https://blog.gopheracademy.com/advent-2018/llvm-ir-and-go/ • https://forums.swift.org/t/plan-for-module-stability/14551/5