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.62k stars 1.47k forks source link

Unexpected behavior with range types and custom operators #24032

Open fierce-goose opened 2 months ago

fierce-goose commented 2 months ago

Description

proc `++`(n: var int) =
    n += 1

type
    r = range[ 0..15 ]

var a: r = 15

++a

echo a

this code should have thrown an error because I'm trying to assign a variable a value larger than possible, but it just goes beyond the allowed limits without error

Nim Version

Nim Compiler Version 2.0.8 [Linux: amd64]

Current Output

16

Expected Output

sysFatal
Error: unhandled exception: over- or underflow [OverflowDefect]

Known Workarounds

No response

Additional Information

No response

juancarlospaco commented 2 months ago

!nim c

proc `++`(n: var int) = n += 1
type r = range[0..15]
var a: r = 15
++a
echo a
github-actions[bot] commented 2 months ago
:penguin: Linux bisect by @juancarlospaco (collaborator)
devel :+1: OK

Output

``` ```

IR

Compiled filesize 93.14 Kb (95,376 bytes) ```cpp #include "nimbase.h" #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) \ FR_.line = n; #define nimlf_(n, file) \ FR_.line = n; FR_.filename = file; typedef struct NimStrPayload NimStrPayload; typedef struct NimStringV2 NimStringV2; struct NimStrPayload { NI cap; NIM_CHAR data[SEQ_DECL_SIZE]; }; struct NimStringV2 { NI len; NimStrPayload* p; }; typedef NimStringV2 tyArray__nHXaesL0DJZHyVS07ARPRA[1]; N_LIB_PRIVATE N_NIMCALL(void, plusplus___temp_u1)(NI* n_p0); N_LIB_PRIVATE N_NOINLINE(void, raiseOverflow)(void); static N_INLINE(void, nimFrame)(TFrame* s_p0); N_LIB_PRIVATE N_NOINLINE(void, callDepthLimitReached__system_u4613)(void); static N_INLINE(void, popFrame)(void); N_LIB_PRIVATE N_NIMCALL(NimStringV2, dollar___systemZdollars_u8)(NI x_p0); N_LIB_PRIVATE N_NIMCALL(void, echoBinSafe)(NimStringV2* args_p0, NI args_p0Len_0); N_LIB_PRIVATE N_NOCONV(void, deallocShared)(void* p_p0); static N_INLINE(NIM_BOOL*, nimErrorFlag)(void); N_LIB_PRIVATE N_NIMCALL(void, nimTestErrorFlag)(void); N_LIB_PRIVATE N_NIMCALL(void, atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminusathdevelatslibatssystemdotnim_Init000)(void); N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void); N_LIB_PRIVATE NI a__temp_u8 = ((NI)15); extern NIM_THREADVAR TFrame* framePtr__system_u2654; extern NIM_THREADVAR NIM_BOOL nimInErrorMode__system_u4397; static N_INLINE(void, nimFrame)(TFrame* s_p0) { { if (!(framePtr__system_u2654 == ((TFrame*) NIM_NIL))) goto LA3_; (*s_p0).calldepth = ((NI16)0); } goto LA1_; LA3_: ; { (*s_p0).calldepth = (NI16)((*framePtr__system_u2654).calldepth + ((NI16)1)); } LA1_: ; (*s_p0).prev = framePtr__system_u2654; framePtr__system_u2654 = s_p0; { if (!((*s_p0).calldepth == ((NI16)2000))) goto LA8_; callDepthLimitReached__system_u4613(); } LA8_: ; } static N_INLINE(void, popFrame)(void) { framePtr__system_u2654 = (*framePtr__system_u2654).prev; } N_LIB_PRIVATE N_NIMCALL(void, plusplus___temp_u1)(NI* n_p0) { NI TM__SRd76hP9cMfCzdUO857UhQQ_2; nimfr_("++", "/home/runner/work/Nim/Nim/temp.nim"); { if (nimAddInt((*n_p0), ((NI)1), &TM__SRd76hP9cMfCzdUO857UhQQ_2)) { raiseOverflow(); goto BeforeRet_; }; (*n_p0) = (NI)(TM__SRd76hP9cMfCzdUO857UhQQ_2); }BeforeRet_: ; popFrame(); } static N_INLINE(NIM_BOOL*, nimErrorFlag)(void) { NIM_BOOL* result; result = (&nimInErrorMode__system_u4397); return result; } 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) { #if 0 void (*volatile inner)(void); inner = PreMainInner; atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminusathdevelatslibatssystemdotnim_Init000(); (*inner)(); #else atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminusathdevelatslibatssystemdotnim_Init000(); PreMainInner(); #endif } N_LIB_PRIVATE N_CDECL(void, NimMainInner)(void) { NimMainModule(); } N_CDECL(void, NimMain)(void) { #if 0 void (*volatile inner)(void); PreMain(); inner = NimMainInner; (*inner)(); #else PreMain(); NimMainInner(); #endif } 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) { { NimStringV2 colontmpD_; tyArray__nHXaesL0DJZHyVS07ARPRA T2_; NIM_BOOL* nimErr_; nimfr_("temp", "/home/runner/work/Nim/Nim/temp.nim"); nimErr_ = nimErrorFlag(); colontmpD_.len = 0; colontmpD_.p = NIM_NIL; plusplus___temp_u1(((NI*) ((&a__temp_u8)))); if (NIM_UNLIKELY(*nimErr_)) goto LA1_; colontmpD_ = dollar___systemZdollars_u8(((NI) (a__temp_u8))); if (NIM_UNLIKELY(*nimErr_)) goto LA1_; T2_[0] = colontmpD_; echoBinSafe(T2_, 1); { LA1_:; } { if (colontmpD_.p && !(colontmpD_.p->cap & NIM_STRLIT_FLAG)) { deallocShared(colontmpD_.p); } } if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_; BeforeRet_: ; nimTestErrorFlag(); popFrame(); } } ```

Stats

  • Started 2024-08-29T22:16:58
  • Finished 2024-08-29T22:16:59
  • Duration
stable :+1: OK

Output

``` ```

IR

Compiled filesize 93.10 Kb (95,336 bytes) ```cpp #include "nimbase.h" #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) \ FR_.line = n; #define nimlf_(n, file) \ FR_.line = n; FR_.filename = file; typedef struct NimStrPayload NimStrPayload; typedef struct NimStringV2 NimStringV2; struct NimStrPayload { NI cap; NIM_CHAR data[SEQ_DECL_SIZE]; }; struct NimStringV2 { NI len; NimStrPayload* p; }; typedef NimStringV2 tyArray__nHXaesL0DJZHyVS07ARPRA[1]; N_LIB_PRIVATE N_NIMCALL(void, plusplus___temp_u1)(NI* n_p0); N_LIB_PRIVATE N_NOINLINE(void, raiseOverflow)(void); static N_INLINE(void, nimFrame)(TFrame* s_p0); N_LIB_PRIVATE N_NOINLINE(void, callDepthLimitReached__system_u4620)(void); static N_INLINE(void, popFrame)(void); N_LIB_PRIVATE N_NIMCALL(NimStringV2, dollar___systemZdollars_u8)(NI x_p0); N_LIB_PRIVATE N_NIMCALL(void, echoBinSafe)(NimStringV2* args_p0, NI args_p0Len_0); N_LIB_PRIVATE N_NOCONV(void, deallocShared)(void* p_p0); static N_INLINE(NIM_BOOL*, nimErrorFlag)(void); N_LIB_PRIVATE N_NIMCALL(void, nimTestErrorFlag)(void); N_LIB_PRIVATE N_NIMCALL(void, atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminus2dot0dot8atslibatssystemdotnim_Init000)(void); N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void); N_LIB_PRIVATE NI a__temp_u8 = ((NI)15); extern NIM_THREADVAR TFrame* framePtr__system_u4059; extern NIM_THREADVAR NIM_BOOL nimInErrorMode__system_u4402; static N_INLINE(void, nimFrame)(TFrame* s_p0) { { if (!(framePtr__system_u4059 == ((TFrame*) NIM_NIL))) goto LA3_; (*s_p0).calldepth = ((NI16)0); } goto LA1_; LA3_: ; { (*s_p0).calldepth = (NI16)((*framePtr__system_u4059).calldepth + ((NI16)1)); } LA1_: ; (*s_p0).prev = framePtr__system_u4059; framePtr__system_u4059 = s_p0; { if (!((*s_p0).calldepth == ((NI16)2000))) goto LA8_; callDepthLimitReached__system_u4620(); } LA8_: ; } static N_INLINE(void, popFrame)(void) { framePtr__system_u4059 = (*framePtr__system_u4059).prev; } N_LIB_PRIVATE N_NIMCALL(void, plusplus___temp_u1)(NI* n_p0) { NI TM__SRd76hP9cMfCzdUO857UhQQ_2; nimfr_("++", "/home/runner/work/Nim/Nim/temp.nim"); { if (nimAddInt((*n_p0), ((NI)1), &TM__SRd76hP9cMfCzdUO857UhQQ_2)) { raiseOverflow(); goto BeforeRet_; }; (*n_p0) = (NI)(TM__SRd76hP9cMfCzdUO857UhQQ_2); }BeforeRet_: ; popFrame(); } static N_INLINE(NIM_BOOL*, nimErrorFlag)(void) { NIM_BOOL* result; result = (&nimInErrorMode__system_u4402); return result; } 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) { #if 0 void (*volatile inner)(void); inner = PreMainInner; atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminus2dot0dot8atslibatssystemdotnim_Init000(); (*inner)(); #else atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminus2dot0dot8atslibatssystemdotnim_Init000(); PreMainInner(); #endif } N_LIB_PRIVATE N_CDECL(void, NimMainInner)(void) { NimMainModule(); } N_CDECL(void, NimMain)(void) { #if 0 void (*volatile inner)(void); PreMain(); inner = NimMainInner; (*inner)(); #else PreMain(); NimMainInner(); #endif } 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) { { NimStringV2 colontmpD_; tyArray__nHXaesL0DJZHyVS07ARPRA T2_; NIM_BOOL* nimErr_; nimfr_("temp", "/home/runner/work/Nim/Nim/temp.nim"); nimErr_ = nimErrorFlag(); colontmpD_.len = 0; colontmpD_.p = NIM_NIL; plusplus___temp_u1((&a__temp_u8)); if (NIM_UNLIKELY(*nimErr_)) goto LA1_; colontmpD_ = dollar___systemZdollars_u8(((NI) (a__temp_u8))); if (NIM_UNLIKELY(*nimErr_)) goto LA1_; T2_[0] = colontmpD_; echoBinSafe(T2_, 1); { LA1_:; } { if (colontmpD_.p && !(colontmpD_.p->cap & NIM_STRLIT_FLAG)) { deallocShared(colontmpD_.p); } } if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_; BeforeRet_: ; nimTestErrorFlag(); popFrame(); } } ```

Stats

  • Started 2024-08-29T22:17:03
  • Finished 2024-08-29T22:17:03
  • Duration
2.0.8 :+1: OK

Output

``` ```

IR

Compiled filesize 93.10 Kb (95,336 bytes) ```cpp #include "nimbase.h" #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) \ FR_.line = n; #define nimlf_(n, file) \ FR_.line = n; FR_.filename = file; typedef struct NimStrPayload NimStrPayload; typedef struct NimStringV2 NimStringV2; struct NimStrPayload { NI cap; NIM_CHAR data[SEQ_DECL_SIZE]; }; struct NimStringV2 { NI len; NimStrPayload* p; }; typedef NimStringV2 tyArray__nHXaesL0DJZHyVS07ARPRA[1]; N_LIB_PRIVATE N_NIMCALL(void, plusplus___temp_u1)(NI* n_p0); N_LIB_PRIVATE N_NOINLINE(void, raiseOverflow)(void); static N_INLINE(void, nimFrame)(TFrame* s_p0); N_LIB_PRIVATE N_NOINLINE(void, callDepthLimitReached__system_u4620)(void); static N_INLINE(void, popFrame)(void); N_LIB_PRIVATE N_NIMCALL(NimStringV2, dollar___systemZdollars_u8)(NI x_p0); N_LIB_PRIVATE N_NIMCALL(void, echoBinSafe)(NimStringV2* args_p0, NI args_p0Len_0); N_LIB_PRIVATE N_NOCONV(void, deallocShared)(void* p_p0); static N_INLINE(NIM_BOOL*, nimErrorFlag)(void); N_LIB_PRIVATE N_NIMCALL(void, nimTestErrorFlag)(void); N_LIB_PRIVATE N_NIMCALL(void, atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminus2dot0dot8atslibatssystemdotnim_Init000)(void); N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void); N_LIB_PRIVATE NI a__temp_u8 = ((NI)15); extern NIM_THREADVAR TFrame* framePtr__system_u4059; extern NIM_THREADVAR NIM_BOOL nimInErrorMode__system_u4402; static N_INLINE(void, nimFrame)(TFrame* s_p0) { { if (!(framePtr__system_u4059 == ((TFrame*) NIM_NIL))) goto LA3_; (*s_p0).calldepth = ((NI16)0); } goto LA1_; LA3_: ; { (*s_p0).calldepth = (NI16)((*framePtr__system_u4059).calldepth + ((NI16)1)); } LA1_: ; (*s_p0).prev = framePtr__system_u4059; framePtr__system_u4059 = s_p0; { if (!((*s_p0).calldepth == ((NI16)2000))) goto LA8_; callDepthLimitReached__system_u4620(); } LA8_: ; } static N_INLINE(void, popFrame)(void) { framePtr__system_u4059 = (*framePtr__system_u4059).prev; } N_LIB_PRIVATE N_NIMCALL(void, plusplus___temp_u1)(NI* n_p0) { NI TM__SRd76hP9cMfCzdUO857UhQQ_2; nimfr_("++", "/home/runner/work/Nim/Nim/temp.nim"); { if (nimAddInt((*n_p0), ((NI)1), &TM__SRd76hP9cMfCzdUO857UhQQ_2)) { raiseOverflow(); goto BeforeRet_; }; (*n_p0) = (NI)(TM__SRd76hP9cMfCzdUO857UhQQ_2); }BeforeRet_: ; popFrame(); } static N_INLINE(NIM_BOOL*, nimErrorFlag)(void) { NIM_BOOL* result; result = (&nimInErrorMode__system_u4402); return result; } 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) { #if 0 void (*volatile inner)(void); inner = PreMainInner; atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminus2dot0dot8atslibatssystemdotnim_Init000(); (*inner)(); #else atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminus2dot0dot8atslibatssystemdotnim_Init000(); PreMainInner(); #endif } N_LIB_PRIVATE N_CDECL(void, NimMainInner)(void) { NimMainModule(); } N_CDECL(void, NimMain)(void) { #if 0 void (*volatile inner)(void); PreMain(); inner = NimMainInner; (*inner)(); #else PreMain(); NimMainInner(); #endif } 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) { { NimStringV2 colontmpD_; tyArray__nHXaesL0DJZHyVS07ARPRA T2_; NIM_BOOL* nimErr_; nimfr_("temp", "/home/runner/work/Nim/Nim/temp.nim"); nimErr_ = nimErrorFlag(); colontmpD_.len = 0; colontmpD_.p = NIM_NIL; plusplus___temp_u1((&a__temp_u8)); if (NIM_UNLIKELY(*nimErr_)) goto LA1_; colontmpD_ = dollar___systemZdollars_u8(((NI) (a__temp_u8))); if (NIM_UNLIKELY(*nimErr_)) goto LA1_; T2_[0] = colontmpD_; echoBinSafe(T2_, 1); { LA1_:; } { if (colontmpD_.p && !(colontmpD_.p->cap & NIM_STRLIT_FLAG)) { deallocShared(colontmpD_.p); } } if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_; BeforeRet_: ; nimTestErrorFlag(); popFrame(); } } ```

Stats

  • Started 2024-08-29T22:17:03
  • Finished 2024-08-29T22:17:04
  • Duration
2.0.0 :+1: OK

Output

``` ```

IR

Compiled filesize 90.96 Kb (93,144 bytes) ```cpp #include "nimbase.h" #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) \ FR_.line = n; #define nimlf_(n, file) \ FR_.line = n; FR_.filename = file; typedef struct NimStrPayload NimStrPayload; typedef struct NimStringV2 NimStringV2; struct NimStrPayload { NI cap; NIM_CHAR data[SEQ_DECL_SIZE]; }; struct NimStringV2 { NI len; NimStrPayload* p; }; typedef NimStringV2 tyArray__nHXaesL0DJZHyVS07ARPRA[1]; N_LIB_PRIVATE N_NIMCALL(void, plusplus___temp_u1)(NI* n_p0); N_LIB_PRIVATE N_NOINLINE(void, raiseOverflow)(void); static N_INLINE(void, nimFrame)(TFrame* s_p0); N_LIB_PRIVATE N_NOINLINE(void, callDepthLimitReached__system_u4607)(void); static N_INLINE(void, popFrame)(void); N_LIB_PRIVATE N_NIMCALL(NimStringV2, dollar___systemZdollars_u8)(NI x_p0); N_LIB_PRIVATE N_NIMCALL(void, echoBinSafe)(NimStringV2* args_p0, NI args_p0Len_0); N_LIB_PRIVATE N_NOCONV(void, deallocShared)(void* p_p0); static N_INLINE(NIM_BOOL*, nimErrorFlag)(void); N_LIB_PRIVATE N_NIMCALL(void, nimTestErrorFlag)(void); N_LIB_PRIVATE N_NIMCALL(void, atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminus2dot0dot0atslibatssystemdotnim_Init000)(void); N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void); N_LIB_PRIVATE NI a__temp_u8 = ((NI)15); extern NIM_THREADVAR TFrame* framePtr__system_u4006; extern NIM_THREADVAR NIM_BOOL nimInErrorMode__system_u4389; static N_INLINE(void, nimFrame)(TFrame* s_p0) { { if (!(framePtr__system_u4006 == ((TFrame*) NIM_NIL))) goto LA3_; (*s_p0).calldepth = ((NI16)0); } goto LA1_; LA3_: ; { (*s_p0).calldepth = (NI16)((*framePtr__system_u4006).calldepth + ((NI16)1)); } LA1_: ; (*s_p0).prev = framePtr__system_u4006; framePtr__system_u4006 = s_p0; { if (!((*s_p0).calldepth == ((NI16)2000))) goto LA8_; callDepthLimitReached__system_u4607(); } LA8_: ; } static N_INLINE(void, popFrame)(void) { framePtr__system_u4006 = (*framePtr__system_u4006).prev; } N_LIB_PRIVATE N_NIMCALL(void, plusplus___temp_u1)(NI* n_p0) { NI TM__SRd76hP9cMfCzdUO857UhQQ_2; nimfr_("++", "/home/runner/work/Nim/Nim/temp.nim"); { if (nimAddInt((*n_p0), ((NI)1), &TM__SRd76hP9cMfCzdUO857UhQQ_2)) { raiseOverflow(); goto BeforeRet_; }; (*n_p0) = (NI)(TM__SRd76hP9cMfCzdUO857UhQQ_2); }BeforeRet_: ; popFrame(); } static N_INLINE(NIM_BOOL*, nimErrorFlag)(void) { NIM_BOOL* result; result = (NIM_BOOL*)0; result = (&nimInErrorMode__system_u4389); return result; } 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) { #if 0 void (*volatile inner)(void); inner = PreMainInner; atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminus2dot0dot0atslibatssystemdotnim_Init000(); (*inner)(); #else atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminus2dot0dot0atslibatssystemdotnim_Init000(); PreMainInner(); #endif } N_LIB_PRIVATE N_CDECL(void, NimMainInner)(void) { NimMainModule(); } N_CDECL(void, NimMain)(void) { #if 0 void (*volatile inner)(void); PreMain(); inner = NimMainInner; (*inner)(); #else PreMain(); NimMainInner(); #endif } 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) { { NimStringV2 colontmpD_; tyArray__nHXaesL0DJZHyVS07ARPRA T2_; NIM_BOOL* nimErr_; nimfr_("temp", "/home/runner/work/Nim/Nim/temp.nim"); nimErr_ = nimErrorFlag(); colontmpD_.len = 0; colontmpD_.p = NIM_NIL; plusplus___temp_u1((&a__temp_u8)); if (NIM_UNLIKELY(*nimErr_)) goto LA1_; colontmpD_ = dollar___systemZdollars_u8(((NI) (a__temp_u8))); if (NIM_UNLIKELY(*nimErr_)) goto LA1_; T2_[0] = colontmpD_; echoBinSafe(T2_, 1); { LA1_:; } { if (colontmpD_.p && !(colontmpD_.p->cap & NIM_STRLIT_FLAG)) { deallocShared(colontmpD_.p); } } if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_; BeforeRet_: ; nimTestErrorFlag(); popFrame(); } } ```

Stats

  • Started 2024-08-29T22:17:07
  • Finished 2024-08-29T22:17:07
  • Duration
1.6.20 :+1: OK

Output

``` ```

IR

Compiled filesize 96.01 Kb (98,312 bytes) ```cpp #include "nimbase.h" #include # 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; typedef struct NimStringDesc NimStringDesc; typedef struct TGenericSeq TGenericSeq; struct TGenericSeq { NI len; NI reserved; }; struct NimStringDesc { TGenericSeq Sup; NIM_CHAR data[SEQ_DECL_SIZE]; }; typedef NimStringDesc* tyArray__nHXaesL0DJZHyVS07ARPRA[1]; N_LIB_PRIVATE N_NIMCALL(void, plusplus___temp_u1)(NI* n); N_LIB_PRIVATE N_NOINLINE(void, raiseOverflow)(void); static N_INLINE(void, nimFrame)(TFrame* s); N_LIB_PRIVATE N_NOINLINE(void, callDepthLimitReached__system_u2997)(void); static N_INLINE(void, popFrame)(void); static N_INLINE(void, nimZeroMem)(void* p, NI size); static N_INLINE(void, nimSetMem__systemZmemory_u7)(void* a, int v, NI size); N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, dollar___systemZdollars_u3)(NI x); N_LIB_PRIVATE N_NIMCALL(void, echoBinSafe)(NimStringDesc** args, NI argsLen_0); static N_INLINE(void, initStackBottomWith)(void* locals); N_LIB_PRIVATE N_NOINLINE(void, nimGC_setStackBottom)(void* theStackBottom); N_LIB_PRIVATE N_NIMCALL(void, atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminus1dot6dot20atslibatssystemdotnim_DatInit000)(void); N_LIB_PRIVATE N_NIMCALL(void, atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminus1dot6dot20atslibatssystemdotnim_Init000)(void); N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void); N_LIB_PRIVATE NI a__temp_u8 = ((NI) 15); extern TFrame* framePtr__system_u2564; static N_INLINE(void, nimFrame)(TFrame* s) { { if (!(framePtr__system_u2564 == ((TFrame*) NIM_NIL))) goto LA3_; (*s).calldepth = ((NI16) 0); } goto LA1_; LA3_: ; { (*s).calldepth = (NI16)((*framePtr__system_u2564).calldepth + ((NI16) 1)); } LA1_: ; (*s).prev = framePtr__system_u2564; framePtr__system_u2564 = s; { if (!((*s).calldepth == ((NI16) 2000))) goto LA8_; callDepthLimitReached__system_u2997(); } LA8_: ; } static N_INLINE(void, popFrame)(void) { framePtr__system_u2564 = (*framePtr__system_u2564).prev; } N_LIB_PRIVATE N_NIMCALL(void, plusplus___temp_u1)(NI* n) { NI TM__SRd76hP9cMfCzdUO857UhQQ_2; nimfr_("++", "/home/runner/work/Nim/Nim/temp.nim"); if (nimAddInt((*n), ((NI) 1), &TM__SRd76hP9cMfCzdUO857UhQQ_2)) { raiseOverflow(); }; (*n) = (NI)(TM__SRd76hP9cMfCzdUO857UhQQ_2); popFrame(); } static N_INLINE(void, nimSetMem__systemZmemory_u7)(void* a, int v, NI size) { void* T1_; T1_ = (void*)0; T1_ = memset(a, v, ((size_t) (size))); } static N_INLINE(void, nimZeroMem)(void* p, NI size) { nimSetMem__systemZmemory_u7(p, ((int) 0), size); } static N_INLINE(void, initStackBottomWith)(void* locals) { nimGC_setStackBottom(locals); } 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; atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminus1dot6dot20atslibatssystemdotnim_DatInit000(); initStackBottomWith((void *)&inner); atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminus1dot6dot20atslibatssystemdotnim_Init000(); (*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) { { tyArray__nHXaesL0DJZHyVS07ARPRA T1_; nimfr_("temp", "/home/runner/work/Nim/Nim/temp.nim"); plusplus___temp_u1((&a__temp_u8)); nimZeroMem((void*)T1_, sizeof(tyArray__nHXaesL0DJZHyVS07ARPRA)); T1_[0] = dollar___systemZdollars_u3(((NI) (a__temp_u8))); echoBinSafe(T1_, 1); popFrame(); } } ```

Stats

  • Started 2024-08-29T22:17:10
  • Finished 2024-08-29T22:17:10
  • Duration
1.4.8 :+1: OK

Output

``` ```

IR

Compiled filesize 92.11 Kb (94,320 bytes) ```cpp #include "nimbase.h" #include # 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; typedef struct NimStringDesc NimStringDesc; typedef struct TGenericSeq TGenericSeq; struct TGenericSeq { NI len; NI reserved; }; struct NimStringDesc { TGenericSeq Sup; NIM_CHAR data[SEQ_DECL_SIZE]; }; typedef NimStringDesc* tyArray__nHXaesL0DJZHyVS07ARPRA[1]; N_LIB_PRIVATE N_NIMCALL(void, plusplus___WvgUV39bhG3GFEhZq0jAG3A)(NI* n); N_LIB_PRIVATE N_NOINLINE(void, raiseOverflow)(void); static N_INLINE(void, nimFrame)(TFrame* s); N_LIB_PRIVATE N_NOINLINE(void, callDepthLimitReached__mMRdr4sgmnykA9aWeM9aDZlw)(void); static N_INLINE(void, popFrame)(void); static N_INLINE(void, nimZeroMem)(void* p, NI size); static N_INLINE(void, nimSetMem__zxfKBYntu9cBapkhrCOk1fgmemory)(void* a, int v, NI size); N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, nimIntToStr)(NI x); N_LIB_PRIVATE N_NIMCALL(void, echoBinSafe)(NimStringDesc** args, NI argsLen_0); static N_INLINE(void, initStackBottomWith)(void* locals); N_LIB_PRIVATE N_NOINLINE(void, nimGC_setStackBottom)(void* theStackBottom); 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 a__pmzNoNHAcaDPxnGmV0hjXA = ((NI) 15); extern TFrame* framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw; extern TFrame* framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw; extern TFrame* framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw; extern TFrame* framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw; extern TFrame* framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw; extern TFrame* framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw; static N_INLINE(void, nimFrame)(TFrame* s) { { if (!(framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw == ((TFrame*) NIM_NIL))) goto LA3_; (*s).calldepth = ((NI16) 0); } goto LA1_; LA3_: ; { (*s).calldepth = (NI16)((*framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw).calldepth + ((NI16) 1)); } LA1_: ; (*s).prev = framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw; framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw = s; { if (!((*s).calldepth == ((NI16) 2000))) goto LA8_; callDepthLimitReached__mMRdr4sgmnykA9aWeM9aDZlw(); } LA8_: ; } static N_INLINE(void, popFrame)(void) { framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw = (*framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw).prev; } N_LIB_PRIVATE N_NIMCALL(void, plusplus___WvgUV39bhG3GFEhZq0jAG3A)(NI* n) { NI TM__SRd76hP9cMfCzdUO857UhQQ_2; nimfr_("++", "/home/runner/work/Nim/Nim/temp.nim"); if (nimAddInt((*n), ((NI) 1), &TM__SRd76hP9cMfCzdUO857UhQQ_2)) { raiseOverflow(); }; (*n) = (NI)(TM__SRd76hP9cMfCzdUO857UhQQ_2); popFrame(); } static N_INLINE(void, nimSetMem__zxfKBYntu9cBapkhrCOk1fgmemory)(void* a, int v, NI size) { void* T1_; T1_ = (void*)0; T1_ = memset(a, v, ((size_t) (size))); } static N_INLINE(void, nimZeroMem)(void* p, NI size) { nimSetMem__zxfKBYntu9cBapkhrCOk1fgmemory(p, ((int) 0), size); } static N_INLINE(void, initStackBottomWith)(void* locals) { nimGC_setStackBottom(locals); } 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) { { tyArray__nHXaesL0DJZHyVS07ARPRA T1_; nimfr_("temp", "/home/runner/work/Nim/Nim/temp.nim"); plusplus___WvgUV39bhG3GFEhZq0jAG3A((&a__pmzNoNHAcaDPxnGmV0hjXA)); nimZeroMem((void*)T1_, sizeof(tyArray__nHXaesL0DJZHyVS07ARPRA)); T1_[0] = nimIntToStr(((NI) (a__pmzNoNHAcaDPxnGmV0hjXA))); echoBinSafe(T1_, 1); popFrame(); } } ```

Stats

  • Started 2024-08-29T22:17:12
  • Finished 2024-08-29T22:17:13
  • Duration
1.2.18 :+1: OK

Output

``` ```

IR

Compiled filesize 91.84 Kb (94,040 bytes) ```cpp #include "nimbase.h" #include # 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; typedef struct NimStringDesc NimStringDesc; typedef struct TGenericSeq TGenericSeq; struct TGenericSeq { NI len; NI reserved; }; struct NimStringDesc { TGenericSeq Sup; NIM_CHAR data[SEQ_DECL_SIZE]; }; typedef NimStringDesc* tyArray__nHXaesL0DJZHyVS07ARPRA[1]; N_LIB_PRIVATE N_NIMCALL(void, plusplus___WvgUV39bhG3GFEhZq0jAG3A)(NI* n); N_LIB_PRIVATE N_NOINLINE(void, raiseOverflow)(void); static N_INLINE(void, nimFrame)(TFrame* s); N_LIB_PRIVATE N_NOINLINE(void, callDepthLimitReached__mMRdr4sgmnykA9aWeM9aDZlw)(void); static N_INLINE(void, popFrame)(void); static N_INLINE(void, nimZeroMem)(void* p, NI size); static N_INLINE(void, nimSetMem__zxfKBYntu9cBapkhrCOk1fgmemory)(void* a, int v, NI size); N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, nimIntToStr)(NI x); N_LIB_PRIVATE N_NIMCALL(void, echoBinSafe)(NimStringDesc** args, NI argsLen_0); static N_INLINE(void, initStackBottomWith)(void* locals); N_LIB_PRIVATE N_NOINLINE(void, nimGC_setStackBottom)(void* theStackBottom); 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 a__pmzNoNHAcaDPxnGmV0hjXA = ((NI) 15); extern TFrame* framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw; extern TFrame* framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw; extern TFrame* framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw; extern TFrame* framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw; extern TFrame* framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw; extern TFrame* framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw; static N_INLINE(void, nimFrame)(TFrame* s) { { if (!(framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw == NIM_NIL)) goto LA3_; (*s).calldepth = ((NI16) 0); } goto LA1_; LA3_: ; { (*s).calldepth = (NI16)((*framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw).calldepth + ((NI16) 1)); } LA1_: ; (*s).prev = framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw; framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw = s; { if (!((*s).calldepth == ((NI16) (((NI) 2000))))) goto LA8_; callDepthLimitReached__mMRdr4sgmnykA9aWeM9aDZlw(); } LA8_: ; } static N_INLINE(void, popFrame)(void) { framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw = (*framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw).prev; } N_LIB_PRIVATE N_NIMCALL(void, plusplus___WvgUV39bhG3GFEhZq0jAG3A)(NI* n) { NI TM__SRd76hP9cMfCzdUO857UhQQ_2; nimfr_("++", "/home/runner/work/Nim/Nim/temp.nim"); if (nimAddInt((*n), ((NI) 1), &TM__SRd76hP9cMfCzdUO857UhQQ_2)) { raiseOverflow(); }; (*n) = (NI)(TM__SRd76hP9cMfCzdUO857UhQQ_2); popFrame(); } static N_INLINE(void, nimSetMem__zxfKBYntu9cBapkhrCOk1fgmemory)(void* a, int v, NI size) { void* T1_; T1_ = (void*)0; T1_ = memset(a, v, ((size_t) (size))); } static N_INLINE(void, nimZeroMem)(void* p, NI size) { nimSetMem__zxfKBYntu9cBapkhrCOk1fgmemory(p, ((int) 0), size); } static N_INLINE(void, initStackBottomWith)(void* locals) { nimGC_setStackBottom(locals); } 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) { { tyArray__nHXaesL0DJZHyVS07ARPRA T1_; nimfr_("temp", "/home/runner/work/Nim/Nim/temp.nim"); plusplus___WvgUV39bhG3GFEhZq0jAG3A((&a__pmzNoNHAcaDPxnGmV0hjXA)); nimZeroMem((void*)T1_, sizeof(tyArray__nHXaesL0DJZHyVS07ARPRA)); T1_[0] = nimIntToStr(((NI) (a__pmzNoNHAcaDPxnGmV0hjXA))); echoBinSafe(T1_, 1); popFrame(); } } ```

Stats

  • Started 2024-08-29T22:17:15
  • Finished 2024-08-29T22:17:15
  • Duration
1.0.10 :+1: OK

Output

``` ```

IR

Compiled filesize 86.98 Kb (89,064 bytes) ```cpp #include "nimbase.h" #include # 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; typedef struct NimStringDesc NimStringDesc; typedef struct TGenericSeq TGenericSeq; struct TGenericSeq { NI len; NI reserved; }; struct NimStringDesc { TGenericSeq Sup; NIM_CHAR data[SEQ_DECL_SIZE]; }; typedef NimStringDesc* tyArray__nHXaesL0DJZHyVS07ARPRA[1]; N_LIB_PRIVATE N_NIMCALL(void, plusplus___WvgUV39bhG3GFEhZq0jAG3A)(NI* n); static N_INLINE(NI, addInt)(NI a, NI b); N_NOINLINE(void, raiseOverflow)(void); static N_INLINE(void, nimFrame)(TFrame* s); N_LIB_PRIVATE N_NOINLINE(void, callDepthLimitReached__mMRdr4sgmnykA9aWeM9aDZlw)(void); static N_INLINE(void, popFrame)(void); static N_INLINE(void, nimZeroMem)(void* p, NI size); static N_INLINE(void, nimSetMem__zxfKBYntu9cBapkhrCOk1fgmemory)(void* a, int v, NI size); N_NIMCALL(NimStringDesc*, nimIntToStr)(NI x); N_NIMCALL(void, echoBinSafe)(NimStringDesc** args, NI argsLen_0); static N_INLINE(void, initStackBottomWith)(void* locals); N_NOINLINE(void, nimGC_setStackBottom)(void* theStackBottom); N_LIB_PRIVATE N_NIMCALL(void, systemDatInit000)(void); N_LIB_PRIVATE N_NIMCALL(void, systemInit000)(void); N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void); NI a__pmzNoNHAcaDPxnGmV0hjXA; extern TFrame* framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw; extern TFrame* framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw; extern TFrame* framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw; extern TFrame* framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw; extern TFrame* framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw; extern TFrame* framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw; static N_INLINE(NI, addInt)(NI a, NI b) { NI result; { result = (NI)0; result = (NI)((NU64)(a) + (NU64)(b)); { NIM_BOOL T3_; T3_ = (NIM_BOOL)0; T3_ = (((NI) 0) <= (NI)(result ^ a)); if (T3_) goto LA4_; T3_ = (((NI) 0) <= (NI)(result ^ b)); LA4_: ; if (!T3_) goto LA5_; goto BeforeRet_; } LA5_: ; raiseOverflow(); }BeforeRet_: ; return result; } static N_INLINE(void, nimFrame)(TFrame* s) { NI T1_; T1_ = (NI)0; { if (!(framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw == NIM_NIL)) goto LA4_; T1_ = ((NI) 0); } goto LA2_; LA4_: ; { T1_ = ((NI) ((NI16)((*framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw).calldepth + ((NI16) 1)))); } LA2_: ; (*s).calldepth = ((NI16) (T1_)); (*s).prev = framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw; framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw = s; { if (!((*s).calldepth == ((NI16) (((NI) 2000))))) goto LA9_; callDepthLimitReached__mMRdr4sgmnykA9aWeM9aDZlw(); } LA9_: ; } static N_INLINE(void, popFrame)(void) { framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw = (*framePtr__HRfVMH3jYeBJz6Q6X9b6Ptw).prev; } N_LIB_PRIVATE N_NIMCALL(void, plusplus___WvgUV39bhG3GFEhZq0jAG3A)(NI* n) { NI TM__SRd76hP9cMfCzdUO857UhQQ_2; nimfr_("++", "/home/runner/work/Nim/Nim/temp.nim"); TM__SRd76hP9cMfCzdUO857UhQQ_2 = addInt((*n), ((NI) 1)); (*n) = (NI)(TM__SRd76hP9cMfCzdUO857UhQQ_2); popFrame(); } static N_INLINE(void, nimSetMem__zxfKBYntu9cBapkhrCOk1fgmemory)(void* a, int v, NI size) { void* T1_; T1_ = (void*)0; T1_ = memset(a, v, ((size_t) (size))); } static N_INLINE(void, nimZeroMem)(void* p, NI size) { nimSetMem__zxfKBYntu9cBapkhrCOk1fgmemory(p, ((int) 0), size); } static N_INLINE(void, initStackBottomWith)(void* locals) { nimGC_setStackBottom(locals); } void PreMainInner(void) { } int cmdCount; char** cmdLine; char** gEnv; void PreMain(void) { void (*volatile inner)(void); inner = PreMainInner; systemDatInit000(); initStackBottomWith((void *)&inner); systemInit000(); (*inner)(); } 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) { { tyArray__nHXaesL0DJZHyVS07ARPRA T1_; nimfr_("temp", "/home/runner/work/Nim/Nim/temp.nim"); a__pmzNoNHAcaDPxnGmV0hjXA = ((NI) 15); plusplus___WvgUV39bhG3GFEhZq0jAG3A((&a__pmzNoNHAcaDPxnGmV0hjXA)); nimZeroMem((void*)T1_, sizeof(tyArray__nHXaesL0DJZHyVS07ARPRA)); T1_[0] = nimIntToStr(((NI) (a__pmzNoNHAcaDPxnGmV0hjXA))); echoBinSafe(T1_, 1); popFrame(); } } ```

Stats

  • Started 2024-08-29T22:17:16
  • Finished 2024-08-29T22:17:17
  • Duration
Stats
  • GCC 11.4.0
  • Clang 14.0.0
  • NodeJS 20.4
  • Created 2024-08-29T22:16:30Z
  • 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 21 mins bisecting 8 commits at 0 commits per second

beef331 commented 2 months ago

The issue is that range implicitly converted to var int as such it loses range checking. A work around is to use

proc `++`[T: range | SomeInteger](n: var T) =
    n = n + 1

type
    r = range[ 0..15 ]

var a: r = 15

++a

echo a
juancarlospaco commented 2 months ago

That should be in the documentation.

Araq commented 2 months ago

range int should not convert to var int.

metagn commented 2 months ago

Seems like a typo in the compiler

https://github.com/nim-lang/Nim/blob/aa0d8e9cfee7b15f80bd147b9bcf626012abb093/compiler/sigmatch.nim#L1020

subtypeCheck is only called for pointer types, but it also checks if the element type of the pointer type (f.last) is a pointer type which I don't think is intentional

I know changing this breaks a package though (from #23176) so we need to at least give a error message that suggests doing ++int(a) instead ("explicit conversion needed" etc), but also we can only do this for isSubrange

metagn commented 2 months ago

Actually some subtype relations for var are allowed, like openarray and non-ref object subtypes:

type
  Foo = object of RootObj
  Bar = object of Foo

proc foo(x: var Foo) = echo "a"
var x: Bar
foo(x) # a

This is intentional: https://github.com/nim-lang/Nim/commit/f348671ba7146420e1bfc7cd21ddc5464f0b9cb3

But still isIntConv etc should fail. So I'm guessing only subtypes should be special cased to have this behavior.

Edit: Never mind the openarray relation is isConvertible. But still valid so just another special case.

Also ++int(a) doesn't work

Araq commented 2 months ago

yes, it means "isSubrange" is a different type relation from "isSubtype". (I wasn't aware of this until now :-) )