shared-suspendable and shared-fixed as separate function types
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 25/100
- Issue 类型
- 功能
- 描述清晰度
- 需要澄清
- 活跃度
- 停滞
- 技术栈
- wasm
- 领域
- compilers
调研方向
首先阅读 issue #42 和 stack-switching #44,包括其中链接的评论,然后将它们的假设与这份设计草案进行比较。当就是否应采用单独的 shared-suspendable 和 shared-fixed 函数类型,以及它们需要哪些调用限制达成共识并完成文档记录时,即视为完成。
由索引模型根据 Issue 内容生成。
描述
During our discussion on https://github.com/WebAssembly/shared-everything-threads/issues/42, we discussed that a "safety valve" decision for JS function access, if we can't reach consensus on (strong/weak) thread-local functions, would be to (re)introduce a version of shared function that cannot have its execution suspended as part of a (hypothetical) shared continuation.
Currently our design doesn't permit nonshared parameters to shared functions in order to be forward-compatible with shared continuations, which would allow such a nonshared object to be smuggled into another thread by suspending execution and resuming in another thread. By forbidding such suspensions, we could allow nonshared parameters, and thus pass in a JS context (e.g. a struct containing unshared references to JS functions) as a regular parameter that would be threaded through execution (or a context local as sketched here), giving a mechanism to call JS functions from shared Wasm functions.
This issue is to discuss the design implications of this approach. A few initial points:
- As noted in my previous comment, the question of how the stack pointer is handled can be answered separately, as it is a scalar parameter. We could choose not to have thread-local globals (threading the stack pointer as a parameter), but still choose to support (strong/weak) thread-local functions.
- All calls to JS through the "context parameter" mechanism have to be indirect calls. Without a way to statically import JS functions as shared, unconditional inlining (the way V8 prefers) is likely infeasible.
- Strong/weak thread-local functions just about make unconditional inlining feasible, so long as every instance-crossing is accompanied by a bitmap "is-on-fast-path" check. The feasibility of this bitmap approach is discussed/criticised here.
- Given the above, maybe the only way to get unconditional inlining is to genuinely provide new JS builtins that are importable as shared, in the manner of string builtins.
- To wear my heart on my sleeve, I'd prefer just the
shared-suspendablesemantics with some mechanism for thread-local functions (weak if necessary) over the below. That being said, I don't think the below is awful, and it seems less controversial from a GC engineering perspective.
Note that, if we still believe that shared continuations will eventually exist, the below approach doesn't permanently solve our current problems, but instead pushes them into the future. Any compilation scheme wanting to use shared continuations will need to mark most functions as shared-suspendable, and so for such a scheme we'd still need to solve the same problem of JS access that we have in the current design (e.g. by introducing thread-local functions).
Design Sketch
Terminology
For the purposes of this discussion, I'm going to refer to functions as being either nonshared, shared-suspendable, or shared-fixed (a different name for shared-nonsuspendable, which is a mouthful). The distinction between these functions would be enforced by a static annotation on the function type.
nonshared functions are what we have today. Remember that in general, shared things can't capture nonshared things.
shared-suspendable functions are the "fully shared" functions we've been discussing before this point:
- No references, access, or calls to any module state with a
nonsharedtype (globals/tables/functions) - No
nonsharedparameters/locals - No instructions that generate new
nonsharedreferences in the body (e.g.struct.new) - These functions can be used to create
sharedcontinuations
shared-fixedfunctions are somewhat more relaxed: - Still no references, access, or calls to any module state with a
nonsharedtype (globals/tables/functions) nonsharedparameters/locals are allowed- Instructions that generate new
nonsharedreferences in the body (e.g.struct.new) are allowed - These functions cannot be part of a
sharedcontinuation, but can be part of anonsharedcontinuation
Intuitively, the call stack of a shared-suspendable function could be captured as part of a shared continuation, and resumed in another thread. This means it's not safe for the frame to ever capture a nonshared object, even transiently. In contrast, shared-fixed function calls are guaranteed to stay in the same thread for the entire duration of their execution. Therefore it's safe to pass in nonshared objects as parameters, and materialise them during the function call's execution. Prior to the standardisation of shared continuations, only shared-fixed functions would be definable.
Restrictions on calling
(EDIT: see this comment for an alternative approach with different restrictions)
shared-suspendable functions can always call shared-fixed functions with no restrictions. The extent to which shared-fixed functions can call shared-suspendable functions depends on some design decisions of stack switching. By default, all forms of shared-fixed->shared-suspendable call would be disallowed by validation (implying annotations/type tracking of [non]suspendable on relevant call instructions).
If the stack switching proposal includes a lexical barrier instruction (e.g. see here), it seems feasible to also include a concept of a "shared-only" barrier which traps upon an attempt to capture a shared continuation, but not a non-shared one. All forms of call to shared-suspendable functions could be allowed inside the body of this barrier. On reflection, I don't think that a shared-fixed call should implicitly introduce such a barrier, since this would mean that every shared-fixed call would have the implicit overhead of "Check if I'm in a continuation and if so, set the barrier bit". Instead I think the shared-only barrier should always be explicit (and would switch validation from shared-fixed mode to shared-suspendable mode within its body). @rossberg please correct me if I'm wrong about the above.
A shared-fixed function could also call a shared-suspendable function by wrapping the latter as a shared continuation and using a hypothetical resume_barrier instruction (as sketched here https://github.com/WebAssembly/stack-switching/issues/44#issuecomment-1909545807). If a "shared-only" barrier proves infeasible, this would be the only way to make a shared-fixed->shared-suspendable call.
Note that in either case, it's still ok for a shared-fixed function to hold a reference to a shared-suspendable function; only calling is complicated. This means that we don't need to distinguish between different kinds of shared for tables and globals - the [non]suspendable distinction is only needed for callable things.
- 主要语言
- WebAssembly
- 星标
- 98
- 派生
- 7
- 平均合并
- 1 天 20 小时
- 30 天内合并 PR
- 1
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
WebAssembly/shared-everything-threads 的其他 Issue
-
难度 5/5 一周以上 新手友好度 15/100
-
难度 5/5 一周以上 新手友好度 35/100
WebAssembly/shared-everything-threads#119 · 2 条评论 ·
-
难度 5/5 一周以上 新手友好度 25/100
WebAssembly/shared-everything-threads#114 · 7 条评论 ·
-
难度 5/5 一周以上 新手友好度 25/100
-
难度 5/5 一周以上 新手友好度 35/100
WebAssembly/shared-everything-threads#105 · 6 条评论 ·
查看 WebAssembly/shared-everything-threads 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 62/100
-
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
A binding pattern element named `from` or `as` fails with "Expected destructuring pattern": `const [from] = [1]`, `const { a: from } = o`, `([from]) => from`可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭bug engine spec compliance
难度 2/5 1-3 小时 新手友好度 78/100
frostney/GocciaScript#1737 ·
维护者通常 1 天内回复
-
build enhancement medium priority
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
bug frontend rt sev-3
难度 2/5 1-3 小时 新手友好度 72/100