Skip to content
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
49 changes: 41 additions & 8 deletions doc/jit/zjit.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,35 @@ To build ZJIT on macOS:
make -j miniruby
```

To build ZJIT on Linux:

```bash
./autogen.sh

./configure \
--enable-zjit=dev \
--prefix="$HOME"/.rubies/ruby-zjit \
--disable-install-doc

make -j miniruby
```

Note that `--enable-zjit=dev` does a lot of IR validation, which will help to catch errors early but mean compilation and warmup are significantly slower.

The valid values for `--enable-zjit` are, from fastest to slowest:
* `--enable-zjit`: enable ZJIT in release mode for maximum performance
* `--enable-zjit=stats`: enable ZJIT in extended-stats mode
* `--enable-zjit=dev_nodebug`: enable ZJIT in development mode but without slow runtime checks
* `--enable-zjit=dev`: enable ZJIT in debug mode for development, also enables `RUBY_DEBUG`

### Regenerate bindings

When modifying `zjit/bindgen/src/main.rs` you need to regenerate bindings in `zjit/src/cruby_bindings.inc.rs` with:

```bash
make zjit-bindgen
```

## Documentation

You can generate and open the source level documentation in your browser using:
Expand All @@ -24,6 +53,16 @@ You can generate and open the source level documentation in your browser using:
cargo doc --document-private-items -p zjit --open
```

### Graph of the Type System

You can generate a graph of the ZJIT type hierarchy using:

```bash
ruby zjit/src/hir_type/gen_hir_type.rb > zjit/src/hir_type/hir_type.inc.rs
dot -O -Tpdf zjit_types.dot
open zjit_types.dot.pdf
```

## Testing

Note that tests link against CRuby, so directly calling `cargo test`, or `cargo nextest` should not build. All tests are instead accessed through `make`.
Expand Down Expand Up @@ -139,14 +178,8 @@ end

### Performance Ratio

The `ratio_in_zjit` stat shows the percentage of Ruby instructions executed in JIT code vs interpreter. This metric only appears when ZJIT is built with `--enable-zjit=stats` (which enables `rb_vm_insn_count` tracking) and represents a key performance indicator for ZJIT effectiveness.

To build with stats support:

```bash
./configure --enable-zjit=stats
make -j
```
The `ratio_in_zjit` stat shows the percentage of Ruby instructions executed in JIT code vs interpreter.
This metric only appears when ZJIT is built with `--enable-zjit=stats` [or more](#build-instructions) (which enables `rb_vm_insn_count` tracking) and represents a key performance indicator for ZJIT effectiveness.

### Tracing side exits

Expand Down
6 changes: 4 additions & 2 deletions lib/bundler/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def initialize(*args)

# lock --lockfile works differently than install --lockfile
unless current_cmd == "lock"
custom_lockfile = options[:lockfile] || Bundler.settings[:lockfile]
custom_lockfile = options[:lockfile] || ENV["BUNDLE_LOCKFILE"] || Bundler.settings[:lockfile]
if custom_lockfile && !custom_lockfile.empty?
Bundler::SharedHelpers.set_env "BUNDLE_LOCKFILE", File.expand_path(custom_lockfile)
reset_settings = true
Expand Down Expand Up @@ -282,8 +282,10 @@ def install
end

require_relative "cli/install"
options = self.options.dup
options["lockfile"] ||= ENV["BUNDLE_LOCKFILE"]
Bundler.settings.temporary(no_install: false) do
Install.new(options.dup).run
Install.new(options).run
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/bundler/man/gemfile.5
Original file line number Diff line number Diff line change
Expand Up @@ -494,9 +494,9 @@ The \fBbundle install\fR \fB\-\-no\-lock\fR option (which disables lockfile crea
.IP "2." 4
The \fBbundle install\fR \fB\-\-lockfile\fR option\.
.IP "3." 4
The \fBlockfile\fR method in the Gemfile\.
.IP "4." 4
The \fBBUNDLE_LOCKFILE\fR environment variable\.
.IP "4." 4
The \fBlockfile\fR method in the Gemfile\.
.IP "5." 4
The default behavior of adding \fB\.lock\fR to the end of the Gemfile name\.
.IP "" 0
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/man/gemfile.5.ronn
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,6 @@ following precedence is used:

1. The `bundle install` `--no-lock` option (which disables lockfile creation).
1. The `bundle install` `--lockfile` option.
1. The `lockfile` method in the Gemfile.
1. The `BUNDLE_LOCKFILE` environment variable.
1. The `lockfile` method in the Gemfile.
1. The default behavior of adding `.lock` to the end of the Gemfile name.
20 changes: 11 additions & 9 deletions lib/optparse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2314,42 +2314,42 @@ def message
# Raises when ambiguously completable string is encountered.
#
class AmbiguousOption < ParseError
const_set(:Reason, 'ambiguous option')
Reason = 'ambiguous option' # :nodoc:
end

#
# Raises when there is an argument for a switch which takes no argument.
#
class NeedlessArgument < ParseError
const_set(:Reason, 'needless argument')
Reason = 'needless argument' # :nodoc:
end

#
# Raises when a switch with mandatory argument has no argument.
#
class MissingArgument < ParseError
const_set(:Reason, 'missing argument')
Reason = 'missing argument' # :nodoc:
end

#
# Raises when switch is undefined.
#
class InvalidOption < ParseError
const_set(:Reason, 'invalid option')
Reason = 'invalid option' # :nodoc:
end

#
# Raises when the given argument does not match required format.
#
class InvalidArgument < ParseError
const_set(:Reason, 'invalid argument')
Reason = 'invalid argument' # :nodoc:
end

#
# Raises when the given argument word can't be completed uniquely.
#
class AmbiguousArgument < InvalidArgument
const_set(:Reason, 'ambiguous argument')
Reason = 'ambiguous argument' # :nodoc:
end

#
Expand Down Expand Up @@ -2448,9 +2448,11 @@ def initialize(*args) # :nodoc:
# and DecimalNumeric. See Acceptable argument classes (in source code).
#
module Acceptables
const_set(:DecimalInteger, OptionParser::DecimalInteger)
const_set(:OctalInteger, OptionParser::OctalInteger)
const_set(:DecimalNumeric, OptionParser::DecimalNumeric)
# :stopdoc:
DecimalInteger = OptionParser::DecimalInteger
OctalInteger = OptionParser::OctalInteger
DecimalNumeric = OptionParser::DecimalNumeric
# :startdoc:
end
end

Expand Down
14 changes: 14 additions & 0 deletions spec/bundler/commands/install_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@
expect(bundled_app("OmgFile.lock")).to exist
end

it "creates lockfile using BUNDLE_LOCKFILE instead of lockfile method" do
ENV["BUNDLE_LOCKFILE"] = "ReallyOmgFile.lock"
install_gemfile <<-G
lockfile "OmgFile.lock"
source "https://gem.repo1"
gem "myrack", "1.0"
G

expect(bundled_app("ReallyOmgFile.lock")).to exist
expect(bundled_app("OmgFile.lock")).not_to exist
ensure
ENV.delete("BUNDLE_LOCKFILE")
end

it "creates lockfile based on --lockfile option is given" do
gemfile bundled_app("OmgFile"), <<-G
source "https://gem.repo1"
Expand Down
18 changes: 11 additions & 7 deletions zjit/src/hir_type/gen_hir_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ def subtype name
end

# Helper to generate graphviz.
def to_graphviz_rec type
def to_graphviz_rec type, f
type.subtypes.each {|subtype|
puts type.name + "->" + subtype.name + ";"
f.puts type.name + "->" + subtype.name + ";"
}
type.subtypes.each {|subtype|
to_graphviz_rec subtype
to_graphviz_rec subtype, f
}
end

# Generate graphviz.
def to_graphviz type
puts "digraph G {"
to_graphviz_rec type
puts "}"
def to_graphviz type, f
f.puts "digraph G {"
to_graphviz_rec type, f
f.puts "}"
end

# ===== Start generating the type DAG =====
Expand Down Expand Up @@ -218,3 +218,7 @@ def add_union name, type_names
}
puts " ];"
puts "}"

File.open("zjit_types.dot", "w") do |f|
to_graphviz(any, f)
end