nim-works / nimskull

An in development statically typed systems programming language; with sustainability at its core. We, the community of users, maintain it.
https://nim-works.github.io/nimskull/index.html
Other
272 stars 38 forks source link

objChecks:off not respected in pragma form #1208

Open disruptek opened 6 months ago

disruptek commented 6 months ago

Specification

The objChecks boolean flag toggles object conversion checks. It may be disabled via configuration or by using a push pragma.

Example


proc example[A](runtime: Foo[A]) =
  {.push objChecks: off.}
  var temporary: Continuation = fn(runtime.continuation)
  runtime.continuation = A temporary
  {.pop.}

Actual Output

Error: unhandled exception: invalid object conversion [ObjectConversionDefect]

Expected Output

Additional Information

Nimskull Compiler Version 0.1.0-dev.21240 [linux: amd64]

Source hash: 55deaaa31f54f81b4c21db86c93230cb629a7822
Source date: 2024-02-24

active boot switches: -d:release -d:danger⏎ 
zerbina commented 6 months ago

As a temporary workaround, you can move .push outside of the procedure, like so:

{.push objChecks: off.}

proc example() =
  ...

{.pop.}

The long-standing problem is that .push and .pop only apply to procedures, which also affects all the other check pragmas (e.g., boundChecks, rangeChecks, etc.). It should also be possible to use objChecks: off directly on the procedure, but that's currently not implemented.


Regarding fixing this, mirgen already supports intra-procedure check enabling/disabling, what's missing is processing the .push and .pop pragmas and implementing the option stack semantics. I'm busy with other things for the next week or so, but I could work on this afterwards.

disruptek commented 6 months ago

Please don't sweat it; plenty of workarounds.