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

Cannot infer the value of static parameters in certain cases (regression 2.1.1 → 2.2.0) #24708

Open
xigoi opened this issue Feb 21, 2025 · 3 comments · May be fixed by #24709
Open

Cannot infer the value of static parameters in certain cases (regression 2.1.1 → 2.2.0) #24708

xigoi opened this issue Feb 21, 2025 · 3 comments · May be fixed by #24709
Assignees

Comments

@xigoi
Copy link

xigoi commented Feb 21, 2025

Description

The following program works correctly in Nim 2.1.1:

type Matrix[m, n: static int] = array[m * n, float]

func `[]`(A: Matrix, i, j: int): float =
  A[A.n * i + j]

func `[]`(A: var Matrix, i, j: int): var float =
  A[A.n * i + j]

func `*`[m, n, p: static int](A: Matrix[m, n], B: Matrix[n, p]): Matrix[m, p] =
  for i in 0 ..< m:
    for k in 0 ..< p:
      for j in 0 ..< n:
        result[i, k] += A[i, j] * B[j, k]

let A: Matrix[2, 2] = [-1, 1, 0, -1]
echo(A * A)

However, in Nim 2.2.0 it fails to compile with the error shown below.

Nim Version

Nim Compiler Version 2.2.0 [Linux: amd64]
Compiled at 2024-10-02
Copyright (c) 2006-2024 by Andreas Rumpf

git hash: 78983f1876726a49c69d65629ab433ea1310ece1
active boot switches: -d:release

Current Output

Hint: used config file '/home/xigoi/.choosenim/toolchains/nim-2.2.0/config/nim.cfg' [Conf]
Hint: used config file '/home/xigoi/.choosenim/toolchains/nim-2.2.0/config/config.nims' [Conf]
Hint: used config file '/home/xigoi/.config/nim/nim.cfg' [Conf]
.....................................................................
/home/xigoi/sandbox/program.nim(16, 8) template/generic instantiation of `*` from here
/home/xigoi/.choosenim/toolchains/nim-2.2.0/lib/system/arithmetics.nim(10, 6) Error: cannot infer the value of the static param 'm'

Expected Output

[1.0, -2.0, 0.0, 1.0]

Known Workarounds

No response

Additional Information

No response

@metagn metagn self-assigned this Feb 21, 2025
@metagn
Copy link
Collaborator

metagn commented Feb 21, 2025

Happens in checkGeneric thankfully, disambiguation of []

Still bisecting just in case there's a deeper issue

@metagn
Copy link
Collaborator

metagn commented Feb 21, 2025

!nim c

type Matrix[m, n: static int] = array[m * n, float]

func `[]`(A: Matrix, i, j: int): float =
  A[A.n * i + j]

func `[]`(A: var Matrix, i, j: int): var float =
  A[A.n * i + j]

func `*`[m, n, p: static int](A: Matrix[m, n], B: Matrix[n, p]): Matrix[m, p] =
  for i in 0 ..< m:
    for k in 0 ..< p:
      for j in 0 ..< n:
        result[i, k] += A[i, j] * B[j, k]

let A: Matrix[2, 2] = [-1, 1, 0, -1]
echo(A * A)

metagn added a commit to metagn/Nim that referenced this issue Feb 21, 2025
@metagn metagn linked a pull request Feb 21, 2025 that will close this issue
Copy link
Contributor

🐧 Linux bisect by @metagn (collaborator)
devel 👎 FAIL

Output


Filesize 0 (0 bytes)
Duration

stable 👎 FAIL

Output


Filesize 0 (0 bytes)
Duration

2.2.2 👎 FAIL

Output


Filesize 0 (0 bytes)
Duration

2.0.0 👍 OK

Output


Filesize 96.27 Kb (98,584 bytes)
Duration 1 mins

1.6.20 👍 OK

Output


Filesize 104.98 Kb (107,504 bytes)
Duration

1.4.8 👎 FAIL

Output


Filesize 104.98 Kb (107,504 bytes)
Duration

1.2.18 👎 FAIL

Output


Filesize 104.98 Kb (107,504 bytes)
Duration

1.0.10 👎 FAIL

Output


Filesize 104.98 Kb (107,504 bytes)
Duration

#ccc7c45d7 ➡️ 🐛

Diagnostics

ryan mcconnell introduced a bug at 2023-12-31 16:52:52 +0000 on commit #ccc7c45d7 with message:


The bug is in the files:


The bug can be in the commits:

(Diagnostics sometimes off-by-one).

Stats
  • GCC 13.3.0
  • Clang 18.1.3
  • NodeJS 18.2
  • Created 2025-02-21T14:08:36Z
  • Comments 2
  • Commands nim c --run -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim

🤖 Bug found in 34 mins bisecting 1179 commits at 34 commits per second

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