From 2a47260d5ae54e86d07788ead25bcf76232454a6 Mon Sep 17 00:00:00 2001 From: Timon Meyer Date: Sat, 4 Nov 2023 11:36:40 +0100 Subject: [PATCH] change last Int's to Offset that need changing fix comparison fix errors previously uncaught by the compiler --- spec/lang/representation.md | 4 ++-- spec/lang/types.md | 6 ++---- spec/lang/well-formed.md | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/spec/lang/representation.md b/spec/lang/representation.md index bba0dcfb..72b8182d 100644 --- a/spec/lang/representation.md +++ b/spec/lang/representation.md @@ -243,7 +243,7 @@ fn compute_discriminant(bytes: List>, dis Discriminator::Known(val) => Some(val), Discriminator::Invalid => None, Discriminator::Unknown { offset, children, fallback } => { - let AbstractByte::Init(val, _) = bytes[offset] + let AbstractByte::Init(val, _) = bytes[offset.bytes()] else { return None }; let next_discriminator = children.get(val).unwrap_or(fallback); compute_discriminant::(bytes, next_discriminator) @@ -274,7 +274,7 @@ impl Type { // write tag afterwards into the encoded bytes. This is fine as we don't allow // encoded data and the tag to overlap at the moment. for (offset, value) in tagger.iter() { - bytes.set(offset, AbstractByte::Init(value, None)); + bytes.set(offset.bytes(), AbstractByte::Init(value, None)); } bytes } diff --git a/spec/lang/types.md b/spec/lang/types.md index 24bb5a74..1f55d28b 100644 --- a/spec/lang/types.md +++ b/spec/lang/types.md @@ -87,8 +87,7 @@ pub struct Variant { /// MUST NOT touch any bytes written by the actual type of the variant and vice /// versa. This is because we allow references/pointers to (enum) fields which /// should be able to dereference without having to deal with the tag. - /// FIXME(essickmango): Int should be `Offset` - pub tagger: Map, + pub tagger: Map, } /// The decision tree that computes the discriminant out of the tag for a specific @@ -101,9 +100,8 @@ pub enum Discriminator { /// We don't know the discriminant, so we branch on the value of a specific byte. /// The fallback is for readability, as we often are only interested in a couple /// of values. - /// FIXME(essickmango): change offset to `Offset` Unknown { - offset: Int, + offset: Offset, #[specr::indirection] fallback: Discriminator, children: Map, diff --git a/spec/lang/well-formed.md b/spec/lang/well-formed.md index 7eeea30a..cbfa6366 100644 --- a/spec/lang/well-formed.md +++ b/spec/lang/well-formed.md @@ -132,7 +132,7 @@ impl Discriminator { Discriminator::Known(variant) => ensure(variant >= Int::ZERO && variant < n_variants), Discriminator::Invalid => ret(()), Discriminator::Unknown { offset, fallback, children } => { - ensure(offset < size.bytes())?; + ensure(offset < size)?; fallback.check_wf::(size, n_variants)?; for discriminator in children.values() { discriminator.check_wf::(size, n_variants)?;