2 index::{BlockIdx, DisplayOptionIdx, InstIdx, SSAValIdx},
7 #[derive(Debug, Error)]
9 #[error("can't create a vector of an only-scalar type: {base_ty:?}")]
10 TriedToCreateVectorOfOnlyScalarType { base_ty: BaseTy },
11 #[error("reg_len out of range")]
13 #[error("invalid reg_len")]
15 #[error("start not in valid range")]
17 #[error("BaseTy mismatch")]
19 #[error("invalid sub-Loc: offset and/or reg_len out of range")]
20 InvalidSubLocOutOfRange,
21 #[error("Ty mismatch: expected {expected_ty:?} got {ty:?}")]
24 expected_ty: Option<Ty>,
26 #[error("function doesn't have entry block")]
28 #[error("instruction index is too big")]
30 #[error("block has invalid start {start}, expected {expected_start}")]
31 BlockHasInvalidStart {
33 expected_start: InstIdx,
35 #[error("block {block} doesn't contain any instructions")]
36 BlockIsEmpty { block: BlockIdx },
37 #[error("entry block must not have any block parameters")]
38 EntryBlockCantHaveParams,
39 #[error("entry block must not have any predecessors")]
40 EntryBlockCantHavePreds,
41 #[error("block end is out of range: {end}")]
42 BlockEndOutOfRange { end: InstIdx },
43 #[error("block's last instruction must be a block terminator: {term_idx}")]
44 BlocksLastInstMustBeTerm { term_idx: InstIdx },
46 "block terminator instructions are only allowed as a block's last \
47 instruction: {inst_idx}"
49 TermInstOnlyAllowedAtBlockEnd { inst_idx: InstIdx },
50 #[error("instruction not in a block: {inst}")]
51 InstHasNoBlock { inst: InstIdx },
52 #[error("operand index {operand_idx} out of range for {inst}")]
53 OperandIndexOutOfRange { inst: InstIdx, operand_idx: usize },
54 #[error("duplicate copy destination operand: operand index {operand_idx} for {inst}")]
55 DupCopyDestOperand { inst: InstIdx, operand_idx: usize },
56 #[error("SSA value index {idx} out of range")]
57 SSAValIdxOutOfRange { idx: SSAValIdx },
58 #[error("instruction index {idx} out of range")]
59 InstIdxOutOfRange { idx: InstIdx },
60 #[error("block index {idx} out of range")]
61 BlockIdxOutOfRange { idx: BlockIdx },
62 #[error("copy instruction's source type doesn't match source operands")]
63 CopySrcTyMismatch { inst: InstIdx },
64 #[error("copy instruction's destination type doesn't match destination operands")]
65 CopyDestTyMismatch { inst: InstIdx },
67 "operand index {operand_idx} for {inst} is missing from SSA value \
71 ssa_val_idx: SSAValIdx,
76 "operand index {operand_idx} for {inst} has kind `Def` but isn't \
77 SSA value {ssa_val_idx}'s definition"
79 OperandDefIsNotSSAValDef {
80 ssa_val_idx: SSAValIdx,
85 "SSA value {ssa_val_idx}'s definition isn't the corresponding \
86 operand's SSA Value: operand index {operand_idx} for {inst}"
88 SSAValDefIsNotOperandsSSAVal {
89 ssa_val_idx: SSAValIdx,
94 "SSA value {ssa_val_idx}'s type can't be used with the constraint on \
95 operand index {operand_idx} for {inst}"
97 ConstraintTyMismatch {
98 ssa_val_idx: SSAValIdx,
103 "fixed location constraint on operand index {operand_idx} for \
104 {inst} conflicts with clobbers"
106 FixedLocConflictsWithClobbers { inst: InstIdx, operand_idx: usize },
107 #[error("operand kind must be def")]
108 OperandKindMustBeDef,
110 "reuse target operand (index {reuse_target_operand_idx}) for \
111 {inst} must have kind `Use`"
113 ReuseTargetOperandMustBeUse {
115 reuse_target_operand_idx: usize,
118 "source block {src_block} missing from branch {branch_inst}'s \
119 target block {tgt_block}'s predecessors"
121 SrcBlockMissingFromBranchTgtBlocksPreds {
123 branch_inst: InstIdx,
127 "branch {inst}'s parameter (index {param_idx}) for successor {succ} \
128 is missing from SSA value {ssa_val_idx}'s uses"
130 MissingBranchSuccParamUse {
131 ssa_val_idx: SSAValIdx,
137 "the number of parameters ({branch_param_count}) for branch {inst}'s \
138 successor {succ} doesn't match the number of parameters \
139 ({block_param_count}) declared in that block"
141 BranchSuccParamCountMismatch {
144 block_param_count: usize,
145 branch_param_count: usize,
148 "the type {branch_param_ty:?} of parameter {param_idx} for branch \
149 {inst}'s successor {succ} doesn't match the type {block_param_ty:?} \
150 declared in that block"
152 BranchSuccParamTyMismatch {
160 "block {block}'s parameter {param_idx} doesn't match SSA value \
161 {ssa_val_idx}'s definition"
163 MismatchedBlockParamDef {
164 ssa_val_idx: SSAValIdx,
169 "predecessor {src_block} of target block {tgt_block} is missing from \
170 that predecessor block's terminating branch {branch_inst}'s targets"
172 PredMissingFromPredsTermBranchsTargets {
174 branch_inst: InstIdx,
177 #[error("block parameter index {param_idx} is out of range for block {block}")]
178 BlockParamIdxOutOfRange { block: BlockIdx, param_idx: usize },
180 "SSA value {ssa_val_idx}'s use isn't the corresponding \
181 operand's SSA Value: operand index {operand_idx} for {inst}"
183 SSAValUseIsNotOperandsSSAVal {
184 ssa_val_idx: SSAValIdx,
189 "SSA value {ssa_val_idx} is use as a branch instruction {inst}'s \
190 block parameter, but that instruction isn't a branch instruction"
192 SSAValUseIsNotBranch {
193 ssa_val_idx: SSAValIdx,
196 #[error("expected instruction {inst} to be a `BlockTerm` instruction")]
197 InstIsNotBlockTerm { inst: InstIdx },
198 #[error("target block {tgt_block} not found in branch instruction {branch_inst}")]
199 BranchTargetNotFound {
200 branch_inst: InstIdx,
204 "branch instruction {branch_inst}'s block parameter index {param_idx} \
205 is out of range for target block {tgt_block}"
207 BranchTargetParamIdxOutOfRange {
208 branch_inst: InstIdx,
213 "SSA value {ssa_val_idx}'s use isn't the corresponding \
214 branch {branch_inst}'s target block parameter's SSA Value for \
215 target block {tgt_block}'s parameter index {param_idx}"
217 MismatchedBranchTargetBlockParamUse {
218 ssa_val_idx: SSAValIdx,
219 branch_inst: InstIdx,
224 "block {block_idx} has incorrect immediate dominator: expected \
226 .expected.display_option_idx(),
227 .found.display_option_idx(),
229 IncorrectImmediateDominator {
231 found: Option<BlockIdx>,
232 expected: Option<BlockIdx>,
235 "critical edges are not allowed: source block {src_block} has \
236 multiple successors and target block {tgt_block} has multiple \
237 predecessors: source block's terminating branch {branch_inst}"
239 CriticalEdgeNotAllowed {
241 branch_inst: InstIdx,
245 "operand can't reuse operand of differing type: in {inst}: reuse \
246 source operand: index {src_operand_idx} type {src_ty:?}) reuse \
247 target operand: index {tgt_operand_idx} type {tgt_ty:?})"
249 ReuseOperandTyMismatch {
251 tgt_operand_idx: usize,
252 src_operand_idx: usize,
258 pub type Result<T, E = Error> = std::result::Result<T, E>;
260 impl From<Error> for arbitrary::Error {
261 fn from(_value: Error) -> Self {
262 Self::IncorrectFormat