Activity

Tony Kan

Optimized the Performance of LLVM Generated by the Compiler

https://github.com/rust-lang/rust/pull/152864

Summary:

Problem:

Small aggregate arguments passed via PassMode::Cast in the Rust ABI (e.g. [u32; 2] cast to i64) are missing noundef in the emitted LLVM IR, even when the type contains no uninit bytes:

#[no_mangle]
pub fn f(v: [u32; 2]) -> u32 { v[0] }
; expected: define i32 @f(i64 noundef %0)
; actual:   define i32 @f(i64 %0)           ← noundef missing

This blocks LLVM from applying optimizations that require value-defined semantics on function arguments.

Root Cause:

adjust_for_rust_abi calls arg.cast_to(Reg::Integer), which internally creates a CastTarget with ArgAttributes::new() — always empty. Any validity attribute that was present before the cast is silently dropped.

This affects all PassMode::Cast arguments and return values in the Rust ABI: plain arrays, newtype wrappers, and any BackendRepr::Memory type small enough to fit in a register.

A prior attempt (rust-lang/rust#127210) used Ty/repr attributes to detect padding.

Solution:

After adjust_for_rust_abi, iterate all PassMode::Cast args and the return value. For each, call layout_is_noundef on the original layout; if it returns true, set NoUndef on the CastTarget’s attrs.

layout_is_noundef uses only the computed layout — BackendRepr, FieldsShape, Variants, Scalar::is_uninit_valid() — and never touches Ty or repr attributes. Anything it cannot prove returns false.

Covered cases:

  • Scalar / ScalarPair (both halves initialized, fields contiguous)
  • FieldsShape::Array (element type recursively uninit-free)
  • FieldsShape::Arbitrary with Variants::Single (fields cover 0..size with no gaps, each recursively uninit-free) — handles newtype wrappers, multi-field structs, single-variant enums, repr(transparent), repr(C) wrappers
Attachment
0
Tony Kan

Eliminate size_of_val == 0 for DSTs with Non-zero-sized Prefix via NUW and Assume

https://github.com/rust-lang/rust/pull/152843

Summary:

Problem:

size_of_val(p) == 0 fails to optimize away for DST types that have a statically-known non-zero-sized prefix:

pub struct Foo<T: ?Sized>(pub [u32; 3], pub T);

pub fn demo(p: &Foo<dyn std::fmt::Debug>) -> bool {
    std::mem::size_of_val(p) == 0  // always false, but LLVM can't prove it
}

Foo has a 12-byte prefix, so its total size is always ≥ 12. Yet the comparison persists as a runtime computation in LLVM IR. This matters because Box<dyn T> drop emits this exact check to guard the deallocation call — for types with a guaranteed non-zero prefix, the branch should vanish but doesn’t.

The slice tail variant Foo<[i32]> already optimized correctly; Foo<dyn Trait> and Foo<[u8]> did not.

Root Cause:

In size_and_align_of_dst (the ADT/Tuple branch), the size computation is:

full_size = (offset + unsized_size + (align-1)) & -align

LLVM cannot prove full_size > 0 because:

  1. offset + unsized_size used plain add — no NUW flag, so LLVM cannot conclude the result is ≥ offset.
  2. (x + addend) & -align — LLVM has no information that alignment rounding never reduces the value below x.

Additionally, the vtable alignment range metadata was [1, u64::MAX] (only non-zero), despite the actual bound being [1, 1 << (ptr_width - 1)] (all alignments are powers of two with a tighter upper bound).

Attachment
0
Tony Kan

Fixed Compiler Code Generation Bugs (ICE): https://github.com/rust-lang/rust/issues/152340

[ICE]: Unexpected def_kind in codegen_fn_attrs: Const

Summary:

Problem:

Coercing a #[target_feature] const fn to a function pointer inside a const body triggers an ICE (debug builds only):

#[target_feature(enable = "sse2")]
const fn with_target_feature() {}

const X: () = unsafe {
    let _: unsafe fn() = with_target_feature; // ICE
};
assertion failed: def_kind.has_codegen_attrs()
unexpected `def_kind` in `codegen_fn_attrs`: Const

Root Cause:

Introduced in rust-lang/rust#135504 (2025-01-14, commit 8fee6a77394). adjust_target_feature_sig unconditionally calls codegen_fn_attrs(caller) to get the caller’s target features. codegen_fn_attrs requires that the DefId satisfies has_codegen_attrs(). DefKind::Const, AssocConst, and InlineConst do not — they have no codegen attributes by design. The debug assertion fires.

In release builds the call “worked” accidentally: codegen_fn_attrs on a const would reach the query machinery and happen to return empty attributes, producing a correct (but unguaranteed) result. The bug was latent until debug builds exposed it.

Solution:

Replace codegen_fn_attrs(caller) with body_codegen_attrs(caller). body_codegen_attrs exists precisely for this case: it delegates to codegen_fn_attrs for function-like DefKinds and returns CodegenFnAttrs::EMPTY for const items. A const body has no target features, so returning empty is semantically correct.

Also fix the pre-existing variable name callee_featurescaller_features (the variable holds the caller‘s features, not the callee’s).

Attachment
0
Tony Kan

Shipped this project!

Hours: 18.77
Cookies: 🍪 556
Multiplier: 29.64 cookies/hr

Can process a viral capsid with 8 million atoms in one second (~800ms)!

v0.4.0

🚀 Features

🩹 Fixes

Full Changelog: https://github.com/TKanX/bio-forge/compare/v0.3.1...v0.4.0

Tony Kan

Implement Context-Aware Histidine Protonation and Refine pH Handling

Summary:

Significantly enhances the hydrogenation pipeline (ops::hydro) by introducing context-aware histidine protonation logic. It now detects potential salt bridges between histidine residues and nearby carboxylate groups (ASP⁻, GLU⁻, C-terminal COO⁻), automatically converting them to the doubly protonated HIP state when geometrically favorable. Additionally, the pH handling logic has been refined to allow users to opt-out of automatic protonation state changes by omitting the --ph flag, preserving original residue names while still adding hydrogens.

Changes:

PR: https://github.com/TKanX/bio-forge/pull/38

Attachment
Attachment
Attachment
Attachment
Attachment
Attachment
Attachment
0
Tony Kan

SEE PR #36: https://github.com/TKanX/bio-forge/pull/36

Summary:

Addresses geometric artifacts observed in reconstructed terminal atoms (N-terminal hydrogens, C-terminal OXT, and nucleic acid termini). The previous implementation of calculate_transform was too simplistic for single/double atom alignments and relied on global SVD coupling which could distort local geometry. Additionally, terminal atom construction has been rewritten to use robust local coordinate frames based on standard bond lengths and angles, rather than rough vector approximations.

Attachment
Attachment
Attachment
0
Tony Kan

v0.1.0

🚀 Features

  1. Core Mathematical Kernel

    • Exact Evaluation: Implements analytical solutions for two-center Coulomb integrals over $ns$ Slater-Type Orbitals (STOs) using ellipsoidal coordinates.
    • Robust Numerics: Automatically handles singularities (one-center limit $R \to 0$) and numerical instabilities (small $\zeta$ differences) using Taylor expansions.
  2. High-Performance Architecture

    • Zero Allocation: Designed strictly for stack-only memory usage, making it suitable for tight loops and embedded systems.
    • Algorithmic Optimization: Utilizes $O(N)$ recurrence relations for auxiliary integrals and Horner’s method for polynomial evaluation, replacing naive $O(N^2)$ approaches.
    • Compile-Time Computation: Factorials and binomial coefficients are precomputed at compile time to minimize runtime overhead.
  3. Portability & Usability

    • no_std Support: Fully compatible with bare-metal and WASM environments (via libm).
    • Dual API: Offers both a high-level structural API (NsOrbital) for safety and a low-level functional API (sto_coulomb_integral) for raw performance.

New Contributors

  • @TKanX Lead Developer

Full Changelog: https://github.com/TKanX/sto-ns/commits/v0.1.0

Attachment
0
Tony Kan

v0.1.0

🚀 Features

  1. Comprehensive Force Field Support

    • Extensive Coverage: Provides atomic partial charges for Proteins (29 residues), Nucleic Acids (DNA/RNA), Water (5 models), and Ions (66 types).
    • Multi-Scheme Compatibility: Supports major force fields including AMBER (ff99SB, ff14SB, ff19SB, ff03) and CHARMM (C22, C27, C36, C36m).
    • Terminal Awareness: Correctly handles N-/C-terminal protein residues (including protonation states) and 5’/3’-terminal nucleic acids.
  2. High-Performance Architecture

    • O(1) Lookups: Utilizes Perfect Hash Functions (PHF) for constant-time charge retrieval, eliminating runtime hash map overhead.
    • Zero Allocation: Designed for stack-only usage with no dynamic memory allocation, ideal for high-throughput simulations.
    • Compile-Time Generation: All data is baked into the binary from CSV sources at compile time, ensuring zero startup cost and maximum optimization.
  3. Portability & Usability

    • no_std Support: Fully compatible with bare-metal, embedded, and WebAssembly (WASM) environments.
    • Type-Safe API: Leverages Rust’s strong type system with enums for Schemes and Positions to prevent invalid queries at compile time.
    • Zero Dependencies: Requires no runtime dependencies (other than the lightweight phf crate), keeping the dependency tree minimal.

New Contributors

  • @TKanX Lead Developer

Full Changelog: https://github.com/TKanX/ffcharge/commits/v0.1.0

Attachment
0
Tony Kan

Shipped this project!

Hours: 15.19
Cookies: 🍪 229
Multiplier: 15.07 cookies/hr

Based on quantum mechanical dynamic charge calculations, this accurately calculates the electric field and charge distribution polarization of drug-protein ligand binding pockets, which is used in drug simulations.

Tony Kan

Summary:

Introduces a major new feature to the cheq library: the ability to perform charge equilibration in the presence of an external electrostatic potential. This enables hybrid QEq/MM simulations, where a quantum-mechanically treated region (the QEq system) polarizes in response to a classical environment (the external field). The implementation supports contributions from both discrete point charges and a uniform electric field, which are incorporated into the QEq equations by modifying the effective electronegativity of each atom.

Changes:

  • Implemented ExternalPotential and PointCharge Data Structures:

    • Created a new PointCharge struct to represent a fixed charge in the classical environment (e.g., an atom from a protein).
    • Developed a flexible ExternalPotential struct to aggregate contributions from multiple PointCharges and/or a uniform_field.
    • Provided a builder-style API for ExternalPotential (with_point_charges, with_uniform_field) for ergonomic construction.
  • Introduced a New solve_in_field Solver Method:

    • Added a new public method, QEqSolver::solve_in_field, which accepts an ExternalPotential as an argument.
    • The method computes the external potential V_ext at each QEq atom’s position, using the same STO/GTO shielded Coulomb formalism for consistency with internal interactions.
    • The external potential is then added to the electronegativity term in the QEq linear system (χ_i* = χ_i + V_ext_i), effectively polarizing the QEq system.
  • Parallelized External Potential Calculation:

    • The calculation of the external potential, which can be computationally intensive for large environments, is parallelized using rayon for optimal performance.
Attachment
1

Comments

milo1004
milo1004 about 1 month ago

Nice addition to Cheq. Supporting external electrostatic potentials (point charges and uniform fields) enables hybrid QEq/MM-style setups and makes charge equilibration more physically realistic.

Tony Kan

Shipped this project!

Hours: 31.76
Cookies: 🍪 624
Multiplier: 19.66 cookies/hr

v0.3.0

🚀 Features

Full Changelog: https://github.com/TKanX/bio-forge/compare/v0.2.2...v0.3.0

Tony Kan

v0.3.0

🚀 Features

Full Changelog: https://github.com/TKanX/bio-forge/compare/v0.2.2...v0.3.0

Attachment
0
Tony Kan

DIFF(+15,607): https://github.com/TKanX/bio-forge/pull/26/changes

Summary:

Introduces the official BioForge Web Application, a high-performance, browser-based interface for molecular structure preparation. Built with Next.js 15, React 19, and Tailwind CSS, this application leverages the bio-forge-wasm crate to perform all heavy computations client-side, ensuring data privacy and zero-latency feedback. It features a fully integrated 3D viewer (Mol*), a reactive pipeline configuration system, and a robust state management architecture utilizing Zustand.

Changes:

  • WASM Integration & Core Logic:

    • Implemented a singleton WASM loader in core/wasm to ensure the heavy binary is initialized only once.
    • Developed a PipelineExecutor (core/pipeline) that orchestrates the execution of Clean, Repair, Hydro, Solvate, and Topology operations directly in the browser thread.
    • Created a robust file parser (core/file) capable of handling PDB, mmCIF, and MOL2 templates, converting them into managed FileEntry objects with live WASM structure references.
  • User Interface & Experience:

    • Design System: Created a comprehensive set of UI primitives (Buttons, Inputs, Sliders, Cards, Badges) styled with Tailwind CSS and oklch color spaces for a modern, accessible dark mode aesthetic.
    • Pipeline Panel: Built interactive configuration forms for every operation (e.g., pH sliders for hydrogenation, ion selection for solvation).
    • 3D Visualization: Integrated Mol (molstar)* for high-performance 3D rendering of structures. The viewer supports instant updates between processing steps without reloading the page.
    • Interactive File List: Implemented file cards with expandable details, real-time status indicators, and batch processing actions.
Attachment
Attachment
0
Tony Kan

Full Changelog: https://github.com/TKanX/bio-forge/commits/v0.2.2

Attachment
0