The cg_clif
project has made significant progress in compiling Rust to C, achieving a 95.9% pass rate on the Rust test suite. This compiler leverages Cranelift as a backend and utilizes a custom ABI for passing Rust data structures. Notably, it's now functional on more unusual platforms like wasm32-wasi
and thumbv6m-none-eabi
(for embedded ARM devices). While performance isn't a primary focus currently, basic functionality and compatibility are progressing rapidly, demonstrating the potential for compiling Rust to a portable C representation.
Rust enums can surprisingly be smaller than expected. While naively, one might assume an enum's size is determined by the largest variant plus a discriminant to track which variant is active, the compiler optimizes this. If an enum's largest variant contains data with internal padding, the discriminant can sometimes be stored within that padding, avoiding an increase in the overall size. This optimization applies even when using #[repr(C)]
or #[repr(u8)]
, so long as the layout allows it. Essentially, the compiler cleverly utilizes existing unused space within variants to store the variant tag, minimizing the enum's memory footprint.
Hacker News users discussed the surprising optimization where Rust can reduce the size of an enum if its variants all have the same representation. Some commenters expressed admiration for this detail of the Rust compiler and its potential performance benefits. A few questioned the long-term stability of relying on this optimization, wondering if changes to the enum's variants could inadvertently increase its size in the future. Others delved into the specifics of how this optimization interacts with features like repr(C)
and niche filling optimizations. One user linked to a relevant section of the Rust Reference, further illuminating the compiler's behavior. The discussion also touched upon the potential downsides, such as making the generated assembly more complex, and how using #[repr(u8)]
might offer a more predictable and explicit way to control enum size.
PlanetScale's Vitess project, which uses a Go-based MySQL interpreter, historically lagged behind C++ in performance. Through focused optimization efforts targeting function call overhead, memory allocation, and string conversion, they significantly improved Vitess's speed. By leveraging Go's built-in profiling tools and making targeted changes like using custom map implementations and byte buffers, they achieved performance comparable to, and in some cases exceeding, a similar C++ interpreter. These improvements demonstrate that with careful optimization, Go can be a competitive choice for performance-sensitive applications like database interpreters.
Hacker News users discussed the benchmarks presented in the PlanetScale blog post, expressing skepticism about their real-world applicability. Several commenters pointed out that the microbenchmarks might not reflect typical database workload performance, and questioned the choice of C++ implementation used for comparison. Some suggested that the Go interpreter's performance improvements, while impressive, might not translate to significant gains in a production environment. Others highlighted the importance of considering factors beyond raw execution speed, such as memory usage and garbage collection overhead. The lack of details about the specific benchmarks and the C++ implementation used made it difficult for some to fully assess the validity of the claims. A few commenters praised the progress Go has made, but emphasized the need for more comprehensive and realistic benchmarks to accurately compare interpreter performance.
This post outlines a vision for first-class WebAssembly support in Swift, enabling developers to compile Swift code directly to Wasm for use in web browsers and other Wasm environments. The proposal emphasizes seamless integration with existing JavaScript ecosystems, allowing bidirectional communication between Swift and JavaScript code. It also aims for near-native performance by leveraging Wasm's capabilities, and proposes tools and workflows to simplify the development process, such as automatic generation of JavaScript bindings for Swift code. The ultimate goal is to empower Swift developers to build high-performance web applications and leverage the growing Wasm ecosystem, while maintaining Swift's core values of safety, performance, and expressiveness.
Hacker News users discussed the potential and challenges of Swift for WebAssembly. Some expressed excitement about the prospect of using Swift for frontend development, highlighting its performance and type safety as advantages over JavaScript. Others were more cautious, pointing to the existing maturity of JavaScript and its ecosystem, and questioning whether Swift could gain significant traction. Concerns were raised about the size of Swift compiled output and the integration with existing JavaScript libraries and frameworks. The potential for full-stack Swift development and server-side applications with WebAssembly was also mentioned as a motivating factor. Several users suggested that prioritizing the developer experience and tooling would be crucial for adoption.
C3 is a new programming language designed as a modern alternative to C. It aims to be safer and easier to use while maintaining C's performance and low-level control. Key features include optional memory safety through compile-time checks and garbage collection, improved syntax and error messages, and built-in modularity. The project is actively under development and includes a self-hosting compiler written in C3. The goal is to provide a practical language for systems programming and other performance-sensitive domains while mitigating common C pitfalls.
HN users discuss C3's goals and features, expressing both interest and skepticism. Several question the need for another C-like language, especially given the continued development of C and C++. Some appreciate the focus on safety and preventing common C errors, while others find the changes too drastic a departure from C's philosophy. There's debate about the practicality of automatic memory management in systems programming, and some concern over the runtime overhead it might introduce. The project's early stage is noted, and some express reservations about its long-term viability and community adoption. Others are more optimistic, praising the clear documentation and expressing interest in following its progress. The use of Python for the compiler is also a point of discussion.
This guide provides a curated list of compiler flags for GCC, Clang, and MSVC, designed to harden C and C++ code against security vulnerabilities. It focuses on options that enable various exploit mitigations, such as stack protectors, control-flow integrity (CFI), address space layout randomization (ASLR), and shadow stacks. The guide categorizes flags by their protective mechanisms, emphasizing practical usage with clear explanations and examples. It also highlights potential compatibility issues and performance impacts, aiming to help developers choose appropriate hardening options for their projects. By leveraging these compiler-based defenses, developers can significantly reduce the risk of successful exploits targeting their software.
Hacker News users generally praised the OpenSSF's compiler hardening guide for C and C++. Several commenters highlighted the importance of such guides in improving overall software security, particularly given the prevalence of C and C++ in critical systems. Some discussed the practicality of implementing all the recommendations, noting potential performance trade-offs and the need for careful consideration depending on the specific project. A few users also mentioned the guide's usefulness for learning more about compiler options and their security implications, even for experienced developers. Some wished for similar guides for other languages, and others offered additional suggestions for hardening, like using static and dynamic analysis tools. One commenter pointed out the difference between control-flow hijacking mitigations and memory safety, emphasizing the limitations of the former.
This blog post demonstrates how to achieve tail call optimization (TCO) in Java, despite the JVM's lack of native support. The author uses the ASM bytecode manipulation library to transform compiled Java bytecode, replacing recursive tail calls with goto instructions that jump back to the beginning of the method. This avoids stack frame growth and prevents StackOverflowErrors, effectively emulating TCO. The post provides a detailed example, transforming a simple factorial function, and discusses the limitations and potential pitfalls of this approach, including the handling of local variables and debugging challenges. Ultimately, it offers a working, albeit complex, solution for achieving TCO in Java for specific use cases.
Hacker News users generally expressed skepticism about the practicality and value of the approach described in the article. Several commenters pointed out that while technically interesting, using ASM to achieve tail-call optimization in Java is likely to be more trouble than it's worth due to the complexity and potential for subtle bugs. The performance benefits were questioned, with some suggesting that iterative solutions would be simpler and potentially faster. Others noted that relying on such a technique would make code less portable and harder to maintain. A few commenters appreciated the cleverness of the solution, but overall the sentiment leaned towards considering it more of a curiosity than a genuinely useful technique.
MilliForth-6502 is a minimalist Forth implementation for the 6502 processor, designed to be incredibly small while remaining a practical programming language. It features a 1 KB dictionary, a 256-byte parameter stack, and implements core Forth words including arithmetic, logic, stack manipulation, and I/O. Despite its size, MilliForth allows for defining new words and includes a simple interactive interpreter. Its compactness makes it suitable for resource-constrained 6502 systems, and the project provides source code and documentation for building and using it.
Hacker News users discussed the practicality and minimalism of MilliForth, a Forth implementation for the 6502 processor. Some questioned its usefulness beyond educational purposes, citing limited memory and awkward programming style compared to assembly language. Others appreciated its cleverness and the challenge of creating such a compact system, viewing it as a testament to Forth's flexibility. Several comments highlighted the historical context of Forth on resource-constrained systems and drew parallels to other small language implementations. The maintainability of generated code and the debugging experience were also mentioned as potential drawbacks. A few commenters expressed interest in exploring MilliForth further and potentially using it for small embedded projects.
Xee is a new XPath and XSLT engine written in Rust, focusing on performance, security, and WebAssembly compatibility. It aims to be a modern alternative to existing engines, offering a safe and efficient way to process XML and HTML in various environments, including browsers and servers. Leveraging Rust's ownership model and memory safety features, Xee minimizes vulnerabilities like use-after-free errors and buffer overflows. Its WebAssembly support enables client-side XML processing without relying on JavaScript, potentially improving performance and security for web applications. While still under active development, Xee already supports a substantial portion of the XPath 3.1 and XSLT 3.0 specifications, with plans to implement streaming transformations and other advanced features in the future.
HN commenters generally praise Xee's speed and the author's approach to error handling. Several highlight the impressive performance benchmarks compared to libxml2, with some noting the potential for Xee to become a valuable tool in performance-sensitive XML processing scenarios. Others appreciate the clean API design and Rust's memory safety advantages. A few discuss the niche nature of XPath/XSLT in modern development, while some express interest in using Xee for specific tasks like web scraping and configuration parsing. The Rust implementation also sparked discussions about language choices for performance-critical applications. Several users inquire about WASM support, indicating potential interest in browser-based applications.
Jakt is a statically-typed, compiled programming language designed for performance and ease of use, with a focus on systems programming, game development, and GUI applications. Inspired by C++, Rust, and other modern languages, it features manual memory management, optional garbage collection, compile-time evaluation, and a friendly syntax. Developed alongside the SerenityOS operating system, Jakt aims to offer a robust and modern alternative for building performant and maintainable software while prioritizing developer productivity.
Hacker News users discuss Jakt's resemblance to C++, Rust, and Swift, noting its potential appeal to those familiar with these languages. Several commenters express interest in its development, praising its apparent simplicity and clean design, particularly the ownership model and memory management. Some skepticism arises about the long-term viability of another niche language, and concerns are voiced about potential performance limitations due to garbage collection. The cross-compilation ability for WebAssembly also generated interest, with users envisioning potential applications. A few commenters mention the project's active and welcoming community as a positive aspect. Overall, the comments indicate a cautious optimism towards Jakt, with many intrigued by its features but also mindful of the challenges facing a new programming language.
Autology is a Lisp dialect designed for self-modifying code and introspection. It exposes its own interpreter and data structures, allowing programs to analyze and manipulate their own source code, execution state, and even the interpreter itself during runtime. This capability enables dynamic code generation, on-the-fly modifications, and powerful metaprogramming techniques. It aims to provide a flexible environment for exploring novel programming paradigms and building self-aware, adaptive systems.
HN users generally expressed interest in Autology, a Lisp dialect with access to its own interpreter. Several commenters compared it favorably to Rebol in terms of metaprogramming capabilities. Some discussion focused on its potential use cases, including live coding and creating interactive development environments. Concerns were raised regarding its apparent early stage of development, the lack of documentation beyond the README, and the potential performance implications of its design. A few users questioned the practicality of such a language, while others were excited by the possibilities it presented for self-modifying code and advanced debugging tools. The reliance on Python for its implementation also sparked some debate.
This GitHub repository preserves incredibly early versions of Dennis Ritchie's Portable C Compiler, including pre-1.0 snapshots dating back to the late 1970s. These versions offer a fascinating glimpse into the evolution of C, showcasing its transition from a research language to the widespread programming powerhouse it became. The repository aims to archive these historically significant artifacts, making them available for study and exploration by those interested in the origins and development of C. It includes various versions for different architectures, providing valuable insights into early compiler design and the challenges of portability in the nascent days of Unix.
Hacker News users discussed the historical significance of the rediscovered C compiler source code, noting its use of PDP-11 assembly and the challenges of porting it to modern systems due to its tight coupling with the original hardware. Several commenters expressed interest in its educational value for understanding early compiler design and the evolution of C. Some debated the compiler's true "firstness," acknowledging earlier, possibly lost, versions, while others focused on the practical difficulties of building and running such old code. A few users shared personal anecdotes about their experiences with early C compilers and PDP-11 machines, adding a personal touch to the historical discussion. The overall sentiment was one of appreciation for the preservation and sharing of this piece of computing history.
The author details the process of creating a ZX Spectrum game from scratch, starting with C code for core game logic. This C code was then manually translated into Z80 assembly, a challenging process requiring careful consideration of memory management and hardware limitations. After the assembly code was complete, they created a loading screen and integrated everything into a working .tap
file, the standard format for Spectrum games. This involved understanding the intricacies of the Spectrum's tape loading system and manipulating audio frequencies to encode the game data for reliable loading on original hardware. The result was a playable game demonstrating a complete pipeline from high-level language to a functional retro game program.
Hacker News users discuss the impressive feat of converting C code to Z80 assembly and then to a working ZX Spectrum tape. Several commenters praise the author's clear explanation of the process and the clever tricks used to optimize for the Z80's limited resources. Some share nostalgic memories of working with the ZX Spectrum and Z80 assembly, while others delve into technical details like memory management and the challenges of cross-development. A few highlight the educational value of the project, showing the direct connection between high-level languages and the underlying hardware. One compelling comment thread discusses the efficiency of the generated Z80 code compared to hand-written assembly, with differing opinions on whether the compiler's output could be further improved. Another interesting exchange revolves around the practical applications of such a technique today, ranging from embedded systems to retro game development.
C Plus Prolog is a project that embeds a Prolog interpreter within C++ code, allowing for logic programming within a C++ application. It aims to provide a seamless integration where Prolog predicates can be called directly from C++ and vice-versa, enabling the combination of Prolog's declarative power with C++'s performance and imperative features. The project leverages a modified version of SWI-Prolog, a popular open-source Prolog implementation, and offers a bidirectional interface for data exchange between the two languages. This facilitates the development of applications that benefit from both efficient procedural code and the logical reasoning capabilities of Prolog.
Hacker News users discussed the practicality and niche appeal of C Plus Prolog. Some expressed interest in its potential for specific applications like implementing rule engines or program analysis tools, while others questioned the performance implications of embedding Prolog within C++. One commenter suggested that a cleaner approach might involve interfacing Prolog with a language like Rust. Several pointed out the project's age and apparent inactivity, raising concerns about maintainability and documentation. The potential for improved tooling using C++-based IDEs was mentioned as a possible benefit. Overall, the discussion centered around the specialized nature of the project and the trade-offs involved in its approach.
Microsoft is developing a new TypeScript compiler implementation called "tsc-native" built using native C++. This new compiler aims to drastically improve TypeScript compilation speed, potentially making it up to 10x faster than the existing JavaScript-based compiler. The project leverages the V8 JavaScript engine's TurboFan JIT compiler to optimize performance-critical parts of the type checking process. While still experimental, initial benchmarks show significant improvements, particularly for large projects. The team is actively working on refining the compiler and invites community feedback as they progress towards a production-ready release.
Hacker News users discussed the potential impact of a native TypeScript compiler. Some expressed skepticism about the claimed 10x speed improvement, emphasizing the need for real-world benchmarks and noting that compile times aren't always the bottleneck in TypeScript development. Others questioned the long-term viability of the project given Microsoft's previous attempts at native compilation. Several commenters pointed out that JavaScript's dynamic nature presents inherent challenges for ahead-of-time compilation and optimization, and wondered how the project would address issues like runtime type checking and dynamic module loading. There was also interest in whether the native compiler would support features like decorators and reflection. Some users expressed hope that a faster compiler could enable new use cases for TypeScript, like scripting and game development.
This 1987 paper by Dybvig explores three distinct implementation models for Scheme: compilation to machine code, abstract machine interpretation, and direct interpretation of source code. It argues that while compilation offers the best performance for finished programs, the flexibility and debugging capabilities of interpreters are crucial for interactive development environments. The paper details the trade-offs between these models, emphasizing the advantages of a mixed approach that leverages both compilation and interpretation techniques. It concludes that an ideal Scheme system would utilize compilation for optimized execution and interpretation for interactive use, debugging, and dynamic code loading, hinting at a system where the boundaries between compiled and interpreted code are blurred.
HN commenters discuss the historical significance of the paper in establishing Scheme's minimalist design and portability. They highlight the cleverness of the three implementations, particularly the threaded code interpreter, and its influence on later languages like Lua. Some note the paper's accessibility and clarity, even for those unfamiliar with Scheme, while others reminisce about using the techniques described. A few comments delve into technical details like register allocation and garbage collection, comparing the approaches to modern techniques. The overall sentiment is one of appreciation for the paper's contribution to computer science and programming language design.
This blog post demonstrates how to compile C++ code using the Clang API, focusing on practical examples and clear explanations. It walks through creating a simple compiler driver, configuring compilation arguments like include paths and optimization levels, and invoking the Clang frontend to generate LLVM IR. The post highlights key components of the Clang API like clang::FrontendAction
and clang::ASTConsumer
, and showcases how to handle diagnostics and access compilation results. It provides a foundation for building tools that leverage Clang's powerful analysis and transformation capabilities.
Hacker News users discussed practical aspects of using the Clang API. Some pointed out the steep learning curve and lack of comprehensive documentation, making it challenging to navigate and debug. Others highlighted the API's power and flexibility for tasks like code analysis, transformation, and generation, exceeding the capabilities of simpler tools. A few commenters shared alternative approaches or libraries for specific use cases, such as libTooling for simpler tasks and Tree-sitter for parsing. The lack of good error messages from the Clang API was also mentioned, along with the difficulty of integrating it into build systems like CMake.
Gleam v1.9.0 introduces improved error messages, specifically around type errors involving records and incorrect argument counts. It also adds the gleam echo
command, a helpful tool for debugging pipelines by printing values at different stages. Additionally, the release includes experimental support for Git integration, allowing Gleam to leverage Git information for dependency resolution and package management. This simplifies workflows and improves dependency management within projects, especially for local development and testing.
Hacker News users discussed the Gleam v1.9.0 release, largely focusing on its novel approach to error handling. Several commenters praised the explicit and exhaustive nature of error handling in Gleam, contrasting it favorably with Elixir's approach, which some found less strict. The discussion also touched upon the tradeoffs between Gleam's stricter error handling and potential verbosity, with some acknowledging the benefits while others expressed concerns about potential boilerplate. A few comments highlighted the language's growing maturity and ecosystem, while others inquired about specific features like concurrency and performance. One commenter appreciated the clear and concise changelog, a sentiment echoed by others who found the update informative and well-presented. The overall tone was positive, with many expressing interest in exploring Gleam further.
LFortran can now compile Prima, a Python plotting library, demonstrating its ability to compile significant real-world Python code into performant executables. This milestone was achieved by leveraging LFortran's Python transpiler, which converts Python code into Fortran, and then compiling the Fortran code. This allows users to benefit from both the ease of use of Python and the performance of Fortran, potentially accelerating scientific computing workflows that utilize Prima for visualization. This achievement highlights the progress of LFortran toward its goal of providing a modern, performant Fortran compiler while also serving as a performance-enhancing tool for Python.
Hacker News users discussed LFortran's ability to compile Prima, a computational physics library. Several commenters expressed excitement about LFortran's progress and potential, particularly its interactive mode and ability to modernize Fortran code. Some questioned the choice of Prima as a demonstration, suggesting it's a niche library. Others discussed the challenges of parsing Fortran's complex grammar and the importance of tooling for scientific computing. One commenter highlighted the potential benefits of transpiling Fortran to other languages, while another suggested integration with Jupyter for enhanced interactivity. There was also a brief discussion about Fortran's continued relevance and its use in high-performance computing.
Type++ is a novel defense against type confusion vulnerabilities that leverages inline type information to enforce type constraints at runtime with minimal overhead. It embeds compact type metadata directly within objects, enabling efficient runtime checks to ensure that memory accesses and operations are consistent with the declared type. The system utilizes a flexible metadata representation supporting diverse types and inheritance hierarchies, and employs a selective instrumentation strategy to minimize performance impact. Evaluation across various benchmarks and real-world applications demonstrates that Type++ effectively detects and prevents type confusion exploits with a modest runtime overhead, typically under 5%, making it a practical solution for enhancing software security.
HN commenters discuss the Type++ paper, generally finding the approach interesting but expressing concerns about performance overhead. Several suggest that a compile-time approach might be preferable, questioning the practicality of runtime checks. Some raise concerns about the complexity of implementation and the potential for bugs within the Type++ system itself. A few highlight the potential benefits for security and catching subtle errors, but the overall sentiment leans towards skepticism regarding the trade-off between safety and performance. The reliance on compiler modifications is also noted as a potential barrier to adoption.
MichiganTypeScript is a proof-of-concept project demonstrating a WebAssembly runtime implemented entirely within TypeScript's type system. It doesn't actually execute WebAssembly code, but instead uses advanced type-level programming techniques to simulate its execution. By representing WebAssembly instructions and memory as types, and leveraging TypeScript's type inference and checking capabilities, the project can statically verify the behavior of a given WebAssembly program. This effectively transforms TypeScript's type checker into an interpreter, showcasing the power and flexibility of its type system, albeit in a non-practical, purely theoretical manner.
Hacker News users discussed the cleverness of using TypeScript's type system for computation, with several expressing fascination and calling it "amazing" or "brilliant." Some debated the practical applications, acknowledging its limitations while appreciating it as a demonstration of the type system's power. Concerns were raised about debugging complexity and the impracticality for larger programs. Others drew parallels to other Turing-complete type systems and pondered the potential for generating optimized WASM code from such TypeScript code. A few commenters pointed out the project's connection to the "ts-sql" project and speculated about leveraging similar techniques for compile-time query validation and optimization. Several users also highlighted the educational value of the project, showcasing the unexpected capabilities of TypeScript's type system.
The blog post "Gleam, Coming from Erlang" explores the author's experience transitioning from Erlang to Gleam, a newer language built on the Erlang Virtual Machine (BEAM). It highlights Gleam's similarities to Erlang, such as its functional nature, immutability, and the benefits of the BEAM ecosystem like concurrency and fault tolerance. However, the author emphasizes key differences, primarily Gleam's static typing, more approachable syntax inspired by Rust and Elm, and its focus on clearer error messages. While acknowledging some current limitations in tooling and library availability compared to Erlang's mature ecosystem, the post ultimately presents Gleam as a promising alternative for building robust, concurrent applications, particularly for developers coming from other statically-typed languages who might find Erlang's syntax challenging.
Hacker News commenters generally expressed interest in Gleam, praising its friendly syntax and the benefits it inherits from the Erlang ecosystem, like the BEAM VM. Some saw it as a potentially strong competitor to Elixir, appreciating its stricter type system and simpler tooling. A few users familiar with Erlang questioned the necessity of Gleam, suggesting that learning Erlang directly might be more worthwhile. Performance comparisons with Elixir and other BEAM languages were also a topic of discussion, with some expressing hope for benchmarks. A recurring sentiment was curiosity about Gleam's potential to attract a larger community and gain wider adoption. Several commenters also appreciated the author's candid comparison between Gleam and Erlang, finding the article helpful for understanding Gleam's niche.
Neut is a statically-typed, compiled programming language designed for building reliable and maintainable systems software. It emphasizes simplicity and explicitness through its C-like syntax, minimal built-in features, and focus on compile-time evaluation. Key features include a powerful macro system enabling metaprogramming and code generation, algebraic data types for representing data structures, and built-in support for pattern matching. Neut aims to empower developers to write efficient and predictable code by offering fine-grained control over memory management and avoiding hidden runtime behavior. Its explicit design choices and limited standard library encourage developers to build reusable components tailored to their specific needs, promoting code clarity and long-term maintainability.
HN commenters generally express interest in Neut, praising its focus on simplicity, safety, and explicitness. Several highlight the appealing aspects of linear types and the borrow checker, noting similarities to Rust but with a seemingly gentler learning curve. Some question the practical applicability of linear types for larger projects, while others anticipate its usefulness in specific domains like game development or embedded systems. A few commenters express skepticism about the limited standard library and the overall maturity of the project, but the overall tone is positive and curious about the language's potential. Performance, particularly relating to garbage collection or its lack thereof, is a recurring point of discussion, with some wondering about the potential for optimizations given the linear type system.
The author seeks a C-like language with modern features like generics, modules, and memory safety, while maintaining C's performance and close-to-the-metal nature. They desire a language suitable for systems programming, potentially as a replacement for C in performance-critical applications, but with the added benefits of contemporary language design. They are exploring if such a language already exists or whether retrofitting C would be a more viable approach. Essentially, they want the power and control of C without its inherent pitfalls and limitations.
The Hacker News comments discuss the practicality and potential benefits of a "retrofitted" C dialect, primarily focusing on memory safety. Some suggest exploring existing options like Zig, Rust, or Odin, which already address many of C's shortcomings. Others express skepticism about the feasibility of such a project, citing the complexity of C's ecosystem and the difficulty of maintaining compatibility while introducing significant changes. A few commenters propose specific improvements, such as optional garbage collection or stricter type checking, but acknowledge the challenges in implementation and adoption. There's a general agreement that memory safety is crucial, but opinions diverge on whether a new dialect or focusing on tooling and better practices within existing C is the best approach. Some also discuss the potential benefits for embedded systems, where C remains dominant.
This blog post chronicles the author's weekend project of building a compiler for a simplified C-like language. It walks through the implementation of a lexical analyzer, parser (using recursive descent), and code generator targeting x86-64 assembly. The compiler handles basic arithmetic operations, variable declarations and assignments, if/else statements, and while loops. The post emphasizes simplicity and educational value over performance or completeness, providing a practical example of compiler construction principles in a digestible format. The code is available on GitHub for readers to explore and experiment with.
HN users largely praised the TinyCompiler project for its educational value, highlighting its clear code and approachable structure as beneficial for learning compiler construction. Several commenters discussed extending the compiler's functionality, such as adding support for different architectures or optimizing the generated code. Some pointed out similar projects or resources, like the "Let's Build a Compiler" tutorial and the Crafting Interpreters book. A few users questioned the "weekend" claim in the title, believing the project would take significantly longer for a novice to complete. The post also sparked discussion about the practical applications of such a compiler, with some suggesting its use for educational purposes or embedding in resource-constrained environments. Finally, there was some debate about the complexity of the compiler compared to more sophisticated tools like LLVM.
Svelte 5 significantly departs from its JavaScript framework roots by compiling components directly to vanilla JavaScript instructions that manipulate the DOM. This eliminates the virtual DOM diffing process typical of other frameworks, resulting in smaller bundle sizes and potentially faster performance. Instead of a framework mediating interactions, Svelte 5 generates imperative code tailored to each component, directly updating the DOM. This shift allows for optimized updates and reduces runtime overhead, making Svelte 5 applications more akin to handcrafted JavaScript than traditional framework-driven applications. While still using familiar Svelte syntax, the output is now a highly optimized, self-contained JavaScript module.
HN users discuss Svelte 5's compilation strategy, which moves reactivity out of the JavaScript runtime and into compiled code. Several commenters express excitement over the potential performance benefits and smaller bundle sizes, comparing it favorably to React and other frameworks. Some raise concerns about debugging and the implications for the ecosystem, particularly around tooling. A few express skepticism, questioning whether the performance gains are significant enough to warrant the shift and whether Svelte's approach will hinder wider adoption. There's also discussion about the blurring line between frameworks and compilers, and whether Svelte's compiled output still qualifies as JavaScript. The impact on hydration and server-side rendering is also a topic of interest.
A recent Clang optimization introduced in version 17 regressed performance when compiling code containing large switch statements within inlined functions. This regression manifested as significantly increased compile times, sometimes by orders of magnitude, and occasionally resulted in internal compiler errors. The issue stems from Clang's attempt to optimize switch lowering by transforming it into a series of conditional moves based on jump tables. This optimization, while beneficial in some cases, interacts poorly with inlining, exploding the complexity of the generated intermediate representation (IR) when a function with a large switch is inlined multiple times. This ultimately overwhelms the compiler's later optimization passes. A workaround involves disabling the problematic optimization via a compiler flag (-mllvm -switch-to-lookup-table-threshold=0) until a proper fix is implemented in a future Clang release.
The Hacker News comments discuss a performance regression in Clang involving large switch statements and inlining. Several commenters confirm experiencing similar issues, particularly when compiling large codebases. Some suggest the regression might be related to changes in the inlining heuristics or the way Clang handles jump tables. One commenter points out that using a constexpr
hash table for large switches can be a faster alternative. Another suggests profiling and selective inlining as a workaround. The lack of clear identification of the root cause and the potential impact on compile times and performance are highlighted as concerning. Some users express frustration with the frequency of such regressions in Clang.
The author is developing a Scheme implementation in async Rust to explore the synergy between the two. They believe Rust's robust tooling, performance, and memory safety, combined with its burgeoning async ecosystem, provide an ideal foundation for a modern Lisp dialect. Async capabilities offer exciting potential for concurrent Scheme programming, especially with features like lightweight tasks and channels. The project aims to leverage Rust's strengths while preserving the elegance and flexibility of Scheme, potentially offering a compelling alternative for both Lisp enthusiasts and Rust developers interested in functional programming.
HN commenters generally expressed interest in the project, finding the combination of Scheme and async Rust intriguing. Several questioned the choice of Rust for performance reasons, arguing that garbage collection makes it a poor fit for truly high-performance async workloads, and suggesting alternatives like C, C++, or even Zig. Some suggested exploring other approaches within the Rust ecosystem, like using a different garbage collector or a stack-allocated scheme. Others praised the project's focus on developer experience and the potential of combining Scheme's expressiveness with Rust's safety features. A few commenters also discussed the challenges of integrating garbage collection with async runtimes and the potential trade-offs involved. The author's responses clarified some of the design choices and acknowledged the performance concerns, indicating they're open to exploring different strategies.
This post explores optimizing Ruby's Foreign Function Interface (FFI) performance by using tiny Just-In-Time (JIT) compilers. The author demonstrates how generating specialized machine code for specific FFI calls can drastically reduce overhead compared to the generic FFI invocation process. They present a proof-of-concept implementation using Rust and inline assembly, showcasing significant speed improvements, especially for repeated calls with the same argument types. While acknowledging limitations and areas for future development, like handling different calling conventions and more complex types, the post concludes that tiny JITs offer a promising path toward a much faster Ruby FFI.
The Hacker News comments on "Tiny JITs for a Faster FFI" express skepticism about the practicality of tiny JITs in real-world scenarios. Several commenters question the performance gains, citing the overhead of the JIT itself and the potential for optimization by the host language's runtime. They argue that a well-optimized native library, or even careful use of the host language's FFI, could often outperform a tiny JIT. One commenter notes the difficulties of debugging and maintaining such a system, and another raises security concerns related to executing untrusted code. The overall sentiment leans towards established optimization techniques rather than introducing a new layer of complexity with a tiny JIT.
This video demonstrates the incredibly fast incremental compilation of the Zig self-hosted compiler. By making a small, seemingly insignificant change to a source file within the compiler's codebase and rebuilding, the video showcases a rebuild time of just around 25 milliseconds. This highlights Zig's efficient build system and its focus on fast iteration times, a key advantage for developer productivity.
Hacker News users generally praised the Zig compiler's fast incremental compilation demonstrated in the video. Several commenters highlighted the impressive speed and how it contributes to a positive developer experience. Some pointed out that while the demo is compelling, real-world project builds with dependencies might not be as instantaneous. Others discussed the potential of Zig's self-hosting capability and build system, comparing it favorably to other languages and build tools. A few users also expressed interest in Zig's memory management and safety features. There was some discussion about the practical limitations of incremental compilation and the importance of understanding its inner workings.
Summary of Comments ( 164 )
https://news.ycombinator.com/item?id=43661329
Hacker News users discussed the impressive 95.9% test pass rate of the Rust-to-C compiler, particularly its ability to target unusual platforms like the Sega Saturn and Sony PlayStation. Some expressed skepticism about the practical applications, questioning the performance implications and debugging challenges of such a complex transpilation process. Others highlighted the potential benefits for code reuse and portability, enabling Rust code to run on legacy or resource-constrained systems. The project's novelty and ambition were generally praised, with several commenters expressing interest in the developer's approach and future developments. Some also debated the suitability of "compiler" versus "transpiler" to describe the project. There was also discussion around specific technical aspects, like memory management and the handling of Rust's borrow checker within the C output.
The Hacker News post titled "Rust to C compiler – 95.9% test pass rate, odd platforms" sparked a discussion with several interesting comments. Many commenters focused on the complexities and nuances of compiling Rust to C, particularly given Rust's unique memory management features.
One commenter highlighted the challenges inherent in translating Rust's borrow checker and ownership model into C, which lacks these built-in mechanisms. They questioned how the compiler handled these crucial aspects of Rust, expressing skepticism about achieving true compatibility without significant runtime overhead or limitations. This comment resonated with others who also expressed concern about the potential performance implications and the difficulty of replicating Rust's safety guarantees in C.
Another commenter pointed out the inherent difficulty in targeting "odd platforms," as mentioned in the title. They elaborated on the potential issues with varying C standard library implementations and the complexities of ensuring compatibility across diverse architectures and operating systems. This prompted a discussion about the trade-offs between portability and performance when attempting such a compilation process.
Several comments also touched on the potential use cases of such a compiler. Some suggested it could be valuable for embedded systems or environments where Rust isn't directly supported. Others questioned the practicality, arguing that if the target platform supports a C compiler, it might also be feasible to support a Rust compiler directly, potentially negating the need for a transpilation step.
The discussion also explored alternative approaches, such as compiling Rust to LLVM bitcode and then using LLVM to generate C code. This was presented as a potentially more robust approach that could leverage LLVM's optimizations and platform support.
Finally, some comments expressed interest in the specific platforms targeted by the project and requested more details about the remaining 4.1% of failing tests. They were curious about the nature of these failures and whether they represented fundamental limitations or solvable issues. Overall, the comments reflected a mixture of curiosity, skepticism, and cautious optimism about the potential of a Rust-to-C compiler.