Skip to content

Commit

Permalink
Merge pull request #2334 from ruby/version
Browse files Browse the repository at this point in the history
Bump to version 0.20.0
  • Loading branch information
kddnewton authored Feb 1, 2024
2 parents c0bc418 + fe489c0 commit cc7567b
Show file tree
Hide file tree
Showing 22 changed files with 64 additions and 97 deletions.
30 changes: 29 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,33 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a

## [Unreleased]

## [0.20.0] - 2024-01-01

### Added

- String literal hash keys are now marked as frozen as static literal.
- `IndexTargetNode` now always has the `ATTRIBUTE_WRITE` flag.
- `Call*Node` nodes now have an `IGNORE_VISIBILITY` flag.
- We now support the `it` default parameter.
- Errors and warnings now have levels associated with them.
- Symbols now have correct encoding flags.
- We have now merged `parser-prism` in, which provides translation to the `whitequark/parser` AST.
- We now emit errors for invalid method definition receivers.

### Changed

- We now emit errors on invalid pinned local variables.
- When passed scopes, it is now assumed that the innermost scope is the current binding.
- We now provide better error recovery for non terminated heredocs.
- Fix for `RationalNode#value` for non-decimal integers.
- Unary symbols `!@` and `~@` now unescape to `!` and `~`, respectively.
- `frozen_string_literal: false` now works properly.

### Removed

- We've removed the `locals_body_index` field.
- We've removed the `verbose` option on the various parse APIs. Warnings are now always emitted with their associated level so that consumers can decide how to handle them.

## [0.19.0] - 2023-12-14

### Added
Expand Down Expand Up @@ -296,7 +323,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a

- 🎉 Initial release! 🎉

[unreleased]: https://github.com/ruby/prism/compare/v0.19.0...HEAD
[unreleased]: https://github.com/ruby/prism/compare/v0.20.0...HEAD
[0.20.0]: https://github.com/ruby/prism/compare/v0.19.0...v0.20.0
[0.19.0]: https://github.com/ruby/prism/compare/v0.18.0...v0.19.0
[0.18.0]: https://github.com/ruby/prism/compare/v0.17.1...v0.18.0
[0.17.1]: https://github.com/ruby/prism/compare/v0.17.0...v0.17.1
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
prism (0.19.0)
prism (0.20.0)

GEM
remote: https://rubygems.org/
Expand Down
6 changes: 0 additions & 6 deletions ext/prism/extension.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ ID rb_option_id_filepath;
ID rb_option_id_encoding;
ID rb_option_id_line;
ID rb_option_id_frozen_string_literal;
ID rb_option_id_verbose;
ID rb_option_id_version;
ID rb_option_id_scopes;

Expand Down Expand Up @@ -130,8 +129,6 @@ build_options_i(VALUE key, VALUE value, VALUE argument) {
if (!NIL_P(value)) pm_options_line_set(options, NUM2INT(value));
} else if (key_id == rb_option_id_frozen_string_literal) {
if (!NIL_P(value)) pm_options_frozen_string_literal_set(options, value == Qtrue);
} else if (key_id == rb_option_id_verbose) {
pm_options_suppress_warnings_set(options, value != Qtrue);
} else if (key_id == rb_option_id_version) {
if (!NIL_P(value)) {
const char *version = check_string(value);
Expand Down Expand Up @@ -667,8 +664,6 @@ parse_input(pm_string_t *input, const pm_options_t *options) {
* integer or nil. Note that this is 1-indexed.
* * `frozen_string_literal` - whether or not the frozen string literal pragma
* has been set. This should be a boolean or nil.
* * `verbose` - the current level of verbosity. This controls whether or not
* the parser emits warnings. This should be a boolean or nil.
* * `version` - the version of prism that should be used to parse Ruby code. By
* default prism assumes you want to parse with the latest vesion of
* prism (which you can trigger with `nil` or `"latest"`). If you want to
Expand Down Expand Up @@ -1079,7 +1074,6 @@ Init_prism(void) {
rb_option_id_encoding = rb_intern_const("encoding");
rb_option_id_line = rb_intern_const("line");
rb_option_id_frozen_string_literal = rb_intern_const("frozen_string_literal");
rb_option_id_verbose = rb_intern_const("verbose");
rb_option_id_version = rb_intern_const("version");
rb_option_id_scopes = rb_intern_const("scopes");

Expand Down
2 changes: 1 addition & 1 deletion ext/prism/extension.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef PRISM_EXT_NODE_H
#define PRISM_EXT_NODE_H

#define EXPECTED_PRISM_VERSION "0.19.0"
#define EXPECTED_PRISM_VERSION "0.20.0"

#include <ruby.h>
#include <ruby/encoding.h>
Expand Down
15 changes: 0 additions & 15 deletions include/prism/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,6 @@ typedef struct {

/** Whether or not the frozen string literal option has been set. */
bool frozen_string_literal;

/**
* Whether or not we should suppress warnings. This is purposefully negated
* so that the default is to not suppress warnings, which allows us to still
* create an options struct with zeroed memory.
*/
bool suppress_warnings;
} pm_options_t;

/**
Expand Down Expand Up @@ -119,14 +112,6 @@ PRISM_EXPORTED_FUNCTION void pm_options_encoding_set(pm_options_t *options, cons
*/
PRISM_EXPORTED_FUNCTION void pm_options_frozen_string_literal_set(pm_options_t *options, bool frozen_string_literal);

/**
* Set the suppress warnings option on the given options struct.
*
* @param options The options struct to set the suppress warnings value on.
* @param suppress_warnings The suppress warnings value to set.
*/
PRISM_EXPORTED_FUNCTION void pm_options_suppress_warnings_set(pm_options_t *options, bool suppress_warnings);

/**
* Set the version option on the given options struct by parsing the given
* string. If the string contains an invalid option, this returns false.
Expand Down
7 changes: 0 additions & 7 deletions include/prism/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -727,13 +727,6 @@ struct pm_parser {
* a true value.
*/
bool frozen_string_literal;

/**
* Whether or not we should emit warnings. This will be set to false if the
* consumer of the library specified it, usually because they are parsing
* when $VERBOSE is nil.
*/
bool suppress_warnings;
};

#endif
4 changes: 2 additions & 2 deletions include/prism/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/**
* The minor version of the Prism library as an int.
*/
#define PRISM_VERSION_MINOR 19
#define PRISM_VERSION_MINOR 20

/**
* The patch version of the Prism library as an int.
Expand All @@ -24,6 +24,6 @@
/**
* The version of the Prism library as a constant string.
*/
#define PRISM_VERSION "0.19.0"
#define PRISM_VERSION "0.20.0"

#endif
12 changes: 1 addition & 11 deletions java/org/prism/ParsingOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@ public byte getValue() {
* @param line the line within the file that the parser starts on. This value is 1-indexed
* @param encoding the name of the encoding that the source file is in
* @param frozenStringLiteral whether the frozen string literal option has been set
* @param verbose whether the parser emits warnings
* @param version code of Ruby version which syntax will be used to parse
* @param scopes scopes surrounding the code that is being parsed with local variable names defined in every scope
* ordered from the outermost scope to the innermost one */
public static byte[] serialize(byte[] filepath, int line, byte[] encoding, boolean frozenStringLiteral,
boolean verbose, SyntaxVersion version, byte[][][] scopes) {
public static byte[] serialize(byte[] filepath, int line, byte[] encoding, boolean frozenStringLiteral, SyntaxVersion version, byte[][][] scopes) {
final ByteArrayOutputStream output = new ByteArrayOutputStream();

// filepath
Expand All @@ -55,14 +53,6 @@ public static byte[] serialize(byte[] filepath, int line, byte[] encoding, boole
output.write(0);
}

// verbose
boolean suppressWarnings = !verbose;
if (suppressWarnings) {
output.write(1);
} else {
output.write(0);
}

// version
output.write(version.getValue());

Expand Down
2 changes: 1 addition & 1 deletion javascript/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ruby/prism",
"version": "0.19.0",
"version": "0.20.0",
"description": "Prism Ruby parser",
"type": "module",
"main": "src/index.js",
Expand Down
5 changes: 1 addition & 4 deletions javascript/src/parsePrism.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ function dumpOptions(options) {
template.push("C");
values.push(options.frozen_string_literal === undefined ? 0 : 1);

template.push("C");
values.push(options.verbose === undefined ? 0 : 1);

template.push("C");
if (!options.version || options.version === "latest") {
values.push(0);
Expand Down Expand Up @@ -170,4 +167,4 @@ function pack(values, template) {
}

return new Uint8Array(buffer);
}
}
3 changes: 0 additions & 3 deletions lib/prism/ffi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,6 @@ def dump_options(options)
template << "C"
values << (options.fetch(:frozen_string_literal, false) ? 1 : 0)

template << "C"
values << (options.fetch(:verbose, true) ? 0 : 1)

template << "C"
values << { nil => 0, "3.3.0" => 1, "latest" => 0 }.fetch(options[:version])

Expand Down
2 changes: 1 addition & 1 deletion prism.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Gem::Specification.new do |spec|
spec.name = "prism"
spec.version = "0.19.0"
spec.version = "0.20.0"
spec.authors = ["Shopify"]
spec.email = ["ruby@shopify.com"]

Expand Down
4 changes: 2 additions & 2 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust/ruby-prism-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ruby-prism-sys"
version = "0.19.0"
version = "0.20.0"
edition = "2021"
license-file = "../../LICENSE.md"
repository = "https://github.com/ruby/prism"
Expand Down
2 changes: 1 addition & 1 deletion rust/ruby-prism-sys/tests/utils_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn version_test() {
CStr::from_ptr(version)
};

assert_eq!(&cstring.to_string_lossy(), "0.19.0");
assert_eq!(&cstring.to_string_lossy(), "0.20.0");
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions rust/ruby-prism/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ruby-prism"
version = "0.19.0"
version = "0.20.0"
edition = "2021"
license-file = "../../LICENSE.md"
repository = "https://github.com/ruby/prism"
Expand All @@ -26,7 +26,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_yaml = "0.9"

[dependencies]
ruby-prism-sys = { version = "0.19.0", path = "../ruby-prism-sys" }
ruby-prism-sys = { version = "0.20.0", path = "../ruby-prism-sys" }

[features]
default = ["vendored"]
Expand Down
32 changes: 16 additions & 16 deletions sig/prism_static.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@ module Prism
BACKEND: :CEXT | :FFI
VERSION: String

def self.parse: (String source, ?filepath: String, ?line: Integer, ?encoding: Encoding, ?frozen_string_literal: bool, ?verbose: bool, ?scopes: Array[Array[Symbol]]) -> ParseResult[ProgramNode]
def self.lex: (String source, ?filepath: String, ?line: Integer, ?encoding: Encoding, ?frozen_string_literal: bool, ?verbose: bool, ?scopes: Array[Array[Symbol]]) -> ParseResult[Array[[Token, Integer]]]
def self.parse_lex: (String source, ?filepath: String, ?line: Integer, ?encoding: Encoding, ?frozen_string_literal: bool, ?verbose: bool, ?scopes: Array[Array[Symbol]]) -> ParseResult[[ProgramNode, Array[[Token, Integer]]]]
def self.dump: (String source, ?filepath: String, ?line: Integer, ?encoding: Encoding, ?frozen_string_literal: bool, ?verbose: bool, ?scopes: Array[Array[Symbol]]) -> String
def self.parse_comments: (String source, ?filepath: String, ?line: Integer, ?encoding: Encoding, ?frozen_string_literal: bool, ?verbose: bool, ?scopes: Array[Array[Symbol]]) -> Array[Comment]
def self.parse_success?: (String source, ?filepath: String, ?line: Integer, ?encoding: Encoding, ?frozen_string_literal: bool, ?verbose: bool, ?scopes: Array[Array[Symbol]]) -> bool
def self.parse_failure?: (String source, ?filepath: String, ?line: Integer, ?encoding: Encoding, ?frozen_string_literal: bool, ?verbose: bool, ?scopes: Array[Array[Symbol]]) -> bool

def self.parse_file: (String filepath, ?line: Integer, ?encoding: Encoding, ?frozen_string_literal: bool, ?verbose: bool, ?scopes: Array[Array[Symbol]]) -> ParseResult[ProgramNode]
def self.lex_file: (String filepath, ?line: Integer, ?encoding: Encoding, ?frozen_string_literal: bool, ?verbose: bool, ?scopes: Array[Array[Symbol]]) -> ParseResult[Array[[Token, Integer]]]
def self.parse_lex_file: (String filepath, ?line: Integer, ?encoding: Encoding, ?frozen_string_literal: bool, ?verbose: bool, ?scopes: Array[Array[Symbol]]) -> ParseResult[[ProgramNode, Array[[Token, Integer]]]]
def self.dump_file: (String filepath, ?line: Integer, ?encoding: Encoding, ?frozen_string_literal: bool, ?verbose: bool, ?scopes: Array[Array[Symbol]]) -> String
def self.parse_file_comments: (String filepath, ?line: Integer, ?encoding: Encoding, ?frozen_string_literal: bool, ?verbose: bool, ?scopes: Array[Array[Symbol]]) -> Array[Comment]
def self.parse_file_failure?: (String filepath, ?line: Integer, ?encoding: Encoding, ?frozen_string_literal: bool, ?verbose: bool, ?scopes: Array[Array[Symbol]]) -> bool
def self.parse_file_success?: (String filepath, ?line: Integer, ?encoding: Encoding, ?frozen_string_literal: bool, ?verbose: bool, ?scopes: Array[Array[Symbol]]) -> bool
def self.parse: (String source, ?filepath: String, ?line: Integer, ?encoding: Encoding, ?frozen_string_literal: bool, ?scopes: Array[Array[Symbol]]) -> ParseResult[ProgramNode]
def self.lex: (String source, ?filepath: String, ?line: Integer, ?encoding: Encoding, ?frozen_string_literal: bool, ?scopes: Array[Array[Symbol]]) -> ParseResult[Array[[Token, Integer]]]
def self.parse_lex: (String source, ?filepath: String, ?line: Integer, ?encoding: Encoding, ?frozen_string_literal: bool, ?scopes: Array[Array[Symbol]]) -> ParseResult[[ProgramNode, Array[[Token, Integer]]]]
def self.dump: (String source, ?filepath: String, ?line: Integer, ?encoding: Encoding, ?frozen_string_literal: bool, ?scopes: Array[Array[Symbol]]) -> String
def self.parse_comments: (String source, ?filepath: String, ?line: Integer, ?encoding: Encoding, ?frozen_string_literal: bool, ?scopes: Array[Array[Symbol]]) -> Array[Comment]
def self.parse_success?: (String source, ?filepath: String, ?line: Integer, ?encoding: Encoding, ?frozen_string_literal: bool, ?scopes: Array[Array[Symbol]]) -> bool
def self.parse_failure?: (String source, ?filepath: String, ?line: Integer, ?encoding: Encoding, ?frozen_string_literal: bool, ?scopes: Array[Array[Symbol]]) -> bool

def self.parse_file: (String filepath, ?line: Integer, ?encoding: Encoding, ?frozen_string_literal: bool, ?scopes: Array[Array[Symbol]]) -> ParseResult[ProgramNode]
def self.lex_file: (String filepath, ?line: Integer, ?encoding: Encoding, ?frozen_string_literal: bool, ?scopes: Array[Array[Symbol]]) -> ParseResult[Array[[Token, Integer]]]
def self.parse_lex_file: (String filepath, ?line: Integer, ?encoding: Encoding, ?frozen_string_literal: bool, ?scopes: Array[Array[Symbol]]) -> ParseResult[[ProgramNode, Array[[Token, Integer]]]]
def self.dump_file: (String filepath, ?line: Integer, ?encoding: Encoding, ?frozen_string_literal: bool, ?scopes: Array[Array[Symbol]]) -> String
def self.parse_file_comments: (String filepath, ?line: Integer, ?encoding: Encoding, ?frozen_string_literal: bool, ?scopes: Array[Array[Symbol]]) -> Array[Comment]
def self.parse_file_failure?: (String filepath, ?line: Integer, ?encoding: Encoding, ?frozen_string_literal: bool, ?scopes: Array[Array[Symbol]]) -> bool
def self.parse_file_success?: (String filepath, ?line: Integer, ?encoding: Encoding, ?frozen_string_literal: bool, ?scopes: Array[Array[Symbol]]) -> bool

def self.load: (String source, String serialized) -> ParseResult[ProgramNode]

type ripper_token = [[Integer, Integer], Symbol, String, untyped]
def self.lex_compat: (String source, ?filepath: String, ?line: Integer, ?encoding: Encoding, ?frozen_string_literal: bool, ?verbose: bool, ?scopes: Array[Array[Symbol]]) -> ParseResult[Array[ripper_token]]
def self.lex_compat: (String source, ?filepath: String, ?line: Integer, ?encoding: Encoding, ?frozen_string_literal: bool, ?scopes: Array[Array[Symbol]]) -> ParseResult[Array[ripper_token]]
def self.lex_ripper: (String source) -> Array[ripper_token]

class ParseResult[T]
Expand Down
9 changes: 0 additions & 9 deletions src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@ pm_options_frozen_string_literal_set(pm_options_t *options, bool frozen_string_l
options->frozen_string_literal = frozen_string_literal;
}

/**
* Set the suppress warnings option on the given options struct.
*/
PRISM_EXPORTED_FUNCTION void
pm_options_suppress_warnings_set(pm_options_t *options, bool suppress_warnings) {
options->suppress_warnings = suppress_warnings;
}

/**
* Set the version option on the given options struct by parsing the given
* string. If the string contains an invalid option, this returns false.
Expand Down Expand Up @@ -189,7 +181,6 @@ pm_options_read(pm_options_t *options, const char *data) {
}

options->frozen_string_literal = *data++;
options->suppress_warnings = *data++;
options->version = (pm_options_version_t) *data++;

uint32_t scopes_count = pm_options_read_u32(data);
Expand Down
12 changes: 2 additions & 10 deletions src/prism.c
Original file line number Diff line number Diff line change
Expand Up @@ -553,9 +553,7 @@ pm_parser_err_token(pm_parser_t *parser, const pm_token_t *token, pm_diagnostic_
*/
static inline void
pm_parser_warn(pm_parser_t *parser, const uint8_t *start, const uint8_t *end, pm_diagnostic_id_t diag_id) {
if (!parser->suppress_warnings) {
pm_diagnostic_list_append(&parser->warning_list, start, end, diag_id);
}
pm_diagnostic_list_append(&parser->warning_list, start, end, diag_id);
}

/**
Expand Down Expand Up @@ -17767,8 +17765,7 @@ pm_parser_init(pm_parser_t *parser, const uint8_t *source, size_t size, const pm
.in_keyword_arg = false,
.current_param_name = 0,
.semantic_token_seen = false,
.frozen_string_literal = false,
.suppress_warnings = false
.frozen_string_literal = false
};

// Initialize the constant pool. We're going to completely guess as to the
Expand Down Expand Up @@ -17814,11 +17811,6 @@ pm_parser_init(pm_parser_t *parser, const uint8_t *source, size_t size, const pm
parser->frozen_string_literal = true;
}

// suppress_warnings option
if (options->suppress_warnings) {
parser->suppress_warnings = true;
}

// version option
parser->version = options->version;

Expand Down
2 changes: 1 addition & 1 deletion templates/java/org/prism/Loader.java.erb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public class Loader {
expect((byte) 'M', "incorrect prism header");

expect((byte) 0, "prism version does not match");
expect((byte) 19, "prism version does not match");
expect((byte) 20, "prism version does not match");
expect((byte) 0, "prism version does not match");

expect((byte) 1, "Loader.java requires no location fields in the serialized output");
Expand Down
2 changes: 1 addition & 1 deletion templates/javascript/src/deserialize.js.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as nodes from "./nodes.js";

const MAJOR_VERSION = 0;
const MINOR_VERSION = 19;
const MINOR_VERSION = 20;
const PATCH_VERSION = 0;

class SerializationBuffer {
Expand Down
Loading

0 comments on commit cc7567b

Please sign in to comment.