Skip to content

Commit

Permalink
Merge pull request #1082 from Shopify/rm-disable-tracepoint-on-check
Browse files Browse the repository at this point in the history
Disable TracePoints when running the check-shims command
  • Loading branch information
rafaelfranca authored Jul 28, 2022
2 parents 7d1b853 + 744c8c9 commit 1b9139d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
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

0 comments on commit 1b9139d

Please sign in to comment.