diff --git a/.cargo/config.toml b/.cargo/config.toml index c2eb6c5..ddb1253 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,4 +1,4 @@ [alias] xtask = "r -p xtask --" wasm-build = "b --target wasm32-unknown-unknown --profile=small -Zbuild-std=core,alloc -Zbuild-std-features=optimize_for_size,panic_immediate_abort -p" -wasm-build-debug = "b --target wasm32-unknown-unknown -p" +wasm-build-debug = "b --target wasm32-unknown-unknown --profile=small-dev -Zbuild-std=core,alloc -Zbuild-std-features=optimize_for_size -p" diff --git a/.gitignore b/.gitignore index cbe94b1..cc0d227 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,4 @@ /.rgignore rustc-ice-* db.sqlite -/depell/src/*.wasm +/depell/src/*.gz diff --git a/Cargo.lock b/Cargo.lock index 8b98e79..14c0d16 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "addr2line" @@ -407,9 +407,9 @@ checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "libc" -version = "0.2.158" +version = "0.2.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" +checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" [[package]] name = "libsqlite3-sys" @@ -528,9 +528,9 @@ checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" [[package]] name = "proc-macro2" -version = "1.0.86" +version = "1.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a" dependencies = [ "unicode-ident", ] @@ -547,7 +547,7 @@ dependencies = [ [[package]] name = "regalloc2" version = "0.10.2" -source = "git+https://github.com/jakubDoka/regalloc2?branch=reuse-allocations#4100af4e24bc2921c0931c901651a969c898f852" +source = "git+https://github.com/jakubDoka/regalloc2?branch=reuse-allocations#21c43e3ee182824e92e2b25f1d3c03ed47f9c02b" dependencies = [ "allocator-api2", "bumpalo", diff --git a/Cargo.toml b/Cargo.toml index 9280b96..ef76769 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,13 +29,16 @@ codegen-units = 1 panic = "abort" [profile.small] -#rustflags = ["-Zfmt-debug=none", "-Zlocation-detail=none"] +rustflags = ["-Zfmt-debug=none", "-Zlocation-detail=none"] inherits = "release" opt-level = "z" -strip = "debuginfo" -#strip = true +strip = true lto = true codegen-units = 1 panic = "abort" - +[profile.small-dev] +inherits = "dev" +opt-level = "z" +strip = "debuginfo" +panic = "abort" diff --git a/depell/Cargo.toml b/depell/Cargo.toml index 7931fa3..cc377b0 100644 --- a/depell/Cargo.toml +++ b/depell/Cargo.toml @@ -12,3 +12,6 @@ rusqlite = "0.32.1" serde = { version = "1.0.210", features = ["derive"] } time = "0.3.36" tokio = { version = "1.40.0", features = ["rt"] } + +[features] +gzip = [] diff --git a/depell/src/main.rs b/depell/src/main.rs index 2527438..1c5b198 100644 --- a/depell/src/main.rs +++ b/depell/src/main.rs @@ -22,7 +22,10 @@ macro_rules! static_asset { get(|| async { axum::http::Response::builder() .header("content-type", $mime) - .body(axum::body::Body::from(Bytes::from_static(include_bytes!($body)))) + .header("content-encoding", "gzip") + .body(axum::body::Body::from(Bytes::from_static(include_bytes!(concat!( + $body, ".gz" + ))))) .unwrap() }) }; @@ -42,20 +45,8 @@ async fn amain() { .route("/", get(Index::page)) .route("/index.css", static_asset!("text/css", "index.css")) .route("/index.js", static_asset!("text/javascript", "index.js")) - .route( - "/hbfmt.wasm", - static_asset!( - "application/wasm", - "../../target/wasm32-unknown-unknown/small/wasm_hbfmt.wasm" - ), - ) - .route( - "/hbc.wasm", - static_asset!( - "application/wasm", - "../../target/wasm32-unknown-unknown/small/wasm_hbc.wasm" - ), - ) + .route("/hbfmt.wasm", static_asset!("application/wasm", "hbfmt.wasm")) + .route("/hbc.wasm", static_asset!("application/wasm", "hbc.wasm")) .route("/index-view", get(Index::get)) .route("/feed", get(Index::page)) .route("/profile", get(Profile::page)) diff --git a/depell/wasm-hbc/Cargo.toml b/depell/wasm-hbc/Cargo.toml index 41bed0f..26cdf99 100644 --- a/depell/wasm-hbc/Cargo.toml +++ b/depell/wasm-hbc/Cargo.toml @@ -9,6 +9,6 @@ crate-type = ["cdylib"] [dependencies] hblang = { workspace = true, features = [] } hbvm.workspace = true -log = "0.4.22" +log = { version = "0.4.22", features = ["release_max_level_error"] } wasm-rt = { version = "0.1.0", path = "../wasm-rt", features = ["log"] } diff --git a/depell/wasm-rt/src/lib.rs b/depell/wasm-rt/src/lib.rs index 309c996..b698e73 100644 --- a/depell/wasm-rt/src/lib.rs +++ b/depell/wasm-rt/src/lib.rs @@ -1,4 +1,5 @@ #![feature(alloc_error_handler)] +#![feature(pointer_is_aligned_to)] #![feature(slice_take)] #![no_std] @@ -36,9 +37,9 @@ macro_rules! decl_runtime { unsafe { use core::fmt::Write; - let mut f = Write(&mut PANIC_MESSAGE[..]); + let mut f = $crate::Write(&mut PANIC_MESSAGE[..]); _ = writeln!(f, "{}", _info); - PANIC_MESSAGE_LEN = 1024 - f.0.len(); + PANIC_MESSAGE_LEN = $max_panic_size - f.0.len(); } } @@ -67,7 +68,7 @@ impl log::Log for Logger { fn log(&self, record: &log::Record) { if self.enabled(record.metadata()) { - const MAX_LOG_MESSAGE: usize = 1024 * 4; + const MAX_LOG_MESSAGE: usize = 1024 * 8; #[no_mangle] static mut LOG_MESSAGES: [u8; MAX_LOG_MESSAGE] = [0; MAX_LOG_MESSAGE]; #[no_mangle] @@ -115,7 +116,8 @@ unsafe impl GlobalAlloc for ArenaAllocator { let until = self.arena.get() as *mut u8; let new_head = (*self.head.get()).sub(size); - let aligned_head = (new_head as usize & !(1 << (align - 1))) as *mut u8; + let aligned_head = (new_head as usize & !(align - 1)) as *mut u8; + debug_assert!(aligned_head.is_aligned_to(align)); if until > aligned_head { return core::ptr::null_mut(); diff --git a/lang/src/codegen.rs b/lang/src/codegen.rs index 78f43b7..a037d42 100644 --- a/lang/src/codegen.rs +++ b/lang/src/codegen.rs @@ -294,7 +294,7 @@ enum LocCow<'a> { Owned(Loc), } -impl<'a> LocCow<'a> { +impl LocCow<'_> { fn as_ref(&self) -> &Loc { match self { Self::Ref(value) => value, @@ -309,7 +309,7 @@ impl<'a> From<&'a Loc> for LocCow<'a> { } } -impl<'a> From for LocCow<'a> { +impl From for LocCow<'_> { fn from(value: Loc) -> Self { Self::Owned(value) } diff --git a/lang/src/lib.rs b/lang/src/lib.rs index cd8aeba..10b39db 100644 --- a/lang/src/lib.rs +++ b/lang/src/lib.rs @@ -23,6 +23,7 @@ slice_from_ptr_range, is_sorted )] +#![feature(pointer_is_aligned_to)] #![warn(clippy::dbg_macro)] #![allow(stable_features, internal_features)] #![no_std] @@ -532,7 +533,7 @@ mod ty { } } - impl<'a> core::fmt::Display for Display<'a> { + impl core::fmt::Display for Display<'_> { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { use Kind as TK; match TK::from_ty(self.ty) { diff --git a/lang/src/parser.rs b/lang/src/parser.rs index ea0040f..df81b0c 100644 --- a/lang/src/parser.rs +++ b/lang/src/parser.rs @@ -818,7 +818,7 @@ generate_expr! { } } -impl<'a> Expr<'a> { +impl Expr<'_> { pub fn declares(&self, iden: Result) -> Option { match *self { Self::Ident { id, name, .. } if iden == Ok(id) || iden == Err(name) => Some(id), @@ -897,13 +897,13 @@ impl Poser for Pos { } } -impl<'a> Poser for Expr<'a> { +impl Poser for Expr<'_> { fn posi(&self) -> Pos { self.pos() } } -impl<'a, T: Poser> Poser for CommentOr<'a, T> { +impl Poser for CommentOr<'_, T> { fn posi(&self) -> Pos { match self { CommentOr::Or(expr) => expr.posi(), @@ -918,7 +918,7 @@ pub enum CommentOr<'a, T> { Comment { literal: &'a str, pos: Pos }, } -impl<'a, T: Copy> CommentOr<'a, T> { +impl CommentOr<'_, T> { pub fn or(&self) -> Option { match *self { CommentOr::Or(v) => Some(v), @@ -1175,7 +1175,7 @@ impl StackAlloc { } let dst = self.data.add(self.len) as *mut T; - debug_assert!(dst.is_aligned(),); + debug_assert!(dst.is_aligned()); self.len += core::mem::size_of::(); core::ptr::write(dst, value); } diff --git a/lang/src/son.rs b/lang/src/son.rs index 52eeebe..8ef7e3b 100644 --- a/lang/src/son.rs +++ b/lang/src/son.rs @@ -2556,7 +2556,7 @@ impl<'a> Function<'a> { } } -impl<'a> regalloc2::Function for Function<'a> { +impl regalloc2::Function for Function<'_> { fn num_insts(&self) -> usize { self.instrs.len() } diff --git a/lang/src/vc.rs b/lang/src/vc.rs index 94892ca..609c40c 100644 --- a/lang/src/vc.rs +++ b/lang/src/vc.rs @@ -272,7 +272,7 @@ impl BitSet { const ELEM_SIZE: usize = core::mem::size_of::() * 8; pub fn clear(&mut self, bit_size: usize) { - let new_len = (bit_size + Self::ELEM_SIZE - 1) / Self::ELEM_SIZE; + let new_len = bit_size.div_ceil(Self::ELEM_SIZE); self.data.clear(); self.data.resize(new_len, 0); } diff --git a/vm/src/mem/softpaging/mapping.rs b/vm/src/mem/softpaging/mapping.rs index 0bf9a38..972266c 100644 --- a/vm/src/mem/softpaging/mapping.rs +++ b/vm/src/mem/softpaging/mapping.rs @@ -10,7 +10,7 @@ use { alloc::boxed::Box, }; -impl<'p, A, const OUT_PROG_EXEC: bool> SoftPagedMem<'p, A, OUT_PROG_EXEC> { +impl SoftPagedMem<'_, A, OUT_PROG_EXEC> { /// Maps host's memory into VM's memory /// /// # Safety diff --git a/vm/src/mem/softpaging/mod.rs b/vm/src/mem/softpaging/mod.rs index 22761ac..c923db4 100644 --- a/vm/src/mem/softpaging/mod.rs +++ b/vm/src/mem/softpaging/mod.rs @@ -32,8 +32,8 @@ pub struct SoftPagedMem<'p, PfH, const OUT_PROG_EXEC: bool = true> { pub icache: ICache, } -impl<'p, PfH: HandlePageFault, const OUT_PROG_EXEC: bool> Memory - for SoftPagedMem<'p, PfH, OUT_PROG_EXEC> +impl Memory + for SoftPagedMem<'_, PfH, OUT_PROG_EXEC> { /// Load value from an address /// @@ -92,7 +92,7 @@ impl<'p, PfH: HandlePageFault, const OUT_PROG_EXEC: bool> Memory } } -impl<'p, PfH: HandlePageFault, const OUT_PROG_EXEC: bool> SoftPagedMem<'p, PfH, OUT_PROG_EXEC> { +impl SoftPagedMem<'_, PfH, OUT_PROG_EXEC> { // Everyone behold, the holy function, the god of HBVM memory accesses! /// Split address to pages, check their permissions and feed pointers with offset diff --git a/xtask/src/main.rs b/xtask/src/main.rs index bdd76d7..ea925f4 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -33,27 +33,34 @@ fn build_wasm_blob(name: &str, debug: bool) -> io::Result<()> { let mut c = build_cmd(if debug { "cargo wasm-build-debug" } else { "cargo wasm-build" }); c.arg(format!("wasm-{name}")); exec(c)?; - - let out_path = format!("target/wasm32-unknown-unknown/small/wasm_{name}.wasm"); + let profile = if debug { "small-dev" } else { "small" }; + let out_path = format!("target/wasm32-unknown-unknown/{profile}/wasm_{name}.wasm"); if !debug { exec(build_cmd(format!("wasm-opt -Oz {out_path} -o {out_path}")))?; } - exec(build_cmd(format!("cp {out_path} depell/src/wasm-{name}.wasm"))) + exec(build_cmd(format!("cp {out_path} depell/src/{name}.wasm")))?; + exec(build_cmd(format!("gzip -f depell/src/{name}.wasm")))?; + Ok(()) } fn main() -> io::Result<()> { let args = std::env::args().skip(1).collect::>(); match args[0].as_str() { "fmt" => fmt(args[1] == "-r" || args[1] == "--renumber"), - "build-depell" => { - build_wasm_blob("hbfmt", false)?; - build_wasm_blob("hbc", false)?; - exec(build_cmd("cargo build -p depell --release"))?; - Ok(()) - } "build-depell-debug" => { build_wasm_blob("hbfmt", true)?; build_wasm_blob("hbc", true)?; + exec(build_cmd("gzip -k -f depell/src/index.js"))?; + exec(build_cmd("gzip -k -f depell/src/index.css"))?; + exec(build_cmd("cargo run -p depell --features gzip"))?; + Ok(()) + } + "build-depell" => { + build_wasm_blob("hbfmt", false)?; + build_wasm_blob("hbc", false)?; + exec(build_cmd("gzip -k -f depell/src/index.js"))?; + exec(build_cmd("gzip -k -f depell/src/index.css"))?; + exec(build_cmd("cargo run -p depell --features gzip --release"))?; Ok(()) } _ => Ok(()),