Skip to content

Instantly share code, notes, and snippets.

@pocke
Created Sep 18, 2020
Embed
What would you like to do?
ruremaでRactorを動かしたい
diff --git a/lib/bitclust/compat.rb b/lib/bitclust/compat.rb
index 26e4a5d..622fd18 100644
--- a/lib/bitclust/compat.rb
+++ b/lib/bitclust/compat.rb
@@ -42,3 +42,43 @@ def fopen(*args, &block)
end
File.open(*args, &block)
end
+
+module Enumerable
+ require 'etc'
+
+ def in_ractors(*args, size: Etc.nprocessors, &block)
+ pipe = Ractor.new { loop { Ractor.yield Ractor.recv } }
+ finish = Ractor.new { loop { Ractor.yield Ractor.recv } }
+
+ size.times.map do
+ Ractor.new(*args, pipe, finish, &block)
+ end
+
+ n = 0
+ each do |args|
+ pipe << args
+ n += 1
+ end
+
+ n.times.map do
+ finish.take
+ end
+ end
+end
+
+require 'erb'
+ERB.const_set :NOT_GIVEN, :DIRTY_HACK_TO_AVOID_RACTOR_ERROR!
+
+class ERB::Compiler
+ class Scanner
+ def self.make_scanner(src, trim_mode, percent)
+ TrimScanner.new(src, trim_mode, percent)
+ end
+ end
+end
+
+require 'uri'
+
+def URI.join(base, path)
+ base[%r!(\A\w+://[^/]+)/?!, 1] + '/' + path
+end
diff --git a/lib/bitclust/nameutils.rb b/lib/bitclust/nameutils.rb
index fe7e97b..0d3b249 100644
--- a/lib/bitclust/nameutils.rb
+++ b/lib/bitclust/nameutils.rb
@@ -17,15 +17,15 @@ module BitClust
module_function
- LIBNAME_RE = %r<[\w\-]+(/[\w\-]+)*>
- CONST_RE = /[A-Z]\w*/
- CONST_PATH_RE = /#{CONST_RE}(?:::#{CONST_RE})*/
- CLASS_NAME_RE = /(?:#{CONST_RE}(?:::compatible)?|fatal|ARGF\.class|main)/
- CLASS_PATH_RE = /(?:#{CONST_PATH_RE}(?:::compatible)?|fatal|ARGF\.class|main)/
- METHOD_NAME_RE = /\w+[?!=]?|===|==|=~|<=>|<=|>=|!=|!~|!@|!|\[\]=|\[\]|\*\*|>>|<<|\+@|\-@|[~+\-*\/%&|^<>`]/
- TYPEMARK_RE = /(?:\.|\#|\.\#|::|\$)/
- METHOD_SPEC_RE = /#{CLASS_PATH_RE}#{TYPEMARK_RE}#{METHOD_NAME_RE}/
- GVAR_RE = /\$(?:\w+|-.|\S)/
+ LIBNAME_RE = %r<[\w\-]+(/[\w\-]+)*>.freeze
+ CONST_RE = /[A-Z]\w*/.freeze
+ CONST_PATH_RE = /#{CONST_RE}(?:::#{CONST_RE})*/.freeze
+ CLASS_NAME_RE = /(?:#{CONST_RE}(?:::compatible)?|fatal|ARGF\.class|main)/.freeze
+ CLASS_PATH_RE = /(?:#{CONST_PATH_RE}(?:::compatible)?|fatal|ARGF\.class|main)/.freeze
+ METHOD_NAME_RE = /\w+[?!=]?|===|==|=~|<=>|<=|>=|!=|!~|!@|!|\[\]=|\[\]|\*\*|>>|<<|\+@|\-@|[~+\-*\/%&|^<>`]/.freeze
+ TYPEMARK_RE = /(?:\.|\#|\.\#|::|\$)/.freeze
+ METHOD_SPEC_RE = /#{CLASS_PATH_RE}#{TYPEMARK_RE}#{METHOD_NAME_RE}/.freeze
+ GVAR_RE = /\$(?:\w+|-.|\S)/.freeze
def libname?(str)
(/\A#{LIBNAME_RE}\z/o =~ str) ? true : false
@@ -125,7 +125,7 @@ module BitClust
# private module function
def split_method_id(id)
- @@split_method_id[id] ||= begin
+ begin
c, rest = id.split("/")
[c, *rest.split(%r<[/\.]>, 3)]
end
@@ -166,16 +166,16 @@ module BitClust
CHAR_TO_NAME = NAME_TO_CHAR.invert
def typechar?(c)
- CHAR_TO_NAME.key?(c)
+ {"s"=>:singleton_method, "i"=>:instance_method, "m"=>:module_function, "c"=>:constant, "v"=>:special_variable}.key?(c)
end
def typename2char(name)
- NAME_TO_CHAR[name] or
+ {:singleton_method=>"s", :instance_method=>"i", :module_function=>"m", :constant=>"c", :special_variable=>"v"}[name] or
raise "must not happen: #{name.inspect}"
end
def typechar2name(char)
- CHAR_TO_NAME[char] or
+ {"s"=>:singleton_method, "i"=>:instance_method, "m"=>:module_function, "c"=>:constant, "v"=>:special_variable}[char] or
raise "must not happen: #{char.inspect}"
end
@@ -187,19 +187,31 @@ module BitClust
'$' => 'v'
}
- CHAR_TO_MARK = MARK_TO_CHAR.invert
+ CHAR_TO_MARK = MARK_TO_CHAR.invert.freeze
def typemark?(m)
- MARK_TO_CHAR.key?(m)
+ {
+ '.' => 's',
+ '#' => 'i',
+ '.#' => 'm',
+ '::' => 'c',
+ '$' => 'v'
+ }.key?(m)
end
def typechar2mark(char)
- CHAR_TO_MARK[char] or
+ {"s"=>".", "i"=>"#", "m"=>".#", "c"=>"::", "v"=>"$"}[char] or
raise "must not happen: #{char.inspect}"
end
def typemark2char(mark)
- MARK_TO_CHAR[mark] or
+ {
+ '.' => 's',
+ '#' => 'i',
+ '.#' => 'm',
+ '::' => 'c',
+ '$' => 'v'
+ }[mark] or
raise "must not happen: #{mark.inspect}"
end
diff --git a/lib/bitclust/server.rb b/lib/bitclust/server.rb
index 4212e0d..2173833 100644
--- a/lib/bitclust/server.rb
+++ b/lib/bitclust/server.rb
@@ -35,15 +35,15 @@ module BitClust
end
class Database # reopen
- include DRb::DRbUndumped
+ # include DRb::DRbUndumped
end
class Entry # reopen
- include DRb::DRbUndumped
+ # include DRb::DRbUndumped
end
class SearchResult # reopen
- include DRb::DRbUndumped
+ # include DRb::DRbUndumped
end
end
diff --git a/lib/bitclust/subcommands/statichtml_command.rb b/lib/bitclust/subcommands/statichtml_command.rb
index 3620278..3df0bb7 100644
--- a/lib/bitclust/subcommands/statichtml_command.rb
+++ b/lib/bitclust/subcommands/statichtml_command.rb
@@ -181,8 +181,8 @@ module BitClust
end
end
- entries = db.docs + db.libraries.sort + db.classes.sort
- create_html_entries("entries", entries, manager, db)
+ # entries = db.docs + db.libraries.sort + db.classes.sort
+ # create_html_entries("entries", entries, manager, db)
create_html_methods("methods", methods, manager, db)
end
@@ -268,10 +268,16 @@ module BitClust
else
progressbar = SilentProgressBar.create(title: title, total: methods.size)
end
- methods.each do |method_name, method_entries|
- create_html_method_file(method_name, method_entries, manager, @outputdir, db)
- progressbar.title = align_progress_bar_title(method_name)
- progressbar.increment
+ @parser = nil # HACK
+ methods.each.in_ractors(self, manager, @outputdir, db) do |this, manager, outputdir, db, pipe, finish|
+ loop do
+ method_name, method_entries = *pipe.take
+ this.__send__ :create_html_method_file, method_name, method_entries, manager, outputdir, db
+ p "done #{method_name}"
+ # progressbar.title = align_progress_bar_title(method_name)
+ # progressbar.increment
+ finish << nil
+ end
end
progressbar.title = original_title
progressbar.finish
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment