Skip to content

Commit

Permalink
change last Int's to Offset that need changing
Browse files Browse the repository at this point in the history
fix comparison
fix errors previously uncaught by the compiler
  • Loading branch information
essickmango committed Nov 11, 2023
1 parent 06f70f2 commit 2a47260
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
4 changes: 2 additions & 2 deletions spec/lang/representation.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ fn compute_discriminant<M: Memory>(bytes: List<AbstractByte<M::Provenance>>, 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::<M>(bytes, next_discriminator)
Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 2 additions & 4 deletions spec/lang/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<Int, u8>,
pub tagger: Map<Offset, u8>,
}

/// The decision tree that computes the discriminant out of the tag for a specific
Expand All @@ -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<u8, Discriminator>,
Expand Down
2 changes: 1 addition & 1 deletion spec/lang/well-formed.md
Original file line number Diff line number Diff line change
Expand Up @@ -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::<T>(size, n_variants)?;
for discriminator in children.values() {
discriminator.check_wf::<T>(size, n_variants)?;
Expand Down

0 comments on commit 2a47260

Please sign in to comment.