nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.57k stars 1.47k forks source link

User-defined typeclasses or type aliases in generic procs cannot be distinct #24337

Open mothfuzz opened 1 week ago

mothfuzz commented 1 week ago

Description

When defining a custom type alias or type class, the distinct keyword in argument position seems to not do anything as implied in the manual. It neither works with explicit nor implicit generics.

type Array2d[W, H: static[int]] = array[H, array[W, int]]

proc normal(a: Array2d, b: Array2d) =
  echo len(a), ", ", len(b)

proc dist(a: Array2d, b: distinct Array2d) =
  echo len(a), ", ", len(b)

proc doubleDist(a: distinct Array2d, b: distinct Array2d) =
  echo len(a), ", ", len(b)

proc explicit[A, B: distinct Array2d](a: A, b: B) =
  echo len(a), ", ", len(b)

let a = [[0, 1]]
let b = [[0, 1, 2]]
explicit(a, b)
doubleDist(a, b)
dist(a, b)
normal(a, b)

Nim Version

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

Current Output

Error: type mismatch
Expression: explicit(a, b)
  [1] a: array[0..0, array[0..1, int]]
  [2] b: array[0..0, array[0..2, int]]

Expected one of (first mismatch at [position]):
[1] proc explicit[A, B: distinct Array2d](a: A; b: B)

Expected Output

1, 1
1, 1
1, 1
1, 1

Known Workarounds

No response

Additional Information

No response

ringabout commented 1 week ago

!nim c

type Array2d[W, H: static[int]] = array[H, array[W, int]]

proc normal(a: Array2d, b: Array2d) =
  echo len(a), ", ", len(b)

proc dist(a: Array2d, b: distinct Array2d) =
  echo len(a), ", ", len(b)

proc doubleDist(a: distinct Array2d, b: distinct Array2d) =
  echo len(a), ", ", len(b)

proc explicit[A, B: distinct Array2d](a: A, b: B) =
  echo len(a), ", ", len(b)

let a = [[0, 1]]
let b = [[0, 1, 2]]
explicit(a, b)
doubleDist(a, b)
dist(a, b)
normal(a, b)
github-actions[bot] commented 1 week ago
:penguin: Linux bisect by @ringabout (member)
devel :-1: FAIL

Output

``` ```

IR

Compiled filesize 0 (0 bytes) ```cpp ```

Stats

  • Started 2024-10-22T01:52:35
  • Finished 2024-10-22T01:52:35
  • Duration

AST

```nim nnkStmtList.newTree( nnkTypeSection.newTree( nnkTypeDef.newTree( newIdentNode("Array2d"), nnkGenericParams.newTree( nnkIdentDefs.newTree( newIdentNode("W"), newIdentNode("H"), nnkBracketExpr.newTree( newIdentNode("static"), newIdentNode("int") ), newEmptyNode() ) ), nnkBracketExpr.newTree( newIdentNode("array"), newIdentNode("H"), nnkBracketExpr.newTree( newIdentNode("array"), newIdentNode("W"), newIdentNode("int") ) ) ) ), nnkProcDef.newTree( newIdentNode("normal"), newEmptyNode(), newEmptyNode(), nnkFormalParams.newTree( newEmptyNode(), nnkIdentDefs.newTree( newIdentNode("a"), newIdentNode("Array2d"), newEmptyNode() ), nnkIdentDefs.newTree( newIdentNode("b"), newIdentNode("Array2d"), newEmptyNode() ) ), newEmptyNode(), newEmptyNode(), nnkStmtList.newTree( nnkCommand.newTree( newIdentNode("echo"), nnkCall.newTree( newIdentNode("len"), newIdentNode("a") ), newLit(", "), nnkCall.newTree( newIdentNode("len"), newIdentNode("b") ) ) ) ), nnkProcDef.newTree( newIdentNode("dist"), newEmptyNode(), newEmptyNode(), nnkFormalParams.newTree( newEmptyNode(), nnkIdentDefs.newTree( newIdentNode("a"), newIdentNode("Array2d"), newEmptyNode() ), nnkIdentDefs.newTree( newIdentNode("b"), nnkDistinctTy.newTree( newIdentNode("Array2d") ), newEmptyNode() ) ), newEmptyNode(), newEmptyNode(), nnkStmtList.newTree( nnkCommand.newTree( newIdentNode("echo"), nnkCall.newTree( newIdentNode("len"), newIdentNode("a") ), newLit(", "), nnkCall.newTree( newIdentNode("len"), newIdentNode("b") ) ) ) ), nnkProcDef.newTree( newIdentNode("doubleDist"), newEmptyNode(), newEmptyNode(), nnkFormalParams.newTree( newEmptyNode(), nnkIdentDefs.newTree( newIdentNode("a"), nnkDistinctTy.newTree( newIdentNode("Array2d") ), newEmptyNode() ), nnkIdentDefs.newTree( newIdentNode("b"), nnkDistinctTy.newTree( newIdentNode("Array2d") ), newEmptyNode() ) ), newEmptyNode(), newEmptyNode(), nnkStmtList.newTree( nnkCommand.newTree( newIdentNode("echo"), nnkCall.newTree( newIdentNode("len"), newIdentNode("a") ), newLit(", "), nnkCall.newTree( newIdentNode("len"), newIdentNode("b") ) ) ) ), nnkProcDef.newTree( newIdentNode("explicit"), newEmptyNode(), nnkGenericParams.newTree( nnkIdentDefs.newTree( newIdentNode("A"), newIdentNode("B"), nnkDistinctTy.newTree( newIdentNode("Array2d") ), newEmptyNode() ) ), nnkFormalParams.newTree( newEmptyNode(), nnkIdentDefs.newTree( newIdentNode("a"), newIdentNode("A"), newEmptyNode() ), nnkIdentDefs.newTree( newIdentNode("b"), newIdentNode("B"), newEmptyNode() ) ), newEmptyNode(), newEmptyNode(), nnkStmtList.newTree( nnkCommand.newTree( newIdentNode("echo"), nnkCall.newTree( newIdentNode("len"), newIdentNode("a") ), newLit(", "), nnkCall.newTree( newIdentNode("len"), newIdentNode("b") ) ) ) ), nnkLetSection.newTree( nnkIdentDefs.newTree( newIdentNode("a"), newEmptyNode(), nnkBracket.newTree( nnkBracket.newTree( newLit(0), newLit(1) ) ) ) ), nnkLetSection.newTree( nnkIdentDefs.newTree( newIdentNode("b"), newEmptyNode(), nnkBracket.newTree( nnkBracket.newTree( newLit(0), newLit(1), newLit(2) ) ) ) ), nnkCall.newTree( newIdentNode("explicit"), newIdentNode("a"), newIdentNode("b") ), nnkCall.newTree( newIdentNode("doubleDist"), newIdentNode("a"), newIdentNode("b") ), nnkCall.newTree( newIdentNode("dist"), newIdentNode("a"), newIdentNode("b") ), nnkCall.newTree( newIdentNode("normal"), newIdentNode("a"), newIdentNode("b") ) ) ```
stable :-1: FAIL

Output

``` ```

IR

Compiled filesize 0 (0 bytes) ```cpp ```

Stats

  • Started 2024-10-22T01:52:39
  • Finished 2024-10-22T01:52:40
  • Duration

AST

```nim nnkStmtList.newTree( nnkTypeSection.newTree( nnkTypeDef.newTree( newIdentNode("Array2d"), nnkGenericParams.newTree( nnkIdentDefs.newTree( newIdentNode("W"), newIdentNode("H"), nnkBracketExpr.newTree( newIdentNode("static"), newIdentNode("int") ), newEmptyNode() ) ), nnkBracketExpr.newTree( newIdentNode("array"), newIdentNode("H"), nnkBracketExpr.newTree( newIdentNode("array"), newIdentNode("W"), newIdentNode("int") ) ) ) ), nnkProcDef.newTree( newIdentNode("normal"), newEmptyNode(), newEmptyNode(), nnkFormalParams.newTree( newEmptyNode(), nnkIdentDefs.newTree( newIdentNode("a"), newIdentNode("Array2d"), newEmptyNode() ), nnkIdentDefs.newTree( newIdentNode("b"), newIdentNode("Array2d"), newEmptyNode() ) ), newEmptyNode(), newEmptyNode(), nnkStmtList.newTree( nnkCommand.newTree( newIdentNode("echo"), nnkCall.newTree( newIdentNode("len"), newIdentNode("a") ), newLit(", "), nnkCall.newTree( newIdentNode("len"), newIdentNode("b") ) ) ) ), nnkProcDef.newTree( newIdentNode("dist"), newEmptyNode(), newEmptyNode(), nnkFormalParams.newTree( newEmptyNode(), nnkIdentDefs.newTree( newIdentNode("a"), newIdentNode("Array2d"), newEmptyNode() ), nnkIdentDefs.newTree( newIdentNode("b"), nnkDistinctTy.newTree( newIdentNode("Array2d") ), newEmptyNode() ) ), newEmptyNode(), newEmptyNode(), nnkStmtList.newTree( nnkCommand.newTree( newIdentNode("echo"), nnkCall.newTree( newIdentNode("len"), newIdentNode("a") ), newLit(", "), nnkCall.newTree( newIdentNode("len"), newIdentNode("b") ) ) ) ), nnkProcDef.newTree( newIdentNode("doubleDist"), newEmptyNode(), newEmptyNode(), nnkFormalParams.newTree( newEmptyNode(), nnkIdentDefs.newTree( newIdentNode("a"), nnkDistinctTy.newTree( newIdentNode("Array2d") ), newEmptyNode() ), nnkIdentDefs.newTree( newIdentNode("b"), nnkDistinctTy.newTree( newIdentNode("Array2d") ), newEmptyNode() ) ), newEmptyNode(), newEmptyNode(), nnkStmtList.newTree( nnkCommand.newTree( newIdentNode("echo"), nnkCall.newTree( newIdentNode("len"), newIdentNode("a") ), newLit(", "), nnkCall.newTree( newIdentNode("len"), newIdentNode("b") ) ) ) ), nnkProcDef.newTree( newIdentNode("explicit"), newEmptyNode(), nnkGenericParams.newTree( nnkIdentDefs.newTree( newIdentNode("A"), newIdentNode("B"), nnkDistinctTy.newTree( newIdentNode("Array2d") ), newEmptyNode() ) ), nnkFormalParams.newTree( newEmptyNode(), nnkIdentDefs.newTree( newIdentNode("a"), newIdentNode("A"), newEmptyNode() ), nnkIdentDefs.newTree( newIdentNode("b"), newIdentNode("B"), newEmptyNode() ) ), newEmptyNode(), newEmptyNode(), nnkStmtList.newTree( nnkCommand.newTree( newIdentNode("echo"), nnkCall.newTree( newIdentNode("len"), newIdentNode("a") ), newLit(", "), nnkCall.newTree( newIdentNode("len"), newIdentNode("b") ) ) ) ), nnkLetSection.newTree( nnkIdentDefs.newTree( newIdentNode("a"), newEmptyNode(), nnkBracket.newTree( nnkBracket.newTree( newLit(0), newLit(1) ) ) ) ), nnkLetSection.newTree( nnkIdentDefs.newTree( newIdentNode("b"), newEmptyNode(), nnkBracket.newTree( nnkBracket.newTree( newLit(0), newLit(1), newLit(2) ) ) ) ), nnkCall.newTree( newIdentNode("explicit"), newIdentNode("a"), newIdentNode("b") ), nnkCall.newTree( newIdentNode("doubleDist"), newIdentNode("a"), newIdentNode("b") ), nnkCall.newTree( newIdentNode("dist"), newIdentNode("a"), newIdentNode("b") ), nnkCall.newTree( newIdentNode("normal"), newIdentNode("a"), newIdentNode("b") ) ) ```
2.0.10 :-1: FAIL

Output

``` ```

IR

Compiled filesize 0 (0 bytes) ```cpp ```

Stats

  • Started 2024-10-22T01:52:43
  • Finished 2024-10-22T01:52:43
  • Duration

AST

```nim nnkStmtList.newTree( nnkTypeSection.newTree( nnkTypeDef.newTree( newIdentNode("Array2d"), nnkGenericParams.newTree( nnkIdentDefs.newTree( newIdentNode("W"), newIdentNode("H"), nnkBracketExpr.newTree( newIdentNode("static"), newIdentNode("int") ), newEmptyNode() ) ), nnkBracketExpr.newTree( newIdentNode("array"), newIdentNode("H"), nnkBracketExpr.newTree( newIdentNode("array"), newIdentNode("W"), newIdentNode("int") ) ) ) ), nnkProcDef.newTree( newIdentNode("normal"), newEmptyNode(), newEmptyNode(), nnkFormalParams.newTree( newEmptyNode(), nnkIdentDefs.newTree( newIdentNode("a"), newIdentNode("Array2d"), newEmptyNode() ), nnkIdentDefs.newTree( newIdentNode("b"), newIdentNode("Array2d"), newEmptyNode() ) ), newEmptyNode(), newEmptyNode(), nnkStmtList.newTree( nnkCommand.newTree( newIdentNode("echo"), nnkCall.newTree( newIdentNode("len"), newIdentNode("a") ), newLit(", "), nnkCall.newTree( newIdentNode("len"), newIdentNode("b") ) ) ) ), nnkProcDef.newTree( newIdentNode("dist"), newEmptyNode(), newEmptyNode(), nnkFormalParams.newTree( newEmptyNode(), nnkIdentDefs.newTree( newIdentNode("a"), newIdentNode("Array2d"), newEmptyNode() ), nnkIdentDefs.newTree( newIdentNode("b"), nnkDistinctTy.newTree( newIdentNode("Array2d") ), newEmptyNode() ) ), newEmptyNode(), newEmptyNode(), nnkStmtList.newTree( nnkCommand.newTree( newIdentNode("echo"), nnkCall.newTree( newIdentNode("len"), newIdentNode("a") ), newLit(", "), nnkCall.newTree( newIdentNode("len"), newIdentNode("b") ) ) ) ), nnkProcDef.newTree( newIdentNode("doubleDist"), newEmptyNode(), newEmptyNode(), nnkFormalParams.newTree( newEmptyNode(), nnkIdentDefs.newTree( newIdentNode("a"), nnkDistinctTy.newTree( newIdentNode("Array2d") ), newEmptyNode() ), nnkIdentDefs.newTree( newIdentNode("b"), nnkDistinctTy.newTree( newIdentNode("Array2d") ), newEmptyNode() ) ), newEmptyNode(), newEmptyNode(), nnkStmtList.newTree( nnkCommand.newTree( newIdentNode("echo"), nnkCall.newTree( newIdentNode("len"), newIdentNode("a") ), newLit(", "), nnkCall.newTree( newIdentNode("len"), newIdentNode("b") ) ) ) ), nnkProcDef.newTree( newIdentNode("explicit"), newEmptyNode(), nnkGenericParams.newTree( nnkIdentDefs.newTree( newIdentNode("A"), newIdentNode("B"), nnkDistinctTy.newTree( newIdentNode("Array2d") ), newEmptyNode() ) ), nnkFormalParams.newTree( newEmptyNode(), nnkIdentDefs.newTree( newIdentNode("a"), newIdentNode("A"), newEmptyNode() ), nnkIdentDefs.newTree( newIdentNode("b"), newIdentNode("B"), newEmptyNode() ) ), newEmptyNode(), newEmptyNode(), nnkStmtList.newTree( nnkCommand.newTree( newIdentNode("echo"), nnkCall.newTree( newIdentNode("len"), newIdentNode("a") ), newLit(", "), nnkCall.newTree( newIdentNode("len"), newIdentNode("b") ) ) ) ), nnkLetSection.newTree( nnkIdentDefs.newTree( newIdentNode("a"), newEmptyNode(), nnkBracket.newTree( nnkBracket.newTree( newLit(0), newLit(1) ) ) ) ), nnkLetSection.newTree( nnkIdentDefs.newTree( newIdentNode("b"), newEmptyNode(), nnkBracket.newTree( nnkBracket.newTree( newLit(0), newLit(1), newLit(2) ) ) ) ), nnkCall.newTree( newIdentNode("explicit"), newIdentNode("a"), newIdentNode("b") ), nnkCall.newTree( newIdentNode("doubleDist"), newIdentNode("a"), newIdentNode("b") ), nnkCall.newTree( newIdentNode("dist"), newIdentNode("a"), newIdentNode("b") ), nnkCall.newTree( newIdentNode("normal"), newIdentNode("a"), newIdentNode("b") ) ) ```
2.0.0 :-1: FAIL

Output

``` ```

IR

Compiled filesize 0 (0 bytes) ```cpp ```

Stats

  • Started 2024-10-22T01:52:47
  • Finished 2024-10-22T01:52:47
  • Duration

AST

```nim nnkStmtList.newTree( nnkTypeSection.newTree( nnkTypeDef.newTree( newIdentNode("Array2d"), nnkGenericParams.newTree( nnkIdentDefs.newTree( newIdentNode("W"), newIdentNode("H"), nnkBracketExpr.newTree( newIdentNode("static"), newIdentNode("int") ), newEmptyNode() ) ), nnkBracketExpr.newTree( newIdentNode("array"), newIdentNode("H"), nnkBracketExpr.newTree( newIdentNode("array"), newIdentNode("W"), newIdentNode("int") ) ) ) ), nnkProcDef.newTree( newIdentNode("normal"), newEmptyNode(), newEmptyNode(), nnkFormalParams.newTree( newEmptyNode(), nnkIdentDefs.newTree( newIdentNode("a"), newIdentNode("Array2d"), newEmptyNode() ), nnkIdentDefs.newTree( newIdentNode("b"), newIdentNode("Array2d"), newEmptyNode() ) ), newEmptyNode(), newEmptyNode(), nnkStmtList.newTree( nnkCommand.newTree( newIdentNode("echo"), nnkCall.newTree( newIdentNode("len"), newIdentNode("a") ), newLit(", "), nnkCall.newTree( newIdentNode("len"), newIdentNode("b") ) ) ) ), nnkProcDef.newTree( newIdentNode("dist"), newEmptyNode(), newEmptyNode(), nnkFormalParams.newTree( newEmptyNode(), nnkIdentDefs.newTree( newIdentNode("a"), newIdentNode("Array2d"), newEmptyNode() ), nnkIdentDefs.newTree( newIdentNode("b"), nnkDistinctTy.newTree( newIdentNode("Array2d") ), newEmptyNode() ) ), newEmptyNode(), newEmptyNode(), nnkStmtList.newTree( nnkCommand.newTree( newIdentNode("echo"), nnkCall.newTree( newIdentNode("len"), newIdentNode("a") ), newLit(", "), nnkCall.newTree( newIdentNode("len"), newIdentNode("b") ) ) ) ), nnkProcDef.newTree( newIdentNode("doubleDist"), newEmptyNode(), newEmptyNode(), nnkFormalParams.newTree( newEmptyNode(), nnkIdentDefs.newTree( newIdentNode("a"), nnkDistinctTy.newTree( newIdentNode("Array2d") ), newEmptyNode() ), nnkIdentDefs.newTree( newIdentNode("b"), nnkDistinctTy.newTree( newIdentNode("Array2d") ), newEmptyNode() ) ), newEmptyNode(), newEmptyNode(), nnkStmtList.newTree( nnkCommand.newTree( newIdentNode("echo"), nnkCall.newTree( newIdentNode("len"), newIdentNode("a") ), newLit(", "), nnkCall.newTree( newIdentNode("len"), newIdentNode("b") ) ) ) ), nnkProcDef.newTree( newIdentNode("explicit"), newEmptyNode(), nnkGenericParams.newTree( nnkIdentDefs.newTree( newIdentNode("A"), newIdentNode("B"), nnkDistinctTy.newTree( newIdentNode("Array2d") ), newEmptyNode() ) ), nnkFormalParams.newTree( newEmptyNode(), nnkIdentDefs.newTree( newIdentNode("a"), newIdentNode("A"), newEmptyNode() ), nnkIdentDefs.newTree( newIdentNode("b"), newIdentNode("B"), newEmptyNode() ) ), newEmptyNode(), newEmptyNode(), nnkStmtList.newTree( nnkCommand.newTree( newIdentNode("echo"), nnkCall.newTree( newIdentNode("len"), newIdentNode("a") ), newLit(", "), nnkCall.newTree( newIdentNode("len"), newIdentNode("b") ) ) ) ), nnkLetSection.newTree( nnkIdentDefs.newTree( newIdentNode("a"), newEmptyNode(), nnkBracket.newTree( nnkBracket.newTree( newLit(0), newLit(1) ) ) ) ), nnkLetSection.newTree( nnkIdentDefs.newTree( newIdentNode("b"), newEmptyNode(), nnkBracket.newTree( nnkBracket.newTree( newLit(0), newLit(1), newLit(2) ) ) ) ), nnkCall.newTree( newIdentNode("explicit"), newIdentNode("a"), newIdentNode("b") ), nnkCall.newTree( newIdentNode("doubleDist"), newIdentNode("a"), newIdentNode("b") ), nnkCall.newTree( newIdentNode("dist"), newIdentNode("a"), newIdentNode("b") ), nnkCall.newTree( newIdentNode("normal"), newIdentNode("a"), newIdentNode("b") ) ) ```
1.6.20 :-1: FAIL

Output

``` ```

IR

Compiled filesize 0 (0 bytes) ```cpp ```

Stats

  • Started 2024-10-22T01:52:50
  • Finished 2024-10-22T01:52:50
  • Duration

AST

```nim nnkStmtList.newTree( nnkTypeSection.newTree( nnkTypeDef.newTree( newIdentNode("Array2d"), nnkGenericParams.newTree( nnkIdentDefs.newTree( newIdentNode("W"), newIdentNode("H"), nnkBracketExpr.newTree( newIdentNode("static"), newIdentNode("int") ), newEmptyNode() ) ), nnkBracketExpr.newTree( newIdentNode("array"), newIdentNode("H"), nnkBracketExpr.newTree( newIdentNode("array"), newIdentNode("W"), newIdentNode("int") ) ) ) ), nnkProcDef.newTree( newIdentNode("normal"), newEmptyNode(), newEmptyNode(), nnkFormalParams.newTree( newEmptyNode(), nnkIdentDefs.newTree( newIdentNode("a"), newIdentNode("Array2d"), newEmptyNode() ), nnkIdentDefs.newTree( newIdentNode("b"), newIdentNode("Array2d"), newEmptyNode() ) ), newEmptyNode(), newEmptyNode(), nnkStmtList.newTree( nnkCommand.newTree( newIdentNode("echo"), nnkCall.newTree( newIdentNode("len"), newIdentNode("a") ), newLit(", "), nnkCall.newTree( newIdentNode("len"), newIdentNode("b") ) ) ) ), nnkProcDef.newTree( newIdentNode("dist"), newEmptyNode(), newEmptyNode(), nnkFormalParams.newTree( newEmptyNode(), nnkIdentDefs.newTree( newIdentNode("a"), newIdentNode("Array2d"), newEmptyNode() ), nnkIdentDefs.newTree( newIdentNode("b"), nnkDistinctTy.newTree( newIdentNode("Array2d") ), newEmptyNode() ) ), newEmptyNode(), newEmptyNode(), nnkStmtList.newTree( nnkCommand.newTree( newIdentNode("echo"), nnkCall.newTree( newIdentNode("len"), newIdentNode("a") ), newLit(", "), nnkCall.newTree( newIdentNode("len"), newIdentNode("b") ) ) ) ), nnkProcDef.newTree( newIdentNode("doubleDist"), newEmptyNode(), newEmptyNode(), nnkFormalParams.newTree( newEmptyNode(), nnkIdentDefs.newTree( newIdentNode("a"), nnkDistinctTy.newTree( newIdentNode("Array2d") ), newEmptyNode() ), nnkIdentDefs.newTree( newIdentNode("b"), nnkDistinctTy.newTree( newIdentNode("Array2d") ), newEmptyNode() ) ), newEmptyNode(), newEmptyNode(), nnkStmtList.newTree( nnkCommand.newTree( newIdentNode("echo"), nnkCall.newTree( newIdentNode("len"), newIdentNode("a") ), newLit(", "), nnkCall.newTree( newIdentNode("len"), newIdentNode("b") ) ) ) ), nnkProcDef.newTree( newIdentNode("explicit"), newEmptyNode(), nnkGenericParams.newTree( nnkIdentDefs.newTree( newIdentNode("A"), newIdentNode("B"), nnkDistinctTy.newTree( newIdentNode("Array2d") ), newEmptyNode() ) ), nnkFormalParams.newTree( newEmptyNode(), nnkIdentDefs.newTree( newIdentNode("a"), newIdentNode("A"), newEmptyNode() ), nnkIdentDefs.newTree( newIdentNode("b"), newIdentNode("B"), newEmptyNode() ) ), newEmptyNode(), newEmptyNode(), nnkStmtList.newTree( nnkCommand.newTree( newIdentNode("echo"), nnkCall.newTree( newIdentNode("len"), newIdentNode("a") ), newLit(", "), nnkCall.newTree( newIdentNode("len"), newIdentNode("b") ) ) ) ), nnkLetSection.newTree( nnkIdentDefs.newTree( newIdentNode("a"), newEmptyNode(), nnkBracket.newTree( nnkBracket.newTree( newLit(0), newLit(1) ) ) ) ), nnkLetSection.newTree( nnkIdentDefs.newTree( newIdentNode("b"), newEmptyNode(), nnkBracket.newTree( nnkBracket.newTree( newLit(0), newLit(1), newLit(2) ) ) ) ), nnkCall.newTree( newIdentNode("explicit"), newIdentNode("a"), newIdentNode("b") ), nnkCall.newTree( newIdentNode("doubleDist"), newIdentNode("a"), newIdentNode("b") ), nnkCall.newTree( newIdentNode("dist"), newIdentNode("a"), newIdentNode("b") ), nnkCall.newTree( newIdentNode("normal"), newIdentNode("a"), newIdentNode("b") ) ) ```
1.4.8 :-1: FAIL

Output

``` ```

IR

Compiled filesize 0 (0 bytes) ```cpp ```

Stats

  • Started 2024-10-22T01:52:54
  • Finished 2024-10-22T01:52:54
  • Duration

AST

```nim nnkStmtList.newTree( nnkTypeSection.newTree( nnkTypeDef.newTree( newIdentNode("Array2d"), nnkGenericParams.newTree( nnkIdentDefs.newTree( newIdentNode("W"), newIdentNode("H"), nnkBracketExpr.newTree( newIdentNode("static"), newIdentNode("int") ), newEmptyNode() ) ), nnkBracketExpr.newTree( newIdentNode("array"), newIdentNode("H"), nnkBracketExpr.newTree( newIdentNode("array"), newIdentNode("W"), newIdentNode("int") ) ) ) ), nnkProcDef.newTree( newIdentNode("normal"), newEmptyNode(), newEmptyNode(), nnkFormalParams.newTree( newEmptyNode(), nnkIdentDefs.newTree( newIdentNode("a"), newIdentNode("Array2d"), newEmptyNode() ), nnkIdentDefs.newTree( newIdentNode("b"), newIdentNode("Array2d"), newEmptyNode() ) ), newEmptyNode(), newEmptyNode(), nnkStmtList.newTree( nnkCommand.newTree( newIdentNode("echo"), nnkCall.newTree( newIdentNode("len"), newIdentNode("a") ), newLit(", "), nnkCall.newTree( newIdentNode("len"), newIdentNode("b") ) ) ) ), nnkProcDef.newTree( newIdentNode("dist"), newEmptyNode(), newEmptyNode(), nnkFormalParams.newTree( newEmptyNode(), nnkIdentDefs.newTree( newIdentNode("a"), newIdentNode("Array2d"), newEmptyNode() ), nnkIdentDefs.newTree( newIdentNode("b"), nnkDistinctTy.newTree( newIdentNode("Array2d") ), newEmptyNode() ) ), newEmptyNode(), newEmptyNode(), nnkStmtList.newTree( nnkCommand.newTree( newIdentNode("echo"), nnkCall.newTree( newIdentNode("len"), newIdentNode("a") ), newLit(", "), nnkCall.newTree( newIdentNode("len"), newIdentNode("b") ) ) ) ), nnkProcDef.newTree( newIdentNode("doubleDist"), newEmptyNode(), newEmptyNode(), nnkFormalParams.newTree( newEmptyNode(), nnkIdentDefs.newTree( newIdentNode("a"), nnkDistinctTy.newTree( newIdentNode("Array2d") ), newEmptyNode() ), nnkIdentDefs.newTree( newIdentNode("b"), nnkDistinctTy.newTree( newIdentNode("Array2d") ), newEmptyNode() ) ), newEmptyNode(), newEmptyNode(), nnkStmtList.newTree( nnkCommand.newTree( newIdentNode("echo"), nnkCall.newTree( newIdentNode("len"), newIdentNode("a") ), newLit(", "), nnkCall.newTree( newIdentNode("len"), newIdentNode("b") ) ) ) ), nnkProcDef.newTree( newIdentNode("explicit"), newEmptyNode(), nnkGenericParams.newTree( nnkIdentDefs.newTree( newIdentNode("A"), newIdentNode("B"), nnkDistinctTy.newTree( newIdentNode("Array2d") ), newEmptyNode() ) ), nnkFormalParams.newTree( newEmptyNode(), nnkIdentDefs.newTree( newIdentNode("a"), newIdentNode("A"), newEmptyNode() ), nnkIdentDefs.newTree( newIdentNode("b"), newIdentNode("B"), newEmptyNode() ) ), newEmptyNode(), newEmptyNode(), nnkStmtList.newTree( nnkCommand.newTree( newIdentNode("echo"), nnkCall.newTree( newIdentNode("len"), newIdentNode("a") ), newLit(", "), nnkCall.newTree( newIdentNode("len"), newIdentNode("b") ) ) ) ), nnkLetSection.newTree( nnkIdentDefs.newTree( newIdentNode("a"), newEmptyNode(), nnkBracket.newTree( nnkBracket.newTree( newLit(0), newLit(1) ) ) ) ), nnkLetSection.newTree( nnkIdentDefs.newTree( newIdentNode("b"), newEmptyNode(), nnkBracket.newTree( nnkBracket.newTree( newLit(0), newLit(1), newLit(2) ) ) ) ), nnkCall.newTree( newIdentNode("explicit"), newIdentNode("a"), newIdentNode("b") ), nnkCall.newTree( newIdentNode("doubleDist"), newIdentNode("a"), newIdentNode("b") ), nnkCall.newTree( newIdentNode("dist"), newIdentNode("a"), newIdentNode("b") ), nnkCall.newTree( newIdentNode("normal"), newIdentNode("a"), newIdentNode("b") ) ) ```
1.2.18 :-1: FAIL

Output

``` ```

IR

Compiled filesize 0 (0 bytes) ```cpp ```

Stats

  • Started 2024-10-22T01:52:57
  • Finished 2024-10-22T01:52:57
  • Duration

AST

```nim nnkStmtList.newTree( nnkTypeSection.newTree( nnkTypeDef.newTree( newIdentNode("Array2d"), nnkGenericParams.newTree( nnkIdentDefs.newTree( newIdentNode("W"), newIdentNode("H"), nnkBracketExpr.newTree( newIdentNode("static"), newIdentNode("int") ), newEmptyNode() ) ), nnkBracketExpr.newTree( newIdentNode("array"), newIdentNode("H"), nnkBracketExpr.newTree( newIdentNode("array"), newIdentNode("W"), newIdentNode("int") ) ) ) ), nnkProcDef.newTree( newIdentNode("normal"), newEmptyNode(), newEmptyNode(), nnkFormalParams.newTree( newEmptyNode(), nnkIdentDefs.newTree( newIdentNode("a"), newIdentNode("Array2d"), newEmptyNode() ), nnkIdentDefs.newTree( newIdentNode("b"), newIdentNode("Array2d"), newEmptyNode() ) ), newEmptyNode(), newEmptyNode(), nnkStmtList.newTree( nnkCommand.newTree( newIdentNode("echo"), nnkCall.newTree( newIdentNode("len"), newIdentNode("a") ), newLit(", "), nnkCall.newTree( newIdentNode("len"), newIdentNode("b") ) ) ) ), nnkProcDef.newTree( newIdentNode("dist"), newEmptyNode(), newEmptyNode(), nnkFormalParams.newTree( newEmptyNode(), nnkIdentDefs.newTree( newIdentNode("a"), newIdentNode("Array2d"), newEmptyNode() ), nnkIdentDefs.newTree( newIdentNode("b"), nnkDistinctTy.newTree( newIdentNode("Array2d") ), newEmptyNode() ) ), newEmptyNode(), newEmptyNode(), nnkStmtList.newTree( nnkCommand.newTree( newIdentNode("echo"), nnkCall.newTree( newIdentNode("len"), newIdentNode("a") ), newLit(", "), nnkCall.newTree( newIdentNode("len"), newIdentNode("b") ) ) ) ), nnkProcDef.newTree( newIdentNode("doubleDist"), newEmptyNode(), newEmptyNode(), nnkFormalParams.newTree( newEmptyNode(), nnkIdentDefs.newTree( newIdentNode("a"), nnkDistinctTy.newTree( newIdentNode("Array2d") ), newEmptyNode() ), nnkIdentDefs.newTree( newIdentNode("b"), nnkDistinctTy.newTree( newIdentNode("Array2d") ), newEmptyNode() ) ), newEmptyNode(), newEmptyNode(), nnkStmtList.newTree( nnkCommand.newTree( newIdentNode("echo"), nnkCall.newTree( newIdentNode("len"), newIdentNode("a") ), newLit(", "), nnkCall.newTree( newIdentNode("len"), newIdentNode("b") ) ) ) ), nnkProcDef.newTree( newIdentNode("explicit"), newEmptyNode(), nnkGenericParams.newTree( nnkIdentDefs.newTree( newIdentNode("A"), newIdentNode("B"), nnkDistinctTy.newTree( newIdentNode("Array2d") ), newEmptyNode() ) ), nnkFormalParams.newTree( newEmptyNode(), nnkIdentDefs.newTree( newIdentNode("a"), newIdentNode("A"), newEmptyNode() ), nnkIdentDefs.newTree( newIdentNode("b"), newIdentNode("B"), newEmptyNode() ) ), newEmptyNode(), newEmptyNode(), nnkStmtList.newTree( nnkCommand.newTree( newIdentNode("echo"), nnkCall.newTree( newIdentNode("len"), newIdentNode("a") ), newLit(", "), nnkCall.newTree( newIdentNode("len"), newIdentNode("b") ) ) ) ), nnkLetSection.newTree( nnkIdentDefs.newTree( newIdentNode("a"), newEmptyNode(), nnkBracket.newTree( nnkBracket.newTree( newLit(0), newLit(1) ) ) ) ), nnkLetSection.newTree( nnkIdentDefs.newTree( newIdentNode("b"), newEmptyNode(), nnkBracket.newTree( nnkBracket.newTree( newLit(0), newLit(1), newLit(2) ) ) ) ), nnkCall.newTree( newIdentNode("explicit"), newIdentNode("a"), newIdentNode("b") ), nnkCall.newTree( newIdentNode("doubleDist"), newIdentNode("a"), newIdentNode("b") ), nnkCall.newTree( newIdentNode("dist"), newIdentNode("a"), newIdentNode("b") ), nnkCall.newTree( newIdentNode("normal"), newIdentNode("a"), newIdentNode("b") ) ) ```
1.0.10 :-1: FAIL

Output

``` ```

IR

Compiled filesize 0 (0 bytes) ```cpp ```

Stats

  • Started 2024-10-22T01:53:00
  • Finished 2024-10-22T01:53:00
  • Duration

AST

```nim nnkStmtList.newTree( nnkTypeSection.newTree( nnkTypeDef.newTree( newIdentNode("Array2d"), nnkGenericParams.newTree( nnkIdentDefs.newTree( newIdentNode("W"), newIdentNode("H"), nnkBracketExpr.newTree( newIdentNode("static"), newIdentNode("int") ), newEmptyNode() ) ), nnkBracketExpr.newTree( newIdentNode("array"), newIdentNode("H"), nnkBracketExpr.newTree( newIdentNode("array"), newIdentNode("W"), newIdentNode("int") ) ) ) ), nnkProcDef.newTree( newIdentNode("normal"), newEmptyNode(), newEmptyNode(), nnkFormalParams.newTree( newEmptyNode(), nnkIdentDefs.newTree( newIdentNode("a"), newIdentNode("Array2d"), newEmptyNode() ), nnkIdentDefs.newTree( newIdentNode("b"), newIdentNode("Array2d"), newEmptyNode() ) ), newEmptyNode(), newEmptyNode(), nnkStmtList.newTree( nnkCommand.newTree( newIdentNode("echo"), nnkCall.newTree( newIdentNode("len"), newIdentNode("a") ), newLit(", "), nnkCall.newTree( newIdentNode("len"), newIdentNode("b") ) ) ) ), nnkProcDef.newTree( newIdentNode("dist"), newEmptyNode(), newEmptyNode(), nnkFormalParams.newTree( newEmptyNode(), nnkIdentDefs.newTree( newIdentNode("a"), newIdentNode("Array2d"), newEmptyNode() ), nnkIdentDefs.newTree( newIdentNode("b"), nnkDistinctTy.newTree( newIdentNode("Array2d") ), newEmptyNode() ) ), newEmptyNode(), newEmptyNode(), nnkStmtList.newTree( nnkCommand.newTree( newIdentNode("echo"), nnkCall.newTree( newIdentNode("len"), newIdentNode("a") ), newLit(", "), nnkCall.newTree( newIdentNode("len"), newIdentNode("b") ) ) ) ), nnkProcDef.newTree( newIdentNode("doubleDist"), newEmptyNode(), newEmptyNode(), nnkFormalParams.newTree( newEmptyNode(), nnkIdentDefs.newTree( newIdentNode("a"), nnkDistinctTy.newTree( newIdentNode("Array2d") ), newEmptyNode() ), nnkIdentDefs.newTree( newIdentNode("b"), nnkDistinctTy.newTree( newIdentNode("Array2d") ), newEmptyNode() ) ), newEmptyNode(), newEmptyNode(), nnkStmtList.newTree( nnkCommand.newTree( newIdentNode("echo"), nnkCall.newTree( newIdentNode("len"), newIdentNode("a") ), newLit(", "), nnkCall.newTree( newIdentNode("len"), newIdentNode("b") ) ) ) ), nnkProcDef.newTree( newIdentNode("explicit"), newEmptyNode(), nnkGenericParams.newTree( nnkIdentDefs.newTree( newIdentNode("A"), newIdentNode("B"), nnkDistinctTy.newTree( newIdentNode("Array2d") ), newEmptyNode() ) ), nnkFormalParams.newTree( newEmptyNode(), nnkIdentDefs.newTree( newIdentNode("a"), newIdentNode("A"), newEmptyNode() ), nnkIdentDefs.newTree( newIdentNode("b"), newIdentNode("B"), newEmptyNode() ) ), newEmptyNode(), newEmptyNode(), nnkStmtList.newTree( nnkCommand.newTree( newIdentNode("echo"), nnkCall.newTree( newIdentNode("len"), newIdentNode("a") ), newLit(", "), nnkCall.newTree( newIdentNode("len"), newIdentNode("b") ) ) ) ), nnkLetSection.newTree( nnkIdentDefs.newTree( newIdentNode("a"), newEmptyNode(), nnkBracket.newTree( nnkBracket.newTree( newLit(0), newLit(1) ) ) ) ), nnkLetSection.newTree( nnkIdentDefs.newTree( newIdentNode("b"), newEmptyNode(), nnkBracket.newTree( nnkBracket.newTree( newLit(0), newLit(1), newLit(2) ) ) ) ), nnkCall.newTree( newIdentNode("explicit"), newIdentNode("a"), newIdentNode("b") ), nnkCall.newTree( newIdentNode("doubleDist"), newIdentNode("a"), newIdentNode("b") ), nnkCall.newTree( newIdentNode("dist"), newIdentNode("a"), newIdentNode("b") ), nnkCall.newTree( newIdentNode("normal"), newIdentNode("a"), newIdentNode("b") ) ) ```
Stats
  • GCC 11.4.0
  • Clang 14.0.0
  • NodeJS 20.4
  • Created 2024-10-22T01:52:05Z
  • Comments 1
  • 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

:robot: Bug found in 28 mins bisecting 8 commits at 0 commits per second

metagn commented 1 week ago

static parameters in tyCompositeTypeClass keep the id of the original param, which universally matches that parameter to the first matching value.

IMO the solution is to add a type binding layer when matching tyCompositeTypeClass in sigmatch like in #24250, but #24250 needs a slight modification: only generic parameters belonging to the matched candidate should be matched in every previous binding layer, other generic parameters (like in this case, W and H) should only be matched in the current layer.