This project is in early development and intended for production use. |
Fidelity represents a revolutionary approach to F# development: a completely dependency-free framework that compiles F# directly to native executables using MLIR and LLVM, bypassing the entire .NET ecosystem. The Firefly compiler transforms F# source code through a sophisticated pipeline that eliminates runtime dependencies while preserving functional programming paradigms.
At its core, Fidelity consists of three foundational libraries:
- Alloy: Base structures providing static resolution of functions and native F# replacements for BCL components
- BAREWire: Memory mapping, IPC, and network interchange using the BARE protocol for seamless process communication
- Firefly: The compiler pipeline that orchestrates the entire F# to native transformation
The compilation pipeline represents a fundamental reimagining of how functional languages can target native execution environments. By leveraging MLIR's multi-level intermediate representation capabilities and LLVM's battle-tested code generation, Fidelity achieves true zero-dependency native compilation.
- F# Source Parsing - Using a standalone F# Compiler Service
- AST Conversion - Transforming F# constructs to MLIR-compatible representations
- MLIR Dialect Generation - Creating domain-specific intermediate representations
- LLVM IR Lowering - Converting to LLVM's intermediate representation
- Native Code Generation - Producing platform-specific executables
The Hello World example demonstrates Fidelity's fundamental capability to compile basic F# programs to native executables without any runtime dependencies. This seemingly simple example actually showcases the complete compilation pipeline working end-to-end, proving that F# syntax and semantics can be preserved while targeting native execution.
TimeLoop represents a step change in functional language native interop capabilities. This example goes far beyond basic compilation by demonstrating sophisticated interaction with system-level APIs and native libraries directly from F# code.
What makes TimeLoop revolutionary:
TimeLoop showcases Fidelity's ability to seamlessly integrate with native system calls and libraries without marshaling overhead or runtime intervention. Unlike traditional F# applications that require complex P/Invoke mechanisms and runtime marshaling, TimeLoop demonstrates direct native function calls with zero-cost abstractions.
The example illustrates how BAREWire's protocol implementation enables efficient memory mapping and IPC communication patterns that would be impossible or prohibitively expensive in traditional .NET environments. This capability opens entirely new architectural possibilities for F# applications, particularly in systems programming, embedded contexts, and high-performance computing scenarios.
Technical significance:
TimeLoop proves that functional programming paradigms can operate at the same performance tier as C/C++ while maintaining F#'s expressive type system and immutability guarantees. The native interop demonstrated here represents a fundamental shift from F# as a high-level application language to F# as a systems programming language capable of zero-overhead native integration.
The compilation results speak to Fidelity's efficiency advantages:
These comparisons demonstrate Fidelity's ability to produce significantly smaller, faster executables with zero runtime dependencies compared to traditional .NET compilation approaches.
- MLIR libraries
- LLVM infrastructure
- F# Compiler Service
- PowerShell (for build scripting)
- MSYS2 or equivalent MinGW development environment
pacman -Syu # Update package database and core system packages
pacman -S mingw-w64-x86_64-toolchain
pacman -S mingw-w64-x86_64-llvm
pacman -S mingw-w64-x86_64-clang
pacman -S mingw-w64-x86_64-cmake
pacman -S mingw-w64-x86_64-ninja
src/
: Source code for the compiler pipelineBindings/
: Native bindings for MLIR and LLVMConversion/
: AST conversion logicPipeline/
: Compilation pipeline implementationExamples/
: Sample F# programs (Hello World, TimeLoop)
tools/
: Build and development scriptsbuild/
: Compiled output directory
Execute the compilation pipeline:
.\tools\build.ps1
Note: Verify path settings match your project and dependency locations.
- Compile F# MLIR Bindings
- Compile MLIR Wrapper Modules
- Generate Conversion Modules
- Build Compilation Pipeline
- Create Example Executables
Present constraints:
- Experimental parsing mechanisms with limited language feature coverage
- No garbage collection implementation
- Minimal optimization strategies currently implemented
Research directions:
- Enhanced type system mapping for complex F# constructs
- Advanced optimization passes leveraging MLIR's transformation infrastructure
- Memory management strategies for functional programming patterns
- Comprehensive language construct support expansion
This implementation deliberately diverges from standard .NET compilation approaches. The F# Compiler Service operates as a standalone library, completely decoupled from .NET infrastructure. Build orchestration uses direct PowerShell coordination, and type resolution includes custom binding implementations where standard mechanisms prove inadequate.
Research Prototype Disclaimer: This represents experimental compiler technology and should be considered a research prototype exploring the boundaries of functional language compilation.