Commits

Amaury Forgeot d'Arc committed 97379fc

When a function is "annotated by example", constant propagation
may occur and gives wrong results.
In this case, reflow the annotation with non-constant parameters.

  • Participants
  • Parent commits ca7830c
  • Branches separate-compilation

Comments (0)

Files changed (1)

File pypy/translator/c/test/test_separate.py

 from pypy.translator.tool.cbuild import ExternalCompilationInfo
 from pypy.rpython.typesystem import getfunctionptr
 from pypy.rpython.lltypesystem import rffi, lltype
+from pypy.annotation import model
 import py
 import sys, os
 
     def compile_separated(self, name, **exports):
         t = TranslationContext()
         t.buildannotator()
+        bk = t.annotator.bookkeeper
+
+        # annotate functions with signatures
         for funcname, func in exports.items():
             if hasattr(func, 'argtypes'):
                 t.annotator.build_types(func, func.argtypes)
+
+        # ensure that functions without signature are not constant-folded
+        for funcname, func in exports.items():
+            if not hasattr(func, 'argtypes'):
+                # build a list of arguments where constants are erased
+                newargs = []
+                graph = bk.getdesc(func).getuniquegraph()
+                for arg in graph.startblock.inputargs:
+                    newarg = model.not_const(t.annotator.binding(arg))
+                    newargs.append(newarg)
+                # and reflow
+                t.annotator.build_types(func, newargs)
+
         t.buildrtyper().specialize()
 
         exported_funcptr = {}
         for funcname, func in exports.items():
-            bk = t.annotator.bookkeeper
             graph = bk.getdesc(func).getuniquegraph()
             funcptr = getfunctionptr(graph)
 
         @export()
         def f2():
             f(1.0)
-            f(2.0)
         firstmodule = self.compile_separated("first", f=f, f2=f2)
 
         # call it from a function compiled in another module