git.delta.rocks / jrsonnet / refs/commits / e7e620bf3687

difftreelog

Merge pull request #138 from CertainLach/stable-async-traits

Yaroslav Bolyukin2023-10-29parents: #fd582d4 #69bb25d.patch.diff
in: master

7 files changed

modified.github/workflows/clippy_check.ymldiffbeforeafterboth
--- a/.github/workflows/clippy_check.yml
+++ b/.github/workflows/clippy_check.yml
@@ -7,7 +7,7 @@
       - uses: actions/checkout@v2
       - uses: actions-rs/toolchain@v1
         with:
-            toolchain: nightly
+            toolchain: nightly-2023-10-28
             components: clippy
             override: true
       - uses: actions-rs/clippy-check@v1
modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -112,17 +112,6 @@
 ]
 
 [[package]]
-name = "async-trait"
-version = "0.1.74"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn 2.0.38",
-]
-
-[[package]]
 name = "autocfg"
 version = "1.1.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -598,7 +587,6 @@
 dependencies = [
  "annotate-snippets",
  "anyhow",
- "async-trait",
  "bincode",
  "derivative",
  "hashbrown 0.14.2",
@@ -801,34 +789,25 @@
 
 [[package]]
 name = "logos"
-version = "0.13.0"
+version = "0.12.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c000ca4d908ff18ac99b93a062cb8958d331c3220719c52e77cb19cc6ac5d2c1"
+checksum = "bf8b031682c67a8e3d5446840f9573eb7fe26efe7ec8d195c9ac4c0647c502f1"
 dependencies = [
  "logos-derive",
 ]
 
 [[package]]
-name = "logos-codegen"
-version = "0.13.0"
+name = "logos-derive"
+version = "0.12.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "dc487311295e0002e452025d6b580b77bb17286de87b57138f3b5db711cded68"
+checksum = "a1d849148dbaf9661a6151d1ca82b13bb4c4c128146a88d05253b38d4e2f496c"
 dependencies = [
  "beef",
  "fnv",
  "proc-macro2",
  "quote",
  "regex-syntax",
- "syn 2.0.38",
-]
-
-[[package]]
-name = "logos-derive"
-version = "0.13.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "dbfc0d229f1f42d790440136d941afd806bc9e949e2bcb8faa813b0f00d1267e"
-dependencies = [
- "logos-codegen",
+ "syn 1.0.109",
 ]
 
 [[package]]
modifiedCargo.tomldiffbeforeafterboth
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -35,7 +35,6 @@
 rustc-hash = "1.1"
 bincode = "1.3"
 annotate-snippets = "0.9.1"
-async-trait = "0.1.60"
 num-bigint = "0.4.3"
 derivative = "2.2.0"
 strsim = "0.10.0"
@@ -45,7 +44,7 @@
 syn = "2.0"
 peg = "0.8.2"
 drop_bomb = "0.1.5"
-logos = "0.13.0"
+logos = "0.12.0"
 miette = "5.5.0"
 rowan = "0.15"
 text-size = "1.1"
modifiedcrates/jrsonnet-evaluator/Cargo.tomldiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/Cargo.toml
+++ b/crates/jrsonnet-evaluator/Cargo.toml
@@ -14,7 +14,7 @@
 # Allows library authors to throw custom errors
 anyhow-error = ["anyhow"]
 # Adds ability to build import closure in async
-async-import = ["async-trait"]
+async-import = []
 
 # Allows to preserve field order in objects
 exp-preserve-order = []
@@ -54,8 +54,6 @@
 bincode = { workspace = true, optional = true }
 # Explaining traces
 annotate-snippets = { workspace = true, features = ["color"], optional = true }
-# Async imports
-async-trait = { workspace = true, optional = true }
 # Bigint
 num-bigint = { workspace = true, features = ["serde"], optional = true }
 derivative.workspace = true
modifiedcrates/jrsonnet-evaluator/src/async_import.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/async_import.rs
+++ b/crates/jrsonnet-evaluator/src/async_import.rs
@@ -1,6 +1,5 @@
-use std::{cell::RefCell, path::Path};
+use std::{cell::RefCell, future::Future, path::Path};
 
-use async_trait::async_trait;
 use jrsonnet_gcmodule::Trace;
 use jrsonnet_interner::IStr;
 use jrsonnet_parser::{
@@ -218,26 +217,37 @@
 	}
 }
 
-#[async_trait(?Send)]
 pub trait AsyncImportResolver {
 	type Error;
 	/// Resolves file path, e.g. `(/home/user/manifests, b.libjsonnet)` can correspond
 	/// both to `/home/user/manifests/b.libjsonnet` and to `/home/user/${vendor}/b.libjsonnet`
 	/// where `${vendor}` is a library path.
 	///
-	/// `from` should only be returned from [`ImportResolver::resolve`], or from other defined file, any other value
-	/// may result in panic
-	async fn resolve_from(&self, from: &SourcePath, path: &str) -> Result<SourcePath, Self::Error>;
-	async fn resolve_from_default(&self, path: &str) -> Result<SourcePath, Self::Error> {
-		self.resolve_from(&SourcePath::default(), path).await
+	/// `from` should only be returned from [`ImportResolver::resolve`],
+	/// or from other defined file, any other value may result in panic
+	fn resolve_from(
+		&self,
+		from: &SourcePath,
+		path: &str,
+	) -> impl Future<Output = Result<SourcePath, Self::Error>>;
+	fn resolve_from_default(
+		&self,
+		path: &str,
+	) -> impl Future<Output = Result<SourcePath, Self::Error>> {
+		async { self.resolve_from(&SourcePath::default(), path).await }
 	}
 	/// Resolves absolute path, doesn't supports jpath and other fancy things
-	async fn resolve(&self, path: &Path) -> Result<SourcePath, Self::Error>;
+	fn resolve(&self, path: &Path) -> impl Future<Output = Result<SourcePath, Self::Error>>;
 
 	/// Load resolved file
-	/// This should only be called with value returned from [`ImportResolver::resolve_file`]/[`ImportResolver::resolve`],
-	/// this cannot be resolved using associated type, as evaluator uses object instead of generic for [`ImportResolver`]
-	async fn load_file_contents(&self, resolved: &SourcePath) -> Result<Vec<u8>, Self::Error>;
+	/// This should only be called with value returned
+	/// from [`ImportResolver::resolve_file`]/[`ImportResolver::resolve`],
+	/// this cannot be resolved using associated type,
+	/// as the evaluator uses object instead of generic for [`ImportResolver`]
+	fn load_file_contents(
+		&self,
+		resolved: &SourcePath,
+	) -> impl Future<Output = Result<Vec<u8>, Self::Error>>;
 }
 
 #[derive(Trace)]
modifiedflake.nixdiffbeforeafterboth
before · flake.nix
1{2  description = "Jrsonnet";3  inputs = {4    nixpkgs.url = "github:nixos/nixpkgs";5    flake-utils.url = "github:numtide/flake-utils";6    rust-overlay = {7      url = "github:oxalica/rust-overlay";8      inputs.nixpkgs.follows = "nixpkgs";9      inputs.flake-utils.follows = "flake-utils";10    };11  };12  outputs = {13    nixpkgs,14    flake-utils,15    rust-overlay,16    ...17  }:18    flake-utils.lib.eachSystem (with flake-utils.lib.system; [x86_64-linux x86_64-windows]) (19      system: let20        pkgs = import nixpkgs {21          inherit system;22          overlays = [rust-overlay.overlays.default];23          config.allowUnsupportedSystem = true;24        };25        lib = pkgs.lib;26        rust =27          (pkgs.rustChannelOf {28            date = "2023-08-02";29            channel = "nightly";30          })31          .default32          .override {33            extensions = ["rust-src" "miri" "rust-analyzer" "clippy"];34          };35      in rec {36        packages = rec {37          go-jsonnet = pkgs.callPackage ./nix/go-jsonnet.nix {};38          sjsonnet = pkgs.callPackage ./nix/sjsonnet.nix {};39          jsonnet = pkgs.callPackage ./nix/jsonnet.nix {};40          # I didn't managed to build it, and nixpkgs version is marked as broken41          # haskell-jsonnet = pkgs.callPackage ./nix/haskell-jsonnet.nix { };42          jrsonnet = pkgs.callPackage ./nix/jrsonnet.nix {43            rustPlatform = pkgs.makeRustPlatform {44              rustc = rust;45              cargo = rust;46            };47          };48          jrsonnet-nightly = pkgs.callPackage ./nix/jrsonnet.nix {49            rustPlatform = pkgs.makeRustPlatform {50              rustc = rust;51              cargo = rust;52            };53            withNightlyFeatures = true;54          };55          jrsonnet-release = pkgs.callPackage ./nix/jrsonnet-release.nix {56            rustPlatform = pkgs.makeRustPlatform {57              rustc = rust;58              cargo = rust;59            };60          };6162          benchmarks = pkgs.callPackage ./nix/benchmarks.nix {63            inherit go-jsonnet sjsonnet jsonnet;64            jrsonnetVariants = [65              {66                drv = jrsonnet;67                name = "";68              }69            ];70          };71          benchmarks-quick = pkgs.callPackage ./nix/benchmarks.nix {72            inherit go-jsonnet sjsonnet jsonnet;73            quick = true;74            jrsonnetVariants = [75              {76                drv = jrsonnet;77                name = "";78              }79            ];80          };81          benchmarks-against-release = pkgs.callPackage ./nix/benchmarks.nix {82            inherit go-jsonnet sjsonnet jsonnet;83            jrsonnetVariants = [84              {85                drv = jrsonnet;86                name = "current";87              }88              {89                drv = jrsonnet-nightly;90                name = "current-nightly";91              }92              {93                drv = jrsonnet-release;94                name = "release";95              }96            ];97          };98          benchmarks-quick-against-release = pkgs.callPackage ./nix/benchmarks.nix {99            inherit go-jsonnet sjsonnet jsonnet;100            quick = true;101            jrsonnetVariants = [102              {103                drv = jrsonnet;104                name = "current";105              }106              {107                drv = jrsonnet-nightly;108                name = "current-nightly";109              }110              {111                drv = jrsonnet-release;112                name = "release";113              }114            ];115          };116        };117        packagesCross = lib.genAttrs ["mingwW64"] (crossSystem: let118          callPackage = pkgs.pkgsCross.${crossSystem}.callPackage;119        in {120          jrsonnet = callPackage ./nix/jrsonnet.nix {121            # rustPlatform = pkgs.makeRustPlatform {122            #   rustc = rust;123            #   cargo = rust;124            # };125          };126        });127        devShells.default = pkgs.mkShell {128          nativeBuildInputs = with pkgs; [129            alejandra130            rust131            cargo-edit132            cargo-asm133            cargo-outdated134            cargo-watch135            cargo-insta136            lld137            hyperfine138            graphviz139          ];140        };141      }142    );143}
after · flake.nix
1{2  description = "Jrsonnet";3  inputs = {4    nixpkgs.url = "github:nixos/nixpkgs";5    flake-utils.url = "github:numtide/flake-utils";6    rust-overlay = {7      url = "github:oxalica/rust-overlay";8      inputs.nixpkgs.follows = "nixpkgs";9      inputs.flake-utils.follows = "flake-utils";10    };11  };12  outputs = {13    nixpkgs,14    flake-utils,15    rust-overlay,16    ...17  }:18    flake-utils.lib.eachSystem (with flake-utils.lib.system; [x86_64-linux x86_64-windows]) (19      system: let20        pkgs = import nixpkgs {21          inherit system;22          overlays = [rust-overlay.overlays.default];23          config.allowUnsupportedSystem = true;24        };25        lib = pkgs.lib;26        rust =27          (pkgs.rustChannelOf {28            date = "2023-10-28";29            channel = "nightly";30          })31          .default32          .override {33            extensions = ["rust-src" "miri" "rust-analyzer" "clippy"];34          };35      in rec {36        packages = rec {37          go-jsonnet = pkgs.callPackage ./nix/go-jsonnet.nix {};38          sjsonnet = pkgs.callPackage ./nix/sjsonnet.nix {};39          jsonnet = pkgs.callPackage ./nix/jsonnet.nix {};40          # I didn't managed to build it, and nixpkgs version is marked as broken41          # haskell-jsonnet = pkgs.callPackage ./nix/haskell-jsonnet.nix { };42          jrsonnet = pkgs.callPackage ./nix/jrsonnet.nix {43            rustPlatform = pkgs.makeRustPlatform {44              rustc = rust;45              cargo = rust;46            };47          };48          jrsonnet-nightly = pkgs.callPackage ./nix/jrsonnet.nix {49            rustPlatform = pkgs.makeRustPlatform {50              rustc = rust;51              cargo = rust;52            };53            withNightlyFeatures = true;54          };55          jrsonnet-release = pkgs.callPackage ./nix/jrsonnet-release.nix {56            rustPlatform = pkgs.makeRustPlatform {57              rustc = rust;58              cargo = rust;59            };60          };6162          benchmarks = pkgs.callPackage ./nix/benchmarks.nix {63            inherit go-jsonnet sjsonnet jsonnet;64            jrsonnetVariants = [65              {66                drv = jrsonnet;67                name = "";68              }69            ];70          };71          benchmarks-quick = pkgs.callPackage ./nix/benchmarks.nix {72            inherit go-jsonnet sjsonnet jsonnet;73            quick = true;74            jrsonnetVariants = [75              {76                drv = jrsonnet;77                name = "";78              }79            ];80          };81          benchmarks-against-release = pkgs.callPackage ./nix/benchmarks.nix {82            inherit go-jsonnet sjsonnet jsonnet;83            jrsonnetVariants = [84              {85                drv = jrsonnet;86                name = "current";87              }88              {89                drv = jrsonnet-nightly;90                name = "current-nightly";91              }92              {93                drv = jrsonnet-release;94                name = "release";95              }96            ];97          };98          benchmarks-quick-against-release = pkgs.callPackage ./nix/benchmarks.nix {99            inherit go-jsonnet sjsonnet jsonnet;100            quick = true;101            jrsonnetVariants = [102              {103                drv = jrsonnet;104                name = "current";105              }106              {107                drv = jrsonnet-nightly;108                name = "current-nightly";109              }110              {111                drv = jrsonnet-release;112                name = "release";113              }114            ];115          };116        };117        packagesCross = lib.genAttrs ["mingwW64"] (crossSystem: let118          callPackage = pkgs.pkgsCross.${crossSystem}.callPackage;119        in {120          jrsonnet = callPackage ./nix/jrsonnet.nix {121            # rustPlatform = pkgs.makeRustPlatform {122            #   rustc = rust;123            #   cargo = rust;124            # };125          };126        });127        devShells.default = pkgs.mkShell {128          nativeBuildInputs = with pkgs; [129            alejandra130            rust131            cargo-edit132            cargo-asm133            cargo-outdated134            cargo-watch135            cargo-insta136            lld137            hyperfine138            graphviz139          ];140        };141      }142    );143}
addedrust-toolchain.tomldiffbeforeafterboth
--- /dev/null
+++ b/rust-toolchain.toml
@@ -0,0 +1,3 @@
+[toolchain]
+channel = "nightly-2023-10-28"
+components = ["rustfmt", "clippy"]