diff --git a/compiler/options.nim b/compiler/options.nim index 1873d9d5b4..f2701dadd4 100644 --- a/compiler/options.nim +++ b/compiler/options.nim @@ -120,7 +120,8 @@ type notnil, dynamicBindSym, forLoopMacros, - caseStmtMacros + caseStmtMacros, + codeReordering, SymbolFilesOption* = enum disabledSf, writeOnlySf, readOnlySf, v2Sf diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim index 263068344d..0ef87720d1 100644 --- a/compiler/pragmas.nim +++ b/compiler/pragmas.nim @@ -48,7 +48,7 @@ const wDeadCodeElimUnused, # deprecated, always on wDeprecated, wFloatchecks, wInfChecks, wNanChecks, wPragma, wEmit, wUnroll, - wLinearScanEnd, wPatterns, wEffects, wNoForward, wReorder, wComputedGoto, + wLinearScanEnd, wPatterns, wEffects, wComputedGoto, wInjectStmt, wDeprecated, wExperimental, wThis} lambdaPragmas* = {FirstCallConv..LastCallConv, wImportc, wExportc, wNodecl, wNosideeffect, wSideeffect, wNoreturn, wDynlib, wHeader, @@ -227,10 +227,6 @@ proc onOff(c: PContext, n: PNode, op: TOptions, resOptions: var TOptions) = if isTurnedOn(c, n): resOptions = resOptions + op else: resOptions = resOptions - op -proc pragmaNoForward(c: PContext, n: PNode; flag=sfNoForward) = - if isTurnedOn(c, n): incl(c.module.flags, flag) - else: excl(c.module.flags, flag) - proc processCallConv(c: PContext, n: PNode) = if n.kind in nkPragmaCallKinds and n.len == 2 and n.sons[1].kind == nkIdent: let sw = whichKeyword(n.sons[1].ident) @@ -724,7 +720,10 @@ proc processExperimental(c: PContext; n: PNode; s: PSym) = case n[1].kind of nkStrLit, nkRStrLit, nkTripleStrLit: try: - c.features.incl parseEnum[Feature](n[1].strVal) + let feature = parseEnum[Feature](n[1].strVal) + c.features.incl feature + if feature == codeReordering: + c.module.flags.incl sfReorder except ValueError: localError(c.config, n[1].info, "unknown experimental feature") else: @@ -815,8 +814,6 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int, noVal(c, it) incl(sym.flags, {sfThread, sfGlobal}) of wDeadCodeElimUnused: discard # deprecated, dead code elim always on - of wNoForward: pragmaNoForward(c, it) - of wReorder: pragmaNoForward(c, it, sfReorder) of wMagic: processMagic(c, it, sym) of wCompileTime: noVal(c, it) diff --git a/tests/misc/tnoforward.nim b/tests/misc/tnoforward.nim index 342e757b85..3e96e34890 100644 --- a/tests/misc/tnoforward.nim +++ b/tests/misc/tnoforward.nim @@ -2,7 +2,8 @@ discard """ disabled: true """ -{. noforward: on .} +# {. noforward: on .} +{.experimental: "codeReordering".} proc foo(x: int) = bar x diff --git a/tests/pragmas/treorder.nim b/tests/pragmas/treorder.nim index 1006af5274..659a6f644f 100644 --- a/tests/pragmas/treorder.nim +++ b/tests/pragmas/treorder.nim @@ -6,7 +6,8 @@ output:'''0 """ import macros -{.reorder: on .} +# {.reorder: on .} +{.experimental: "codeReordering".} echo foo(-1) echo callWithFoo(0) @@ -71,4 +72,4 @@ macro make(arg: untyped): untyped = proc first(i: int): void = make(second) -var ss {.compileTime.}: string = "" \ No newline at end of file +var ss {.compileTime.}: string = "" diff --git a/tests/pragmas/treorderdeclared.nim b/tests/pragmas/treorderdeclared.nim new file mode 100644 index 0000000000..67403471b0 --- /dev/null +++ b/tests/pragmas/treorderdeclared.nim @@ -0,0 +1,12 @@ +discard """ +output:'''false''' +""" + +{.experimental: "codeReordering".} + +proc x() = + echo(declared(foo)) + +var foo = 4 + +x() # "false", the same as it would be with code reordering OFF