<commit_before>(**
 * Copyright (c) 2015, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the "hack" directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 *
 *)

(*****************************************************************************)
(* Module used to type DynamicYield
 * Each class that uses the DynamicYield trait or which extends a class that
 * uses the DynamicYield trait implicitly defines a few methods. If it
 * explicitly defines a yieldFoo method, then it implicitly also defines genFoo
 * (unless this method is explicitly defined).
 * It does this with __call().
 *)
(*****************************************************************************)
open Utils
open Typing_defs

module Reason = Typing_reason
module Type   = Typing_ops
module Env    = Typing_env
module SN     = Naming_special_names

(* Classes that use the DynamicYield trait and implement {gen|get}Foo
 * also provide a deprecated {get|gen}Foo() via __call *)
let rec decl env methods =
  SMap.fold begin fun name ce (env, acc) ->
    (match (fst ce.ce_type) with
      | Reason.Rdynamic_yield _ -> env, acc
      | _ ->
        (match parse_gen_name name with
          | Some base ->
            let get_name = "get"^base in
            (* Define getFoo(), which is T if genFoo() is Awaitable<T> *)
            let ce_r, ft = extract_fun_t ce in
            let base_ty = (match (ft.ft_ret : decl ty) with
              | _, Tapply ((p_exp, cname), [(_, exp)])
                when cname = SN.Classes.cAwaitable ->
                Some (Reason.Rwitness p_exp, exp)
              | _, Tapply ((p_exp, cname), _) when cname = SN.Classes.cAwaitable ->
                (* arguably this should be an error *)
                Some (Reason.Rwitness p_exp, Tany)
              | _, Tany ->
                Some (Reason.Rwitness ft.ft_pos, Tany)
              | _ -> (* arguably this should be an error *)
                None
            ) in
            (match base_ty with
              | None -> env, acc
              | Some base_ty -> (
                let base_p = Reason.to_pos (fst base_ty) in
                let get_r = Reason.Rdynamic_yield (base_p, ft.ft_pos, get_name, name) in
                let deprec_msg = Printf.sprintf begin
                   "The pseudo-method %s is deprecated; instead of relying "^^
                   "on DynamicYield::__call, use await %s(...)"
                end get_name name name in
                let get_ty = ce_r, Tfun {ft with
                  ft_ret = get_r, (snd base_ty);
                  ft_deprecated = Some deprec_msg
                } in
                let ce' = {ce with ce_type = get_ty; ce_synthesized = true} in
                let acc = add get_name ce' acc in
                env, acc
              ))
          | None -> env, acc
        )
    )
  end methods (env, methods)

and contains_dynamic_yield = SSet.mem SN.FB.cDynamicYield
and contains_dynamic_yield_interface = SSet.mem SN.FB.cIUseDynamicYield
and implements_dynamic_yield_interface ancestors = SMap.mem SN.FB.cIUseDynamicYield ancestors
and is_dynamic_yield name = (name = SN.FB.cDynamicYield)

and remove_prefix prefix str =
  if str_starts_with str prefix<commit_msg>[hack] Fix OSS build after dynamic yield error message fix<commit_after>(**
 * Copyright (c) 2015, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the "hack" directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 *
 *)

(*****************************************************************************)
(* Module used to type DynamicYield
 * Each class that uses the DynamicYield trait or which extends a class that
 * uses the DynamicYield trait implicitly defines a few methods. If it
 * explicitly defines a yieldFoo method, then it implicitly also defines genFoo
 * (unless this method is explicitly defined).
 * It does this with __call().
 *)
(*****************************************************************************)
open Utils
open Typing_defs

module Reason = Typing_reason
module Type   = Typing_ops
module Env    = Typing_env
module SN     = Naming_special_names

(* Classes that use the DynamicYield trait and implement {gen|get}Foo
 * also provide a deprecated {get|gen}Foo() via __call *)
let rec decl env methods =
  SMap.fold begin fun name ce (env, acc) ->
    (match (fst ce.ce_type) with
      | Reason.Rdynamic_yield _ -> env, acc
      | _ ->
        (match parse_gen_name name with
          | Some base ->
            let get_name = "get"^base in
            (* Define getFoo(), which is T if genFoo() is Awaitable<T> *)
            let ce_r, ft = extract_fun_t ce in
            let base_ty = (match (ft.ft_ret : decl ty) with
              | _, Tapply ((p_exp, cname), [(_, exp)])
                when cname = SN.Classes.cAwaitable ->
                Some (Reason.Rwitness p_exp, exp)
              | _, Tapply ((p_exp, cname), _) when cname = SN.Classes.cAwaitable ->
                (* arguably this should be an error *)
                Some (Reason.Rwitness p_exp, Tany)
              | _, Tany ->
                Some (Reason.Rwitness ft.ft_pos, Tany)
              | _ -> (* arguably this should be an error *)
                None
            ) in
            (match base_ty with
              | None -> env, acc
              | Some base_ty -> (
                let base_p = Reason.to_pos (fst base_ty) in
                let get_r = Reason.Rdynamic_yield (base_p, ft.ft_pos, get_name, name) in
                let deprec_msg = Printf.sprintf begin
                   "The pseudo-method %s is deprecated; instead of relying "^^
                   "on DynamicYield::__call, use await %s(...)"
                end get_name name in
                let get_ty = ce_r, Tfun {ft with
                  ft_ret = get_r, (snd base_ty);
                  ft_deprecated = Some deprec_msg
                } in
                let ce' = {ce with ce_type = get_ty; ce_synthesized = true} in
                let acc = add get_name ce' acc in
                env, acc
              ))
          | None -> env, acc
        )
    )
  end methods (env, methods)

and contains_dynamic_yield = SSet.mem SN.FB.cDynamicYield
and contains_dynamic_yield_interface = SSet.mem SN.FB.cIUseDynamicYield
and implements_dynamic_yield_interface ancestors = SMap.mem SN.FB.cIUseDynamicYield ancestors
and is_dynamic_yield name = (name = SN.FB.cDynamicYield)

and remove_prefix prefix str =
  if str_starts_with str prefix
{'fraction_non_alphanumeric': 0.12373587150505651, 'fraction_numerical': 0.001189767995240928, 'mean_word_length': 2.203906622201048, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, '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': '5610712', 'n_tokens_mistral': 1975, 'n_tokens_neox': 1827, 'n_words': 671}