Skip to content

Commit 3960a94

Browse files
authored
Merge pull request #499 from Kmeakin/usize-vars
Use `usize` instead of `u16` for vars
2 parents a2d6790 + 19529ff commit 3960a94

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

fathom/src/env.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
use std::fmt;
2121

2222
/// Underlying variable representation.
23-
type RawVar = u16;
23+
type RawVar = usize;
2424

2525
/// A [de Bruijn index], which represents a variable counting the number of
2626
/// binders between a variable occurrence and the binder that introduced the
@@ -52,7 +52,7 @@ impl Index {
5252

5353
/// Returns the previously bound variable, relative to this one.
5454
pub const fn prev(self) -> Index {
55-
Index(self.0 + 1) // FIXME: check overflow?
55+
Index(self.0 + 1)
5656
}
5757
}
5858

@@ -99,7 +99,7 @@ impl Level {
9999

100100
/// Returns the next bound variable, relative to this one.
101101
pub const fn next(self) -> Level {
102-
Level(self.0 + 1) // FIXME: check overflow?
102+
Level(self.0 + 1)
103103
}
104104
}
105105

@@ -154,12 +154,12 @@ impl EnvLen {
154154

155155
/// Push an entry onto the environment.
156156
pub fn push(&mut self) {
157-
self.0 += 1; // FIXME: check overflow?
157+
self.0 += 1;
158158
}
159159

160160
/// Pop an entry off the environment.
161161
pub fn pop(&mut self) {
162-
self.0 -= 1; // FIXME: check underflow?
162+
self.0 -= 1;
163163
}
164164

165165
/// Truncate the environment to the given length.
@@ -193,7 +193,7 @@ impl<Entry> UniqueEnv<Entry> {
193193
where
194194
Entry: Clone,
195195
{
196-
self.entries.resize(usize::from(new_len.0), entry)
196+
self.entries.resize(new_len.0, entry)
197197
}
198198

199199
/// Push an entry onto the environment.
@@ -209,7 +209,7 @@ impl<Entry> UniqueEnv<Entry> {
209209

210210
/// Truncate the environment to the given length.
211211
pub fn truncate(&mut self, len: EnvLen) {
212-
self.entries.truncate(len.0 as usize);
212+
self.entries.truncate(len.0);
213213
}
214214

215215
pub fn reserve(&mut self, additional: usize) {
@@ -249,7 +249,7 @@ impl<Entry> SliceEnv<Entry> {
249249

250250
/// Lookup an entry in the environment using a level
251251
pub fn get_level(&self, level: Level) -> Option<&Entry> {
252-
self.entries.get(usize::from(level.0))
252+
self.entries.get(level.0)
253253
}
254254

255255
/// Lookup an entry in the environment using an index
@@ -259,7 +259,7 @@ impl<Entry> SliceEnv<Entry> {
259259

260260
/// Set an entry in the environment using a level
261261
pub fn set_level(&mut self, level: Level, entry: Entry) {
262-
self.entries[usize::from(level.0)] = entry;
262+
self.entries[level.0] = entry;
263263
}
264264

265265
/// Iterate over the elements in the environment.
@@ -329,7 +329,7 @@ impl<Entry> SharedEnv<Entry> {
329329

330330
/// Lookup an entry in the environment using a level
331331
pub fn get_level(&self, level: Level) -> Option<&Entry> {
332-
self.entries.get(usize::from(level.0))
332+
self.entries.get(level.0)
333333
}
334334

335335
/// Lookup an entry in the environment using an index
@@ -339,7 +339,6 @@ impl<Entry> SharedEnv<Entry> {
339339

340340
/// Push an entry onto the environment.
341341
pub fn push(&mut self, entry: Entry) {
342-
assert!(self.entries.len() < usize::from(u16::MAX));
343342
self.entries.push_back_mut(entry);
344343
}
345344

0 commit comments

Comments
 (0)