<commit_before>module Dry
  module Types
    class Compiler
      attr_reader :registry

      def initialize(registry)
        @registry = registry
      end

      def call(ast)
        visit(ast)
      end

      def visit(node)
        type, body = node
        send(:"visit_#{ type }", body)
      end

      def visit_constructor(node)
        definition, fn_register_name, meta = node
        fn = Dry::Types::FnContainer[fn_register_name]
        primitive = visit(definition)
        Types::Constructor.new(primitive, &fn)
      end

      def visit_safe(node)
        ast, meta = node
        Types::Safe.new(call(ast), meta: meta)
      end

      def visit_definition(node)
        type, meta = node

        if registry.registered?(type)
          registry[type].meta(meta)
        else
          Definition.new(type, meta: meta)
        end
      end

      def visit_sum(node)
        *types, meta = node
        types.map { |type| visit(type) }.reduce(:|).meta(meta)
      end

      def visit_array(node)
        member, meta = node
        registry['array'].member(call(member)).meta(meta)
      end

      def visit_hash(node)
        constructor, schema, meta = node
        merge_with('hash', constructor, schema).meta(meta)
      end

      def visit_json_hash(node)
        schema, meta = node
        merge_with('json.hash', :symbolized, schema).meta(meta)
      end

      def visit_json_array(node)
        member, meta = node
        registry['json.array'].member(call(member)).meta(meta)
      end

      def visit_form_hash(node)
        schema, meta = node
        merge_with('form.hash', :symbolized, schema).meta(meta)
      end

      def visit_form_array(node)
        member, meta = node
        registry['form.array'].member(call(member)).meta(meta)
      end

      def visit_member(node)
        name, type = node
        { name => visit(type) }
      end

      def merge_with(hash_id, constructor, schema)
        registry[hash_id].__send__(
          constructor, schema.map { |key| visit(key) }.reduce({}, :update)
        )
      end<commit_msg>Use visit instead of call in visitors<commit_after>module Dry
  module Types
    class Compiler
      attr_reader :registry

      def initialize(registry)
        @registry = registry
      end

      def call(ast)
        visit(ast)
      end

      def visit(node)
        type, body = node
        send(:"visit_#{ type }", body)
      end

      def visit_constructor(node)
        definition, fn_register_name, meta = node
        fn = Dry::Types::FnContainer[fn_register_name]
        primitive = visit(definition)
        Types::Constructor.new(primitive, &fn)
      end

      def visit_safe(node)
        ast, meta = node
        Types::Safe.new(visit(ast), meta: meta)
      end

      def visit_definition(node)
        type, meta = node

        if registry.registered?(type)
          registry[type].meta(meta)
        else
          Definition.new(type, meta: meta)
        end
      end

      def visit_sum(node)
        *types, meta = node
        types.map { |type| visit(type) }.reduce(:|).meta(meta)
      end

      def visit_array(node)
        member, meta = node
        registry['array'].member(visit(member)).meta(meta)
      end

      def visit_hash(node)
        constructor, schema, meta = node
        merge_with('hash', constructor, schema).meta(meta)
      end

      def visit_json_hash(node)
        schema, meta = node
        merge_with('json.hash', :symbolized, schema).meta(meta)
      end

      def visit_json_array(node)
        member, meta = node
        registry['json.array'].member(visit(member)).meta(meta)
      end

      def visit_form_hash(node)
        schema, meta = node
        merge_with('form.hash', :symbolized, schema).meta(meta)
      end

      def visit_form_array(node)
        member, meta = node
        registry['form.array'].member(visit(member)).meta(meta)
      end

      def visit_member(node)
        name, type = node
        { name => visit(type) }
      end

      def merge_with(hash_id, constructor, schema)
        registry[hash_id].__send__(
          constructor, schema.map { |key| visit(key) }.reduce({}, :update)
        )
      end
{'fraction_non_alphanumeric': 0.10751665080875357, 'fraction_numerical': 0.0, 'mean_word_length': 2.076079005120702, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6057302', 'n_tokens_mistral': 1245, 'n_tokens_neox': 1216, 'n_words': 287}