Skip to content

Commit

Permalink
remove legacy code (#21134)
Browse files Browse the repository at this point in the history
* remove legacy code

* fixes
  • Loading branch information
ringabout authored Dec 26, 2022
1 parent b08c50b commit f7c203f
Show file tree
Hide file tree
Showing 27 changed files with 466 additions and 1,066 deletions.
3 changes: 0 additions & 3 deletions compiler/astalgo.nim
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ import strutils except addf
when defined(nimPreviewSlimSystem):
import std/assertions

when not defined(nimHasCursor):
{.pragma: cursor.}

proc hashNode*(p: RootRef): Hash
proc treeToYaml*(conf: ConfigRef; n: PNode, indent: int = 0, maxRecDepth: int = - 1): Rope
# Convert a tree into its YAML representation; this is used by the
Expand Down
2 changes: 0 additions & 2 deletions compiler/cgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1929,8 +1929,6 @@ template injectG() {.dirty.} =
graph.backend = newModuleList(graph)
let g = BModuleList(graph.backend)

when not defined(nimHasSinkInference):
{.pragma: nosinks.}

proc myOpen(graph: ModuleGraph; module: PSym; idgen: IdGenerator): PPassContext {.nosinks.} =
injectG()
Expand Down
47 changes: 24 additions & 23 deletions compiler/condsyms.nim
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,24 @@ proc initDefines*(symbols: StringTableRef) =
defineSymbol("nimHasSignatureHashInMacro") # deadcode
defineSymbol("nimHasDefault") # deadcode
defineSymbol("nimMacrosSizealignof") # deadcode
defineSymbol("nimNoZeroExtendMagic") # deadcode
defineSymbol("nimMacrosGetNodeId") # deadcode
defineSymbol("nimFixedForwardGeneric") # deadcode
defineSymbol("nimToOpenArrayCString") # deadcode
defineSymbol("nimHasUsed") # deadcode
defineSymbol("nimnomagic64") # deadcode
defineSymbol("nimNewShiftOps") # deadcode
defineSymbol("nimHasCursor") # deadcode
defineSymbol("nimAlignPragma") # deadcode
defineSymbol("nimHasExceptionsQuery") # deadcode
defineSymbol("nimHasIsNamedTuple") # deadcode
defineSymbol("nimHashOrdinalFixed") # deadcode
defineSymbol("nimHasSinkInference") # deadcode
defineSymbol("nimNewIntegerOps") # deadcode
defineSymbol("nimHasInvariant") # deadcode



# > 0.20.0
defineSymbol("nimNoZeroExtendMagic")
defineSymbol("nimMacrosGetNodeId")
for f in Feature:
defineSymbol("nimHas" & $f)

Expand All @@ -98,31 +112,18 @@ proc initDefines*(symbols: StringTableRef) =

defineSymbol("nimFixedOwned")
defineSymbol("nimHasStyleChecks")
defineSymbol("nimToOpenArrayCString")
defineSymbol("nimHasUsed")
defineSymbol("nimFixedForwardGeneric")
defineSymbol("nimnomagic64")
defineSymbol("nimNewShiftOps")
defineSymbol("nimHasCursor")
defineSymbol("nimAlignPragma")
defineSymbol("nimHasExceptionsQuery")
defineSymbol("nimHasIsNamedTuple")
defineSymbol("nimHashOrdinalFixed")

when defined(nimHasLibFFI):
# Renaming as we can't conflate input vs output define flags; e.g. this
# will report the right thing regardless of whether user adds
# `-d:nimHasLibFFI` in his user config.
defineSymbol("nimHasLibFFIEnabled")
defineSymbol("nimHasLibFFIEnabled") # deadcode

defineSymbol("nimHasSinkInference")
defineSymbol("nimNewIntegerOps")
defineSymbol("nimHasInvariant")
defineSymbol("nimHasStacktraceMsgs")
defineSymbol("nimHasStacktraceMsgs") # deadcode
defineSymbol("nimDoesntTrackDefects")
defineSymbol("nimHasLentIterators")
defineSymbol("nimHasDeclaredMagic")
defineSymbol("nimHasStacktracesModule")
defineSymbol("nimHasLentIterators") # deadcode
defineSymbol("nimHasDeclaredMagic") # deadcode
defineSymbol("nimHasStacktracesModule") # deadcode
defineSymbol("nimHasEffectTraitsModule")
defineSymbol("nimHasCastPragmaBlocks")
defineSymbol("nimHasDeclaredLocs")
Expand All @@ -133,8 +134,8 @@ proc initDefines*(symbols: StringTableRef) =
defineSymbol("nimHasCustomLiterals")
defineSymbol("nimHasUnifiedTuple")
defineSymbol("nimHasIterable")
defineSymbol("nimHasTypeofVoid")
defineSymbol("nimHasDragonBox")
defineSymbol("nimHasTypeofVoid") # deadcode
defineSymbol("nimHasDragonBox") # deadcode
defineSymbol("nimHasHintAll")
defineSymbol("nimHasTrace")
defineSymbol("nimHasEffectsOf")
Expand Down
3 changes: 0 additions & 3 deletions compiler/depends.nim
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ proc generateDot*(graph: ModuleGraph; project: AbsoluteFile) =
rope(project.splitFile.name), b.dotGraph],
changeFileExt(project, "dot"))

when not defined(nimHasSinkInference):
{.pragma: nosinks.}

proc myOpen(graph: ModuleGraph; module: PSym; idgen: IdGenerator): PPassContext {.nosinks.} =
var g: PGen
new(g)
Expand Down
7 changes: 3 additions & 4 deletions compiler/renderer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@

# This module implements the renderer of the standard Nim representation.

when defined(nimHasUsed):
# 'import renderer' is so useful for debugging
# that Nim shouldn't produce a warning for that:
{.used.}
# 'import renderer' is so useful for debugging
# that Nim shouldn't produce a warning for that:
{.used.}

import
lexer, options, idents, strutils, ast, msgs, lineinfos
Expand Down
3 changes: 0 additions & 3 deletions compiler/sem.nim
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,6 @@ proc semExprFlagDispatched(c: PContext, n: PNode, flags: TExprFlags; expectedTyp
evaluated = evalAtCompileTime(c, result)
if evaluated != nil: return evaluated

when not defined(nimHasSinkInference):
{.pragma: nosinks.}

include hlo, seminst, semcall

proc resetSemFlag(n: PNode) =
Expand Down
2 changes: 0 additions & 2 deletions compiler/sigmatch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2661,8 +2661,6 @@ proc argtypeMatches*(c: PContext, f, a: PType, fromHlo = false): bool =
# pattern templates do not allow for conversions except from int literal
res != nil and m.convMatches == 0 and m.intConvMatches in [0, 256]

when not defined(nimHasSinkInference):
{.pragma: nosinks.}

proc instTypeBoundOp*(c: PContext; dc: PSym; t: PType; info: TLineInfo;
op: TTypeAttachedOp; col: int): PSym {.nosinks.} =
Expand Down
5 changes: 0 additions & 5 deletions compiler/vm.nim
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ const
when hasFFI:
import evalffi

when not defined(nimHasCursor):
{.pragma: cursor.}

proc stackTraceAux(c: PCtx; x: PStackFrame; pc: int; recursionLimit=100) =
if x != nil:
Expand Down Expand Up @@ -533,9 +531,6 @@ template maybeHandlePtr(node2: PNode, reg: TFullReg, isAssign2: bool): bool =
else:
false

when not defined(nimHasSinkInference):
{.pragma: nosinks.}

template takeAddress(reg, source) =
reg.nodeAddr = addr source
GC_ref source
Expand Down
78 changes: 38 additions & 40 deletions compiler/vmops.nim
Original file line number Diff line number Diff line change
Expand Up @@ -141,41 +141,40 @@ proc staticWalkDirImpl(path: string, relative: bool): PNode =
for k, f in walkDir(path, relative):
result.add toLit((k, f))

when defined(nimHasInvariant):
from std / compilesettings import SingleValueSetting, MultipleValueSetting

proc querySettingImpl(conf: ConfigRef, switch: BiggestInt): string =
{.push warning[Deprecated]:off.}
case SingleValueSetting(switch)
of arguments: result = conf.arguments
of outFile: result = conf.outFile.string
of outDir: result = conf.outDir.string
of nimcacheDir: result = conf.getNimcacheDir().string
of projectName: result = conf.projectName
of projectPath: result = conf.projectPath.string
of projectFull: result = conf.projectFull.string
of command: result = conf.command
of commandLine: result = conf.commandLine
of linkOptions: result = conf.linkOptions
of compileOptions: result = conf.compileOptions
of ccompilerPath: result = conf.cCompilerPath
of backend: result = $conf.backend
of libPath: result = conf.libpath.string
of gc: result = $conf.selectedGC
of mm: result = $conf.selectedGC
{.pop.}

proc querySettingSeqImpl(conf: ConfigRef, switch: BiggestInt): seq[string] =
template copySeq(field: untyped): untyped =
for i in field: result.add i.string

case MultipleValueSetting(switch)
of nimblePaths: copySeq(conf.nimblePaths)
of searchPaths: copySeq(conf.searchPaths)
of lazyPaths: copySeq(conf.lazyPaths)
of commandArgs: result = conf.commandArgs
of cincludes: copySeq(conf.cIncludes)
of clibs: copySeq(conf.cLibs)
from std / compilesettings import SingleValueSetting, MultipleValueSetting

proc querySettingImpl(conf: ConfigRef, switch: BiggestInt): string =
{.push warning[Deprecated]:off.}
case SingleValueSetting(switch)
of arguments: result = conf.arguments
of outFile: result = conf.outFile.string
of outDir: result = conf.outDir.string
of nimcacheDir: result = conf.getNimcacheDir().string
of projectName: result = conf.projectName
of projectPath: result = conf.projectPath.string
of projectFull: result = conf.projectFull.string
of command: result = conf.command
of commandLine: result = conf.commandLine
of linkOptions: result = conf.linkOptions
of compileOptions: result = conf.compileOptions
of ccompilerPath: result = conf.cCompilerPath
of backend: result = $conf.backend
of libPath: result = conf.libpath.string
of gc: result = $conf.selectedGC
of mm: result = $conf.selectedGC
{.pop.}

proc querySettingSeqImpl(conf: ConfigRef, switch: BiggestInt): seq[string] =
template copySeq(field: untyped): untyped =
for i in field: result.add i.string

case MultipleValueSetting(switch)
of nimblePaths: copySeq(conf.nimblePaths)
of searchPaths: copySeq(conf.searchPaths)
of lazyPaths: copySeq(conf.lazyPaths)
of commandArgs: result = conf.commandArgs
of cincludes: copySeq(conf.cIncludes)
of clibs: copySeq(conf.cLibs)

proc stackTrace2(c: PCtx, msg: string, n: PNode) =
stackTrace(c, PStackFrame(prc: c.prc.sym, comesFrom: 0, next: nil), c.exceptionInstr, msg, n.info)
Expand Down Expand Up @@ -257,11 +256,10 @@ proc registerAdditionalOps*(c: PCtx) =
systemop getCurrentException
registerCallback c, "stdlib.*.staticWalkDir", proc (a: VmArgs) {.nimcall.} =
setResult(a, staticWalkDirImpl(getString(a, 0), getBool(a, 1)))
when defined(nimHasInvariant):
registerCallback c, "stdlib.compilesettings.querySetting", proc (a: VmArgs) =
setResult(a, querySettingImpl(c.config, getInt(a, 0)))
registerCallback c, "stdlib.compilesettings.querySettingSeq", proc (a: VmArgs) =
setResult(a, querySettingSeqImpl(c.config, getInt(a, 0)))
registerCallback c, "stdlib.compilesettings.querySetting", proc (a: VmArgs) =
setResult(a, querySettingImpl(c.config, getInt(a, 0)))
registerCallback c, "stdlib.compilesettings.querySettingSeq", proc (a: VmArgs) =
setResult(a, querySettingSeqImpl(c.config, getInt(a, 0)))

if defined(nimsuggest) or c.config.cmd == cmdCheck:
discard "don't run staticExec for 'nim suggest'"
Expand Down
9 changes: 4 additions & 5 deletions lib/core/macros.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1519,11 +1519,10 @@ proc boolVal*(n: NimNode): bool {.noSideEffect.} =
if n.kind == nnkIntLit: n.intVal != 0
else: n == bindSym"true" # hacky solution for now

when defined(nimMacrosGetNodeId):
proc nodeID*(n: NimNode): int {.magic: "NodeId".}
## Returns the id of `n`, when the compiler has been compiled
## with the flag `-d:useNodeids`, otherwise returns `-1`. This
## proc is for the purpose to debug the compiler only.
proc nodeID*(n: NimNode): int {.magic: "NodeId".}
## Returns the id of `n`, when the compiler has been compiled
## with the flag `-d:useNodeids`, otherwise returns `-1`. This
## proc is for the purpose to debug the compiler only.

macro expandMacros*(body: typed): untyped =
## Expands one level of macro - useful for debugging.
Expand Down
3 changes: 0 additions & 3 deletions lib/pure/collections/lists.nim
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ import std/private/since
when defined(nimPreviewSlimSystem):
import std/assertions

when not defined(nimHasCursor):
{.pragma: cursor.}

type
DoublyLinkedNodeObj*[T] = object
## A node of a doubly linked list.
Expand Down
40 changes: 10 additions & 30 deletions lib/pure/hashes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -380,16 +380,10 @@ proc hash*(x: string): Hash =
runnableExamples:
doAssert hash("abracadabra") != hash("AbracadabrA")

when not defined(nimToOpenArrayCString):
result = 0
for c in x:
result = result !& ord(c)
result = !$result
when nimvm:
result = hashVmImpl(x, 0, high(x))
else:
when nimvm:
result = hashVmImpl(x, 0, high(x))
else:
result = murmurHash(toOpenArrayByte(x, 0, high(x)))
result = murmurHash(toOpenArrayByte(x, 0, high(x)))

proc hash*(x: cstring): Hash =
## Efficient hashing of null-terminated strings.
Expand All @@ -398,22 +392,14 @@ proc hash*(x: cstring): Hash =
doAssert hash(cstring"AbracadabrA") == hash("AbracadabrA")
doAssert hash(cstring"abracadabra") != hash(cstring"AbracadabrA")

when not defined(nimToOpenArrayCString):
result = 0
var i = 0
while x[i] != '\0':
result = result !& ord(x[i])
inc i
result = !$result
when nimvm:
hashVmImpl(x, 0, high(x))
else:
when nimvm:
hashVmImpl(x, 0, high(x))
when not defined(js):
murmurHash(toOpenArrayByte(x, 0, x.high))
else:
when not defined(js) and defined(nimToOpenArrayCString):
murmurHash(toOpenArrayByte(x, 0, x.high))
else:
let xx = $x
murmurHash(toOpenArrayByte(xx, 0, high(xx)))
let xx = $x
murmurHash(toOpenArrayByte(xx, 0, high(xx)))

proc hash*(sBuf: string, sPos, ePos: int): Hash =
## Efficient hashing of a string buffer, from starting
Expand All @@ -424,13 +410,7 @@ proc hash*(sBuf: string, sPos, ePos: int): Hash =
var a = "abracadabra"
doAssert hash(a, 0, 3) == hash(a, 7, 10)

when not defined(nimToOpenArrayCString):
result = 0
for i in sPos..ePos:
result = result !& ord(sBuf[i])
result = !$result
else:
murmurHash(toOpenArrayByte(sBuf, sPos, ePos))
murmurHash(toOpenArrayByte(sBuf, sPos, ePos))

proc hashIgnoreStyle*(x: string): Hash =
## Efficient hashing of strings; style is ignored.
Expand Down
Loading

0 comments on commit f7c203f

Please sign in to comment.