@@ -6,8 +6,8 @@ import enum2nif, icniftags
66type
77 DecodeContext = object
88 graph: ModuleGraph
9- symbols: Table [int , PSym ]
10- types: Table [int , PType ]
9+ symbols: Table [ItemId , PSym ]
10+ types: Table [ItemId , PType ]
1111 modules: Table [int , FileIndex ] # maps module id in NIF to FileIndex of the module
1212
1313proc nodeKind (n: Cursor ): TNodeKind {.inline .} =
@@ -59,21 +59,22 @@ when false:
5959 else :
6060 expectTag (n, id)
6161
62- proc fromNifModuleId (c: var DecodeContext ; n: var Cursor ): FileIndex =
62+ proc fromNifModuleId (c: var DecodeContext ; n: var Cursor ): (FileIndex , int32 ) =
63+ expect n, {ParLe , IntLit }
6364 if n.kind == ParLe :
6465 expectTag n, modIdTag
6566 incExpect n, IntLit
6667 let id = pool.integers[n.intId]
6768 incExpect n, StringLit
6869 let path = pool.strings[n.litId].AbsoluteFile
69- result = fileInfoIdx (c.graph.config, path)
70+ result = ( fileInfoIdx (c.graph.config, path), id. int32 )
7071 assert id notin c.modules
71- c.modules[id] = result
72+ c.modules[id] = result [ 0 ]
7273 inc n
7374 skipParRi n
7475 elif n.kind == IntLit :
7576 let id = pool.integers[n.intId]
76- result = c.modules[id]
77+ result = ( c.modules[id], id. int32 )
7778 inc n
7879
7980proc fromNifSymbol (c: var DecodeContext ; n: var Cursor ): PSym
@@ -82,14 +83,12 @@ proc fromNif(c: var DecodeContext; n: var Cursor): PNode
8283
8384proc fromNifSymDef (c: var DecodeContext ; n: var Cursor ): PSym =
8485 expectTag n, symIdTag
85- incExpect n, IntLit
86- let id = pool.integers[n.intId]
87- incExpect n, Ident
88- let ident = c.graph.cache.getIdent (pool.strings[n.litId])
8986 inc n
90- let itemIdModule = c.fromNifModuleId (n). int32
87+ let ( itemIdModule, nifModId) = c.fromNifModuleId (n)
9188 expect n, IntLit
9289 let itemId = pool.integers[n.intId].int32
90+ incExpect n, Ident
91+ let ident = c.graph.cache.getIdent (pool.strings[n.litId])
9392 incExpect n, ParLe
9493 let kind = parseSymKind (pool.tags[n.tagId])
9594 # TODO : add kind specific data
@@ -99,7 +98,7 @@ proc fromNifSymDef(c: var DecodeContext; n: var Cursor): PSym =
9998 let flags = if n.kind == Ident : pool.strings[n.litId].parseSymFlags else : {}
10099 inc n
101100 var position = if kind == skModule:
102- c.fromNifModuleId (n).int
101+ c.fromNifModuleId (n)[ 0 ] .int
103102 else :
104103 expect n, IntLit
105104 let p = pool.integers[n.intId]
@@ -109,7 +108,7 @@ proc fromNifSymDef(c: var DecodeContext; n: var Cursor): PSym =
109108 let disamb = pool.integers[n.intId].int32
110109 inc n
111110
112- result = PSym (itemId: ItemId (module: itemIdModule, item: itemId),
111+ result = PSym (itemId: ItemId (module: itemIdModule. int32 , item: itemId),
113112 kind: kind,
114113 name: ident,
115114 flags: flags,
@@ -119,8 +118,9 @@ proc fromNifSymDef(c: var DecodeContext; n: var Cursor): PSym =
119118 # PNode, PSym or PType type fields in PSym can have cycles.
120119 # Add PSym to `c.symbols` before parsing these fields so that
121120 # they can refer this PSym.
122- assert id notin c.symbols
123- c.symbols[id] = result
121+ let nifItemId = ItemId (module: nifModId, item: itemId)
122+ assert nifItemId notin c.symbols
123+ c.symbols[nifItemId] = result
124124
125125 result .typ = c.fromNifType n
126126 result .setOwner (c.fromNifSymbol n)
@@ -134,10 +134,8 @@ proc fromNifSymDef(c: var DecodeContext; n: var Cursor): PSym =
134134
135135proc fromNifTypeDef (c: var DecodeContext ; n: var Cursor ): PType =
136136 expectTag n, typeIdTag
137- incExpect n, IntLit
138- let id = pool.integers[n.intId]
139137 inc n
140- let itemIdModule = c.fromNifModuleId (n). int32
138+ let ( itemIdModule, nifModId) = c.fromNifModuleId (n)
141139 expect n, IntLit
142140 let itemId = pool.integers[n.intId].int32
143141 incExpect n, Ident
@@ -146,11 +144,12 @@ proc fromNifTypeDef(c: var DecodeContext; n: var Cursor): PType =
146144 let flags = if n.kind == Ident : pool.strings[n.litId].parseTypeFlags else : {}
147145 inc n
148146
149- result = PType (itemId: ItemId (module: itemIdModule, item: itemId),
147+ result = PType (itemId: ItemId (module: itemIdModule. int32 , item: itemId),
150148 kind: kind,
151149 flags: flags)
152- assert id notin c.types
153- c.types[id] = result
150+ let nifItemId = ItemId (module: nifModId, item: itemId)
151+ assert nifItemId notin c.types
152+ c.types[nifItemId] = result
154153
155154 expect n, {DotToken , ParLe }
156155 if n.kind == DotToken :
@@ -186,7 +185,11 @@ proc fromNifSymbol(c: var DecodeContext; n: var Cursor): PSym =
186185 result = c.fromNifSymDef n
187186 elif n.tagId == symTag:
188187 incExpect n, IntLit
189- result = c.symbols[pool.integers[n.intId]]
188+ let nifModId = pool.integers[n.intId].int32
189+ incExpect n, IntLit
190+ let item = pool.integers[n.intId].int32
191+ let nifItemId = ItemId (module: nifModId, item: item)
192+ result = c.symbols[nifItemId]
190193 inc n
191194 skipParRi n
192195 else :
@@ -202,7 +205,11 @@ proc fromNifType(c: var DecodeContext; n: var Cursor): PType =
202205 result = c.fromNifTypeDef n
203206 elif n.tagId == typeTag:
204207 incExpect n, IntLit
205- result = c.types[pool.integers[n.intId]]
208+ let nifModId = pool.integers[n.intId].int32
209+ incExpect n, IntLit
210+ let item = pool.integers[n.intId].int32
211+ let nifItemId = ItemId (module: nifModId, item: item)
212+ result = c.types[nifItemId]
206213 inc n
207214 skipParRi n
208215 else :
0 commit comments