workaround `--mm:orc` codegen bug with `{.noSideEffect.}` (#63)

Inlining `template` that uses `{.noSideEffect.}` without a `block` can
lead to invalid codegen that contains double-frees. Wrap problematic
instances with `block` to prevent issues in `libnimbus_lc` wasm (orc).
This commit is contained in:
Etan Kissling 2023-10-27 15:12:07 +02:00 committed by GitHub
parent 4bdbc29e54
commit 543b2f3dd0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 40 additions and 37 deletions

View File

@ -8,6 +8,7 @@ export
template encode*(Format: type, value: auto, params: varargs[untyped]): auto = template encode*(Format: type, value: auto, params: varargs[untyped]): auto =
mixin init, Writer, writeValue, PreferredOutputType mixin init, Writer, writeValue, PreferredOutputType
block: # https://github.com/nim-lang/Nim/issues/22874
{.noSideEffect.}: {.noSideEffect.}:
# We assume that there is no side-effects here, because we are # We assume that there is no side-effects here, because we are
# using a `memoryOutput`. The computed side-effects are coming # using a `memoryOutput`. The computed side-effects are coming
@ -37,6 +38,7 @@ template decode*(Format: distinct type,
# TODO, this is dusplicated only due to a Nim bug: # TODO, this is dusplicated only due to a Nim bug:
# If `input` was `string|openArray[byte]`, it won't match `seq[byte]` # If `input` was `string|openArray[byte]`, it won't match `seq[byte]`
mixin init, Reader mixin init, Reader
block: # https://github.com/nim-lang/Nim/issues/22874
{.noSideEffect.}: {.noSideEffect.}:
# We assume that there are no side-effects here, because we are # We assume that there are no side-effects here, because we are
# using a `memoryInput`. The computed side-effects are coming # using a `memoryInput`. The computed side-effects are coming
@ -57,6 +59,7 @@ template decode*(Format: distinct type,
# TODO, this is dusplicated only due to a Nim bug: # TODO, this is dusplicated only due to a Nim bug:
# If `input` was `string|openArray[byte]`, it won't match `seq[byte]` # If `input` was `string|openArray[byte]`, it won't match `seq[byte]`
mixin init, Reader mixin init, Reader
block: # https://github.com/nim-lang/Nim/issues/22874
{.noSideEffect.}: {.noSideEffect.}:
# We assume that there are no side-effects here, because we are # We assume that there are no side-effects here, because we are
# using a `memoryInput`. The computed side-effects are coming # using a `memoryInput`. The computed side-effects are coming