Skip to content

Commit c959738

Browse files
Niharika Devanathanfacebook-github-bot
authored andcommitted
Reland merged out changes in D75026944
Summary: I accidentally overwrote my changes in v3 of the above mentioned diff with the v4 version which merged out some of my intended edits. Update the corresponding files with the right version of the code. Reviewed By: vassilmladenov Differential Revision: D76614862 fbshipit-source-id: 3cc038d44f1616bbce4bc32803428205c2469f83
1 parent b4e182d commit c959738

File tree

6 files changed

+29
-35
lines changed

6 files changed

+29
-35
lines changed

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -513,17 +513,15 @@ fn assemble_method(token_iter: &mut Lexer<'_>, adata: &AdataMap) -> Result<hhbc:
513513
})
514514
}
515515

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+
516523
fn assemble_single_tparam_info(token_iter: &mut Lexer<'_>) -> Result<TParamInfo> {
517-
parse!(token_iter, "[" <name:assemble_class_name()> "," <num:num> "]");
518-
let shadows_class_tparam = match num.into_number() {
519-
Ok(b"0") => false,
520-
Ok(b"1") => true,
521-
_ => {
522-
return Err(
523-
token_iter.error(r#"Non "0"/"1" string in tparam info shadows class tparam"#)
524-
);
525-
}
526-
};
524+
parse!(token_iter, "[" <name:assemble_class_name()> <shadows_class_tparam:parse_bool> "]");
527525
Ok(TParamInfo {
528526
name,
529527
shadows_class_tparam,

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -535,13 +535,9 @@ fn print_tparam_info(w: &mut dyn Write, tparam_info: &[TParamInfo]) -> Result<()
535535
"<{}> ",
536536
fmt_separated(
537537
",",
538-
tparam_info.iter().map(|t| {
539-
format!(
540-
"[{},{}]",
541-
t.name.as_str(),
542-
if t.shadows_class_tparam { 1 } else { 0 }
543-
)
544-
})
538+
tparam_info
539+
.iter()
540+
.map(|t| { format!("[{} {}]", t.name.as_str(), t.shadows_class_tparam) })
545541
)
546542
)
547543
}

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -571,12 +571,7 @@ pub(crate) fn parse_readonly(tokenizer: &mut Tokenizer<'_>) -> Result<ReadonlyOp
571571
}
572572

573573
pub(crate) fn parse_single_tparam_info(tokenizer: &mut Tokenizer<'_>) -> Result<TParamInfo> {
574-
parse!(tokenizer, "[" <name:parse_class_name> "," <shadows:id> "]");
575-
let shadows_class_tparam = match shadows.identifier() {
576-
"0" => false,
577-
"1" => true,
578-
_ => return Err(shadows.bail("Unexpected token when parsing TParamInfo")),
579-
};
574+
parse!(tokenizer, "[" <name:parse_class_name> <shadows_class_tparam:parse_bool> "]");
580575
Ok(TParamInfo {
581576
name,
582577
shadows_class_tparam,
@@ -824,6 +819,12 @@ pub(crate) fn parse_usize(tokenizer: &mut Tokenizer<'_>) -> Result<usize> {
824819
Ok(i)
825820
}
826821

822+
pub(crate) fn parse_bool(tokenizer: &mut Tokenizer<'_>) -> Result<bool> {
823+
let t = tokenizer.expect_any_identifier()?;
824+
let b = t.identifier().parse()?;
825+
Ok(b)
826+
}
827+
827828
pub(crate) fn parse_user_id(tokenizer: &mut Tokenizer<'_>) -> Result<(Vec<u8>, TokenLoc)> {
828829
let t = tokenizer.expect_any_token()?;
829830
let tloc = t.loc().clone();

hphp/hack/src/hackc/ir/print/formatters.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,9 @@ impl Display for FmtTParamInfo<'_> {
175175
let FmtTParamInfo(tpi) = *self;
176176
write!(
177177
f,
178-
"[{},{}]",
178+
"[{} {}]",
179179
FmtIdentifierId(tpi.name.as_bytes_id()),
180-
if tpi.shadows_class_tparam { "1" } else { "0" }
180+
tpi.shadows_class_tparam
181181
)
182182
}
183183
}

hphp/runtime/vm/as.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2359,9 +2359,9 @@ std::vector<LowStringPtr> parse_tparam_names(AsmState& as) {
23592359
}
23602360

23612361
/*
2362-
* directive-function : upper-bound-list attribute-list ?line-range type-info
2363-
* identifier
2364-
* parameter-list function-flags '{' function-body
2362+
* directive-function : attribute-list ?line-range tparam-names type-info
2363+
* identifier parameter-list function-flags '{'
2364+
* function-body
23652365
* ;
23662366
*/
23672367
void parse_function(AsmState& as) {
@@ -2410,9 +2410,9 @@ void parse_function(AsmState& as) {
24102410
}
24112411

24122412
/*
2413-
* directive-method : shadowed-tparam-list upper-bound-list attribute-list
2414-
* ?line-range tparam-names type-info identifier
2415-
* parameter-list function-flags '{' function-body
2413+
* directive-method : attribute-list ?line-range tparam-names type-info
2414+
* identifier parameter-list function-flags '{'
2415+
* function-body
24162416
* ;
24172417
*/
24182418
void parse_method(AsmState& as) {
@@ -2785,9 +2785,8 @@ void parse_class_body(AsmState& as) {
27852785
}
27862786

27872787
/*
2788-
* directive-class : upper-bound-list ?"top" attribute-list identifier
2789-
* ?line-range extension-clause implements-clause '{'
2790-
* class-body
2788+
* directive-class : attribute-list identifier ?line-range tparam-names
2789+
* extension-clause implements-clause '{' class-body
27912790
* ;
27922791
*
27932792
* extension-clause : empty

hphp/runtime/vm/reified-generics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ extractSizeAndPosFromReifiedAttribute(
8484
assertx(isIntType(v.m_type));
8585
if (k.m_data.num == 0) {
8686
len = (size_t) v.m_data.num;
87-
assertx(len == typeParamNames.size());
87+
always_assert(len == typeParamNames.size());
8888
} else {
8989
if (k.m_data.num % 3 == 1) {
9090
// This is the reified generic index

0 commit comments

Comments
 (0)