| 116 | } |
| 117 | |
| 118 | pub fn def_with_span(self, cx: &CodegenCx<'_>, span: Span) -> Word { |
| 119 | match self.kind { |
| 120 | SpirvValueKind::Def(id) => id, |
| 121 | |
| 122 | SpirvValueKind::IllegalConst(id) => { |
| 123 | let entry = &cx.builder.id_to_const.borrow()[&id]; |
| 124 | let msg = match entry.legal.unwrap_err() { |
| 125 | IllegalConst::Shallow(cause) => { |
| 126 | if let ( |
| 127 | LeafIllegalConst::CompositeContainsPtrTo, |
| 128 | SpirvConst::Composite(_fields), |
| 129 | ) = (cause, &entry.val) |
| 130 | { |
| 131 | // FIXME(eddyb) materialize this at runtime, using |
| 132 | // `OpCompositeConstruct` (transitively, i.e. after |
| 133 | // putting every field through `SpirvValue::def`), |
| 134 | // if we have a `Builder` to do that in. |
| 135 | // FIXME(eddyb) this isn't possible right now, as |
| 136 | // the builder would be dynamically "locked" anyway |
| 137 | // (i.e. attempting to do `bx.emit()` would panic). |
| 138 | } |
| 139 | |
| 140 | cause.message() |
| 141 | } |
| 142 | |
| 143 | IllegalConst::Indirect(cause) => cause.message(), |
| 144 | }; |
| 145 | |
| 146 | cx.zombie_with_span(id, span, msg); |
| 147 | |
| 148 | id |
| 149 | } |
| 150 | |
| 151 | SpirvValueKind::IllegalTypeUsed(id) => { |
| 152 | cx.tcx |
| 153 | .sess |
| 154 | .struct_span_err(span, "Can't use type as a value") |
| 155 | .note(format!("Type: *{}", cx.debug_type(id))) |
| 156 | .emit(); |
| 157 | |
| 158 | id |
| 159 | } |
| 160 | |
| 161 | SpirvValueKind::FnAddr { .. } => { |
| 162 | cx.builder |
| 163 | .const_to_id |
| 164 | .borrow() |
| 165 | .get(&WithType { |
| 166 | ty: self.ty, |
| 167 | val: SpirvConst::ZombieUndefForFnAddr, |
| 168 | }) |
| 169 | .expect("FnAddr didn't go through proper undef registration") |
| 170 | .val |
| 171 | } |
| 172 | |
| 173 | SpirvValueKind::LogicalPtrCast { |
| 174 | original_ptr: _, |
| 175 | original_pointee_ty, |