Restructure action-dependence APIs (#7074)

- Rename `ActionIsDependent` to `ActionIsPerformable` (with negated
meaning), because that name is more concrete and, um, actionable.
- Replace `OperandIsDependent` with `OperandDependence`, which returns a
`ConstantDependence` instead of a bool. We need this additional
generality for handling form actions, where we sometimes need to ask
whether something has _any_ dependence, not just whether it has template
dependence.
This commit is contained in:
Geoff Romer
2026-04-17 19:03:21 +00:00
committed by GitHub
parent f91990aa87
commit ad0a4ea8a4
4 changed files with 62 additions and 56 deletions
+11 -10
View File
@@ -1971,17 +1971,18 @@ auto Convert(Context& context, SemIR::LocId loc_id, SemIR::InstId expr_id,
// didn't apply in the template definition.
// TODO: Support this for targets other than `Value`.
if (sem_ir.insts().Get(expr_id).type_id() != target.type_id &&
target.kind == ConversionTarget::Value &&
(OperandIsDependent(context, expr_id) ||
OperandIsDependent(context, target.type_id))) {
target.kind == ConversionTarget::Value) {
auto target_type_inst_id = context.types().GetTypeInstId(target.type_id);
return AddDependentActionSplice(
context, loc_id,
SemIR::ConvertToValueAction{
.type_id = GetSingletonType(context, SemIR::InstType::TypeInstId),
.inst_id = expr_id,
.target_type_inst_id = target_type_inst_id},
target_type_inst_id);
SemIR::ConvertToValueAction convert_action = {
.type_id = GetSingletonType(context, SemIR::InstType::TypeInstId),
.inst_id = expr_id,
.target_type_inst_id = target_type_inst_id};
// We don't use `HandleAction` here because it would call `PerformAction`
// inline if it's performable, which would lead to infinite recursion.
if (!ActionIsPerformable(context, convert_action)) {
return AddDependentActionSplice(context, loc_id, convert_action,
target_type_inst_id);
}
}
// If this is not a builtin conversion, try an `ImplicitAs` conversion.