Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pragmas don't always affect immediately subsequent code #19609

Closed
tersec opened this issue Mar 14, 2022 · 2 comments
Closed

pragmas don't always affect immediately subsequent code #19609

tersec opened this issue Mar 14, 2022 · 2 comments

Comments

@tersec
Copy link
Contributor

tersec commented Mar 14, 2022

Pragmas affect unintuitive parts of code.

Example

Example #1

proc foo() =
  {.checks: off.}
  var s2 = newSeq[int](0)
  s2[0] = 0

foo()

Example #2

proc foo() =
  {.checks: off.}
  # Does trigger IndexDefect
  var s2 = newSeq[int](0)
  s2[0] = 0

foo()
# Doesn't trigger IndexDefect
var s = newSeq[int](0)
s[0] = 0

Example #3

{.checks: off.}
var s2 = newSeq[int](0)
s2[0] = 0

Example #4

template foo() =
  {.checks: off.}
  var s2 = newSeq[int](0)
  s2[0] = 0

foo()

Current Output

Example #1: Error: unhandled exception: index out of bounds, the container is empty [IndexDefect]
Example #2: IndexDefect, but not in foo(), but rather in the global/module scope array indexing
Example #3: no IndexDefect, i.e. the pragma appears to function as intended
Example #4: no IndexDefect, so unlike with the proc() (example #1), a template indeed behaves more like example #3

Tested with

Nim Compiler Version 1.2.16 [Linux: amd64]
Compiled at 2022-03-07
Copyright (c) 2006-2020 by Andreas Rumpf

git hash: c6a9f27b3e36bae9aacec1bd6c37893fb98fd33f
active boot switches: -d:release

(s/Defect/Error/, but otherwise the same)

Nim Compiler Version 1.6.4 [Linux: amd64]
Compiled at 2022-02-10
Copyright (c) 2006-2021 by Andreas Rumpf
Nim Compiler Version 1.7.1 [Linux: amd64]
Compiled at 2022-03-14
Copyright (c) 2006-2022 by Andreas Rumpf

git hash: 4c76f9f1523a72f560138709642c2d51ea365b85
active boot switches: -d:release

Expected Output

Not this.

Possible Solution

Avoid pragmas?

Additional Information

I came across these when attempting to selectively enable and disable pragmas to potentially isolate sections of code which

These are related to #19603 but whereas that issue points to a case where pragmas have too much effect, this points to them having too little effect. Reasonably likely a shared set of root causes though.

@tersec
Copy link
Contributor Author

tersec commented Mar 26, 2022

Maybe fixed by 51df9ff the same as #19603 -- I tested it with the same set of pragmas, and likewise it depends on non-module-scope.

@ringabout
Copy link
Member

Maybe fixed by 51df9ff the same as #19603 -- I tested it with the same set of pragmas, and likewise it depends on non-module-scope.

Indeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants