Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…#411 #412 #413

392: internal: remove sons from leaf nodes empty/none r=disruptek a=saem

## Summary
- pulls nkEmpty and nkNone into a branch without sons
- ensures more correctness by design

## Details
- various small fixes to get bootstrap working
- no tests failed, so that's a good{?} sign



395: stdlib: remove deprecated modules r=disruptek a=saem

deprecated stdlib module removal:
- removed events, LockFreeHash, parseopt2, and securehash
- associated clean-up in testament
- lib/deprecate/pure now only contains ospaths, an include for os
- remove events related tests

396: lang: remove deprecated c/C octal prefix r=disruptek a=saem

## Summary
- can no longer use 0c1
- this has long since been deprecated and not referenced in the manual


397: macros: remove deprecated TNimSym/TypeKinds r=disruptek a=saem

## Summary
- Removed macros.TNimSym and macros.TypeKinds

## Details
They are not used anywhere in the code base

399: dialect: remove old case object define r=disruptek a=saem

## Summary
- removed old case object define

NB reset magic is still present


401: stdlib: httpcore ==(string, HttpCode):bool removed r=disruptek a=saem

dropped proc from stdlib, it been deprecatd forever

402: stdlib: removed deprecated module oswalkdir r=disruptek a=saem

functionality has long since been moved to `std/os`

403: stdlib: times, remove deprecated procs r=disruptek a=saem

Removed deprecated constructors and setters for `times.DateTime`

Updated associated broken tests.

405: stdlib: remove deprecated os.existsFile/Dir r=disruptek a=saem

fileExists/dirExists are already present

406: pragma: remove the deprecated unroll pragma r=disruptek a=saem

supposedly it was ignored by the compiler, the fewer pragmas the better.

407: strutils: remove deprecated delete proc r=disruptek a=saem

## Summary

- remove deprecated `delete(var string, int, int)`
- removed associated tests
- updated usage of removed proc in rstgen

409: sequtils: remove deprecated delete proc r=disruptek a=saem

remove deprecated `delete[T](var T, int, int)` and its tests

410: algorithm: remove deprecated reversed proc r=disruptek a=saem

## Summary

- remove deprecated `reversed[T](var openArray[T], int, int): seq[T]`
- removed associated tests


411: math: renamed internal c_frexp2 to c_frexp r=disruptek a=saem

internal proc rename, no impact

412: options: remove deprecated UnpackError r=disruptek a=saem

## Summary

Removed UnpackError, was replaced with UnpackDefect a while back

## Details

Defects in general are a bad idea, but less code is good too

413: lang: remove for loop and case statement macros r=disruptek a=saem

There are better ways to do these sorts of things.

Co-authored-by: Saem Ghani <saemghani+github@gmail.com>
  • Loading branch information
bors[bot] and saem authored Aug 6, 2022
Show file tree
Hide file tree
Showing 57 changed files with 158 additions and 1,774 deletions.
7 changes: 5 additions & 2 deletions compiler/ast/ast.nim
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,10 @@ proc addSonNilAllowed*(father, son: PNode) =
father.sons.add(son)

proc delSon*(father: PNode, idx: int) =
if father.len == 0: return
for i in idx..<father.len - 1: father[i] = father[i + 1]
if father.len == 0:
return
for i in idx..<father.len - 1:
father[i] = father[i + 1]
father.sons.setLen(father.len - 1)

template copyNodeImpl(dst, src, processSonsStmt) =
Expand All @@ -451,6 +453,7 @@ template copyNodeImpl(dst, src, processSonsStmt) =
of nkSym: dst.sym = src.sym
of nkIdent: dst.ident = src.ident
of nkStrLit..nkTripleStrLit: dst.strVal = src.strVal
of nkEmpty, nkNone: discard # no children, nothing to do
else: processSonsStmt

proc copyNode*(src: PNode): PNode =
Expand Down
21 changes: 15 additions & 6 deletions compiler/ast/ast_types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,8 @@ type
sym*: PSym
of nkIdent:
ident*: PIdent
of nkEmpty, nkNone:
discard
else:
sons*: TNodeSeq

Expand Down Expand Up @@ -890,8 +892,6 @@ type

PScope* = ref TScope



PLib* = ref TLib
TSym* {.acyclic.} = object of TIdObj # Keep in sync with PackedSym
## proc and type instantiations are cached in the generic symbol
Expand Down Expand Up @@ -1032,7 +1032,14 @@ type
TImplication* = enum
impUnknown, impNo, impYes


const
nkWithoutSons* =
{nkCharLit..nkUInt64Lit} +
{nkFloatLit..nkFloat128Lit} +
{nkStrLit..nkTripleStrLit} +
{nkSym} +
{nkIdent} +
{nkEmpty, nkNone}

type
EffectsCompat* = enum
Expand Down Expand Up @@ -1118,7 +1125,7 @@ type

type Indexable* = PNode | PType

proc len*(n: Indexable): int {.inline.} =
func len*(n: Indexable): int {.inline.} =
result = n.sons.len

proc add*(father, son: Indexable) =
Expand All @@ -1128,8 +1135,10 @@ proc add*(father, son: Indexable) =
template `[]`*(n: Indexable, i: int): Indexable = n.sons[i]
template `[]=`*(n: Indexable, i: int; x: Indexable) = n.sons[i] = x

template `[]`*(n: Indexable, i: BackwardsIndex): Indexable = n[n.len - i.int]
template `[]=`*(n: Indexable, i: BackwardsIndex; x: Indexable) = n[n.len - i.int] = x
template `[]`*(n: Indexable, i: BackwardsIndex): Indexable =
n[n.len - i.int]
template `[]=`*(n: Indexable, i: BackwardsIndex; x: Indexable) =
n[n.len - i.int] = x

const emptyReportId* = ReportId(0)

Expand Down
17 changes: 3 additions & 14 deletions compiler/ast/lexer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,7 @@ proc getNumber(L: var Lexer, result: var Token) =
isBase10 = true
numDigits = 0
const
# 'c', 'C' is deprecated
baseCodeChars = {'X', 'x', 'o', 'b', 'B', 'c', 'C'}
baseCodeChars = {'X', 'x', 'o', 'b', 'B'}
literalishChars = baseCodeChars + {'A'..'F', 'a'..'f', '0'..'9', '_', '\''}
floatTypes = {tkFloatLit, tkFloat32Lit, tkFloat64Lit, tkFloat128Lit}
result.tokType = tkIntLit # int literal until we know better
Expand All @@ -378,19 +377,10 @@ proc getNumber(L: var Lexer, result: var Token) =
field = (if isPositive: value else: -value)

# First stage: find out base, make verifications, build token literal string
# {'c', 'C'} is added for deprecation reasons to provide a clear error message
if L.buf[L.bufpos] == '0' and L.buf[L.bufpos + 1] in baseCodeChars + {'c', 'C', 'O'}:
if L.buf[L.bufpos] == '0' and L.buf[L.bufpos + 1] in baseCodeChars + {'O'}:
isBase10 = false
eatChar(L, result, '0')
case L.buf[L.bufpos]
of 'c', 'C':
lexMessageLitNum(L,
"$1 will soon be invalid for oct literals; Use '0o' " &
"for octals. 'c', 'C' prefix",
startpos,
rlexDeprecatedOctalPrefix)
eatChar(L, result, 'c')
numDigits = matchUnderscoreChars(L, result, {'0'..'7'})
of 'O':
lexMessageLitNum(L, "$1 is an invalid int literal; For octal literals " &
"use the '0o' prefix.", startpos, rlexInvalidIntegerPrefix)
Expand Down Expand Up @@ -484,8 +474,7 @@ proc getNumber(L: var Lexer, result: var Token) =
if L.buf[pos] != '_':
xi = `shl`(xi, 1) or (ord(L.buf[pos]) - ord('0'))
inc(pos)
# 'c', 'C' is deprecated (a warning is issued elsewhere)
of 'o', 'c', 'C':
of 'o':
result.base = base8
while pos < endpos:
if L.buf[pos] != '_':
Expand Down
3 changes: 1 addition & 2 deletions compiler/ast/trees.nim
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ proc findPragma*(n: PNode, which: TSpecialWord): PNode =
return son

proc effectSpec*(n: PNode, effectType: TSpecialWord): PNode =
for i in 0..<n.len:
var it = n[i]
for it in n:
if it.kind == nkExprColonExpr and whichPragma(it) == effectType:
result = it[1]
if result.kind notin {nkCurly, nkBracket}:
Expand Down
2 changes: 1 addition & 1 deletion compiler/ast/wordrecg.nim
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ type
wCompileTime = "compileTime", wNoInit = "noinit", wPassc = "passc", wPassl = "passl",
wLocalPassc = "localPassC", wBorrow = "borrow", wDiscardable = "discardable",
wFieldChecks = "fieldChecks", wSubsChar = "subschar", wAcyclic = "acyclic",
wShallow = "shallow", wUnroll = "unroll", wLinearScanEnd = "linearScanEnd",
wShallow = "shallow", wLinearScanEnd = "linearScanEnd",
wComputedGoto = "computedGoto", wExperimental = "experimental",
wWrite = "write", wGensym = "gensym", wInject = "inject", wDirty = "dirty",
wInheritable = "inheritable", wThreadVar = "threadvar", wEmit = "emit",
Expand Down
3 changes: 0 additions & 3 deletions compiler/front/in_options.nim
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,6 @@ type
destructor,
notnil,
dynamicBindSym,
forLoopMacros, ## not experimental anymore; remains here for backwards
## compatibility
caseStmtMacros,## ditto
vmopsDanger,
strictFuncs,
views,
Expand Down
2 changes: 1 addition & 1 deletion compiler/sem/evaltempl.nim
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ proc evalTemplateArgs(n: PNode, s: PSym; conf: ConfigRef; fromHlo: bool): PNode
# wiser to just deprecate immediate templates and macros
# now that we have working untyped parameters.
genericParams = if fromHlo: 0
else: s.ast[genericParamsPos].len
else: s.ast[genericParamsPos].safeLen
expectedRegularParams = s.typ.len-1
givenRegularParams = totalParams - genericParams
if givenRegularParams < 0: givenRegularParams = 0
Expand Down
21 changes: 2 additions & 19 deletions compiler/sem/pragmas.nim
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const
wPassl, wPassc, wLocalPassc,
wDeadCodeElimUnused, # deprecated, always on
wDeprecated,
wFloatChecks, wInfChecks, wNanChecks, wPragma, wEmit, wUnroll,
wFloatChecks, wInfChecks, wNanChecks, wPragma, wEmit,
wLinearScanEnd, wPatterns, wTrMacros, wEffects, wComputedGoto,
wExperimental, wThis, wUsed, wAssert}
lambdaPragmas* = {FirstCallConv..LastCallConv,
Expand Down Expand Up @@ -154,8 +154,7 @@ proc pragmaAsm*(c: PContext, n: PNode): tuple[marker: char, err: PNode] =
## Returns ` as the default marker if no other markers are found
result.marker = '`'
if n != nil:
for i in 0..<n.len:
let it = n[i]
for it in n:
if it.kind in nkPragmaCallKinds and it.len == 2 and it[0].kind == nkIdent:
case whichKeyword(it[0].ident)
of wSubsChar:
Expand Down Expand Up @@ -826,20 +825,6 @@ proc noVal(c: PContext; n: PNode): PNode =
else:
n

proc pragmaUnroll(c: PContext, n: PNode): PNode =
result = n
if c.p.nestedLoopCounter <= 0:
result = invalidPragma(c, n)
elif n.kind in nkPragmaCallKinds and n.len == 2:
var (unrollFactor, err) = intLitToIntOrErr(c, n)
if err.isNil:
if unrollFactor <% 32:
n[1] = newIntNode(nkIntLit, unrollFactor)
else:
result = invalidPragma(c, n)
else:
result = err

proc pragmaLine(c: PContext, n: PNode): PNode =
result = n
if n.kind in nkPragmaCallKinds and n.len == 2:
Expand Down Expand Up @@ -1650,8 +1635,6 @@ proc prepareSinglePragma(
sym.typ.flags.incl tfExplicitCallConv
of wEmit:
result = pragmaEmit(c, it)
of wUnroll:
result = pragmaUnroll(c, it)
of wLinearScanEnd, wComputedGoto:
result = noVal(c, it)
of wEffects:
Expand Down
7 changes: 4 additions & 3 deletions compiler/sem/sem.nim
Original file line number Diff line number Diff line change
Expand Up @@ -581,8 +581,9 @@ proc semMacroExpr(c: PContext, n: PNode, sym: PSym,
if sym == c.p.owner:
globalReport(c.config, info, reportSym(rsemCyclicDependency, sym))

let genericParams = sym.ast[genericParamsPos].len
let suppliedParams = max(n.safeLen - 1, 0)
let
genericParams = sym.ast[genericParamsPos].safeLen
suppliedParams = max(n.safeLen - 1, 0)

if suppliedParams < genericParams:
globalReport(
Expand All @@ -604,7 +605,7 @@ proc semMacroExpr(c: PContext, n: PNode, sym: PSym,
c.config.localReport(n.info, SemReport(
sym: sym,
kind: rsemExpandMacro,
ast: n,
ast: original,
expandedAst: result))

result = wrapInComesFrom(n.info, sym, result)
Expand Down
5 changes: 3 additions & 2 deletions compiler/sem/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1711,13 +1711,14 @@ proc maybeInstantiateGeneric(c: PContext, n: PNode, s: PSym): PNode =
## Instantiates generic if not lacking implicit generics,
## otherwise returns n.
let
neededGenParams = s.ast[genericParamsPos].len
neededGenParams = s.ast[genericParamsPos].safeLen # might be an nkEmpty
heldGenParams = n.len - 1
var implicitParams = 0
for x in s.ast[genericParamsPos]:
if tfImplicitTypeParam in x.typ.flags:
inc implicitParams
if heldGenParams != neededGenParams and implicitParams + heldGenParams == neededGenParams:
if heldGenParams != neededGenParams and
implicitParams + heldGenParams == neededGenParams:
# This is an implicit + explicit generic procedure without all args passed,
# kicking back the sem'd symbol fixes #17212
# Uncertain the hackiness of this solution.
Expand Down
78 changes: 0 additions & 78 deletions compiler/sem/semstmts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1614,83 +1614,8 @@ proc isTrivalStmtExpr(n: PNode): bool =
return false
result = true

proc handleStmtMacro(c: PContext; n, selector: PNode; magicType: string;
flags: TExprFlags): PNode =
if selector.kind in nkCallKinds:
# we transform
# n := for a, b, c in m(x, y, z): Y
# to
# m(n)
let maType = magicsys.getCompilerProc(c.graph, magicType)
if maType == nil: return

let headSymbol = selector[0]
var o: TOverloadIter
var match: PSym = nil
var symx = initOverloadIter(o, c, headSymbol)
while symx != nil:
if symx.kind in {skTemplate, skMacro}:
if symx.typ.len == 2 and symx.typ[1] == maType.typ:
if match == nil:
match = symx
else:
localReport(
c.config, n.info,
reportSymbols(rsemAmbiguous, @[match, symx]).withIt do:
it.ast = selector
)
elif symx.isError:
localReport(c.config, symx.ast)

symx = nextOverloadIter(o, c, headSymbol)

if match == nil: return
var callExpr = newNodeI(nkCall, n.info)
callExpr.add newSymNode(match)
callExpr.add n
case match.kind
of skMacro: result = semMacroExpr(c, callExpr, match, flags)
of skTemplate: result = semTemplateExpr(c, callExpr, match, flags)
else: result = nil

proc handleForLoopMacro(c: PContext; n: PNode; flags: TExprFlags): PNode =
result = handleStmtMacro(c, n, n[^2], "ForLoopStmt", flags)

proc handleCaseStmtMacro(c: PContext; n: PNode; flags: TExprFlags): PNode =
# n[0] has been sem'checked and has a type. We use this to resolve
# '`case`(n[0])' but then we pass 'n' to the `case` macro. This seems to
# be the best solution.
var toResolve = newNodeI(nkCall, n.info)
toResolve.add newIdentNode(getIdent(c.cache, "case"), n.info)
toResolve.add n[0]

var errors: seq[SemCallMismatch]
var r = resolveOverloads(c, toResolve, {skTemplate, skMacro}, {}, errors)
if r.state == csMatch:
var match = r.calleeSym
markUsed(c, n[0].info, match)
onUse(n[0].info, match)

# but pass 'n' to the `case` macro, not 'n[0]':
r.call[1] = n
let toExpand = semResolvedCall(c, r, r.call, {})
case match.kind
of skMacro: result = semMacroExpr(c, toExpand, match, flags)
of skTemplate: result = semTemplateExpr(c, toExpand, match, flags)
else: result = nil
else:
assert r.call.kind == nkError
result = r.call # xxx: hope this is nkError
# this would be the perfectly consistent solution with 'for loop macros',
# but it kinda sucks for pattern matching as the matcher is not attached to
# a type then:
when false:
result = handleStmtMacro(c, n, n[0], "CaseStmt")

proc semFor(c: PContext, n: PNode; flags: TExprFlags): PNode =
checkMinSonsLen(n, 3, c.config)
result = handleForLoopMacro(c, n, flags)
if result != nil: return result
openScope(c)
result = n
n[^2] = semExprNoDeref(c, n[^2], {efWantIterator})
Expand Down Expand Up @@ -1748,9 +1673,6 @@ proc semCase(c: PContext, n: PNode; flags: TExprFlags): PNode =
else:
popCaseContext(c)
closeScope(c)
result = handleCaseStmtMacro(c, n, flags)
if result != nil:
return result
result[0] = c.config.newError(n[0], reportSem rsemSelectorMustBeOfCertainTypes)
return
for i in 1..<n.len:
Expand Down
10 changes: 7 additions & 3 deletions compiler/sem/semtempl.nim
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,18 @@ type
spNone, spGenSym, spInject

proc symBinding(n: PNode): TSymBinding =
for i in 0..<n.len:
let it = n[i]
result = spNone
for it in n:
let key = if it.kind == nkExprColonExpr: it[0] else: it
if key.kind == nkIdent:

case key.kind
of nkIdent:
case whichKeyword(key.ident)
of wGensym: return spGenSym
of wInject: return spInject
else: discard
else:
discard

type
TSymChoiceRule = enum
Expand Down
2 changes: 1 addition & 1 deletion compiler/sem/sigmatch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ proc initCandidate*(ctx: PContext, c: var TCandidate, callee: PSym,
c.magic = c.calleeSym.magic
if binding != nil and callee.kind in routineKinds:
var typeParams = callee.ast[genericParamsPos]
for i in 1..min(typeParams.len, binding.len-1):
for i in 1..min(typeParams.safeLen, binding.safeLen-1):
var formalTypeParam = typeParams[i-1].typ
var bound = binding[i].typ
if bound != nil:
Expand Down
2 changes: 1 addition & 1 deletion compiler/vm/vm.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3626,7 +3626,7 @@ proc evalMacroCall*(module: PSym; idgen: IdGenerator; g: ModuleGraph; templInstC

# put macro generic parameters into registers
let gp = sym.ast[genericParamsPos]
for i in 0..<gp.len:
for i in 0..<gp.safeLen:
let idx = sym.typ.len + i
if idx < n.len:
setupMacroParam(tos.slots[idx], c[], n[idx], gp[i].sym.typ)
Expand Down
6 changes: 0 additions & 6 deletions config/nim.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,6 @@ tcc.options.always = "-w"
--define:nimEmulateOverflowChecks
@end

@if nimv019:
--multimethods:on
--define:nimOldCaseObjects
--define:nimOldShiftRight
@end

@if lto or lto_incremental:
@if lto_incremental:
vcc.options.always%= "${vcc.options.always} /GL /Gw /Gy"
Expand Down
3 changes: 0 additions & 3 deletions doc/lib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -459,9 +459,6 @@ Miscellaneous
* `colors <colors.html>`_
This module implements color handling for Nim.

* `enumerate <enumerate.html>`_
This module implements `enumerate` syntactic sugar based on Nim's macro system.

* `logging <logging.html>`_
This module implements a simple logger.

Expand Down
Loading

0 comments on commit 086304b

Please sign in to comment.