From 0b1650576c6102ce85b4b2c0788b3a5b77154e43 Mon Sep 17 00:00:00 2001 From: metagn Date: Sat, 1 Oct 2022 23:35:09 +0300 Subject: [PATCH 1/2] move widestrs out of system (#20462) * move widestrs out of system * fix osproc --- changelog.md | 1 + lib/pure/asyncfile.nim | 2 ++ lib/pure/browsers.nim | 2 ++ lib/pure/includes/osenv.nim | 2 ++ lib/pure/includes/oserr.nim | 2 ++ lib/pure/memfiles.nim | 2 ++ lib/pure/os.nim | 3 +++ lib/pure/osproc.nim | 2 ++ lib/std/envvars.nim | 2 ++ lib/std/oserrors.nim | 2 ++ lib/std/private/win_setenv.nim | 3 +++ lib/std/syncio.nim | 2 ++ lib/std/tempfiles.nim | 2 ++ lib/{system => std}/widestrs.nim | 3 +-- lib/system.nim | 5 +++-- lib/system_overview.rst | 1 - lib/windows/registry.nim | 3 +++ lib/windows/winlean.nim | 1 + lib/wrappers/odbcsql.nim | 3 +++ tests/arc/t19862.nim | 2 ++ tests/ccgbugs/tcgbug.nim | 1 + tests/effects/tstrict_funcs_imports.nim | 9 +++++++++ tests/js/tstdlib_imports.nim | 5 +++++ tests/stdlib/t15663.nim | 4 +++- tests/stdlib/tenvvars.nim | 1 + tests/stdlib/tosenv.nim | 1 + tests/stdlib/twchartoutf8.nim | 1 + tests/test_nimscript.nims | 4 +++- tools/kochdocs.nim | 1 - 29 files changed, 64 insertions(+), 8 deletions(-) rename lib/{system => std}/widestrs.nim (98%) diff --git a/changelog.md b/changelog.md index 70ebbac097..840a19b51b 100644 --- a/changelog.md +++ b/changelog.md @@ -14,6 +14,7 @@ - `std/assertions` - `std/formatfloat` - `std/objectdollar` + - `std/widestrs` In the future, these definitions will be removed from the `system` module, and their respective modules will have to be imported to use them. diff --git a/lib/pure/asyncfile.nim b/lib/pure/asyncfile.nim index 9cc9f5b489..217dca6d94 100644 --- a/lib/pure/asyncfile.nim +++ b/lib/pure/asyncfile.nim @@ -26,6 +26,8 @@ import asyncdispatch, os when defined(nimPreviewSlimSystem): import std/[assertions, syncio] + when defined(windows): + import std/widestrs # TODO: Fix duplication introduced by PR #4683. diff --git a/lib/pure/browsers.nim b/lib/pure/browsers.nim index c36e31b118..b95b37a1d1 100644 --- a/lib/pure/browsers.nim +++ b/lib/pure/browsers.nim @@ -21,6 +21,8 @@ when defined(nimPreviewSlimSystem): when defined(windows): import winlean + when useWinUnicode and defined(nimPreviewSlimSystem): + import std/widestrs from os import absolutePath else: import os diff --git a/lib/pure/includes/osenv.nim b/lib/pure/includes/osenv.nim index b7200a8e2a..a1d906519f 100644 --- a/lib/pure/includes/osenv.nim +++ b/lib/pure/includes/osenv.nim @@ -43,6 +43,8 @@ when not defined(nimscript): else: when defined(windows): + when defined(nimPreviewSlimSystem): + import std/widestrs proc c_putenv(envstring: cstring): cint {.importc: "_putenv", header: "".} from std/private/win_setenv import setEnvImpl proc c_wgetenv(varname: WideCString): WideCString {.importc: "_wgetenv", diff --git a/lib/pure/includes/oserr.nim b/lib/pure/includes/oserr.nim index a6eba84ba1..c58fdb22c4 100644 --- a/lib/pure/includes/oserr.nim +++ b/lib/pure/includes/oserr.nim @@ -11,6 +11,8 @@ when not defined(nimscript): when defined(windows): import winlean + when useWinUnicode and defined(nimPreviewSlimSystem): + import std/widestrs proc `==`*(err1, err2: OSErrorCode): bool {.borrow.} proc `$`*(err: OSErrorCode): string {.borrow.} diff --git a/lib/pure/memfiles.nim b/lib/pure/memfiles.nim index a952933eda..d0877b311b 100644 --- a/lib/pure/memfiles.nim +++ b/lib/pure/memfiles.nim @@ -17,6 +17,8 @@ when defined(windows): import winlean + when useWinUnicode and defined(nimPreviewSlimSystem): + import std/widestrs elif defined(posix): import posix else: diff --git a/lib/pure/os.nim b/lib/pure/os.nim index a39fcaf469..b1292a648b 100644 --- a/lib/pure/os.nim +++ b/lib/pure/os.nim @@ -968,6 +968,9 @@ proc getCacheDir*(app: string): string = when defined(windows): type DWORD = uint32 + when defined(nimPreviewSlimSystem): + import std/widestrs + proc getTempPath( nBufferLength: DWORD, lpBuffer: WideCString ): DWORD {.stdcall, dynlib: "kernel32.dll", importc: "GetTempPathW".} = diff --git a/lib/pure/osproc.nim b/lib/pure/osproc.nim index a0079cf953..5e130b47a5 100644 --- a/lib/pure/osproc.nim +++ b/lib/pure/osproc.nim @@ -33,6 +33,8 @@ when defined(linux) and defined(useClone): when defined(nimPreviewSlimSystem): import std/[syncio, assertions] + when defined(windows): + import std/widestrs type diff --git a/lib/std/envvars.nim b/lib/std/envvars.nim index d7706c17d1..9748cd2ad2 100644 --- a/lib/std/envvars.nim +++ b/lib/std/envvars.nim @@ -61,6 +61,8 @@ when not defined(nimscript): proc c_putenv(envstring: cstring): cint {.importc: "_putenv", header: "".} from std/private/win_setenv import setEnvImpl import winlean + when defined(nimPreviewSlimSystem): + import std/widestrs proc c_wgetenv(varname: WideCString): WideCString {.importc: "_wgetenv", header: "".} proc getEnvImpl(env: cstring): WideCString = c_wgetenv(env.newWideCString) diff --git a/lib/std/oserrors.nim b/lib/std/oserrors.nim index 9c2649eab8..8d06c41dad 100644 --- a/lib/std/oserrors.nim +++ b/lib/std/oserrors.nim @@ -16,6 +16,8 @@ type when not defined(nimscript): when defined(windows): import winlean + when defined(nimPreviewSlimSystem): + import std/widestrs else: var errno {.importc, header: "".}: cint diff --git a/lib/std/private/win_setenv.nim b/lib/std/private/win_setenv.nim index 89bb0421fd..9315f3e7ec 100644 --- a/lib/std/private/win_setenv.nim +++ b/lib/std/private/win_setenv.nim @@ -23,6 +23,9 @@ check errno_t vs cint when not defined(windows): discard else: + when defined(nimPreviewSlimSystem): + import std/widestrs + type wchar_t {.importc: "wchar_t".} = int16 proc setEnvironmentVariableW*(lpName, lpValue: WideCString): int32 {. diff --git a/lib/std/syncio.nim b/lib/std/syncio.nim index fc132bba7d..dadad97918 100644 --- a/lib/std/syncio.nim +++ b/lib/std/syncio.nim @@ -12,6 +12,8 @@ include system/inclrtl import std/private/since import std/formatfloat +when defined(windows): + import std/widestrs # ----------------- IO Part ------------------------------------------------ type diff --git a/lib/std/tempfiles.nim b/lib/std/tempfiles.nim index ee42f8a5c9..1160aaaad5 100644 --- a/lib/std/tempfiles.nim +++ b/lib/std/tempfiles.nim @@ -30,6 +30,8 @@ const when defined(windows): import winlean + when defined(nimPreviewSlimSystem): + import std/widestrs var O_RDWR {.importc: "_O_RDWR", header: "".}: cint diff --git a/lib/system/widestrs.nim b/lib/std/widestrs.nim similarity index 98% rename from lib/system/widestrs.nim rename to lib/std/widestrs.nim index bb348fd677..7df4004d19 100644 --- a/lib/system/widestrs.nim +++ b/lib/std/widestrs.nim @@ -7,8 +7,7 @@ # distribution, for details about the copyright. # -# Nim support for C/C++'s `wide strings`:idx:. This is part of the system -# module! Do not import it directly! +# Nim support for C/C++'s `wide strings`:idx:. #when not declared(ThisIsSystem): # {.error: "You must not import this module explicitly".} diff --git a/lib/system.nim b/lib/system.nim index daee96c1c5..fd31cf3da3 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -2655,8 +2655,9 @@ when defined(genode): # and return to thread entrypoint. -import system/widestrs -export widestrs +when not defined(nimPreviewSlimSystem): + import std/widestrs + export widestrs when notJSnotNims: when defined(windows) and compileOption("threads"): diff --git a/lib/system_overview.rst b/lib/system_overview.rst index 1580693753..b338845d68 100644 --- a/lib/system_overview.rst +++ b/lib/system_overview.rst @@ -8,7 +8,6 @@ is in separate files: * `exceptions `_ * `assertions `_ * `dollars `_ -* `widestrs `_ * `ctypes `_ diff --git a/lib/windows/registry.nim b/lib/windows/registry.nim index 44e4e44208..6abc41a893 100644 --- a/lib/windows/registry.nim +++ b/lib/windows/registry.nim @@ -11,6 +11,9 @@ import winlean, os +when defined(nimPreviewSlimSystem): + import std/widestrs + type HKEY* = uint diff --git a/lib/windows/winlean.nim b/lib/windows/winlean.nim index 91b0d18c10..93ab3dd2eb 100644 --- a/lib/windows/winlean.nim +++ b/lib/windows/winlean.nim @@ -19,6 +19,7 @@ when defined(nimHasStyleChecks): when defined(nimPreviewSlimSystem): from std/syncio import FileHandle + import std/widestrs const useWinUnicode* = not defined(useWinAnsi) diff --git a/lib/wrappers/odbcsql.nim b/lib/wrappers/odbcsql.nim index 4e37e1a174..6b300c5ffe 100644 --- a/lib/wrappers/odbcsql.nim +++ b/lib/wrappers/odbcsql.nim @@ -7,6 +7,9 @@ # distribution, for details about the copyright. # +when defined(nimPreviewSlimSystem): + import std/widestrs + when not defined(ODBCVER): const ODBCVER = 0x0351 ## define ODBC version 3.51 by default diff --git a/tests/arc/t19862.nim b/tests/arc/t19862.nim index f7146ec268..6d3f576926 100644 --- a/tests/arc/t19862.nim +++ b/tests/arc/t19862.nim @@ -2,6 +2,8 @@ discard """ matrix: "--gc:refc; --gc:arc" """ +import std/widestrs + # bug #19862 type NewString = object diff --git a/tests/ccgbugs/tcgbug.nim b/tests/ccgbugs/tcgbug.nim index 0fe4b88525..14ed390d40 100644 --- a/tests/ccgbugs/tcgbug.nim +++ b/tests/ccgbugs/tcgbug.nim @@ -24,6 +24,7 @@ q(a) # bug #914 when defined(windows): + import std/widestrs var x = newWideCString("Hello") echo "success" diff --git a/tests/effects/tstrict_funcs_imports.nim b/tests/effects/tstrict_funcs_imports.nim index 264771a1ad..eb83bb69b4 100644 --- a/tests/effects/tstrict_funcs_imports.nim +++ b/tests/effects/tstrict_funcs_imports.nim @@ -7,6 +7,15 @@ discard """ when defined(linux): import linenoise +when defined(nimPreviewSlimSystem): + import std/[ + assertions, + formatfloat, + objectdollar, + syncio, + widestrs, + ] + import algorithm, asyncdispatch, diff --git a/tests/js/tstdlib_imports.nim b/tests/js/tstdlib_imports.nim index 30aca75613..ed01ff6a41 100644 --- a/tests/js/tstdlib_imports.nim +++ b/tests/js/tstdlib_imports.nim @@ -4,6 +4,11 @@ discard """ {.warning[UnusedImport]: off.} +when defined(nimPreviewSlimSystem): + import std/[ + syncio, assertions, formatfloat, objectdollar, widestrs + ] + import std/[ # Core: bitops, typetraits, lenientops, macros, volatile, typeinfo, diff --git a/tests/stdlib/t15663.nim b/tests/stdlib/t15663.nim index 1ad5677fdf..8e8bfd9a82 100644 --- a/tests/stdlib/t15663.nim +++ b/tests/stdlib/t15663.nim @@ -3,5 +3,7 @@ discard """ output: "Test" """ +import std/widestrs + let ws = newWideCString("Test") -echo ws \ No newline at end of file +echo ws diff --git a/tests/stdlib/tenvvars.nim b/tests/stdlib/tenvvars.nim index 47c1ad24ab..2d084f71d8 100644 --- a/tests/stdlib/tenvvars.nim +++ b/tests/stdlib/tenvvars.nim @@ -49,6 +49,7 @@ template main = main() when defined(windows): + import std/widestrs proc c_wgetenv(env: WideCString): WideCString {.importc: "_wgetenv", header: "".} proc c_getenv(env: cstring): cstring {.importc: "getenv", header: "".} diff --git a/tests/stdlib/tosenv.nim b/tests/stdlib/tosenv.nim index f7b3bb9d60..365edc8c2f 100644 --- a/tests/stdlib/tosenv.nim +++ b/tests/stdlib/tosenv.nim @@ -50,6 +50,7 @@ static: main() main() when defined(windows): + import std/widestrs proc c_wgetenv(env: WideCString): WideCString {.importc: "_wgetenv", header: "".} proc c_getenv(env: cstring): cstring {.importc: "getenv", header: "".} diff --git a/tests/stdlib/twchartoutf8.nim b/tests/stdlib/twchartoutf8.nim index add104b07d..0b6cf696ea 100644 --- a/tests/stdlib/twchartoutf8.nim +++ b/tests/stdlib/twchartoutf8.nim @@ -10,6 +10,7 @@ import std/[syncio, assertions] when not defined(windows): echo "OK" else: + import std/widestrs {.push gcsafe.} const CP_UTF8 = 65001'i32 diff --git a/tests/test_nimscript.nims b/tests/test_nimscript.nims index 5fc77f6e4b..a68e00fe17 100644 --- a/tests/test_nimscript.nims +++ b/tests/test_nimscript.nims @@ -6,7 +6,9 @@ from stdtest/specialpaths import buildDir when defined(nimPreviewSlimSystem): - import std/syncio + import std/[ + syncio, assertions, formatfloat, objectdollar, widestrs + ] import std/[ # Core: diff --git a/tools/kochdocs.nim b/tools/kochdocs.nim index 18659825b8..ee9c29499b 100644 --- a/tools/kochdocs.nim +++ b/tools/kochdocs.nim @@ -197,7 +197,6 @@ lib/system/assertions.nim lib/system/iterators.nim lib/system/exceptions.nim lib/system/dollars.nim -lib/system/widestrs.nim lib/system/ctypes.nim """.splitWhitespace() From 567c3f055ded0d81d15d6d5bc18377ca8c607c6d Mon Sep 17 00:00:00 2001 From: Bung Date: Sun, 2 Oct 2022 05:19:07 +0800 Subject: [PATCH 2/2] Fix #19224 For loops over a hardcoded empty array crash the compiler (#20476) * Fix #11684 For loops over a hardcoded empty array crash the compiler * Update t19224.nim --- compiler/semstmts.nim | 3 +++ tests/errmsgs/t19224.nim | 12 ++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 tests/errmsgs/t19224.nim diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 4f01f508e1..270086e66e 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -853,6 +853,9 @@ proc semForVars(c: PContext, n: PNode; flags: TExprFlags): PNode = var iterAfterVarLent = iter.skipTypes({tyGenericInst, tyAlias, tyLent, tyVar}) # n.len == 3 means that there is one for loop variable # and thus no tuple unpacking: + if iterAfterVarLent.kind == tyEmpty: + localError(c.config, n[^2].info, "cannot infer element type of $1" % + renderTree(n[^2], {renderNoComments})) if iterAfterVarLent.kind != tyTuple or n.len == 3: if n.len == 3: if n[0].kind == nkVarTuple: diff --git a/tests/errmsgs/t19224.nim b/tests/errmsgs/t19224.nim new file mode 100644 index 0000000000..7a9ecb2e70 --- /dev/null +++ b/tests/errmsgs/t19224.nim @@ -0,0 +1,12 @@ +discard """ +cmd: "nim check --hints:off $file" +errormsg: "" +nimout: ''' +t19224.nim(10, 10) Error: cannot infer element type of items([]) +t19224.nim(12, 10) Error: cannot infer element type of items(@[]) +''' +""" + +for _ in []: discard + +for _ in @[]: discard