Skip to content

Commit

Permalink
Remove nkStmtListType and nkBlockType
Browse files Browse the repository at this point in the history
  • Loading branch information
Clyybber committed Mar 5, 2024
1 parent a34c846 commit 1db4ffe
Show file tree
Hide file tree
Showing 12 changed files with 13 additions and 56 deletions.
2 changes: 0 additions & 2 deletions compiler/ast/ast_query.nim
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ const
nkIteratorTy,
nkSharedTy,
nkEnumTy,
nkStmtListType,
nkBlockType
}

# TODO: replace with `nk*Literals`, see above
Expand Down
3 changes: 0 additions & 3 deletions compiler/ast/ast_types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,6 @@ type
nkBlockExpr ## a statement block ending in an expr; this is used
## to allow powerful multi-line templates that open a
## temporary scope
nkStmtListType ## a statement list ending in a type; for macros
nkBlockType ## a statement block ending in a type; for macros
## types as syntactic trees:

nkWith ## distinct with `foo`
nkWithout ## distinct without `foo`
Expand Down
8 changes: 4 additions & 4 deletions compiler/ast/renderer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -633,14 +633,14 @@ proc longMode(g: TSrcGen; n: PNode, start: int = 0, theEnd: int = - 1): bool =

proc gstmts(g: var TSrcGen, n: PNode, c: TContext, doIndent=true) =
if n.kind == nkEmpty: return
if n.kind in {nkStmtList, nkStmtListExpr, nkStmtListType}:
if n.kind in {nkStmtList, nkStmtListExpr}:
if doIndent: indentNL(g)
for i in 0..<n.len:
if i > 0:
optNL(g, n[i-1], n[i])
else:
optNL(g)
if n[i].kind in {nkStmtList, nkStmtListExpr, nkStmtListType}:
if n[i].kind in {nkStmtList, nkStmtListExpr}:
gstmts(g, n[i], c, doIndent=false)
else:
gsub(g, n[i], fromStmtList = true)
Expand Down Expand Up @@ -1421,7 +1421,7 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext, fromStmtList = false) =
put(g, tkSpaces, Space)
putWithSpace(g, tkEquals, "=")
gsub(g, n, 1)
of nkStmtList, nkStmtListExpr, nkStmtListType:
of nkStmtList, nkStmtListExpr:
if n.len == 1 and n[0].kind == nkDiscardStmt:
put(g, tkParLe, "(")
gsub(g, n[0])
Expand Down Expand Up @@ -1654,7 +1654,7 @@ proc renderTree*(n: PNode, renderFlags: TRenderFlags = {}): string =
# do not indent the initial statement list so that
# writeFile("file.nim", repr n)
# produces working Nim code:
if n.kind in {nkStmtList, nkStmtListExpr, nkStmtListType}:
if n.kind in {nkStmtList, nkStmtListExpr}:
gstmts(g, n, emptyContext, doIndent = false)
else:
gsub(g, n)
Expand Down
1 change: 1 addition & 0 deletions compiler/front/condsyms.nim
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,4 @@ proc initDefines*(symbols: StringTableRef) =
defineSymbol("nimskullReworkStaticExec")
defineSymbol("nimskullNoMagicNewAssign")
defineSymbol("nimskullNoFloat128")
defineSymbol("nimskullHasNkStmtListTypeAndNkBlockTypeRemoved")
18 changes: 0 additions & 18 deletions compiler/mir/mirgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -551,24 +551,6 @@ proc genTypeExpr(c: var TCtx, n: PNode): Value =
# FIXME: a ``nkStmtListExpr`` shouldn't reach here, but it does. See
# ``tests/lang_callable/generics/t18859.nim`` for a case where it
# does
if n[^1].typ.kind == tyTypeDesc:
genTypeExpr(c, n.lastSon)
else:
# HACK: this is big hack. Consider the following case:
#
# .. code-block:: nim
#
# type Obj[T] = object
# p: T not nil
#
# var x: Obj[ref int]
#
# The ``T not nil`` is a ``nkStmtListType`` node with a single
# ``nkInfix`` sub-node, where the latter doesn't use a
# ``tyTypeDesc`` type but a ``tyRef`` instead. For now, we work
# around this by using the type of the ``nkStmtListType``
typeLit(n.typ)
of nkBlockType:
genTypeExpr(c, n.lastSon)
of nkSym:
case n.sym.kind
Expand Down
3 changes: 0 additions & 3 deletions compiler/sem/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3623,9 +3623,6 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
result = semTypeNode2(c, n, nil)
# a type expression is of type ``typeDesc[T]``
result.typ = makeTypeDesc(c, result.typ.skipTypes({tyTypeDesc}))
of nkStmtListType:
result = semTypeNode2(c, n, nil)
result.typ = makeTypeDesc(c, result.typ)
of nkCall, nkInfix, nkPrefix, nkPostfix, nkCommand, nkCallStrLit:
# check if it is an expression macro:
checkMinSonsLen(n, 1, c.config)
Expand Down
6 changes: 3 additions & 3 deletions compiler/sem/semfold.nim
Original file line number Diff line number Diff line change
Expand Up @@ -857,14 +857,14 @@ proc foldConstExprAux(m: PSym, n: PNode, idgen: IdGenerator, g: ModuleGraph): Fo
return
of nkSym:
discard "may be folded away"
of nkTypeExprs - {nkStmtListType, nkBlockType}:
of nkTypeExprs:
result.node = newNodeIT(nkType, n.info, n.typ)
of nkBracket, nkCurly, nkTupleConstr, nkRange, nkAddr, nkHiddenAddr,
nkHiddenDeref, nkDerefExpr, nkBracketExpr, nkCallKinds, nkIfExpr,
nkElifExpr, nkElseExpr, nkElse, nkElifBranch:
for it in n.items:
result.add foldConstExprAux(m, it, idgen, g)
of nkCast, nkConv, nkHiddenStdConv, nkHiddenSubConv, nkBlockExpr, nkBlockType:
of nkCast, nkConv, nkHiddenStdConv, nkHiddenSubConv, nkBlockExpr:
# the first slot only holds the type/label, which we don't need to traverse
# into / fold
result.add n[0]
Expand All @@ -888,7 +888,7 @@ proc foldConstExprAux(m: PSym, n: PNode, idgen: IdGenerator, g: ModuleGraph): Fo
result.add n[0] # skip the type slot
for i in 1..<n.len:
result.add foldConstExprAux(m, n[i], idgen, g)
of nkStmtListExpr, nkStmtListType:
of nkStmtListExpr:
for i in 0..<n.len-1:
result.add foldInAstAux(m, n[i], idgen, g)
# the last node is an expression
Expand Down
2 changes: 1 addition & 1 deletion compiler/sem/semgnrc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ proc semGenericStmt(c: PContext, n: PNode,
n[^1] = checkError semGenericStmt(c, n[^1], flags, ctx)
closeScope(c)
closeScope(c)
of nkBlockStmt, nkBlockExpr, nkBlockType:
of nkBlockStmt, nkBlockExpr:
checkSonsLen(n, 2, c.config)
openScope(c)
if n[0].kind != nkEmpty:
Expand Down
5 changes: 0 additions & 5 deletions compiler/sem/sempass2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1440,11 +1440,6 @@ proc track(tracked: PEffects, n: PNode) =
track(tracked, n[i])

inc tracked.leftPartOfAsgn
of nkBlockType, nkStmtListType:
# TODO: it's a minor breaking change (macros can observe it via
# `getImpl`), but these nodes should instead be folded into
# ``nkType`` nodes by ``semfold``
discard
of nkBindStmt, nkMixinStmt, nkImportStmt, nkImportExceptStmt, nkExportStmt,
nkExportExceptStmt, nkFromStmt:
# a declarative statement that is not relevant to the analysis. Report
Expand Down
2 changes: 1 addition & 1 deletion compiler/sem/semtempl.nim
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ proc semTemplBody(c: var TemplCtx, n: PNode): PNode =
hasError = true

closeScope(c)
of nkBlockStmt, nkBlockExpr, nkBlockType:
of nkBlockStmt, nkBlockExpr:
checkSonsLen(n, 2, c.c.config)
openScope(c)
case n[0].kind
Expand Down
15 changes: 1 addition & 14 deletions compiler/sem/semtypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1675,18 +1675,6 @@ proc semStmtListType(c: PContext, n: PNode, prev: PType): PType =
else:
result = nil

proc semBlockType(c: PContext, n: PNode, prev: PType): PType =
inc(c.execCon.nestedBlockCounter)
checkSonsLen(n, 2, c.config)
openScope(c)
if n[0].kind notin {nkEmpty, nkSym}:
addDecl(c, newSymS(skLabel, n[0], c))
result = semStmtListType(c, n[1], prev)
n[1].typ = result
n.typ = result
closeScope(c)
dec(c.execCon.nestedBlockCounter)

proc semGenericParamInInvocation(c: PContext, n: PNode): PType =
result = semTypeNode(c, n, nil)
n.typ = makeTypeDesc(c, result)
Expand Down Expand Up @@ -2312,8 +2300,7 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
else:
result = semProcTypeWithScope(c, n, prev, skProc)
of nkEnumTy: result = semEnum(c, n, prev)
of nkStmtListType, nkStmtListExpr: result = semStmtListType(c, n, prev)
of nkBlockType: result = semBlockType(c, n, prev)
of nkStmtListExpr: result = semStmtListType(c, n, prev)
of nkError:
localReport(c.config, n, reportSem rsemTypeExpected)
result = newOrPrevType(tyError, prev, c)
Expand Down
4 changes: 2 additions & 2 deletions lib/core/macros.nim
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ type
nnkIncludeStmt,
nnkBindStmt, nnkMixinStmt, nnkUsingStmt,
nnkCommentStmt, nnkStmtListExpr, nnkBlockExpr,
nnkStmtListType, nnkBlockType,
nnkWith, nnkWithout,
nnkWith = skipEnumValue(nimskullHasNkStmtListTypeAndNkBlockTypeRemoved, nnkBlockExpr, 2),
nnkWithout,
nnkTypeOfExpr, nnkObjectTy,
nnkTupleTy, nnkTupleClassTy, nnkTypeClassTy, nnkStaticTy,
nnkRecList, nnkRecCase, nnkRecWhen,
Expand Down

0 comments on commit 1db4ffe

Please sign in to comment.