ECMAScript仕様輪読会 #35
前回: ECMAScript仕様輪読会 #34
Scrapboxの招待リンク: https://scrapbox.io/projects/esspec/invitations/85b96c9fa718ce5185e307196ed8fb53
connpass: https://esspec.connpass.com/
Discord: https://discord.gg/59S3y6weQj
ES Spec Draft: https://tc39.es/ecma262/
Twitter hashtag: #esspec
便利ツール
esspec-memo: https://tars0x9752.github.io/esspec-memo/esspec.html
Scrapbox Codeblock Generator: https://vzvu3k6k.github.io/scrapbox-codeblock/
TC39 Terminology: https://github.com/tc39/how-we-work/blob/main/terminology.md
自己紹介 (近況報告)
syumai
Twitter: https://twitter.com/__syumai GitHub: https://github.com/syumai
久々にオフラインイベントで喋りました
https://speakerdeck.com/syumai/gonogenericswohuo-yong-suru
Goのメモリモデルに関するおすすめ資料
https://twitter.com/shino_nobishii/status/1664450241784057856?s=20
https://docs.google.com/presentation/d/1UjL5jTqreNrFpulVi6l_H5vY_Bcz9jQriL65gZs1zFM/edit
https://github.com/nobishino/goconference2023/blob/main/glossary.md
tars0x9752 (たーず / naoki aoyama) tars0x9752.icon
ここ最近はゆっくりしてた
のどかでよさそうyebis0942.icon
yebis0942yebis0942.icon
先週開催されたGo Conference 2023でKyoto.goという団体でコミュニティブースを出しました
NFTを配ったり、リーンコーヒーという雑談フレームワークで雑談会したりしていました
オンラインイベントブース、さまざまな戦略性があるのではという話
harupiyo / Jun Yasumura
「英文法は絵に描きやすいルールでできている」https://www.asuka-g.co.jp/book/english/011968.html 絵入りで500ページのボリュームがあって嬉しい
前回のあらすじ
Promise.withResolvers
https://github.com/tc39/proposal-promise-with-resolvers
https://docs.google.com/presentation/d/1CEh2xgW-KB0Tpz2GQtcJ8nDbWq99d3y8NCwYJw-laSI/edit#slide=id.g21f4a1bf534_0_1
みんな再発明している
今回の範囲
9.6 InitializeHostDefinedRealm から始めて、9.7 Agents へ
InitializeHostDefinedRealm
Realmは必ずこれを経由して作られているはず
Agents
agent
ECMAScript execution contexts
an execution context stack
a running execution context
an Agent Record
an executing thread
executing thread
他のagentとは独立して、agentのexecution contextにおいてalgorithmic stepを実行する
複数のagentに共有されうる
ただし、Agent Recordの[[CanBlock]]がtrueのagentはthreadを共有できない
NOTE: ブラウザによっては同じウィンドウ内のタブ同士が同じexecuting threadを共有するものがある
どういうことなのか…
Agent Record
[[CanBlock]]: agentがblockするとは?
[[IsLockFree1, 2, 8]]: lock-freeとは?
[[IsLockFree8]]の値は観測後も変えてよい?
lock-freeとは
https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Atomics/isLockFree
メモリモデルの理解が必要そう
Go言語のメモリモデルでは出てこない概念
NOTE2:
4-byte atomic operationは常にlock-free
size nのatomic accessがlock-freeだとしても、size nのatomicでないアクセスは可能(ということか?)
参考: Go言語のメモリモデルの話
「よくわかるThe Go Memory Model」
スライド
よくわかるThe Go Memory Model 用語集
AgentCanSuspend ( )
blockとsuspendは同義なのかyebis0942.icon
NOTE:
実行環境によっては、一部のagentをsuspendするのが不適切な場合がある
例
ブラウザのdocumentのメインイベントを処理するAgentはsuspendすべきではない
(おそらくブラウザのUIが無反応になってしまうから)
でもworkerのイベントを処理するスレッドはsuspendしてもいいかも
Agent Clusters
An agent cluster is a maximal set of agents that can communicate by operating on shared memory.
Programs within different agents may share memory by unspecified means. At a minimum, the backing memory for SharedArrayBuffers can be shared among the agents in the cluster.
unspecified means: 不特定な手段?
大意としては、「agent間のメモリ共有手段は仕様では限定しない。少なくともSharedArrayBuffersの裏側のメモリは共有可能である」ということかyebis0942.icon
embeddingとは?
An embedding may deactivate (stop forward progress)
ここで初出だが、具体的な説明はspecの中にはない
agentを止めたり再開したりできるもの
NOTE 4
生存期間が違うagentがメモリを共有すると、停止されたagentがlockを取りっぱなしになってdeadlockしたりstarveしたりする
なので、そういう共有はできない
(英語) deactivated indefinitely
無期限に無効化する?
(英語) the preceding restriction
(この文書で)先に述べた制約