<commit_before>/*
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

#include "Deleter.h"
#include "DexClass.h"
#include "DexUtil.h"
#include "ReachableClasses.h"
#include "Walkers.h"

size_t delete_methods(
    std::vector<DexClass*>& scope,
    std::unordered_set<DexMethod*>& removable,
    ConcurrentSet<DexMethod*>& delayed_make_static,
    std::function<DexMethod*(DexMethodRef*, MethodSearch search)> resolver) {

  // if a removable candidate is invoked do not delete
  walk::opcodes(scope, [](DexMethod* meth) { return true; },
                [&](DexMethod* meth, IRInstruction* insn) {
                  if (is_invoke(insn->opcode())) {
                    auto callee =
                        resolver(insn->get_method(), opcode_to_search(insn));
                    if (callee != nullptr) {
                      removable.erase(callee);
                    }
                  }
                });

  size_t deleted = 0;
  for (auto callee : removable) {
    if (!callee->is_concrete()) continue;
    if (!can_delete(callee)) continue;<commit_msg>Fix Deleter service allowing deletion of referenced methods<commit_after>/*
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

#include "Deleter.h"
#include "DexClass.h"
#include "DexUtil.h"
#include "ReachableClasses.h"
#include "Walkers.h"

size_t delete_methods(
    std::vector<DexClass*>& scope,
    std::unordered_set<DexMethod*>& removable,
    ConcurrentSet<DexMethod*>& delayed_make_static,
    std::function<DexMethod*(DexMethodRef*, MethodSearch search)> resolver) {

  // if a removable candidate is invoked do not delete
  walk::opcodes(scope, [](DexMethod* meth) { return true; },
                [&](DexMethod* meth, IRInstruction* insn) {
                  if (is_invoke(insn->opcode())) {
                    auto callee =
                        resolver(insn->get_method(), opcode_to_search(insn));
                    if (callee != nullptr) {
                      removable.erase(callee);
                    }
                  }
                });

  // if a removable candidate is referenced by an annotation do not delete
  walk::annotations(scope, [&](DexAnnotation* anno) {
    for (auto anno_element : anno->anno_elems()) {
      auto ev = anno_element.encoded_value;
      if (ev->evtype() == DEVT_METHOD) {
        DexEncodedValueMethod* evm = static_cast<DexEncodedValueMethod*>(ev);
        if (evm->method()->is_def()) {
          removable.erase(evm->method()->as_def());
        }
      }
    }
  });

  size_t deleted = 0;
  for (auto callee : removable) {
    if (!callee->is_concrete()) continue;
    if (!can_delete(callee)) continue;
{'fraction_non_alphanumeric': 0.12452700378396973, 'fraction_numerical': 0.0006879944960440316, 'mean_word_length': 2.5680981595092023, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4421237', 'n_tokens_mistral': 904, 'n_tokens_neox': 874, 'n_words': 223}