SWIFT 5.0 has been around for some time. We have got new powers like ABI and Module Stability and Library Evolution support along with it making our lives simpler. Let us discuss these in depth about the possibilities that they bring along with them. We would also discuss the proposal that will make SWIFT touch new heights in the near future.
Welcome to New Swift: Library Evolution & LSP Support
1. Welcome to New SWIFT
Library Evolution and LSP Support
G Abhisek
2. What are we going to discuss
• ABI Stability
• Module Stability
• Library Evolution Support
• LSP Support
3.
4. 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
5. What does an Assembly Language contain
• Opcodes
• Data layout
• Type metadata
• Functions respect calling conventions
9. 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
10. 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
11. 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
12. 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
13. 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)
14. Name Mangling
• Used to produce unique names of functions, properties,
types, etc
• ABI stability means a stable mangling scheme
• Introduction of Compact Manglings
15. 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
16. 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
17. 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
18. 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
19. 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
21. 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