Skip to content

Commit f682b76

Browse files
committed
Add Deref impl for Spanned
1 parent 8140ea8 commit f682b76

File tree

5 files changed

+33
-27
lines changed

5 files changed

+33
-27
lines changed

fathom/src/core/binary.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ impl<'arena, 'env, 'data> Context<'arena, 'env, 'data> {
450450
len: &ArcValue<'arena>,
451451
elem_format: &ArcValue<'arena>,
452452
) -> Result<ArcValue<'arena>, ReadError<'arena>> {
453-
let len = match self.elim_context().force(len).inner.as_ref() {
453+
let len = match self.elim_context().force(len).as_ref() {
454454
Value::ConstLit(Const::U8(len, _)) => u64::from(*len),
455455
Value::ConstLit(Const::U16(len, _)) => u64::from(*len),
456456
Value::ConstLit(Const::U32(len, _)) => u64::from(*len),
@@ -503,7 +503,7 @@ impl<'arena, 'env, 'data> Context<'arena, 'env, 'data> {
503503
elem_format: &ArcValue<'arena>,
504504
) -> Result<ArcValue<'arena>, ReadError<'arena>> {
505505
let len_span = len.span();
506-
let len = match self.elim_context().force(len).inner.as_ref() {
506+
let len = match self.elim_context().force(len).as_ref() {
507507
Value::ConstLit(Const::U8(len, _)) => Some(usize::from(*len)),
508508
Value::ConstLit(Const::U16(len, _)) => Some(usize::from(*len)),
509509
Value::ConstLit(Const::U32(len, _)) => usize::try_from(*len).ok(),
@@ -526,7 +526,7 @@ impl<'arena, 'env, 'data> Context<'arena, 'env, 'data> {
526526
pos_value: &ArcValue<'arena>,
527527
elem_format: &ArcValue<'arena>,
528528
) -> Result<ArcValue<'arena>, ReadError<'arena>> {
529-
let pos = match self.elim_context().force(pos_value).inner.as_ref() {
529+
let pos = match self.elim_context().force(pos_value).as_ref() {
530530
Value::ConstLit(Const::Pos(pos)) => *pos,
531531
_ => return Err(ReadError::InvalidValue(pos_value.span())),
532532
};
@@ -544,7 +544,7 @@ impl<'arena, 'env, 'data> Context<'arena, 'env, 'data> {
544544
format: &ArcValue<'arena>,
545545
r#ref: &ArcValue<'arena>,
546546
) -> Result<ArcValue<'arena>, ReadError<'arena>> {
547-
let pos = match self.elim_context().force(r#ref).inner.as_ref() {
547+
let pos = match self.elim_context().force(r#ref).as_ref() {
548548
Value::ConstLit(Const::Ref(pos)) => *pos,
549549
_ => return Err(ReadError::InvalidValue(r#ref.span())),
550550
};

fathom/src/core/semantics.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -453,13 +453,13 @@ macro_rules! step {
453453
// TODO: Should we merge the spans of the input idents to produce the output span?
454454
macro_rules! const_step {
455455
([$($input:ident : $Input:ident),*] => $output:expr) => {
456-
step!(_, [$($input),*] => match ($($input.inner.as_ref(),)*) {
456+
step!(_, [$($input),*] => match ($($input.as_ref(),)*) {
457457
($(Value::ConstLit(Const::$Input($input, ..)),)*) => Spanned::empty(Arc::new(Value::ConstLit($output))),
458458
_ => return None,
459459
})
460460
};
461461
([$($input:ident , $style:ident : $Input:ident),*] => $output:expr) => {
462-
step!(_, [$($input),*] => match ($($input.inner.as_ref(),)*) {
462+
step!(_, [$($input),*] => match ($($input.as_ref(),)*) {
463463
($(Value::ConstLit(Const::$Input($input, $style)),)*) => Spanned::empty(Arc::new(Value::ConstLit($output))),
464464
_ => return None,
465465
})
@@ -617,10 +617,10 @@ fn prim_step(prim: Prim) -> Option<PrimStep> {
617617
}),
618618

619619
Prim::Array8Find | Prim::Array16Find | Prim::Array32Find | Prim::Array64Find => {
620-
step!(context, [_, _, pred, array] => match array.inner.as_ref() {
620+
step!(context, [_, _, pred, array] => match array.as_ref() {
621621
Value::ArrayLit(elems) => {
622622
for elem in elems {
623-
match context.fun_app(pred.clone(), elem.clone()).inner.as_ref() {
623+
match context.fun_app(pred.clone(), elem.clone()).as_ref() {
624624
Value::ConstLit(Const::Bool(true)) => {
625625
// TODO: Is elem.span right here?
626626
return Some(Spanned{ span: elem.span(), inner: Arc::new(Value::prim(Prim::OptionSome, [elem.clone()])) })
@@ -676,7 +676,7 @@ impl<'arena, 'env> ElimContext<'arena, 'env> {
676676
pub fn force(&self, value: &ArcValue<'arena>) -> ArcValue<'arena> {
677677
let mut forced_value = value.clone();
678678
// Attempt to force flexible values until we don't see any more.
679-
while let Value::Stuck(Head::FlexibleVar(var), spine) = forced_value.inner.as_ref() {
679+
while let Value::Stuck(Head::FlexibleVar(var), spine) = forced_value.as_ref() {
680680
match self.flexible_exprs.get_global(*var) {
681681
// Apply the spine to the solution. This might uncover another
682682
// flexible value so we'll continue looping.
@@ -841,7 +841,7 @@ impl<'arena, 'env> ElimContext<'arena, 'env> {
841841

842842
/// Find the representation type of a format description.
843843
pub fn format_repr(&self, format: &ArcValue<'arena>) -> ArcValue<'arena> {
844-
match format.inner.as_ref() {
844+
match format.as_ref() {
845845
Value::FormatRecord(labels, formats) | Value::FormatOverlap(labels, formats) => {
846846
Spanned {
847847
span: format.span(),
@@ -1044,7 +1044,7 @@ impl<'in_arena, 'out_arena, 'env> QuoteContext<'in_arena, 'out_arena, 'env> {
10441044
pub fn quote(&mut self, value: &ArcValue<'in_arena>) -> Term<'out_arena> {
10451045
let value = self.elim_context().force(value);
10461046
let span = value.span();
1047-
match value.inner.as_ref() {
1047+
match value.as_ref() {
10481048
Value::Stuck(head, spine) => {
10491049
let head_expr = match head {
10501050
Head::Prim(prim) => Term::Prim(span, *prim),
@@ -1241,7 +1241,7 @@ impl<'arena, 'env> ConversionContext<'arena, 'env> {
12411241
let value0 = self.elim_context().force(value0);
12421242
let value1 = self.elim_context().force(value1);
12431243

1244-
match (value0.inner.as_ref(), value1.inner.as_ref()) {
1244+
match (value0.as_ref(), value1.as_ref()) {
12451245
// `ReportedError`s result from errors that have already been
12461246
// reported, so we prevent them from triggering more errors.
12471247
(Value::Stuck(Head::Prim(Prim::ReportedError), _), _)

fathom/src/source.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ impl<T> Spanned<T> {
3636
}
3737
}
3838

39+
impl<T> Deref for Spanned<T> {
40+
type Target = T;
41+
42+
fn deref(&self) -> &Self::Target {
43+
&self.inner
44+
}
45+
}
46+
3947
#[derive(Debug, Copy, Clone)]
4048
pub enum Span {
4149
Range(ByteRange),

fathom/src/surface/elaboration.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,7 +1375,7 @@ impl<'interner, 'arena, 'error> Context<'interner, 'arena, 'error> {
13751375
) -> core::Term<'arena> {
13761376
let expected_type = self.elim_context().force(expected_type);
13771377

1378-
match (surface_term, expected_type.inner.as_ref()) {
1378+
match (surface_term, expected_type.as_ref()) {
13791379
(Term::Let(range, def_pattern, def_type, def_expr, output_expr), _) => {
13801380
let (def_pattern, def_type_value) = self.synth_ann_pattern(def_pattern, *def_type);
13811381
let def_type = self.quote_context(self.scope).quote(&def_type_value); // FIXME: avoid requote if possible?
@@ -1486,7 +1486,7 @@ impl<'interner, 'arena, 'error> Context<'interner, 'arena, 'error> {
14861486
}
14871487
};
14881488

1489-
let len = match len_value.map(|val| (val.span(), val.inner.as_ref())) {
1489+
let len = match len_value.map(|val| (val.span(), val.as_ref())) {
14901490
None => Some(elem_exprs.len() as u64),
14911491
Some((_, Value::ConstLit(Const::U8(len, _)))) => Some(*len as u64),
14921492
Some((_, Value::ConstLit(Const::U16(len, _)))) => Some(*len as u64),
@@ -1766,7 +1766,7 @@ impl<'interner, 'arena, 'error> Context<'interner, 'arena, 'error> {
17661766

17671767
// Ensure that the head type is a function type
17681768
let head_type = self.elim_context().force(&head_type);
1769-
let (head_expr, input_type, output_type) = match head_type.inner.as_ref() {
1769+
let (head_expr, input_type, output_type) = match head_type.as_ref() {
17701770
// The simple case - it's easy to see that it is a function type!
17711771
Value::FunType(_, input_type, output_type) => {
17721772
(head_expr, input_type.clone(), output_type.clone())
@@ -1879,7 +1879,7 @@ impl<'interner, 'arena, 'error> Context<'interner, 'arena, 'error> {
18791879
let head_expr_value = self.eval_context().eval(&head_expr);
18801880

18811881
let head_type = self.elim_context().force(&head_type);
1882-
match head_type.inner.as_ref() {
1882+
match head_type.as_ref() {
18831883
Value::RecordType(labels, types) => {
18841884
let mut labels = labels.iter();
18851885
let mut types = types.clone();

fathom/src/surface/elaboration/unification.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ impl<'arena, 'env> Context<'arena, 'env> {
203203
let value0 = self.elim_context().force(value0);
204204
let value1 = self.elim_context().force(value1);
205205

206-
match (value0.inner.as_ref(), value1.inner.as_ref()) {
206+
match (value0.as_ref(), value1.as_ref()) {
207207
// `ReportedError`s result from errors that have already been
208208
// reported, so we prevent them from triggering more errors.
209209
(Value::Stuck(Head::Prim(Prim::ReportedError), _), _)
@@ -455,16 +455,14 @@ impl<'arena, 'env> Context<'arena, 'env> {
455455

456456
for elim in spine {
457457
match elim {
458-
Elim::FunApp(input_expr) => {
459-
match self.elim_context().force(input_expr).inner.as_ref() {
460-
Value::Stuck(Head::RigidVar(source_var), spine)
461-
if spine.is_empty() && self.renaming.set_rigid(*source_var) => {}
462-
Value::Stuck(Head::RigidVar(source_var), _) => {
463-
return Err(SpineError::NonLinearSpine(*source_var))
464-
}
465-
_ => return Err(SpineError::NonRigidFunApp),
458+
Elim::FunApp(input_expr) => match self.elim_context().force(input_expr).as_ref() {
459+
Value::Stuck(Head::RigidVar(source_var), spine)
460+
if spine.is_empty() && self.renaming.set_rigid(*source_var) => {}
461+
Value::Stuck(Head::RigidVar(source_var), _) => {
462+
return Err(SpineError::NonLinearSpine(*source_var))
466463
}
467-
}
464+
_ => return Err(SpineError::NonRigidFunApp),
465+
},
468466
Elim::RecordProj(label) => return Err(SpineError::RecordProj(*label)),
469467
Elim::ConstMatch(_) => return Err(SpineError::ConstMatch),
470468
}
@@ -499,7 +497,7 @@ impl<'arena, 'env> Context<'arena, 'env> {
499497
) -> Result<Term<'arena>, RenameError> {
500498
let val = self.elim_context().force(value);
501499
let span = val.span();
502-
match val.inner.as_ref() {
500+
match val.as_ref() {
503501
Value::Stuck(head, spine) => {
504502
let head_expr = match head {
505503
Head::Prim(prim) => Term::Prim(span, *prim),

0 commit comments

Comments
 (0)