{"id":28274869,"url":"https://github.com/jakkusakura/ferrophase","last_synced_at":"2025-07-28T18:07:35.219Z","repository":{"id":60046905,"uuid":"524581368","full_name":"JakkuSakura/FerroPhase","owner":"JakkuSakura","description":"An experiment of high level code optimization","archived":false,"fork":false,"pushed_at":"2025-05-19T19:47:14.000Z","size":1436,"stargazers_count":30,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-27T19:55:55.032Z","etag":null,"topics":["compiler","programming-language"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JakkuSakura.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-08-14T05:28:17.000Z","updated_at":"2025-05-19T19:47:20.000Z","dependencies_parsed_at":"2023-11-07T15:31:37.708Z","dependency_job_id":"a38a9550-d537-4eb8-8599-ce583380a54f","html_url":"https://github.com/JakkuSakura/FerroPhase","commit_stats":null,"previous_names":["jakkusakura/shll","jakkusakura/ferrophase"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/JakkuSakura/FerroPhase","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JakkuSakura%2FFerroPhase","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JakkuSakura%2FFerroPhase/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JakkuSakura%2FFerroPhase/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JakkuSakura%2FFerroPhase/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JakkuSakura","download_url":"https://codeload.github.com/JakkuSakura/FerroPhase/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JakkuSakura%2FFerroPhase/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260126169,"owners_count":22962597,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["compiler","programming-language"],"created_at":"2025-05-21T02:13:30.633Z","updated_at":"2025-06-16T08:31:04.605Z","avatar_url":"https://github.com/JakkuSakura.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FerroPhase: High-Level Extension Language for Rust\n\nThis language explores higher-level abstractions for Rust through staged compilation and rich type manipulation.\n\nGoal: Expressiveness and safety while leveraging Rust's performance\n\nIt adds advanced type capabilities and meta-programming to the Rust ecosystem.\n\nSee rust-lang/examples/main_02.rs for example.\n\n## Name Origin\n\nThe name \"FerroPhase\" is derived from two key concepts that define this language:\n\n1. **Ferro-**: From the Latin word \"ferrum\" meaning iron, establishing a connection to Rust (which is iron oxide). This acknowledges FerroPhase's foundation in Rust syntax and semantics.\n\n2. **-Phase**: Represents the staged compilation process that transforms high-level abstractions into valid Rust code. This highlights the language's role as a phase in the development process that feeds into the Rust compiler.\n\nTogether, \"FerroPhase\" captures both the language's Rust heritage and its role as a complementary layer that enhances Rust development.\n\n## Vision: Complementing Rust\n\nFerroPhase aims to be a complement to Rust rather than a replacement. While Rust excels at performance and safety, it can be verbose and lacks certain high-level abstractions. FerroPhase addresses this gap by:\n\n- Providing advanced type system features inspired by TypeScript\n- Enabling powerful meta-programming capabilities\n- Simplifying complex patterns through higher-level abstractions\n- Transpiling to clean, idiomatic Rust code\n\nWhen it comes to abstraction, even Rust and C++ claim they provide zero-cost abstraction, but they also have their\nproblems.\n\n- Interpreted languages like Python is slow\n- template in C++ and Rust is fastest, but with weird syntax and incomplete features compared to the language itself\n- Generics(in Java) doesn't provide much runtime performance benefit. Even with help of JIT it's hard to optimize at\n  higher level than method\n- OOP polymorphism involves calling dynamic dispatched methods, which involves a runtime cost\n- codegen requires an external tool, and writing such tool involves much work\n- macros(in Rust/Scala/C) is hard to debug, and limited to decorate a function/struct(or text replacement in C)\n- lisp is powerful in metaprogramming, but it's an interpreter language\n\nThe ideal solution is the FerroPhase language, which provides high-level abstractions that transpile to Rust:\n\n- Write declarative/high level code, and let Rust handle the performance aspects\n- Leverage Rust's ecosystem and optimization capabilities\n\nTo sum up: make the language simple yet expressive, and produces clean, idiomatic Rust code\n\n## Syntax\n\n## Frontend\n\nSame as rust with extensions for advanced type operations and meta-programming\n\n## Optimization\n\nThen AST gets passed through multiple transformation phases, maintaining the same semantics while generating optimal Rust code.\n\nCurrent transformation phases:\n\n- [x] Specialization and inlining\n- [ ] Flow analysis\n- [ ] Dead code elimination\n\n### Specialization\n\n### Flow analysis\n\n### Dead code elimination\n\n## Backend\n\nAST gets transpiled into Rust as the primary target language. This approach leverages:\n\n- Full interoperability with existing Rust code\n- The entire Rust ecosystem\n- Rust's sophisticated optimizations\n- Zero runtime overhead compared to hand-written Rust\n- Easy integration into existing Rust projects\n\nScala remains as an experimental alternative target.\n\nThe language aims to experiment with simple syntax and expressive capabilities.\nCompile time is not a concern, as we maintain the same semantics between phases.\n\n### Type System\n\nFerroPhase brings TypeScript-inspired type features to the Rust ecosystem:\n\n```rust\n// structural typing, solid type\ntype Foo = struct {\n    a: i32,\n    b: i32,\n}\n// named typing\nstruct Foo {\n    a: i32,\n    b: i32,\n}\n// impl trait\nimpl Read\n// addition of traits\nimpl Read + impl Write\nimpl Read + Write\n// generic\nVec\u003cT\u003e\n// subtraction of traits\nimpl Read + impl Write - impl Write\n// union type\ntype RW = impl Write | impl Write\n// intersection type\ntype RW = impl Read + impl Write\ntype RW = impl Read \u0026 impl Write\n\n// building a struct\ntype Foo2 = Type\u003c{\n    type mut T = struct {}\n    T.a = bool;\n    T.b = i32;\n    T\n}\u003e\n\n// type function\ntype NestedVec\u003cT, const n: usize\u003e = Type\u003c{\n    if n == 0 {\n        T\n    } else {\n        Vec \u003c NestedVec \u003c T, n - 1 \u003e\u003e\n    }\n}\u003e\n// typeof\ntype Foo = typeof(1)\n// literal types\ntype Foo = 1\n\n// type alias\ntype Foo = i32\n\n// if const\nfn foo() {\n    if const { true } {\n        println!(\"true\")\n    } else {\n        println!(\"false\")\n    }\n}\n// type dict\ntype Foo = struct {\n    \"/api\": EndpointApi,\n    \"/user\": EndpointUser,\n}\nFoo[\"/api\"]\n\n// fn LinkedList(comptime T: type) type {\n//   return struct {\n//     pub const Node = struct {\n//     prev: ? * Node = null,\n//     next: ? * Node = null,\n//     data: T,\n//     };\n//     \n//     first: ? * Node = null,\n//     last: ? * Node = null,\n//     len: usize = 0,\n//   };\n// }\n\ntype LinkedList\u003cT\u003e = struct {\n    type Node = struct {\n    prev: ? * Node = null,\n    next: ? * Node = null,\n    data: T,\n    };\n    first: ? * Node = null,\n    last: ? * Node = null,\n    len: usize = 0,\n}\n```\n\n## Use Cases\n\nFerroPhase is particularly valuable for:\n\n1. **API Design**: Create expressive, type-safe APIs with minimal boilerplate\n2. **Domain-Specific Languages**: Build custom DSLs that compile to efficient Rust\n3. **Complex Data Processing**: Express algorithms at a higher level\n4. **Type-Heavy Systems**: Work with sophisticated type relationships more easily\n5. **Code Generation**: Generate specialized implementations from high-level descriptions\n\n## References\n\nStruct is (partly) similar to GoLang and Zig\nSimilar to Zig's comptime system, but aims to do more than Zig with less and simpler\ncode. https://kristoff.it/blog/what-is-zig-comptime/\nInteresting article describes biformity which FerroPhase aims to solve:\nhttps://hirrolot.github.io/posts/why-static-languages-suffer-from-complexity.html\n\n## TODO\n\n- [ ] Use miette for error handling\n- [ ] Refer to rustc's demand-driven compilation. i.e. use trait instead of passes where possible. this is already WIP\n- [ ] Use tree-sitter for CST\n- [ ] Implement checks using passes, similar to mutations\n- [ ] Implement TypeScript-inspired type system\n- [ ] Create seamless Rust integration\n- [ ] Build language server for IDE support\n\n## Development Roadmap\n\n### Phase 1: Core Language Foundation (Short-term)\n1. **Enhanced Type System**\n   - Implement structural typing\n   - Add union and intersection types\n   - Develop type inference engine\n   - Support type-level computation\n\n2. **Metaprogramming Foundation**\n   - Implement compile-time evaluation\n   - Create AST manipulation utilities\n   - Support code generation from types\n\n3. **Rust Integration**\n   - Seamless import of Rust types and functions\n   - Clean Rust code generation\n   - Type-preserving translation\n\n4. **Developer Experience**\n   - Implement helpful error messages\n   - Create basic IDE support\n   - Build documentation tools\n\n### Phase 2: Advanced Features (Medium-term)\n1. **Extended Type System**\n   - Add effect tracking\n   - Implement advanced type inference\n   - Support higher-kinded types\n   - Create standard type utilities\n\n2. **Pattern Libraries**\n   - Functional programming patterns\n   - Common design patterns\n   - Domain-specific abstractions\n\n3. **Tooling Ecosystem**\n   - Full-featured language server\n   - Integration with popular IDEs\n   - Build system integration\n\n4. **Standard Library**\n   - High-level data structures\n   - Functional utilities\n   - Common abstractions\n\n### Phase 3: Ecosystem Growth (Long-term)\n1. **Community Building**\n   - Documentation and tutorials\n   - Example projects\n   - Community packages\n\n2. **Integration with Rust Ecosystem**\n   - Crates.io compatibility\n   - Cargo plugin\n   - Seamless workflow with Rust projects\n\n3. **Enterprise Features**\n   - Large project support\n   - Performance profiling\n   - Migration tools from pure Rust\n\n### Contributors Guide\n\n1. **Getting Started**\n   - Set up the development environment\n   - Understand the compiler architecture\n   - Pick beginner-friendly issues\n\n2. **Areas Needing Help**\n   - Parser improvements and syntax design\n   - Type system implementation\n   - Optimization algorithms\n   - Backend code generation\n   - Testing infrastructure\n   - Documentation\n\n3. **Development Process**\n   - Fork the repository\n   - Make changes in a feature branch\n   - Submit pull requests with tests\n   - Participate in code reviews\n\nBy focusing on complementing Rust rather than replacing it, FerroPhase can carve out a valuable niche in the programming language ecosystem, similar to how TypeScript extends JavaScript or how Kotlin enhances Java.\n`","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjakkusakura%2Fferrophase","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjakkusakura%2Fferrophase","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjakkusakura%2Fferrophase/lists"}