Link a constant handle to its value. This does not de-duplicate data but does avoid replacing any existing constant values. use `set` to tie a specific `const42` to its value; use `insert` to add a value and return the next available `const` entity.
(&mut self, constant_handle: Constant, constant_value: ConstantData)
| 234 | /// replacing any existing constant values. use `set` to tie a specific `const42` to its value; |
| 235 | /// use `insert` to add a value and return the next available `const` entity. |
| 236 | pub fn set(&mut self, constant_handle: Constant, constant_value: ConstantData) { |
| 237 | let replaced = self |
| 238 | .handles_to_values |
| 239 | .insert(constant_handle, constant_value.clone()); |
| 240 | assert!( |
| 241 | replaced.is_none(), |
| 242 | "attempted to overwrite an existing constant {:?}: {:?} => {:?}", |
| 243 | constant_handle, |
| 244 | &constant_value, |
| 245 | replaced.unwrap() |
| 246 | ); |
| 247 | self.values_to_handles |
| 248 | .insert(constant_value, constant_handle); |
| 249 | } |
| 250 | |
| 251 | /// Iterate over the constants in insertion order. |
| 252 | pub fn iter(&self) -> impl Iterator<Item = (&Constant, &ConstantData)> { |