owned this note changed 4 years ago
Linked with GitHub

Swift Actor 實作探索 - John Lin

tags: COSCUP2021 zh-tw COSCUP2021 帶您讀源碼 TR212

歡迎來到 https://hackmd.io/@coscup/2021 共筆

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

點擊本頁上方的 開始用 Markdown 一起寫筆記!
手機版請點選上方 按鈕展開議程列表。

請從這裡開始


slide: https://tinyurl.com/3ur2stp8

Actor Model:
非同步運算模型、even C language can implement

Actor:
Unit of operation, a computer that can make another computer

Message:

How actor model work

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

like person write mail to another person, required sender and receiver

swift

same gen as Go, Rust

open source

swift feature

every C feature can be done by swift
FP: map, high order fn, 1st class fn, lamda, closure

swift async await

async let y = fetch() // give y a promise

Swift Actor


if call inc() on mulit-thread, will cause race condition

actor solove that

swift actor message passig

method can type check, message can't

in swift, every message passing, become method(auto)

Demo

for update UI
before actor, using LIB dispatch to change thread to main thread
after actor, actor change for you

Complier gen actor

Grammer tree -> SIL (SSA Form)
SSA Form is var only assign once.

SIL -> IR

ACtor

SIL of actor Counter
8 lines of code -> 360 lines of code

IR > 1k+ lines

recap

Select a repo