<commit_before>Code.require_file "../helpers/introspection.exs", __DIR__

defmodule Alchemist.Code.Ast do

  @empty_env_info %{requires: [], imports: [], behaviours: []}

  @partials [:def, :defp, :defmodule, :@, :defmacro, :defmacrop, :defoverridable, :__ENV__, :__CALLER__, :raise, :if, :unless, :in]

  def extract_use_info(use_ast, module) do
    try do
      env = Map.put(__ENV__, :module, module)
      {expanded_ast, _requires} = Macro.prewalk(use_ast, env, &do_expand/2)
      {_ast, env_info} = Macro.prewalk(expanded_ast, @empty_env_info, &pre_walk_expanded/2)
      env_info
    rescue
      e ->
        IO.puts(:stderr, "Expanding #{Macro.to_string(use_ast)} failed.")
        IO.puts(:stderr, Exception.message(e) <> "\n" <> Exception.format_stacktrace(System.stacktrace))
        @empty_env_info
    end
  end

  def expand_partial(ast, env) do
    {expanded_ast, _} = Macro.prewalk(ast, env, &do_expand_partial/2)
    expanded_ast
  end

  def expand_all(ast, env) do
    {expanded_ast, _} = Macro.prewalk(ast, env, &do_expand_all/2)
    expanded_ast
  end

  def set_module_for_env(env, module) do
    Map.put(env, :module, module)
  end<commit_msg>Silencing when expansion is not possible<commit_after>Code.require_file "../helpers/introspection.exs", __DIR__

defmodule Alchemist.Code.Ast do

  @empty_env_info %{requires: [], imports: [], behaviours: []}

  @partials [:def, :defp, :defmodule, :@, :defmacro, :defmacrop, :defoverridable, :__ENV__, :__CALLER__, :raise, :if, :unless, :in]

  def extract_use_info(use_ast, module) do
    try do
      env = Map.put(__ENV__, :module, module)
      {expanded_ast, _requires} = Macro.prewalk(use_ast, env, &do_expand/2)
      {_ast, env_info} = Macro.prewalk(expanded_ast, @empty_env_info, &pre_walk_expanded/2)
      env_info
    rescue
      _e ->
        # IO.puts(:stderr, "Expanding #{Macro.to_string(use_ast)} failed.")
        # IO.puts(:stderr, Exception.message(e) <> "\n" <> Exception.format_stacktrace(System.stacktrace))
        @empty_env_info
    end
  end

  def expand_partial(ast, env) do
    {expanded_ast, _} = Macro.prewalk(ast, env, &do_expand_partial/2)
    expanded_ast
  end

  def expand_all(ast, env) do
    {expanded_ast, _} = Macro.prewalk(ast, env, &do_expand_all/2)
    expanded_ast
  end

  def set_module_for_env(env, module) do
    Map.put(env, :module, module)
  end
{'fraction_non_alphanumeric': 0.13947590870667795, 'fraction_numerical': 0.0033812341504649195, 'mean_word_length': 3.8904958677685952, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '7042746', 'n_tokens_mistral': 912, 'n_tokens_neox': 893, 'n_words': 174}