Skip to content

Commit

Permalink
fixes regression in Nim - nim-lang/Nim#19078
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharycarter committed Nov 26, 2021
1 parent 14c784d commit 181791e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions compiler/condsyms.nim
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,4 @@ proc initDefines*(symbols: StringTableRef) =
defineSymbol("nimHasHintAll")
defineSymbol("nimHasTrace")
defineSymbol("nimHasEffectsOf")
defineSymbol("nimHasEnforceNoRaises")
4 changes: 3 additions & 1 deletion compiler/pragmas.nim
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const
wAsmNoStackFrame, wDiscardable, wNoInit, wCodegenDecl,
wGensym, wInject, wRaises, wEffectsOf, wTags, wLocks, wDelegator, wGcSafe,
wConstructor, wLiftLocals, wStackTrace, wLineTrace, wNoDestroy,
wRequires, wEnsures}
wRequires, wEnsures, wEnforceNoRaises}
converterPragmas* = procPragmas
methodPragmas* = procPragmas+{wBase}-{wImportCpp}
templatePragmas* = {wDeprecated, wError, wGensym, wInject, wDirty,
Expand Down Expand Up @@ -1781,6 +1781,8 @@ proc prepareSinglePragma(
result = pragmaProposition(c, it)
of wEnsures:
result = pragmaEnsures(c, it)
of wEnforceNoRaises:
sym.flags.incl sfNeverRaises
else:
result = newInvalidPragmaNode(c, it)
elif comesFromPush and whichKeyword(ident) != wInvalid:
Expand Down
2 changes: 1 addition & 1 deletion compiler/wordrecg.nim
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ type
wAsmNoStackFrame = "asmNoStackFrame", wImplicitStatic = "implicitStatic",
wGlobal = "global", wCodegenDecl = "codegenDecl", wUnchecked = "unchecked",
wGuard = "guard", wLocks = "locks", wPartial = "partial", wExplain = "explain",
wLiftLocals = "liftlocals",
wLiftLocals = "liftlocals", wEnforceNoRaises = "enforceNoRaises",

wAuto = "auto", wBool = "bool", wCatch = "catch", wChar = "char",
wClass = "class", wCompl = "compl", wConst_cast = "const_cast", wDefault = "default",
Expand Down
9 changes: 6 additions & 3 deletions lib/std/private/digitsutils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,17 @@ func addIntImpl(result: var string, x: uint64) {.inline.} =
dec next
addChars(result, tmp, next, tmp.len - next)

func addInt*(result: var string, x: uint64) =
when not defined(nimHasEnforceNoRaises):
{.pragma: enforceNoRaises.}

func addInt*(result: var string, x: uint64) {.enforceNoRaises.} =
when nimvm: addIntImpl(result, x)
else:
when not defined(js): addIntImpl(result, x)
else:
addChars(result, numToString(x))

proc addInt*(result: var string; x: int64) =
proc addInt*(result: var string; x: int64) {.enforceNoRaises.} =
## Converts integer to its string representation and appends it to `result`.
runnableExamples:
var s = "foo"
Expand All @@ -110,5 +113,5 @@ proc addInt*(result: var string; x: int64) =
addChars(result, numToString(x))
else: impl()

proc addInt*(result: var string; x: int) {.inline.} =
proc addInt*(result: var string; x: int) {.inline, enforceNoRaises.} =
addInt(result, int64(x))

0 comments on commit 181791e

Please sign in to comment.