Skip to content

Commit ef6a563

Browse files
Paul Vickfacebook-github-bot
authored andcommitted
Plumb module doc comments through to reflection
Summary: Adds a field to ReflectionModule to get the doc comment for the module, and plumbs that back through to HackC. Reviewed By: oulgen Differential Revision: D40104245 fbshipit-source-id: 3d3230544a6815cfc4431a5460a7e8ad750b9908
1 parent b3690a0 commit ef6a563

File tree

23 files changed

+120
-3
lines changed

23 files changed

+120
-3
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,7 @@ fn print_module_def<'arena>(
616616
print_span(w, &module_def.span)?;
617617
w.write_all(b" {")?;
618618
newline(w)?;
619+
print_doc_comment(ctx, w, module_def.doc_comment.as_ref())?;
619620
w.write_all(b"}")?;
620621
newline(w)
621622
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ pub fn emit_module<'a, 'arena, 'decl>(
2222
let attributes = emit_attribute::from_asts(emitter, &ast_module.user_attributes)?;
2323
let name = ClassName::from_ast_name_and_mangle(alloc, &ast_module.name.1);
2424
let span = Span::from_pos(&ast_module.span);
25+
let doc_comment = ast_module.doc_comment.clone();
2526
Ok(Module {
2627
attributes: Slice::fill_iter(alloc, attributes.into_iter()),
2728
name,
2829
span,
30+
doc_comment: Maybe::from(doc_comment.map(|c| Str::new_str(alloc, &(c.0).1))),
2931
})
3032
}
3133

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,13 @@ fn assemble_module<'arena>(
266266
let name = assemble_class_name(alloc, token_iter)?;
267267
let span = assemble_span(token_iter)?;
268268
token_iter.expect(Token::into_open_curly)?;
269+
let doc_comment = assemble_doc_comment(alloc, token_iter)?;
269270
token_iter.expect(Token::into_close_curly)?;
270271
Ok(hhbc::Module {
271272
attributes,
272273
name,
273274
span,
275+
doc_comment,
274276
})
275277
}
276278

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,16 +792,19 @@ fn cmp_module(a: &Module<'_>, b: &Module<'_>) -> Result<()> {
792792
attributes: a_attributes,
793793
name: a_name,
794794
span: a_span,
795+
doc_comment: a_doc_comment,
795796
} = a;
796797
let Module {
797798
attributes: b_attributes,
798799
name: b_name,
799800
span: b_span,
801+
doc_comment: b_doc_comment,
800802
} = b;
801803

802804
cmp_eq(a_name, b_name).qualified("name")?;
803805
cmp_attributes(a_attributes, b_attributes).qualified("attributes")?;
804806
cmp_eq(a_span, b_span).qualified("span")?;
807+
cmp_eq(a_doc_comment, b_doc_comment).qualified("doc_comment")?;
805808
Ok(())
806809
}
807810

hphp/hack/src/hackc/hhbc/module.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
// This source code is licensed under the MIT license found in the
44
// LICENSE file in the "hack" directory of this source tree.
55

6+
use ffi::Maybe;
67
use ffi::Slice;
8+
use ffi::Str;
79
use serde::Serialize;
810

911
use crate::Attribute;
@@ -16,4 +18,5 @@ pub struct Module<'arena> {
1618
pub attributes: Slice<'arena, Attribute<'arena>>,
1719
pub name: ClassName<'arena>,
1820
pub span: Span,
21+
pub doc_comment: Maybe<Str<'arena>>,
1922
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ pub fn bc_to_ir<'a>(unit: &'_ Unit<'a>, filename: &Path) -> ir::Unit<'a> {
4343
attributes: module.attributes.iter().map(convert_attribute).collect(),
4444
name: ir::ClassId::from_hhbc(module.name, &mut strings),
4545
src_loc: ir::SrcLoc::from_span(filename, &module.span),
46+
doc_comment: module.doc_comment.into(),
4647
})
4748
.collect();
4849

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ pub fn ir_to_bc<'a>(alloc: &'a bumpalo::Bump, ir_unit: ir::Unit<'a>) -> hhbc::Un
5454
attributes: convert_attributes(alloc, module.attributes),
5555
name: strings.lookup_class_name(module.name),
5656
span: module.src_loc.to_span(),
57+
doc_comment: module.doc_comment.into(),
5758
}),
5859
);
5960
unit.module_use = ir_unit.module_use.into();

hphp/hack/src/hackc/ir/ir_core/module.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// This source code is licensed under the MIT license found in the
44
// LICENSE file in the "hack" directory of this source tree.
55

6+
use ffi::Str;
7+
68
use crate::Attribute;
79
use crate::ClassId;
810
use crate::SrcLoc;
@@ -11,4 +13,5 @@ pub struct Module<'a> {
1113
pub attributes: Vec<Attribute<'a>>,
1214
pub name: ClassId,
1315
pub src_loc: SrcLoc,
16+
pub doc_comment: Option<Str<'a>>,
1417
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,16 +491,19 @@ fn sem_diff_module<'arena>(
491491
attributes: a_attributes,
492492
name: a_name,
493493
span: a_span,
494+
doc_comment: a_doc_comment,
494495
} = a;
495496
let Module {
496497
attributes: b_attributes,
497498
name: b_name,
498499
span: b_span,
500+
doc_comment: b_doc_comment,
499501
} = b;
500502

501503
sem_diff_eq(&path.qualified("name"), a_name, b_name)?;
502504
sem_diff_attributes(&path.qualified("attributes"), a_attributes, b_attributes)?;
503505
sem_diff_eq(&path.qualified("span"), a_span, b_span)?;
506+
sem_diff_eq(&path.qualified("doc_comment"), a_doc_comment, b_doc_comment)?;
504507
Ok(())
505508
}
506509

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?hh
2+
3+
<<file:__EnableUnstableFeatures('modules')>>
4+
5+
/** this is a doc comment */
6+
new module a.b {
7+
}

0 commit comments

Comments
 (0)