Showing with 334 additions and 124 deletions.
  1. +1 −1 .builds/freebsd.yml
  2. +1 −1 .builds/openbsd_0.yml
  3. +1 −1 .builds/openbsd_1.yml
  4. +1 −1 .builds/openbsd_2.yml
  5. +2 −2 .github/workflows/ci_docs.yml
  6. +1 −1 .travis.yml
  7. +1 −1 azure-pipelines.yml
  8. +1 −1 build_all.bat
  9. +1 −1 build_all.sh
  10. +33 −0 changelog.md
  11. +1 −1 ci/build.bat
  12. +1 −1 ci/build.sh
  13. +1 −1 ci/nsis_build.bat
  14. +1 −1 compiler/ast.nim
  15. +1 −1 compiler/btrees.nim
  16. +6 −1 compiler/ccgexprs.nim
  17. +9 −2 compiler/ccgtypes.nim
  18. +17 −5 compiler/commands.nim
  19. +1 −1 compiler/jsgen.nim
  20. +20 −11 compiler/liftdestructors.nim
  21. +3 −1 compiler/lineinfos.nim
  22. +1 −1 compiler/linter.nim
  23. +1 −1 compiler/modulegraphs.nim
  24. +1 −1 compiler/nim.nim
  25. +1 −1 compiler/nimpaths.nim
  26. +4 −3 compiler/options.nim
  27. +2 −2 compiler/semdata.nim
  28. +3 −0 compiler/semexprs.nim
  29. +6 −5 compiler/semtypes.nim
  30. +1 −1 compiler/semtypinst.nim
  31. +5 −4 compiler/types.nim
  32. +1 −1 compiler/vmdef.nim
  33. +1 −1 compiler/vmgen.nim
  34. +2 −0 config/nim.cfg
  35. +2 −0 doc/advopt.txt
  36. +3 −1 lib/impure/db_postgres.nim
  37. +32 −14 lib/pure/asyncfutures.nim
  38. +2 −2 lib/pure/asynchttpserver.nim
  39. +2 −6 lib/pure/asyncnet.nim
  40. +18 −1 lib/pure/asyncstreams.nim
  41. +14 −5 lib/pure/httpclient.nim
  42. +3 −4 lib/pure/net.nim
  43. +2 −0 lib/pure/os.nim
  44. +1 −1 lib/pure/sugar.nim
  45. +1 −1 lib/pure/typetraits.nim
  46. +9 −9 lib/std/jsonutils.nim
  47. +1 −1 lib/std/monotimes.nim
  48. +1 −1 lib/std/private/globs.nim
  49. +2 −2 lib/std/sha1.nim
  50. +1 −1 lib/std/wrapnils.nim
  51. +2 −1 lib/system.nim
  52. +1 −1 lib/system/exceptions.nim
  53. +14 −6 lib/system/orc.nim
  54. +4 −0 lib/system/seqs_v2.nim
  55. +11 −2 lib/wrappers/openssl.nim
  56. +13 −0 tests/arc/tnewseq_legacy.nim
  57. +2 −2 tests/async/tasync_traceback.nim
  58. +3 −1 tests/cpp/temitlist.nim
  59. +3 −1 tests/cpp/tempty_generic_obj.nim
  60. +3 −1 tests/exception/tcpp_imported_exc.nim
  61. +2 −2 tests/newconfig/tfoo.nim
  62. +2 −0 tests/newconfig/tfoo.nims
  63. +23 −0 tests/stdlib/thttpclient_standalone.nim
  64. +23 −0 tests/stylecheck/tusages.nim
  65. +1 −1 tools/ci_generate.nim
2 changes: 1 addition & 1 deletion .builds/freebsd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ environment:
tasks:
- setup: |
cd Nim
git clone --depth 1 -q https://github.com/nim-lang/csources.git
git clone --depth 1 -q https://github.com/nim-lang/csources_v1.git csources
gmake -C csources -j $(sysctl -n hw.ncpu)
bin/nim c --skipUserCfg --skipParentCfg koch
echo 'export PATH=$HOME/Nim/bin:$PATH' >> $HOME/.buildenv
Expand Down
2 changes: 1 addition & 1 deletion .builds/openbsd_0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ environment:
tasks:
- setup: |
cd Nim
git clone --depth 1 -q https://github.com/nim-lang/csources.git
git clone --depth 1 -q https://github.com/nim-lang/csources_v1.git csources
gmake -C csources -j $(sysctl -n hw.ncpuonline)
bin/nim c koch
echo 'export PATH=$HOME/Nim/bin:$PATH' >> $HOME/.buildenv
Expand Down
2 changes: 1 addition & 1 deletion .builds/openbsd_1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ environment:
tasks:
- setup: |
cd Nim
git clone --depth 1 -q https://github.com/nim-lang/csources.git
git clone --depth 1 -q https://github.com/nim-lang/csources_v1.git csources
gmake -C csources -j $(sysctl -n hw.ncpuonline)
bin/nim c koch
echo 'export PATH=$HOME/Nim/bin:$PATH' >> $HOME/.buildenv
Expand Down
2 changes: 1 addition & 1 deletion .builds/openbsd_2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ environment:
tasks:
- setup: |
cd Nim
git clone --depth 1 -q https://github.com/nim-lang/csources.git
git clone --depth 1 -q https://github.com/nim-lang/csources_v1.git csources
gmake -C csources -j $(sysctl -n hw.ncpuonline)
bin/nim c koch
echo 'export PATH=$HOME/Nim/bin:$PATH' >> $HOME/.buildenv
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
id: csources-version
shell: bash
run: |
sha=$(git ls-remote https://github.com/nim-lang/csources master | cut -f 1)
sha=$(git ls-remote https://github.com/nim-lang/csources_v1 master | cut -f 1)
echo "::set-output name=sha::$sha"
- name: 'Get prebuilt csources from cache'
Expand All @@ -88,7 +88,7 @@ jobs:
if: steps.csources-cache.outputs.cache-hit != 'true'
uses: actions/checkout@v2
with:
repository: nim-lang/csources
repository: nim-lang/csources_v1
path: csources

- name: 'Build 1-stage compiler from csources'
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ addons:
- valgrind

before_script:
- git clone --depth 1 https://github.com/nim-lang/csources.git
- git clone --depth 1 https://github.com/nim-lang/csources_v1.git csources
- export PATH="$PWD/bin${PATH:+:$PATH}"
- make -C csources -j 2 LD=$CC ucpu=$CPU

Expand Down
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
- checkout: self
fetchDepth: 1

- bash: git clone --depth 1 https://github.com/nim-lang/csources
- bash: git clone --depth 1 https://github.com/nim-lang/csources_v1 csources
displayName: 'Checkout Nim csources'

- task: NodeTool@0
Expand Down
2 changes: 1 addition & 1 deletion build_all.bat
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@echo off
rem build development version of the compiler; can be rerun safely
if not exist csources (
git clone --depth 1 https://github.com/nim-lang/csources.git
git clone --depth 1 https://github.com/nim-lang/csources_v1.git csources
)
if not exist bin\nim.exe (
cd csources
Expand Down
2 changes: 1 addition & 1 deletion build_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ echo_run(){
"$@"
}

[ -d csources ] || echo_run git clone -q --depth 1 https://github.com/nim-lang/csources.git
[ -d csources ] || echo_run git clone -q --depth 1 https://github.com/nim-lang/csources_v1.git csources

nim_csources=bin/nim_csources

Expand Down
33 changes: 33 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,21 @@



## Changes affecting backward compatibility

- The configuration subsystem now allows for `-d:release` and `-d:danger` to work as expected.
The downside is that these defines now have custom logic that doesn't apply for
other defines.


## Standard library additions and changes
- Added support for parenthesized expressions in `strformat`

- Fixed buffer overflow bugs in `net`

- Added `sections` iterator in `parsecfg`.

- Make custom op in macros.quote work for all statements.

- On Windows the SSL library now checks for valid certificates.
It uses the `cacert.pem` file for this purpose which was extracted
Expand Down Expand Up @@ -31,6 +45,7 @@
- Added `asyncdispatch.activeDescriptors` that returns the number of currently
active async event handles/file descriptors

- Fixed premature garbage collection in asyncdispatch, when a stack trace override is in place.

## Language changes

Expand All @@ -46,5 +61,23 @@

- Added `unsafeIsolate` and `extract` to `std/isolation`.

- `--hint:CC` now goes to stderr (like all other hints) instead of stdout.

- json build instructions are now generated in `$nimcache/outFileBasename.json`
instead of `$nimcache/projectName.json`. This allows avoiding recompiling a given project
compiled with different options if the output file differs.

- `--usenimcache` (implied by `nim r main`) now generates an output file that includes a hash of
some of the compilation options, which allows caching generated binaries:
nim r main # recompiles
nim r -d:foo main # recompiles
nim r main # uses cached binary
nim r main arg1 arg2 # ditto (runtime arguments are irrelevant)

- The style checking of the compiler now supports a `--styleCheck:usages` switch. This switch
enforces that every symbol is written as it was declared, not enforcing
the official Nim style guide. To be enabled, this has to be combined either
with `--styleCheck:error` or `--styleCheck:hint`.

## Tool changes

2 changes: 1 addition & 1 deletion ci/build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ REM Some debug info
echo "Running on %CI_RUNNER_ID% (%CI_RUNNER_DESCRIPTION%) with tags %CI_RUNNER_TAGS%."
gcc -v

git clone --depth 1 https://github.com/nim-lang/csources.git
git clone --depth 1 https://github.com/nim-lang/csources_v1.git csources
cd csources
call build64.bat
cd ..
Expand Down
2 changes: 1 addition & 1 deletion ci/build.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
sh ci/deps.sh

# Build from C sources.
git clone --depth 1 https://github.com/nim-lang/csources.git
git clone --depth 1 https://github.com/nim-lang/csources_v1.git csources
cd csources
sh build.sh
cd ..
Expand Down
2 changes: 1 addition & 1 deletion ci/nsis_build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Rem Build csources
koch csources -d:release || exit /b

rem Grab C sources and nimsuggest
git clone --depth 1 https://github.com/nim-lang/csources.git
git clone --depth 1 https://github.com/nim-lang/csources_v1.git csources

set PATH=%CD%\bin;%PATH%

Expand Down
2 changes: 1 addition & 1 deletion compiler/ast.nim
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ type

PInstantiation* = ref TInstantiation

TScope* = object
TScope* {.acyclic.} = object
depthLevel*: int
symbols*: TStrTable
parent*: PScope
Expand Down
2 changes: 1 addition & 1 deletion compiler/btrees.nim
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const
Mhalf = M div 2

type
Node[Key, Val] = ref object
Node[Key, Val] {.acyclic.} = ref object
entries: int
keys: array[M, Key]
case isInternal: bool
Expand Down
7 changes: 6 additions & 1 deletion compiler/ccgexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2324,7 +2324,12 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
gcUsage(p.config, e)
else:
genNewFinalize(p, e)
of mNewSeq: genNewSeq(p, e)
of mNewSeq:
if optSeqDestructors in p.config.globalOptions:
e[1] = makeAddr(e[1])
genCall(p, e, d)
else:
genNewSeq(p, e)
of mNewSeqOfCap: genNewSeqOfCap(p, e, d)
of mSizeOf:
let t = e[1].typ.skipTypes({tyTypeDesc})
Expand Down
11 changes: 9 additions & 2 deletions compiler/ccgtypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1327,6 +1327,10 @@ proc genHook(m: BModule; t: PType; info: TLineInfo; op: TTypeAttachedOp): Rope =

genProc(m, theProc)
result = theProc.loc.r

when false:
if not canFormAcycle(t) and op == attachedTrace:
echo "ayclic but has this =trace ", t, " ", theProc.ast
else:
when false:
if op == attachedTrace and m.config.selectedGC == gcOrc and
Expand All @@ -1352,9 +1356,12 @@ proc genTypeInfoV2Impl(m: BModule, t, origType: PType, name: Rope; info: TLineIn
let traceImpl = genHook(m, t, info, attachedTrace)
let disposeImpl = genHook(m, t, info, attachedDispose)

addf(m.s[cfsTypeInit3], "$1.destructor = (void*)$2; $1.size = sizeof($3); $1.align = NIM_ALIGNOF($3); $1.name = $4;$n; $1.traceImpl = (void*)$5; $1.disposeImpl = (void*)$6;", [
var flags = 0
if not canFormAcycle(t): flags = flags or 1

addf(m.s[cfsTypeInit3], "$1.destructor = (void*)$2; $1.size = sizeof($3); $1.align = NIM_ALIGNOF($3); $1.name = $4;$n; $1.traceImpl = (void*)$5; $1.disposeImpl = (void*)$6; $1.flags = $7;", [
name, destroyImpl, getTypeDesc(m, t), typeName,
traceImpl, disposeImpl])
traceImpl, disposeImpl, rope(flags)])

if t.kind == tyObject and t.len > 0 and t[0] != nil and optEnableDeepCopy in m.config.globalOptions:
discard genTypeInfoV1(m, t, info)
Expand Down
22 changes: 17 additions & 5 deletions compiler/commands.nim
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ proc splitSwitch(conf: ConfigRef; switch: string, cmd, arg: var string, pass: TC
proc processOnOffSwitch(conf: ConfigRef; op: TOptions, arg: string, pass: TCmdLinePass,
info: TLineInfo) =
case arg.normalize
of "","on": conf.options.incl op
of "", "on": conf.options.incl op
of "off": conf.options.excl op
else: localError(conf, info, errOnOrOffExpectedButXFound % arg)

Expand Down Expand Up @@ -391,6 +391,19 @@ proc handleStdinInput*(conf: ConfigRef) =
if conf.outDir.isEmpty:
conf.outDir = getNimcacheDir(conf)

proc specialDefine(conf: ConfigRef, key: string) =
# Keep this syncronized with the default config/nim.cfg!
if cmpIgnoreStyle(key, "nimQuirky") == 0:
conf.exc = excQuirky
elif cmpIgnoreStyle(key, "release") == 0 or cmpIgnoreStyle(key, "danger") == 0:
conf.options.excl {optStackTrace, optLineTrace, optLineDir, optOptimizeSize}
conf.globalOptions.excl {optExcessiveStackTrace, optCDebug}
conf.options.incl optOptimizeSpeed
if cmpIgnoreStyle(key, "danger") == 0 or cmpIgnoreStyle(key, "quick") == 0:
conf.options.excl {optObjCheck, optFieldCheck, optRangeCheck, optBoundsCheck,
optOverflowCheck, optAssert, optStackTrace, optLineTrace, optLineDir}
conf.globalOptions.excl {optCDebug}

proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
conf: ConfigRef) =
var
Expand Down Expand Up @@ -450,12 +463,10 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
expectArg(conf, switch, arg, pass, info)
if {':', '='} in arg:
splitSwitch(conf, arg, key, val, pass, info)
if cmpIgnoreStyle(key, "nimQuirky") == 0:
conf.exc = excQuirky
specialDefine(conf, key)
defineSymbol(conf.symbols, key, val)
else:
if cmpIgnoreStyle(arg, "nimQuirky") == 0:
conf.exc = excQuirky
specialDefine(conf, arg)
defineSymbol(conf.symbols, arg)
of "undef", "u":
expectArg(conf, switch, arg, pass, info)
Expand Down Expand Up @@ -854,6 +865,7 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
of "off": conf.globalOptions = conf.globalOptions - {optStyleHint, optStyleError}
of "hint": conf.globalOptions = conf.globalOptions + {optStyleHint} - {optStyleError}
of "error": conf.globalOptions = conf.globalOptions + {optStyleError}
of "usages": conf.globalOptions.incl optStyleUsages
else: localError(conf, info, errOffHintsError % arg)
of "showallmismatches":
processOnOffSwitchG(conf, {optShowAllMismatches}, arg, pass, info)
Expand Down
2 changes: 1 addition & 1 deletion compiler/jsgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import
cgmeth, lowerings, sighashes, modulegraphs, lineinfos, rodutils,
transf, injectdestructors, sourcemap

import std/[json, sets, math, tables, intsets, strutils]
import json, sets, math, tables, intsets, strutils

from modulegraphs import ModuleGraph, PPassContext

Expand Down
31 changes: 20 additions & 11 deletions compiler/liftdestructors.nim
Original file line number Diff line number Diff line change
Expand Up @@ -435,13 +435,17 @@ proc setLenSeqCall(c: var TLiftCtx; t: PType; x, y: PNode): PNode =
result = newTree(nkCall, newSymNode(op, x.info), x, lenCall)

proc forallElements(c: var TLiftCtx; t: PType; body, x, y: PNode) =
let counterIdx = body.len
let i = declareCounter(c, body, toInt64(firstOrd(c.g.config, t)))
let whileLoop = genWhileLoop(c, i, x)
let elemType = t.lastSon
let b = if c.kind == attachedTrace: y else: y.at(i, elemType)
fillBody(c, elemType, whileLoop[1], x.at(i, elemType), b)
addIncStmt(c, whileLoop[1], i)
body.add whileLoop
if whileLoop[1].len > 0:
addIncStmt(c, whileLoop[1], i)
body.add whileLoop
else:
body.sons.setLen counterIdx

proc fillSeqOp(c: var TLiftCtx; t: PType; body, x, y: PNode) =
case c.kind
Expand All @@ -464,8 +468,9 @@ proc fillSeqOp(c: var TLiftCtx; t: PType; body, x, y: PNode) =
forallElements(c, t, body, x, y)
body.add genBuiltin(c.g, mDestroy, "destroy", x)
of attachedTrace:
# follow all elements:
forallElements(c, t, body, x, y)
if canFormAcycle(t.elemType):
# follow all elements:
forallElements(c, t, body, x, y)
of attachedDispose:
forallElements(c, t, body, x, y)
body.add genBuiltin(c.g, mDestroy, "destroy", x)
Expand Down Expand Up @@ -598,16 +603,20 @@ proc atomicRefOp(c: var TLiftCtx; t: PType; body, x, y: PNode) =
body.add genIf(c, cond, actions)
of attachedDeepCopy: assert(false, "cannot happen")
of attachedTrace:
if isFinal(elemType):
let typInfo = genBuiltin(c.g, mGetTypeInfoV2, "getTypeInfoV2", newNodeIT(nkType, x.info, elemType))
typInfo.typ = getSysType(c.g, c.info, tyPointer)
body.add callCodegenProc(c.g, "nimTraceRef", c.info, genAddrOf(x), typInfo, y)
else:
# If the ref is polymorphic we have to account for this
body.add callCodegenProc(c.g, "nimTraceRefDyn", c.info, genAddrOf(x), y)
if isCyclic:
if isFinal(elemType):
let typInfo = genBuiltin(c.g, mGetTypeInfoV2, "getTypeInfoV2", newNodeIT(nkType, x.info, elemType))
typInfo.typ = getSysType(c.g, c.info, tyPointer)
body.add callCodegenProc(c.g, "nimTraceRef", c.info, genAddrOf(x), typInfo, y)
else:
# If the ref is polymorphic we have to account for this
body.add callCodegenProc(c.g, "nimTraceRefDyn", c.info, genAddrOf(x), y)
#echo "can follow ", elemType, " static ", isFinal(elemType)
of attachedDispose:
# this is crucial! dispose is like =destroy but we don't follow refs
# as that is dealt within the cycle collector.
if not isCyclic:
body.add genIf(c, cond, actions)
when false:
let cond = copyTree(x)
cond.typ = getSysType(c.g, x.info, tyBool)
Expand Down
4 changes: 3 additions & 1 deletion compiler/lineinfos.nim
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type
warnLockLevel = "LockLevel", warnResultShadowed = "ResultShadowed",
warnInconsistentSpacing = "Spacing", warnCaseTransition = "CaseTransition",
warnCycleCreated = "CycleCreated", warnObservableStores = "ObservableStores",
warnResultUsed = "ResultUsed",
warnUser = "User",

hintSuccess = "Success", hintSuccessX = "SuccessX", hintCC = "CC",
Expand Down Expand Up @@ -125,6 +126,7 @@ const
warnCaseTransition: "Potential object case transition, instantiate new object instead",
warnCycleCreated: "$1",
warnObservableStores: "observable stores to '$1'",
warnResultUsed: "used 'result' variable",
warnUser: "$1",
hintSuccess: "operation successful: $#",
# keep in sync with `testament.isSuccess`
Expand Down Expand Up @@ -176,7 +178,7 @@ type
TNoteKinds* = set[TNoteKind]

proc computeNotesVerbosity(): array[0..3, TNoteKinds] =
result[3] = {low(TNoteKind)..high(TNoteKind)} - {warnObservableStores}
result[3] = {low(TNoteKind)..high(TNoteKind)} - {warnObservableStores, warnResultUsed}
result[2] = result[3] - {hintStackTrace, warnUninit, hintExtendedContext}
result[1] = result[2] - {warnProveField, warnProveIndex,
warnGcUnsafe, hintPath, hintDependency, hintCodeBegin, hintCodeEnd,
Expand Down
2 changes: 1 addition & 1 deletion compiler/linter.nim
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ proc nep1CheckDefImpl(conf: ConfigRef; info: TLineInfo; s: PSym; k: TSymKind) =
lintReport(conf, info, beau, s.name.s)

template styleCheckDef*(conf: ConfigRef; info: TLineInfo; s: PSym; k: TSymKind) =
if {optStyleHint, optStyleError} * conf.globalOptions != {}:
if {optStyleHint, optStyleError} * conf.globalOptions != {} and optStyleUsages notin conf.globalOptions:
nep1CheckDefImpl(conf, info, s, k)

template styleCheckDef*(conf: ConfigRef; info: TLineInfo; s: PSym) =
Expand Down
2 changes: 1 addition & 1 deletion compiler/modulegraphs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import ast, intsets, tables, options, lineinfos, hashes, idents,
type
SigHash* = distinct MD5Digest

ModuleGraph* = ref object
ModuleGraph* {.acyclic.} = ref object
modules*: seq[PSym] ## indexed by int32 fileIdx
packageSyms*: TStrTable
deps*: IntSet # the dependency graph or potentially its transitive closure.
Expand Down
Loading