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

distinctBase matching regression #22417

Closed
arnetheduck opened this issue Aug 8, 2023 · 10 comments
Closed

distinctBase matching regression #22417

arnetheduck opened this issue Aug 8, 2023 · 10 comments

Comments

@arnetheduck
Copy link
Contributor

arnetheduck commented Aug 8, 2023

Description

import std/typetraits

type A = distinct int

var v: A

distinctBase(v) = 42

echo distinctBase(v)

distinctBase v = 42

Nim Version

works in 1.6, fails in 2.0

Current Output

No response

Expected Output

No response

Possible Solution

No response

Additional Information

No response

arnetheduck added a commit to status-im/nim-ssz-serialization that referenced this issue Aug 8, 2023
@ringabout
Copy link
Member

!nim c

import std/typetraits

type A = int

var v: A

distinctBase v = 42

@github-actions
Copy link
Contributor

github-actions bot commented Aug 8, 2023

@ringabout (member)

devel 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --styleCheck:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim(4, 1) Error: type mismatch
Expression: distinctBase v = 42
  [1] v = 42: v: int literal(42)

Expected one of (first mismatch at [position]):
[1] proc distinctBase(T: typedesc; recursive: static bool = true): typedesc
[1] template distinctBase[T](a: T; recursive: static bool = true): untyped

Stats

  • Started 2023-08-08T10:56:26
  • Finished 2023-08-08T10:56:26
  • Duration

IR

Compiled filesize 0 bytes (0 bytes)

AST

nnkStmtList.newTree(
  nnkImportStmt.newTree(
    nnkInfix.newTree(
      newIdentNode("/"),
      newIdentNode("std"),
      newIdentNode("typetraits")
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("A"),
      newEmptyNode(),
      newIdentNode("int")
    )
  ),
  nnkVarSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("v"),
      newIdentNode("A"),
      newEmptyNode()
    )
  ),
  nnkCommand.newTree(
    newIdentNode("distinctBase"),
    nnkExprEqExpr.newTree(
      newIdentNode("v"),
      newLit(42)
    )
  )
)
stable 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --styleCheck:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim(4, 1) Error: type mismatch
Expression: distinctBase v = 42
  [1] v = 42: v: int literal(42)

Expected one of (first mismatch at [position]):
[1] proc distinctBase(T: typedesc; recursive: static bool = true): typedesc
[1] template distinctBase[T](a: T; recursive: static bool = true): untyped

Stats

  • Started 2023-08-08T10:56:27
  • Finished 2023-08-08T10:56:27
  • Duration

IR

Compiled filesize 0 bytes (0 bytes)

AST

nnkStmtList.newTree(
  nnkImportStmt.newTree(
    nnkInfix.newTree(
      newIdentNode("/"),
      newIdentNode("std"),
      newIdentNode("typetraits")
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("A"),
      newEmptyNode(),
      newIdentNode("int")
    )
  ),
  nnkVarSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("v"),
      newIdentNode("A"),
      newEmptyNode()
    )
  ),
  nnkCommand.newTree(
    newIdentNode("distinctBase"),
    nnkExprEqExpr.newTree(
      newIdentNode("v"),
      newLit(42)
    )
  )
)
2.0.0 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --styleCheck:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim(4, 1) Error: type mismatch
Expression: distinctBase v = 42
  [1] v = 42: v: int literal(42)

Expected one of (first mismatch at [position]):
[1] proc distinctBase(T: typedesc; recursive: static bool = true): typedesc
[1] template distinctBase[T](a: T; recursive: static bool = true): untyped

Stats

  • Started 2023-08-08T10:56:27
  • Finished 2023-08-08T10:56:28
  • Duration

IR

Compiled filesize 0 bytes (0 bytes)

AST

nnkStmtList.newTree(
  nnkImportStmt.newTree(
    nnkInfix.newTree(
      newIdentNode("/"),
      newIdentNode("std"),
      newIdentNode("typetraits")
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("A"),
      newEmptyNode(),
      newIdentNode("int")
    )
  ),
  nnkVarSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("v"),
      newIdentNode("A"),
      newEmptyNode()
    )
  ),
  nnkCommand.newTree(
    newIdentNode("distinctBase"),
    nnkExprEqExpr.newTree(
      newIdentNode("v"),
      newLit(42)
    )
  )
)
1.6.0 👍 $\color{green}\textbf{\large OK}$

Output


Stats

  • Started 2023-08-08T10:56:31
  • Finished 2023-08-08T10:56:32
  • Duration
1.4.0 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --styleCheck:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim(4, 14) template/generic instantiation of `distinctBase` from here
/home/runner/.choosenim/toolchains/nim-1.4.0/lib/pure/typetraits.nim(79, 17) Error: distinctBase expects a distinct type as argument. The given type was A

Stats

  • Started 2023-08-08T10:56:34
  • Finished 2023-08-08T10:56:34
  • Duration

IR

Compiled filesize 94.91 Kb (97,184 bytes)
#define NIM_INTBITS 64
#include "nimbase.h"
#undef LANGUAGE_C
#undef MIPSEB
#undef MIPSEL
#undef PPC
#undef R3000
#undef R4000
#undef i386
#undef linux
#undef mips
#undef near
#undef far
#undef powerpc
#undef unix
  #  define nimfr_(proc, file) \
      TFrame FR_; \
      FR_.procname = proc; FR_.filename = file; FR_.line = 0; FR_.len = 0; nimFrame(&FR_);
  #  define nimfrs_(proc, file, slots, length) \
      struct {TFrame* prev;NCSTRING procname;NI line;NCSTRING filename; NI len; VarSlot s[slots];} FR_; \
      FR_.procname = proc; FR_.filename = file; FR_.line = 0; FR_.len = length; nimFrame((TFrame*)&FR_);
  #  define nimln_(n, file) \
      FR_.line = n; FR_.filename = file;
  static N_INLINE(void, initStackBottomWith)(void* locals);
N_LIB_PRIVATE N_NOINLINE(void, nimGC_setStackBottom)(void* theStackBottom);
static N_INLINE(void, nimFrame)(TFrame* s);
N_LIB_PRIVATE N_NOINLINE(void, callDepthLimitReached_system_2997)(void);
static N_INLINE(void, popFrame)(void);
N_LIB_PRIVATE N_NIMCALL(void, systemDatInit000)(void);
N_LIB_PRIVATE N_NIMCALL(void, systemInit000)(void);
N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void);
N_LIB_PRIVATE NI v_temp_3;
extern TFrame* framePtr_system_2564;
extern TFrame* framePtr_system_2564;
extern TFrame* framePtr_system_2564;
extern TFrame* framePtr_system_2564;
extern TFrame* framePtr_system_2564;
extern TFrame* framePtr_system_2564;
static N_INLINE(void, initStackBottomWith)(void* locals) {
	nimGC_setStackBottom(locals);
}
static N_INLINE(void, nimFrame)(TFrame* s) {
	{
		if (!(framePtr_system_2564 == ((TFrame*) NIM_NIL))) goto LA3_;
		(*s).calldepth = ((NI16) 0);
	}
	goto LA1_;
	LA3_: ;
	{
		(*s).calldepth = (NI16)((*framePtr_system_2564).calldepth + ((NI16) 1));
	}
	LA1_: ;
	(*s).prev = framePtr_system_2564;
	framePtr_system_2564 = s;
	{
		if (!((*s).calldepth == ((NI16) 2000))) goto LA8_;
		callDepthLimitReached_system_2997();
	}
	LA8_: ;
}
static N_INLINE(void, popFrame)(void) {
	framePtr_system_2564 = (*framePtr_system_2564).prev;
}
N_LIB_PRIVATE void PreMainInner(void) {
}
N_LIB_PRIVATE int cmdCount;
N_LIB_PRIVATE char** cmdLine;
N_LIB_PRIVATE char** gEnv;
N_LIB_PRIVATE void PreMain(void) {
	void (*volatile inner)(void);
	inner = PreMainInner;
	systemDatInit000();
	initStackBottomWith((void *)&inner);
	systemInit000();
	(*inner)();
}
N_LIB_PRIVATE N_CDECL(void, NimMainInner)(void) {
	NimMainModule();
}
N_CDECL(void, NimMain)(void) {
	void (*volatile inner)(void);
	PreMain();
	inner = NimMainInner;
	initStackBottomWith((void *)&inner);
	(*inner)();
}
int main(int argc, char** args, char** env) {
	cmdLine = args;
	cmdCount = argc;
	gEnv = env;
	NimMain();
	return nim_program_result;
}
N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void) {
{
	nimfr_("temp", "/home/runner/work/Nim/Nim/temp.nim");
	v_temp_3 = ((NI) 42);
	popFrame();
}
}

AST

nnkStmtList.newTree(
  nnkImportStmt.newTree(
    nnkInfix.newTree(
      newIdentNode("/"),
      newIdentNode("std"),
      newIdentNode("typetraits")
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("A"),
      newEmptyNode(),
      newIdentNode("int")
    )
  ),
  nnkVarSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("v"),
      newIdentNode("A"),
      newEmptyNode()
    )
  ),
  nnkAsgn.newTree(
    nnkCommand.newTree(
      newIdentNode("distinctBase"),
      newIdentNode("v")
    ),
    newLit(42)
  )
)
1.2.0 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --styleCheck:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim(4, 14) template/generic instantiation of `distinctBase` from here
/home/runner/.choosenim/toolchains/nim-1.2.0/lib/pure/typetraits.nim(80, 17) Error: distinctBase expects a distinct type as argument. The given type was A

Stats

  • Started 2023-08-08T10:56:50
  • Finished 2023-08-08T10:56:50
  • Duration

IR

Compiled filesize 94.91 Kb (97,184 bytes)
#define NIM_INTBITS 64
#include "nimbase.h"
#undef LANGUAGE_C
#undef MIPSEB
#undef MIPSEL
#undef PPC
#undef R3000
#undef R4000
#undef i386
#undef linux
#undef mips
#undef near
#undef far
#undef powerpc
#undef unix
  #  define nimfr_(proc, file) \
      TFrame FR_; \
      FR_.procname = proc; FR_.filename = file; FR_.line = 0; FR_.len = 0; nimFrame(&FR_);
  #  define nimfrs_(proc, file, slots, length) \
      struct {TFrame* prev;NCSTRING procname;NI line;NCSTRING filename; NI len; VarSlot s[slots];} FR_; \
      FR_.procname = proc; FR_.filename = file; FR_.line = 0; FR_.len = length; nimFrame((TFrame*)&FR_);
  #  define nimln_(n, file) \
      FR_.line = n; FR_.filename = file;
  static N_INLINE(void, initStackBottomWith)(void* locals);
N_LIB_PRIVATE N_NOINLINE(void, nimGC_setStackBottom)(void* theStackBottom);
static N_INLINE(void, nimFrame)(TFrame* s);
N_LIB_PRIVATE N_NOINLINE(void, callDepthLimitReached_system_2997)(void);
static N_INLINE(void, popFrame)(void);
N_LIB_PRIVATE N_NIMCALL(void, systemDatInit000)(void);
N_LIB_PRIVATE N_NIMCALL(void, systemInit000)(void);
N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void);
N_LIB_PRIVATE NI v_temp_3;
extern TFrame* framePtr_system_2564;
extern TFrame* framePtr_system_2564;
extern TFrame* framePtr_system_2564;
extern TFrame* framePtr_system_2564;
extern TFrame* framePtr_system_2564;
extern TFrame* framePtr_system_2564;
static N_INLINE(void, initStackBottomWith)(void* locals) {
	nimGC_setStackBottom(locals);
}
static N_INLINE(void, nimFrame)(TFrame* s) {
	{
		if (!(framePtr_system_2564 == ((TFrame*) NIM_NIL))) goto LA3_;
		(*s).calldepth = ((NI16) 0);
	}
	goto LA1_;
	LA3_: ;
	{
		(*s).calldepth = (NI16)((*framePtr_system_2564).calldepth + ((NI16) 1));
	}
	LA1_: ;
	(*s).prev = framePtr_system_2564;
	framePtr_system_2564 = s;
	{
		if (!((*s).calldepth == ((NI16) 2000))) goto LA8_;
		callDepthLimitReached_system_2997();
	}
	LA8_: ;
}
static N_INLINE(void, popFrame)(void) {
	framePtr_system_2564 = (*framePtr_system_2564).prev;
}
N_LIB_PRIVATE void PreMainInner(void) {
}
N_LIB_PRIVATE int cmdCount;
N_LIB_PRIVATE char** cmdLine;
N_LIB_PRIVATE char** gEnv;
N_LIB_PRIVATE void PreMain(void) {
	void (*volatile inner)(void);
	inner = PreMainInner;
	systemDatInit000();
	initStackBottomWith((void *)&inner);
	systemInit000();
	(*inner)();
}
N_LIB_PRIVATE N_CDECL(void, NimMainInner)(void) {
	NimMainModule();
}
N_CDECL(void, NimMain)(void) {
	void (*volatile inner)(void);
	PreMain();
	inner = NimMainInner;
	initStackBottomWith((void *)&inner);
	(*inner)();
}
int main(int argc, char** args, char** env) {
	cmdLine = args;
	cmdCount = argc;
	gEnv = env;
	NimMain();
	return nim_program_result;
}
N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void) {
{
	nimfr_("temp", "/home/runner/work/Nim/Nim/temp.nim");
	v_temp_3 = ((NI) 42);
	popFrame();
}
}

AST

nnkStmtList.newTree(
  nnkImportStmt.newTree(
    nnkInfix.newTree(
      newIdentNode("/"),
      newIdentNode("std"),
      newIdentNode("typetraits")
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("A"),
      newEmptyNode(),
      newIdentNode("int")
    )
  ),
  nnkVarSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("v"),
      newIdentNode("A"),
      newEmptyNode()
    )
  ),
  nnkAsgn.newTree(
    nnkCommand.newTree(
      newIdentNode("distinctBase"),
      newIdentNode("v")
    ),
    newLit(42)
  )
)
1.0.0 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --styleCheck:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim(4, 1) Error: undeclared identifier: 'distinctBase'

Stats

  • Started 2023-08-08T10:57:01
  • Finished 2023-08-08T10:57:01
  • Duration

IR

Compiled filesize 94.91 Kb (97,184 bytes)
#define NIM_INTBITS 64
#include "nimbase.h"
#undef LANGUAGE_C
#undef MIPSEB
#undef MIPSEL
#undef PPC
#undef R3000
#undef R4000
#undef i386
#undef linux
#undef mips
#undef near
#undef far
#undef powerpc
#undef unix
  #  define nimfr_(proc, file) \
      TFrame FR_; \
      FR_.procname = proc; FR_.filename = file; FR_.line = 0; FR_.len = 0; nimFrame(&FR_);
  #  define nimfrs_(proc, file, slots, length) \
      struct {TFrame* prev;NCSTRING procname;NI line;NCSTRING filename; NI len; VarSlot s[slots];} FR_; \
      FR_.procname = proc; FR_.filename = file; FR_.line = 0; FR_.len = length; nimFrame((TFrame*)&FR_);
  #  define nimln_(n, file) \
      FR_.line = n; FR_.filename = file;
  static N_INLINE(void, initStackBottomWith)(void* locals);
N_LIB_PRIVATE N_NOINLINE(void, nimGC_setStackBottom)(void* theStackBottom);
static N_INLINE(void, nimFrame)(TFrame* s);
N_LIB_PRIVATE N_NOINLINE(void, callDepthLimitReached_system_2997)(void);
static N_INLINE(void, popFrame)(void);
N_LIB_PRIVATE N_NIMCALL(void, systemDatInit000)(void);
N_LIB_PRIVATE N_NIMCALL(void, systemInit000)(void);
N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void);
N_LIB_PRIVATE NI v_temp_3;
extern TFrame* framePtr_system_2564;
extern TFrame* framePtr_system_2564;
extern TFrame* framePtr_system_2564;
extern TFrame* framePtr_system_2564;
extern TFrame* framePtr_system_2564;
extern TFrame* framePtr_system_2564;
static N_INLINE(void, initStackBottomWith)(void* locals) {
	nimGC_setStackBottom(locals);
}
static N_INLINE(void, nimFrame)(TFrame* s) {
	{
		if (!(framePtr_system_2564 == ((TFrame*) NIM_NIL))) goto LA3_;
		(*s).calldepth = ((NI16) 0);
	}
	goto LA1_;
	LA3_: ;
	{
		(*s).calldepth = (NI16)((*framePtr_system_2564).calldepth + ((NI16) 1));
	}
	LA1_: ;
	(*s).prev = framePtr_system_2564;
	framePtr_system_2564 = s;
	{
		if (!((*s).calldepth == ((NI16) 2000))) goto LA8_;
		callDepthLimitReached_system_2997();
	}
	LA8_: ;
}
static N_INLINE(void, popFrame)(void) {
	framePtr_system_2564 = (*framePtr_system_2564).prev;
}
N_LIB_PRIVATE void PreMainInner(void) {
}
N_LIB_PRIVATE int cmdCount;
N_LIB_PRIVATE char** cmdLine;
N_LIB_PRIVATE char** gEnv;
N_LIB_PRIVATE void PreMain(void) {
	void (*volatile inner)(void);
	inner = PreMainInner;
	systemDatInit000();
	initStackBottomWith((void *)&inner);
	systemInit000();
	(*inner)();
}
N_LIB_PRIVATE N_CDECL(void, NimMainInner)(void) {
	NimMainModule();
}
N_CDECL(void, NimMain)(void) {
	void (*volatile inner)(void);
	PreMain();
	inner = NimMainInner;
	initStackBottomWith((void *)&inner);
	(*inner)();
}
int main(int argc, char** args, char** env) {
	cmdLine = args;
	cmdCount = argc;
	gEnv = env;
	NimMain();
	return nim_program_result;
}
N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void) {
{
	nimfr_("temp", "/home/runner/work/Nim/Nim/temp.nim");
	v_temp_3 = ((NI) 42);
	popFrame();
}
}

AST

nnkStmtList.newTree(
  nnkImportStmt.newTree(
    nnkInfix.newTree(
      newIdentNode("/"),
      newIdentNode("std"),
      newIdentNode("typetraits")
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("A"),
      newEmptyNode(),
      newIdentNode("int")
    )
  ),
  nnkVarSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("v"),
      newIdentNode("A"),
      newEmptyNode()
    )
  ),
  nnkAsgn.newTree(
    nnkCommand.newTree(
      newIdentNode("distinctBase"),
      newIdentNode("v")
    ),
    newLit(42)
  )
)
0.20.2 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --styleCheck:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim(4, 1) Error: undeclared identifier: 'distinctBase'

Stats

  • Started 2023-08-08T10:57:11
  • Finished 2023-08-08T10:57:11
  • Duration

IR

Compiled filesize 94.91 Kb (97,184 bytes)
#define NIM_INTBITS 64
#include "nimbase.h"
#undef LANGUAGE_C
#undef MIPSEB
#undef MIPSEL
#undef PPC
#undef R3000
#undef R4000
#undef i386
#undef linux
#undef mips
#undef near
#undef far
#undef powerpc
#undef unix
  #  define nimfr_(proc, file) \
      TFrame FR_; \
      FR_.procname = proc; FR_.filename = file; FR_.line = 0; FR_.len = 0; nimFrame(&FR_);
  #  define nimfrs_(proc, file, slots, length) \
      struct {TFrame* prev;NCSTRING procname;NI line;NCSTRING filename; NI len; VarSlot s[slots];} FR_; \
      FR_.procname = proc; FR_.filename = file; FR_.line = 0; FR_.len = length; nimFrame((TFrame*)&FR_);
  #  define nimln_(n, file) \
      FR_.line = n; FR_.filename = file;
  static N_INLINE(void, initStackBottomWith)(void* locals);
N_LIB_PRIVATE N_NOINLINE(void, nimGC_setStackBottom)(void* theStackBottom);
static N_INLINE(void, nimFrame)(TFrame* s);
N_LIB_PRIVATE N_NOINLINE(void, callDepthLimitReached_system_2997)(void);
static N_INLINE(void, popFrame)(void);
N_LIB_PRIVATE N_NIMCALL(void, systemDatInit000)(void);
N_LIB_PRIVATE N_NIMCALL(void, systemInit000)(void);
N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void);
N_LIB_PRIVATE NI v_temp_3;
extern TFrame* framePtr_system_2564;
extern TFrame* framePtr_system_2564;
extern TFrame* framePtr_system_2564;
extern TFrame* framePtr_system_2564;
extern TFrame* framePtr_system_2564;
extern TFrame* framePtr_system_2564;
static N_INLINE(void, initStackBottomWith)(void* locals) {
	nimGC_setStackBottom(locals);
}
static N_INLINE(void, nimFrame)(TFrame* s) {
	{
		if (!(framePtr_system_2564 == ((TFrame*) NIM_NIL))) goto LA3_;
		(*s).calldepth = ((NI16) 0);
	}
	goto LA1_;
	LA3_: ;
	{
		(*s).calldepth = (NI16)((*framePtr_system_2564).calldepth + ((NI16) 1));
	}
	LA1_: ;
	(*s).prev = framePtr_system_2564;
	framePtr_system_2564 = s;
	{
		if (!((*s).calldepth == ((NI16) 2000))) goto LA8_;
		callDepthLimitReached_system_2997();
	}
	LA8_: ;
}
static N_INLINE(void, popFrame)(void) {
	framePtr_system_2564 = (*framePtr_system_2564).prev;
}
N_LIB_PRIVATE void PreMainInner(void) {
}
N_LIB_PRIVATE int cmdCount;
N_LIB_PRIVATE char** cmdLine;
N_LIB_PRIVATE char** gEnv;
N_LIB_PRIVATE void PreMain(void) {
	void (*volatile inner)(void);
	inner = PreMainInner;
	systemDatInit000();
	initStackBottomWith((void *)&inner);
	systemInit000();
	(*inner)();
}
N_LIB_PRIVATE N_CDECL(void, NimMainInner)(void) {
	NimMainModule();
}
N_CDECL(void, NimMain)(void) {
	void (*volatile inner)(void);
	PreMain();
	inner = NimMainInner;
	initStackBottomWith((void *)&inner);
	(*inner)();
}
int main(int argc, char** args, char** env) {
	cmdLine = args;
	cmdCount = argc;
	gEnv = env;
	NimMain();
	return nim_program_result;
}
N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void) {
{
	nimfr_("temp", "/home/runner/work/Nim/Nim/temp.nim");
	v_temp_3 = ((NI) 42);
	popFrame();
}
}

AST

nnkStmtList.newTree(
  nnkImportStmt.newTree(
    nnkInfix.newTree(
      newIdentNode("/"),
      newIdentNode("std"),
      newIdentNode("typetraits")
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("A"),
      newEmptyNode(),
      newIdentNode("int")
    )
  ),
  nnkVarSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("v"),
      newIdentNode("A"),
      newEmptyNode()
    )
  ),
  nnkAsgn.newTree(
    nnkCommand.newTree(
      newIdentNode("distinctBase"),
      newIdentNode("v")
    ),
    newLit(42)
  )
)
#4ca2dcb40 ➡️ 🐛

Diagnostics

metagn introduced a bug at 2022-12-06 15:11:56 +0300 on commit #4ca2dcb40 with message:

Named arguments in commands + many grammar fixes (#20994)

* Breaking parser changes, implement https://github.com/nim-lang/RFCs/issues/442

Types are separated from expressions and better reflected in the grammar.

* add test

* more accurate grammar

* fix keyword typedescs

* accept expressions in proc argument lists

* CI "fixes"

* fixes

* allow full ref expressions again, adapt old tests

* cleanup, fix some tests

* improve grammar, try and revert semtypes change

* restrict sigil binding to identOrLiteral

* fix, should have caught this immediately

* add changelog entry, fix double not nil bug

* correct grammar

* change section

* fix

* real fix hopefully

* fix test

* support LL(1) for tuples

* make grammar.txt too

The bug is in the files:

changelog.md
compiler/parser.nim
doc/grammar.txt
tests/assert/tassert2.nim
tests/effects/tdiagnostic_messages.nim
tests/effects/teffects1.nim
tests/errmsgs/t9768.nim
tests/errmsgs/tsigmatch2.nim
tests/parser/tcommand_as_expr.nim
tests/parser/tcommandequals.nim
tests/parser/tcommandindent.nim
tests/parser/tdoublenotnil.nim
tests/parser/ttypeexprobject.nim
tests/parser/ttypeexprs.nim
tests/system/tvarargslen.nim
tests/typerel/t7600_1.nim
tests/typerel/t7600_2.nim
tests/varres/tprevent_forloopvar_mutations.nim

The bug can be in the commits:

(Diagnostics sometimes off-by-one).

Stats
  • GCC (Ubuntu 11.3.0-1ubuntu1~22.04.1) 11.3.0
  • LibC (Ubuntu GLIBC 2.35-0ubuntu3.1) 2.35
  • Valgrind 3.18.1
  • NodeJS 18.17.0
  • Linux 5.15.0-1042-
  • Created 2023-08-08T10:55:46Z
  • Issue Comments 1
  • Commands nim c --run -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --styleCheck: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 7 minutes bisecting 1625 commits at 215 commits per second.

@arnetheduck
Copy link
Contributor Author

a more meaningful version, ie type A = distinct int probably works all the way back to 1.2...

@metagn
Copy link
Collaborator

metagn commented Aug 8, 2023

Why was the issue edited to the distinct int version if it works? @bung87

distinctBase v = 42 fails because parsing rules were changed in 2.0 and it parses as distinctBase(v = 42).

@bung87
Copy link
Collaborator

bung87 commented Aug 8, 2023

it doesn't work, the problem here is not related to the type definition, the matched distinctBase is template, v = 42 treat as the template first argument. the result is

Error: type mismatch: got <v: int literal(42)>
but expected one of:
proc distinctBase(T: typedesc; recursive: static bool = true): typedesc
  first type mismatch at position: 1
  unknown named parameter: v
template distinctBase[T](a: T; recursive: static bool = true): untyped
  first type mismatch at position: 1
  unknown named parameter: v

expression: distinctBase v = 42

@metagn
Copy link
Collaborator

metagn commented Aug 8, 2023

Yes. That is new parser behavior in 2.0.

From the changelog:

foo a = b now means foo(a = b) rather than foo(a) = b. This is consistent with the existing behavior of foo a, b = c meaning foo(a, b = c). This decision was made with the assumption that the old syntax was used rarely; if your code used the old syntax, please be aware of this change.

Maybe the "porting guide" was not comprehensive enough.

@bung87
Copy link
Collaborator

bung87 commented Aug 8, 2023

so this is expected behavior, not a issue now.

@metagn
Copy link
Collaborator

metagn commented Aug 8, 2023

@arnetheduck Any further problems?

@arnetheduck
Copy link
Contributor Author

weird but ok, whatever. I think the most accurate summary of the change is "command syntax has many weird quirks, avoid it" - ie when you see foo a = b on its own, I don't think many people would think it'll bind = more tightly because an assignment is typically not thought of as an expression, even if in fact it can be one.

consider:

proc f(v: int): int =
  echo v
  var x: int
  x = 44

var v: int
echo f(v = 42)

x = 44 in the above case is not an expression: the function will return 0 which means that assignment only "sometimes" exhibits expression properties - if this change was made, the above should reasonably also see expression treatment and turn into a return value for f.

Closing for now, this bug is probably not the right place for this discussion, though it's certainly an oddball change that broke compat.

@metagn
Copy link
Collaborator

metagn commented Aug 9, 2023

Read nim-lang/RFCs#442 for reasoning

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

4 participants