Should `inst` be printed with a type suffix? Polymorphic instructions may need a suffix indicating the value of the controlling type variable if it can't be trivially inferred.
(func: &Function, inst: Inst)
| 285 | // if it can't be trivially inferred. |
| 286 | // |
| 287 | fn type_suffix(func: &Function, inst: Inst) -> Option<Type> { |
| 288 | let inst_data = &func.dfg.insts[inst]; |
| 289 | let constraints = inst_data.opcode().constraints(); |
| 290 | |
| 291 | if !constraints.is_polymorphic() { |
| 292 | return None; |
| 293 | } |
| 294 | |
| 295 | // If the controlling type variable can be inferred from the type of the designated value input |
| 296 | // operand, we don't need the type suffix. |
| 297 | if constraints.use_typevar_operand() { |
| 298 | let ctrl_var = inst_data.typevar_operand(&func.dfg.value_lists).unwrap(); |
| 299 | let def_block = match func.dfg.value_def(ctrl_var) { |
| 300 | ValueDef::Result(instr, _) => func.layout.inst_block(instr), |
| 301 | ValueDef::Param(block, _) => Some(block), |
| 302 | ValueDef::Union(..) => None, |
| 303 | }; |
| 304 | if def_block.is_some() && def_block == func.layout.inst_block(inst) { |
| 305 | return None; |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | let rtype = func.dfg.ctrl_typevar(inst); |
| 310 | assert!( |
| 311 | !rtype.is_invalid(), |
| 312 | "Polymorphic instruction must produce a result" |
| 313 | ); |
| 314 | Some(rtype) |
| 315 | } |
| 316 | |
| 317 | /// Write out any aliases to the given target, including indirect aliases |
| 318 | fn write_value_aliases( |
no test coverage detected