Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump Ruby checkout to 3.0 #400

Merged
merged 5 commits into from
Dec 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fixtures/small/nested_destructuring_actual.rb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
_1, (_2, _3) = []
_a, (_b, _c) = []
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to ruby/ruby#3163 -- in Ruby 3, assigning to numbered param is now a syntax error. This is technically a backwards-incompatible change for rubyfmt, but IMO I think that's fine.

2 changes: 1 addition & 1 deletion fixtures/small/nested_destructuring_expected.rb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
_1, (_2, _3) = []
_a, (_b, _c) = []
6 changes: 3 additions & 3 deletions librubyfmt/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ fn main() -> Output {
#[cfg(target_os = "linux")]
let libname = "ruby-static";
#[cfg(target_os = "macos")]
let libname = "ruby.2.7-static";
let libname = "ruby.3.0-static";
#[cfg(all(target_arch = "x86_64", windows))]
let libname = "x64-vcruntime140-ruby270-static";
let libname = "x64-vcruntime140-ruby300-static";
#[cfg(all(target_arch = "x86", windows))]
let libname = "vcruntime140-ruby270-static";
let libname = "vcruntime140-ruby300-static";
#[cfg(all(target_env = "gnu", windows))]
compile_error!("rubyfmt on Windows is currently only supported with msvc");

Expand Down
2 changes: 1 addition & 1 deletion librubyfmt/ruby_checkout
Submodule ruby_checkout updated 4130 files
34 changes: 16 additions & 18 deletions librubyfmt/rubyfmt_lib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,25 +146,25 @@ def escape_percent_array_paren_content(part, pattern)

define_method(:"on_#{event}_add") do |parts, part|
delim = parts[1][0][1]
parts.tap do |node|
unless delim.end_with?('[')
delim_start = delim[-1]
delim_close = DELIM_CLOSE_PAREN[delim_start]
pattern = if delim_close
/(?<!\\)(?:\\\\)*(?:\\[#{Regexp.escape(delim_start)}#{Regexp.escape(delim_close)}]|[\[\]])/
else
/(?<!\\)(?:\\\\)*(?:\\#{Regexp.escape(delim_start)}|[\[\]])/
end
if part[0].is_a?(Array)
part.each do |sub_part|
escape_percent_array_paren_content(sub_part, pattern)
end
else
escape_percent_array_paren_content(part, pattern)

unless delim.end_with?('[')
Copy link
Collaborator Author

@reese reese Dec 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is due to ruby/ruby#3281, which moved tap from Object to Kernel in Ruby 3. In most cases that's fine, but since we're kinda hacking together Ruby bootstrapping here, Kernel hasn't been loaded yet, so tap doesn't exist. I also don't think we really needed it here, so I just removed it.

delim_start = delim[-1]
delim_close = DELIM_CLOSE_PAREN[delim_start]
pattern = if delim_close
/(?<!\\)(?:\\\\)*(?:\\[#{Regexp.escape(delim_start)}#{Regexp.escape(delim_close)}]|[\[\]])/
else
/(?<!\\)(?:\\\\)*(?:\\#{Regexp.escape(delim_start)}|[\[\]])/
end
if part[0].is_a?(Array)
part.each do |sub_part|
escape_percent_array_paren_content(sub_part, pattern)
end
else
escape_percent_array_paren_content(part, pattern)
end
node[1] << part
end
parts[1] << part

super(parts, part)
end
end
Expand Down Expand Up @@ -569,5 +569,3 @@ def on___end__(val)
end
end
end

GC.disable
2 changes: 2 additions & 0 deletions librubyfmt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ use simplelog::{ConfigBuilder, LevelFilter, TermLogger, TerminalMode};

extern "C" {
pub fn Init_ripper();
pub fn rb_gc_disable();
}

pub struct RubyfmtString(Box<str>);
Expand Down Expand Up @@ -193,6 +194,7 @@ unsafe fn load_ripper() -> Result<(), ()> {
"../ruby_checkout/ext/ripper/lib/ripper/sexp.rb"
))?;

rb_gc_disable();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally open to suggestions on a better way to do this since I couldn't really figure out why GC.disable seemed to be undefined after I bumped to 3, but I ended up just calling the underlying VM implementation here instead to get ~the same result.

Ok(())
}

Expand Down