| 330 | } |
| 331 | |
| 332 | fn absolute_impl(&self, span: SpanId, depth: usize) -> Option<SourceSpan> |
| 333 | where |
| 334 | S: Span, |
| 335 | { |
| 336 | assert!( |
| 337 | depth <= Self::MAX_SPAN_DEPTH, |
| 338 | "Cannot resolve excessively deep span of {depth}, likely due to a circular dependency" |
| 339 | ); |
| 340 | |
| 341 | // Special case synthetic spans, which have no source location |
| 342 | if span == SpanId::SYNTHETIC { |
| 343 | return Some(SourceSpan::from_parts( |
| 344 | self.source_id, |
| 345 | TextRange::empty(TextSize::new(0)), |
| 346 | )); |
| 347 | } |
| 348 | |
| 349 | let entry = self.get_entry(span)?; |
| 350 | let ancestors = &self.ancestors[entry.ancestors.clone()]; |
| 351 | |
| 352 | let (base, rest) = match ancestors { |
| 353 | [] => return Some(SourceSpan::from_parts(span.source_id(), entry.span.range())), |
| 354 | [base, rest @ ..] => (*base, rest), |
| 355 | }; |
| 356 | |
| 357 | let mut base = self.absolute_impl(base, depth + 1)?.range(); |
| 358 | for &ancestor in rest { |
| 359 | let ancestor = self.absolute_impl(ancestor, depth + 1)?.range(); |
| 360 | |
| 361 | base = match entry.mode { |
| 362 | SpanResolutionMode::Intersection => base.intersect(ancestor)?, |
| 363 | SpanResolutionMode::Union => base.cover(ancestor), |
| 364 | }; |
| 365 | } |
| 366 | |
| 367 | let range = entry.span.range() + base.start(); |
| 368 | Some(SourceSpan::from_parts(span.source_id(), range)) |
| 369 | } |
| 370 | |
| 371 | /// Resolves a span to its absolute source position. |
| 372 | /// |