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

`create Lock` error, importc regression #22344

Closed Gruruya closed 1 year ago

Gruruya commented 1 year ago

Description

Regression found on easy_sqlite, exclusively errors on 1.6.14 and 1.6.15, not 1.6.12 or devel.

Minimal repro:

import locks
var a = create Lock

sizeof(Lock) does compile however.

Nim Version

1.6.14-1.6.15

Current Output

/reproduce.nim(2, 16) template/generic instantiation of `create` from here
/lib/system/memalloc.nim(148, 18) Error: 'sizeof' requires '.importc' types to be '.completeStruct'

Expected Output

/reproduce.nim(2, 5) Hint: 'a' is declared but not used [XDeclaredButNotUsed]

Possible Solution

No response

Additional Information

No response

ringabout commented 1 year ago

!nim c

import locks
var a = create Lock
github-actions[bot] commented 1 year ago

@ringabout (member)

devel :+1: OK

Output

Stats

  • Created 2023-07-29T05:19:07Z
  • Started 2023-07-29T05:19:43
  • Finished 2023-07-29T05:19:43
  • Duration 1 minute
  • Commands nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
stable :-1: FAIL

Output

Error: Command failed: nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings: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(2, 16) template/generic instantiation of `create` from here
/home/runner/.choosenim/toolchains/nim-1.6.14/lib/system/memalloc.nim(148, 18) Error: 'sizeof' requires '.importc' types to be '.completeStruct'

Stats

  • Created 2023-07-29T05:19:07Z
  • Started 2023-07-29T05:19:44
  • Finished 2023-07-29T05:19:44
  • Duration now
  • Commands nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim

IR

Filesize 74.48 Kb ```cpp #define NIM_INTBITS 64 #include "nimbase.h" #include #include #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) \ FR_.line = n; #define nimlf_(n, file) \ FR_.line = n; FR_.filename = file; typedef long tyArray__B71stzPvuTXMbmiYmn9brGQ[5]; static N_INLINE(pthread_mutex_t*, create__temp_u2)(NI size_p1); N_LIB_PRIVATE N_NOCONV(void*, alloc0Impl__system_u1759)(NI size_p0); N_LIB_PRIVATE N_NOINLINE(void, raiseOverflow)(void); N_LIB_PRIVATE N_NOINLINE(void, raiseRangeErrorI)(NI64 i_p0, NI64 a_p1, NI64 b_p2); N_LIB_PRIVATE N_NIMCALL(void, nimTestErrorFlag)(void); static N_INLINE(void, nimFrame)(TFrame* s_p0); N_LIB_PRIVATE N_NOINLINE(void, callDepthLimitReached__system_u4606)(void); static N_INLINE(void, popFrame)(void); N_LIB_PRIVATE N_NIMCALL(void, atmdotdotatsdotdotatsdotdotatsdotchoosenimatstoolchainsatsnimminusathdevelatslibatssystemdotnim_Init000)(void); N_LIB_PRIVATE N_NIMCALL(void, NimMainModule)(void); N_LIB_PRIVATE pthread_mutex_t* a__temp_u29; extern NIM_THREADVAR TFrame* framePtr__system_u4005; static N_INLINE(pthread_mutex_t*, create__temp_u2)(NI size_p1) { pthread_mutex_t* result; NI TM__SRd76hP9cMfCzdUO857UhQQ_2; void* T1_; { result = (pthread_mutex_t*)0; if (nimMulInt(((NI)sizeof(pthread_mutex_t)), ((NI) (size_p1)), &TM__SRd76hP9cMfCzdUO857UhQQ_2)) { raiseOverflow(); goto BeforeRet_; }; if (((NI)(TM__SRd76hP9cMfCzdUO857UhQQ_2)) < ((NI)0) || ((NI)(TM__SRd76hP9cMfCzdUO857UhQQ_2)) > ((NI)IL64(9223372036854775807))){ raiseRangeErrorI((NI)(TM__SRd76hP9cMfCzdUO857UhQQ_2), ((NI)0), ((NI)IL64(9223372036854775807))); goto BeforeRet_; } T1_ = (void*)0; T1_ = alloc0Impl__system_u1759(((NI) ((NI)(TM__SRd76hP9cMfCzdUO857UhQQ_2)))); result = ((pthread_mutex_t*) (T1_)); }BeforeRet_: ; return result; } static N_INLINE(void, nimFrame)(TFrame* s_p0) { { if (!(framePtr__system_u4005 == ((TFrame*) NIM_NIL))) goto LA3_; (*s_p0).calldepth = ((NI16)0); } goto LA1_; LA3_: ; { (*s_p0).calldepth = (NI16)((*framePtr__system_u4005).calldepth + ((NI16)1)); } LA1_: ; (*s_p0).prev = framePtr__system_u4005; framePtr__system_u4005 = s_p0; { if (!((*s_p0).calldepth == ((NI16)2000))) goto LA8_; callDepthLimitReached__system_u4606(); } LA8_: ; } static N_INLINE(void, popFrame)(void) { framePtr__system_u4005 = (*framePtr__system_u4005).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) { #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) { { nimfr_("temp", "/home/runner/work/Nim/Nim/temp.nim"); a__temp_u29 = create__temp_u2(((NI)1)); nimTestErrorFlag(); popFrame(); } } ```

AST

```nim ```
1.6.0 :+1: OK

Output

``` ```

Stats

  • Created 2023-07-29T05:19:07Z
  • Started 2023-07-29T05:19:47
  • Finished 2023-07-29T05:19:48
  • Duration 1 minute
  • Commands nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
1.4.0 :+1: OK

Output

``` ```

Stats

  • Created 2023-07-29T05:19:07Z
  • Started 2023-07-29T05:19:50
  • Finished 2023-07-29T05:19:51
  • Duration 1 minute
  • Commands nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
1.2.0 :+1: OK

Output

``` ```

Stats

  • Created 2023-07-29T05:19:07Z
  • Started 2023-07-29T05:20:06
  • Finished 2023-07-29T05:20:06
  • Duration now
  • Commands nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
1.0.0 :+1: OK

Output

``` ```

Stats

  • Created 2023-07-29T05:19:07Z
  • Started 2023-07-29T05:20:20
  • Finished 2023-07-29T05:20:20
  • Duration now
  • Commands nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
0.20.2 :+1: OK

Output

``` ```

Stats

  • Created 2023-07-29T05:19:07Z
  • Started 2023-07-29T05:20:32
  • Finished 2023-07-29T05:20:32
  • Duration now
  • Commands nim c --run -d:strip -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
#26ed32e67 :arrow_right: :bug:

Diagnostics

andreas rumpf introduced a bug at 2021-10-30 10:14:23 +0200 on commit #26ed32e67 with message: ``` fixes #19000 (#19032) * fixes #19000 * progress (cherry picked from commit 2bda4a30a6b12dd0840dc347e454e54fe26721e7) ``` The bug is in the files: ``` lib/system/memalloc.nim ``` The bug can be in the commits: (Diagnostics sometimes off-by-one).
:robot: Bug found in 51 minutes bisecting 461 commits at 9 commits per second.
ringabout commented 1 year ago

!nim c --gc:arc

import locks
var a = create Lock
ringabout commented 1 year ago

https://github.com/nim-lang/Nim/pull/20518 needs to be backported