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

Disable TracePoints when running the check-shims command #1082

Merged
merged 1 commit into from
Jul 28, 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
12 changes: 12 additions & 0 deletions lib/tapioca.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@
module Tapioca
extend T::Sig

@traces = T.let([], T::Array[TracePoint])

sig { params(trace_name: Symbol, block: T.proc.params(arg0: TracePoint).void).void }
def self.register_trace(trace_name, &block)
@traces << TracePoint.trace(trace_name, &block)
end

sig { void }
def self.disable_traces
@traces.each(&:disable)
end

sig do
type_parameters(:Result)
.params(blk: T.proc.returns(T.type_parameter(:Result)))
Expand Down
2 changes: 2 additions & 0 deletions lib/tapioca/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ def gem(*gems)
option :payload, type: :boolean, desc: "Check shims against Sorbet's payload", default: true
option :workers, aliases: ["-w"], type: :numeric, desc: "Number of parallel workers (default: auto)"
def check_shims
Tapioca.disable_traces

command = Commands::CheckShims.new(
gem_rbi_dir: options[:gem_rbi_dir],
dsl_rbi_dir: options[:dsl_rbi_dir],
Expand Down
4 changes: 2 additions & 2 deletions lib/tapioca/runtime/trackers/constant_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ConstantLocation < T::Struct
@class_files = {}.compare_by_identity

# Immediately activated upon load. Observes class/module definition.
TracePoint.trace(:class) do |tp|
Tapioca.register_trace(:class) do |tp|
next if tp.self.singleton_class?

key = tp.self
Expand All @@ -40,7 +40,7 @@ class ConstantLocation < T::Struct
(@class_files[key] ||= Set.new) << loc
end

TracePoint.trace(:c_return) do |tp|
Tapioca.register_trace(:c_return) do |tp|
next unless tp.method_id == :new
next unless Module === tp.return_value

Expand Down