diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..d7cafe9 --- /dev/null +++ b/.envrc @@ -0,0 +1,3 @@ +# shellcheck shell=bash +use flake +watch_file rust-toolchain diff --git a/.gitignore b/.gitignore index 2f7896d..a918bcc 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ +.direnv target/ diff --git a/README.md b/README.md index ad7ca00..85e08c9 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,18 @@ # qwik-optimizer -Qwik Optimizer remake +Qwik Optimizer remake **_DISCLAIMER_**: This is very much a work in progress so expect this space to change a lot. ## What + This is a ground up re-implementation of the original Qwik Optimzer. ## Why -The decision was made to mover from SWC to Oxide as the foundation for the Qwik Optimizer. -In the process of doing this, we hope to make the internal Qwik Optimizer more modular and to be more idiomatic Rust. +The decision was made to mover from SWC to Oxide as the foundation for the Qwik Optimizer. +In the process of doing this, we hope to make the internal Qwik Optimizer more modular and to be more idiomatic Rust. ## Modules @@ -27,3 +28,16 @@ This module currently contains metadata info for components. Not much save for the unit tests. +## Nix + +If you have Nix installed, you can enter a development shell with all the necessary dependencies by running: + +```bash +nix develop +``` + +You can also install `direnv` and have it automatically load the development environment when you enter the project directory: + +```bash +direnv allow +``` diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..23a7813 --- /dev/null +++ b/flake.lock @@ -0,0 +1,62 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1758690382, + "narHash": "sha256-NY3kSorgqE5LMm1LqNwGne3ZLMF2/ILgLpFr1fS4X3o=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e643668fd71b949c53f8626614b21ff71a07379d", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1744536153, + "narHash": "sha256-awS2zRgF4uTwrOKwwiJcByDzDOdo3Q1rPZbiHQg/N38=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "18dd725c29603f582cf1900e0d25f9f1063dbf11", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1758940228, + "narHash": "sha256-sTS04L9LKqzP1oiVXYDwcMzfFSF0DnSJQFzZBpEgLFE=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "5bfedf3fbbf5caf8e39f7fcd62238f54d82aa1e2", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..6ec50a8 --- /dev/null +++ b/flake.nix @@ -0,0 +1,37 @@ +# This is a Nix configuration file. It is used to define the environment +# for the project. It is a declarative way to define the dependencies. +# It is used by the `nix develop` command to create a development environment +# with all the dependencies needed for the project. + +# To update the dependencies, run `nix flake update`. +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + rust-overlay.url = "github:oxalica/rust-overlay"; + }; + + outputs = { self, rust-overlay, nixpkgs }: + let + b = builtins; + devShell = system: _pkgs: + let + overlays = [ (import rust-overlay) ]; + pkgs = import nixpkgs { inherit system overlays; }; + in { + default = pkgs.mkShell { + nativeBuildInputs = with pkgs; [ + bashInteractive + gitMinimal + + # Provides rustc and cargo + (rust-bin.stable.latest.default.override { + # For rust-analyzer + extensions = [ "rust-src" ]; + # For building wasm + targets = [ "wasm32-unknown-unknown" ]; + }) + ]; + }; + }; + in { devShells = b.mapAttrs (devShell) nixpkgs.legacyPackages; }; +} diff --git a/optimizer/src/component/component.rs b/optimizer/src/component/component.rs index 8f6cc1e..ed4c1dd 100644 --- a/optimizer/src/component/component.rs +++ b/optimizer/src/component/component.rs @@ -55,7 +55,7 @@ impl QrlComponent { exported_expression: Expression<'_>, imports: Vec, source_type: &SourceType, - source_info: &SourceInfo, + _source_info: &SourceInfo, allocator: &Allocator, ) -> String { let name = &id.symbol_name; diff --git a/optimizer/src/component/id.rs b/optimizer/src/component/id.rs index 3df964d..e6f5909 100644 --- a/optimizer/src/component/id.rs +++ b/optimizer/src/component/id.rs @@ -127,7 +127,7 @@ impl Id { /// - The `scope` (if provided). /// /// [V 1.0 REF] see `QwikTransform.register_context_name` in `transform.rs. - pub fn new( + pub(crate) fn new( source_info: &SourceInfo, segments: &Vec, target: &Target, diff --git a/optimizer/src/component/qrl.rs b/optimizer/src/component/qrl.rs index 23fcfab..287ddfe 100644 --- a/optimizer/src/component/qrl.rs +++ b/optimizer/src/component/qrl.rs @@ -1,10 +1,10 @@ use crate::component::{Import, QRL, QRL_SUFFIX, QWIK_CORE_SOURCE}; use crate::ext::AstBuilderExt; -use oxc_allocator::{Allocator, Box as OxcBox, CloneIn, FromIn, IntoIn, Vec as OxcVec}; +use oxc_allocator::{Allocator, Box as OxcBox, CloneIn, FromIn, Vec as OxcVec}; use oxc_ast::ast::*; use oxc_ast::AstBuilder; use oxc_semantic::{NodeId, ReferenceFlags, ReferenceId, ScopeId, SymbolFlags, SymbolId}; -use oxc_span::{Atom, SPAN}; +use oxc_span::SPAN; use oxc_traverse::TraverseCtx; use serde::Serialize; use std::collections::HashMap; diff --git a/optimizer/src/entry_strategy.rs b/optimizer/src/entry_strategy.rs index 11fe82c..9bce869 100644 --- a/optimizer/src/entry_strategy.rs +++ b/optimizer/src/entry_strategy.rs @@ -69,7 +69,7 @@ impl PerComponentStrategy { } impl EntryPolicy for PerComponentStrategy { - fn get_entry_for_sym(&self, context: &[String], segment: &Segment) -> Option { + fn get_entry_for_sym(&self, _context: &[String], _segment: &Segment) -> Option { panic!("Not implemented") /* context.first().map_or_else( @@ -90,7 +90,7 @@ impl SmartStrategy { } impl EntryPolicy for SmartStrategy { - fn get_entry_for_sym(&self, context: &[String], segment: &Segment) -> Option { + fn get_entry_for_sym(&self, _context: &[String], _segment: &Segment) -> Option { panic!("Not implemented") /* // Event handlers without scope variables are put into a separate file diff --git a/optimizer/src/illegal_code.rs b/optimizer/src/illegal_code.rs index b08e8ec..aa17164 100644 --- a/optimizer/src/illegal_code.rs +++ b/optimizer/src/illegal_code.rs @@ -52,7 +52,7 @@ impl IllegalCode for Statement<'_> { bid.and_then(|bid| bid.symbol_id.get()) .map(|id| IllegalCodeType::Class(id, cd.name().map(String::from))) } - s => None, + _s => None, } } } diff --git a/optimizer/src/import_clean_up.rs b/optimizer/src/import_clean_up.rs index 70822b3..3904f53 100644 --- a/optimizer/src/import_clean_up.rs +++ b/optimizer/src/import_clean_up.rs @@ -20,7 +20,7 @@ impl ImportCleanUp<'_> { pub fn clean_up<'a>(program: &mut Program<'a>, allocator: &'a Allocator) { let SemanticBuilderReturn { semantic, - errors: semantic_errors, + errors: _semantic_errors, } = SemanticBuilder::new().build(program); let scoping = semantic.into_scoping();