summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2021-04-14 22:35:18 +0200
committerGitHub <noreply@github.com>2021-04-14 22:35:18 +0200
commiteff9d75379d6f9f4a52c2040425dad1f408ede37 (patch)
tree3f022b5c0ffad66c0dfa37e14adc8df7e2c39216 /compiler
parentd6242d7fe19849d6cc7079f0b006065fb2a8a19e (diff)
downloadNim-eff9d75379d6f9f4a52c2040425dad1f408ede37.tar.gz
IC: rodfiles: no floats (#17720)
Diffstat (limited to 'compiler')
-rw-r--r--compiler/ic/ic.nim19
-rw-r--r--compiler/ic/integrity.nim6
-rw-r--r--compiler/ic/packed_ast.nim11
-rw-r--r--compiler/ic/rodfiles.nim3
4 files changed, 18 insertions, 21 deletions
diff --git a/compiler/ic/ic.nim b/compiler/ic/ic.nim
index 4613b9cb8..4f63ce03a 100644
--- a/compiler/ic/ic.nim
+++ b/compiler/ic/ic.nim
@@ -224,7 +224,7 @@ proc toLitId(x: string; m: var PackedModule): LitId =
 
 proc toLitId(x: BiggestInt; m: var PackedModule): LitId =
   ## store an integer as a literal
-  result = getOrIncl(m.sh.integers, x)
+  result = getOrIncl(m.sh.numbers, x)
 
 proc toPackedInfo(x: TLineInfo; c: var PackedEncoder; m: var PackedModule): PackedLineInfo =
   PackedLineInfo(line: x.line, col: x.col, file: toLitId(x.fileIndex, c, m))
@@ -400,7 +400,7 @@ proc toPackedNode*(n: PNode; ir: var PackedTree; c: var PackedEncoder; m: var Pa
                             typeId: storeTypeLater(n.typ, c, m), info: info)
   of externIntLit:
     ir.nodes.add PackedNode(kind: n.kind, flags: n.flags,
-                            operand: int32 getOrIncl(m.sh.integers, n.intVal),
+                            operand: int32 getOrIncl(m.sh.numbers, n.intVal),
                             typeId: storeTypeLater(n.typ, c, m), info: info)
   of nkStrLit..nkTripleStrLit:
     ir.nodes.add PackedNode(kind: n.kind, flags: n.flags,
@@ -408,7 +408,7 @@ proc toPackedNode*(n: PNode; ir: var PackedTree; c: var PackedEncoder; m: var Pa
                             typeId: storeTypeLater(n.typ, c, m), info: info)
   of nkFloatLit..nkFloat128Lit:
     ir.nodes.add PackedNode(kind: n.kind, flags: n.flags,
-                            operand: int32 getOrIncl(m.sh.floats, n.floatVal),
+                            operand: int32 getOrIncl(m.sh.numbers, cast[BiggestInt](n.floatVal)),
                             typeId: storeTypeLater(n.typ, c, m), info: info)
   else:
     let patchPos = ir.prepare(n.kind, n.flags,
@@ -521,8 +521,7 @@ proc loadRodFile*(filename: AbsoluteFile; m: var PackedModule; config: ConfigRef
 
   loadSeqSection depsSection, m.imports
 
-  loadTabSection integersSection, m.sh.integers
-  loadTabSection floatsSection, m.sh.floats
+  loadTabSection numbersSection, m.sh.numbers
 
   loadSeqSection exportsSection, m.exports
 
@@ -587,8 +586,7 @@ proc saveRodFile*(filename: AbsoluteFile; encoder: var PackedEncoder; m: var Pac
 
   storeSeqSection depsSection, m.imports
 
-  storeTabSection integersSection, m.sh.integers
-  storeTabSection floatsSection, m.sh.floats
+  storeTabSection numbersSection, m.sh.numbers
 
   storeSeqSection exportsSection, m.exports
 
@@ -700,11 +698,11 @@ proc loadNodes*(c: var PackedDecoder; g: var PackedModuleGraph; thisModule: int;
   of directIntLit:
     result.intVal = tree.nodes[n.int].operand
   of externIntLit:
-    result.intVal = g[thisModule].fromDisk.sh.integers[n.litId]
+    result.intVal = g[thisModule].fromDisk.sh.numbers[n.litId]
   of nkStrLit..nkTripleStrLit:
     result.strVal = g[thisModule].fromDisk.sh.strings[n.litId]
   of nkFloatLit..nkFloat128Lit:
-    result.floatVal = g[thisModule].fromDisk.sh.floats[n.litId]
+    result.floatVal = cast[BiggestFloat](g[thisModule].fromDisk.sh.numbers[n.litId])
   of nkModuleRef:
     let (n1, n2) = sons2(tree, n)
     assert n1.kind == nkInt32Lit
@@ -1151,5 +1149,4 @@ proc rodViewer*(rodfile: AbsoluteFile; config: ConfigRef, cache: IdentCache) =
 
   echo "symbols: ", m.sh.syms.len, " types: ", m.sh.types.len,
     " top level nodes: ", m.topLevel.nodes.len, " other nodes: ", m.bodies.nodes.len,
-    " strings: ", m.sh.strings.len, " integers: ", m.sh.integers.len,
-    " floats: ", m.sh.floats.len
+    " strings: ", m.sh.strings.len, " numbers: ", m.sh.numbers.len
diff --git a/compiler/ic/integrity.nim b/compiler/ic/integrity.nim
index b4545de94..a28f2066a 100644
--- a/compiler/ic/integrity.nim
+++ b/compiler/ic/integrity.nim
@@ -79,12 +79,10 @@ proc checkNode(c: var CheckedContext; tree: PackedTree; n: NodePos) =
     checkLocalSym(c, tree.nodes[n.int].operand)
   of directIntLit:
     discard
-  of externIntLit:
-    assert c.g.packed[c.thisModule].fromDisk.sh.integers.hasLitId n.litId
+  of externIntLit, nkFloatLit..nkFloat128Lit:
+    assert c.g.packed[c.thisModule].fromDisk.sh.numbers.hasLitId n.litId
   of nkStrLit..nkTripleStrLit:
     assert c.g.packed[c.thisModule].fromDisk.sh.strings.hasLitId n.litId
-  of nkFloatLit..nkFloat128Lit:
-    assert c.g.packed[c.thisModule].fromDisk.sh.floats.hasLitId n.litId
   of nkModuleRef:
     let (n1, n2) = sons2(tree, n)
     assert n1.kind == nkInt32Lit
diff --git a/compiler/ic/packed_ast.nim b/compiler/ic/packed_ast.nim
index 5cc3b1476..0649b56ce 100644
--- a/compiler/ic/packed_ast.nim
+++ b/compiler/ic/packed_ast.nim
@@ -106,8 +106,8 @@ type
     syms*: seq[PackedSym]
     types*: seq[PackedType]
     strings*: BiTable[string] # we could share these between modules.
-    integers*: BiTable[BiggestInt]
-    floats*: BiTable[BiggestFloat]
+    numbers*: BiTable[BiggestInt] # we also store floats in here so
+                                  # that we can assure that every bit is kept
     #config*: ConfigRef
 
   PackedInstantiation* = object
@@ -394,10 +394,13 @@ proc toString*(tree: PackedTree; n: NodePos; sh: Shared; nesting: int;
     result.addInt tree.nodes[pos].operand
   of externSIntLit:
     result.add " "
-    result.addInt sh.integers[LitId tree.nodes[pos].operand]
+    result.addInt sh.numbers[LitId tree.nodes[pos].operand]
   of externUIntLit:
     result.add " "
-    result.add $cast[uint64](sh.integers[LitId tree.nodes[pos].operand])
+    result.add $cast[uint64](sh.numbers[LitId tree.nodes[pos].operand])
+  of nkFloatLit..nkFloat128Lit:
+    result.add " "
+    result.add $cast[BiggestFloat](sh.numbers[LitId tree.nodes[pos].operand])
   else:
     result.add "(\n"
     for i in 1..(nesting+1)*2: result.add ' '
diff --git a/compiler/ic/rodfiles.nim b/compiler/ic/rodfiles.nim
index 39a5b6b73..fbe1cad33 100644
--- a/compiler/ic/rodfiles.nim
+++ b/compiler/ic/rodfiles.nim
@@ -16,8 +16,7 @@ type
     stringsSection
     checkSumsSection
     depsSection
-    integersSection
-    floatsSection
+    numbersSection
     exportsSection
     reexportsSection
     compilerProcsSection