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

Regression when using the volatile module on devel #23499

Closed
Abathargh opened this issue Apr 13, 2024 · 2 comments · Fixed by #23503
Closed

Regression when using the volatile module on devel #23499

Abathargh opened this issue Apr 13, 2024 · 2 comments · Fixed by #23503
Assignees

Comments

@Abathargh
Copy link
Contributor

Description

Using the voilatile module currently incurs in a compiler error.

I have run a git bisect and the outcome is the following:

*[72d0ba2df][~/projects/nim/Nim]$ git bisect good
9b378296f65fff962225acc1bef2b3811fffda03 is the first bad commit
commit 9b378296f65fff962225acc1bef2b3811fffda03
Author: ringabout <43030857+ringabout@users.noreply.github.com>
Date:   Wed Apr 10 20:41:16 2024 +0800

    fixes addr/hiddenAddr in strictdefs (#23477)

Minimal example:

import volatile

var ctr = 0

proc main =
  volatileStore(addr ctr, 1)
  echo volatileLoad(addr ctr)

when isMainModule:
  main()

I know this is not a perfect use case for it, but for example I use import volatile to interact with memory mapped registers on mcus, and it's a necessary feature there.

Nim Version

Nim Compiler Version 2.1.1 [Linux: amd64]
Compiled at 2024-04-12
Copyright (c) 2006-2024 by Andreas Rumpf

git hash: 779bc84
active boot switches: -d:release

Current Output

Hint: used config file '/home/mar/projects/nim/Nim/config/nim.cfg' [Conf]
Hint: used config file '/home/mar/projects/nim/Nim/config/config.nims' [Conf]
......................................................................
/home/mar/projects/nim/volatile_test/vol.nim(6, 16) template/generic instantiation of `volatileStore` from here
/home/mar/projects/nim/Nim/lib/pure/volatile.nim(31, 12) Error: type mismatch
Expression: `[]=`(ctr, 1)
  [1] ctr: int
  [2] 1: int literal(1)

Expected one of (first mismatch at [position]):
[0] proc `[]=`(s: var string; i: BackwardsIndex; x: char)
[0] proc `[]=`[I: Ordinal; T, S](a: T; i: I; x: sink S)
[0] proc `[]=`[Idx, T; U, V: Ordinal](a: var array[Idx, T]; x: HSlice[U, V];
                                  b: openArray[T])
[0] proc `[]=`[Idx, T](a: var array[Idx, T]; i: BackwardsIndex; x: T)
[0] proc `[]=`[T, U: Ordinal](s: var string; x: HSlice[T, U]; b: string)
[0] proc `[]=`[T; U, V: Ordinal](s: var seq[T]; x: HSlice[U, V]; b: openArray[T])
[0] proc `[]=`[T](s: var openArray[T]; i: BackwardsIndex; x: T)
[0] template `[]=`(a: WideCStringObj; idx: int; val: Utf16Char)
[0] template `[]=`(s: string; i: int; val: char)

Expected Output

Hint: used config file '/home/mar/.choosenim/toolchains/nim-2.0.2/config/nim.cfg' [Conf]
Hint: used config file '/home/mar/.choosenim/toolchains/nim-2.0.2/config/config.nims' [Conf]
.......................................................................
CC: ../../../.choosenim/toolchains/nim-2.0.2/lib/system/exceptions.nim
CC: ../../../.choosenim/toolchains/nim-2.0.2/lib/std/private/digitsutils.nim
CC: ../../../.choosenim/toolchains/nim-2.0.2/lib/system/dollars.nim
CC: ../../../.choosenim/toolchains/nim-2.0.2/lib/system.nim
CC: vol.nim
Hint:  [Link]
Hint: mm: orc; threads: on; opt: none (DEBUG BUILD, `-d:release` generates faster code)
27658 lines; 0.428s; 30.309MiB peakmem; proj: /home/mar/projects/nim/volatile_test/vol.nim; out: /home/mar/projects/nim/volatile_test/vol [SuccessX]

Possible Solution

No response

Additional Information

No response

@ringabout ringabout self-assigned this Apr 13, 2024
@ringabout
Copy link
Member

proc semArrPut(c: PContext; n: PNode; flags: TExprFlags): PNode =
  # rewrite `[]=`(a, i, x)  back to ``a[i] = x``.
  let b = newNodeI(nkBracketExpr, n.info)
  b.add(n[1].skipAddr)

I don't think it should skip addr here or it should handle addr deref here and it wasn't skipped before because addr ... existed in the form of a magic function.

@ringabout
Copy link
Member

Besides 8990626 changed the meaning of skipAddr for frontend

Araq pushed a commit that referenced this issue Apr 15, 2024
fixes #23499

In the
8990626
the effect of `skipAddr` changed to skip `nkAddr` and `nkHiddenAddr`.
Some old code was not adapted. In the
#23477, the magic `addr` function
was handled in the semantic analysis phase, which causes it be skipped
incorrectly
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

Successfully merging a pull request may close this issue.

2 participants