Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Singletons should be Send, Sync and Clone #7

Merged
merged 25 commits into from
Nov 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
81f98a6
Failing test: Singletons must be Clone.
LukeMathWalker Nov 10, 2022
66290da
Write data structure that allows to insert new elements without using…
LukeMathWalker Nov 11, 2022
71ed132
Draft Sync check
LukeMathWalker Nov 14, 2022
16d51ca
Fix handling of hyphens and "wrong" versions in the rustdoc module.
LukeMathWalker Nov 17, 2022
8d73b37
Add `tracing`.
LukeMathWalker Nov 19, 2022
61841de
Extract into function.
LukeMathWalker Nov 19, 2022
dfd85b9
Implement error + rendering diagnostic.
LukeMathWalker Nov 19, 2022
2592de6
Fix trait resolution.
LukeMathWalker Nov 19, 2022
fa8335e
Fix package search
LukeMathWalker Nov 19, 2022
f1fcbae
Fix error reporting when dealing with references.
LukeMathWalker Nov 19, 2022
a4c0266
Clippy fixes
LukeMathWalker Nov 19, 2022
dd24ef6
Remove unused parameter.
LukeMathWalker Nov 19, 2022
183c74c
Fix more clippy lints
LukeMathWalker Nov 19, 2022
46c3028
Fix test expected error message.
LukeMathWalker Nov 19, 2022
24c5e8c
Fix Clone checking. Send seems to be broken.
LukeMathWalker Nov 19, 2022
5840359
Green.
LukeMathWalker Nov 19, 2022
5ad1609
Sync :check:
LukeMathWalker Nov 19, 2022
2e6f79a
Implement Clone
LukeMathWalker Nov 19, 2022
fed593a
Remove stray dbg.
LukeMathWalker Nov 19, 2022
0c4590d
Be careful with namespaces.
LukeMathWalker Nov 20, 2022
625769f
Add nice help message explaining why we care about those traits.
LukeMathWalker Nov 20, 2022
3fa6379
Update example
LukeMathWalker Nov 20, 2022
2eb7cb6
Add rudimentary tracing instrumentation.
LukeMathWalker Nov 20, 2022
40fce3d
More instrumentation.
LukeMathWalker Nov 20, 2022
970264c
Remove wasteful clone.
LukeMathWalker Nov 20, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions examples/app_blueprint/blueprint.ron
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
),
],
component_lifecycles: {
(
registered_at: "app_blueprint",
import_path: "crate :: http_client",
): Singleton,
(
registered_at: "app_blueprint",
import_path: "crate :: extract_path",
Expand All @@ -28,10 +32,6 @@
registered_at: "app_blueprint",
import_path: "crate :: logger",
): Transient,
(
registered_at: "app_blueprint",
import_path: "crate :: http_client",
): Singleton,
},
router: {
"/home": (
Expand All @@ -54,25 +54,25 @@
constructor_locations: {
(
registered_at: "app_blueprint",
import_path: "crate :: extract_path",
import_path: "crate :: http_client",
): (
line: 39,
line: 38,
column: 10,
file: "examples/app_blueprint/src/lib.rs",
),
(
registered_at: "app_blueprint",
import_path: "crate :: http_client",
import_path: "crate :: logger",
): (
line: 38,
line: 40,
column: 10,
file: "examples/app_blueprint/src/lib.rs",
),
(
registered_at: "app_blueprint",
import_path: "crate :: logger",
import_path: "crate :: extract_path",
): (
line: 40,
line: 39,
column: 10,
file: "examples/app_blueprint/src/lib.rs",
),
Expand Down
2 changes: 2 additions & 0 deletions libs/pavex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ itertools = "0.10.3"
cargo-manifest = "0.3"
toml = "0.5"
pathdiff = "0.2.1"
elsa = "1.4.0"
tracing = "0.1"
38 changes: 30 additions & 8 deletions libs/pavex/src/rustdoc/compute.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use std::path::{Path, PathBuf};

use anyhow::Context;
use guppy::Version;

use crate::rustdoc::package_id_spec::PackageIdSpecification;
use crate::rustdoc::utils::normalize_crate_name;
use crate::rustdoc::TOOLCHAIN_CRATES;

#[derive(Debug, thiserror::Error)]
Expand All @@ -13,6 +15,17 @@ pub struct CannotGetCrateData {
pub source: anyhow::Error,
}

fn format_optional_version(v: &Option<Version>) -> Option<tracing::field::DisplayValue<String>> {
v.as_ref().map(|v| {
use std::fmt::Write;
let mut s = format!("v{}.{}.{}", v.major, v.minor, v.patch);
if !v.pre.is_empty() {
write!(&mut s, "-{}", v.pre).unwrap();
}
tracing::field::display(s)
})
}

/// Return the JSON documentation for a crate.
/// The crate is singled out, within the current workspace, using a [`PackageIdSpecification`].
///
Expand All @@ -21,7 +34,15 @@ pub struct CannotGetCrateData {
///
/// `root_folder` is `cargo`'s target directory for the current workspace: that is where we are
/// going to look for the JSON files generated by `rustdoc`.
pub(super) fn get_crate_data(
#[tracing::instrument(
skip_all,
fields(
crate.name = package_id_spec.name,
crate.version = format_optional_version(& package_id_spec.version),
crate.source = package_id_spec.source
)
)]
pub(super) fn compute_crate_docs(
root_folder: &Path,
package_id_spec: &PackageIdSpecification,
) -> Result<rustdoc_types::Crate, CannotGetCrateData> {
Expand All @@ -34,17 +55,17 @@ pub(super) fn get_crate_data(
// documentation on the fly. We assume that their JSON docs have been pre-computed and are
// available for us to look at.
if TOOLCHAIN_CRATES.contains(&package_id_spec.name.as_str()) {
get_toolchain_crate_data(package_id_spec)
get_toolchain_crate_docs(package_id_spec)
} else {
_get_crate_data(root_folder, package_id_spec)
_compute_crate_docs(root_folder, package_id_spec)
}
.map_err(|e| CannotGetCrateData {
package_spec: package_id_spec.to_string(),
source: e,
})
}

fn get_toolchain_crate_data(
fn get_toolchain_crate_docs(
package_id_spec: &PackageIdSpecification,
) -> Result<rustdoc_types::Crate, anyhow::Error> {
let root_folder = get_json_docs_root_folder_via_rustup()?;
Expand Down Expand Up @@ -113,7 +134,7 @@ fn get_nightly_toolchain_root_folder_via_rustup() -> Result<PathBuf, anyhow::Err
Ok(path.parent().unwrap().parent().unwrap().to_path_buf())
}

fn _get_crate_data(
fn _compute_crate_docs(
target_directory: &Path,
package_id_spec: &PackageIdSpecification,
) -> Result<rustdoc_types::Crate, anyhow::Error> {
Expand Down Expand Up @@ -142,9 +163,10 @@ fn _get_crate_data(
);
}

let json_path = target_directory
.join("doc")
.join(format!("{}.json", &package_id_spec.name));
let json_path = target_directory.join("doc").join(format!(
"{}.json",
normalize_crate_name(&package_id_spec.name)
));

let json = fs_err::read_to_string(json_path).with_context(|| {
format!(
Expand Down
1 change: 1 addition & 0 deletions libs/pavex/src/rustdoc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub use queries::{Crate, CrateCollection, GlobalTypeId, UnknownTypePath};
mod compute;
mod package_id_spec;
mod queries;
mod utils;

pub const STD_PACKAGE_ID: &str = "std";
pub const TOOLCHAIN_CRATES: [&str; 3] = ["std", "core", "alloc"];
Loading