From 9733c3d8f2f8b808617737dc21c49a9040c36b13 Mon Sep 17 00:00:00 2001 From: Thomas Jiang Date: Thu, 10 Mar 2022 15:28:32 -0800 Subject: [PATCH] sealed_whitelist Summary: Migrate from: https://www.internalfb.com/code/fbsource/[1e23f98b01d1]/fbcode/hphp/hack/src/decl/decl_folded_class.ml?lines=305-308 Differential Revision: D34730147 fbshipit-source-id: 3600dfc76a17170063414ead93d2b2c823caf00b --- hphp/hack/src/rupro/lib/decl_defs/debug.rs | 4 ++++ hphp/hack/src/rupro/lib/decl_defs/folded.rs | 1 + .../rupro/lib/folded_decl_provider/fold.rs | 10 ++++++++++ .../rupro/folded_decls/sealed_whitelist.php | 4 ++++ .../sealed_whitelist.php.folded_decls.exp | 19 +++++++++++++++++++ 5 files changed, 38 insertions(+) create mode 100644 hphp/hack/test/rupro/folded_decls/sealed_whitelist.php create mode 100644 hphp/hack/test/rupro/folded_decls/sealed_whitelist.php.folded_decls.exp diff --git a/hphp/hack/src/rupro/lib/decl_defs/debug.rs b/hphp/hack/src/rupro/lib/decl_defs/debug.rs index 5aa1a7011c022d..322d20ffc0794b 100644 --- a/hphp/hack/src/rupro/lib/decl_defs/debug.rs +++ b/hphp/hack/src/rupro/lib/decl_defs/debug.rs @@ -161,6 +161,7 @@ impl fmt::Debug for FoldedClass { xhp_attr_deps, req_ancestors, req_ancestors_extends, + sealed_whitelist, decl_errors, } = self; @@ -244,6 +245,9 @@ impl fmt::Debug for FoldedClass { if !req_ancestors_extends.is_empty() { s.field("req_ancestors_extends", req_ancestors_extends); } + if let Some(sealed_whitelist) = sealed_whitelist { + s.field("sealed_whitelist", sealed_whitelist); + } if !decl_errors.is_empty() { s.field("decl_errors", decl_errors); } diff --git a/hphp/hack/src/rupro/lib/decl_defs/folded.rs b/hphp/hack/src/rupro/lib/decl_defs/folded.rs index b51f5c78987fc7..68a938f2acf8ae 100644 --- a/hphp/hack/src/rupro/lib/decl_defs/folded.rs +++ b/hphp/hack/src/rupro/lib/decl_defs/folded.rs @@ -150,6 +150,7 @@ pub struct FoldedClass { pub xhp_attr_deps: TypeNameIndexSet, pub req_ancestors: Box<[Requirement]>, pub req_ancestors_extends: TypeNameIndexSet, + pub sealed_whitelist: Option, pub decl_errors: Box<[TypingError]>, } diff --git a/hphp/hack/src/rupro/lib/folded_decl_provider/fold.rs b/hphp/hack/src/rupro/lib/folded_decl_provider/fold.rs index c031b5786f2690..8ae6d78a7cef33 100644 --- a/hphp/hack/src/rupro/lib/folded_decl_provider/fold.rs +++ b/hphp/hack/src/rupro/lib/folded_decl_provider/fold.rs @@ -755,6 +755,13 @@ impl DeclFolder { (req_ancestors, req_ancestors_extends) } + fn get_sealed_whitelist(&self, sc: &ShallowClass) -> Option { + sc.user_attributes + .iter() + .find(|ua| ua.name.id() == self.special_names.user_attributes.uaSealed) + .map(|ua| ua.classname_params.iter().copied().collect()) + } + pub fn decl_class( &self, sc: &ShallowClass, @@ -807,6 +814,8 @@ impl DeclFolder { let (req_ancestors, req_ancestors_extends) = self.get_class_requirements(sc, parents); + let sealed_whitelist = self.get_sealed_whitelist(sc); + Arc::new(FoldedClass { name: sc.name.id(), pos: sc.name.pos().clone(), @@ -840,6 +849,7 @@ impl DeclFolder { xhp_attr_deps, req_ancestors: req_ancestors.into_boxed_slice(), req_ancestors_extends, + sealed_whitelist, decl_errors: errors.into_boxed_slice(), }) } diff --git a/hphp/hack/test/rupro/folded_decls/sealed_whitelist.php b/hphp/hack/test/rupro/folded_decls/sealed_whitelist.php new file mode 100644 index 00000000000000..5aec941db0218e --- /dev/null +++ b/hphp/hack/test/rupro/folded_decls/sealed_whitelist.php @@ -0,0 +1,4 @@ +> +class A {} diff --git a/hphp/hack/test/rupro/folded_decls/sealed_whitelist.php.folded_decls.exp b/hphp/hack/test/rupro/folded_decls/sealed_whitelist.php.folded_decls.exp new file mode 100644 index 00000000000000..0371d458a64364 --- /dev/null +++ b/hphp/hack/test/rupro/folded_decls/sealed_whitelist.php.folded_decls.exp @@ -0,0 +1,19 @@ +FoldedClass { + name: "\\A", + kind: Cclass( + Concrete, + ), + consts: { + "class": ClassConst { + is_synthesized: true, + kind: CCConcrete, + pos: NPos, + ty: HH\classname, + origin: "\\A", + refs: [], + }, + }, + sealed_whitelist: { + "\\A", + }, +}