Showing with 1,339 additions and 877 deletions.
  1. +27 −0 changelog.md
  2. +0 −9 compiler.nimble
  3. +8 −0 compiler/ast.nim
  4. +3 −1 compiler/ccgcalls.nim
  5. +9 −2 compiler/ccgexprs.nim
  6. +14 −14 compiler/ccgtypes.nim
  7. +1 −1 compiler/cgen.nim
  8. +1 −0 compiler/condsyms.nim
  9. +3 −3 compiler/docgen.nim
  10. +2 −2 compiler/extccomp.nim
  11. +1 −1 compiler/injectdestructors.nim
  12. +1 −1 compiler/installer.ini
  13. +6 −5 compiler/jsgen.nim
  14. +6 −0 compiler/lexer.nim
  15. +2 −2 compiler/liftdestructors.nim
  16. +2 −0 compiler/lineinfos.nim
  17. +7 −0 compiler/msgs.nim
  18. +14 −0 compiler/nim.nim
  19. +14 −2 compiler/options.nim
  20. +80 −12 compiler/parser.nim
  21. +50 −1 compiler/pathutils.nim
  22. +5 −2 compiler/pragmas.nim
  23. +32 −23 compiler/semcall.nim
  24. +36 −4 compiler/semexprs.nim
  25. +3 −0 compiler/sempass2.nim
  26. +4 −1 compiler/semstmts.nim
  27. +2 −0 compiler/semtempl.nim
  28. +42 −42 compiler/sighashes.nim
  29. +2 −2 compiler/sizealignoffsetimpl.nim
  30. +11 −1 compiler/suggest.nim
  31. +12 −0 compiler/types.nim
  32. +16 −3 compiler/vm.nim
  33. +2 −1 compiler/vmdef.nim
  34. +13 −1 compiler/vmgen.nim
  35. +1 −1 copying.txt
  36. +7 −9 doc/manual.rst
  37. +2 −2 doc/tut2.rst
  38. +15 −0 lib/compilation.nim
  39. +27 −4 lib/core/macros.nim
  40. +18 −11 lib/impure/db_postgres.nim
  41. +36 −74 lib/js/dom.nim
  42. +3 −3 lib/packages/docutils/rst.nim
  43. +23 −3 lib/posix/posix.nim
  44. +2 −2 lib/pure/asynchttpserver.nim
  45. +1 −1 lib/pure/collections/deques.nim
  46. +2 −2 lib/pure/concurrency/atomics.nim
  47. +2 −2 lib/pure/htmlparser.nim
  48. +81 −42 lib/pure/memfiles.nim
  49. +3 −3 lib/pure/net.nim
  50. +65 −0 lib/pure/parseutils.nim
  51. +1 −1 lib/pure/unicode.nim
  52. +4 −17 lib/std/sysrand.nim
  53. +1 −15 lib/system.nim
  54. +2 −0 lib/system/assertions.nim
  55. +4 −3 lib/system/io.nim
  56. +3 −0 lib/wrappers/odbcsql.nim
  57. +2 −2 lib/wrappers/openssl.nim
  58. +15 −0 nim.nimble
  59. +151 −42 nimsuggest/nimsuggest.nim
  60. +10 −5 nimsuggest/tester.nim
  61. +0 −2 nimsuggest/tests/tgeneric_highlight.nim
  62. +0 −4 nimsuggest/tests/tv3.nim
  63. +45 −0 nimsuggest/tests/tv3_outline.nim
  64. +1 −1 readme.md
  65. +3 −3 testament/important_packages.nim
  66. +28 −0 tests/arc/topenarray.nim
  67. +4 −0 tests/ccgbugs/m1/defs.nim
  68. +4 −0 tests/ccgbugs/m2/defs.nim
  69. +10 −0 tests/ccgbugs/t20139.nim
  70. +19 −19 tests/concepts/texplain.nim
  71. +22 −1 tests/macros/tmacros_various.nim
  72. +22 −0 tests/macros/tprochelpers.nim
  73. +12 −0 tests/magics/t20938.nim
  74. +29 −0 tests/misc/tsizeof3.nim
  75. +1 −1 tests/nimdoc/trunnableexamples.nim
  76. +3 −0 tests/parser/tprocexprasstmt.nim
  77. +5 −0 tests/pragmas/tcompile_missing_file.nim
  78. +76 −0 tests/specialops/terrmsgs.nim
  79. +20 −0 tests/specialops/tnewseq.nim
  80. +6 −0 tests/stdlib/tdeques.nim
  81. +18 −0 tests/stdlib/tio.nim
  82. +3 −2 tests/stdlib/tmemfiles2.nim
  83. +39 −0 tests/stdlib/tparseutils.nim
  84. +15 −0 tests/system/trefs.nim
  85. +1 −0 tests/template/m1027a.nim
  86. +1 −0 tests/template/m1027b.nim
  87. +22 −0 tests/template/t1027.nim
  88. +9 −5 tests/untestable/tpostgres.nim
  89. +9 −28 tools/nimgrab.nim
  90. +0 −431 tools/urldownloader.nim
27 changes: 27 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,33 @@
This warning will become an error in future versions! Use a `cast` operation
like `cast[cstring](x)` instead.

- `logging` will default to flushing all log level messages. To get the legacy behaviour of only flushing Error and Fatal messages, use `-d:nimV1LogFlushBehavior`.

- Object fields now support default values, see https://nim-lang.github.io/Nim/manual.html#types-default-values-for-object-fields for details.

- Redefining templates with the same signature was previously
allowed to support certain macro code. To do this explicitly, the
`{.redefine.}` pragma has been added. Note that this is only for templates.
Implicit redefinition of templates is now deprecated and will give an error in the future.

- Using an unnamed break in a block is deprecated. This warning will become an error in future versions! Use a named block with a named break instead.

- Several Standard libraries are moved to nimble packages, use `nimble` to install them:
- `std/punycode` => `punycode`
- `std/asyncftpclient` => `asyncftpclient`
- `std/smtp` => `smtp`
- `std/db_common` => `db_connector/db_common`
- `std/db_sqlite` => `db_connector/db_sqlite`
- `std/db_mysql` => `db_connector/db_mysql`
- `std/db_postgres` => `db_connector/db_postgres`
- `std/db_odbc` => `db_connector/db_odbc`

- Previously, calls like `foo(a, b): ...` or `foo(a, b) do: ...` where the final argument of
`foo` had type `proc ()` were assumed by the compiler to mean `foo(a, b, proc () = ...)`.
This behavior is now deprecated. Use `foo(a, b) do (): ...` or `foo(a, b, proc () = ...)` instead.

- If no exception or any exception deriving from Exception but not Defect or CatchableError given in except, a `warnBareExcept` warning will be triggered.

## Standard library additions and changes

- `macros.parseExpr` and `macros.parseStmt` now accept an optional
Expand Down
9 changes: 0 additions & 9 deletions compiler.nimble

This file was deleted.

8 changes: 8 additions & 0 deletions compiler/ast.nim
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,8 @@ type
ident*: PIdent
else:
sons*: TNodeSeq
when defined(nimsuggest):
endInfo*: TLineInfo

TStrTable* = object # a table[PIdent] of PSym
counter*: int
Expand Down Expand Up @@ -873,6 +875,8 @@ type
typ*: PType
name*: PIdent
info*: TLineInfo
when defined(nimsuggest):
endInfo*: TLineInfo
owner*: PSym
flags*: TSymFlags
ast*: PNode # syntax tree of proc, iterator, etc.:
Expand Down Expand Up @@ -1657,6 +1661,8 @@ proc copyNode*(src: PNode): PNode =
of nkIdent: result.ident = src.ident
of nkStrLit..nkTripleStrLit: result.strVal = src.strVal
else: discard
when defined(nimsuggest):
result.endInfo = src.endInfo

template transitionNodeKindCommon(k: TNodeKind) =
let obj {.inject.} = n[]
Expand Down Expand Up @@ -1705,6 +1711,8 @@ template copyNodeImpl(dst, src, processSonsStmt) =
if src == nil: return
dst = newNode(src.kind)
dst.info = src.info
when defined(nimsuggest):
result.endInfo = src.endInfo
dst.typ = src.typ
dst.flags = src.flags * PersistentNodeFlags
dst.comment = src.comment
Expand Down
4 changes: 3 additions & 1 deletion compiler/ccgcalls.nim
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,16 @@ proc reifiedOpenArray(n: PNode): bool {.inline.} =
else:
result = true

proc genOpenArraySlice(p: BProc; q: PNode; formalType, destType: PType): (Rope, Rope) =
proc genOpenArraySlice(p: BProc; q: PNode; formalType, destType: PType; prepareForMutation = false): (Rope, Rope) =
var a, b, c: TLoc
initLocExpr(p, q[1], a)
initLocExpr(p, q[2], b)
initLocExpr(p, q[3], c)
# but first produce the required index checks:
if optBoundsCheck in p.options:
genBoundsCheck(p, a, b, c)
if prepareForMutation:
linefmt(p, cpsStmts, "#nimPrepareStrMutationV2($1);$n", [byRefLoc(p, a)])
let ty = skipTypes(a.t, abstractVar+{tyPtr})
let dest = getTypeDesc(p.module, destType)
let lengthExpr = "($1)-($2)+1" % [rdLoc(c), rdLoc(b)]
Expand Down
11 changes: 9 additions & 2 deletions compiler/ccgexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1577,6 +1577,7 @@ proc genArrToSeq(p: BProc, n: PNode, d: var TLoc) =
return
if d.k == locNone:
getTemp(p, n.typ, d)
initLocExpr(p, n[1], a)
# generate call to newSeq before adding the elements per hand:
let L = toInt(lengthOrd(p.config, n[1].typ))
if optSeqDestructors in p.config.globalOptions:
Expand All @@ -1586,7 +1587,6 @@ proc genArrToSeq(p: BProc, n: PNode, d: var TLoc) =
getSeqPayloadType(p.module, seqtype)])
else:
genNewSeqAux(p, d, intLiteral(L), L == 0)
initLocExpr(p, n[1], a)
# bug #5007; do not produce excessive C source code:
if L < 10:
for i in 0..<L:
Expand Down Expand Up @@ -1796,9 +1796,13 @@ proc genArrayLen(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
# Bug #9279, len(toOpenArray()) has to work:
if a.kind in nkCallKinds and a[0].kind == nkSym and a[0].sym.magic == mSlice:
# magic: pass slice to openArray:
var m: TLoc
var b, c: TLoc
initLocExpr(p, a[1], m)
initLocExpr(p, a[2], b)
initLocExpr(p, a[3], c)
if optBoundsCheck in p.options:
genBoundsCheck(p, m, b, c)
if op == mHigh:
putIntoDest(p, d, e, ropecg(p.module, "($2)-($1)", [rdLoc(b), rdLoc(c)]))
else:
Expand Down Expand Up @@ -2295,7 +2299,10 @@ proc genDispose(p: BProc; n: PNode) =
lineCg(p, cpsStmts, ["#nimDestroyAndDispose($#)", rdLoc(a)])

proc genSlice(p: BProc; e: PNode; d: var TLoc) =
let (x, y) = genOpenArraySlice(p, e, e.typ, e.typ.lastSon)
let (x, y) = genOpenArraySlice(p, e, e.typ, e.typ.lastSon,
prepareForMutation = e[1].kind == nkHiddenDeref and
e[1].typ.skipTypes(abstractInst).kind == tyString and
p.config.selectedGC in {gcArc, gcOrc})
if d.k == locNone: getTemp(p, e.typ, d)
linefmt(p, cpsStmts, "$1.Field0 = $2; $1.Field1 = $3;$n", [rdLoc(d), x, y])
when false:
Expand Down
28 changes: 14 additions & 14 deletions compiler/ccgtypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ proc mangleName(m: BModule; s: PSym): Rope =
result.add rope s.itemId.item
if m.hcrOn:
result.add "_"
result.add(idOrSig(s, m.module.name.s.mangle, m.sigConflicts))
result.add(idOrSig(s, m.module.name.s.mangle, m.sigConflicts, m.config))
s.loc.r = result
writeMangledName(m.ndi, s, m.config)

Expand Down Expand Up @@ -311,7 +311,7 @@ proc getSimpleTypeDesc(m: BModule, typ: PType): Rope =
else: result = nil

if result != nil and typ.isImportedType():
let sig = hashType typ
let sig = hashType(typ, m.config)
if cacheGetType(m.typeCache, sig) == nil:
m.typeCache[sig] = result

Expand Down Expand Up @@ -371,10 +371,10 @@ proc getTypeDescWeak(m: BModule; t: PType; check: var IntSet; kind: TSymKind): R
if isImportedCppType(etB) and t.kind == tyGenericInst:
result = getTypeDescAux(m, t, check, kind)
else:
result = getTypeForward(m, t, hashType(t))
result = getTypeForward(m, t, hashType(t, m.config))
pushType(m, t)
of tySequence:
let sig = hashType(t)
let sig = hashType(t, m.config)
if optSeqDestructors in m.config.globalOptions:
if skipTypes(etB[0], typedescInst).kind == tyEmpty:
internalError(m.config, "cannot map the empty seq type to a C type")
Expand Down Expand Up @@ -407,7 +407,7 @@ proc getSeqPayloadType(m: BModule; t: PType): Rope =
#result = getTypeForward(m, t, hashType(t)) & "_Content"

proc seqV2ContentType(m: BModule; t: PType; check: var IntSet) =
let sig = hashType(t)
let sig = hashType(t, m.config)
let result = cacheGetType(m.typeCache, sig)
if result == nil:
discard getTypeDescAux(m, t, check, skVar)
Expand Down Expand Up @@ -672,7 +672,7 @@ proc resolveStarsInCppType(typ: PType, idx, stars: int): PType =
else: result.elemType

proc getOpenArrayDesc(m: BModule, t: PType, check: var IntSet; kind: TSymKind): Rope =
let sig = hashType(t)
let sig = hashType(t, m.config)
if kind == skParam:
result = getTypeDescWeak(m, t[0], check, kind) & "*"
else:
Expand All @@ -696,7 +696,7 @@ proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet; kind: TSymKin
# C type generation into an analysis and a code generation phase somehow.
if t.sym != nil: useHeader(m, t.sym)
if t != origTyp and origTyp.sym != nil: useHeader(m, origTyp.sym)
let sig = hashType(origTyp)
let sig = hashType(origTyp, m.config)

defer: # defer is the simplest in this case
if isImportedType(t) and not m.typeABICache.containsOrIncl(sig):
Expand Down Expand Up @@ -725,7 +725,7 @@ proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet; kind: TSymKin
result = getTypeDescAux(m, et, check, kind) & star
else:
# no restriction! We have a forward declaration for structs
let name = getTypeForward(m, et, hashType et)
let name = getTypeForward(m, et, hashType(et, m.config))
result = name & star
m.typeCache[sig] = result
of tySequence:
Expand All @@ -734,7 +734,7 @@ proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet; kind: TSymKin
m.typeCache[sig] = result
else:
# no restriction! We have a forward declaration for structs
let name = getTypeForward(m, et, hashType et)
let name = getTypeForward(m, et, hashType(et, m.config))
result = name & seqStar(m) & star
m.typeCache[sig] = result
pushType(m, et)
Expand Down Expand Up @@ -897,7 +897,7 @@ proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet; kind: TSymKin
discard # addAbiCheck(m, t, result) # already handled elsewhere
of tySet:
# Don't use the imported name as it may be scoped: 'Foo::SomeKind'
result = $t.kind & '_' & t.lastSon.typeName & $t.lastSon.hashType
result = $t.kind & '_' & t.lastSon.typeName & $t.lastSon.hashType(m.config)
m.typeCache[sig] = result
if not isImportedType(t):
let s = int(getSize(m.config, t))
Expand Down Expand Up @@ -1070,7 +1070,7 @@ proc discriminatorTableName(m: BModule, objtype: PType, d: PSym): Rope =
objtype = objtype[0].skipTypes(abstractPtrs)
if objtype.sym == nil:
internalError(m.config, d.info, "anonymous obj with discriminator")
result = "NimDT_$1_$2" % [rope($hashType(objtype)), rope(d.name.s.mangle)]
result = "NimDT_$1_$2" % [rope($hashType(objtype, m.config)), rope(d.name.s.mangle)]

proc rope(arg: Int128): Rope = rope($arg)

Expand Down Expand Up @@ -1291,7 +1291,7 @@ proc genTypeInfo2Name(m: BModule; t: PType): Rope =
res.add m.name.s & "."
res.add it.sym.name.s
else:
res.add $hashType(it)
res.add $hashType(it, m.config)
res.add "|"
it = it[0]
result = makeCString(res)
Expand Down Expand Up @@ -1355,7 +1355,7 @@ proc genTypeInfoV2(m: BModule, t: PType; info: TLineInfo): Rope =

let prefixTI = if m.hcrOn: "(" else: "(&"

let sig = hashType(origType)
let sig = hashType(origType, m.config)
result = m.typeInfoMarkerV2.getOrDefault(sig)
if result != nil:
return prefixTI.rope & result & ")".rope
Expand Down Expand Up @@ -1426,7 +1426,7 @@ proc genTypeInfoV1(m: BModule, t: PType; info: TLineInfo): Rope =

let prefixTI = if m.hcrOn: "(" else: "(&"

let sig = hashType(origType)
let sig = hashType(origType, m.config)
result = m.typeInfoMarker.getOrDefault(sig)
if result != nil:
return prefixTI.rope & result & ")".rope
Expand Down
2 changes: 1 addition & 1 deletion compiler/cgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1600,7 +1600,7 @@ proc registerModuleToMain(g: BModuleList; m: BModule) =
hcrModuleMeta.addf("\t\"\"};$n", [])
hcrModuleMeta.addf("$nN_LIB_EXPORT N_NIMCALL(void**, HcrGetImportedModules)() { return (void**)hcr_module_list; }$n", [])
hcrModuleMeta.addf("$nN_LIB_EXPORT N_NIMCALL(char*, HcrGetSigHash)() { return \"$1\"; }$n$n",
[($sigHash(m.module)).rope])
[($sigHash(m.module, m.config)).rope])
if sfMainModule in m.module.flags:
g.mainModProcs.add(hcrModuleMeta)
g.mainModProcs.addf("static void* hcr_handle;$N", [])
Expand Down
1 change: 1 addition & 0 deletions compiler/condsyms.nim
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,4 @@ proc initDefines*(symbols: StringTableRef) =
defineSymbol("nimHasEffectsOf")

defineSymbol("nimHasEnforceNoRaises")
defineSymbol("nimHasWarnBareExcept")
6 changes: 3 additions & 3 deletions compiler/docgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1536,7 +1536,7 @@ proc commandJson*(cache: IdentCache, conf: ConfigRef) =
let filename = getOutFile(conf, RelativeFile conf.projectName, JsonExt)
try:
writeFile(filename, content)
except:
except IOError:
rawMessage(conf, errCannotOpenFile, filename.string)

proc commandTags*(cache: IdentCache, conf: ConfigRef) =
Expand All @@ -1559,7 +1559,7 @@ proc commandTags*(cache: IdentCache, conf: ConfigRef) =
let filename = getOutFile(conf, RelativeFile conf.projectName, TagsExt)
try:
writeFile(filename, content)
except:
except IOError:
rawMessage(conf, errCannotOpenFile, filename.string)

proc commandBuildIndex*(conf: ConfigRef, dir: string, outFile = RelativeFile"") =
Expand All @@ -1580,5 +1580,5 @@ proc commandBuildIndex*(conf: ConfigRef, dir: string, outFile = RelativeFile"")

try:
writeFile(filename, code)
except:
except IOError:
rawMessage(conf, errCannotOpenFile, filename.string)
4 changes: 2 additions & 2 deletions compiler/extccomp.nim
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ proc ccHasSaneOverflow*(conf: ConfigRef): bool =
var exe = getConfigVar(conf, conf.cCompiler, ".exe")
if exe.len == 0: exe = CC[conf.cCompiler].compilerExe
# NOTE: should we need the full version, use -dumpfullversion
let (s, exitCode) = try: execCmdEx(exe & " -dumpversion") except: ("", 1)
let (s, exitCode) = try: execCmdEx(exe & " -dumpversion") except IOError, OSError, ValueError: ("", 1)
if exitCode == 0:
var major: int
discard parseInt(s, major)
Expand Down Expand Up @@ -1006,7 +1006,7 @@ proc changeDetectedViaJsonBuildInstructions*(conf: ConfigRef; jsonFile: Absolute
proc runJsonBuildInstructions*(conf: ConfigRef; jsonFile: AbsoluteFile) =
var bcache: BuildCache
try: bcache.fromJson(jsonFile.string.parseFile)
except:
except ValueError, KeyError, JsonKindError:
let e = getCurrentException()
conf.quitOrRaise "\ncaught exception:\n$#\nstacktrace:\n$#error evaluating JSON file: $#" %
[e.msg, e.getStackTrace(), jsonFile.string]
Expand Down
2 changes: 1 addition & 1 deletion compiler/injectdestructors.nim
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ proc genOp(c: var Con; t: PType; kind: TTypeAttachedOp; dest, ri: PNode): PNode
var op = getAttachedOp(c.graph, t, kind)
if op == nil or op.ast.isGenericRoutine:
# give up and find the canonical type instead:
let h = sighashes.hashType(t, {CoType, CoConsiderOwned, CoDistinct})
let h = sighashes.hashType(t, c.graph.config, {CoType, CoConsiderOwned, CoDistinct})
let canon = c.graph.canonTypes.getOrDefault(h)
if canon != nil:
op = getAttachedOp(c.graph, canon, kind)
Expand Down
2 changes: 1 addition & 1 deletion compiler/installer.ini
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,5 @@ shortDesc: "The Nim Compiler"
licenses: "bin/nim,MIT;lib/*,MIT;"

[nimble]
pkgName: "compiler"
pkgName: "nim"
pkgFiles: "compiler/*;doc/basicopt.txt;doc/advopt.txt;doc/nimdoc.css"
11 changes: 6 additions & 5 deletions compiler/jsgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ proc mangleName(m: BModule, s: PSym): Rope =
if m.config.hcrOn:
# When hot reloading is enabled, we must ensure that the names
# of functions and types will be preserved across rebuilds:
result.add(idOrSig(s, m.module.name.s, m.sigConflicts))
result.add(idOrSig(s, m.module.name.s, m.sigConflicts, m.config))
else:
result.add("_")
result.add(rope(s.id))
Expand Down Expand Up @@ -2393,17 +2393,18 @@ proc genProc(oldProc: PProc, prc: PSym): Rope =
if prc.typ[0] != nil and sfPure notin prc.flags:
resultSym = prc.ast[resultPos].sym
let mname = mangleName(p.module, resultSym)
let returnAddress = not isIndirect(resultSym) and
# otherwise uses "fat pointers"
let useRawPointer = not isIndirect(resultSym) and
resultSym.typ.kind in {tyVar, tyPtr, tyLent, tyRef, tyOwned} and
mapType(p, resultSym.typ) == etyBaseIndex
if returnAddress:
if useRawPointer:
resultAsgn = p.indentLine(("var $# = null;$n") % [mname])
resultAsgn.add p.indentLine("var $#_Idx = 0;$n" % [mname])
else:
let resVar = createVar(p, resultSym.typ, isIndirect(resultSym))
resultAsgn = p.indentLine(("var $# = $#;$n") % [mname, resVar])
gen(p, prc.ast[resultPos], a)
if returnAddress:
if mapType(p, resultSym.typ) == etyBaseIndex:
returnStmt = "return [$#, $#];$n" % [a.address, a.res]
else:
returnStmt = "return $#;$n" % [a.res]
Expand Down Expand Up @@ -2711,7 +2712,7 @@ proc genModule(p: PProc, n: PNode) =
if p.config.hcrOn and n.kind == nkStmtList:
let moduleSym = p.module.module
var moduleLoadedVar = rope(moduleSym.name.s) & "_loaded" &
idOrSig(moduleSym, moduleSym.name.s, p.module.sigConflicts)
idOrSig(moduleSym, moduleSym.name.s, p.module.sigConflicts, p.config)
lineF(p, "var $1;$n", [moduleLoadedVar])
var inGuardedBlock = false

Expand Down
6 changes: 6 additions & 0 deletions compiler/lexer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ type
cache*: IdentCache
when defined(nimsuggest):
previousToken: TLineInfo
tokenEnd*: TLineInfo
previousTokenEnd*: TLineInfo
config*: ConfigRef

proc getLineInfo*(L: Lexer, tok: Token): TLineInfo {.inline.} =
Expand Down Expand Up @@ -1216,6 +1218,10 @@ proc skip(L: var Lexer, tok: var Token) =
proc rawGetTok*(L: var Lexer, tok: var Token) =
template atTokenEnd() {.dirty.} =
when defined(nimsuggest):
L.previousTokenEnd.line = L.tokenEnd.line
L.previousTokenEnd.col = L.tokenEnd.col
L.tokenEnd.line = tok.line.uint16
L.tokenEnd.col = getColNumber(L, L.bufpos).int16
# we attach the cursor to the last *strong* token
if tok.tokType notin weakTokens:
L.previousToken.line = tok.line.uint16
Expand Down
Loading