emscripten-core / emscripten-core/emscripten

Should remove remove (reduce usage of) withStackSave?

Open
#21,763 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

The `withStackSave` helper is a convenient way to avoid having the remember to write `stackRestore` at the end of a JS library function.

However, this construct has some cost. Firstly it create an inner closure object, and secondly it relies on `try/finally` control flow to restore the stack pointer.

At the time when I originally wrong `withStackSave` I was under the impression that restore in the stack, even in the exceptional case, was important. However, my new/current understanding is that the shadow stack pointer doesn't need to be restored during unwinding until an exception is caught. i.e. its up the outer try/catch to return the stack pointer.

The other useful think about `withStackSave` is that for function with multiple exit points one doesn't need to repeat the `stackRestore` statement for each one. Perhaps for such functions we can keep this helper around, but I suspect that are few functions that have enough exit points to justify this helper.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.