pystachy 0.3.0a2__tar.gz → 0.3.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. {pystachy-0.3.0a2 → pystachy-0.3.1}/PKG-INFO +1 -1
  2. pystachy-0.3.1/VERSION +1 -0
  3. {pystachy-0.3.0a2 → pystachy-0.3.1}/pystachy.egg-info/PKG-INFO +1 -1
  4. {pystachy-0.3.0a2 → pystachy-0.3.1}/runtime.c +49 -16
  5. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/driver.py +199 -17
  6. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/program.py +15 -0
  7. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/utils.py +13 -0
  8. pystachy-0.3.0a2/VERSION +0 -1
  9. {pystachy-0.3.0a2 → pystachy-0.3.1}/LICENSE +0 -0
  10. {pystachy-0.3.0a2 → pystachy-0.3.1}/README.md +0 -0
  11. {pystachy-0.3.0a2 → pystachy-0.3.1}/THIRD_PARTY_NOTICES +0 -0
  12. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/_argparse_help.py +0 -0
  13. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/_markupbase.py +0 -0
  14. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/_pyrandom.py +0 -0
  15. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/_pystachy__io.py +0 -0
  16. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/_pystachy_abc.py +0 -0
  17. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/_pystachy_atexit.py +0 -0
  18. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/_pystachy_bfile.py +0 -0
  19. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/_pystachy_binascii.py +0 -0
  20. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/_pystachy_bytescan.py +0 -0
  21. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/_pystachy_cache.py +0 -0
  22. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/_pystachy_codecs.py +0 -0
  23. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/_pystachy_copy.py +0 -0
  24. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/_pystachy_ctypes.py +0 -0
  25. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/_pystachy_iterators.py +0 -0
  26. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/_pystachy_itertools.py +0 -0
  27. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/_pystachy_json_any.py +0 -0
  28. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/_pystachy_json_int.py +0 -0
  29. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/_pystachy_mappingproxy.py +0 -0
  30. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/_pystachy_object.py +0 -0
  31. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/_pystachy_percent.py +0 -0
  32. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/_pystachy_range.py +0 -0
  33. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/_pystachy_re_specialized.py +0 -0
  34. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/_pystachy_string.py +0 -0
  35. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/_pystachy_struct.py +0 -0
  36. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/_pystachy_thread.py +0 -0
  37. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/_pystachy_time.py +0 -0
  38. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/_pystachy_types.py +0 -0
  39. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/_pystachy_unicodedata.py +0 -0
  40. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/_pystachy_unicodedata_db.py +0 -0
  41. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/_pystachy_unicodedata_names.py +0 -0
  42. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/_pystachy_weakref.py +0 -0
  43. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/_weakrefset.py +0 -0
  44. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/argparse.py +0 -0
  45. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/bisect.py +0 -0
  46. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/codecs.py +0 -0
  47. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/collections/__init__.py +0 -0
  48. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/colorsys.py +0 -0
  49. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/contextlib.py +0 -0
  50. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/copy.py +0 -0
  51. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/csv.py +0 -0
  52. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/ctypes.py +0 -0
  53. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/curses/__init__.py +0 -0
  54. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/curses/ascii.py +0 -0
  55. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/datetime.py +0 -0
  56. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/difflib.py +0 -0
  57. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/enum.py +0 -0
  58. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/fnmatch.py +0 -0
  59. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/functools.py +0 -0
  60. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/genericpath.py +0 -0
  61. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/getopt.py +0 -0
  62. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/gettext.py +0 -0
  63. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/glob.py +0 -0
  64. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/heapq.py +0 -0
  65. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/html/__init__.py +0 -0
  66. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/html/entities.py +0 -0
  67. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/html/parser.py +0 -0
  68. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/io.py +0 -0
  69. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/json.py +0 -0
  70. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/keyword.py +0 -0
  71. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/logging/__init__.py +0 -0
  72. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/mpz.py +0 -0
  73. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/operator.py +0 -0
  74. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/pathlib.py +0 -0
  75. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/posixpath.py +0 -0
  76. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/pyobj.py +0 -0
  77. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/random.py +0 -0
  78. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/re/__init__.py +0 -0
  79. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/re/_constants.py +0 -0
  80. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/re/_sre.py +0 -0
  81. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/re/_unicode.py +0 -0
  82. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/shlex.py +0 -0
  83. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/shutil.py +0 -0
  84. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/stat.py +0 -0
  85. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/statistics.py +0 -0
  86. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/string.py +0 -0
  87. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/struct.py +0 -0
  88. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/textwrap.py +0 -0
  89. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/this.py +0 -0
  90. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/threading.py +0 -0
  91. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/token.py +0 -0
  92. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/tomllib/__init__.py +0 -0
  93. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/tomllib/_parser.py +0 -0
  94. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/tomllib/_re.py +0 -0
  95. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/tomllib/_types.py +0 -0
  96. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/traceback.py +0 -0
  97. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/types.py +0 -0
  98. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/urllib/__init__.py +0 -0
  99. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/urllib/parse.py +0 -0
  100. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/warnings.py +0 -0
  101. {pystachy-0.3.0a2 → pystachy-0.3.1}/lib/weakref.py +0 -0
  102. {pystachy-0.3.0a2 → pystachy-0.3.1}/mpz/mpz.c +0 -0
  103. {pystachy-0.3.0a2 → pystachy-0.3.1}/pyembed.c +0 -0
  104. {pystachy-0.3.0a2 → pystachy-0.3.1}/pyext.c +0 -0
  105. {pystachy-0.3.0a2 → pystachy-0.3.1}/pyproject.toml +0 -0
  106. {pystachy-0.3.0a2 → pystachy-0.3.1}/pystachy.egg-info/SOURCES.txt +0 -0
  107. {pystachy-0.3.0a2 → pystachy-0.3.1}/pystachy.egg-info/dependency_links.txt +0 -0
  108. {pystachy-0.3.0a2 → pystachy-0.3.1}/pystachy.egg-info/entry_points.txt +0 -0
  109. {pystachy-0.3.0a2 → pystachy-0.3.1}/pystachy.egg-info/top_level.txt +0 -0
  110. {pystachy-0.3.0a2 → pystachy-0.3.1}/pystachy.py +0 -0
  111. {pystachy-0.3.0a2 → pystachy-0.3.1}/pystachy_cli.py +0 -0
  112. {pystachy-0.3.0a2 → pystachy-0.3.1}/pystachy_toolchain.py +0 -0
  113. {pystachy-0.3.0a2 → pystachy-0.3.1}/runtime.py +0 -0
  114. {pystachy-0.3.0a2 → pystachy-0.3.1}/ryu/LICENSE-Boost +0 -0
  115. {pystachy-0.3.0a2 → pystachy-0.3.1}/ryu/common.h +0 -0
  116. {pystachy-0.3.0a2 → pystachy-0.3.1}/ryu/d2s.c +0 -0
  117. {pystachy-0.3.0a2 → pystachy-0.3.1}/ryu/d2s_intrinsics.h +0 -0
  118. {pystachy-0.3.0a2 → pystachy-0.3.1}/ryu/d2s_small_table.h +0 -0
  119. {pystachy-0.3.0a2 → pystachy-0.3.1}/ryu/digit_table.h +0 -0
  120. {pystachy-0.3.0a2 → pystachy-0.3.1}/ryu/ryu.h +0 -0
  121. {pystachy-0.3.0a2 → pystachy-0.3.1}/setup.cfg +0 -0
  122. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/__init__.py +0 -0
  123. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/__init__.py +0 -0
  124. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/analysis.py +0 -0
  125. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/argparse_schema.py +0 -0
  126. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/bigints.py +0 -0
  127. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/builtins.py +0 -0
  128. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/cache_toolchain.py +0 -0
  129. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/cached_run.py +0 -0
  130. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/callbacks.py +0 -0
  131. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/calls.py +0 -0
  132. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/containers.py +0 -0
  133. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/conversions.py +0 -0
  134. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/ctypes_schema.py +0 -0
  135. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/declarations.py +0 -0
  136. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/diagnostics.py +0 -0
  137. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/dynamic.py +0 -0
  138. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/emission.py +0 -0
  139. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/exceptions.py +0 -0
  140. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/expressions.py +0 -0
  141. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/flow.py +0 -0
  142. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/functions.py +0 -0
  143. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/gen.py +0 -0
  144. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/generators.py +0 -0
  145. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/ir.py +0 -0
  146. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/ircheck.py +0 -0
  147. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/lexer.py +0 -0
  148. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/llvm_abi.py +0 -0
  149. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/loader.py +0 -0
  150. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/local_versions.py +0 -0
  151. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/lower_module.py +0 -0
  152. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/lowering.py +0 -0
  153. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/memory_ir.py +0 -0
  154. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/module.py +0 -0
  155. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/names.py +0 -0
  156. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/optimizations.py +0 -0
  157. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/parser.py +0 -0
  158. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/program_cache.py +0 -0
  159. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/reflection.py +0 -0
  160. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/scalar_ir.py +0 -0
  161. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/scope.py +0 -0
  162. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/source_lines.py +0 -0
  163. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/specs.py +0 -0
  164. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/statements.py +0 -0
  165. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/structs.py +0 -0
  166. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/syntax.py +0 -0
  167. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/templates.py +0 -0
  168. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/union_arithmetic.py +0 -0
  169. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/union_proof.py +0 -0
  170. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/union_state.py +0 -0
  171. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/unions.py +0 -0
  172. {pystachy-0.3.0a2 → pystachy-0.3.1}/src/pystachy_compiler/variables.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pystachy
3
- Version: 0.3.0a2
3
+ Version: 0.3.1
4
4
  Summary: Compile a typed subset of Python to native code through LLVM
5
5
  License-Expression: MIT
6
6
  Project-URL: Source, https://github.com/den-run-ai/pystachy
pystachy-0.3.1/VERSION ADDED
@@ -0,0 +1 @@
1
+ v0.3.1
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pystachy
3
- Version: 0.3.0a2
3
+ Version: 0.3.1
4
4
  Summary: Compile a typed subset of Python to native code through LLVM
5
5
  License-Expression: MIT
6
6
  Project-URL: Source, https://github.com/den-run-ai/pystachy
@@ -1490,23 +1490,45 @@ double pys_float_str(Str *s) {
1490
1490
  const char *p = t->s, *e = t->s + t->len;
1491
1491
  while (p < e && aws(*p)) p++;
1492
1492
  while (e > p && aws(e[-1])) e--;
1493
- Buf b = {0}; const char *q = p;
1494
- if (q < e && (*q == '+' || *q == '-')) put(&b, q++, 1);
1493
+ const char *q = p;
1494
+ if (q < e && (*q == '+' || *q == '-')) q++;
1495
1495
  I n = e - q;
1496
- if ((n == 3 && !strncasecmp(q, "inf", 3)) || (n == 8 && !strncasecmp(q, "infinity", 8)) || (n == 3 && !strncasecmp(q, "nan", 3))) {
1497
- put(&b, q, n); put(&b, "", 1); return fstrtod(b.p, 0);
1498
- }
1499
- int digits = 0, prev = 0; /* prev: 1 after a digit; underscores only between digits */
1500
- for (; q < e; q++) {
1496
+ int special = (n == 3 && !strncasecmp(q, "inf", 3)) ||
1497
+ (n == 8 && !strncasecmp(q, "infinity", 8)) ||
1498
+ (n == 3 && !strncasecmp(q, "nan", 3));
1499
+ int digits = 0, prev = 0, underscores = 0;
1500
+ /* Preserve Python's lexical checks before asking libc to validate decimal
1501
+ syntax. In particular, reject NUL, hex floats and misplaced underscores. */
1502
+ if (!special) for (; q < e; q++) {
1501
1503
  char c = *q;
1502
- if (c >= '0' && c <= '9') { digits = 1; prev = 1; put(&b, q, 1); continue; }
1503
- if (c == '_' && prev && q + 1 < e && q[1] >= '0' && q[1] <= '9') { prev = 0; continue; }
1504
- if (c == '.' || c == 'e' || c == 'E' || ((c == '+' || c == '-') && q > p && (q[-1] | 32) == 'e')) { prev = 0; put(&b, q, 1); continue; }
1504
+ if (c >= '0' && c <= '9') { digits = 1; prev = 1; continue; }
1505
+ if (c == '_' && prev && q + 1 < e && q[1] >= '0' && q[1] <= '9') {
1506
+ prev = 0; underscores = 1; continue;
1507
+ }
1508
+ if (c == '.' || c == 'e' || c == 'E' ||
1509
+ ((c == '+' || c == '-') && q > p && (q[-1] | 32) == 'e')) { prev = 0; continue; }
1505
1510
  badlit("ValueError: could not convert string to float", -1, s);
1506
1511
  }
1507
- put(&b, "", 1);
1508
- char *end; double v = fstrtod(b.p, &end);
1509
- if (!digits || *end) badlit("ValueError: could not convert string to float", -1, s);
1512
+ if (!special && !digits) badlit("ValueError: could not convert string to float", -1, s);
1513
+ const char *parse = p, *limit = e;
1514
+ Buf b = {0};
1515
+ if (underscores) {
1516
+ /* Filtering remains necessary, but reserve once instead of growing for
1517
+ individual characters. Never pass the unfiltered source to strtod. */
1518
+ b.cap = e - p + 1; b.p = gc_raw(b.cap);
1519
+ for (q = p; q < e; q++) if (*q != '_') b.p[b.n++] = *q;
1520
+ b.p[b.n] = 0;
1521
+ parse = b.p; limit = b.p + b.n;
1522
+ } else if (e != t->s + t->len) {
1523
+ /* A trimmed end is not a terminator. Copy exactly the validated span so
1524
+ strtod cannot consume a suffix beyond its logical end. */
1525
+ put(&b, p, e - p); put(&b, "", 1);
1526
+ parse = b.p; limit = b.p + b.n - 1;
1527
+ }
1528
+ /* Direct only when e is the real string terminator. All bytes up to it were
1529
+ validated above; Str owns that terminator even for embedded/sliced text. */
1530
+ char *end; double v = fstrtod(parse, &end);
1531
+ if (end != limit) badlit("ValueError: could not convert string to float", -1, s);
1510
1532
  return v;
1511
1533
  }
1512
1534
 
@@ -6813,13 +6835,24 @@ static Str *read1(File *f, I n) { /* n < 0: to the end; else n characters (
6813
6835
  }
6814
6836
  /* n characters: their bytes gather in t, and go to b only when t is full, as readline's do (a
6815
6837
  put() per byte took most of the time); a read that fits in t becomes its str without b */
6816
- char t[4096]; I m = 0;
6817
- for (I k = 0;;) {
6838
+ char t[4096]; I m = 0; int trailing = 0;
6839
+ for (I k = 0; k < n || trailing;) {
6818
6840
  int c = get(f);
6819
6841
  if (c == EOF) break;
6820
- if ((f->lat || (c & 0xC0) != 0x80) && k++ == n) { unget(f, c); break; } /* the next character starts */
6842
+ if (f->lat || (c & 0xC0) != 0x80) {
6843
+ if (k == n) { unget(f, c); break; } /* malformed UTF-8 ended before its expected continuation */
6844
+ k++;
6845
+ trailing = !f->lat && c >= 0xC2 && c <= 0xF4 ? c >= 0xF0 ? 3 : c >= 0xE0 ? 2 : 1 : 0;
6846
+ } else if (trailing) trailing--;
6821
6847
  t[m++] = (char)getnl(f, c);
6822
6848
  if (m == (I)sizeof t) { put(&b, t, m); m = 0; }
6849
+ /* A completed character satisfies read(n) without probing the next one:
6850
+ that probe blocks on live pipes, even for read(0). Universal newline=""
6851
+ still needs to resolve a final CR, like getnl does for newline=None. */
6852
+ if (k == n && !trailing && c == '\r' && f->nl == 1) {
6853
+ int d = get(f);
6854
+ if (d != EOF) unget(f, d);
6855
+ }
6823
6856
  }
6824
6857
  if (b.n) put(&b, t, m);
6825
6858
  else b = (Buf){t, m, m};
@@ -14,7 +14,7 @@ from src.pystachy_compiler.names import RENAMED
14
14
  from src.pystachy_compiler.parser import Parser
15
15
  from src.pystachy_compiler.specs import JIT_INLINE, LIBS, LINKDL, MODULES, OPTS, PLATFORM
16
16
  from src.pystachy_compiler.syntax import LAMBDAS
17
- from src.pystachy_compiler.utils import optimizations
17
+ from src.pystachy_compiler.utils import optimizations, timing_end, timing_start
18
18
 
19
19
 
20
20
  JOINS = 8 # the passes after the first that a program's joins may take (see compile_program)
@@ -108,6 +108,7 @@ def compile_program(path: str, src: str, dirs: list[str], ext: str) -> str:
108
108
  idtry = True
109
109
  slice_eh = False
110
110
  while True:
111
+ attempt = timing_start()
111
112
  g = Gen()
112
113
  g.ext = ext
113
114
  g.eh = slice_eh
@@ -121,7 +122,10 @@ def compile_program(path: str, src: str, dirs: list[str], ext: str) -> str:
121
122
  ld = Loader(dirs)
122
123
  ld.ext = ext
123
124
  try:
124
- return g.program(ld.program(path, src))
125
+ loaded = timing_start()
126
+ mods = ld.program(path, src)
127
+ timing_end("program.load", loaded)
128
+ return g.program(mods)
125
129
  except Rejoin as retry:
126
130
  if isinstance(retry, NeedSliceEH):
127
131
  slice_eh = True
@@ -148,6 +152,8 @@ def compile_program(path: str, src: str, dirs: list[str], ext: str) -> str:
148
152
  LIBS.pop()
149
153
  while len(LINKDL) > linkdl:
150
154
  LINKDL.pop()
155
+ finally:
156
+ timing_end("program.attempt", attempt)
151
157
 
152
158
 
153
159
  def runtime_ir(path: str, src: str, cache: bool) -> str:
@@ -164,7 +170,10 @@ def runtime_ir(path: str, src: str, cache: bool) -> str:
164
170
  try:
165
171
  ld = Loader([])
166
172
  ld.rtmode = True
167
- return g.program(ld.program(path, src))
173
+ loaded = timing_start()
174
+ mods = ld.program(path, src)
175
+ timing_end("runtime.load", loaded)
176
+ return g.program(mods)
168
177
  finally:
169
178
  # A failed hosted compilation must not admit runtime-only imports in the
170
179
  # next program. Nested callers retain their own temporary configuration.
@@ -195,6 +204,13 @@ def sh(cmd: str) -> int:
195
204
  return st >> 8 if st & 255 == 0 else 1
196
205
 
197
206
 
207
+ def timed_sh(name: str, cmd: str) -> int:
208
+ started = timing_start()
209
+ code = sh(cmd)
210
+ timing_end(name, started)
211
+ return code
212
+
213
+
198
214
  # the lines of /proc/cpuinfo that tell which CPU -march=native compiles for (x86-64's, AArch64's)
199
215
  CPUID: list[str] = ["vendor_id", "cpu family", "model", "model name", "stepping", "flags", "CPU implementer", "CPU architecture",
200
216
  "CPU variant", "CPU part", "CPU revision", "Features"]
@@ -250,6 +266,44 @@ def stat3(p: str) -> str:
250
266
  return ""
251
267
 
252
268
 
269
+ def runtime_c_cache_enabled(flags: list[str]) -> bool:
270
+ value = os.getenv("PYSTACHY_RUNTIME_C_CACHE", "0")
271
+ if value != "0" and value != "1":
272
+ fail("PYSTACHY_RUNTIME_C_CACHE must be 0 or 1", 0)
273
+ # Keep custom flags, instrumentation and their diagnostic ordering on the
274
+ # existing path. This first cache is deliberately limited to Linux defaults.
275
+ return value == "1" and PLATFORM == "linux" and len(flags) == 0
276
+
277
+
278
+ def runtime_c_snapshot(source: str, directory: str) -> str:
279
+ # Normalize only preprocessor line markers for our captured source tree.
280
+ # An expanded __FILE__/__BASE_FILE__ containing that directory is semantic:
281
+ # retain the ordinary build rather than rewriting a C string literal.
282
+ # Unlike __FILE__, these expand during semantic analysis, after -E.
283
+ # Their filename still depends on the original line markers.
284
+ if "__builtin_FILE" in source or "__builtin_source_location" in source:
285
+ return ""
286
+ out: list[str] = []
287
+ directory = directory.replace("\\", "\\\\").replace('"', '\\"')
288
+ for line in source.split("\n"):
289
+ if directory + "/" in line:
290
+ if not line.startswith("# "):
291
+ return ""
292
+ line = line.replace('"' + directory + "/", '"')
293
+ out.append(line)
294
+ return "\n".join(out)
295
+
296
+
297
+ def runtime_c_key(source: str, paths: list[str], times: list[str], strip: str) -> str:
298
+ # Preprocessing captures included headers, environment include paths and
299
+ # target macros. Compile those exact bytes, rather than reopening headers.
300
+ # No Pystachy executable, hosted source, runtime.py or typed-IR option belongs
301
+ # here: they do not produce this C bitcode. Bump the schema for recipe changes.
302
+ identity = ["runtime-c-v2", PLATFORM, "-O2 -fexceptions -x cpp-output", strip]
303
+ identity = identity + [os.path.realpath(p) for p in paths[:2]] + times[:2]
304
+ return fnv("\n".join(identity) + "\n" + source)
305
+
306
+
253
307
  def settled(st: str, now: float) -> bool:
254
308
  # did st's file last change more than 2 s before now? A file system keeps times at a coarse grain
255
309
  # (the kernel's clock tick, or a second on some), so a file changed again within it may show st
@@ -325,9 +379,69 @@ def compiler_version(home: str) -> str:
325
379
  return f"pystachy {version} (commit {revision})"
326
380
 
327
381
 
382
+ def output_alias(first: str, second: str) -> bool:
383
+ if os.path.realpath(first) == os.path.realpath(second):
384
+ return True
385
+ try:
386
+ return os.path.samefile(first, second)
387
+ except OSError:
388
+ return False
389
+
390
+
391
+ def check_retained_ir(path: str, source: str, output: str) -> None:
392
+ if output_alias(path, source) or output_alias(path, output):
393
+ fail("--emit-ir must name a different file from the source and executable", 0)
394
+ if os.path.isdir(path):
395
+ fail("--emit-ir must name a file, not a directory", 0)
396
+
397
+
398
+ def retained_ir_path(cmd: str, source: str, args: list[str]) -> str:
399
+ # run's remaining arguments belong to the program, not the compiler.
400
+ if cmd == "run":
401
+ return ""
402
+ path = ""
403
+ default_output = source[:-3] if source.endswith(".py") else source + ".exe"
404
+ output = default_output
405
+ i = 0
406
+ while i < len(args):
407
+ if args[i] == "-o" and i + 1 < len(args):
408
+ output = args[i + 1] or default_output
409
+ i += 2
410
+ elif args[i] == "--emit-ir":
411
+ if cmd != "build" or path != "" or i + 1 >= len(args) or args[i + 1] == "" or args[i + 1] == "-o" or args[i + 1] == "--emit-ir":
412
+ fail("--emit-ir requires one file path and is only supported by build", 0)
413
+ path = args[i + 1]
414
+ i += 2
415
+ else:
416
+ i += 1
417
+ if path != "":
418
+ check_retained_ir(path, source, output)
419
+ return path
420
+
421
+
422
+ def publish_retained_ir(path: str, source: str, output: str, ir: str, own: str) -> None:
423
+ # A private sibling directory keeps the final replace on one filesystem,
424
+ # without following an existing output symlink or overwriting a partial file.
425
+ # Publication is called only after the executable has linked successfully.
426
+ check_retained_ir(path, source, output)
427
+ staging = path + ".tmp." + own
428
+ os.mkdir(staging, 0o700)
429
+ part = staging + "/ir"
430
+ try:
431
+ f = open(part, "w", encoding=RAW)
432
+ f.write(ir)
433
+ f.close()
434
+ os.replace(part, path)
435
+ finally:
436
+ if os.path.exists(part):
437
+ os.remove(part)
438
+ os.rmdir(staging)
439
+
440
+
328
441
  def main() -> None:
329
442
  # the parser and the code generator recurse for each level of nesting (at most MAXNEST), a
330
443
  # dozen calls deep each: more than CPython's default limit of 1,000 calls when it runs this file
444
+ total = timing_start()
331
445
  sys.setrecursionlimit(MAXNEST * 40)
332
446
  argv = sys.argv
333
447
  if len(argv) == 2 and (argv[1] == "--version" or argv[1] == "-V"):
@@ -336,6 +450,7 @@ def main() -> None:
336
450
  if len(argv) < 3 or (argv[1] != "run" and argv[1] != "build" and argv[1] != "ext" and argv[1] != "ir" and argv[1] != "check" and argv[1] != "rt"):
337
451
  print("usage: pystachy run FILE.py [ARGS...] JIT-compile and run (LLVM ORC via lli)", file=sys.stderr)
338
452
  print(" pystachy build FILE.py [-o EXE] compile ahead of time to a native executable", file=sys.stderr)
453
+ print(" [--emit-ir RAW.ll] retain raw IR after a successful build", file=sys.stderr)
339
454
  print(" pystachy ext NAME.py [-o NAME.abi3.so] compile to a CPython extension module (abi3, CPython 3.12+)", file=sys.stderr)
340
455
  print(" pystachy ir FILE.py [-o OUT.ll] emit LLVM IR", file=sys.stderr)
341
456
  print(" pystachy check FILE.py only parse it, with the checks CPython makes before running it", file=sys.stderr)
@@ -346,6 +461,7 @@ def main() -> None:
346
461
  diagnostics.SRC = argv[2]
347
462
  if not os.path.exists(diagnostics.SRC):
348
463
  fail("file not found", 0)
464
+ retained = retained_ir_path(cmd, diagnostics.SRC, argv[3:])
349
465
  jitflags = ""
350
466
  if cmd == "run":
351
467
  codegen = os.getenv("PYSTACHY_JIT_CODEGEN", "2")
@@ -363,10 +479,13 @@ def main() -> None:
363
479
  f = open(diagnostics.SRC, "r", encoding=RAW)
364
480
  Parser(Lexer(f.read(), 1).file()).module()
365
481
  f.close()
482
+ timing_end("driver.total", total)
366
483
  return
367
484
  if cmd == "rt":
368
485
  f = open(diagnostics.SRC, "r", encoding=RAW)
486
+ frontend = timing_start()
369
487
  ir = runtime_ir(diagnostics.SRC, f.read(), False)
488
+ timing_end("runtime.frontend", frontend)
370
489
  f.close()
371
490
  if len(argv) == 5 and argv[3] == "-o":
372
491
  f = open(argv[4], "w", encoding=RAW)
@@ -374,6 +493,7 @@ def main() -> None:
374
493
  f.close()
375
494
  else:
376
495
  print(ir, end="")
496
+ timing_end("driver.total", total)
377
497
  return
378
498
  # the compiler that runs, for the runtime's cache (below): when named by its path, or a script
379
499
  # that CPython runs, its file's stat3() as the driver starts, and when that is
@@ -402,8 +522,11 @@ def main() -> None:
402
522
  if d != "":
403
523
  dirs.append(d)
404
524
  dirs.append(home + "/lib")
525
+ cache_start = timing_start()
405
526
  pcroot, pccontext, pcexe = cached_run.prepare(cmd, diagnostics.SRC, me, home, dirs, llvm_dir(), RTPARTS)
527
+ timing_end("program.cache_lookup", cache_start)
406
528
  if pcexe != "":
529
+ timing_end("driver.prepare_run", total)
407
530
  cached_run.execute(pcexe, diagnostics.SRC, argv[3:])
408
531
  for d in dirs[:-1]:
409
532
  if program_cache.tracked_exists(d + "/ffi.py") or program_cache.tracked_exists(d + "/ffi/__init__.py"):
@@ -413,7 +536,9 @@ def main() -> None:
413
536
  ext = diagnostics.SRC[diagnostics.SRC.rfind("/") + 1 : -3] if cmd == "ext" and diagnostics.SRC.endswith(".py") else ""
414
537
  if pcroot != "":
415
538
  cached_run.trace("frontend")
539
+ frontend = timing_start()
416
540
  ir = compile_program(diagnostics.SRC, f.read(), dirs, ext)
541
+ timing_end("program.frontend", frontend)
417
542
  f.close()
418
543
  # a program that opts in to neither dynamic Any nor promoting ints: pys_plain, below (read now, as
419
544
  # building the runtime compiles runtime.py as a program of its own, which has no opt-in)
@@ -426,6 +551,8 @@ def main() -> None:
426
551
  if argv[i] == "-o" and i + 1 < len(argv) and cmd != "run":
427
552
  out = argv[i + 1]
428
553
  i += 2
554
+ elif argv[i] == "--emit-ir" and cmd == "build":
555
+ i += 2 # validated before compiling; publish only after the native build
429
556
  elif argv[i] == "--abi" and i + 1 < len(argv) and cmd == "ext" and (argv[i + 1] == "abi3" or argv[i + 1] == "abi3t"):
430
557
  abi = argv[i + 1]
431
558
  i += 2
@@ -457,7 +584,9 @@ def main() -> None:
457
584
  f = open(out, "w", encoding=RAW)
458
585
  f.write(ir)
459
586
  f.close()
587
+ timing_end("driver.total", total)
460
588
  return
589
+ cache_start = timing_start()
461
590
  rtc = home + "/runtime.c"
462
591
  rtpy = home + "/runtime.py"
463
592
  if not os.path.exists(rtc) or not os.path.exists(rtpy):
@@ -468,6 +597,7 @@ def main() -> None:
468
597
  # if clang marked them nounwind. runtime.py goes through the optimizations on the IR as programs
469
598
  # do, so the ones PYSTACHY_OPT turns off count too: the cached runtime's key (below) has both
470
599
  flags = os.getenv("PYSTACHY_CFLAGS", "").split()
600
+ cache_c = runtime_c_cache_enabled(flags)
471
601
  asan = address_sanitized(flags)
472
602
  on = optimizations()
473
603
  off = [o for o in OPTS if o not in on]
@@ -582,6 +712,7 @@ def main() -> None:
582
712
  key = fnv("\n".join(lines + times + [rc[1], rp[1], rm[1]] + component_hashes + [x[1] for x in rs] + runtime_inputs))
583
713
  rtb = f"{cache}/runtime-py-{lin}-{key}.bc"
584
714
  rtir = ""
715
+ timing_end("runtime.cache_lookup", cache_start)
585
716
  if not trusted or not os.path.exists(rtb):
586
717
  # the bytes of runtime.c, of the files it includes and of runtime.py, read once: the runtime is
587
718
  # built from them, and named by their hash, so that an edit while it is built names another
@@ -596,7 +727,9 @@ def main() -> None:
596
727
  os.rmdir(tmp)
597
728
  src = diagnostics.SRC
598
729
  diagnostics.SRC = rtpy
730
+ frontend = timing_start()
599
731
  rtir = runtime_ir(rtpy, rp[0].replace("\r\n", "\n").replace("\r", "\n"), True)
732
+ timing_end("runtime.frontend", frontend)
600
733
  diagnostics.SRC = src
601
734
  tmp = tempfile.mkdtemp()
602
735
  ll = tmp + "/prog.ll"
@@ -683,7 +816,44 @@ def main() -> None:
683
816
  # only the ungrouped subset constructor may be renamed by llvm-link.
684
817
  modules = f"{q(rcb)} {q(rpb)}"
685
818
  sanitize = f"{tc[0]} -O2 -emit-llvm -c -x ir {q(rpl)} -o {q(rpb)} -Wno-override-module -Wno-unused-command-line-argument{cflags} -mllvm -asan-with-comdat=0 -fexceptions && "
686
- code = sh(sanitize + f"{tc[0]} -O2 -S -emit-llvm -x c {q(rcc)} -o {q(rll)} -Wno-unused-command-line-argument{cflags} -fexceptions && {strip} {q(rll)} > {q(rsl)} && {tc[1]} {q(rsl)} -o {q(rcb)} && {tc[2]} {modules} -o {q(lnk)} && {tc[3]} -O2 {q(lnk)} -o {q(part)}")
819
+ cstarted = timing_start()
820
+ cbuild = f"{tc[0]} -O2 -S -emit-llvm -x c {q(rcc)} -o {q(rll)} -Wno-unused-command-line-argument{cflags} -fexceptions && {strip} {q(rll)} > {q(rsl)} && {tc[1]} {q(rsl)} -o {q(rcb)}"
821
+ ccached = ""
822
+ cline = ""
823
+ chit = False
824
+ if cache_c and "" not in paths[:2] and "" not in times[:2] and all(settled(t, now) for t in times[:2]):
825
+ # Capture headers and target macros once; compile those same bytes.
826
+ # Warnings, semantic temporary paths and unstable tools use the
827
+ # original path so diagnostics and instrumentation stay unchanged.
828
+ pre = tmp + "/runtime.i"
829
+ perr = tmp + "/runtime-preprocess.err"
830
+ prepared = timed_sh("runtime.c_preprocess", f"{tc[0]} -O2 -E -x c {q(rcc)} -o {q(pre)} -fexceptions 2> {q(perr)}")
831
+ if prepared == 0 and os.path.getsize(perr) == 0 and [stat3(p) for p in paths[:2]] == times[:2]:
832
+ f = open(pre, "r", encoding=RAW, newline="")
833
+ captured = runtime_c_snapshot(f.read(), tmp)
834
+ f.close()
835
+ if captured != "":
836
+ cline = fnv("\n".join([os.path.realpath(p) for p in paths[:2]]))
837
+ ccached = cache + "/runtime-c-" + cline + "-" + runtime_c_key(captured, paths, times, strip) + ".bc"
838
+ f = open(pre, "w", encoding=RAW, newline="")
839
+ f.write(captured)
840
+ f.close()
841
+ # Readers take a private copy before validation; another
842
+ # build may replace/prune the entry at any point. A missing,
843
+ # unreadable or malformed entry is a miss, not a build error.
844
+ chit = timed_sh("runtime.c_cache_read", f"(test -f {q(ccached)} && test ! -L {q(ccached)} && cp {q(ccached)} {q(rcb)} && {tc[3]} -passes=verify -disable-output {q(rcb)}) 2> /dev/null") == 0
845
+ cbuild = f"{tc[0]} -O2 -S -emit-llvm -x cpp-output {q(pre)} -o {q(rll)} -Wno-unused-command-line-argument -fexceptions && {strip} {q(rll)} > {q(rsl)} && {tc[1]} {q(rsl)} -o {q(rcb)}"
846
+ code = 0 if chit else timed_sh("runtime.c", sanitize + cbuild)
847
+ if code == 0:
848
+ code = timed_sh("runtime.link_optimize", f"{tc[2]} {modules} -o {q(lnk)} && {tc[3]} -O2 {q(lnk)} -o {q(part)}")
849
+ if code == 0 and ccached != "" and not chit and [stat3(p) for p in paths[:2]] == times[:2]:
850
+ # Stage privately on the cache filesystem; rename only a complete
851
+ # file. Publication failure cannot invalidate the successful build.
852
+ # Keep one entry per tool pair; concurrent readers tolerate pruning.
853
+ stage = ccached + "." + own
854
+ old = q(cache) + "/runtime-c-" + cline + "-" + "?" * 16 + ".bc"
855
+ sh(f"""(umask 077; mkdir {q(stage)} && {{ test ! -d {q(ccached)} && cp {q(rcb)} {q(stage + '/entry')} && mv -f {q(stage + '/entry')} {q(ccached)} && for f in {old}; do [ "$f" = {q(ccached)} ] || rm -f "$f"; done; rm -f {q(stage + '/entry')}; rmdir {q(stage)}; }}) 2> /dev/null""")
856
+ timing_end("runtime.llvm_build", cstarted)
687
857
  for p in RTPARTS:
688
858
  os.remove(tmp + "/" + p)
689
859
  for d in sub:
@@ -694,7 +864,7 @@ def main() -> None:
694
864
  if code == 0 and cmd == "run" and (rtir != "" or not os.path.exists(rto)):
695
865
  # (from the bitcode, so runtime.py's part is in it; sanitizer passes instrumented the runtime already.
696
866
  # -x ir: clang would take a name not ending in .bc, as part's, for a linker input, and do nothing)
697
- code = sh(f"{tc[0]} -O2 -fPIC -c -x ir {q(usebc)} -o {q(parto)} -Wno-unused-command-line-argument{ccflags}")
867
+ code = timed_sh("runtime.codegen", f"{tc[0]} -O2 -fPIC -c -x ir {q(usebc)} -o {q(parto)} -Wno-unused-command-line-argument{ccflags}")
698
868
  useo = parto
699
869
  if code == 0 and cmd == "run" and PLATFORM == "linux" and pcroot == "":
700
870
  # the shared library: the cache's, made from the cache's .o, or one of this run's (from its own
@@ -711,7 +881,7 @@ def main() -> None:
711
881
  f.write(RTSO)
712
882
  f.close()
713
883
  xp = f"{rts}.x.{os.getpid()}.{own}"
714
- useso = partso if sh(f"{{ printf '#!/bin/sh\\n' > {q(xp)} && chmod +x {q(xp)} && {q(xp)} && {tc[0]} -shared -fPIC -O2 -x c {q(rso)} -x none {q(useo)} -o {q(partso)} -Wl,-Bsymbolic -lm -ldl -Wno-unused-command-line-argument{ccflags}; }} 2> /dev/null") == 0 else ""
884
+ useso = partso if timed_sh("runtime.shared_link", f"{{ printf '#!/bin/sh\\n' > {q(xp)} && chmod +x {q(xp)} && {q(xp)} && {tc[0]} -shared -fPIC -O2 -x c {q(rso)} -x none {q(useo)} -o {q(partso)} -Wl,-Bsymbolic -lm -ldl -Wno-unused-command-line-argument{ccflags}; }} 2> /dev/null") == 0 else ""
715
885
  sh(f"rm -f {q(xp)}")
716
886
  # pystachy ext links two more C files, compiled as runtime.c is and cached beside it by the same
717
887
  # rules: pyembed.c (CPython in the process, hosting an extension module: its stdio hooks) and
@@ -814,7 +984,7 @@ def main() -> None:
814
984
  public = f"{entry}{ext}" + (",pys_new" if newalloc else "")
815
985
  inline = (f" && {llvm}opt -passes='forceattrs,always-inline,internalize,globaldce' {LATE_INLINE}"
816
986
  f" -internalize-public-api-list={entry}{ext} {q(bc)} -o {q(bc)}") if newalloc else ""
817
- code = sh(f"{llvm}llvm-link {q(ll)} {q(glue[1][2])} {q(glue[0][2])} -o {q(lnk)} && {llvm}llvm-link --only-needed {q(lnk)} {q(usebc)} -o {q(bc)}"
987
+ code = timed_sh("extension.backend", f"{llvm}llvm-link {q(ll)} {q(glue[1][2])} {q(glue[0][2])} -o {q(lnk)} && {llvm}llvm-link --only-needed {q(lnk)} {q(usebc)} -o {q(bc)}"
818
988
  + f" && {llvm}opt -passes='internalize,default<O2>' -internalize-public-api-list={public} {q(bc)} -o {q(bc)}" + inline
819
989
  + f" && {llvm}clang -O2 -fPIC -c {q(bc)} -o {q(obj)} -Wno-unused-command-line-argument{ccflags} && {llvm}clang -shared {q(obj)} -o {q(out)}{libs} -lm{cflags}")
820
990
  elif cmd == "build":
@@ -824,12 +994,16 @@ def main() -> None:
824
994
  # optimizing it again (the same code generation: a module without pys_new keeps the one step)
825
995
  if out == "":
826
996
  out = diagnostics.SRC[:-3] if diagnostics.SRC.endswith(".py") else diagnostics.SRC + ".exe"
827
- cc = f"{llvm}clang -O2 -c {q(bc)} -o {q(obj)} -Wno-unused-command-line-argument{ccflags}"
828
- if newalloc:
829
- cc = (f"{llvm}clang -O2 -c -emit-llvm {q(bc)} -o {q(obc)} -Wno-unused-command-line-argument{ccflags}"
830
- f" && {llvm}opt -passes=forceattrs,always-inline {LATE_INLINE} {q(obc)} -o {q(lbc)}"
831
- f" && {llvm}clang -O2 -c -Xclang -disable-llvm-passes {q(lbc)} -o {q(obj)} -Wno-unused-command-line-argument{ccflags}")
832
- code = sh(f"{link} && {cc} && {llvm}clang {q(obj)} -o {q(out)}{libs} -lm{cflags}")
997
+ code = timed_sh("program.llvm_link", link)
998
+ if code == 0 and newalloc:
999
+ code = timed_sh("program.llvm_optimize", f"{llvm}clang -O2 -c -emit-llvm {q(bc)} -o {q(obc)} -Wno-unused-command-line-argument{ccflags}")
1000
+ if code == 0 and newalloc:
1001
+ code = timed_sh("program.late_inline", f"{llvm}opt -passes=forceattrs,always-inline {LATE_INLINE} {q(obc)} -o {q(lbc)}")
1002
+ if code == 0:
1003
+ cc = f"{llvm}clang -O2 -c -Xclang -disable-llvm-passes {q(lbc)}" if newalloc else f"{llvm}clang -O2 -c {q(bc)}"
1004
+ code = timed_sh("program.codegen" if newalloc else "program.optimize_codegen", cc + f" -o {q(obj)} -Wno-unused-command-line-argument{ccflags}")
1005
+ if code == 0:
1006
+ code = timed_sh("program.link", f"{llvm}clang {q(obj)} -o {q(out)}{libs} -lm{cflags}")
833
1007
  else:
834
1008
  # Match the precompiled runtime's target before instcombine folds sizeof/GEP.
835
1009
  # LLVM's default layout gives i64 only four-byte alignment; ORC later installs
@@ -902,13 +1076,13 @@ def main() -> None:
902
1076
  # there), from which lli could map nothing: the shell that runs opt first asks whether this
903
1077
  # run may execute it (Linux's access(X_OK) fails on such a mount), and exits 3 if not, when
904
1078
  # the program is written again without the callbacks' constructor, for lli to link the .o
905
- code = sh((f"[ -x {q(useso)} ] || exit 3; " if useso != "" else "") + f"{fast} {q(ll)} -o {q(bc)}")
1079
+ code = timed_sh("program.jit_optimize", (f"[ -x {q(useso)} ] || exit 3; " if useso != "" else "") + f"{fast} {q(ll)} -o {q(bc)}")
906
1080
  if code == 3 and useso != "":
907
1081
  useso = ""
908
1082
  f = open(ll, "w", encoding=RAW)
909
1083
  f.write(layout + jir)
910
1084
  f.close()
911
- code = sh(f"{fast} {q(ll)} -o {q(bc)}")
1085
+ code = timed_sh("program.jit_optimize", f"{fast} {q(ll)} -o {q(bc)}")
912
1086
  if code == 0:
913
1087
  if pcroot != "":
914
1088
  # The ordinary JIT cleanup above already ran. Disable further
@@ -930,6 +1104,7 @@ def main() -> None:
930
1104
  os.remove(p)
931
1105
  os.rmdir(tmp)
932
1106
  cached_run.trace("stored")
1107
+ timing_end("driver.prepare_run", total)
933
1108
  cached_run.execute(pcexe, diagnostics.SRC, rest)
934
1109
  cached_run.trace("bypass native artifact unavailable")
935
1110
  program_cache.stop()
@@ -941,7 +1116,7 @@ def main() -> None:
941
1116
  # PYSTACHY_GC_STRESS_PROGRAM: the program's own collection interval, apart from the
942
1117
  # compiler's (PYSTACHY_GC_STRESS), so that the tests can stress programs without stressing
943
1118
  # their compilation
944
- for p in [ll, obj, pcout, pclink, pclink2, pcerror, rcc, rll, rsl, rcb, rpl, rpb, lnk, part, hp, rso, tmp + "/pyembed.c"] + [g[3] for g in glue]:
1119
+ for p in [ll, obj, pcout, pclink, pclink2, pcerror, rcc, rll, rsl, rcb, rpl, rpb, lnk, part, hp, rso, tmp + "/runtime.i", tmp + "/runtime-preprocess.err", tmp + "/pyembed.c"] + [g[3] for g in glue]:
945
1120
  if os.path.exists(p):
946
1121
  os.remove(p)
947
1122
  gsp = os.getenv("PYSTACHY_GC_STRESS_PROGRAM", "")
@@ -961,11 +1136,18 @@ def main() -> None:
961
1136
  run = f"unset PYSTACHY_PROGRAM_CACHE_LOCK; {archive}{env}PYSTACHY_ARGV0={q(diagnostics.SRC)} exec {llvm}lli{jitflags}{pe}{rt} /dev/fd/9 {' '.join([q(a) for a in rest])}"
962
1137
  fds = f" 7< {q(peo[1])}" if embed else ""
963
1138
  parts = q(parto) + " " + q(partso) + (" " + q(peo[2]) if peo[2] != "" else "")
1139
+ timing_end("driver.prepare_run", total)
964
1140
  os.execv("/bin/sh", ["sh", "-c", f"exec 9< {q(bc)} 8< {q(useso if useso != '' else useo)}{fds} && rm -f {q(bc)} {parts} && rmdir {q(tmp)} && {run}"])
965
- for p in [ll, bc, obj, obc, lbc, pcout, pclink, pclink2, pcerror, rcc, rll, rsl, rcb, rpl, rpb, lnk, part, parto, partso, hp, rso, tmp + "/pyembed.c", tmp + "/pyext.c", peo[2]] + [g[3] for g in glue]:
1141
+ for p in [ll, bc, obj, obc, lbc, pcout, pclink, pclink2, pcerror, rcc, rll, rsl, rcb, rpl, rpb, lnk, part, parto, partso, hp, rso, tmp + "/runtime.i", tmp + "/runtime-preprocess.err", tmp + "/pyembed.c", tmp + "/pyext.c", peo[2]] + [g[3] for g in glue]:
966
1142
  if os.path.exists(p):
967
1143
  os.remove(p)
968
1144
  os.rmdir(tmp)
1145
+ if code == 0 and msg == "" and retained != "":
1146
+ try:
1147
+ publish_retained_ir(retained, diagnostics.SRC, out, ir, own)
1148
+ except OSError:
1149
+ fail("cannot write --emit-ir output: " + retained, 0)
1150
+ timing_end("driver.total", total)
969
1151
  if msg != "":
970
1152
  fail(msg, 0)
971
1153
  sys.exit(code)
@@ -53,6 +53,8 @@ from src.pystachy_compiler.utils import (
53
53
  short_ascii,
54
54
  targs,
55
55
  template_ok,
56
+ timing_end,
57
+ timing_start,
56
58
  typestr,
57
59
  )
58
60
 
@@ -801,6 +803,8 @@ def gen_abc_class(self, c: str) -> bool:
801
803
  return False
802
804
 
803
805
  def gen_program(self, mods: list[Mod]) -> str:
806
+ started = timing_start()
807
+ phase = "runtime" if self.rtmode else "program"
804
808
  self.opts = optimizations()
805
809
  self.identity_modules(mods) # (which modules' code tracks numeric identity: dynamic.py)
806
810
  # (lib's modules of range objects and of object()'s bind no global of another module: the
@@ -1111,6 +1115,8 @@ def gen_program(self, mods: list[Mod]) -> str:
1111
1115
  self.declare(st.kids[0].s, "bool")
1112
1116
  for m in mods:
1113
1117
  self.mfile[m.name] = m.path[2:] if m.path.startswith("./") else m.path
1118
+ timing_end(phase + ".prepare", started)
1119
+ started = timing_start()
1114
1120
  self.compiling = True
1115
1121
  self.modlevel = True
1116
1122
  for m in mods:
@@ -1233,10 +1239,12 @@ def gen_program(self, mods: list[Mod]) -> str:
1233
1239
  for nm in self.flagged:
1234
1240
  if nm not in self.gtypes and nm not in self.funcs and nm not in self.classes:
1235
1241
  self.global_var(f"@g.{nm}.def", "bool") # (a variable no compiled code assigns)
1242
+ timing_end(phase + ".discover", started)
1236
1243
  # Finite comparison field discoveries only grow (incompatible joins are
1237
1244
  # terminal). Finish these even if earlier fields used the ordinary join budget.
1238
1245
  if len(self.newhints) > 0 and (not self.final or any(k.startswith("cmpfield:") or k.startswith("cmpwrite:") for k in self.newhints)):
1239
1246
  raise Rejoin() # (joins found wider types: the next pass compiles them, see join_hint)
1247
+ started = timing_start()
1240
1248
  # The completed adapter set makes candidate discovery independent of which
1241
1249
  # caller first compiled a kernel. Versions add no frontend inference state.
1242
1250
  if not self.rtmode and "callbacks" in self.opts:
@@ -1263,6 +1271,8 @@ def gen_program(self, mods: list[Mod]) -> str:
1263
1271
  # storage facts, so the first verification uses complete effect summaries too.
1264
1272
  for fn in self.fns:
1265
1273
  self.verify(fn, False)
1274
+ timing_end(phase + ".analysis", started)
1275
+ started = timing_start()
1266
1276
  if len(on) > 0:
1267
1277
  # (before eh_ir: a block that a try statement covers keeps its exception edge to the
1268
1278
  # landing block, Blk.handler, which the passes count, see preds)
@@ -1272,6 +1282,8 @@ def gen_program(self, mods: list[Mod]) -> str:
1272
1282
  changed = True # optimize verifies each changed pass when checks are enabled
1273
1283
  if changed and dump:
1274
1284
  self.effects() # (what the passes left: tests/ir/*.fx pin them)
1285
+ timing_end(phase + ".optimize", started)
1286
+ started = timing_start()
1275
1287
  for fn in self.fns if self.eh else self.fns[:0]:
1276
1288
  if len(fn.tries) > 0:
1277
1289
  self.eh_ir(fn)
@@ -1282,6 +1294,8 @@ def gen_program(self, mods: list[Mod]) -> str:
1282
1294
  print(f"{fn.f.ll}: {fxs(fn.fx)}".rstrip(), file=sys.stderr)
1283
1295
  if "tupleret" in on:
1284
1296
  self.tuple_rets() # (which functions return their tuples' slots by value: lowering reads it)
1297
+ timing_end(phase + ".finalize", started)
1298
+ started = timing_start()
1285
1299
  for fn in self.fns:
1286
1300
  self.lower(fn)
1287
1301
  # its LLVM text is all that is left to print: its IR goes (its summary, IFn.fx, stays)
@@ -1293,6 +1307,7 @@ def gen_program(self, mods: list[Mod]) -> str:
1293
1307
  for op in ["eq", "cmp", "repr"] if not self.rtmode else []:
1294
1308
  self.dispatch(op) # (each program defines them: runtime.py calls them like runtime.c)
1295
1309
  ir = self.lower_module()
1310
+ timing_end(phase + ".lower", started)
1296
1311
  RENAMED.clear() # (the program's classes': runtime.py, which the driver may compile next, has none)
1297
1312
  return ir
1298
1313
 
@@ -1,6 +1,8 @@
1
1
  """Utils component of the self-hosting Pystachy compiler."""
2
2
  from __future__ import annotations
3
3
  import os
4
+ import sys
5
+ import time
4
6
  from src.pystachy_compiler.diagnostics import FILES, LINES, dynamic_program, fail, where
5
7
  from src.pystachy_compiler.ir import ClassInfo, Closure, FnInfo, Ins
6
8
  from src.pystachy_compiler.llvm_abi import llvm_decl
@@ -28,6 +30,17 @@ from src.pystachy_compiler.specs import (
28
30
  from src.pystachy_compiler.syntax import Node
29
31
 
30
32
 
33
+ def timing_start() -> float:
34
+ # Disabled timing reads no clock. A negative sentinel also permits clock zero.
35
+ return time.perf_counter() if os.getenv("PYSTACHY_TIMING", "") == "1" else -1.0
36
+
37
+
38
+ def timing_end(name: str, started: float) -> None:
39
+ if started >= 0.0:
40
+ elapsed = time.perf_counter() - started
41
+ print(f"pystachy-timing\t{name}\t{elapsed:.9f}", file=sys.stderr)
42
+
43
+
31
44
  def lib_source(line: int, libdir: str, filename: str) -> bool:
32
45
  # Private library behavior belongs to the shipped file, not a user module
33
46
  # with the same import name. Loader strips a leading ./ from recorded paths.
pystachy-0.3.0a2/VERSION DELETED
@@ -1 +0,0 @@
1
- v0.3.0-alpha.2
File without changes
File without changes
File without changes
File without changes