prism 0.24.0 → 0.29.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/BSDmakefile +58 -0
  3. data/CHANGELOG.md +132 -1
  4. data/Makefile +25 -18
  5. data/README.md +45 -6
  6. data/config.yml +828 -25
  7. data/docs/build_system.md +31 -0
  8. data/docs/configuration.md +4 -0
  9. data/docs/cruby_compilation.md +1 -1
  10. data/docs/parser_translation.md +14 -9
  11. data/docs/releasing.md +7 -9
  12. data/docs/ripper_translation.md +50 -0
  13. data/docs/ruby_api.md +1 -0
  14. data/docs/serialization.md +26 -5
  15. data/ext/prism/api_node.c +1037 -936
  16. data/ext/prism/api_pack.c +9 -0
  17. data/ext/prism/extconf.rb +62 -18
  18. data/ext/prism/extension.c +351 -71
  19. data/ext/prism/extension.h +5 -4
  20. data/include/prism/ast.h +539 -101
  21. data/include/prism/defines.h +106 -2
  22. data/include/prism/diagnostic.h +168 -74
  23. data/include/prism/encoding.h +22 -4
  24. data/include/prism/node.h +93 -0
  25. data/include/prism/options.h +84 -9
  26. data/include/prism/pack.h +11 -0
  27. data/include/prism/parser.h +213 -54
  28. data/include/prism/prettyprint.h +8 -0
  29. data/include/prism/static_literals.h +120 -0
  30. data/include/prism/util/pm_buffer.h +65 -2
  31. data/include/prism/util/pm_constant_pool.h +18 -1
  32. data/include/prism/util/pm_integer.h +119 -0
  33. data/include/prism/util/pm_list.h +1 -1
  34. data/include/prism/util/pm_newline_list.h +8 -0
  35. data/include/prism/util/pm_string.h +26 -2
  36. data/include/prism/version.h +2 -2
  37. data/include/prism.h +59 -1
  38. data/lib/prism/compiler.rb +8 -1
  39. data/lib/prism/debug.rb +46 -3
  40. data/lib/prism/desugar_compiler.rb +5 -3
  41. data/lib/prism/dispatcher.rb +29 -0
  42. data/lib/prism/dot_visitor.rb +141 -54
  43. data/lib/prism/dsl.rb +48 -36
  44. data/lib/prism/ffi.rb +82 -17
  45. data/lib/prism/inspect_visitor.rb +2156 -0
  46. data/lib/prism/lex_compat.rb +34 -15
  47. data/lib/prism/mutation_compiler.rb +13 -2
  48. data/lib/prism/node.rb +4453 -4459
  49. data/lib/prism/node_ext.rb +249 -30
  50. data/lib/prism/pack.rb +4 -0
  51. data/lib/prism/parse_result/comments.rb +35 -18
  52. data/lib/prism/parse_result/newlines.rb +2 -2
  53. data/lib/prism/parse_result.rb +218 -43
  54. data/lib/prism/pattern.rb +28 -10
  55. data/lib/prism/polyfill/byteindex.rb +13 -0
  56. data/lib/prism/polyfill/unpack1.rb +14 -0
  57. data/lib/prism/reflection.rb +411 -0
  58. data/lib/prism/serialize.rb +480 -112
  59. data/lib/prism/translation/parser/compiler.rb +376 -88
  60. data/lib/prism/translation/parser/lexer.rb +103 -22
  61. data/lib/prism/translation/parser/rubocop.rb +41 -13
  62. data/lib/prism/translation/parser.rb +123 -11
  63. data/lib/prism/translation/parser33.rb +1 -1
  64. data/lib/prism/translation/parser34.rb +1 -1
  65. data/lib/prism/translation/ripper/sexp.rb +125 -0
  66. data/lib/prism/translation/ripper/shim.rb +5 -0
  67. data/lib/prism/translation/ripper.rb +3216 -462
  68. data/lib/prism/translation/ruby_parser.rb +111 -56
  69. data/lib/prism/translation.rb +3 -1
  70. data/lib/prism/visitor.rb +10 -0
  71. data/lib/prism.rb +12 -20
  72. data/prism.gemspec +46 -14
  73. data/rbi/prism/compiler.rbi +12 -0
  74. data/rbi/prism/inspect_visitor.rbi +12 -0
  75. data/rbi/prism/node.rbi +8712 -0
  76. data/rbi/prism/node_ext.rbi +107 -0
  77. data/rbi/prism/parse_result.rbi +358 -0
  78. data/rbi/prism/reflection.rbi +58 -0
  79. data/rbi/prism/translation/parser.rbi +11 -0
  80. data/rbi/prism/translation/parser33.rbi +6 -0
  81. data/rbi/prism/translation/parser34.rbi +6 -0
  82. data/rbi/prism/translation/ripper.rbi +15 -0
  83. data/rbi/prism/visitor.rbi +470 -0
  84. data/rbi/prism.rbi +38 -7748
  85. data/sig/prism/compiler.rbs +9 -0
  86. data/sig/prism/dispatcher.rbs +16 -0
  87. data/sig/prism/dot_visitor.rbs +6 -0
  88. data/sig/prism/dsl.rbs +462 -0
  89. data/sig/prism/inspect_visitor.rbs +22 -0
  90. data/sig/prism/lex_compat.rbs +10 -0
  91. data/sig/prism/mutation_compiler.rbs +158 -0
  92. data/sig/prism/node.rbs +3558 -0
  93. data/sig/prism/node_ext.rbs +82 -0
  94. data/sig/prism/pack.rbs +43 -0
  95. data/sig/prism/parse_result.rbs +160 -0
  96. data/sig/prism/pattern.rbs +13 -0
  97. data/sig/prism/reflection.rbs +50 -0
  98. data/sig/prism/serialize.rbs +6 -0
  99. data/sig/prism/visitor.rbs +168 -0
  100. data/sig/prism.rbs +188 -4767
  101. data/src/diagnostic.c +636 -230
  102. data/src/encoding.c +211 -108
  103. data/src/node.c +7555 -451
  104. data/src/options.c +66 -31
  105. data/src/pack.c +33 -17
  106. data/src/prettyprint.c +1383 -1431
  107. data/src/prism.c +4734 -1310
  108. data/src/regexp.c +17 -2
  109. data/src/serialize.c +68 -46
  110. data/src/static_literals.c +638 -0
  111. data/src/token_type.c +10 -9
  112. data/src/util/pm_buffer.c +147 -20
  113. data/src/util/pm_char.c +4 -4
  114. data/src/util/pm_constant_pool.c +35 -11
  115. data/src/util/pm_integer.c +642 -0
  116. data/src/util/pm_list.c +1 -1
  117. data/src/util/pm_newline_list.c +14 -5
  118. data/src/util/pm_string.c +134 -5
  119. data/src/util/pm_string_list.c +2 -2
  120. metadata +41 -9
  121. data/docs/ripper.md +0 -36
  122. data/include/prism/util/pm_state_stack.h +0 -42
  123. data/lib/prism/node_inspector.rb +0 -68
  124. data/rbi/prism_static.rbi +0 -207
  125. data/sig/prism_static.rbs +0 -201
  126. data/src/util/pm_state_stack.c +0 -25
data/ext/prism/api_pack.c CHANGED
@@ -1,5 +1,12 @@
1
1
  #include "prism/extension.h"
2
2
 
3
+ #ifdef PRISM_EXCLUDE_PACK
4
+
5
+ void
6
+ Init_prism_pack(void) {}
7
+
8
+ #else
9
+
3
10
  static VALUE rb_cPrism;
4
11
  static VALUE rb_cPrismPack;
5
12
  static VALUE rb_cPrismPackDirective;
@@ -265,3 +272,5 @@ Init_prism_pack(void) {
265
272
  pack_symbol = ID2SYM(rb_intern("pack"));
266
273
  unpack_symbol = ID2SYM(rb_intern("unpack"));
267
274
  }
275
+
276
+ #endif
data/ext/prism/extconf.rb CHANGED
@@ -1,22 +1,31 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "rbconfig"
4
+
3
5
  if ARGV.delete("--help")
4
6
  print(<<~TEXT)
5
7
  USAGE: ruby #{$PROGRAM_NAME} [options]
6
8
 
7
9
  Flags that are always valid:
8
10
 
9
- --enable-debug-mode-build
10
- Enable debug mode build.
11
- You may also use set PRISM_DEBUG_MODE_BUILD environment variable.
11
+ --enable-build-debug
12
+ Enable debug build.
13
+ You may also set the PRISM_BUILD_DEBUG environment variable.
14
+
15
+ --enable-build-minimal
16
+ Enable minimal build.
17
+ You may also set the PRISM_BUILD_MINIMAL environment variable.
12
18
 
13
19
  --help
14
20
  Display this message.
15
21
 
16
22
  Environment variables used:
17
23
 
18
- PRISM_DEBUG_MODE_BUILD
19
- Equivalent to `--enable-debug-mode-build` when set, even if nil or blank.
24
+ PRISM_BUILD_DEBUG
25
+ Equivalent to `--enable-build-debug` when set, even if nil or blank.
26
+
27
+ PRISM_BUILD_MINIMAL
28
+ Equivalent to `--enable-build-minimal` when set, even if nil or blank.
20
29
 
21
30
  TEXT
22
31
  exit!(0)
@@ -36,25 +45,51 @@ end
36
45
  # Runs `make` in the root directory of the project. Note that this is the
37
46
  # `Makefile` for the overall project, not the `Makefile` that is being generated
38
47
  # by this script.`
39
- def make(target)
48
+ def make(env, target)
49
+ puts "Running make #{target} with #{env.inspect}"
40
50
  Dir.chdir(File.expand_path("../..", __dir__)) do
41
- system("make", target, exception: true)
51
+ system(
52
+ env,
53
+ RUBY_PLATFORM.include?("openbsd") ? "gmake" : "make",
54
+ target,
55
+ exception: true
56
+ )
42
57
  end
43
58
  end
44
59
 
45
- require "rbconfig"
46
-
47
60
  # On non-CRuby we only need the shared library since we'll interface with it
48
61
  # through FFI, so we'll build only that and not the C extension. We also avoid
49
- # `require "mkmf"` as that prepends the LLVM toolchain to PATH on TruffleRuby,
50
- # but we want to use the native toolchain here since libprism is run natively.
62
+ # `require "mkmf"` as that prepends the GraalVM LLVM toolchain to PATH on TruffleRuby < 24.0,
63
+ # but we want to use the system toolchain here since libprism is run natively.
51
64
  if RUBY_ENGINE != "ruby"
52
65
  generate_templates
53
- make("build/libprism.#{RbConfig::CONFIG["SOEXT"]}")
66
+ soext = RbConfig::CONFIG["SOEXT"]
67
+ # Pass SOEXT to avoid an extra subprocess just to query that
68
+ make({ "SOEXT" => soext }, "build/libprism.#{soext}")
54
69
  File.write("Makefile", "all install clean:\n\t@#{RbConfig::CONFIG["NULLCMD"]}\n")
55
70
  return
56
71
  end
57
72
 
73
+ # We're going to need to run `make` using prism's `Makefile`.
74
+ # We want to use the same toolchain (compiler, flags, etc) to compile libprism.a and
75
+ # the C extension since they will be linked together.
76
+ # The C extension uses RbConfig, which contains values from the toolchain that built the running Ruby.
77
+ env = RbConfig::CONFIG.slice("SOEXT", "CPPFLAGS", "CFLAGS", "CC", "AR", "ARFLAGS", "MAKEDIRS", "RMALL")
78
+
79
+ # It's possible that the Ruby that is being run wasn't actually compiled on this
80
+ # machine, in which case parts of RbConfig might be incorrect. In this case
81
+ # we'll need to do some additional checks and potentially fall back to defaults.
82
+ if env.key?("CC") && !File.exist?(env["CC"])
83
+ env.delete("CC")
84
+ env.delete("CFLAGS")
85
+ env.delete("CPPFLAGS")
86
+ end
87
+
88
+ if env.key?("AR") && !File.exist?(env["AR"])
89
+ env.delete("AR")
90
+ env.delete("ARFLAGS")
91
+ end
92
+
58
93
  require "mkmf"
59
94
 
60
95
  # First, ensure that we can find the header for the prism library.
@@ -71,13 +106,22 @@ unless find_header("prism/extension.h", File.expand_path("..", __dir__))
71
106
  raise "prism/extension.h is required"
72
107
  end
73
108
 
74
- # If `--enable-debug-mode-build` is passed to this script or the
75
- # `PRISM_DEBUG_MODE_BUILD` environment variable is defined, we'll build with the
76
- # `PRISM_DEBUG_MODE_BUILD` macro defined. This causes parse functions to
109
+ # If `--enable-build-debug` is passed to this script or the
110
+ # `PRISM_BUILD_DEBUG` environment variable is defined, we'll build with the
111
+ # `PRISM_BUILD_DEBUG` macro defined. This causes parse functions to
77
112
  # duplicate their input so that they have clearly set bounds, which is useful
78
113
  # for finding bugs that cause the parser to read off the end of the input.
79
- if enable_config("debug-mode-build", ENV["PRISM_DEBUG_MODE_BUILD"] || false)
80
- append_cflags("-DPRISM_DEBUG_MODE_BUILD")
114
+ if enable_config("build-debug", ENV["PRISM_BUILD_DEBUG"] || false)
115
+ append_cflags("-DPRISM_BUILD_DEBUG")
116
+ end
117
+
118
+ # If `--enable-build-minimal` is passed to this script or the
119
+ # `PRISM_BUILD_MINIMAL` environment variable is defined, we'll build with the
120
+ # set of defines that comprise the minimal set. This causes the parser to be
121
+ # built with minimal features, necessary for stripping out functionality when
122
+ # the size of the final built artifact is a concern.
123
+ if enable_config("build-minimal", ENV["PRISM_BUILD_MINIMAL"] || false)
124
+ append_cflags("-DPRISM_BUILD_MINIMAL")
81
125
  end
82
126
 
83
127
  # By default, all symbols are hidden in the shared library.
@@ -89,7 +133,7 @@ append_cflags("-fvisibility=hidden")
89
133
  archive_target = "build/libprism.a"
90
134
  archive_path = File.expand_path("../../#{archive_target}", __dir__)
91
135
 
92
- make(archive_target) unless File.exist?(archive_path)
136
+ make(env, archive_target) unless File.exist?(archive_path)
93
137
  $LOCAL_LIBS << " #{archive_path}"
94
138
 
95
139
  # Finally, we'll create the `Makefile` that is going to be used to configure and