Skip to content

Commit

Permalink
delete a lot of dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
krux02 committed Aug 20, 2019
1 parent 75baaa5 commit 9aef8a1
Show file tree
Hide file tree
Showing 87 changed files with 19 additions and 1,711 deletions.
11 changes: 0 additions & 11 deletions compiler/ast.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1333,10 +1333,6 @@ proc newType*(kind: TTypeKind, owner: PSym): PType =
result.lockLevel = UnspecifiedLockLevel
when debugIds:
registerId(result)
when false:
if result.id == 76426:
echo "KNID ", kind
writeStackTrace()

proc mergeLoc(a: var TLoc, b: TLoc) =
if a.k == low(a.k): a.k = b.k
Expand Down Expand Up @@ -1810,13 +1806,6 @@ proc findUnresolvedStatic*(n: PNode): PNode =

return nil

when false:
proc containsNil*(n: PNode): bool =
# only for debugging
if n.isNil: return true
for i in 0 ..< n.safeLen:
if n[i].containsNil: return true

template hasDestructor*(t: PType): bool = {tfHasAsgn, tfHasOwned} * t.flags != {}
template incompleteType*(t: PType): bool =
t.sym != nil and {sfForward, sfNoForward} * t.sym.flags == {sfForward}
Expand Down
11 changes: 0 additions & 11 deletions compiler/btrees.nim
Original file line number Diff line number Diff line change
Expand Up @@ -202,17 +202,6 @@ when isMainModule:
for k, v in st:
echo k, ": ", v

when false:
var b2 = initBTree[string, string]()
const iters = 10_000
for i in 1..iters:
b2.add($i, $(iters - i))
for i in 1..iters:
let x = b2.getOrDefault($i)
if x != $(iters - i):
echo "got ", x, ", but expected ", iters - i
echo b2.entries

when true:
var b2 = initBTree[int, string]()
var t2 = initTable[int, string]()
Expand Down
48 changes: 1 addition & 47 deletions compiler/ccgexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1003,23 +1003,7 @@ proc genAndOr(p: BProc, e: PNode, d: var TLoc, m: TMagic) =
# tmp = a
# end:
# a = tmp
when false:
#if isSimpleExpr(e) and p.module.compileToCpp:
var tmpA, tmpB: TLoc
#getTemp(p, e.typ, tmpA)
#getTemp(p, e.typ, tmpB)
initLocExprSingleUse(p, e.sons[1], tmpA)
initLocExprSingleUse(p, e.sons[2], tmpB)
tmpB.k = locExpr
if m == mOr:
tmpB.r = "((" & rdLoc(tmpA) & ")||(" & rdLoc(tmpB) & "))"
else:
tmpB.r = "((" & rdLoc(tmpA) & ")&&(" & rdLoc(tmpB) & "))"
if d.k == locNone:
d = tmpB
else:
genAssignment(p, d, tmpB, {})
else:
when true:
var
L: TLabel
tmp: TLoc
Expand Down Expand Up @@ -1063,11 +1047,6 @@ proc genEcho(p: BProc, n: PNode) =
var a: TLoc
initLocExpr(p, n, a)
linefmt(p, cpsStmts, "#echoBinSafe($1, $2);$n", [a.rdLoc, n.len])
when false:
p.module.includeHeader("<stdio.h>")
linefmt(p, cpsStmts, "printf($1$2);$n",
makeCString(repeat("%s", n.len) & "\L"), [args])
linefmt(p, cpsStmts, "fflush(stdout);$n", [])

proc gcUsage(conf: ConfigRef; n: PNode) =
if conf.selectedGC == gcNone: message(conf, n.info, warnGcMem, n.renderTree)
Expand Down Expand Up @@ -1511,10 +1490,6 @@ proc genOfHelper(p: BProc; dest: PType; a: Rope; info: TLineInfo): Rope =
let cache = "Nim_OfCheck_CACHE" & p.module.labels.rope
addf(p.module.s[cfsVars], "static TNimType* $#[2];$n", [cache])
result = ropecg(p.module, "#isObjWithCache($#.m_type, $#, $#)", [a, ti, cache])
when false:
# former version:
result = ropecg(p.module, "#isObj($1.m_type, $2)",
[a, genTypeInfo(p.module, dest, info)])

proc genOf(p: BProc, x: PNode, typ: PType, d: var TLoc) =
var a: TLoc
Expand Down Expand Up @@ -2059,23 +2034,6 @@ proc genDestroy(p: BProc; n: PNode) =
internalError(p.config, n.info, "destructor turned out to be not trivial")
discard "ignore calls to the default destructor"

proc genDispose(p: BProc; n: PNode) =
when false:
let elemType = n[1].typ.skipTypes(abstractVar).lastSon

var a: TLoc
initLocExpr(p, n[1].skipAddr, a)

if isFinal(elemType):
if elemType.destructor != nil:
var destroyCall = newNodeI(nkCall, n.info)
genStmts(p, destroyCall)
lineCg(p, cpsStmts, ["#nimRawDispose($#)", rdLoc(a)])
else:
# ``nimRawDisposeVirtual`` calls the ``finalizer`` which is the same as the
# destructor, but it uses the runtime type. Afterwards the memory is freed:
lineCg(p, cpsStmts, ["#nimDestroyAndDispose($#)", rdLoc(a)])

proc genEnumToStr(p: BProc, e: PNode, d: var TLoc) =
const ToStringProcSlot = -4
let t = e[1].typ.skipTypes(abstractInst)
Expand Down Expand Up @@ -2362,10 +2320,6 @@ proc genClosure(p: BProc, n: PNode, d: var TLoc) =
if n.sons[0].skipConv.kind == nkClosure:
internalError(p.config, n.info, "closure to closure created")
# tasyncawait.nim breaks with this optimization:
when false:
if d.k != locNone:
linefmt(p, cpsStmts, "$1.ClP_0 = $2; $1.ClE_0 = $3;$n",
[d.rdLoc, a.rdLoc, b.rdLoc])
else:
getTemp(p, n.typ, tmp)
linefmt(p, cpsStmts, "$1.ClP_0 = $2; $1.ClE_0 = $3;$n",
Expand Down
8 changes: 1 addition & 7 deletions compiler/ccgmerge.nim
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@ proc genMergeInfo*(m: BModule): Rope =
writeTypeCache(m.typeCache, s)
s.add("declared:{")
writeIntSet(m.declaredThings, s)
when false:
s.add("typeInfo:{")
writeIntSet(m.typeInfoMarker, s)
s.add("labels:")
encodeVInt(m.labels, s)
s.add(" flags:")
Expand Down Expand Up @@ -190,8 +187,6 @@ proc readTypeCache(L: var TBaseLexer, result: var TypeCache) =
inc L.bufpos
var value = decodeStr(L.buf, L.bufpos)
# XXX implement me
when false:
idTablePut(result, newFakeType(key), value.rope)
inc L.bufpos

proc readIntSet(L: var TBaseLexer, result: var IntSet) =
Expand All @@ -214,8 +209,7 @@ proc processMergeInfo(L: var TBaseLexer, m: BModule) =
case k
of "typeCache": readTypeCache(L, m.typeCache)
of "declared": readIntSet(L, m.declaredThings)
of "typeInfo":
when false: readIntSet(L, m.typeInfoMarker)
of "typeInfo": discard
of "labels": m.labels = decodeVInt(L.buf, L.bufpos)
of "flags":
m.flags = cast[set[CodegenFlag]](decodeVInt(L.buf, L.bufpos) != 0)
Expand Down
18 changes: 0 additions & 18 deletions compiler/ccgtypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,6 @@ proc mangleField(m: BModule; name: PIdent): string =
if isKeyword(name):
result.add "_0"

when false:
proc hashOwner(s: PSym): SigHash =
var m = s
while m.kind != skModule: m = m.owner
let p = m.owner
assert p.kind == skPackage
result = gDebugInfo.register(p.name.s, m.name.s)

proc mangleName(m: BModule; s: PSym): Rope =
result = s.loc.r
if result == nil:
Expand Down Expand Up @@ -743,16 +735,6 @@ proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet): Rope =
of 4: addf(m.s[cfsTypes], "typedef NI32 $1;$n", [result])
of 8: addf(m.s[cfsTypes], "typedef NI64 $1;$n", [result])
else: internalError(m.config, t.sym.info, "getTypeDescAux: enum")
when false:
let owner = hashOwner(t.sym)
if not gDebugInfo.hasEnum(t.sym.name.s, t.sym.info.line, owner):
var vals: seq[(string, int)] = @[]
for i in 0 ..< t.n.len:
assert(t.n.sons[i].kind == nkSym)
let field = t.n.sons[i].sym
vals.add((field.name.s, field.position.int))
gDebugInfo.registerEnum(EnumDesc(size: size, owner: owner, id: t.sym.id,
name: t.sym.name.s, values: vals))
of tyProc:
result = getTypeName(m, origTyp, sig)
m.typeCache[sig] = result
Expand Down
7 changes: 0 additions & 7 deletions compiler/cgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1842,13 +1842,6 @@ proc getCFile(m: BModule): AbsoluteFile =
else: ".nim.c"
result = changeFileExt(completeCfilePath(m.config, withPackageName(m.config, m.cfilename)), ext)

when false:
proc myOpenCached(graph: ModuleGraph; module: PSym, rd: PRodReader): PPassContext =
injectG()
var m = newModule(g, module, graph.config)
readMergeInfo(getCFile(m), m)
result = m

proc addHcrInitGuards(p: BProc, n: PNode, inInitGuard: var bool) =
if n.kind == nkStmtList:
for child in n:
Expand Down
1 change: 0 additions & 1 deletion compiler/condsyms.nim
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ proc initDefines*(symbols: StringTableRef) =
defineSymbol("nimDistros")
defineSymbol("nimHasCppDefine")
defineSymbol("nimGenericInOutFlags")
when false: defineSymbol("nimHasOpt")
defineSymbol("nimNoArrayToCstringConversion")
defineSymbol("nimNewRoof")
defineSymbol("nimHasRunnableExamples")
Expand Down
6 changes: 0 additions & 6 deletions compiler/dfa.nim
Original file line number Diff line number Diff line change
Expand Up @@ -705,12 +705,6 @@ proc genCall(c: var Con; n: PNode) =
inc c.inCall
for i in 1..<n.len:
gen(c, n[i])
when false:
if t != nil and i < t.len and t.sons[i].kind == tyVar:
# This is wrong! Pass by var is a 'might def', not a 'must def'
# like the other defs we emit. This is not good enough for a move
# optimizer.
genDef(c, n[i])
# every call can potentially raise:
if c.inTryStmt > 0 and canRaise(n[0]):
# we generate the instruction sequence:
Expand Down
17 changes: 0 additions & 17 deletions compiler/docgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -427,18 +427,6 @@ proc prepareExamples(d: PDoc; n: PNode) =
runnableExamples.info = n.info
for a in n.lastSon: runnableExamples.add a
testExample(d, runnableExamples)
when false:
proc extractImports(n: PNode; result: PNode) =
if n.kind in {nkImportStmt, nkImportExceptStmt, nkFromStmt}:
result.add copyTree(n)
n.kind = nkEmpty
return
for i in 0..<n.safeLen: extractImports(n[i], result)
let imports = newTree(nkStmtList)
var savedLastSon = copyTree n.lastSon
extractImports(savedLastSon, imports)
for imp in imports: runnableExamples.add imp
runnableExamples.add newTree(nkBlockStmt, newNode(nkEmpty), copyTree savedLastSon)

proc getAllRunnableExamplesRec(d: PDoc; n, orig: PNode; dest: var Rope) =
if n.info.fileIndex != orig.info.fileIndex: return
Expand Down Expand Up @@ -676,11 +664,6 @@ proc genItem(d: PDoc, n, nameNode: PNode, k: TSymKind) =
let docItemSeeSrc = getConfigVar(d.conf, "doc.item.seesrc")
if docItemSeeSrc.len > 0:
let path = relativeTo(AbsoluteFile toFullPath(d.conf, n.info), AbsoluteDir getCurrentDir(), '/')
when false:
let cwd = canonicalizePath(d.conf, getCurrentDir())
var path = toFullPath(d.conf, n.info)
if path.startsWith(cwd):
path = path[cwd.len+1 .. ^1].replace('\\', '/')
let gitUrl = getConfigVar(d.conf, "git.url")
if gitUrl.len > 0:
let defaultBranch =
Expand Down
8 changes: 0 additions & 8 deletions compiler/evaltempl.nim
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,6 @@ proc wrapInComesFrom*(info: TLineInfo; sym: PSym; res: PNode): PNode =
result.info = info
if result.kind in {nkStmtList, nkStmtListExpr} and result.len > 0:
result.lastSon.info = info
when false:
# this hack is required to
var x = result
while x.kind == nkStmtListExpr: x = x.lastSon
if x.kind in nkCallKinds:
for i in 1..<x.len:
if x[i].kind in nkCallKinds:
x.sons[i].info = info
else:
result = newNodeI(nkStmtListExpr, info)
var d = newNodeI(nkComesFrom, info)
Expand Down
4 changes: 0 additions & 4 deletions compiler/extccomp.nim
Original file line number Diff line number Diff line change
Expand Up @@ -712,10 +712,6 @@ proc getLinkCmd(conf: ConfigRef; output: AbsoluteFile,
let builddll = if isDllBuild: CC[conf.cCompiler].buildDll else: ""
let exefile = quoteShell(output)

when false:
if optCDebug in conf.globalOptions:
writeDebugInfo(exefile.changeFileExt("ndb"))

# Map files are required by Nintendo Switch compilation. They are a list
# of all function calls in the library and where they come from.
let mapfile = quoteShell(getNimcacheDir(conf) / RelativeFile(splitFile(output).name & ".map"))
Expand Down
6 changes: 0 additions & 6 deletions compiler/guards.nim
Original file line number Diff line number Diff line change
Expand Up @@ -918,12 +918,6 @@ proc pleViaModelRec(m: var TModel; a, b: PNode): TImplication =
result = impliesLe(fact, a, b)
if result != impUnknown:
return result
when false:
# given: x <= y; y==a; x <= a this means: a <= b if x <= b
if sameTree(y, a):
result = ple(m, b, x)
if result != impUnknown:
return result

proc pleViaModel(model: TModel; aa, bb: PNode): TImplication =
# compute replacements:
Expand Down
2 changes: 0 additions & 2 deletions compiler/importer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ proc importSymbol(c: PContext, n: PNode, fromMod: PSym) =
if s == nil:
errorUndeclaredIdentifier(c, n.info, ident.s)
else:
when false:
if s.kind == skStub: loadStub(s)
let multiImport = s.kind notin ExportableSymKinds or s.kind in skProcKinds
# for an enumeration we have to add all identifiers
if multiImport:
Expand Down
44 changes: 0 additions & 44 deletions compiler/injectdestructors.nim
Original file line number Diff line number Diff line change
Expand Up @@ -216,41 +216,6 @@ proc isLastRead(n: PNode; c: var Con): bool =
result = isLastRead(n, c, instr+1, -1) >= 0
dbg:
echo "ugh ", c.otherRead.isNil, " ", result

when false:
let s = n.sym
var pcs: seq[int] = @[instr+1]
var takenGotos: IntSet
var takenForks = initIntSet()
while pcs.len > 0:
var pc = pcs.pop

takenGotos = initIntSet()
while pc < c.g.len:
case c.g[pc].kind
of def:
if c.g[pc].sym == s:
# the path lead to a redefinition of 's' --> abandon it.
break
inc pc
of use:
if c.g[pc].sym == s:
c.otherRead = c.g[pc].n
return false
inc pc
of goto:
# we must leave endless loops eventually:
if not takenGotos.containsOrIncl(pc):
pc = pc + c.g[pc].dest
else:
inc pc
of fork:
# we follow the next instruction but push the dest onto our "work" stack:
if not takenForks.containsOrIncl(pc):
pcs.add pc + c.g[pc].dest
inc pc
of InstrKind.join:
inc pc
#echo c.graph.config $ n.info, " last read here!"
return true

Expand Down Expand Up @@ -340,15 +305,6 @@ proc genOp(c: Con; t: PType; kind: TTypeAttachedOp; dest, ri: PNode): PNode =
addrExp.add(dest)
result = newTree(nkCall, newSymNode(op), addrExp)

when false:
proc preventMoveRef(dest, ri: PNode): bool =
let lhs = dest.typ.skipTypes({tyGenericInst, tyAlias, tySink})
var ri = ri
if ri.kind in nkCallKinds and ri[0].kind == nkSym and ri[0].sym.magic == mUnown:
ri = ri[1]
let rhs = ri.typ.skipTypes({tyGenericInst, tyAlias, tySink})
result = lhs.kind == tyRef and rhs.kind == tyOwned

proc canBeMoved(t: PType): bool {.inline.} =
let t = t.skipTypes({tyGenericInst, tyAlias, tySink})
result = t.kind != tyRef and t.attachedOps[attachedSink] != nil
Expand Down
6 changes: 0 additions & 6 deletions compiler/jsgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1442,12 +1442,6 @@ proc genArgs(p: PProc, n: PNode, r: var TCompRes; start=1) =
inc emitted
hasArgs = true
add(r.res, ")")
when false:
# XXX look into this:
let jsp = countJsParams(typ)
if emitted != jsp and tfVarargs notin typ.flags:
localError(p.config, n.info, "wrong number of parameters emitted; expected: " & $jsp &
" but got: " & $emitted)
r.kind = resExpr

proc genOtherArg(p: PProc; n: PNode; i: int; typ: PType;
Expand Down
7 changes: 0 additions & 7 deletions compiler/lambdalifting.nim
Original file line number Diff line number Diff line change
Expand Up @@ -523,13 +523,6 @@ proc newEnvVar(cache: IdentCache; owner: PSym; typ: PType; info: TLineInfo): PNo
v.flags = {sfShadowed, sfGeneratedOp}
v.typ = typ
result = newSymNode(v)
when false:
if owner.kind == skIterator and owner.typ.callConv == ccClosure:
let it = getHiddenParam(owner)
addUniqueField(it.typ.sons[0], v)
result = indirectAccess(newSymNode(it), v, v.info)
else:
result = newSymNode(v)

proc setupEnvVar(owner: PSym; d: DetectionPass;
c: var LiftingPass; info: TLineInfo): PNode =
Expand Down
3 changes: 0 additions & 3 deletions compiler/liftdestructors.nim
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,6 @@ proc useSeqOrStrOp(c: var TLiftCtx; t: PType; body, x, y: PNode) =
moveCall.add destructorCall(c.g, t.destructor, x)
body.add moveCall
# alternatively we could do this:
when false:
doAssert t.asink != nil
body.add newAsgnCall(c.g, t.asink, x, y)
of attachedDestructor:
doAssert t.destructor != nil
body.add destructorCall(c.g, t.destructor, x)
Expand Down
Loading

0 comments on commit 9aef8a1

Please sign in to comment.