Skip to content

Commit d359db9

Browse files
SamChou19815meta-codesync[bot]
authored andcommitted
[flow] Remove key-set regexp and key-mirror reason descriptions
Summary: Delete `RKeySet`, `RRegExp`, and `RObjectKeyMirror`. Replace result descriptions with location-only reasons, preserving the original annotation and definition metadata behavior. Keep the genuine `$KeyMirror` symbol as `RType` on both type-application operations. The builtin `RegExp`, key extraction, and key-mirror type operations are unchanged. Changelog: [internal] Remove key-set regexp and key-mirror reason descriptions. Reviewed By: gkz Differential Revision: D127198876 fbshipit-source-id: 1b5371780d818a122ee8a2387137977a7e4abd64
1 parent 0a0e7bf commit d359db9

6 files changed

Lines changed: 20 additions & 40 deletions

File tree

‎rust_port/crates/flow_common/src/reason.rs‎

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -301,17 +301,14 @@ pub enum VirtualReasonDesc<L: Dupe> {
301301
RThis,
302302
RThisType,
303303
RImplicitInstantiation,
304-
RKeySet,
305304
RPrototype,
306305
RObjectPrototype,
307306
RFunctionPrototype,
308307
RDestructuring,
309308
RDefaultValue,
310309
RConstructor,
311-
RRegExp,
312310
RDummyPrototype,
313311
RDummyThis,
314-
RObjectKeyMirror,
315312
RSomeProperty,
316313
RGlobalObject,
317314
RObjectPatternRestProp,
@@ -434,15 +431,13 @@ impl<A: Dupe> VirtualReasonDesc<A> {
434431
RThis => RThis,
435432
RThisType => RThisType,
436433
RImplicitInstantiation => RImplicitInstantiation,
437-
RKeySet => RKeySet,
438434
RPrototype => RPrototype,
439435
RObjectPrototype => RObjectPrototype,
440436
RFunctionPrototype => RFunctionPrototype,
441437
RDestructuring => RDestructuring,
442438
RDefaultValue => RDefaultValue,
443439
RConstructor => RConstructor,
444440
RRecordType(s) => RRecordType(s.dupe()),
445-
RRegExp => RRegExp,
446441
RDummyPrototype => RDummyPrototype,
447442
RDummyThis => RDummyThis,
448443
RType(n) => RType(n.dupe()),
@@ -465,7 +460,6 @@ impl<A: Dupe> VirtualReasonDesc<A> {
465460
RCode(s) => RCode(s.dupe()),
466461
RGlobalObject => RGlobalObject,
467462
ROpaqueType(s) => ROpaqueType(s.dupe()),
468-
RObjectKeyMirror => RObjectKeyMirror,
469463
RRendersNothing => RRendersNothing,
470464
RObjectPatternRestProp => RObjectPatternRestProp,
471465
RArrayPatternRestProp => RArrayPatternRestProp,
@@ -523,8 +517,7 @@ impl<L: Dupe> VirtualReasonDesc<L> {
523517
match self.unwrap() {
524518
Some(
525519
RNumber | RBigInt | RString | RSymbol | RUniqueSymbol | RBoolean | RStringLit(_)
526-
| RNumberLit(_) | RBigIntLit(_) | RBooleanLit(_) | RFbt | RTemplateString | RKeySet
527-
| RRegExp,
520+
| RNumberLit(_) | RBigIntLit(_) | RBooleanLit(_) | RFbt | RTemplateString,
528521
) => Scalar,
529522

530523
Some(
@@ -1257,8 +1250,6 @@ pub fn string_of_desc<L: Dupe>(desc: &VirtualReasonDesc<L>) -> String {
12571250
RThisType => "`this` type".to_string(),
12581251
RImplicitInstantiation => "implicit instantiation".to_string(),
12591252

1260-
RKeySet => "key set".to_string(),
1261-
12621253
// Prototypes
12631254
RPrototype => "prototype".to_string(),
12641255
RObjectPrototype => "object prototype".to_string(),
@@ -1275,10 +1266,8 @@ pub fn string_of_desc<L: Dupe>(desc: &VirtualReasonDesc<L>) -> String {
12751266
RRecordType(name) => format!("record `{}`", name),
12761267

12771268
// Misc
1278-
RRegExp => "regexp".to_string(),
12791269
RDummyPrototype => "empty prototype object".to_string(),
12801270
RDummyThis => "bound `this` in method".to_string(),
1281-
RObjectKeyMirror => "`$KeyMirror`".to_string(),
12821271

12831272
// Type aliases and params
12841273
RType(x) => format!("`{}`", prettify_react_util(x.as_str())),

‎rust_port/crates/flow_typing/src/ty_normalizer_flow.rs‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use dupe::Dupe;
1313
use flow_aloc::ALoc;
1414
use flow_common::reason::Name;
1515
use flow_common::reason::Reason;
16-
use flow_common::reason::VirtualReasonDesc;
1716
use flow_common_ty::ty::ALocElt;
1817
use flow_common_ty::ty::ALocTy;
1918
use flow_common_ty::ty_printer;
@@ -108,10 +107,7 @@ impl NormalizerInput for FlowInput {
108107
flow_js::flow_non_speculating(env.cx, (&t, &use_t))?;
109108
match lookahead::peek_types(env.cx, &collector.collect_to_vec()) {
110109
lookahead::Lookahead::LowerBounds(ref bounds) if bounds.len() == 1 => {
111-
let t = type_util::mod_reason_of_t(
112-
&|r| r.replace_desc(VirtualReasonDesc::RKeySet),
113-
&bounds[0],
114-
);
110+
let t = type_util::mod_reason_of_t(&|r| r.replace_desc(None), &bounds[0]);
115111
cont(env, state, t)
116112
}
117113
_ => default(env, state),

‎rust_port/crates/flow_typing_flow_js/src/flow_js/dispatch.rs‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2740,10 +2740,8 @@ fn __flow_impl<'cx>(
27402740
suggestion,
27412741
}))
27422742
} else {
2743-
let keys = Type::new(KeysT(
2744-
reason_o.dupe().replace_desc_new(VirtualReasonDesc::RKeySet),
2745-
l.dupe(),
2746-
));
2743+
let keys =
2744+
Type::new(KeysT(reason_o.dupe().replace_desc_new(None), l.dupe()));
27472745
flow_js_utils::incompatible_types_error(key, &keys, use_op.dupe(), None)
27482746
};
27492747
flow_js_utils::add_output_with_env(cx, env, err)?;
@@ -2832,10 +2830,7 @@ fn __flow_impl<'cx>(
28322830
suggestion: None,
28332831
}))
28342832
} else {
2835-
let keys = Type::new(KeysT(
2836-
reason_o.dupe().replace_desc_new(VirtualReasonDesc::RKeySet),
2837-
l.dupe(),
2838-
));
2833+
let keys = Type::new(KeysT(reason_o.dupe().replace_desc_new(None), l.dupe()));
28392834
flow_js_utils::incompatible_types_error(key, &keys, use_op.dupe(), None)
28402835
};
28412836
flow_js_utils::add_output_with_env(cx, env, err)?;

‎rust_port/crates/flow_typing_statement/src/statement.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,7 +1660,7 @@ fn bigint_literal_inner<'a>(
16601660
}
16611661

16621662
pub fn regexp_literal<'a>(cx: &mut Context<'a>, loc: ALoc) -> Result<Type, JobError> {
1663-
let reason = mk_annot_reason(VirtualReasonDesc::RRegExp, loc);
1663+
let reason = mk_annot_reason(None, loc);
16641664
flow_js::get_builtin_type_non_speculating(cx, &reason, None, "RegExp")
16651665
}
16661666

@@ -14282,7 +14282,7 @@ fn static_method_call_object<'a>(
1428214282
let reason_clone = reason.dupe();
1428314283
let use_op_clone = use_op.dupe();
1428414284
tvar_resolver::mk_tvar_and_fully_resolve_where::<JobError>(cx, arr_reason, |cx, tvar| {
14285-
let keys_reason = reason_clone.dupe().replace_desc_new(RKeySet);
14285+
let keys_reason = reason_clone.dupe().replace_desc_new(None);
1428614286
flow_js::flow_non_speculating(
1428714287
cx,
1428814288
(

‎rust_port/crates/flow_typing_statement/src/type_annotation.rs‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use flow_common::polarity::Polarity;
2020
use flow_common::reason;
2121
use flow_common::reason::Name;
2222
use flow_common::reason::Reason;
23+
use flow_common::reason::VirtualReasonDesc;
2324
use flow_common::subst_name::SubstName;
2425
use flow_data_structure_wrapper::ord_map::FlowOrdMap;
2526
use flow_data_structure_wrapper::ord_set::FlowOrdSet;
@@ -1343,7 +1344,7 @@ fn convert_inner<'a>(
13431344
let argument_ast = convert_inner(cx, env, &inner.argument)?;
13441345
let arg_t = argument_ast.loc().1.dupe();
13451346
let t = Type::new(type_::TypeInner::KeysT(
1346-
reason::mk_reason(reason::VirtualReasonDesc::RKeySet, loc.dupe()),
1347+
reason::mk_reason(None, loc.dupe()),
13471348
arg_t,
13481349
));
13491350
ast::types::Type::new(TypeInner::Keyof {
@@ -2538,10 +2539,7 @@ fn convert_inner<'a>(
25382539
let tp = ts.into_iter().next().unwrap();
25392540
Ok(reconstruct_ast(
25402541
Type::new(type_::TypeInner::KeysT(
2541-
reason::mk_reason(
2542-
reason::VirtualReasonDesc::RKeySet,
2543-
loc.dupe(),
2544-
),
2542+
reason::mk_reason(None, loc.dupe()),
25452543
tp,
25462544
)),
25472545
None,
@@ -2713,14 +2711,14 @@ fn convert_inner<'a>(
27132711
let (ts, targs_ast) =
27142712
convert_type_params(cx, env, inner.targs.as_ref())?;
27152713
let t1 = ts.into_iter().next().unwrap();
2716-
let reason = reason::mk_reason(
2717-
reason::VirtualReasonDesc::RObjectKeyMirror,
2718-
loc.dupe(),
2719-
);
2714+
let reason = reason::mk_reason(None, loc.dupe());
2715+
let type_reason = reason.dupe().replace_desc(VirtualReasonDesc::RType(
2716+
FlowSmolStr::new_inline("$KeyMirror"),
2717+
));
27202718
let result_t =
27212719
FlowJs::mk_possibly_evaluated_destructor_for_annotations(
27222720
cx,
2723-
use_op(&reason),
2721+
use_op(&type_reason),
27242722
&reason,
27252723
&t1,
27262724
&type_::Destructor::TypeMap(type_::TypeMap::ObjectKeyMirror),

‎rust_port/crates/flow_typing_utils/src/type_sig_merge.rs‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2423,7 +2423,7 @@ fn merge_annot<'cx>(
24232423
})
24242424
}
24252425
Annot::Keys(box (loc, t)) => {
2426-
let reason = reason::mk_reason(RKeySet, loc.dupe());
2426+
let reason = reason::mk_reason(None, loc.dupe());
24272427
let t = merge_impl(env, cx, file, t, false, false);
24282428
Type::new(type_::TypeInner::KeysT(reason, t))
24292429
}
@@ -2576,9 +2576,11 @@ fn merge_annot<'cx>(
25762576
}
25772577
Annot::ObjKeyMirror(inner) => {
25782578
let AnnotObjKeyMirror { loc, obj } = inner.as_ref();
2579-
let reason = reason::mk_reason(RObjectKeyMirror, loc.dupe());
2579+
let reason = reason::mk_reason(None, loc.dupe());
25802580
let use_op = type_::UseOp::Op(Arc::new(type_::RootUseOp::TypeApplication {
2581-
type_: reason.dupe(),
2581+
type_: reason
2582+
.dupe()
2583+
.replace_desc(RType(FlowSmolStr::new_inline("$KeyMirror"))),
25822584
}));
25832585
let obj = merge_impl(env, cx, file, obj, false, false);
25842586
let id = eval_id_of_aloc(cx, loc.dupe());

0 commit comments

Comments
 (0)