diff --git a/compiler/ast.nim b/compiler/ast.nim index 8afe80b78c8..86910b9e8c5 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -785,28 +785,13 @@ type kind: TNodeKind ## presently the same as the nim node extra: ExtraDataId ## id into extra data about this node, depends on ## `kind`, for lookup of literal, sym, ident, etc - AstTree = OrderedTable[NodeId, TNodeSeq] - ## store the tree structure for nodes, this is effectively `sons` - - # ExtraData = object - # case kind: ExtraDataKind - # of IntLiteralKind: - # intVal: BiggestInt - # of FloatLiteralKind: - # floatVal: BiggestFloat - # of StringLiteralKind: - # strVal: string - # of SymbolDataKind: - # sym: PSym - # of IdentifierDataKind: - # ident: PIdent State = ref object nodeList: NodeList ## each node, NodeId is their sequence index nodeFlag: seq[TNodeFlags] ## flags for each node, rarely accessed bloat nodeInf: seq[TLineInfo] ## info on a per node basis - astData: AstTree ## actual tree structure for the various AST + # astData: AstTree ## actual tree structure for the various AST # sparse data, not all nodes have these nodeTyp: OrderedTable[NodeId, PType] ## types @@ -817,12 +802,7 @@ type nodeInt: seq[BiggestInt] ## int literals nodeFlt: seq[BiggestFloat] ## float literals nodeStr: seq[string] ## string literals - - # nodeSym: OrderedTable[NodeId, PSym] ## symbols - # nodeIdt: OrderedTable[NodeId, PIdent] ## identifiers - # nodeInt: OrderedTable[NodeId, BiggestInt] ## int literals - # nodeFlt: OrderedTable[NodeId, BiggestFloat] ## float literals - # nodeStr: OrderedTable[NodeId, string] ## string literals + astData: seq[TNodeSeq] ## the sons for ast nodes ExtraDataKind {.pure.} = enum ExtraDataNone, @@ -830,7 +810,8 @@ type ExtraDataFloat, ExtraDataString, ExtraDataSymbol, - ExtraDataIdentifier + ExtraDataIdentifier, + ExtraDataAst # IDs # xxx: disabled distincts until the basics work @@ -1108,7 +1089,7 @@ func extraDataKind(k: TNodeKind): ExtraDataKind {.inline.} = of nkStrLit..nkTripleStrLit: ExtraDataString of nkSym: ExtraDataSymbol of nkIdent: ExtraDataIdentifier - else: ExtraDataNone + else: ExtraDataAst const # unknownLineInfoId = InfoId 0 @@ -1246,11 +1227,14 @@ proc sons*(n: PNode): var TNodeSeq {.inline.} = # assert n.kind notin haveNoSons, "not a parent, id: " & $n.id {.cast(noSideEffect).}: # assert n.id.int <= state.nodeList.len, "invalid node id: " & $n.id.int - result = state.astData.mgetOrPut(n.id, @[]) + if n.extraId == nilExtraDataId: + state.astData.add @[] + state.nodeList[n.idx].extra = ExtraDataId state.astData.len + result = state.astData[n.extraId.idx] proc `sons=`*(n: PNode, sons: TNodeSeq) = # assert n.kind notin haveNoSons, "not a parent, id: " & $n.id # assert n.id.int <= state.nodeList.len, "invalid node id: " & $n.id.int - state.astData[n.id] = sons + state.astData[n.extraIdx] = sons proc idToNode*(id: NodeId): PNode {.inline.} = # assert id.int <= state.nodeList.len, "invalid node id: " & $id.int @@ -1559,13 +1543,7 @@ proc add*(father, son: Indexable) {.inline.} = template `[]`*(n: Indexable, i: int): Indexable = n.sons[i] template `[]=`*(n: Indexable, i: int; x: Indexable) = - when n is PNode: - var tmp = state.astData[n.id] - tmp[i] = x - state.astData[n.id] = tmp - else: - n.sons[i] = x - # n.sons[i] = x + 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 @@ -1628,7 +1606,9 @@ template newNodeImpl(kind: TNodeKind, info2: TLineInfo) = of ExtraDataIdentifier: state.nodeIdt.add nil state.nodeList[nodeIdx].extra = ExtraDataId state.nodeIdt.len - of ExtraDataNone: + of ExtraDataAst, ExtraDataNone: + state.astData.add @[] + state.nodeList[nodeIdx].extra = ExtraDataId state.astData.len discard result = PNode(id: nodeId) @@ -2049,8 +2029,6 @@ proc applyToNode*(src, dest: PNode) = # assert not dest.isNil # assert not src.isNil # assert dest.id != src.id, "applying to self, id: " & $src.id - if state.astData.hasKey(src.id): - state.astData[dest.id] = state.astData[src.id] state.nodeList[dest.idx] = state.nodeList[src.idx] state.nodeFlag[dest.idx] = state.nodeFlag[src.idx] state.nodeInf[dest.idx] = state.nodeInf[src.idx] @@ -2067,8 +2045,8 @@ proc applyToNode*(src, dest: PNode) = dest.sym = src.sym of ExtraDataIdentifier: dest.ident = src.ident - of ExtraDataNone: - discard + of ExtraDataAst, ExtraDataNone: + dest.sons = src.sons proc copyNode*(src: PNode): PNode = # does not copy its sons! @@ -2137,7 +2115,9 @@ template transitionNodeKindCommon(k, old: TNodeKind) = for clear in clears.items: case clear - of nodeClearAst: discard # state.astData.del(n.id) + of nodeClearAst: + if oldExtraDataKind == ExtraDataAst: + state.astData[n.extraIdx].setLen(0) of nodeClearFlg: state.nodeFlag[n.idx] = {} of nodeClearInf: state.nodeInf[n.idx] = unknownLineInfo of nodeClearTyp: state.nodeTyp.del(n.id) diff --git a/compiler/sem.nim b/compiler/sem.nim index 9d03a451f8c..04d1d0beb07 100644 --- a/compiler/sem.nim +++ b/compiler/sem.nim @@ -851,7 +851,6 @@ proc myProcess(context: PPassContext, n: PNode): PNode {.nosinks.} = ## from a module as it's parsed and uses the context to accumulate data. var c = PContext(context) # no need for an expensive 'try' if we stop after the first error anyway: - echo "processing: ", c.config.`$`(n.info) if c.config.errorMax <= 1: result = semStmtAndGenerateGenerics(c, n) else: