Skip to content

Commit f27e1c2

Browse files
committed
Swap HashData to use a SlotMap internally, uncapping max hashed items
1 parent 38a04f2 commit f27e1c2

13 files changed

Lines changed: 316 additions & 426 deletions

File tree

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/engine_bibtex/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ edition = "2021"
2121

2222
[dependencies]
2323
libc = "^0.2"
24+
slotmap = "1.0"
2425
tectonic_io_base = { path = "../io_base", version = '0.0.0-dev.0' }
2526
tectonic_bridge_core = { path = "../bridge_core", version = "0.0.0-dev.0" }
2627
tectonic_errors = { path = "../errors", version = "0.0.0-dev.0" }

crates/engine_bibtex/src/auxi.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use crate::{
1919
};
2020
use std::ffi::CString;
2121
use tectonic_bridge_core::FileFormat;
22+
use crate::hash::HashPointer;
2223

2324
const AUX_STACK_SIZE: usize = 20;
2425

@@ -105,7 +106,7 @@ fn aux_bib_data_command(
105106

106107
let file = &buffers.buffer(BufTy::Base)
107108
[buffers.offset(BufTy::Base, 1)..buffers.offset(BufTy::Base, 2)];
108-
let res = hash.lookup_str_insert(ctx, pool, file, HashExtra::BibFile)?;
109+
let res = hash.lookup_str_insert(pool, file, HashExtra::BibFile);
109110
if res.exists {
110111
ctx.write_logs("This database file appears more than once: ");
111112
print_bib_name(ctx, pool, hash.text(res.loc))?;
@@ -176,7 +177,7 @@ fn aux_bib_style_command(
176177

177178
let file = &buffers.buffer(BufTy::Base)
178179
[buffers.offset(BufTy::Base, 1)..buffers.offset(BufTy::Base, 2)];
179-
let res = hash.lookup_str_insert(ctx, pool, file, HashExtra::BstFile)?;
180+
let res = hash.lookup_str_insert(pool, file, HashExtra::BstFile);
180181
if res.exists {
181182
ctx.write_logs("Already encountered style file");
182183
print_confusion(ctx);
@@ -276,17 +277,17 @@ fn aux_citation_command(
276277
let lc_cite = &mut buffers.buffer_mut(BufTy::Ex)[range];
277278
lc_cite.make_ascii_lowercase();
278279

279-
let lc_res = hash.lookup_str_insert(ctx, pool, lc_cite, HashExtra::LcCite(0))?;
280+
let lc_res = hash.lookup_str_insert(pool, lc_cite, HashExtra::LcCite(HashPointer::default()));
280281
if lc_res.exists {
281-
let HashExtra::LcCite(cite_loc) = hash.node(lc_res.loc).extra else {
282+
let &HashExtra::LcCite(cite_loc) = hash.node(lc_res.loc).extra() else {
282283
panic!("LcCite lookup didn't have LcCite extra");
283284
};
284285

285286
let cite = &buffers.buffer(BufTy::Base)
286287
[buffers.offset(BufTy::Base, 1)..buffers.offset(BufTy::Base, 2)];
287288
let uc_res = hash.lookup_str(pool, cite, StrIlk::Cite);
288289
if uc_res.is_none() {
289-
let HashExtra::Cite(cite) = hash.node(cite_loc).extra else {
290+
let &HashExtra::Cite(cite) = hash.node(cite_loc).extra() else {
290291
panic!("LcCite location didn't have a Cite extra");
291292
};
292293

@@ -301,7 +302,7 @@ fn aux_citation_command(
301302
} else {
302303
let cite = &buffers.buffer(BufTy::Base)
303304
[buffers.offset(BufTy::Base, 1)..buffers.offset(BufTy::Base, 2)];
304-
let uc_res = hash.lookup_str_insert(ctx, pool, cite, HashExtra::Cite(0))?;
305+
let uc_res = hash.lookup_str_insert(pool, cite, HashExtra::Cite(0));
305306
if uc_res.exists {
306307
hash_cite_confusion(ctx);
307308
return Err(BibtexError::Fatal);
@@ -312,8 +313,8 @@ fn aux_citation_command(
312313
}
313314

314315
cites.set_cite(cites.ptr(), hash.text(uc_res.loc));
315-
hash.node_mut(uc_res.loc).extra = HashExtra::Cite(cites.ptr());
316-
hash.node_mut(lc_res.loc).extra = HashExtra::LcCite(uc_res.loc);
316+
*hash.node_mut(uc_res.loc).extra_mut() = HashExtra::Cite(cites.ptr());
317+
*hash.node_mut(lc_res.loc).extra_mut() = HashExtra::LcCite(uc_res.loc);
317318
cites.set_ptr(cites.ptr() + 1);
318319
}
319320
}
@@ -375,7 +376,7 @@ fn aux_input_command(
375376

376377
let file = &buffers.buffer(BufTy::Base)
377378
[buffers.offset(BufTy::Base, 1)..buffers.offset(BufTy::Base, 2)];
378-
let res = hash.lookup_str_insert(ctx, pool, file, HashExtra::AuxFile)?;
379+
let res = hash.lookup_str_insert(pool, file, HashExtra::AuxFile);
379380
if res.exists {
380381
ctx.write_logs("Already encountered file ");
381382
print_aux_name(ctx, pool, hash.text(res.loc))?;
@@ -425,7 +426,7 @@ pub(crate) fn get_aux_command_and_process(
425426
.lookup_str(globals.pool, line, StrIlk::AuxCommand);
426427

427428
if let Some(loc) = res {
428-
let HashExtra::AuxCommand(cmd) = globals.hash.node(loc).extra else {
429+
let &HashExtra::AuxCommand(cmd) = globals.hash.node(loc).extra() else {
429430
panic!("AuxCommand lookup didn't have AuxCommand extra");
430431
};
431432

crates/engine_bibtex/src/bibs.rs

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use slotmap::Key;
12
use crate::{
23
buffer::{BufTy, GlobalBuffer},
34
char_info::LexClass,
@@ -194,10 +195,10 @@ pub(crate) fn get_bib_command_or_entry_and_process(
194195
.hash
195196
.lookup_str(globals.pool, bib_cmd, StrIlk::BibCommand);
196197

197-
let mut lc_cite_loc = 0;
198+
let mut lc_cite_loc = HashPointer::default();
198199

199200
if let Some(loc) = res {
200-
let HashExtra::BibCommand(cmd) = globals.hash.node(loc).extra else {
201+
let &HashExtra::BibCommand(cmd) = globals.hash.node(loc).extra() else {
201202
panic!("BibCommand lookup didn't have BibCommand extra");
202203
};
203204

@@ -352,13 +353,12 @@ pub(crate) fn get_bib_command_or_entry_and_process(
352353

353354
// let text = globals.hash.text(res.loc);
354355
let res = globals.hash.lookup_str_insert(
355-
ctx,
356356
globals.pool,
357357
bib_macro,
358358
HashExtra::Macro(StrNumber::default()),
359-
)?;
359+
);
360360
// TODO: Insert overwriting?
361-
globals.hash.node_mut(res.loc).extra = HashExtra::Macro(globals.hash.text(res.loc));
361+
*globals.hash.node_mut(res.loc).extra_mut() = HashExtra::Macro(globals.hash.text(res.loc));
362362
*cur_macro_loc = res.loc;
363363

364364
if !eat_bib_white_space(ctx, globals.buffers, globals.bibs) {
@@ -444,7 +444,7 @@ pub(crate) fn get_bib_command_or_entry_and_process(
444444
.lookup_str(globals.pool, bst_fn, StrIlk::BstFn)
445445
.filter(|&loc| {
446446
matches!(
447-
globals.hash.node(loc).extra,
447+
globals.hash.node(loc).extra(),
448448
HashExtra::BstFn(BstFn::Wizard(_))
449449
)
450450
});
@@ -515,14 +515,14 @@ pub(crate) fn get_bib_command_or_entry_and_process(
515515
let lc_res = if ctx.all_entries {
516516
globals
517517
.hash
518-
.lookup_str_insert(ctx, globals.pool, lc_cite, HashExtra::LcCite(0))?
518+
.lookup_str_insert(globals.pool, lc_cite, HashExtra::LcCite(HashPointer::default()))
519519
} else {
520520
globals
521521
.hash
522522
.lookup_str(globals.pool, lc_cite, StrIlk::LcCite)
523523
.map_or(
524524
LookupRes {
525-
loc: usize::MAX,
525+
loc: HashPointer::default(),
526526
exists: false,
527527
},
528528
|loc| LookupRes { loc, exists: true },
@@ -534,10 +534,10 @@ pub(crate) fn get_bib_command_or_entry_and_process(
534534
// TODO: Improve this tangled control flow
535535
let mut inner = || {
536536
if lc_res.exists {
537-
let HashExtra::LcCite(cite_loc) = globals.hash.node(lc_res.loc).extra else {
537+
let &HashExtra::LcCite(cite_loc) = globals.hash.node(lc_res.loc).extra() else {
538538
panic!("LcCite lookup didn't have LcCite extra");
539539
};
540-
let HashExtra::Cite(cite) = globals.hash.node(cite_loc).extra else {
540+
let &HashExtra::Cite(cite) = globals.hash.node(cite_loc).extra() else {
541541
panic!("LcCite location didn't have Cite extra");
542542
};
543543

@@ -547,28 +547,22 @@ pub(crate) fn get_bib_command_or_entry_and_process(
547547
|| entry_ptr < globals.cites.all_marker()
548548
|| entry_ptr > globals.cites.old_num_cites()
549549
{
550-
if globals.cites.get_type(entry_ptr) == 0 {
550+
if globals.cites.get_type(entry_ptr).is_null() {
551551
if !ctx.all_entries && entry_ptr >= globals.cites.old_num_cites() {
552552
let range = globals.buffers.offset(BufTy::Base, 1)
553553
..globals.buffers.offset(BufTy::Base, 2);
554554
let cite = &globals.buffers.buffer(BufTy::Base)[range];
555555
let uc_res = globals.hash.lookup_str_insert(
556-
ctx,
557556
globals.pool,
558557
cite,
559558
HashExtra::Cite(0),
560559
);
561560

562-
let uc_res = match uc_res {
563-
Ok(res) => res,
564-
Err(e) => return Some(Err(e)),
565-
};
566-
567561
res = uc_res;
568562

569563
if !uc_res.exists {
570-
globals.hash.node_mut(lc_res.loc).extra = HashExtra::LcCite(uc_res.loc);
571-
globals.hash.node_mut(uc_res.loc).extra = HashExtra::Cite(entry_ptr);
564+
*globals.hash.node_mut(lc_res.loc).extra_mut() = HashExtra::LcCite(uc_res.loc);
565+
*globals.hash.node_mut(uc_res.loc).extra_mut() = HashExtra::Cite(entry_ptr);
572566
globals
573567
.cites
574568
.set_cite(entry_ptr, globals.hash.text(uc_res.loc));
@@ -588,7 +582,7 @@ pub(crate) fn get_bib_command_or_entry_and_process(
588582
.lookup_str(globals.pool, lc_cite, StrIlk::LcCite)
589583
.map_or(
590584
LookupRes {
591-
loc: usize::MAX,
585+
loc: HashPointer::default(),
592586
exists: false,
593587
},
594588
|loc| LookupRes { loc, exists: true },
@@ -605,7 +599,7 @@ pub(crate) fn get_bib_command_or_entry_and_process(
605599
}
606600
}
607601

608-
if globals.cites.get_type(entry_ptr) == 0 {
602+
if globals.cites.get_type(entry_ptr).is_null() {
609603
ctx.write_logs("The cite list is messed up");
610604
print_confusion(ctx);
611605
return Some(Err(BibtexError::Fatal));
@@ -631,7 +625,7 @@ pub(crate) fn get_bib_command_or_entry_and_process(
631625
if res.exists {
632626
if globals.cites.entry_ptr() >= globals.cites.all_marker() {
633627
globals.cites.set_exists(globals.cites.entry_ptr(), true);
634-
let HashExtra::LcCite(cite_loc) = globals.hash.node(lc_res.loc).extra else {
628+
let &HashExtra::LcCite(cite_loc) = globals.hash.node(lc_res.loc).extra() else {
635629
panic!("LcCite lookup didn't have LcCite extra");
636630
};
637631
globals.cites.set_entry_ptr(globals.cites.ptr());
@@ -651,7 +645,7 @@ pub(crate) fn get_bib_command_or_entry_and_process(
651645
let res =
652646
globals
653647
.hash
654-
.lookup_str_insert(ctx, globals.pool, cite, HashExtra::Cite(0))?;
648+
.lookup_str_insert(globals.pool, cite, HashExtra::Cite(0));
655649
if res.exists {
656650
hash_cite_confusion(ctx);
657651
return Err(BibtexError::Fatal);
@@ -747,7 +741,7 @@ pub(crate) fn get_bib_command_or_entry_and_process(
747741
}
748742
}
749743

750-
*field_name_loc = 0;
744+
*field_name_loc = HashPointer::default();
751745
let mut store_field = false;
752746
if store_entry {
753747
let range =
@@ -760,7 +754,7 @@ pub(crate) fn get_bib_command_or_entry_and_process(
760754
match res {
761755
Some(loc)
762756
if matches!(
763-
globals.hash.node(loc).extra,
757+
globals.hash.node(loc).extra(),
764758
HashExtra::BstFn(BstFn::Field(_))
765759
) =>
766760
{

0 commit comments

Comments
 (0)