module T::Private::Methods::CallValidation
def self.create_validator_method_fast0(mod, original_method, method_sig, return_type)
def self.create_validator_method_fast0(mod, original_method, method_sig, return_type) mod.send(:define_method, method_sig.method_name) do |&blk| # This block is called for every `sig`. It's critical to keep it fast and # reduce number of allocations that happen here. # This method is a manually sped-up version of more general code in `validate_call` T::Profile.typecheck_sample_attempts -= 1 should_sample = T::Profile.typecheck_sample_attempts == 0 if should_sample T::Profile.typecheck_sample_attempts = T::Profile::SAMPLE_RATE T::Profile.typecheck_samples += 1 t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC) end if method_sig.bind message = method_sig.bind.error_message_for_obj(self) if message CallValidation.report_error( method_sig, message, 'Bind', nil, method_sig.bind, self ) end end if should_sample T::Profile.typecheck_duration += (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t1) end if method_sig.ever_failed && method_sig.generated return original_method.bind(self).call(&blk) end # The following line breaks are intentional to show nice pry message # PRY note: # this code is sig validation code. # Please issue `finish` to step out of it return_value = original_method.bind(self).call(&blk) if should_sample t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC) end unless return_value.is_a?(return_type) message = method_sig.return_type.error_message_for_obj(return_value) if message CallValidation.report_error( method_sig, message, 'Return value', nil, return_type, return_value, caller_offset: -1 ) end end if should_sample T::Profile.typecheck_duration += (Process.clock_gettime(Process::CLOCK_MONOTONIC) - t1) end return_value end end