Skip to content

Commit 2c4177f

Browse files
authored
Turn lsh into a standalone crate (#958)
* Remove `stdext` from `lsh` This required a huge change from raw pointers for graphs to vecs and indices. To make it less ugly (due to borrowing), I refactored the data common between frontend and backend into `ir.rs`. * Move `lsh-bin` into `lsh` as its main binary The assembly output remains unmodified (as is the overall approach). The Rust output lost its mermaid diagrams, because they were in the way and outlived their usefulness anyway (they are too large).
1 parent f6ae615 commit 2c4177f

26 files changed

Lines changed: 1093 additions & 1265 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ jobs:
4444
- name: Install Rust
4545
run: rustup toolchain install nightly --no-self-update --profile minimal --component rust-src,rustfmt,clippy
4646
- name: Check formatting
47-
run: cargo fmt --all -- --check
47+
run: cargo +nightly fmt --all -- --check
4848
- name: Run tests
49-
run: cargo test --all-features --all-targets
49+
run: cargo +nightly test --all-features --all-targets
5050
- name: Run clippy
51-
run: cargo clippy --workspace --all-features --all-targets -- --no-deps --deny warnings
51+
run: cargo +nightly clippy --workspace --all-features --all-targets -- --no-deps --deny warnings

‎Cargo.lock‎

Lines changed: 1 addition & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,3 @@ incremental = true # Improves re-compile times
2525
[profile.bench]
2626
codegen-units = 16 # Make compiling criterion faster (16 is the default, but profile.release sets it to 1)
2727
lto = "thin" # Similarly, speed up linking by a ton
28-
29-
[workspace.dependencies]
30-
edit = { path = "./crates/edit" }
31-
lsh = { path = "./crates/lsh" }
32-
stdext = { path = "./crates/stdext" }
33-
unicode-gen = { path = "./crates/unicode-gen" }

‎crates/README.md‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@ This directory contains the crates that make up Edit and its supporting tooling.
55
* `edit`: Main editor binary and library<br>
66
It is split apart into a library to allow for benchmarks.
77
* `lsh`: Syntax-highlighting compiler and runtime
8-
* `lsh-bin`: A small CLI for experimenting with and debugging LSH output
98
* `stdext`: Shared utility code used across the workspace
109
* `unicode-gen`: Code generation utilities for Unicode LUTs

‎crates/edit/Cargo.toml‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[package]
22
name = "edit"
3+
description = "A simple editor for simple needs."
34
version = "2.0.0"
45

56
edition.workspace = true
@@ -19,15 +20,14 @@ harness = false
1920
debug-latency = []
2021

2122
[dependencies]
22-
lsh.workspace = true
23-
stdext.workspace = true
23+
lsh = { path = "../lsh", default-features = false, features = ["compiler", "glob"] }
24+
stdext = { path = "../stdext" }
2425

2526
[target.'cfg(unix)'.dependencies]
2627
libc = "0.2"
2728

2829
[build-dependencies]
29-
stdext.workspace = true
30-
lsh.workspace = true
30+
lsh = { path = "../lsh", default-features = false, features = ["compiler", "glob"] }
3131
# The default toml crate bundles its dependencies with bad compile times. Thanks.
3232
# Thankfully toml-span exists. FWIW the alternative is yaml-rust (without the 2 suffix).
3333
toml-span = { version = "0.7", default-features = false }

‎crates/edit/benches/lib.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ use std::io::Cursor;
66
use std::path::Path;
77
use std::{mem, vec};
88

9+
use ::lsh::glob;
910
use criterion::{BenchmarkId, Criterion, Throughput, criterion_group, criterion_main};
1011
use edit::helpers::*;
1112
use edit::{buffer, hash, json, lsh, oklab, simd, unicode};
1213
use stdext::arena::{self, scratch_arena};
1314
use stdext::collections::BVec;
1415
use stdext::float::parse_f64_approx;
15-
use stdext::glob;
1616
use stdext::unicode::Utf8Chars;
1717

1818
struct EditingTracePatch<'a>(usize, usize, &'a str);

‎crates/edit/build/main.rs‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
#![allow(irrefutable_let_patterns)]
55

6-
use stdext::arena::scratch_arena;
7-
86
use crate::helpers::env_opt;
97

108
mod helpers;
@@ -18,8 +16,6 @@ enum TargetOs {
1816
}
1917

2018
fn main() {
21-
stdext::arena::init(128 * 1024 * 1024).unwrap();
22-
2319
let target_os = match env_opt("CARGO_CFG_TARGET_OS").as_str() {
2420
"windows" => TargetOs::Windows,
2521
"macos" | "ios" => TargetOs::MacOS,
@@ -34,13 +30,11 @@ fn main() {
3430
}
3531

3632
fn compile_lsh() {
37-
let scratch = scratch_arena(None);
38-
3933
let lsh_path = lsh::compiler::builtin_definitions_path();
4034
let out_dir = env_opt("OUT_DIR");
4135
let out_path = format!("{out_dir}/lsh_definitions.rs");
4236

43-
let mut generator = lsh::compiler::Generator::new(&scratch);
37+
let mut generator = lsh::compiler::Generator::new();
4438
match generator.read_directory(lsh_path).and_then(|_| generator.generate_rust()) {
4539
Ok(c) => std::fs::write(out_path, c).unwrap(),
4640
Err(err) => {

‎crates/edit/src/lsh/highlighter.rs‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ use crate::{simd, unicode};
1212

1313
const MAX_LINE_LEN: usize = 32 * KIBI;
1414

15+
struct VecWithAlloc<'a, 'b, T> {
16+
arena: &'a Arena,
17+
vec: &'b mut BVec<'a, T>,
18+
}
19+
20+
impl<'a, 'b, T> ExtendOne<T> for VecWithAlloc<'a, 'b, T> {
21+
fn extend_one(&mut self, value: T) {
22+
self.vec.push(self.arena, value);
23+
}
24+
}
25+
1526
#[derive(Clone)]
1627
pub struct Highlighter<'a> {
1728
doc: &'a dyn ReadableDocument,
@@ -71,7 +82,8 @@ impl<'doc> Highlighter<'doc> {
7182
}
7283

7384
let line = unicode::strip_newline(line);
74-
let mut res = self.runtime.parse_next_line(arena, line);
85+
let mut res: BVec<'a, Highlight<HighlightKind>> = BVec::empty();
86+
self.runtime.parse_next_line(line, VecWithAlloc { arena, vec: &mut res });
7587

7688
// Adjust the range to account for the line offset.
7789
for h in res.iter_mut() {

‎crates/edit/src/lsh/mod.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use std::path::Path;
1111

1212
pub use definitions::{FILE_ASSOCIATIONS, HighlightKind, LANGUAGES};
1313
pub use highlighter::*;
14+
use lsh::glob::glob_match;
1415
pub use lsh::runtime::Language;
15-
use stdext::glob::glob_match;
1616

1717
pub fn process_file_associations<T>(
1818
associations: &[(T, &'static Language)],

‎crates/lsh-bin/Cargo.toml‎

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

0 commit comments

Comments
 (0)