mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 22:02:52 +01:00
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:
+11
-10
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user