Debian Codegraph @

pypy/config/pypyoption.py

raw symbols SCIP
1 import os
2 import sys
3
4 import py
5
6 from rpython.config.config import (OptionDescription, BoolOption, IntOption,
7 ChoiceOption, StrOption, to_optparse)
8 from rpython.config.translationoption import IS_64_BITS
9
10
11 modulepath = py.path.local(__file__).dirpath().dirpath().join("module")
12 all_modules = [p.basename for p in modulepath.listdir()
13 if p.check(dir=True, dotfile=False)
14 and p.join('__init__.py').check()
15 and not p.basename.startswith('test')]
16
17 essential_modules = set([
18 "exceptions", "_io", "sys", "builtins", "posix", "_warnings",
19 "itertools", "_frozen_importlib", "operator", "_locale", "struct",
20 "thread", "__pypy__", "zipimport", "_opcode",
21 ])
22 if sys.platform == "win32":
23 essential_modules.add("_winreg")
24
25 default_modules = essential_modules.copy()
26 default_modules.update([
27 "_codecs", "atexit", "gc", "_weakref", "marshal", "errno", "imp",
28 "itertools", "math", "cmath", "_sre", "_pickle_support",
29 "token", "_ast", "_random",
30 "_string", "_testing", "time", "_abc", "_pickle",
31 ])
32
33
34 # --allworkingmodules
35 working_modules = default_modules.copy()
36 working_modules.update([
37 "_socket", "unicodedata", "mmap", "fcntl", "pwd",
38 "select", "_lsprof", "signal", "_rawffi", "termios",
39 "zlib", "bz2", "_md5", "_minimal_curses",
40 "itertools", "pyexpat", "cpyext", "array",
41 "binascii", "_multiprocessing", '_warnings', "_collections",
42 "_multibytecodec", "_continuation", "_cffi_backend",
43 "_csv", "_pypyjson", "_posixsubprocess", "_cppyy", # "micronumpy",
44 "_jitlog", "_hpy_universal"
45 # "_hashlib", "crypt"
46 ])
47
48 import rpython.rlib.rvmprof.cintf
49 if rpython.rlib.rvmprof.cintf.IS_SUPPORTED:
50 working_modules.add('_vmprof')
51 working_modules.add('faulthandler')
52
53 translation_modules = default_modules.copy()
54 translation_modules.update([
55 "fcntl", "time", "select", "signal", "_rawffi", "zlib", "struct",
56 "array", "binascii",
57 # the following are needed for pyrepl (and hence for the
58 # interactive prompt/pdb)
59 "termios", "_minimal_curses",
60 ])
61
62 reverse_debugger_disable_modules = set([
63 "_continuation", "_vmprof", "_multiprocessing",
64 "micronumpy",
65 ])
66
67 # XXX this should move somewhere else, maybe to platform ("is this posixish"
68 # check or something)
69 if sys.platform == "win32":
70 # unix only modules
71 for name in ["crypt", "fcntl", "pwd", "termios", "_minimal_curses",
72 "_posixsubprocess"]:
73 if name in working_modules:
74 working_modules.remove(name)
75 if name in translation_modules:
76 translation_modules.remove(name)
77
78 if "faulthandler" in working_modules:
79 working_modules.remove("faulthandler") # missing details
80 if "_vmprof" in working_modules:
81 working_modules.remove("_vmprof") # FIXME: missing details
82
83 # The _locale module is needed by site.py on Windows
84 default_modules.add("_locale")
85
86 # needed to invoke MSVC
87 translation_modules.update(["thread", "_winreg", "_cffi_backend"])
88
89 # not ported yet
90 if IS_64_BITS:
91 for name in ["_cppyy", "micronumpy"]:
92 if name in working_modules:
93 working_modules.remove(name)
94
95 if sys.platform == "sunos5":
96 working_modules.remove('fcntl') # LOCK_NB not defined
97 working_modules.remove("_minimal_curses")
98 working_modules.remove("termios")
99 if "_cppyy" in working_modules:
100 working_modules.remove("_cppyy") # depends on ctypes
101
102 if sys.platform.startswith('linux') and sys.maxsize <= 2**31:
103 # _hpy_universal needs tweaking to work on 32-bit linux
104 working_modules.remove('_hpy_universal')
105
106 #if sys.platform.startswith("linux"):
107 # _mach = os.popen('uname -m', 'r').read().strip()
108 # if _mach.startswith(...):
109 # working_modules.remove("_continuation")
110
111
112 module_dependencies = {
113 '_multiprocessing': [('objspace.usemodules.time', True),
114 ('objspace.usemodules.thread', True)],
115 '_cffi_backend': [('objspace.usemodules.thread', True)],
116 'cpyext': [('objspace.usemodules.array', True)],
117 '_cppyy': [('objspace.usemodules.cpyext', True)],
118 'faulthandler': [('objspace.usemodules._vmprof', True)],
119 }
120 module_suggests = {
121 # the reason you want _rawffi is for ctypes, which
122 # itself needs the interp-level struct module
123 # because 'P' is missing from the app-level one
124 "_rawffi": [("objspace.usemodules.struct", True)],
125 "cpyext": [("translation.secondaryentrypoints", "cpyext,main")],
126 }
127 if sys.platform == "win32":
128 module_suggests["cpyext"].append(("translation.shared", True))
129
130
131 pypy_optiondescription = OptionDescription("objspace", "Object Space Options", [
132 OptionDescription("usemodules", "Which Modules should be used", [
133 BoolOption(modname, "use module %s" % (modname, ),
134 default=modname in default_modules,
135 cmdline="--withmod-%s" % (modname, ),
136 requires=module_dependencies.get(modname, []),
137 suggests=module_suggests.get(modname, []),
138 negation=modname not in essential_modules,
139 )
140 for modname in all_modules]),
141
142 BoolOption("allworkingmodules", "use as many working modules as possible",
143 # NB. defaults to True, but in py.py this is overridden by
144 # a False suggestion because it takes a while to start up.
145 # Actual module enabling only occurs if
146 # enable_allworkingmodules() is called, and it depends
147 # on the selected backend.
148 default=True,
149 cmdline="--allworkingmodules",
150 negation=True),
151
152 StrOption("extmodules",
153 "Comma-separated list of third-party builtin modules",
154 cmdline="--ext",
155 default=None),
156
157 BoolOption("translationmodules",
158 "use only those modules that are needed to run translate.py on pypy",
159 default=False,
160 cmdline="--translationmodules",
161 suggests=[("objspace.allworkingmodules", False)]),
162
163 StrOption("soabi",
164 "Tag to differentiate extension modules built for different Python interpreters",
165 cmdline="--soabi",
166 default=None),
167
168 BoolOption("honor__builtins__",
169 "Honor the __builtins__ key of a module dictionary",
170 default=False),
171
172 BoolOption("disable_call_speedhacks",
173 "make sure that all calls go through space.call_args",
174 default=False),
175
176 BoolOption("disable_entrypoints",
177 "Disable external entry points, notably the"
178 " cpyext module and cffi's embedding mode.",
179 default=False,
180 requires=[("objspace.usemodules.cpyext", False)]),
181
182 BoolOption("disable_entrypoints_in_cffi",
183 "Disable only cffi's embedding mode.",
184 default=False),
185
186 ChoiceOption("hash",
187 "The hash function to use for strings: fnv from CPython 2.7"
188 " or siphash24 from CPython >= 3.4",
189 ["fnv", "siphash24"],
190 default="siphash24",
191 cmdline="--hash"),
192
193 BoolOption("hpy_cpyext_API",
194 "Enable the HPy/cpyext API in the hpy_universal module",
195 default=True),
196
197 StrOption("platlibdir",
198 "Configure the platlibdir at translation time",
199 cmdline="--platlibdir",
200 default="lib"),
201
202 OptionDescription("std", "Standard Object Space Options", [
203 BoolOption("withtproxy", "support transparent proxies",
204 default=True),
205
206 BoolOption("withprebuiltint", "prebuild commonly used int objects",
207 default=False),
208
209 IntOption("prebuiltintfrom", "lowest integer which is prebuilt",
210 default=-5, cmdline="--prebuiltintfrom"),
211
212 IntOption("prebuiltintto", "highest integer which is prebuilt",
213 default=100, cmdline="--prebuiltintto"),
214
215 BoolOption("withsmalllong", "use a version of 'long' in a C long long",
216 default=False),
217
218 BoolOption("withspecialisedtuple",
219 "use specialised tuples",
220 default=False),
221
222 BoolOption("withliststrategies",
223 "enable optimized ways to store lists of primitives ",
224 default=True),
225
226 BoolOption("withmethodcachecounter",
227 "try to cache methods and provide a counter in __pypy__. "
228 "for testing purposes only.",
229 default=False),
230 IntOption("methodcachesizeexp",
231 " 2 ** methodcachesizeexp is the size of the of the method cache ",
232 default=11),
233 BoolOption("intshortcut",
234 "special case addition and subtraction of two integers in BINARY_ADD/"
235 "/BINARY_SUBTRACT and their inplace counterparts",
236 default=False),
237 BoolOption("optimized_list_getitem",
238 "special case the 'list[integer]' expressions",
239 default=False),
240 BoolOption("newshortcut",
241 "cache and shortcut calling __new__ from builtin types",
242 default=False),
243 ]),
244 ])
245
246 def get_pypy_config(overrides=None, translating=False):
247 from rpython.config.translationoption import get_combined_translation_config
248 return get_combined_translation_config(
249 pypy_optiondescription, overrides=overrides,
250 translating=translating)
251
252 def set_pypy_opt_level(config, level):
253 """Apply PyPy-specific optimization suggestions on the 'config'.
254 The optimizations depend on the selected level and possibly on the backend.
255 """
256 # all the good optimizations for PyPy should be listed here
257 if level in ['2', '3', 'jit']:
258 config.objspace.std.suggest(intshortcut=True)
259 config.objspace.std.suggest(optimized_list_getitem=True)
260 #config.objspace.std.suggest(newshortcut=True)
261 config.objspace.std.suggest(withspecialisedtuple=True)
262 #if not IS_64_BITS:
263 # config.objspace.std.suggest(withsmalllong=True)
264
265 # extra costly optimizations only go in level 3
266 if level == '3':
267 config.translation.suggest(profopt=
268 "-c 'from richards import main;main(); "
269 "from test import pystone; pystone.main()'")
270
271 # memory-saving optimizations
272 if level == 'mem':
273 config.objspace.std.suggest(withprebuiltint=True)
274 config.objspace.std.suggest(withliststrategies=True)
275 if not IS_64_BITS:
276 config.objspace.std.suggest(withsmalllong=True)
277
278 # extra optimizations with the JIT
279 if level == 'jit':
280 pass # none at the moment
281
282 if config.translation.sandbox or config.translation.reverse_debugger:
283 config.objspace.hash = "fnv"
284
285
286 def enable_allworkingmodules(config):
287 modules = working_modules.copy()
288 if config.translation.sandbox:
289 modules = default_modules
290 if config.translation.reverse_debugger:
291 for mod in reverse_debugger_disable_modules:
292 setattr(config.objspace.usemodules, mod, False)
293 # ignore names from 'essential_modules', notably 'exceptions', which
294 # may not be present in config.objspace.usemodules at all
295 modules = [name for name in modules if name not in essential_modules]
296
297 config.objspace.usemodules.suggest(**dict.fromkeys(modules, True))
298
299 def enable_translationmodules(config):
300 modules = translation_modules
301 modules = [name for name in modules if name not in essential_modules]
302 config.objspace.usemodules.suggest(**dict.fromkeys(modules, True))
303
304
305 if __name__ == '__main__':
306 config = get_pypy_config()
307 print config.getpaths()
308 parser = to_optparse(config) #, useoptions=["translation.*"])
309 option, args = parser.parse_args()
310 print config
311 print working_modules