π§ Under Active Development π§
This project is in early development and not intended for production use.
Native-first type resolution for F# ahead-of-time compilation.
fsnative is F# Native Compiler Services (FNCS), a specialized fork of Microsoft's F# compiler designed for native compilation. Where the standard F# compiler assumes a managed runtime with garbage collection and BCL types, fsnative understands native types, deterministic memory, and statically resolved operations from the ground up.
fsnative is the frontend for the Fidelity native compilation framework. It parses F# code, performs type checking, and produces a typed abstract syntax tree that flows directly into native code generation. No .NET runtime required.
FNCS is part of the Fidelity native F# compilation ecosystem:
| Project | Role |
|---|---|
| Firefly | AOT compiler: F# β PSG β MLIR β Native binary |
| Alloy | Native standard library with platform bindings |
| BAREWire | Binary encoding, memory mapping, zero-copy IPC |
| Farscape | C/C++ header parsing for native library bindings |
| XParsec | Parser combinators powering PSG traversal and header parsing |
| fsnative | F# Native Compiler Services (this repository) |
| fsnative-spec | F# Native language specification |
The name "Fidelity" reflects the framework's core mission: preserving type and memory safety from source code through compilation to native execution.
The standard F# Compiler Services does an excellent job for .NET development. Microsoft is making progress with ahead-of-time (AOT) compilation, but there are fundamental limitations. When you're compiling to true native binaries without a runtime or garbage collector, many .NET assumptions become obstacles:
Strings are garbage-collected UTF-16 objects. Native compilation needs UTF-8 strings with deterministic lifetimes. When a string goes out of scope, its memory should be freed immediately.
Option types are heap-allocated reference types. Native compilation needs value options that live on the stack and cost nothing when they're None.
Memory has no notion of ownership or regions. Native compilation needs to distinguish stack memory from heap memory, peripheral registers from RAM, read-only flash from writable SRAM. The type system should enforce these distinctions at compile time.
The runtime manages all memory. Native compilation needs explicit control. Pointers should carry lifetime information. The compiler should track whether memory is borrowed or owned, mutable or immutable.
These aren't bugs to work around. They're fundamental assumptions baked into the type system. fsnative replaces those assumptions with native-first semantics while preserving the F# developer experience.
fsnative makes native types intrinsic to the compiler:
// What you write
let greeting = "Hello, World!"
// Standard F#: System.String (UTF-16, GC-managed)
// fsnative: NativeStr (UTF-8, deterministic lifetime)// What you write
let maybeValue = Some 42
// Standard F#: int option (reference type, heap allocated)
// fsnative: int voption (value type, stack allocated)// What you write
let inline add a b = a + b
// Standard F#: resolves against System.Int32.op_Addition
// fsnative: resolves against Alloy.BasicOps witness hierarchyThe compiler knows these types. It doesn't discover them by reading assembly metadata. It understands their layout, their semantics, their operations. When fsnative produces a typed tree, the types are already native, ready for direct translation to MLIR and LLVM.
fsnative is one piece of a larger native compilation story:
F# Source
β
fsnative (FNCS) β You are here
β
Program Semantic Graph (PSG)
β
Alex β MLIR β LLVM
β
Native Binary
Together with Firefly, Alloy, BAREWire, and Farscape, fsnative compiles F# to efficient, standalone native binaries that run without any runtime.
- Parsing: Full F# syntax support via the battle-tested FCS lexer and parser
- Native Type Resolution: String literals, options, and arrays resolve to native types
- Memory Region Tracking: Pointers carry region and access-kind information through the type system
- Native SRTP: Statically resolved type parameters resolve against the Alloy witness hierarchy
- Typed Tree: Complete
FSharpExproutput for downstream code generation - IDE Services: Symbol resolution, type information, and semantic classification for tooling
fsnative is a focused frontend, not a complete compiler:
- No IL generation: That's what the standard F# compiler does
- No MSBuild integration: Project files are handled by Firefly
- No NuGet resolution: Package management is external
- No REPL: Interactive scripting requires a managed runtime
fsnative stops at the typed tree. Code generation happens in Firefly via MLIR.
fsnative is consumed as a library by the Firefly compiler:
// Firefly uses fsnative for type checking
let checker = FNCSChecker.Create()
let results = checker.ParseAndCheck(sourceFiles, config)
// Results contain the typed tree with native type resolution
let typedTree = results.TypedTree
let srtpResolutions = results.SRTPResolutionsFor most use cases, you'll interact with fsnative through Firefly rather than directly.
| Phase | Description | Status |
|---|---|---|
| Phase 1 | Structural pruning and namespace transformation | In Progress |
| Phase 2 | Native type integration | Pending |
| Phase 3 | SRTP resolution against Alloy witnesses | Pending |
| Phase 4 | Memory region and access kind measures | Future |
See docs/fidelity/FNCS_Phase1_Transformation_Plan.md for detailed status.
| Document | Description |
|---|---|
| docs/fidelity/README.md | FNCS overview and architecture |
| docs/fidelity/FNCS_Phase1_Transformation_Plan.md | Detailed transformation roadmap |
| docs/fidelity/FNCS_Pruning_Plan.md | Component pruning strategy |
| fsnative-spec | Normative language specification |
fsnative is a fork of Microsoft's dotnet/fsharp repository. We're grateful to the F# team and community for creating and maintaining an excellent compiler.
Our modifications focus on type resolution, not syntax. We maintain the fork as a focused, surgical modification rather than a wholesale rewrite. The parsing, name resolution, and constraint solving machinery remains largely intact. What changes is the underlying type machinery those mechanisms operate against.
This project is licensed under the MIT License - see the LICENSE file for details.
Original work is copyright Microsoft Corporation. Modifications are copyright SpeakEZ Technologies.
fsnative is developed by SpeakEZ Technologies as part of the Fidelity native compilation framework.
- Microsoft F# Team: For the F# compiler and FCS that FNCS is based on
- Don Syme and F# Contributors: For creating an elegant functional language
- Firefly Team: For the native compilation infrastructure
F# syntax you know. Native semantics you need.