Helper: compile a single definition/theorem/opaque (non-mutual case). When `aux` is false (ephemeral compilation for metadata capture), skip storing the Ixon blob, Named entry, and block stats.
(
name: &Name,
def: &Def,
cache: &mut BlockCache,
stt: &CompileState,
aux: bool,
)
| 3226 | (MutConst::Defn(x), MutConst::Defn(y)) => compare_defn(x, y, mut_ctx, stt)?, |
| 3227 | (MutConst::Indc(x), MutConst::Indc(y)) => { |
| 3228 | compare_indc(x, y, mut_ctx, cache, stt)? |
| 3229 | }, |
| 3230 | (MutConst::Recr(x), MutConst::Recr(y)) => compare_recr(x, y, mut_ctx, stt)?, |
| 3231 | _ => SOrd::cmp(&mut_const_kind(x), &mut_const_kind(y)), |
| 3232 | }; |
| 3233 | if so.strong { |
| 3234 | cache.cmps.insert(key, so.ordering); |
| 3235 | } |
| 3236 | Ok(if reversed { so.ordering.reverse() } else { so.ordering }) |
| 3237 | } |
| 3238 | |
| 3239 | /// Check if two mutual constants are structurally equal. |
| 3240 | pub fn eq_const( |
| 3241 | x: &MutConst, |
| 3242 | y: &MutConst, |
| 3243 | mut_ctx: &MutCtx, |
| 3244 | cache: &mut BlockCache, |
| 3245 | stt: &CompileState, |
| 3246 | ) -> Result<bool, CompileError> { |
| 3247 | let ordering = compare_const(x, y, mut_ctx, cache, stt)?; |
| 3248 | Ok(ordering == Ordering::Equal) |
| 3249 | } |
| 3250 | |
| 3251 | /// Group consecutive equal elements in a sorted slice. Assumes the input |
| 3252 | /// is already sorted by the same relation used for equality testing. |
| 3253 | pub fn group_by<T, F>( |
| 3254 | items: Vec<&T>, |
| 3255 | mut eq: F, |
| 3256 | ) -> Result<Vec<Vec<&T>>, CompileError> |
| 3257 | where |
| 3258 | F: FnMut(&T, &T) -> Result<bool, CompileError>, |
| 3259 | { |
| 3260 | let mut groups = Vec::new(); |
| 3261 | let mut current: Vec<&T> = Vec::new(); |
| 3262 | for item in items { |
| 3263 | if let Some(last) = current.last() { |
| 3264 | if eq(last, item)? { |
| 3265 | current.push(item); |
| 3266 | } else { |
| 3267 | groups.push(std::mem::replace(&mut current, vec![item])); |
| 3268 | } |
| 3269 | } else { |
| 3270 | current.push(item); |
| 3271 | } |
| 3272 | } |
| 3273 | if !current.is_empty() { |
| 3274 | groups.push(current); |
| 3275 | } |
| 3276 | Ok(groups) |
| 3277 | } |
| 3278 | |
| 3279 | /// Merge two sorted sequences of mutual constants into one sorted sequence. |
| 3280 | pub fn merge<'a>( |
| 3281 | left: Vec<&'a MutConst>, |
| 3282 | right: Vec<&'a MutConst>, |
| 3283 | ctx: &MutCtx, |
| 3284 | cache: &mut BlockCache, |
| 3285 | stt: &CompileState, |
no test coverage detected