prism 2.0.0.rc1-aarch64-linux-gnu → 2.0.0.rc2-aarch64-linux-gnu

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b4036994b20df769f33c03ecaeed79c35c63048283601368712c38d686926f51
4
- data.tar.gz: 693b0acbe9282faea8218055aa907ac734f83a3c82f29477d7f8e6f456b221a6
3
+ metadata.gz: 8557a1e5bd84fd44413917a7b49cf8c5ec53649931a738088fc888659da503ee
4
+ data.tar.gz: 3a3f53478f70a2f23d98d991aed5faf6aec62b35fbaa472fee5c5693c7c30a8e
5
5
  SHA512:
6
- metadata.gz: 3fdc572f3cdd02cfaff667f7fb120f2edd836d008064488bb4c126852060565379eb084d31ddae5ef99d201c40962fe1504c988693685dbc5d85aa3f0dd42e3b
7
- data.tar.gz: 9405ddb6daef815aedda63df8bca23a6f168d24581ecbe2c3b3da935330675e49265a5c1b007ab20ff23575e0715b830ab992a17b382c2e111ac453c47e240f0
6
+ metadata.gz: 8a71a5a7e1df18717d7d341ee38e7cecc8a217f561f45b659c75c93cf668467cf4ed5132b64b218487878fea79c8a78e734a9ff0fbff725455dc4066ba9ca6d6
7
+ data.tar.gz: 94967a15358cbe43037bef27b2bfb7250e9fccb0ce97184dc5054803e0b9b9cf2c925d2bba96891f0f39b5c46913e1f62191d01552b7a9ae2e98db14c93243e8
data/CHANGELOG.md CHANGED
@@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
12
12
  - Precompiled platform-specific variants on rubygems.org.
13
13
  - Many documentation improvements, including a new playground.
14
14
  - Prism now ships accurate and complete RBS and RBI definitions.
15
+ - The license is now owned by the Ruby developers.
15
16
 
16
17
  ### Added
17
18
 
@@ -29,6 +30,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
29
30
  - Allow pattern matching with prism nodes to match on location slices, like `node in Prism::StringNode[content: "foo"]`.
30
31
  - `Prism.parse_file` and similar now accept anything responding to `to_path` (like `Pathname`) directly.
31
32
  - `attach_comments` was added as a valid option. Each comment is attached to the node that ends latest on the comment's line before it, otherwise to the innermost node that contains it (or to that node's statements, if only whitespace and comments come between the comment and the statements), otherwise to the top-level statements. The attached comments are available through `Node#comments` and through `pm_node_comments_size` and `pm_node_comment` in the C API, as well as `pm_parser_comment_attachment`, `pm_parser_comment_ranges_size`, and `pm_parser_comment_range`, which expose the attachments grouped by node. When the option is set, the comments on the parse result are sorted by start offset.
33
+ - `StringQuery#keyword?` was added to check if the string query matches a keyword.
34
+ - `Source#checksum` was added to retrieve the checksum of the source content.
32
35
 
33
36
  ### Changed
34
37
 
@@ -71,6 +74,7 @@ Note that for this major version, almost every change listed below is breaking.
71
74
  - Most allocations are now performed through an arena.
72
75
  - `newline_list` was renamed to `list_offset_list`.
73
76
  - `Diagnostic::message` now returns `&[u8]` instead of `&str`.
77
+ - `StringQuery` is now exposed.
74
78
 
75
79
  #### JavaScript
76
80
 
data/CODE_OF_CONDUCT.md CHANGED
@@ -55,7 +55,7 @@ further defined and clarified by project maintainers.
55
55
  ## Enforcement
56
56
 
57
57
  Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at opensource@shopify.com. All
58
+ reported by contacting the project team at ruby-core@ruby-lang.org. All
59
59
  complaints will be reviewed and investigated and will result in a response that
60
60
  is deemed necessary and appropriate to the circumstances. The project team is
61
61
  obligated to maintain confidentiality with regard to the reporter of an incident.
data/LICENSE.md CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2022-present, Shopify Inc.
1
+ Copyright 2022-present, Ruby developers
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
4
 
@@ -106,6 +106,7 @@ The header is structured like the following table:
106
106
  | `1` | 1 indicates only semantics fields were serialized, 0 indicates all fields were serialized (including location fields) |
107
107
  | string | the encoding name |
108
108
  | varsint | the start line |
109
+ | `8` | the checksum of the source up to the end of the `__END__` line in native endian order, see `pm_parser_checksum` |
109
110
  | varuint | number of newline offsets |
110
111
  | varuint* | newline offsets |
111
112
  | varuint | number of comments |
data/ext/prism/api_node.c CHANGED
@@ -253,7 +253,7 @@ pm_source_new(const pm_parser_t *parser, rb_encoding *encoding, VALUE comments,
253
253
  offsets = rb_str_new((const char *) line_offsets->offsets, line_offsets->size * sizeof(uint32_t));
254
254
  }
255
255
 
256
- VALUE source = rb_funcall(rb_cPrismSource, rb_intern("for"), 6, source_string, LONG2NUM(pm_parser_start_line(parser)), offsets, comments, comment_attachments, comment_ranges);
256
+ VALUE source = rb_funcall(rb_cPrismSource, rb_intern("for"), 7, source_string, LONG2NUM(pm_parser_start_line(parser)), offsets, comments, comment_attachments, comment_ranges, ULL2NUM(pm_parser_checksum(parser)));
257
257
  if (freeze) rb_obj_freeze(source);
258
258
 
259
259
  return source;
@@ -983,8 +983,9 @@ parse_lex_input(const uint8_t *input, size_t input_length, const pm_options_t *o
983
983
 
984
984
  result_t result = check_raise_error_option(parser, options, path_encoding);
985
985
  if (result.type == RESULT_OK) {
986
- /* Update the Source object with the correct encoding and line offsets,
987
- * which are only available after pm_parse() completes. */
986
+ /* Update the Source object with the correct encoding, line offsets,
987
+ * and source hash, which are only available after pm_parse()
988
+ * completes. */
988
989
  rb_encoding *encoding = rb_enc_find(pm_parser_encoding_name(parser));
989
990
  rb_enc_associate(source_string, encoding);
990
991
 
@@ -993,6 +994,8 @@ parse_lex_input(const uint8_t *input, size_t input_length, const pm_options_t *o
993
994
  rb_ary_store(offsets, (long) index, ULONG2NUM(line_offsets->offsets[index]));
994
995
  }
995
996
 
997
+ rb_funcall(source, rb_intern("replace_checksum"), 1, ULL2NUM(pm_parser_checksum(parser)));
998
+
996
999
  if (pm_options_freeze(options)) {
997
1000
  rb_obj_freeze(source_string);
998
1001
  rb_obj_freeze(offsets);
@@ -1678,6 +1681,20 @@ string_query_method_name_p(VALUE self, VALUE string) {
1678
1681
  return string_query(pm_string_query_method_name(source, RSTRING_LEN(string), rb_enc_get(string)->name));
1679
1682
  }
1680
1683
 
1684
+ /**
1685
+ * :markup: markdown
1686
+ * call-seq:
1687
+ * keyword?(string) -> bool
1688
+ *
1689
+ * Returns true if the string is a valid keyword, such as `if`, `defined?`, or
1690
+ * `__FILE__`.
1691
+ */
1692
+ static VALUE
1693
+ string_query_keyword_p(VALUE self, VALUE string) {
1694
+ const uint8_t *source = (const uint8_t *) check_string(string);
1695
+ return string_query(pm_string_query_keyword(source, RSTRING_LEN(string), rb_enc_get(string)->name));
1696
+ }
1697
+
1681
1698
  /******************************************************************************/
1682
1699
  /* Initialization of the extension */
1683
1700
  /******************************************************************************/
@@ -1778,6 +1795,7 @@ Init_prism(void) {
1778
1795
  rb_define_singleton_method(rb_cPrismStringQuery, "local?", string_query_local_p, 1);
1779
1796
  rb_define_singleton_method(rb_cPrismStringQuery, "constant?", string_query_constant_p, 1);
1780
1797
  rb_define_singleton_method(rb_cPrismStringQuery, "method_name?", string_query_method_name_p, 1);
1798
+ rb_define_singleton_method(rb_cPrismStringQuery, "keyword?", string_query_keyword_p, 1);
1781
1799
 
1782
1800
  Init_prism_api_node();
1783
1801
  }
@@ -1,7 +1,7 @@
1
1
  #ifndef PRISM_EXT_NODE_H
2
2
  #define PRISM_EXT_NODE_H
3
3
 
4
- #define EXPECTED_PRISM_VERSION "2.0.0.rc1"
4
+ #define EXPECTED_PRISM_VERSION "2.0.0.rc2"
5
5
 
6
6
  #include <ruby.h>
7
7
  #include <ruby/encoding.h>
@@ -4,6 +4,8 @@
4
4
  #ifndef PRISM_COMPILER_ACCEL_H
5
5
  #define PRISM_COMPILER_ACCEL_H
6
6
 
7
+ #include "prism/compiler/endianness.h"
8
+
7
9
  /**
8
10
  * Platform detection for SIMD/fast-path implementations. At most one of these
9
11
  * macros is defined, selecting the best available vectorization strategy.
@@ -17,7 +19,7 @@
17
19
  # define PRISM_HAS_NEON
18
20
  #elif (defined(__x86_64__) && defined(__SSE2__)) || (defined(_MSC_VER) && defined(_M_X64))
19
21
  # define PRISM_HAS_SSE2
20
- #elif defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
22
+ #elif defined(PRISM_LITTLE_ENDIAN_COMPTIME)
21
23
  # define PRISM_HAS_SWAR
22
24
  #endif
23
25
 
@@ -0,0 +1,46 @@
1
+ /**
2
+ * @file compiler/bswap.h
3
+ */
4
+ #ifndef PRISM_COMPILER_BSWAP_H
5
+ #define PRISM_COMPILER_BSWAP_H
6
+
7
+ /**
8
+ * Byte swap utilities for 32-bit and 64-bit integers.
9
+ */
10
+ #if defined(__GNUC__) || defined(__clang__)
11
+ #define pm_bswap32(x_) __builtin_bswap32((x_))
12
+ #define pm_bswap64(x_) __builtin_bswap64((x_))
13
+ #elif defined(_MSC_VER)
14
+ #include <stdlib.h>
15
+
16
+ #define pm_bswap32(x_) _byteswap_ulong((x_))
17
+ #define pm_bswap64(x_) _byteswap_uint64((x_))
18
+ #else
19
+ #include <stdint.h>
20
+
21
+ static uint32_t
22
+ pm_bswap32(uint32_t x) {
23
+ return (
24
+ ((x >> 24) & 0x000000FFUL) |
25
+ ((x << 24) & 0xFF000000UL) |
26
+ ((x >> 8) & 0x0000FF00UL) |
27
+ ((x << 8) & 0x00FF0000UL)
28
+ );
29
+ }
30
+
31
+ static uint64_t
32
+ pm_bswap64(uint64_t x) {
33
+ return (
34
+ ((x >> 56) & 0x00000000000000FFULL) |
35
+ ((x << 56) & 0xFF00000000000000ULL) |
36
+ ((x >> 40) & 0x000000000000FF00ULL) |
37
+ ((x << 40) & 0x00FF000000000000ULL) |
38
+ ((x >> 24) & 0x0000000000FF0000ULL) |
39
+ ((x << 24) & 0x0000FF0000000000ULL) |
40
+ ((x >> 8) & 0x00000000FF000000ULL) |
41
+ ((x << 8) & 0x000000FF00000000ULL)
42
+ );
43
+ }
44
+ #endif
45
+
46
+ #endif
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @file compiler/endianness.h
3
+ */
4
+ #ifndef PRISM_COMPILER_ENDIANNESS_H
5
+ #define PRISM_COMPILER_ENDIANNESS_H
6
+
7
+ /**
8
+ * Detect endianness at compile-time through the use of predefined macros.
9
+ */
10
+ #if defined(_WIN32) || defined(__LITTLE_ENDIAN__) || (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
11
+ #define PRISM_LITTLE_ENDIAN_COMPTIME
12
+ #endif
13
+
14
+ /**
15
+ * Determine endianness at runtime, either through predefined macros or through
16
+ * a runtime check that is usually folded.
17
+ */
18
+ #if defined(PRISM_LITTLE_ENDIAN_COMPTIME)
19
+ #define PRISM_LITTLE_ENDIAN_RUNTIME 1
20
+ #elif defined(__BIG_ENDIAN__) || (defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
21
+ #define PRISM_LITTLE_ENDIAN_RUNTIME 0
22
+ #else
23
+ #include <stdint.h>
24
+
25
+ static inline int
26
+ pm_little_endian(void) {
27
+ const union { uint32_t u; uint8_t c[4]; } one = { 1 };
28
+ return one.c[0];
29
+ }
30
+
31
+ #define PRISM_LITTLE_ENDIAN_RUNTIME pm_little_endian()
32
+ #endif
33
+
34
+ #endif
@@ -52,6 +52,9 @@ void pm_buffer_append_varsint(pm_buffer_t *buffer, int32_t value);
52
52
  /* Append a double to the buffer. */
53
53
  void pm_buffer_append_double(pm_buffer_t *buffer, double value);
54
54
 
55
+ /* Append a 64-bit unsigned integer to the buffer in native endian order. */
56
+ void pm_buffer_append_uint64(pm_buffer_t *buffer, uint64_t value);
57
+
55
58
  /* Append a unicode codepoint to the buffer. */
56
59
  bool pm_buffer_append_unicode_codepoint(pm_buffer_t *buffer, uint32_t value);
57
60
 
@@ -715,9 +715,23 @@ struct pm_parser_t {
715
715
  /* The current local scope. */
716
716
  pm_scope_t *current_scope;
717
717
 
718
+ /*
719
+ * Scopes that have been popped, kept for reuse by the next push. Scopes
720
+ * are allocated from the metadata arena, so they are never freed
721
+ * individually.
722
+ */
723
+ pm_scope_t *free_scopes;
724
+
718
725
  /* The current parsing context. */
719
726
  pm_context_node_t *current_context;
720
727
 
728
+ /*
729
+ * Context nodes that have been popped, kept for reuse by the next push.
730
+ * Context nodes are allocated from the metadata arena, so they are never
731
+ * freed individually.
732
+ */
733
+ pm_context_node_t *free_contexts;
734
+
721
735
  /*
722
736
  * The encoding functions for the current file is attached to the parser as
723
737
  * it's parsing so that it can change with a magic comment.
@@ -981,4 +995,10 @@ void pm_parser_init(pm_arena_t *arena, pm_parser_t *parser, const uint8_t *sourc
981
995
  */
982
996
  void pm_parser_cleanup(pm_parser_t *parser);
983
997
 
998
+ /*
999
+ * Returns true if the bytes between start and end spell a keyword, using the
1000
+ * same lookup that the lexer does.
1001
+ */
1002
+ bool pm_keyword_p(const uint8_t *start, const uint8_t *end);
1003
+
984
1004
  #endif
@@ -0,0 +1,16 @@
1
+ #ifndef PRISM_INTERNAL_XXH3_H
2
+ #define PRISM_INTERNAL_XXH3_H
3
+
4
+ #include <stddef.h>
5
+ #include <stdint.h>
6
+
7
+ /**
8
+ * Computes the XXH3 digest of the given input.
9
+ *
10
+ * @param input The input data to hash.
11
+ * @param length The length of the input data.
12
+ * @return The 64-bit XXH3 hash of the input data.
13
+ */
14
+ uint64_t pm_xxh3(const uint8_t *input, size_t length);
15
+
16
+ #endif
@@ -177,6 +177,27 @@ PRISM_EXPORTED_FUNCTION const pm_line_offset_list_t * pm_parser_line_offsets(con
177
177
  */
178
178
  PRISM_EXPORTED_FUNCTION const pm_location_t * pm_parser_data_loc(const pm_parser_t *parser) PRISM_NONNULL(1);
179
179
 
180
+ /**
181
+ * Returns the checksum of the source code that was parsed. The data section
182
+ * after an __END__ marker is not code, so the hash covers the source only up to
183
+ * and including the newline that ends the __END__ line. The __END__ marker is
184
+ * only found by parsing, so this must be called after pm_parse.
185
+ *
186
+ * The hash is computed from the source on each call rather than during
187
+ * parsing, so that parses that never ask for it do not pay for it. This
188
+ * requires the source to still be alive, and callers that need the value more
189
+ * than once should keep it.
190
+ *
191
+ * The hash is currently the 64-bit variant of XXH3 with a seed of 0. It is not
192
+ * cryptographic, and the algorithm may change between versions of prism, so
193
+ * hashes should only be compared against other hashes computed by the same
194
+ * version of prism.
195
+ *
196
+ * @param parser the parser whose checksum we want to get
197
+ * @returns the checksum of the source code that was parsed
198
+ */
199
+ PRISM_EXPORTED_FUNCTION uint64_t pm_parser_checksum(const pm_parser_t *parser) PRISM_NONNULL(1);
200
+
180
201
  /**
181
202
  * Returns whether the given parser is continuable, meaning that it could become
182
203
  * valid if more input were appended, as opposed to being definitively invalid.
@@ -60,4 +60,15 @@ PRISM_EXPORTED_FUNCTION pm_string_query_t pm_string_query_constant(const uint8_t
60
60
  */
61
61
  PRISM_EXPORTED_FUNCTION pm_string_query_t pm_string_query_method_name(const uint8_t *source, size_t length, const char *encoding_name) PRISM_NONNULL(1, 3);
62
62
 
63
+ /**
64
+ * Check that the slice is a keyword.
65
+ *
66
+ * @param source The source to check.
67
+ * @param length The length of the source.
68
+ * @param encoding_name The name of the encoding of the source.
69
+ * @returns PM_STRING_QUERY_TRUE if the query is true, PM_STRING_QUERY_FALSE if
70
+ * the query is false, and PM_STRING_QUERY_ERROR if the encoding was invalid.
71
+ */
72
+ PRISM_EXPORTED_FUNCTION pm_string_query_t pm_string_query_keyword(const uint8_t *source, size_t length, const char *encoding_name) PRISM_NONNULL(1, 3);
73
+
63
74
  #endif
@@ -26,7 +26,7 @@
26
26
  /**
27
27
  * The version of the Prism library as a constant string.
28
28
  */
29
- #define PRISM_VERSION "2.0.0.rc1"
29
+ #define PRISM_VERSION "2.0.0.rc2"
30
30
 
31
31
  /**
32
32
  * The prism version and the serialization format.
Binary file
Binary file
Binary file
data/lib/prism/ffi.rb CHANGED
@@ -124,6 +124,7 @@ module Prism # :nodoc:
124
124
  "pm_string_query_local",
125
125
  "pm_string_query_constant",
126
126
  "pm_string_query_method_name",
127
+ "pm_string_query_keyword",
127
128
  []
128
129
  )
129
130
 
@@ -722,6 +723,11 @@ module Prism # :nodoc:
722
723
  query(LibRubyParser.pm_string_query_method_name(string, string.bytesize, string.encoding.name))
723
724
  end
724
725
 
726
+ # Mirrors the C extension's StringQuery::keyword? method.
727
+ def keyword?(string)
728
+ query(LibRubyParser.pm_string_query_keyword(string, string.bytesize, string.encoding.name))
729
+ end
730
+
725
731
  private
726
732
 
727
733
  # Parse the enum result and return an appropriate boolean.