[DOC] RubyVM::YJIT doc improvements

* Weaken notice about API stability. A few public APIs in here now.
* Prune out APIs from the docs that are private in nature
* Enable markdown mode and ensure `--` options are quoted so they are
  rendered as two dashes in the HTML.
This commit is contained in:
Alan Wu 2023-11-10 19:08:13 -05:00
parent cdaca574ce
commit 277a3ecbf5

42
yjit.rb
View File

@ -1,35 +1,34 @@
# frozen_string_literal: true # frozen_string_literal: true
# :markup: markdown
# This module allows for introspection of YJIT, CRuby's in-process # This module allows for introspection of \YJIT, CRuby's just-in-time compiler.
# just-in-time compiler. This module exists only to help develop YJIT, as such, # Everything in the module is highly implementation specific and the API might
# everything in the module is highly implementation specific and comes with no # be less stable compared to the standard library.
# API stability guarantee whatsoever.
# #
# This module may not exist if YJIT does not support the particular platform # This module may not exist if \YJIT does not support the particular platform
# for which CRuby is built. There is also no API stability guarantee as to in # for which CRuby is built.
# what situations this module is defined.
module RubyVM::YJIT module RubyVM::YJIT
# Check if YJIT is enabled # Check if \YJIT is enabled.
def self.enabled? def self.enabled?
Primitive.cexpr! 'RBOOL(rb_yjit_enabled_p)' Primitive.cexpr! 'RBOOL(rb_yjit_enabled_p)'
end end
# Check if --yjit-stats is used. # Check if `--yjit-stats` is used.
def self.stats_enabled? def self.stats_enabled?
Primitive.rb_yjit_stats_enabled_p Primitive.rb_yjit_stats_enabled_p
end end
# Check if rb_yjit_trace_exit_locations_enabled_p is enabled. # Check if rb_yjit_trace_exit_locations_enabled_p is enabled.
def self.trace_exit_locations_enabled? def self.trace_exit_locations_enabled? # :nodoc:
Primitive.rb_yjit_trace_exit_locations_enabled_p Primitive.rb_yjit_trace_exit_locations_enabled_p
end end
# Discard statistics collected for --yjit-stats. # Discard statistics collected for `--yjit-stats`.
def self.reset_stats! def self.reset_stats!
Primitive.rb_yjit_reset_stats_bang Primitive.rb_yjit_reset_stats_bang
end end
# Enable YJIT compilation. # Enable \YJIT compilation.
def self.enable def self.enable
Primitive.rb_yjit_enable Primitive.rb_yjit_enable
end end
@ -38,7 +37,7 @@ module RubyVM::YJIT
# Primitive.rb_yjit_get_exit_locations into a format readable # Primitive.rb_yjit_get_exit_locations into a format readable
# by Stackprof. This will allow us to find the exact location of a # by Stackprof. This will allow us to find the exact location of a
# side exit in YJIT based on the instruction that is exiting. # side exit in YJIT based on the instruction that is exiting.
def self.exit_locations def self.exit_locations # :nodoc:
return unless trace_exit_locations_enabled? return unless trace_exit_locations_enabled?
results = Primitive.rb_yjit_get_exit_locations results = Primitive.rb_yjit_get_exit_locations
@ -148,8 +147,8 @@ module RubyVM::YJIT
File.binwrite(filename, Marshal.dump(RubyVM::YJIT.exit_locations)) File.binwrite(filename, Marshal.dump(RubyVM::YJIT.exit_locations))
end end
# Return a hash for statistics generated for the --yjit-stats command line option. # Return a hash for statistics generated for the `--yjit-stats` command line option.
# Return nil when option is not passed or unavailable. # Return `nil` when option is not passed or unavailable.
def self.runtime_stats(context: false) def self.runtime_stats(context: false)
stats = Primitive.rb_yjit_get_stats(context) stats = Primitive.rb_yjit_get_stats(context)
return stats if stats.nil? return stats if stats.nil?
@ -182,7 +181,7 @@ module RubyVM::YJIT
end end
# Format and print out counters as a String. This returns a non-empty # Format and print out counters as a String. This returns a non-empty
# content only when --yjit-stats is enabled. # content only when `--yjit-stats` is enabled.
def self.stats_string def self.stats_string
# Lazily require StringIO to avoid breaking miniruby # Lazily require StringIO to avoid breaking miniruby
require 'stringio' require 'stringio'
@ -191,8 +190,8 @@ module RubyVM::YJIT
strio.string strio.string
end end
# Produce disassembly for an iseq # Produce disassembly for an iseq. This requires a `--enable-yjit=dev` build.
def self.disasm(iseq) def self.disasm(iseq) # :nodoc:
# If a method or proc is passed in, get its iseq # If a method or proc is passed in, get its iseq
iseq = RubyVM::InstructionSequence.of(iseq) iseq = RubyVM::InstructionSequence.of(iseq)
@ -206,7 +205,7 @@ module RubyVM::YJIT
end end
# Produce a list of instructions compiled by YJIT for an iseq # Produce a list of instructions compiled by YJIT for an iseq
def self.insns_compiled(iseq) def self.insns_compiled(iseq) # :nodoc:
return nil unless self.enabled? return nil unless self.enabled?
# If a method or proc is passed in, get its iseq # If a method or proc is passed in, get its iseq
@ -214,7 +213,8 @@ module RubyVM::YJIT
Primitive.rb_yjit_insns_compiled(iseq) Primitive.rb_yjit_insns_compiled(iseq)
end end
# Free and recompile all existing JIT code # Discard existing compiled code to reclaim memory
# and allow for recompilations in the future.
def self.code_gc def self.code_gc
Primitive.rb_yjit_code_gc Primitive.rb_yjit_code_gc
end end
@ -233,7 +233,7 @@ module RubyVM::YJIT
end end
end end
class << self class << self # :stopdoc:
private private
def _dump_locations # :nodoc: def _dump_locations # :nodoc: