From 768df6af73a9f4307c06ee58e2c760270dac5139 Mon Sep 17 00:00:00 2001 From: Katy Voor Date: Fri, 25 Oct 2024 16:05:11 -0700 Subject: [PATCH] Rip out old way to replace trivial builtin wrappers in sandbox mode (revert D61638064) Summary: Mostly a revert of a prior diff. We can actually just grab the builtin off the attribute to avoid reading the .hhvmconfig in HHVM but still tie the map to www rev. Reviewed By: mdko Differential Revision: D63444793 fbshipit-source-id: 8fdfd4186e1a4216050f4aa5f54fdcf55b477abd --- hphp/doc/configs.specification | 1 - hphp/hack/src/hackc/cli/compile.rs | 1 - hphp/hack/src/hackc/cli/hackc.rs | 1 - hphp/hack/src/hackc/compile/options.rs | 1 - hphp/hack/src/hackc/emitter/emit_expression.rs | 14 +++++++------- hphp/hack/src/hackc/emitter/emit_statement.rs | 2 +- hphp/hack/src/hackc/emitter/emitter.rs | 9 --------- hphp/hack/src/hackc/ffi_bridge/compiler_ffi.rs | 4 ---- hphp/runtime/base/runtime-option.cpp | 7 ------- hphp/runtime/base/runtime-option.h | 1 - hphp/runtime/vm/unit-parser.cpp | 1 - 11 files changed, 8 insertions(+), 34 deletions(-) diff --git a/hphp/doc/configs.specification b/hphp/doc/configs.specification index 5ee6f5e6aabb9..4f9b86d19c1c3 100644 --- a/hphp/doc/configs.specification +++ b/hphp/doc/configs.specification @@ -293,7 +293,6 @@ The format can be found in hphp/tools/configs/generate-configs.rs reified generic bytecode, powered by decl directed bytecode - std::map Hack.Lang.AliasedNamespaces = {}, UNKNOWN, repooptionsflag(Parser)|lookuppath(AliasedNamespaces) -- std::map Hack.Lang.TrivialBuiltins = {}, UNKNOWN, repooptionsflag(Parser)|lookuppath(TrivialBuiltins) - bool Hack.Lang.OptimizeParamLifetimes = false, paulbiss, repooptionsflag(Parser)|hackc(hhbc) - bool Hack.Lang.OptimizeLocalLifetimes = false, paulbiss, repooptionsflag(Parser)|hackc(hhbc) diff --git a/hphp/hack/src/hackc/cli/compile.rs b/hphp/hack/src/hackc/cli/compile.rs index b0ed7cfd3dd69..2af6e8228a9dd 100644 --- a/hphp/hack/src/hackc/cli/compile.rs +++ b/hphp/hack/src/hackc/cli/compile.rs @@ -160,7 +160,6 @@ pub(crate) fn native_env(filepath: RelativePath, opts: &SingleFileOpts) -> Resul hhbc_flags, hhvm: Hhvm { include_roots: Default::default(), - trivial_builtins: Default::default(), parser_options, }, flags: opts.env_flags.clone(), diff --git a/hphp/hack/src/hackc/cli/hackc.rs b/hphp/hack/src/hackc/cli/hackc.rs index c13df485c60f6..1f3218dcc3b58 100644 --- a/hphp/hack/src/hackc/cli/hackc.rs +++ b/hphp/hack/src/hackc/cli/hackc.rs @@ -225,7 +225,6 @@ impl Opts { filepath: relative_path::RelativePath::make(relative_path::Prefix::Dummy, path), hhvm: Hhvm { include_roots: Default::default(), - trivial_builtins: Default::default(), parser_options, }, flags: self.env_flags.clone(), diff --git a/hphp/hack/src/hackc/compile/options.rs b/hphp/hack/src/hackc/compile/options.rs index 7bf74e8cb405c..0f62c469498d4 100644 --- a/hphp/hack/src/hackc/compile/options.rs +++ b/hphp/hack/src/hackc/compile/options.rs @@ -40,7 +40,6 @@ impl Default for CompilerFlags { pub struct Hhvm { pub include_roots: BTreeMap, pub parser_options: ParserOptions, - pub trivial_builtins: BTreeMap, } impl Hhvm { diff --git a/hphp/hack/src/hackc/emitter/emit_expression.rs b/hphp/hack/src/hackc/emitter/emit_expression.rs index b49402a8eeba3..b3208668dd818 100644 --- a/hphp/hack/src/hackc/emitter/emit_expression.rs +++ b/hphp/hack/src/hackc/emitter/emit_expression.rs @@ -1818,7 +1818,7 @@ fn emit_call<'a, 'd>( readonly_return: bool, ) -> Result { if let Some(ast_defs::Id(_, s)) = expr.as_id() { - let fid = e.emit_function_name(s); + let fid = hhbc::FunctionName::from_ast_name(s); e.add_function_ref(fid); } let readonly_this = match &expr.2 { @@ -1837,7 +1837,7 @@ fn emit_call<'a, 'd>( match expr.2.as_id() { None => emit_call_default(e, env, pos, expr, targs, args, uarg, fcall_args), Some(ast_defs::Id(_, id)) => { - let fq = e.emit_function_name(id); + let fq = hhbc::FunctionName::from_ast_name(id); let lower_fq_name = fq.as_str(); emit_special_function(e, env, pos, targs, args, uarg, lower_fq_name) .transpose() @@ -2112,7 +2112,7 @@ fn emit_call_lhs_and_fcall<'a, 'd>( ]), InstrSeq::gather(vec![instr::f_call_func_d( fcall_args, - e.emit_function_name(fid), + hhbc::FunctionName::from_ast_name(fid), )]), )) } @@ -2309,12 +2309,12 @@ fn emit_call_lhs_and_fcall<'a, 'd>( } = fcall_args; let fq_id = match string_utils::strip_global_ns(&id.1) { "min" if num_args == 2 && !flags.contains(FCallArgsFlags::HasUnpack) => { - e.emit_function_name("__SystemLib\\min2") + hhbc::FunctionName::from_ast_name("__SystemLib\\min2") } "max" if num_args == 2 && !flags.contains(FCallArgsFlags::HasUnpack) => { - e.emit_function_name("__SystemLib\\max2") + hhbc::FunctionName::from_ast_name("__SystemLib\\max2") } - _ => e.emit_function_name(&id.1), + _ => hhbc::FunctionName::from_ast_name(&id.1), }; let generics = emit_generics(e, env, &mut fcall_args)?; Ok(( @@ -2325,7 +2325,7 @@ fn emit_call_lhs_and_fcall<'a, 'd>( Expr_::String(s) => { match std::str::from_utf8(s) { Ok(s) => { - let fq_id = e.emit_function_name(s); + let fq_id = hhbc::FunctionName::intern(s); let generics = emit_generics(e, env, &mut fcall_args)?; Ok(( InstrSeq::gather(vec![instr::null_uninit(), instr::null_uninit()]), diff --git a/hphp/hack/src/hackc/emitter/emit_statement.rs b/hphp/hack/src/hackc/emitter/emit_statement.rs index d0edf454c6d23..32e00a12465df 100644 --- a/hphp/hack/src/hackc/emitter/emit_statement.rs +++ b/hphp/hack/src/hackc/emitter/emit_statement.rs @@ -283,7 +283,7 @@ fn emit_call<'a, 'd>( .. } = c { - let ft = e.emit_function_name(&sid.1); + let ft = hhbc::FunctionName::from_ast_name(&sid.1); let fname = ft.as_str(); if fname == "unset" { Ok(InstrSeq::gather( diff --git a/hphp/hack/src/hackc/emitter/emitter.rs b/hphp/hack/src/hackc/emitter/emitter.rs index bd85c3588eba5..30383c79bf93f 100644 --- a/hphp/hack/src/hackc/emitter/emitter.rs +++ b/hphp/hack/src/hackc/emitter/emitter.rs @@ -244,15 +244,6 @@ impl<'d> Emitter<'d> { let state = std::mem::take(&mut self.symbol_refs_state); state.to_hhas() } - - pub fn emit_function_name(&self, s: &str) -> hhbc::FunctionName { - let stripped = hhbc_string_utils::strip_global_ns(s); - let ret = match self.options().hhvm.trivial_builtins.get(stripped) { - Some(v) => v, - None => s, - }; - hhbc::FunctionName::from_ast_name(ret) - } } impl<'d> print_expr::SpecialClassResolver for Emitter<'d> { diff --git a/hphp/hack/src/hackc/ffi_bridge/compiler_ffi.rs b/hphp/hack/src/hackc/ffi_bridge/compiler_ffi.rs index 50487e4c04440..ec6437c0a0c87 100644 --- a/hphp/hack/src/hackc/ffi_bridge/compiler_ffi.rs +++ b/hphp/hack/src/hackc/ffi_bridge/compiler_ffi.rs @@ -41,7 +41,6 @@ mod ffi { filepath: String, aliased_namespaces: Vec, - trivial_builtins: Vec, include_roots: Vec, hhbc_flags: HhbcFlags, @@ -542,9 +541,6 @@ impl ffi::NativeEnv { include_roots: (self.include_roots.iter()) .map(|e| (e.key.clone().into(), e.value.clone().into())) .collect(), - trivial_builtins: (self.trivial_builtins.iter()) - .map(|e| (e.key.clone(), e.value.clone())) - .collect(), parser_options: ParserOptions { auto_namespace_map: (self.aliased_namespaces.iter()) .map(|e| (e.key.clone(), e.value.clone())) diff --git a/hphp/runtime/base/runtime-option.cpp b/hphp/runtime/base/runtime-option.cpp index ef384d92672c3..3e68f2739da6c 100644 --- a/hphp/runtime/base/runtime-option.cpp +++ b/hphp/runtime/base/runtime-option.cpp @@ -295,13 +295,6 @@ void RepoOptionsFlags::initAliasedNamespaces(hackc::NativeEnv& env) const { } } -void RepoOptionsFlags::initTrivialBuiltins(hackc::NativeEnv& env) const { - if (!RO::EvalReplaceTrivialBuiltins) return; - for (auto& [k, v] : TrivialBuiltins) { - env.trivial_builtins.emplace_back(hackc::StringMapEntry{k, v}); - } -} - void RepoOptionsFlags::initDeclConfig(hackc::DeclParserConfig& config) const { for (auto& [k, v] : AliasedNamespaces) { config.aliased_namespaces.emplace_back(hackc::StringMapEntry{k, v}); diff --git a/hphp/runtime/base/runtime-option.h b/hphp/runtime/base/runtime-option.h index 55859b3edde11..388cc2122093d 100644 --- a/hphp/runtime/base/runtime-option.h +++ b/hphp/runtime/base/runtime-option.h @@ -116,7 +116,6 @@ SECTIONS_FOR_REPOOPTIONSFLAGS() void initHhbcFlags(hackc::HhbcFlags&) const; void initParserFlags(hackc::ParserFlags&) const; void initAliasedNamespaces(hackc::NativeEnv&) const; - void initTrivialBuiltins(hackc::NativeEnv&) const; std::string autoloadQuery() const { return Query; } folly::dynamic autoloadQueryObj() const { return m_cachedQuery; } diff --git a/hphp/runtime/vm/unit-parser.cpp b/hphp/runtime/vm/unit-parser.cpp index c362d7bca162d..de89060d1a228 100644 --- a/hphp/runtime/vm/unit-parser.cpp +++ b/hphp/runtime/vm/unit-parser.cpp @@ -134,7 +134,6 @@ CompilerResult hackc_compile( } }; options.initAliasedNamespaces(native_env); - options.initTrivialBuiltins(native_env); options.initHhbcFlags(native_env.hhbc_flags); options.initParserFlags(native_env.parser_flags); if (RO::EvalHackCompilerInheritConfig) {