Showing with 4,431 additions and 863 deletions.
  1. +6 −6 azure-pipelines.yml
  2. +1 −1 changelog.md
  3. +5 −1 ci/funs.sh
  4. +24 −7 compiler/ast.nim
  5. +21 −11 compiler/ccgexprs.nim
  6. +2 −1 compiler/ccgstmts.nim
  7. +3 −3 compiler/ccgtypes.nim
  8. +38 −34 compiler/cgen.nim
  9. +1 −1 compiler/commands.nim
  10. +1 −0 compiler/condsyms.nim
  11. +2 −4 compiler/dfa.nim
  12. +1 −1 compiler/docgen.nim
  13. +25 −8 compiler/extccomp.nim
  14. +20 −12 compiler/importer.nim
  15. +6 −3 compiler/injectdestructors.nim
  16. +84 −69 compiler/jsgen.nim
  17. +1 −1 compiler/lambdalifting.nim
  18. +6 −6 compiler/liftdestructors.nim
  19. +3 −1 compiler/lineinfos.nim
  20. +9 −5 compiler/linter.nim
  21. +23 −10 compiler/lookups.nim
  22. +2 −1 compiler/lowerings.nim
  23. +5 −7 compiler/msgs.nim
  24. +33 −9 compiler/parser.nim
  25. +25 −11 compiler/pragmas.nim
  26. +1 −0 compiler/renderer.nim
  27. +28 −25 compiler/sem.nim
  28. +12 −3 compiler/semcall.nim
  29. +5 −3 compiler/semdata.nim
  30. +269 −142 compiler/semexprs.nim
  31. +2 −7 compiler/semfold.nim
  32. +22 −0 compiler/semgnrc.nim
  33. +14 −2 compiler/seminst.nim
  34. +21 −0 compiler/semmacrosanity.nim
  35. +9 −1 compiler/semmagic.nim
  36. +18 −5 compiler/semobjconstr.nim
  37. +3 −0 compiler/semparallel.nim
  38. +2 −1 compiler/sempass2.nim
  39. +137 −59 compiler/semstmts.nim
  40. +10 −2 compiler/semtempl.nim
  41. +45 −12 compiler/semtypes.nim
  42. +47 −15 compiler/semtypinst.nim
  43. +2 −1 compiler/sighashes.nim
  44. +34 −8 compiler/sigmatch.nim
  45. +2 −2 compiler/sizealignoffsetimpl.nim
  46. +12 −1 compiler/transf.nim
  47. +3 −1 compiler/typeallowed.nim
  48. +60 −18 compiler/types.nim
  49. +3 −1 compiler/varpartitions.nim
  50. +6 −2 compiler/vm.nim
  51. +43 −8 compiler/vmgen.nim
  52. +1 −1 compiler/wordrecg.nim
  53. +16 −10 config/nim.cfg
  54. +11 −3 doc/destructors.rst
  55. +4 −3 doc/grammar.txt
  56. +44 −8 doc/manual.rst
  57. +59 −0 doc/manual_experimental.rst
  58. +11 −4 koch.nim
  59. +1 −1 lib/compilation.nim
  60. +30 −8 lib/core/macros.nim
  61. +7 −1 lib/nimbase.h
  62. +2 −2 lib/posix/posix_linux_amd64.nim
  63. +1 −1 lib/pure/asyncfutures.nim
  64. +2 −2 lib/pure/asyncmacro.nim
  65. +10 −5 lib/pure/browsers.nim
  66. +4 −4 lib/pure/collections/sequtils.nim
  67. +2 −2 lib/pure/collections/tables.nim
  68. +1 −1 lib/pure/ioselects/ioselectors_epoll.nim
  69. +2 −8 lib/pure/json.nim
  70. +1 −1 lib/pure/os.nim
  71. +1 −1 lib/pure/parseopt.nim
  72. +2 −2 lib/pure/selectors.nim
  73. +3 −2 lib/pure/strutils.nim
  74. +39 −10 lib/pure/terminal.nim
  75. +1 −1 lib/pure/times.nim
  76. +11 −10 lib/std/enumutils.nim
  77. +17 −17 lib/std/jsonutils.nim
  78. +25 −15 lib/system.nim
  79. +5 −3 lib/system/assign.nim
  80. +3 −3 lib/system/atomics.nim
  81. +1 −1 lib/system/channels_builtin.nim
  82. +3 −0 lib/system/chcks.nim
  83. +0 −1 lib/system/gc_common.nim
  84. +2 −1 lib/system/jssys.nim
  85. +7 −1 lib/system/memalloc.nim
  86. +6 −6 lib/system/orc.nim
  87. +3 −3 lib/system/seqs_v2.nim
  88. +4 −4 lib/system/sets.nim
  89. +3 −1 lib/system/strmantle.nim
  90. +3 −3 lib/windows/winlean.nim
  91. +4 −2 nim.nimble
  92. +1 −1 nimsuggest/nimsuggest.nim
  93. +2 −2 testament/important_packages.nim
  94. +25 −0 tests/arc/t20588.nim
  95. +12 −0 tests/arc/tarc_orc.nim
  96. +1 −1 tests/arc/tasyncleak.nim
  97. +14 −0 tests/array/t20248.nim
  98. +1 −1 tests/assign/tassign.nim
  99. +1 −1 tests/ast_pattern_matching.nim
  100. +19 −0 tests/async/t20111.nim
  101. +6 −0 tests/async/t21447.nim
  102. +32 −0 tests/borrow/typeclassborrow.nim
  103. +6 −0 tests/ccgbugs/t10964.nim
  104. +1 −1 tests/ccgbugs/targ_lefttoright.nim
  105. +1 −1 tests/ccgbugs/tccgen1.nim
  106. +1 −1 tests/ccgbugs/tmissingbracket.nim
  107. +28 −0 tests/ccgbugs2/tcodegen.nim
  108. +55 −0 tests/closure/t11042.nim
  109. +20 −0 tests/closure/t20152.nim
  110. +2 −0 tests/compiler/samplelib.nim
  111. +3 −0 tests/compiler/tcmdlineclib.nim
  112. +10 −0 tests/compiler/tcmdlineclib.nims
  113. +32 −0 tests/controlflow/tunreachable.nim
  114. +6 −0 tests/converter/texplicit_conversion.nim
  115. +45 −0 tests/discard/tdiscardable.nim
  116. +14 −0 tests/discard/tillegaldiscardtypes.nim
  117. +45 −4 tests/distinct/tdistinct.nim
  118. +5 −0 tests/effects/teffects1.nim
  119. +1 −1 tests/effects/teffects2.nim
  120. +1 −1 tests/effects/teffects3.nim
  121. +1 −1 tests/effects/teffects4.nim
  122. +39 −0 tests/effects/teffectsmisc.nim
  123. +17 −0 tests/effects/tstrict_effects3.nim
  124. +28 −0 tests/enum/t21863.nim
  125. +9 −1 tests/enum/tenum.nim
  126. +14 −0 tests/errmsgs/t14444.nim
  127. +12 −0 tests/errmsgs/t16654.nim
  128. +18 −0 tests/errmsgs/t18886.nim
  129. +7 −0 tests/errmsgs/t18983.nim
  130. +12 −0 tests/errmsgs/t19224.nim
  131. +10 −0 tests/errmsgs/t19882.nim
  132. +5 −0 tests/errmsgs/t19882_2.nim
  133. +5 −0 tests/errmsgs/t5282.nim
  134. +6 −0 tests/errmsgs/t8064.nim
  135. +29 −0 tests/errmsgs/tcase_stmt.nim
  136. +40 −13 tests/errmsgs/treportunused.nim
  137. +8 −2 tests/float/tfloat4.nim
  138. +11 −0 tests/generics/m3770.nim
  139. +1 −1 tests/generics/module_with_generics.nim
  140. +20 −0 tests/generics/t16639.nim
  141. +13 −0 tests/generics/t3770.nim
  142. +9 −0 tests/generics/t6637.nim
  143. +10 −0 tests/generics/t7446.nim
  144. +1 −1 tests/generics/tcan.nim
  145. +13 −0 tests/generics/tgeneric0.nim
  146. +123 −0 tests/generics/tgeneric_recursionlimit.nim
  147. +32 −0 tests/generics/tgenerics_issues.nim
  148. +14 −0 tests/generics/tgenerics_various.nim
  149. +79 −0 tests/generics/tstatic_constrained.nim
  150. +33 −0 tests/global/t3505.nim
  151. +1 −0 tests/import/buzz/m21496.nim
  152. +1 −0 tests/import/fizz/m21496.nim
  153. +9 −0 tests/import/t21496.nim
  154. +114 −0 tests/iter/t21306.nim
  155. +54 −0 tests/iter/tgeniteratorinblock.nim
  156. +13 −0 tests/iter/titer_issues.nim
  157. +15 −23 tests/lexer/tcustom_numeric_literals.nim
  158. +22 −0 tests/macros/t15691.nim
  159. +38 −0 tests/macros/t16758.nim
  160. +2 −2 tests/macros/tgettypeinst.nim
  161. +60 −0 tests/macros/tmacros_various.nim
  162. +1 −1 tests/macros/tvtable.nim
  163. +30 −0 tests/metatype/tstatic_generic_typeclass.nim
  164. +1 −1 tests/method/tmethod_issues.nim
  165. +3 −3 tests/method/tmultim.nim
  166. +4 −0 tests/misc/m15955.nim
  167. +11 −0 tests/misc/m15955_main.nim
  168. +2 −0 tests/misc/m20149.nim
  169. +20 −0 tests/misc/t11634.nim
  170. +14 −0 tests/misc/t12869.nim
  171. +22 −0 tests/misc/t15955.nim
  172. +9 −0 tests/misc/t16244.nim
  173. +2 −0 tests/misc/t16264.nim
  174. +12 −0 tests/misc/t16541.nim
  175. +19 −0 tests/misc/t19046.nim
  176. +13 −0 tests/misc/t21109.nim
  177. +4 −0 tests/misc/t6549.nim
  178. +28 −0 tests/misc/trfc405.nim
  179. +5 −0 tests/misc/trunner.nim
  180. +8 −3 tests/modules/timportas.nim
  181. +15 −0 tests/objects/t20972.nim
  182. +2 −2 tests/objects/tobjconstr2.nim
  183. +1 −1 tests/openarray/topenarray.nim
  184. +12 −0 tests/parallel/tsimple_array_checks.nim
  185. +9 −0 tests/parser/t12274.nim
  186. +46 −0 tests/parser/t20922.nim
  187. +17 −2 tests/parser/tdo.nim
  188. +41 −0 tests/pragmas/tcustom_pragma.nim
  189. +1 −1 tests/proc/tillegalreturntype.nim
  190. +29 −0 tests/sets/t15435.nim
  191. +18 −0 tests/sets/t20997.nim
  192. +8 −0 tests/statictypes/t20148.nim
  193. +20 −0 tests/statictypes/tstatictypes.nim
  194. +6 −2 tests/stdlib/tjsonutils.nim
  195. +58 −0 tests/stdlib/tmacros.nim
  196. +1 −1 tests/stdlib/tsequtils.nim
  197. +1 −1 tests/stdlib/tstrset.nim
  198. +7 −0 tests/stdlib/tstrutils.nim
  199. +12 −1 tests/stdlib/tsugar.nim
  200. +1 −0 tests/stylecheck/foreign_package/foreign_package.nim
  201. +2 −0 tests/stylecheck/foreign_package/foreign_package.nimble
  202. +16 −0 tests/stylecheck/tforeign_package.nim
  203. +43 −0 tests/stylecheck/thint.nim
  204. +7 −0 tests/system/tdollars.nim
  205. +22 −0 tests/template/mdotcall.nim
  206. +17 −0 tests/template/t11705.nim
  207. +19 −0 tests/template/t19149.nim
  208. +10 −0 tests/template/t19700.nim
  209. +10 −0 tests/template/tdotcall.nim
  210. +6 −0 tests/template/template_issues.nim
  211. +8 −0 tests/template/tinnerouterproc.nim
  212. +11 −0 tests/template/tunderscore1.nim
  213. +77 −28 tests/testdata/mycert.pem
  214. +1 −1 tests/typerel/tcommontype.nim
  215. +1 −1 tests/typerel/ttypelessemptyset.nim
  216. +11 −0 tests/types/t15836.nim
  217. +26 −0 tests/types/t15836_2.nim
  218. +5 −0 tests/types/t21027.nim
  219. +123 −0 tests/types/tcyclic.nim
  220. +1 −1 tests/types/tfinalobj.nim
  221. +2 −2 tests/types/tinheritref.nim
  222. +9 −0 tests/types/tnontype.nim
  223. +292 −0 tests/types/ttopdowninference.nim
  224. +77 −65 tests/untestable/thttpclient_ssl_remotenetwork.nim
  225. +11 −0 tests/views/tconst_views.nim
  226. +27 −0 tests/views/tviews1.nim
  227. +9 −0 tests/vm/t17121.nim
  228. +19 −0 tests/vm/t19075.nim
  229. +69 −0 tests/vm/t21704.nim
  230. +12 −0 tests/vm/tmisc_vm.nim
  231. +4 −0 tests/vm/topenarrays.nim
  232. +87 −3 tests/vm/tvmmisc.nim
  233. +21 −0 tests/whenstmt/t12517.nim
  234. +16 −0 tests/whenstmt/t19426.nim
12 changes: 6 additions & 6 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ jobs:
strategy:
matrix:
Linux_amd64:
vmImage: 'ubuntu-18.04'
vmImage: 'ubuntu-20.04'
CPU: amd64
# regularly breaks, refs bug #17325
Linux_i386:
# on 'ubuntu-16.04' (not supported anymore anyways) it errored with:
# g++-multilib : Depends: gcc-multilib (>= 4:5.3.1-1ubuntu1) but it is not going to be installed
vmImage: 'ubuntu-18.04'
CPU: i386
# Linux_i386:
# # on 'ubuntu-16.04' (not supported anymore anyways) it errored with:
# # g++-multilib : Depends: gcc-multilib (>= 4:5.3.1-1ubuntu1) but it is not going to be installed
# vmImage: 'ubuntu-20.04'
# CPU: i386
OSX_amd64:
vmImage: 'macOS-11'
CPU: amd64
Expand Down
2 changes: 1 addition & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
- `nim` can now compile version 1.4.0 as follows: `nim c --lib:lib --stylecheck:off compiler/nim`,
without requiring `-d:nimVersion140` which is now a noop.

- `--styleCheck` now only applies to the current package.
- `--styleCheck`, `--hintAsError` and `--warningAsError` now only applies to the current package.


## Tool changes
Expand Down
6 changes: 5 additions & 1 deletion ci/funs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ _nimNumCpu(){
# FreeBSD | macOS: $(sysctl -n hw.ncpu)
# OpenBSD: $(sysctl -n hw.ncpuonline)
# windows: $NUMBER_OF_PROCESSORS ?
echo $(nproc 2>/dev/null || sysctl -n hw.logicalcpu 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null || 1)
if env | grep -q '^NIMCORES='; then
echo $NIMCORES
else
echo $(nproc 2>/dev/null || sysctl -n hw.logicalcpu 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null || 1)
fi
}

_nimBuildCsourcesIfNeeded(){
Expand Down
31 changes: 24 additions & 7 deletions compiler/ast.nim
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ type
TNodeKinds* = set[TNodeKind]

type
TSymFlag* = enum # 48 flags!
TSymFlag* = enum # 49 flags!
sfUsed, # read access of sym (for warnings) or simply used
sfExported, # symbol is exported from module
sfFromGeneric, # symbol is instantiation of a generic; this is needed
Expand Down Expand Up @@ -300,6 +300,12 @@ type
sfSingleUsedTemp # For temporaries that we know will only be used once
sfNoalias # 'noalias' annotation, means C's 'restrict'
sfEffectsDelayed # an 'effectsDelayed' parameter
sfGeneratedType # A anonymous generic type that is generated by the compiler for
# objects that do not have generic parameters in case one of the
# object fields has one.
#
# This is disallowed but can cause the typechecking to go into
# an infinite loop, this flag is used as a sentinel to stop it.

TSymFlags* = set[TSymFlag]

Expand Down Expand Up @@ -499,6 +505,7 @@ type
nfLastRead # this node is a last read
nfFirstWrite# this node is a first write
nfHasComment # node has a comment
nfSkipFieldChecking # node skips field visable checking

TNodeFlags* = set[TNodeFlag]
TTypeFlag* = enum # keep below 32 for efficiency reasons (now: 45)
Expand Down Expand Up @@ -670,7 +677,7 @@ type
mInSet, mRepr, mExit,
mSetLengthStr, mSetLengthSeq,
mIsPartOf, mAstToStr, mParallel,
mSwap, mIsNil, mArrToSeq,
mSwap, mIsNil, mArrToSeq, mOpenArrayToSeq,
mNewString, mNewStringOfCap, mParseBiggestFloat,
mMove, mWasMoved, mDestroy, mTrace,
mDefault, mUnown, mFinished, mIsolate, mAccessEnv, mAccessTypeField, mReset,
Expand Down Expand Up @@ -704,8 +711,8 @@ type
mSymIsInstantiationOf, mNodeId, mPrivateAccess


# things that we can evaluate safely at compile time, even if not asked for it:
const
# things that we can evaluate safely at compile time, even if not asked for it:
ctfeWhitelist* = {mNone, mSucc,
mPred, mInc, mDec, mOrd, mLengthOpenArray,
mLengthStr, mLengthArray, mLengthSeq,
Expand Down Expand Up @@ -734,6 +741,9 @@ const
mEqSet, mLeSet, mLtSet, mMulSet, mPlusSet, mMinusSet,
mConStrStr, mAppendStrCh, mAppendStrStr, mAppendSeqElem,
mInSet, mRepr}

generatedMagics* = {mNone, mIsolate, mFinished, mOpenArrayToSeq}
## magics that are generated as normal procs in the backend

type
ItemId* = object
Expand Down Expand Up @@ -1062,7 +1072,8 @@ const
nfDotSetter, nfDotField,
nfIsRef, nfIsPtr, nfPreventCg, nfLL,
nfFromTemplate, nfDefaultRefsParam,
nfExecuteOnReload, nfLastRead, nfFirstWrite}
nfExecuteOnReload, nfLastRead,
nfFirstWrite, nfSkipFieldChecking}
namePos* = 0
patternPos* = 1 # empty except for term rewriting macros
genericParamsPos* = 2
Expand Down Expand Up @@ -1102,11 +1113,10 @@ const

proc getPIdent*(a: PNode): PIdent {.inline.} =
## Returns underlying `PIdent` for `{nkSym, nkIdent}`, or `nil`.
# xxx consider whether also returning the 1st ident for {nkOpenSymChoice, nkClosedSymChoice}
# which may simplify code.
case a.kind
of nkSym: a.sym.name
of nkIdent: a.ident
of nkOpenSymChoice, nkClosedSymChoice: a.sons[0].sym.name
else: nil

const
Expand Down Expand Up @@ -1507,7 +1517,7 @@ proc assignType*(dest, src: PType) =
# this fixes 'type TLock = TSysLock':
if src.sym != nil:
if dest.sym != nil:
dest.sym.flags.incl src.sym.flags-{sfExported}
dest.sym.flags.incl src.sym.flags-{sfUsed, sfExported}
if dest.sym.annex == nil: dest.sym.annex = src.sym.annex
mergeLoc(dest.sym.loc, src.sym.loc)
else:
Expand Down Expand Up @@ -1679,6 +1689,10 @@ proc transitionIntKind*(n: PNode, kind: range[nkCharLit..nkUInt64Lit]) =
transitionNodeKindCommon(kind)
n.intVal = obj.intVal

proc transitionIntToFloatKind*(n: PNode, kind: range[nkFloatLit..nkFloat128Lit]) =
transitionNodeKindCommon(kind)
n.floatVal = BiggestFloat(obj.intVal)

proc transitionNoneToSym*(n: PNode) =
transitionNodeKindCommon(nkSym)

Expand Down Expand Up @@ -2018,6 +2032,9 @@ template detailedInfo*(sym: PSym): string =
proc isInlineIterator*(typ: PType): bool {.inline.} =
typ.kind == tyProc and tfIterator in typ.flags and typ.callConv != ccClosure

proc isIterator*(typ: PType): bool {.inline.} =
typ.kind == tyProc and tfIterator in typ.flags

proc isClosureIterator*(typ: PType): bool {.inline.} =
typ.kind == tyProc and tfIterator in typ.flags and typ.callConv == ccClosure

Expand Down
32 changes: 21 additions & 11 deletions compiler/ccgexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1003,12 +1003,12 @@ proc genBoundsCheck(p: BProc; arr, a, b: TLoc) =
if reifiedOpenArray(arr.lode):
linefmt(p, cpsStmts,
"if ($2-$1 != -1 && " &
"($1 < 0 || $1 >= $3.Field1 || $2 < 0 || $2 >= $3.Field1)){ #raiseIndexError(); $4}$n",
"($1 < 0 || $1 >= $3.Field1 || $2 < 0 || $2 >= $3.Field1)){ #raiseIndexError4($1, $2, $3.Field1); $4}$n",
[rdLoc(a), rdLoc(b), rdLoc(arr), raiseInstr(p)])
else:
linefmt(p, cpsStmts,
"if ($2-$1 != -1 && ($1 < 0 || $1 >= $3Len_0 || $2 < 0 || $2 >= $3Len_0))" &
"{ #raiseIndexError(); $4}$n",
"{ #raiseIndexError4($1, $2, $3Len_0); $4}$n",
[rdLoc(a), rdLoc(b), rdLoc(arr), raiseInstr(p)])
of tyArray:
let first = intLiteral(firstOrd(p.config, ty))
Expand All @@ -1019,7 +1019,7 @@ proc genBoundsCheck(p: BProc; arr, a, b: TLoc) =
of tySequence, tyString:
linefmt(p, cpsStmts,
"if ($2-$1 != -1 && " &
"($1 < 0 || $1 >= $3 || $2 < 0 || $2 >= $3)){ #raiseIndexError(); $4}$n",
"($1 < 0 || $1 >= $3 || $2 < 0 || $2 >= $3)){ #raiseIndexError4($1, $2, $3); $4}$n",
[rdLoc(a), rdLoc(b), lenExpr(p, arr), raiseInstr(p)])
else: discard

Expand Down Expand Up @@ -1361,7 +1361,7 @@ proc rawGenNew(p: BProc, a: var TLoc, sizeExpr: Rope; needsInit: bool) =
p.module.s[cfsTypeInit3].addf("$1->finalizer = (void*)$2;$n", [ti, rdLoc(f)])

if a.storage == OnHeap and usesWriteBarrier(p.config):
if canFormAcycle(a.t):
if canFormAcycle(p.module.g.graph, a.t):
linefmt(p, cpsStmts, "if ($1) { #nimGCunrefRC1($1); $1 = NIM_NIL; }$n", [a.rdLoc])
else:
linefmt(p, cpsStmts, "if ($1) { #nimGCunrefNoCycle($1); $1 = NIM_NIL; }$n", [a.rdLoc])
Expand Down Expand Up @@ -1398,7 +1398,7 @@ proc genNewSeqAux(p: BProc, dest: TLoc, length: Rope; lenIsZero: bool) =
var call: TLoc
initLoc(call, locExpr, dest.lode, OnHeap)
if dest.storage == OnHeap and usesWriteBarrier(p.config):
if canFormAcycle(dest.t):
if canFormAcycle(p.module.g.graph, dest.t):
linefmt(p, cpsStmts, "if ($1) { #nimGCunrefRC1($1); $1 = NIM_NIL; }$n", [dest.rdLoc])
else:
linefmt(p, cpsStmts, "if ($1) { #nimGCunrefNoCycle($1); $1 = NIM_NIL; }$n", [dest.rdLoc])
Expand Down Expand Up @@ -1812,8 +1812,17 @@ proc genArrayLen(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
if op == mHigh: unaryExpr(p, e, d, "($1Len_0-1)")
else: unaryExpr(p, e, d, "$1Len_0")
else:
if op == mHigh: unaryExpr(p, e, d, "($1.Field1-1)")
else: unaryExpr(p, e, d, "$1.Field1")
let isDeref = a.kind in {nkHiddenDeref, nkDerefExpr}
if op == mHigh:
if isDeref:
unaryExpr(p, e, d, "($1->Field1-1)")
else:
unaryExpr(p, e, d, "($1.Field1-1)")
else:
if isDeref:
unaryExpr(p, e, d, "$1->Field1")
else:
unaryExpr(p, e, d, "$1.Field1")
of tyCstring:
if op == mHigh: unaryExpr(p, e, d, "($1 ? (#nimCStrLen($1)-1) : -1)")
else: unaryExpr(p, e, d, "($1 ? #nimCStrLen($1) : 0)")
Expand Down Expand Up @@ -1864,7 +1873,7 @@ proc genSetLengthSeq(p: BProc, e: PNode, d: var TLoc) =

initLoc(call, locCall, e, OnHeap)
if not p.module.compileToCpp:
const setLenPattern = "($3) #setLengthSeqV2(&($1)->Sup, $4, $2)"
const setLenPattern = "($3) #setLengthSeqV2(($1)?&($1)->Sup:NIM_NIL, $4, $2)"
call.r = ropecg(p.module, setLenPattern, [
rdLoc(a), rdLoc(b), getTypeDesc(p.module, t),
genTypeInfoV1(p.module, t.skipTypes(abstractInst), e.info)])
Expand Down Expand Up @@ -2036,7 +2045,7 @@ proc genSetOp(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
of mCard:
var a: TLoc
initLocExpr(p, e[1], a)
putIntoDest(p, d, e, ropecg(p.module, "#cardSet($1, $2)", [rdCharLoc(a), size]))
putIntoDest(p, d, e, ropecg(p.module, "#cardSet($1, $2)", [addrLoc(p.config, a), size]))
of mLtSet, mLeSet:
getTemp(p, getSysType(p.module.g.graph, unknownLineInfo, tyInt), i) # our counter
initLocExpr(p, e[1], a)
Expand Down Expand Up @@ -2384,7 +2393,7 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
genDollar(p, e, d, "#nimFloatToStr($1)")
of mCStrToStr: genDollar(p, e, d, "#cstrToNimstr($1)")
of mStrToStr, mUnown: expr(p, e[1], d)
of mIsolate, mFinished: genCall(p, e, d)
of generatedMagics: genCall(p, e, d)
of mEnumToStr:
if optTinyRtti in p.config.globalOptions:
genEnumToStr(p, e, d)
Expand Down Expand Up @@ -2979,7 +2988,8 @@ proc expr(p: BProc, n: PNode, d: var TLoc) =
if n[genericParamsPos].kind == nkEmpty:
var prc = n[namePos].sym
if useAliveDataFromDce in p.module.flags:
if p.module.alive.contains(prc.itemId.item) and prc.magic in {mNone, mIsolate, mFinished}:
if p.module.alive.contains(prc.itemId.item) and
prc.magic in generatedMagics:
genProc(p.module, prc)
elif prc.skipGenericOwner.kind == skModule and sfCompileTime notin prc.flags:
if ({sfExportc, sfCompilerProc} * prc.flags == {sfExportc}) or
Expand Down
3 changes: 2 additions & 1 deletion compiler/ccgstmts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ proc genClosureVar(p: BProc, a: PNode) =
genLineDir(p, a)
if immediateAsgn:
loadInto(p, a[0], a[2], v)
else:
elif sfNoInit notin a[0][1].sym.flags:
constructLoc(p, v)

proc genVarStmt(p: BProc, n: PNode) =
Expand Down Expand Up @@ -1592,6 +1592,7 @@ proc genAsgn(p: BProc, e: PNode, fastAsgn: bool) =
initLoc(a, locNone, le, OnUnknown)
a.flags.incl(lfEnforceDeref)
a.flags.incl(lfPrepareForMutation)
genLineDir(p, le) # it can be a nkBracketExpr, which may raise
expr(p, le, a)
a.flags.excl(lfPrepareForMutation)
if fastAsgn: incl(a.flags, lfNoDeepCopy)
Expand Down
6 changes: 3 additions & 3 deletions compiler/ccgtypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ proc genTypeInfoAuxBase(m: BModule; typ, origType: PType;
# compute type flags for GC optimization
var flags = 0
if not containsGarbageCollectedRef(typ): flags = flags or 1
if not canFormAcycle(typ): flags = flags or 2
if not canFormAcycle(m.g.graph, typ): flags = flags or 2
#else echo("can contain a cycle: " & typeToString(typ))
if flags != 0:
m.s[cfsTypeInit3].addf("$1.flags = $2;$n", [nameHcr, rope(flags)])
Expand Down Expand Up @@ -1312,7 +1312,7 @@ proc genHook(m: BModule; t: PType; info: TLineInfo; op: TTypeAttachedOp): Rope =
result = theProc.loc.r

when false:
if not canFormAcycle(t) and op == attachedTrace:
if not canFormAcycle(m.g.graph, t) and op == attachedTrace:
echo "ayclic but has this =trace ", t, " ", theProc.ast
else:
when false:
Expand All @@ -1339,7 +1339,7 @@ proc genTypeInfoV2Impl(m: BModule, t, origType: PType, name: Rope; info: TLineIn
let traceImpl = genHook(m, t, info, attachedTrace)

var flags = 0
if not canFormAcycle(t): flags = flags or 1
if not canFormAcycle(m.g.graph, 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.flags = $6;", [
name, destroyImpl, getTypeDesc(m, t), typeName,
Expand Down
Loading