mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-12 22:33:49 +00:00
new pragma: 'noinit'
This commit is contained in:
@@ -236,7 +236,8 @@ type
|
||||
|
||||
const
|
||||
sfFakeConst* = sfDeadCodeElim # const cannot be put into a data section
|
||||
sfDispatcher* = sfDeadCodeElim # copied method symbol is the dispatcher
|
||||
sfDispatcher* = sfDeadCodeElim # copied method symbol is the dispatcher
|
||||
sfNoInit* = sfMainModule # don't generate code to init the variable
|
||||
|
||||
type
|
||||
TTypeKind* = enum # order is important!
|
||||
|
||||
@@ -74,9 +74,9 @@ proc fillLoc(a: var TLoc, k: TLocKind, typ: PType, r: PRope, s: TStorageLoc) =
|
||||
a.s = s
|
||||
if a.r == nil: a.r = r
|
||||
|
||||
proc isSimpleConst(typ: PType): bool =
|
||||
result = not (skipTypes(typ, abstractVar).kind in
|
||||
{tyTuple, tyObject, tyArray, tyArrayConstr, tySet, tySequence})
|
||||
proc isSimpleConst(typ: PType): bool =
|
||||
result = skipTypes(typ, abstractVar).kind notin
|
||||
{tyTuple, tyObject, tyArray, tyArrayConstr, tySet, tySequence}
|
||||
|
||||
proc useHeader(m: BModule, sym: PSym) =
|
||||
if lfHeader in sym.loc.Flags:
|
||||
@@ -263,10 +263,11 @@ proc zeroTemp(p: BProc, loc: TLoc) =
|
||||
appcg(p, cpsStmts, "#genericReset((void*)$1, $2);$n",
|
||||
[addrLoc(loc), genTypeInfo(p.module, loc.t)])
|
||||
|
||||
proc initVariable(p: BProc, v: PSym) =
|
||||
var b = containsGarbageCollectedRef(v.typ)
|
||||
if b or v.ast == nil:
|
||||
zeroVar(p, v.loc, b)
|
||||
proc initVariable(p: BProc, v: PSym) =
|
||||
if sfNoInit notin v.flags:
|
||||
var b = containsGarbageCollectedRef(v.typ)
|
||||
if b or v.ast == nil:
|
||||
zeroVar(p, v.loc, b)
|
||||
|
||||
proc initTemp(p: BProc, tmp: var TLoc) =
|
||||
if containsGarbageCollectedRef(tmp.t) or isInvalidReturnType(tmp.t):
|
||||
|
||||
@@ -32,12 +32,13 @@ const
|
||||
iteratorPragmas* = {FirstCallConv..LastCallConv, wNosideEffect, wSideEffect,
|
||||
wImportc, wExportc, wNodecl, wMagic, wDeprecated, wBorrow, wExtern,
|
||||
wImportcpp, wImportobjc, wError, wDiscardable}
|
||||
stmtPragmas* = {wChecks, wObjChecks, wFieldChecks, wRangechecks, wBoundchecks,
|
||||
wOverflowchecks, wNilchecks, wAssertions, wWarnings, wHints, wLinedir,
|
||||
wStacktrace, wLinetrace, wOptimization, wHint, wWarning, wError, wFatal,
|
||||
wDefine, wUndef, wCompile, wLink, wLinkSys, wPure, wPush, wPop, wBreakpoint,
|
||||
wCheckpoint, wPassL, wPassC, wDeadCodeElim, wDeprecated, wFloatChecks,
|
||||
wInfChecks, wNanChecks, wPragma, wEmit, wUnroll, wLinearScanEnd}
|
||||
stmtPragmas* = {wChecks, wObjChecks, wFieldChecks, wRangechecks,
|
||||
wBoundchecks, wOverflowchecks, wNilchecks, wAssertions, wWarnings, wHints,
|
||||
wLinedir, wStacktrace, wLinetrace, wOptimization, wHint, wWarning, wError,
|
||||
wFatal, wDefine, wUndef, wCompile, wLink, wLinkSys, wPure, wPush, wPop,
|
||||
wBreakpoint, wCheckpoint, wPassL, wPassC, wDeadCodeElim, wDeprecated,
|
||||
wFloatChecks, wInfChecks, wNanChecks, wPragma, wEmit, wUnroll,
|
||||
wLinearScanEnd}
|
||||
lambdaPragmas* = {FirstCallConv..LastCallConv, wImportc, wExportc, wNodecl,
|
||||
wNosideEffect, wSideEffect, wNoreturn, wDynLib, wHeader,
|
||||
wDeprecated, wExtern, wThread, wImportcpp, wImportobjc, wNoStackFrame}
|
||||
@@ -48,7 +49,7 @@ const
|
||||
wImportcpp, wImportobjc, wError}
|
||||
varPragmas* = {wImportc, wExportc, wVolatile, wRegister, wThreadVar, wNodecl,
|
||||
wMagic, wHeader, wDeprecated, wCompilerProc, wDynLib, wExtern,
|
||||
wImportcpp, wImportobjc, wError}
|
||||
wImportcpp, wImportobjc, wError, wNoInit}
|
||||
constPragmas* = {wImportc, wExportc, wHeader, wDeprecated, wMagic, wNodecl,
|
||||
wExtern, wImportcpp, wImportobjc, wError}
|
||||
procTypePragmas* = {FirstCallConv..LastCallConv, wVarargs, wNosideEffect,
|
||||
@@ -556,6 +557,9 @@ proc pragma(c: PContext, sym: PSym, n: PNode, validPragmas: TSpecialWords) =
|
||||
of wDiscardable:
|
||||
noVal(it)
|
||||
if sym != nil: incl(sym.flags, sfDiscardable)
|
||||
of wNoInit:
|
||||
noVal(it)
|
||||
if sym != nil: incl(sym.flags, sfNoInit)
|
||||
of wChecks, wObjChecks, wFieldChecks, wRangechecks, wBoundchecks,
|
||||
wOverflowchecks, wNilchecks, wAssertions, wWarnings, wHints,
|
||||
wLinedir, wStacktrace, wLinetrace, wOptimization, wByRef,
|
||||
|
||||
@@ -50,7 +50,7 @@ type
|
||||
wHints, wOptimization, wSpeed, wSize, wNone,
|
||||
wDeadCodeElim, wSafecode,
|
||||
wPragma,
|
||||
wCompileTime,
|
||||
wCompileTime, wNoInit,
|
||||
wPassc, wPassl, wBorrow, wDiscardable,
|
||||
wFieldChecks,
|
||||
wCheckPoint, wSubsChar,
|
||||
@@ -96,7 +96,7 @@ const
|
||||
"optimization", "speed", "size", "none",
|
||||
"deadcodeelim", "safecode",
|
||||
"pragma",
|
||||
"compiletime",
|
||||
"compiletime", "noinit",
|
||||
"passc", "passl", "borrow", "discardable", "fieldchecks",
|
||||
"checkpoint",
|
||||
"subschar", "acyclic", "shallow", "unroll", "linearscanend",
|
||||
|
||||
@@ -1526,6 +1526,14 @@ T = enum cast[T](0); this may be an invalid value
|
||||
============================ ==============================================
|
||||
|
||||
|
||||
The implicit initialization can be avoided for optimization reasons with the
|
||||
`noinit`:idx: pragma:
|
||||
|
||||
.. code-block:: nimrod
|
||||
var
|
||||
a {.noInit.}: array [0..1023, char]
|
||||
|
||||
|
||||
Const section
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
@@ -1781,6 +1789,7 @@ sugar for:
|
||||
result = expr
|
||||
return result
|
||||
|
||||
|
||||
``return`` without an expression is a short notation for ``return result`` if
|
||||
the proc has a return type. The `result`:idx: variable is always the return
|
||||
value of the procedure. It is automatically declared by the compiler. As all
|
||||
|
||||
@@ -65,6 +65,8 @@ Language Additions
|
||||
a compile-time error.
|
||||
- There is a new ``discardable`` pragma that can be used to mark a routine
|
||||
so that its result can be discarded implicitely.
|
||||
- Added a new ``noinit`` pragma to prevent automatic initialization to zero
|
||||
of variables.
|
||||
- Constants can now have the type ``seq``.
|
||||
- There is a new user-definable syntactic construct ``a{i, ...}``
|
||||
that has no semantics yet for built-in types and so can be overloaded to your
|
||||
|
||||
Reference in New Issue
Block a user