Skip to content

Commit e3e01a7

Browse files
SamChou19815meta-codesync[bot]
authored andcommitted
[flow] Remove call result reason wrappers
Summary: Delete `RFunctionCall`, `RConstructorCall`, and `RJSXFunctionCall` and their mapping and display cases. Call results and latent predicate calls now use location-only reasons. Missing-argument diagnostics were migrated to printed types in the preceding commit. Changelog: [internal] Remove call result reason wrappers. Reviewed By: gkz Differential Revision: D126828382 fbshipit-source-id: 09bcff09e6c44337ed20e361c3056a1d52a85e65
1 parent 2a46e7e commit e3e01a7

5 files changed

Lines changed: 58 additions & 110 deletions

File tree

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,6 @@ pub enum VirtualReasonDesc<L: Dupe> {
348348
RTupleElement,
349349
RTupleOutOfBoundsAccess(i32),
350350
RFunction(ReasonDescFunction),
351-
RFunctionCall(Option<Arc<VirtualReasonDesc<L>>>),
352-
RJSXFunctionCall(FlowSmolStr),
353351
RUnaryOperator(FlowSmolStr, Arc<VirtualReasonDesc<L>>),
354352
RBinaryOperator(
355353
Box<(
@@ -373,7 +371,6 @@ pub enum VirtualReasonDesc<L: Dupe> {
373371
member_name: FlowSmolStr,
374372
},
375373
REnumUnknownMembers(Arc<VirtualReasonDesc<L>>),
376-
RConstructorCall(Option<Arc<VirtualReasonDesc<L>>>),
377374
RRecordType(FlowSmolStr),
378375
RType(FlowSmolStr),
379376
RTypeAlias(Box<(FlowSmolStr, Option<L>, Option<Arc<VirtualReasonDesc<L>>>)>),
@@ -454,7 +451,6 @@ impl<A: Dupe> VirtualReasonDesc<A> {
454451
RTupleUnknownElementFromInexact => RTupleUnknownElementFromInexact,
455452
RFunction(func) => RFunction(*func),
456453
RFunctionType => RFunctionType,
457-
RJSXFunctionCall(s) => RJSXFunctionCall(s.dupe()),
458454
RFbt => RFbt,
459455
RUninitialized => RUninitialized,
460456
RPossiblyUninitialized => RPossiblyUninitialized,
@@ -535,7 +531,6 @@ impl<A: Dupe> VirtualReasonDesc<A> {
535531
RReactChildren => RReactChildren,
536532

537533
// Recursive variants
538-
RFunctionCall(d) => RFunctionCall(d.as_ref().map(|d| Arc::new(d.map_locs(f)))),
539534
RUnknownUnspecifiedProperty(d) => RUnknownUnspecifiedProperty(Arc::new(d.map_locs(f))),
540535
RUnaryOperator(s, d) => RUnaryOperator(s.dupe(), Arc::new(d.map_locs(f))),
541536
RBinaryOperator(box (s, d1, d2)) => RBinaryOperator(Box::new((
@@ -548,7 +543,6 @@ impl<A: Dupe> VirtualReasonDesc<A> {
548543
Arc::new(d1.map_locs(f)),
549544
Arc::new(d2.map_locs(f)),
550545
))),
551-
RConstructorCall(d) => RConstructorCall(d.as_ref().map(|d| Arc::new(d.map_locs(f)))),
552546
RTypeAlias(box (s, loc_opt, d)) => RTypeAlias(Box::new((
553547
s.dupe(),
554548
loc_opt.as_ref().map(f),
@@ -1294,13 +1288,8 @@ pub fn string_of_desc<L: Dupe>(desc: &VirtualReasonDesc<L>) -> String {
12941288
// Functions
12951289
RFunction(func) => format!("{}function", func.prefix()),
12961290
RFunctionType => "function type".to_string(),
1297-
RFunctionCall(d) => format!(
1298-
"call of {}",
1299-
d.as_deref().map(string_of_desc).unwrap_or_default()
1300-
),
13011291

13021292
// JSX
1303-
RJSXFunctionCall(raw_jsx) => format!("`{}(...)`", raw_jsx),
13041293
RFbt => "`<fbt/>`".to_string(),
13051294

13061295
// Operators
@@ -1364,10 +1353,6 @@ pub fn string_of_desc<L: Dupe>(desc: &VirtualReasonDesc<L>) -> String {
13641353

13651354
// Constructors
13661355
RConstructor => "constructor".to_string(),
1367-
RConstructorCall(d) => format!(
1368-
"new {}",
1369-
d.as_deref().map(string_of_desc).unwrap_or_default()
1370-
),
13711356

13721357
// Records
13731358
RRecordType(name) => format!("record `{}`", name),

‎rust_port/crates/flow_typing_errors/src/intermediate_error.rs‎

Lines changed: 43 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ use flow_typing_type::type_::VirtualRootUseOp;
7070
use flow_typing_type::type_::VirtualUseOp;
7171
use flow_typing_type::type_::aconstraint::AnnotationInferenceOperation;
7272
use flow_typing_type::type_::fold_virtual_use_op;
73+
use flow_typing_type::type_::implicit_instantiation_reference_kind;
7374
use flow_typing_type::type_::root_of_use_op;
7475
use flow_typing_type::type_::type_or_type_desc::ErrorTypeDesc;
7576
use flow_typing_type::type_::type_or_type_desc::TypeOrTypeDescT;
@@ -3386,6 +3387,39 @@ where
33863387
}
33873388
};
33883389

3390+
let missing_argument_message =
3391+
|def: &VirtualReason<L>, op: &VirtualReason<L>, inner_use_op: &VirtualUseOp<L>| {
3392+
if let VirtualUseOp::Op(inner_root) = inner_use_op
3393+
&& matches!(
3394+
inner_root.as_ref(),
3395+
VirtualRootUseOp::FunCall(..) | VirtualRootUseOp::FunCallMethod(..)
3396+
)
3397+
{
3398+
let def = def.dupe().update_desc(|desc| match desc {
3399+
Some(VirtualReasonDesc::RFunctionType) => {
3400+
Some(VirtualReasonDesc::RFunction(ReasonDescFunction::RNormal))
3401+
}
3402+
_ => desc,
3403+
});
3404+
Message::MessageFunctionRequiresAnotherArgument { def, from: None }
3405+
} else if op.desc(false).is_none()
3406+
&& let Some(kind) = implicit_instantiation_reference_kind(inner_use_op)
3407+
{
3408+
Message::MessageFunctionRequiresAnotherArgumentFromCall {
3409+
def: def.dupe(),
3410+
call: ImplicitInstantiationReferenceData {
3411+
loc: op.loc().dupe(),
3412+
kind: kind.dupe(),
3413+
},
3414+
}
3415+
} else {
3416+
Message::MessageFunctionRequiresAnotherArgument {
3417+
def: def.dupe(),
3418+
from: Some(op.dupe()),
3419+
}
3420+
}
3421+
};
3422+
33893423
// An error between two incompatible types. A "lower" type and an "upper" type.
33903424
let mk_incompatible_error = |additional_explanation: Option<Explanation<L>>,
33913425
lower: VirtualReason<L>,
@@ -3447,30 +3481,7 @@ where
34473481

34483482
VirtualUseOp::Frame(frame, inner_use_op) => match frame.as_ref() {
34493483
VirtualFrameUseOp::FunMissingArg(box FunMissingArgData { def, op, .. }) => {
3450-
let message = match inner_use_op.as_ref() {
3451-
VirtualUseOp::Op(inner_root) => match inner_root.as_ref() {
3452-
VirtualRootUseOp::FunCall(..) | VirtualRootUseOp::FunCallMethod(..) => {
3453-
let new_def = def.dupe().update_desc(|desc| match desc {
3454-
Some(VirtualReasonDesc::RFunctionType) => Some(
3455-
VirtualReasonDesc::RFunction(ReasonDescFunction::RNormal),
3456-
),
3457-
_ => desc,
3458-
});
3459-
Message::MessageFunctionRequiresAnotherArgument {
3460-
def: new_def,
3461-
from: None,
3462-
}
3463-
}
3464-
_ => Message::MessageFunctionRequiresAnotherArgument {
3465-
def: def.dupe(),
3466-
from: Some(op.dupe()),
3467-
},
3468-
},
3469-
_ => Message::MessageFunctionRequiresAnotherArgument {
3470-
def: def.dupe(),
3471-
from: Some(op.dupe()),
3472-
},
3473-
};
3484+
let message = missing_argument_message(def, op, inner_use_op);
34743485
mk_use_op_error_reason(
34753486
op,
34763487
use_op.clone(),
@@ -3733,29 +3744,7 @@ where
37333744
&& let VirtualFrameUseOp::FunMissingArg(box FunMissingArgData { def, op, .. }) =
37343745
frame.as_ref()
37353746
{
3736-
let message = match inner_use_op.as_ref() {
3737-
VirtualUseOp::Op(inner_root)
3738-
if matches!(
3739-
inner_root.as_ref(),
3740-
VirtualRootUseOp::FunCall(..) | VirtualRootUseOp::FunCallMethod(..)
3741-
) =>
3742-
{
3743-
let new_def = def.dupe().update_desc(|desc| match desc {
3744-
Some(VirtualReasonDesc::RFunctionType) => {
3745-
Some(VirtualReasonDesc::RFunction(ReasonDescFunction::RNormal))
3746-
}
3747-
_ => desc,
3748-
});
3749-
Message::MessageFunctionRequiresAnotherArgument {
3750-
def: new_def,
3751-
from: None,
3752-
}
3753-
}
3754-
_ => Message::MessageFunctionRequiresAnotherArgument {
3755-
def: def.dupe(),
3756-
from: Some(op.dupe()),
3757-
},
3758-
};
3747+
let message = missing_argument_message(def, op, inner_use_op);
37593748
mk_use_op_error_reason(op, use_op.clone(), explanation, message)
37603749
} else {
37613750
let (((lower_loc, lower_desc), (upper_loc, upper_desc)), use_op) =
@@ -10699,6 +10688,13 @@ where
1069910688
ref_(from),
1070010689
]),
1070110690
},
10691+
MessageFunctionRequiresAnotherArgumentFromCall { def, call } => {
10692+
friendly::Message(vec![
10693+
ref_(def),
10694+
text(" requires another argument from "),
10695+
render_implicit_instantiation_reference(call),
10696+
])
10697+
}
1070210698
MessageIncompatibleComponentRestParam(rest_param) => friendly::Message(vec![
1070310699
text("Cannot use "),
1070410700
ref_of_type(rest_param),

‎rust_port/crates/flow_typing_errors/src/intermediate_error_types.rs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2397,6 +2397,11 @@ pub enum Message<L: Dupe> {
23972397
from: Option<VirtualReason<L>>,
23982398
},
23992399

2400+
MessageFunctionRequiresAnotherArgumentFromCall {
2401+
def: VirtualReason<L>,
2402+
call: ImplicitInstantiationReferenceData<L>,
2403+
},
2404+
24002405
MessageImportTypeAsTypeof(FlowSmolStr),
24012406
MessageImportTypeAsValue(FlowSmolStr),
24022407
MessageImportValueAsType(FlowSmolStr),

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

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7484,12 +7484,7 @@ fn expression_<'a>(
74847484
name,
74857485
callee_loc.dupe(),
74867486
)?;
7487-
let reason_call = mk_reason(
7488-
VirtualReasonDesc::RConstructorCall(
7489-
desc_of_t(&id_t).cloned().map(Arc::new),
7490-
),
7491-
loc.dupe(),
7492-
);
7487+
let reason_call = mk_reason(None, loc.dupe());
74937488
let use_op =
74947489
UseOp::Op(Arc::new(type_::RootUseOp::FunCall(Box::new(FunCallData {
74957490
op: reason.dupe(),
@@ -7551,10 +7546,7 @@ fn expression_<'a>(
75517546
}
75527547
None => (vec![], vec![], None),
75537548
};
7554-
let reason = mk_reason(
7555-
VirtualReasonDesc::RConstructorCall(desc_of_t(&class_).cloned().map(Arc::new)),
7556-
loc.dupe(),
7557-
);
7549+
let reason = mk_reason(None, loc.dupe());
75587550
let use_op = UseOp::Op(Arc::new(type_::RootUseOp::FunCall(Box::new(FunCallData {
75597551
op: mk_expression_reason(e),
75607552
fn_: mk_expression_reason(&inner.callee),
@@ -7943,10 +7935,7 @@ fn expression_<'a>(
79437935
let tag_ast = expression(None, None, None, cx, &inner.tag)?;
79447936
let (targts, targs_ast) = convert_call_targs_opt(cx, inner.targs.as_ref())?;
79457937
let t = tag_ast.loc().1.dupe();
7946-
let reason = mk_reason(
7947-
RFunctionCall(desc_of_t(&t).cloned().map(Arc::new)),
7948-
loc.dupe(),
7949-
);
7938+
let reason = mk_reason(None, loc.dupe());
79507939
let reason_array = mk_reason(VirtualReasonDesc::RArray, reason.loc().dupe());
79517940
let ret_id = flow_typing_tvar::mk_no_wrap(cx, &reason);
79527941
let ret_tvar = Tvar::new(reason.dupe(), ret_id as u32);
@@ -9148,12 +9137,7 @@ pub fn optional_chain<'a>(
91489137
} = inner.callee.deref() =>
91499138
{
91509139
let (targts, targs) = convert_call_targs_opt(cx, inner.targs.as_ref())?;
9151-
let reason = mk_reason(
9152-
VirtualReasonDesc::RFunctionCall(Some(
9153-
VirtualReasonDesc::RCode(FlowSmolStr::new_inline("super")).into(),
9154-
)),
9155-
loc.dupe(),
9156-
);
9140+
let reason = mk_reason(None, loc.dupe());
91579141
let super_t = super_(cx, super_loc.dupe())?;
91589142
let (argts, arguments_ast) = arg_list(cx, &inner.arguments)?;
91599143
let super_reason = reason_of_t(&super_t).dupe();
@@ -10642,12 +10626,7 @@ pub fn optional_chain<'a>(
1064210626
};
1064310627
let get_reason: Box<dyn Fn(&Type) -> Reason + '_> = {
1064410628
let loc = loc.dupe();
10645-
Box::new(move |lhs_t: &Type| {
10646-
mk_reason(
10647-
RFunctionCall(desc_of_t(lhs_t).cloned().map(Arc::new)),
10648-
loc.dupe(),
10649-
)
10650-
})
10629+
Box::new(move |_lhs_t: &Type| mk_reason(None, loc.dupe()))
1065110630
};
1065210631
let get_result: Box<
1065310632
dyn Fn(&mut Context<'a>, &Vec<CallArg>, Reason, &Type) -> Result<Type, JobError>,
@@ -13851,10 +13830,7 @@ fn non_react_jsx_desugar<'a>(
1385113830
attributes: &[ast::jsx::OpeningAttribute<ALoc, ALoc>],
1385213831
children: Vec<type_::UnresolvedParam>,
1385313832
) -> Result<(Type, Option<Type>, Option<Type>), CheckExprError> {
13854-
let reason = mk_reason(
13855-
VirtualReasonDesc::RJSXFunctionCall(FlowSmolStr::from(raw_jsx_expr)),
13856-
loc_element.dupe(),
13857-
);
13833+
let reason = mk_reason(None, loc_element.dupe());
1385813834
// A JSX element with no attributes should pass in null as the second arg
1385913835
let props = if attributes.is_empty() {
1386013836
type_::null::at(loc_opening.dupe())

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

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use std::cell::Cell;
99
use std::cell::RefCell;
1010
use std::ops::Deref;
1111
use std::rc::Rc;
12-
use std::sync::Arc;
1312

1413
use dupe::Dupe;
1514
use dupe::IterDupedExt;
@@ -72,7 +71,6 @@ use flow_typing_type::type_::union_rep;
7271
use flow_typing_type::type_::union_rep::QuickMemResult;
7372
use flow_typing_type::type_::unknown_use;
7473
use flow_typing_type::type_util;
75-
use flow_typing_type::type_util::desc_of_t;
7674
use flow_typing_type::type_util::loc_of_t;
7775
use flow_typing_type::type_util::reason_of_t;
7876
use flow_utils_concurrency::job_error::JobError;
@@ -735,10 +733,7 @@ fn predicate_no_concretization<'cx>(
735733
let use_op = pred_funcall_info.0.dupe();
736734
let targs = &pred_funcall_info.3;
737735
let argts = &pred_funcall_info.4;
738-
let reason = mk_reason(
739-
VirtualReasonDesc::RFunctionCall(desc_of_t(fun_t).cloned().map(Arc::new)),
740-
loc,
741-
);
736+
let reason = mk_reason(None, loc);
742737
call_latent_param_pred(
743738
cx,
744739
env,
@@ -760,10 +755,7 @@ fn predicate_no_concretization<'cx>(
760755
let use_op = pred_funcall_info.0.dupe();
761756
let targs = &pred_funcall_info.3;
762757
let argts = &pred_funcall_info.4;
763-
let reason = mk_reason(
764-
VirtualReasonDesc::RFunctionCall(desc_of_t(fun_t).cloned().map(Arc::new)),
765-
loc,
766-
);
758+
let reason = mk_reason(None, loc);
767759
call_latent_this_pred(
768760
cx,
769761
env,
@@ -940,10 +932,7 @@ fn predicate_no_concretization<'cx>(
940932
let use_op = pred_funcall_info.0.dupe();
941933
let targs = &pred_funcall_info.3;
942934
let argts = &pred_funcall_info.4;
943-
let reason = mk_reason(
944-
VirtualReasonDesc::RFunctionCall(desc_of_t(fun_t).cloned().map(Arc::new)),
945-
loc,
946-
);
935+
let reason = mk_reason(None, loc);
947936
call_latent_param_pred(
948937
cx,
949938
env,
@@ -965,10 +954,7 @@ fn predicate_no_concretization<'cx>(
965954
let use_op = pred_funcall_info.0.dupe();
966955
let targs = &pred_funcall_info.3;
967956
let argts = &pred_funcall_info.4;
968-
let reason = mk_reason(
969-
VirtualReasonDesc::RFunctionCall(desc_of_t(fun_t).cloned().map(Arc::new)),
970-
loc,
971-
);
957+
let reason = mk_reason(None, loc);
972958
call_latent_this_pred(
973959
cx,
974960
env,

0 commit comments

Comments
 (0)