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

Spawn worker processes if steep_command is specified #672

Merged
merged 2 commits into from
Nov 22, 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 bin/steep-prof
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "stackprof"

mode = (ENV["STEEP_STACKPROF_MODE"] || :wall).to_sym
mode = (ENV["STEEP_STACKPROF_MODE"] || :cpu).to_sym
out = ENV["STEEP_STACKPROF_OUT"] || "tmp/stackprof-#{mode}-steep.dump"
interval = ENV["STEEP_STACKPROF_INTERVAL"]&.to_i || 1000

Expand Down
2 changes: 1 addition & 1 deletion lib/steep/drivers/check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def run
steepfile: project.steepfile_path,
args: command_line_patterns,
delay_shutdown: true,
steep_command: jobs_option.steep_command_value,
steep_command: jobs_option.steep_command,
count: jobs_option.jobs_count_value
)

Expand Down
2 changes: 1 addition & 1 deletion lib/steep/drivers/checkfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def run
steepfile: project.steepfile_path,
args: [],
delay_shutdown: true,
steep_command: jobs_option.steep_command_value,
steep_command: jobs_option.steep_command,
count: count
)

Expand Down
4 changes: 2 additions & 2 deletions lib/steep/drivers/langserver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def project
def run
@project = load_config()

interaction_worker = Server::WorkerProcess.start_worker(:interaction, name: "interaction", steepfile: project.steepfile_path, steep_command: jobs_option.steep_command_value)
typecheck_workers = Server::WorkerProcess.start_typecheck_workers(steepfile: project.steepfile_path, args: [], steep_command: jobs_option.steep_command_value, count: jobs_option.jobs_count_value)
interaction_worker = Server::WorkerProcess.start_worker(:interaction, name: "interaction", steepfile: project.steepfile_path, steep_command: jobs_option.steep_command)
typecheck_workers = Server::WorkerProcess.start_typecheck_workers(steepfile: project.steepfile_path, args: [], steep_command: jobs_option.steep_command, count: jobs_option.jobs_count_value)

master = Server::Master.new(
project: project,
Expand Down
2 changes: 1 addition & 1 deletion lib/steep/drivers/stats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def run
steepfile: project.steepfile_path,
delay_shutdown: true,
args: command_line_patterns,
steep_command: jobs_option.steep_command_value,
steep_command: jobs_option.steep_command,
count: jobs_option.jobs_count_value
)

Expand Down
4 changes: 0 additions & 4 deletions lib/steep/drivers/utils/jobs_option.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ def default_jobs_count
def jobs_count_value
jobs_count || default_jobs_count
end

def steep_command_value
steep_command || "steep"
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/steep/drivers/watch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def run()
server_reader = LanguageServer::Protocol::Transport::Io::Reader.new(server_read)
server_writer = LanguageServer::Protocol::Transport::Io::Writer.new(server_write)

typecheck_workers = Server::WorkerProcess.start_typecheck_workers(steepfile: project.steepfile_path, args: dirs.map(&:to_s), steep_command: jobs_option.steep_command_value, count: jobs_option.jobs_count_value)
typecheck_workers = Server::WorkerProcess.start_typecheck_workers(steepfile: project.steepfile_path, args: dirs.map(&:to_s), steep_command: jobs_option.steep_command, count: jobs_option.jobs_count_value)

master = Server::Master.new(
project: project,
Expand Down
27 changes: 16 additions & 11 deletions lib/steep/server/worker_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,27 @@ def initialize(reader:, writer:, stderr:, wait_thread:, name:, index: nil)
@index = index
end

def self.start_worker(type, name:, steepfile:, steep_command: "steep", index: nil, delay_shutdown: false, patterns: [])
def self.start_worker(type, name:, steepfile:, steep_command:, index: nil, delay_shutdown: false, patterns: [])
begin
fork_worker(
type,
name: name,
steepfile: steepfile,
index: index,
delay_shutdown: delay_shutdown,
patterns: patterns
)
unless steep_command
fork_worker(
type,
name: name,
steepfile: steepfile,
index: index,
delay_shutdown: delay_shutdown,
patterns: patterns
)
else
# Use `#spawn_worker`
raise NotImplementedError
end
rescue NotImplementedError
spawn_worker(
type,
name: name,
steepfile: steepfile,
steep_command: steep_command,
steep_command: steep_command || "steep",
index: index,
delay_shutdown: delay_shutdown,
patterns: patterns
Expand Down Expand Up @@ -122,7 +127,7 @@ def self.spawn_worker(type, name:, steepfile:, steep_command:, index:, delay_shu
new(reader: reader, writer: writer, stderr: stderr, wait_thread: thread, name: name, index: index&.[](1))
end

def self.start_typecheck_workers(steepfile:, args:, steep_command: "steep", count: [Etc.nprocessors - 1, 1].max, delay_shutdown: false)
def self.start_typecheck_workers(steepfile:, args:, steep_command:, count: [Etc.nprocessors - 1, 1].max, delay_shutdown: false)
count.times.map do |i|
start_worker(
:typecheck,
Expand Down
2 changes: 0 additions & 2 deletions sig/steep/drivers/utils/jobs_option.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ module Steep
def default_jobs_count: () -> Integer

def jobs_count_value: () -> Integer

def steep_command_value: () -> String
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions sig/steep/server/worker_process.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module Steep
worker_type `type`,
name: String,
steepfile: Pathname,
?steep_command: ::String,
steep_command: String?,
?patterns: Array[String],
?delay_shutdown: bool,
?index: [Integer, Integer]?
Expand Down Expand Up @@ -76,7 +76,7 @@ module Steep
def self.start_typecheck_workers: (
steepfile: Pathname,
args: Array[String],
?steep_command: ::String,
steep_command: ::String?,
?count: Integer,
?delay_shutdown: bool
) -> Array[WorkerProcess]
Expand Down
16 changes: 8 additions & 8 deletions test/master_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -526,8 +526,8 @@ def test_code_type_check
project = Project.new(steepfile_path: steepfile)
Project::DSL.parse(project, steepfile.read)

interaction_worker = Server::WorkerProcess.start_worker(:interaction, name: "interaction", steepfile: steepfile)
typecheck_workers = Server::WorkerProcess.start_typecheck_workers(steepfile: steepfile, count: 1, args: [])
interaction_worker = Server::WorkerProcess.start_worker(:interaction, name: "interaction", steepfile: steepfile, steep_command: nil)
typecheck_workers = Server::WorkerProcess.start_typecheck_workers(steepfile: steepfile, count: 1, args: [], steep_command: nil)

master = Server::Master.new(
project: project,
Expand Down Expand Up @@ -607,8 +607,8 @@ def test_signature_type_check
project = Project.new(steepfile_path: steepfile)
Project::DSL.parse(project, steepfile.read)

interaction_worker = Server::WorkerProcess.start_worker(:interaction, name: "interaction", steepfile: steepfile)
typecheck_workers = Server::WorkerProcess.start_typecheck_workers(steepfile: steepfile, count: 1, args: [])
interaction_worker = Server::WorkerProcess.start_worker(:interaction, name: "interaction", steepfile: steepfile, steep_command: nil)
typecheck_workers = Server::WorkerProcess.start_typecheck_workers(steepfile: steepfile, count: 1, args: [], steep_command: nil)

master = Server::Master.new(project: project,
reader: worker_reader,
Expand Down Expand Up @@ -681,8 +681,8 @@ def test_code_interaction
project = Project.new(steepfile_path: steepfile)
Project::DSL.parse(project, steepfile.read)

interaction_worker = Server::WorkerProcess.start_worker(:interaction, name: "interaction", steepfile: steepfile)
typecheck_workers = Server::WorkerProcess.start_typecheck_workers(steepfile: steepfile, count: 2, args: [])
interaction_worker = Server::WorkerProcess.start_worker(:interaction, name: "interaction", steepfile: steepfile, steep_command: nil)
typecheck_workers = Server::WorkerProcess.start_typecheck_workers(steepfile: steepfile, count: 2, args: [], steep_command: nil)

master = Server::Master.new(project: project,
reader: worker_reader,
Expand Down Expand Up @@ -731,8 +731,8 @@ def test_workspace_symbol
project = Project.new(steepfile_path: steepfile)
Project::DSL.parse(project, steepfile.read)

interaction_worker = Server::WorkerProcess.start_worker(:interaction, name: "interaction", steepfile: steepfile)
typecheck_workers = Server::WorkerProcess.start_typecheck_workers(steepfile: steepfile, count: 2, args: [])
interaction_worker = Server::WorkerProcess.start_worker(:interaction, name: "interaction", steepfile: steepfile, steep_command: nil)
typecheck_workers = Server::WorkerProcess.start_typecheck_workers(steepfile: steepfile, count: 2, args: [], steep_command: nil)

master = Server::Master.new(project: project,
reader: worker_reader,
Expand Down