Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c8b8dac

Browse files
mdkofacebook-github-bot
authored andcommitted
Remove EmitClassPointers runtime option
Summary: It looks like we can remove the `EmitClassPointers` runtime option, since it is almost always set to 2 (i.e. "LazyClass"). Reviewed By: edwinsmith Differential Revision: D39150358 fbshipit-source-id: 0adc178f19cd6542102db4fb7651355d3c2770ed
1 parent 0b8e83d commit c8b8dac

File tree

82 files changed

+96
-171
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+96
-171
lines changed

hphp/compiler/compiler.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,6 @@ RepoGlobalData getGlobalData() {
455455
gd.HackArrCompatSerializeNotices =
456456
RuntimeOption::EvalHackArrCompatSerializeNotices;
457457
gd.AbortBuildOnVerifyError = RuntimeOption::EvalAbortBuildOnVerifyError;
458-
gd.EmitClassPointers = RuntimeOption::EvalEmitClassPointers;
459458
gd.EmitClsMethPointers = RuntimeOption::EvalEmitClsMethPointers;
460459
gd.IsVecNotices = RuntimeOption::EvalIsVecNotices;
461460
gd.RaiseClassConversionWarning =

hphp/hack/src/hackc/compile/options.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ impl Default for CompilerFlags {
3737
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
3838
pub struct Hhvm {
3939
pub include_roots: BTreeMap<BString, BString>,
40-
pub emit_class_pointers: i32,
4140
pub check_int_overflow: i32,
4241
pub parser_options: ParserOptions,
4342
}
@@ -146,10 +145,6 @@ impl Options {
146145
pub fn check_int_overflow(&self) -> bool {
147146
self.hhvm.check_int_overflow > 0
148147
}
149-
150-
pub fn emit_class_pointers(&self) -> i32 {
151-
self.hhvm.emit_class_pointers
152-
}
153148
}
154149

155150
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]

hphp/hack/src/hackc/emitter/constant_folder.rs

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,7 @@ fn class_const_to_typed_value<'arena, 'decl>(
109109
if let ClassExpr::Id(ast_defs::Id(_, cname)) = cexpr {
110110
let classid =
111111
hhbc::ClassName::from_ast_name_and_mangle(emitter.alloc, cname).as_ffi_str();
112-
if emitter.options().emit_class_pointers() == 2 {
113-
return Ok(TypedValue::LazyClass(classid));
114-
} else {
115-
return Ok(TypedValue::String(classid));
116-
}
112+
return Ok(TypedValue::LazyClass(classid));
117113
}
118114
}
119115
Err(Error::UserDefinedConstant)
@@ -303,17 +299,13 @@ pub fn expr_to_typed_value<'arena, 'decl>(
303299
e: &Emitter<'arena, 'decl>,
304300
expr: &ast::Expr,
305301
) -> Result<TypedValue<'arena>, Error> {
306-
expr_to_typed_value_(
307-
e, expr, false, /*allow_maps*/
308-
false, /*force_class_const*/
309-
)
302+
expr_to_typed_value_(e, expr, false /*allow_maps*/)
310303
}
311304

312305
pub fn expr_to_typed_value_<'arena, 'decl>(
313306
emitter: &Emitter<'arena, 'decl>,
314307
expr: &ast::Expr,
315308
allow_maps: bool,
316-
force_class_const: bool,
317309
) -> Result<TypedValue<'arena>, Error> {
318310
stack_limit::maybe_grow(|| {
319311
// TODO: ML equivalent has this as an implicit parameter that defaults to false.
@@ -364,30 +356,18 @@ pub fn expr_to_typed_value_<'arena, 'decl>(
364356
}
365357
Expr_::KeyValCollection(x) => keyvalcollection_expr_to_typed_value(emitter, x),
366358
Expr_::Shape(fields) => shape_to_typed_value(emitter, fields),
367-
Expr_::ClassConst(x) => class_const_expr_to_typed_value(emitter, x, force_class_const),
359+
Expr_::ClassConst(x) => class_const_to_typed_value(emitter, &x.0, &x.1),
368360

369361
Expr_::ClassGet(_) => Err(Error::UserDefinedConstant),
370362
ast::Expr_::As(x) if (x.1).1.is_hlike() => {
371-
expr_to_typed_value_(emitter, &x.0, allow_maps, false)
363+
expr_to_typed_value_(emitter, &x.0, allow_maps)
372364
}
373365
Expr_::Upcast(e) => expr_to_typed_value(emitter, &e.0),
374366
_ => Err(Error::NotLiteral),
375367
}
376368
})
377369
}
378370

379-
fn class_const_expr_to_typed_value<'arena, 'decl>(
380-
emitter: &Emitter<'arena, 'decl>,
381-
x: &(ast::ClassId, ast::Pstring),
382-
force_class_const: bool,
383-
) -> Result<TypedValue<'arena>, Error> {
384-
if emitter.options().emit_class_pointers() == 1 && !force_class_const {
385-
Err(Error::NotLiteral)
386-
} else {
387-
class_const_to_typed_value(emitter, &x.0, &x.1)
388-
}
389-
}
390-
391371
fn valcollection_keyset_expr_to_typed_value<'arena, 'decl>(
392372
emitter: &Emitter<'arena, 'decl>,
393373
x: &(ast::VcKind, Option<ast::Targ>, Vec<ast::Expr>),
@@ -720,7 +700,7 @@ pub fn literals_from_exprs<'arena, 'decl>(
720700
}
721701
let ret = exprs
722702
.iter()
723-
.map(|expr| expr_to_typed_value_(e, expr, false, true))
703+
.map(|expr| expr_to_typed_value_(e, expr, false))
724704
.collect();
725705
if let Err(Error::NotLiteral) = ret {
726706
Err(Error::unrecoverable("literals_from_exprs: not literal"))

hphp/hack/src/hackc/emitter/emit_expression.rs

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,10 +1120,7 @@ fn emit_collection<'a, 'arena, 'decl>(
11201120
transform_to_collection: Option<CollectionType>,
11211121
) -> Result<InstrSeq<'arena>> {
11221122
let pos = &expr.1;
1123-
match constant_folder::expr_to_typed_value_(
1124-
e, expr, true, /*allow_map*/
1125-
false, /*force_class_const*/
1126-
) {
1123+
match constant_folder::expr_to_typed_value_(e, expr, true /*allow_map*/) {
11271124
Ok(tv) => {
11281125
let instr = emit_adata::typed_value_into_instr(e, tv)?;
11291126
emit_static_collection(env, transform_to_collection, pos, instr)
@@ -4550,17 +4547,10 @@ fn get_elem_member_key<'a, 'arena, 'decl>(
45504547
};
45514548
let fq_id = hhbc::ClassName::<'arena>::from_ast_name_and_mangle(alloc, cname)
45524549
.unsafe_as_str();
4553-
if e.options().emit_class_pointers() > 0 {
4554-
Ok((
4555-
MemberKey::ET(Str::from(fq_id), ReadonlyOp::Any),
4556-
instr::raise_class_string_conversion_warning(),
4557-
))
4558-
} else {
4559-
Ok((
4560-
MemberKey::ET(Str::from(fq_id), ReadonlyOp::Any),
4561-
instr::empty(),
4562-
))
4563-
}
4550+
Ok((
4551+
MemberKey::ET(Str::from(fq_id), ReadonlyOp::Any),
4552+
instr::raise_class_string_conversion_warning(),
4553+
))
45644554
}
45654555
_ => {
45664556
// General case
@@ -4740,15 +4730,8 @@ fn emit_class_const<'a, 'arena, 'decl>(
47404730
match cexpr {
47414731
ClassExpr::Id(ast_defs::Id(pos, name)) => {
47424732
let cid = hhbc::ClassName::from_ast_name_and_mangle(alloc, &name);
4743-
let cname = cid.unsafe_as_str();
47444733
Ok(if string_utils::is_class(&id.1) {
4745-
if e.options().emit_class_pointers() == 1 {
4746-
emit_pos_then(&pos, instr::resolve_class(cid))
4747-
} else if e.options().emit_class_pointers() == 2 {
4748-
emit_pos_then(&pos, instr::lazy_class(cid))
4749-
} else {
4750-
emit_pos_then(&pos, instr::string(alloc, cname))
4751-
}
4734+
emit_pos_then(&pos, instr::lazy_class(cid))
47524735
} else {
47534736
e.add_class_ref(cid.clone());
47544737
// TODO(hrust) enabel `let const_id = hhbc::ConstName::from_ast_name(&id.1);`,
@@ -4760,26 +4743,18 @@ fn emit_class_const<'a, 'arena, 'decl>(
47604743
}
47614744
_ => {
47624745
let load_const = if string_utils::is_class(&id.1) {
4763-
if e.options().emit_class_pointers() == 2 {
4764-
instr::lazy_class_from_class()
4765-
} else {
4766-
instr::class_name()
4767-
}
4746+
instr::lazy_class_from_class()
47684747
} else {
47694748
// TODO(hrust) enable `let const_id = hhbc::ConstName::from_ast_name(&id.1);`,
47704749
// `from_ast_name` should be able to accpet Cow<str>
47714750
let const_id =
47724751
hhbc::ConstName::new(Str::new_str(alloc, string_utils::strip_global_ns(&id.1)));
47734752
instr::cls_cns(const_id)
47744753
};
4775-
if string_utils::is_class(&id.1) && e.options().emit_class_pointers() == 1 {
4776-
emit_load_class_ref(e, env, pos, cexpr)
4777-
} else {
4778-
Ok(InstrSeq::gather(vec![
4779-
emit_load_class_ref(e, env, pos, cexpr)?,
4780-
load_const,
4781-
]))
4782-
}
4754+
Ok(InstrSeq::gather(vec![
4755+
emit_load_class_ref(e, env, pos, cexpr)?,
4756+
load_const,
4757+
]))
47834758
}
47844759
}
47854760
}

hphp/hack/src/hackc/emitter/emit_property.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@ pub fn from_ast<'ast, 'arena, 'decl>(
129129
Some(c) if (c.0).1 == "Map" || (c.0).1 == "ImmMap" => true,
130130
_ => false,
131131
};
132-
let deep_init = !args.is_static
133-
&& expr_requires_deep_init(e, emitter.options().emit_class_pointers() > 0);
132+
let deep_init = !args.is_static && expr_requires_deep_init(e, true);
134133
match constant_folder::expr_to_typed_value(emitter, e) {
135134
Ok(tv) if !(deep_init || is_collection_map) => (Some(tv), None, Attr::AttrNone),
136135
_ => {

hphp/hack/src/hackc/ffi_bridge/compiler_ffi.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ pub mod compile_ffi {
4444
filepath: String,
4545
aliased_namespaces: Vec<StringMapEntry>,
4646
include_roots: Vec<StringMapEntry>,
47-
emit_class_pointers: i32,
4847
check_int_overflow: i32,
4948

5049
hhbc_flags: HhbcFlags,
@@ -239,7 +238,6 @@ impl compile_ffi::NativeEnv {
239238
include_roots: (self.include_roots.iter())
240239
.map(|e| (e.key.clone().into(), e.value.clone().into()))
241240
.collect(),
242-
emit_class_pointers: self.emit_class_pointers,
243241
check_int_overflow: self.check_int_overflow,
244242
parser_options: ParserOptions {
245243
po_auto_namespace_map: (self.aliased_namespaces.iter())

hphp/hack/src/hackc/hackc/assemble.rs

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,12 +1022,13 @@ fn assemble_typed_value<'arena>(
10221022
))
10231023
}
10241024

1025-
/// s:s.len():"(escaped s)";
1026-
fn deserialize_string<'arena, 'a>(
1025+
/// s:s.len():"(escaped s)"; or l:s.len():"(escaped s)";
1026+
fn deserialize_string_or_lazyclass<'arena, 'a>(
10271027
alloc: &'arena Bump,
10281028
src: &'a [u8],
1029+
s_or_l: StringOrLazyClass,
10291030
) -> Result<(&'a [u8], hhbc::TypedValue<'arena>)> {
1030-
let src = expect(src, b"s")?;
1031+
let src = expect(src, s_or_l.prefix())?;
10311032
let src = expect(src, b":")?;
10321033
let (len, src) = expect_usize(src)?;
10331034
let src = expect(src, b":")?;
@@ -1044,7 +1045,29 @@ fn assemble_typed_value<'arena>(
10441045
let src = &src[len..];
10451046
let src = expect(src, b"\"")?;
10461047
let src = expect(src, b";")?;
1047-
Ok((src, hhbc::TypedValue::String(Str::new_slice(alloc, s))))
1048+
Ok((src, s_or_l.build(Str::new_slice(alloc, s))))
1049+
}
1050+
1051+
#[derive(PartialEq)]
1052+
pub enum StringOrLazyClass {
1053+
String,
1054+
LazyClass,
1055+
}
1056+
1057+
impl StringOrLazyClass {
1058+
pub fn prefix(&self) -> &[u8] {
1059+
match self {
1060+
StringOrLazyClass::String => b"s",
1061+
StringOrLazyClass::LazyClass => b"l",
1062+
}
1063+
}
1064+
1065+
pub fn build<'arena>(&self, content: Str<'arena>) -> hhbc::TypedValue<'arena> {
1066+
match self {
1067+
StringOrLazyClass::String => hhbc::TypedValue::String(content),
1068+
StringOrLazyClass::LazyClass => hhbc::TypedValue::LazyClass(content),
1069+
}
1070+
}
10481071
}
10491072

10501073
#[derive(PartialEq)]
@@ -1125,13 +1148,15 @@ fn assemble_typed_value<'arena>(
11251148
b'd' => deserialize_float(src).context("Assembling a TV float")?,
11261149
b'N' => deserialize_null(src).context("Assembling a TV Null")?,
11271150
b'u' => deserialize_uninit(src).context("Assembling a uninit")?,
1128-
b's' => deserialize_string(alloc, src).context("Assembling a TV string")?,
1151+
b's' => deserialize_string_or_lazyclass(alloc, src, StringOrLazyClass::String)
1152+
.context("Assembling a TV string")?,
11291153
b'v' => deserialize_vec_or_keyset(alloc, src, VecOrKeyset::Vec)
11301154
.context("Assembling a TV vec")?,
11311155
b'k' => deserialize_vec_or_keyset(alloc, src, VecOrKeyset::Keyset)
11321156
.context("Assembling a TV keyset")?,
11331157
b'D' => deserialize_dict(alloc, src).context("Assembling a TV dict")?,
1134-
b'l' => todo!(), // Never encounter LazyClass in all WWW...
1158+
b'l' => deserialize_string_or_lazyclass(alloc, src, StringOrLazyClass::LazyClass)
1159+
.context("Assembling a LazyClass")?,
11351160
_ => bail!("Unknown tv: {}", src[0]),
11361161
};
11371162
Ok((src, tr))
@@ -2054,6 +2079,12 @@ fn assemble_instr<'arena>(
20542079
b"True" => {
20552080
assemble_single_opcode_instr(&mut sl_lexer, || hhbc::Opcode::True, "True")
20562081
}
2082+
b"LazyClass" => assemble_lazyclass_opcode(alloc, &mut sl_lexer),
2083+
b"LazyClassFromClass" => assemble_single_opcode_instr(
2084+
&mut sl_lexer,
2085+
|| hhbc::Opcode::LazyClassFromClass,
2086+
"LazyClassFromClass",
2087+
),
20572088
b"VerifyOutType" => assemble_local_carrying_opcode_instr(
20582089
&mut sl_lexer,
20592090
decl_map,
@@ -3717,6 +3748,20 @@ fn assemble_double_opcode<'arena>(token_iter: &mut Lexer<'_>) -> Result<hhbc::In
37173748
)))
37183749
}
37193750

3751+
fn assemble_lazyclass_opcode<'arena>(
3752+
alloc: &'arena Bump,
3753+
token_iter: &mut Lexer<'_>,
3754+
) -> Result<hhbc::Instruct<'arena>> {
3755+
token_iter.expect_is_str(Token::into_identifier, "LazyClass")?;
3756+
let st_data = token_iter.expect(Token::into_str_literal)?;
3757+
let st_data =
3758+
escaper::unescape_literal_bytes_into_vec_bytes(escaper::unquote_slice(st_data.as_bytes()))?;
3759+
token_iter.expect_end()?;
3760+
Ok(hhbc::Instruct::Opcode(hhbc::Opcode::LazyClass(
3761+
hhbc::ClassName::new(Str::new_slice(alloc, &st_data)),
3762+
)))
3763+
}
3764+
37203765
type Line = usize;
37213766

37223767
#[derive(Debug, PartialEq, Eq, Copy, Clone)]

hphp/hack/src/hackc/hackc/hackc.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ struct Opts {
5656
#[clap(flatten)]
5757
pub(crate) env_flags: EnvFlags,
5858

59-
#[clap(long, default_value("0"))]
60-
emit_class_pointers: i32,
61-
6259
#[clap(long, default_value("0"))]
6360
check_int_overflow: i32,
6461

@@ -227,7 +224,6 @@ impl Opts {
227224
hhvm: Hhvm {
228225
include_roots: Default::default(),
229226
parser_options,
230-
emit_class_pointers: self.emit_class_pointers,
231227
check_int_overflow: self.check_int_overflow,
232228
},
233229
flags: self.env_flags.clone(),

hphp/hack/src/hackc/ir/conversions/bc_to_ir/instrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,7 @@ fn convert_opcode<'a, 'b>(ctx: &mut Context<'a, 'b>, opcode: &Opcode<'a>) -> boo
10391039
Opcode::LIterInit => todo!(),
10401040
Opcode::LIterNext => todo!(),
10411041
Opcode::LateBoundCls => simple!(Hhbc::LateBoundCls),
1042-
Opcode::LazyClass => todo!(),
1042+
Opcode::LazyClass => simple!(Hhbc::LazyClass),
10431043
Opcode::LazyClassFromClass => todo!(),
10441044
Opcode::LockObj => simple!(Hhbc::LockObj),
10451045
Opcode::Lt => simple!(Hhbc::CmpOp, CmpOp::Lt),

hphp/hack/src/hackc/ir/conversions/ir_to_bc/emitter.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,10 @@ impl<'a, 'b> InstrEmitter<'a, 'b> {
518518
Hhbc::IssetS(_, _) => Opcode::IssetS,
519519
Hhbc::IterFree(iter_id, _) => Opcode::IterFree(iter_id),
520520
Hhbc::LateBoundCls(_) => Opcode::LateBoundCls,
521+
Hhbc::LazyClass(clsid, _) => {
522+
let clsid = self.strings.lookup_class_name(clsid);
523+
Opcode::LazyClass(clsid)
524+
}
521525
Hhbc::LockObj(..) => Opcode::LockObj,
522526
Hhbc::MemoSet(_, ref locals, _) => {
523527
let locals = self.convert_local_range(locals);

0 commit comments

Comments
 (0)