Skip to content

Commit 085c13a

Browse files
ricklavoiefacebook-github-bot
authored andcommitted
Revert D76614862 D75026944 D75498477 D75470326
Differential Revision: D76664263 fbshipit-source-id: 64ffb830f49c5acce2c0c9f00fe0068fa366bec0
1 parent 159314f commit 085c13a

Some content is hidden

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

58 files changed

+223
-621
lines changed

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

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use hhbc::ModuleName;
2626
use hhbc::ParamEntry;
2727
use hhbc::StringId;
2828
use hhbc::StringIdMap;
29-
use hhbc::TParamInfo;
3029
use hhbc::TypedValue;
3130
use hhvm_types_ffi::Attr;
3231
use log::trace;
@@ -322,7 +321,6 @@ fn assemble_typedef(token_iter: &mut Lexer<'_>, case_type: bool) -> Result<hhbc:
322321

323322
fn assemble_class(token_iter: &mut Lexer<'_>, adata: &AdataMap) -> Result<hhbc::Class> {
324323
parse!(token_iter, ".class"
325-
<tparams:assemble_tparams()>
326324
<upper_bounds:assemble_upper_bounds()>
327325
<attr:assemble_special_and_user_attrs()>
328326
<name:assemble_class_name()>
@@ -374,7 +372,6 @@ fn assemble_class(token_iter: &mut Lexer<'_>, adata: &AdataMap) -> Result<hhbc::
374372
ctx_constants: ctx_constants.into(),
375373
requirements: requirements.into(),
376374
upper_bounds: upper_bounds.into(),
377-
tparams: tparams.into(),
378375
doc_comment,
379376
flags,
380377
};
@@ -480,7 +477,7 @@ fn assemble_const_or_type_const(
480477
fn assemble_method(token_iter: &mut Lexer<'_>, adata: &AdataMap) -> Result<hhbc::Method> {
481478
let method_tok = token_iter.peek().copied();
482479
token_iter.expect_str(Token::is_decl, ".method")?;
483-
let tparam_info = assemble_tparam_info(token_iter)?;
480+
let shadowed_tparams = assemble_shadowed_tparams(token_iter)?;
484481
let upper_bounds = assemble_upper_bounds(token_iter)?;
485482
let (attrs, attributes) = assemble_special_and_user_attrs(token_iter)?;
486483
let span = assemble_span(token_iter)?;
@@ -497,7 +494,7 @@ fn assemble_method(token_iter: &mut Lexer<'_>, adata: &AdataMap) -> Result<hhbc:
497494
attrs,
498495
params,
499496
return_type,
500-
tparam_info,
497+
shadowed_tparams,
501498
upper_bounds,
502499
span,
503500
)?;
@@ -513,28 +510,19 @@ fn assemble_method(token_iter: &mut Lexer<'_>, adata: &AdataMap) -> Result<hhbc:
513510
})
514511
}
515512

516-
fn parse_bool(token_iter: &mut Lexer<'_>) -> Result<bool> {
517-
let tok = token_iter.expect(Token::is_identifier)?;
518-
let id = tok.as_str()?;
519-
let b = id.parse()?;
520-
Ok(b)
521-
}
522-
523-
fn assemble_single_tparam_info(token_iter: &mut Lexer<'_>) -> Result<TParamInfo> {
524-
parse!(token_iter, "[" <name:assemble_class_name()> <shadows_class_tparam:parse_bool> "]");
525-
Ok(TParamInfo {
526-
name,
527-
shadows_class_tparam,
528-
})
529-
}
530-
531-
fn assemble_tparam_info(token_iter: &mut Lexer<'_>) -> Result<Vec<TParamInfo>> {
532-
Ok(if token_iter.peek_is(Token::is_lt) {
533-
parse!(token_iter, "<" <tparams:assemble_single_tparam_info(),*> ">");
534-
tparams
535-
} else {
536-
Vec::new()
537-
})
513+
fn assemble_shadowed_tparams(token_iter: &mut Lexer<'_>) -> Result<Vec<ClassName>> {
514+
token_iter.expect(Token::is_open_curly)?;
515+
let mut stp = Vec::new();
516+
while token_iter.peek_is(Token::is_identifier) {
517+
stp.push(ClassName::intern(
518+
token_iter.expect(Token::is_identifier)?.as_str()?,
519+
));
520+
if !token_iter.peek_is(Token::is_close_curly) {
521+
token_iter.expect(Token::is_comma)?;
522+
}
523+
}
524+
token_iter.expect(Token::is_close_curly)?;
525+
Ok(stp)
538526
}
539527

540528
fn assemble_method_flags(token_iter: &mut Lexer<'_>) -> Result<hhbc::MethodFlags> {
@@ -1035,7 +1023,6 @@ where
10351023
/// .function {upper bounds} [special_and_user_attrs] (span) <type_info> name (params) flags? {body}
10361024
fn assemble_function(token_iter: &mut Lexer<'_>, adata: &AdataMap) -> Result<hhbc::Function> {
10371025
token_iter.expect_str(Token::is_decl, ".function")?;
1038-
let tparam_info = assemble_tparam_info(token_iter)?;
10391026
let upper_bounds = assemble_upper_bounds(token_iter)?;
10401027
// Special and user attrs may or may not be specified. If not specified, no [] printed
10411028
let (attrs, attributes) = assemble_special_and_user_attrs(token_iter)?;
@@ -1051,6 +1038,7 @@ fn assemble_function(token_iter: &mut Lexer<'_>, adata: &AdataMap) -> Result<hhb
10511038
let mut decl_map = DeclMap::default();
10521039
let params = assemble_params(token_iter, &mut decl_map)?;
10531040
let flags = assemble_function_flags(name, token_iter)?;
1041+
let shadowed_tparams = Default::default();
10541042
let body = assemble_body(
10551043
token_iter,
10561044
&mut decl_map,
@@ -1059,7 +1047,7 @@ fn assemble_function(token_iter: &mut Lexer<'_>, adata: &AdataMap) -> Result<hhb
10591047
attrs,
10601048
params,
10611049
return_type,
1062-
tparam_info,
1050+
shadowed_tparams,
10631051
upper_bounds,
10641052
span,
10651053
)?;
@@ -1115,15 +1103,6 @@ fn assemble_upper_bounds(token_iter: &mut Lexer<'_>) -> Result<Vec<hhbc::UpperBo
11151103
Ok(ubs)
11161104
}
11171105

1118-
fn assemble_tparams(token_iter: &mut Lexer<'_>) -> Result<Vec<ClassName>> {
1119-
Ok(if token_iter.peek_is(Token::is_lt) {
1120-
parse!(token_iter, "<" <tparams:assemble_class_name(),*> ">");
1121-
tparams
1122-
} else {
1123-
Vec::new()
1124-
})
1125-
}
1126-
11271106
/// Ex: (T as <"HH\\int" "HH\\int" upper_bound>)
11281107
fn assemble_upper_bound(token_iter: &mut Lexer<'_>) -> Result<hhbc::UpperBound> {
11291108
parse!(token_iter, "(" <id:id> "as" <tis:assemble_type_info(TypeInfoKind::NotEnumOrTypeDef),*> ")");
@@ -1395,7 +1374,7 @@ fn assemble_body(
13951374
attrs: hhbc::Attr,
13961375
params: Vec<ParamEntry>,
13971376
return_type: Maybe<hhbc::TypeInfo>,
1398-
tparam_info: Vec<TParamInfo>,
1377+
shadowed_tparams: Vec<ClassName>,
13991378
upper_bounds: Vec<hhbc::UpperBound>,
14001379
span: hhbc::Span,
14011380
) -> Result<hhbc::Body> {
@@ -1457,7 +1436,7 @@ fn assemble_body(
14571436
is_memoize_wrapper_lsb,
14581437
doc_comment,
14591438
return_type,
1460-
tparam_info: tparam_info.into(),
1439+
shadowed_tparams: shadowed_tparams.into(),
14611440
upper_bounds: upper_bounds.into(),
14621441
span,
14631442
repr: hhbc::BcRepr {

hphp/hack/src/hackc/bytecode_printer/print.rs

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ use hhbc::Span;
4646
use hhbc::SrcLoc;
4747
use hhbc::StringId;
4848
use hhbc::SymbolRefs;
49-
use hhbc::TParamInfo;
5049
use hhbc::TraitReqKind;
5150
use hhbc::TypeConstant;
5251
use hhbc::TypeInfo;
@@ -330,7 +329,6 @@ fn print_fun_def(
330329
let body = &fun_def.body;
331330
newline(w)?;
332331
w.write_all(b".function ")?;
333-
print_tparam_info(w, &body.tparam_info)?;
334332
print_upper_bounds_(w, &body.upper_bounds)?;
335333
w.write_all(b" ")?;
336334
print_special_and_user_attrs(
@@ -526,19 +524,11 @@ fn print_enum_includes(w: &mut dyn Write, enum_includes: &[ClassName]) -> Result
526524
write_bytes!(w, " enum_includes ({})", fmt_separated(" ", enum_includes))
527525
}
528526

529-
fn print_tparam_info(w: &mut dyn Write, tparam_info: &[TParamInfo]) -> Result<()> {
530-
if tparam_info.is_empty() {
531-
return Ok(());
532-
}
527+
fn print_shadowed_tparams(w: &mut dyn Write, shadowed_tparams: &[ClassName]) -> Result<()> {
533528
write_bytes!(
534529
w,
535-
"<{}> ",
536-
fmt_separated(
537-
",",
538-
tparam_info
539-
.iter()
540-
.map(|t| { format!("[{} {}]", t.name.as_str(), t.shadows_class_tparam) })
541-
)
530+
"{{{}}}",
531+
fmt_separated(", ", shadowed_tparams.iter().map(|s| s.as_str()))
542532
)
543533
}
544534

@@ -551,7 +541,7 @@ fn print_method_def(
551541
let body = &method_def.body;
552542
newline(w)?;
553543
w.write_all(b" .method ")?;
554-
print_tparam_info(w, &body.tparam_info)?;
544+
print_shadowed_tparams(w, &body.shadowed_tparams)?;
555545
print_upper_bounds_(w, &body.upper_bounds)?;
556546
w.write_all(b" ")?;
557547
print_special_and_user_attrs(
@@ -592,17 +582,6 @@ fn print_method_def(
592582
})
593583
}
594584

595-
fn print_tparams(w: &mut dyn Write, tparams: &[ClassName]) -> Result<()> {
596-
if tparams.is_empty() {
597-
return Ok(());
598-
}
599-
write_bytes!(
600-
w,
601-
"<{}> ",
602-
fmt_separated(",", tparams.iter().map(|s| s.as_str()))
603-
)
604-
}
605-
606585
fn print_class_def(
607586
ctx: &Context<'_>,
608587
w: &mut dyn Write,
@@ -611,7 +590,6 @@ fn print_class_def(
611590
) -> Result<()> {
612591
newline(w)?;
613592
w.write_all(b".class ")?;
614-
print_tparams(w, class_def.tparams.as_ref())?;
615593
print_upper_bounds(w, class_def.upper_bounds.as_ref())?;
616594
w.write_all(b" ")?;
617595
print_special_and_user_attrs(

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

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use hhbc::Param;
2929
use hhbc::ParamEntry;
3030
use hhbc::Span;
3131
use hhbc::StringId;
32-
use hhbc::TParamInfo;
3332
use hhbc::TypeInfo;
3433
use hhbc::TypedValue;
3534
use hhbc::UpperBound;
@@ -116,7 +115,7 @@ pub fn emit_body<'b, 'd>(
116115
args.class_tparam_names,
117116
args.flags.contains(Flags::SKIP_AWAITABLE),
118117
);
119-
let tparam_info = emit_tparam_info(args.immediate_tparams, args.class_tparam_names);
118+
let shadowed_tparams = emit_shadowed_tparams(args.immediate_tparams, args.class_tparam_names);
120119
let decl_vars = make_decl_vars(
121120
emitter,
122121
&scope,
@@ -179,7 +178,7 @@ pub fn emit_body<'b, 'd>(
179178
false, // is_memoize_wrapper
180179
false, // is_memoize_wrapper_lsb
181180
upper_bounds,
182-
tparam_info,
181+
shadowed_tparams,
183182
attributes,
184183
attrs,
185184
coeffects,
@@ -389,7 +388,7 @@ pub fn make_body<'a, 'd>(
389388
is_memoize_wrapper: bool,
390389
is_memoize_wrapper_lsb: bool,
391390
upper_bounds: Vec<UpperBound>,
392-
tparam_info: Vec<TParamInfo>,
391+
shadowed_tparams: Vec<String>,
393392
attributes: Vec<Attribute>,
394393
attrs: Attr,
395394
coeffects: Coeffects,
@@ -454,7 +453,10 @@ pub fn make_body<'a, 'd>(
454453
is_memoize_wrapper,
455454
is_memoize_wrapper_lsb,
456455
upper_bounds: upper_bounds.into(),
457-
tparam_info: tparam_info.into(),
456+
shadowed_tparams: shadowed_tparams
457+
.into_iter()
458+
.map(|s| ClassName::intern(&s))
459+
.collect(),
458460
return_type: return_type.into(),
459461
doc_comment: doc_comment
460462
.map(|(_, comment)| comment.into_bytes().into())
@@ -757,22 +759,18 @@ pub fn emit_generics_upper_bounds(
757759
.collect::<Vec<_>>()
758760
}
759761

760-
fn emit_tparam_info(
762+
fn emit_shadowed_tparams(
761763
immediate_tparams: &[ast::Tparam],
762764
class_tparam_names: &[&str],
763-
) -> Vec<TParamInfo> {
764-
let s1 = get_tp_names(immediate_tparams);
765+
) -> Vec<String> {
766+
let s1 = get_tp_names_set(immediate_tparams);
765767
let s2: HashSet<&str> = class_tparam_names.iter().cloned().collect();
766-
let r: Vec<TParamInfo> = s1
767-
.iter()
768-
.map(|name| {
769-
let shadows_class_tparam = s2.contains(name);
770-
TParamInfo {
771-
name: ClassName::intern(name),
772-
shadows_class_tparam,
773-
}
774-
})
775-
.collect();
768+
// TODO(hrust): remove sort after Rust emitter released
769+
let mut r = s1
770+
.intersection(&s2)
771+
.map(|s| (*s).into())
772+
.collect::<Vec<_>>();
773+
r.sort();
776774
r
777775
}
778776

@@ -792,6 +790,10 @@ pub fn get_tp_names(tparams: &[ast::Tparam]) -> Vec<&str> {
792790
tparams.iter().map(get_tp_name).collect()
793791
}
794792

793+
pub fn get_tp_names_set(tparams: &[ast::Tparam]) -> HashSet<&str> {
794+
tparams.iter().map(get_tp_name).collect()
795+
}
796+
795797
fn modify_prog_for_debugger_eval(_: &mut InstrSeq) {
796798
unimplemented!() // SF(2021-03-17): I found it like this.
797799
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ fn make_86method<'d>(
116116
method_is_memoize_wrapper,
117117
method_is_memoize_wrapper_lsb,
118118
vec![], // upper_bounds
119-
vec![], // tparam_info
119+
vec![], // shadowed_tparams
120120
vec![], // attributes
121121
attrs,
122122
coeffects,
@@ -816,7 +816,6 @@ pub fn emit_class<'a, 'd>(emitter: &mut Emitter<'d>, ast_class: &'a ast::Class_)
816816
methods: methods.into(),
817817
enum_type: Maybe::from(enum_type),
818818
upper_bounds: upper_bounds.into(),
819-
tparams: tparams.into_iter().map(ClassName::intern).collect(),
820819
properties: Vec::from_iter(properties.into_iter().map(|p| p.prop)).into(),
821820
requirements: requirements.into(),
822821
type_constants: type_constants.into(),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ fn emit_constant_cinit<'a, 'd>(
6262
false, /* is_memoize_wrapper */
6363
false, /* is_memoize_wrapper_lsb */
6464
vec![], /* upper_bounds */
65-
vec![], /* tparam_info */
65+
vec![], /* shadowed_params */
6666
vec![], /* attributes */
6767
attrs,
6868
Coeffects::default(),

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use env::emitter::Emitter;
1212
use error::Result;
1313
use hhbc::Attribute;
1414
use hhbc::Body;
15-
use hhbc::ClassName;
1615
use hhbc::Coeffects;
1716
use hhbc::FCallArgs;
1817
use hhbc::FCallArgsFlags;
@@ -24,7 +23,6 @@ use hhbc::LocalRange;
2423
use hhbc::Param;
2524
use hhbc::Span;
2625
use hhbc::StringId;
27-
use hhbc::TParamInfo;
2826
use hhbc::TypeInfo;
2927
use hhbc::TypedValue;
3028
use hhbc_string_utils::reified;
@@ -83,14 +81,6 @@ pub(crate) fn emit_wrapper_function<'a, 'd>(
8381
.iter()
8482
.map(|tp| tp.name.1.as_str())
8583
.collect::<Vec<_>>();
86-
let tparam_info = fd
87-
.tparams
88-
.iter()
89-
.map(|s| TParamInfo {
90-
name: ClassName::intern(s.name.1.as_str()),
91-
shadows_class_tparam: false,
92-
})
93-
.collect::<Vec<_>>();
9484
let params = emit_param::from_asts(emitter, &mut tparams, true, &scope, &f.params)?;
9585
let mut attributes = emit_attribute::from_asts(emitter, &f.user_attributes)?;
9686
attributes.extend(emit_attribute::add_reified_attribute(&fd.tparams));
@@ -138,7 +128,6 @@ pub(crate) fn emit_wrapper_function<'a, 'd>(
138128
decl_vars,
139129
instrs,
140130
Span::from_pos(&f.span),
141-
tparam_info,
142131
)?;
143132

144133
let mut flags = FunctionFlags::empty();
@@ -399,7 +388,6 @@ fn make_wrapper_body<'a, 'd>(
399388
decl_vars: Vec<StringId>,
400389
instrs: InstrSeq,
401390
span: Span,
402-
tparam_info: Vec<TParamInfo>,
403391
) -> Result<Body> {
404392
emit_body::make_body(
405393
emitter,
@@ -408,7 +396,7 @@ fn make_wrapper_body<'a, 'd>(
408396
true, /* is_memoize_wrapper */
409397
false, /* is_memoize_wrapper_lsb */
410398
vec![], /* upper_bounds */
411-
tparam_info,
399+
vec![], /* shadowed_tparams */
412400
attributes,
413401
Attr::AttrNone,
414402
coeffects,

0 commit comments

Comments
 (0)