Skip to content

Commit 2b3df5a

Browse files
dak2claude
andcommitted
Remove Buffer; store path instead of source text on Source
Ruby's RBS::Buffer exists because RBS::Location is lazy: it holds a reference to the buffer and slices out text on demand for #source and pos_to_loc. The Rust port mirrored that shape, but the architecture underneath it isn't lazy — AstConverter eagerly interns or copies every semantically relevant string (names, comments, annotations, literals) at conversion time, and LocationRange is a plain 4x u32 offset Copy type with no reference back into the source. There is no deferred slicing step left that would ever need the buffer, so nothing in the crate calls Buffer::content() after parse_one() returns — it's a write-only store. Keeping it anyway means holding the full text of every loaded file for the Environment's lifetime for no benefit: ~4.3MB across core + stdlib alone, more with gems, growing for as long as the Environment lives. Source.buffer: Buffer is replaced with Source.path: PathBuf, keeping just enough to identify the file for error reporting. parse_one() no longer moves `content` into a Buffer, so the explicit drop(signature) that used to be needed to end its borrow first is gone too. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent 0b70e05 commit 2b3df5a

5 files changed

Lines changed: 3 additions & 31 deletions

File tree

rust/ruby-rbs/src/buffer.rs

Lines changed: 0 additions & 22 deletions
This file was deleted.

rust/ruby-rbs/src/environment/source.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::path::PathBuf;
22

33
use crate::ast::{Declaration, Directive};
4-
use crate::buffer::Buffer;
54

65
/// Where a loaded signature file came from, corresponding to the `source`
76
/// values yielded by `RBS::EnvironmentLoader#each_dir`.
@@ -31,7 +30,7 @@ impl SourceKind {
3130
/// `RBS::Source::RBS` equivalent.
3231
#[derive(Debug)]
3332
pub struct Source {
34-
pub buffer: Buffer,
33+
pub path: PathBuf,
3534
pub directives: Vec<Directive>,
3635
pub declarations: Vec<Declaration>,
3736
pub kind: SourceKind,

rust/ruby-rbs/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
pub mod ast;
2-
pub mod buffer;
32
pub mod environment;
43
pub(crate) mod file_finder;
54
pub mod ids;

rust/ruby-rbs/src/loader/mod.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use std::io;
44
use std::path::{Path, PathBuf};
55

66
use crate::ast::AstConverter;
7-
use crate::buffer::Buffer;
87
use crate::environment::{Environment, Source, SourceKind};
98
use crate::file_finder;
109
use crate::interners::Interners;
@@ -175,12 +174,9 @@ pub(crate) fn parse_one(
175174
.iter()
176175
.map(|node| converter.convert_declaration(&node))
177176
.collect();
178-
// SignatureNode borrows `content` and has a Drop impl; drop it
179-
// explicitly before moving `content` into the Buffer.
180-
drop(signature);
181177

182178
Ok(Source {
183-
buffer: Buffer::new(path.to_path_buf(), content),
179+
path: path.to_path_buf(),
184180
directives,
185181
declarations,
186182
kind: kind.clone(),

rust/ruby-rbs/tests/loader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ fn loaded_sources_carry_converted_declarations_and_directives() {
120120
let env = Environment::from_loader(&loader).unwrap();
121121

122122
let source = &env.sources()[0];
123-
assert!(source.buffer.name().ends_with("person.rbs"));
123+
assert!(source.path.ends_with("person.rbs"));
124124
assert!(matches!(source.directives.as_slice(), [Directive::Use(_)]));
125125

126126
let [Declaration::Class(class)] = source.declarations.as_slice() else {

0 commit comments

Comments
 (0)