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

Fix: insert .clone() invocations before invoking middlewares #346

Merged
merged 6 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 1 addition & 3 deletions libs/pavex_cli/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use anyhow::Result;
use vergen_gitcl::{
Emitter, GitclBuilder,
};
use vergen_gitcl::{Emitter, GitclBuilder};

pub fn main() -> Result<()> {
Emitter::default()
Expand Down
15 changes: 12 additions & 3 deletions libs/pavex_test_runner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,16 @@ fn compile_generated_apps(
cmd.arg("-p").arg(name);
}
let output = cmd
.arg("--all-targets")
.current_dir(runtime_directory)
.output()
.context("Failed to invoke `cargo build` on the generated crates")?;
let build_output = CommandOutput::try_from(&output).context("Failed to parse build output")?;
let mut crate_names2error = BTreeMap::<_, String>::new();
for line in build_output.stderr.lines() {
for line in build_output
.stderr
.lines()
.chain(build_output.stdout.lines())
{
let Ok(cargo_metadata::Message::CompilerMessage(msg)) =
serde_json::from_str::<cargo_metadata::Message>(line)
else {
Expand Down Expand Up @@ -602,9 +605,11 @@ impl TestData {

[package.metadata.px.generate]
generator_type = "cargo_workspace_binary"
generator_name = "app"
generator_name = "dummy"
};
cargo_toml["package"]["name"] = format!("application_{}", self.name_hash).into();
cargo_toml["package"]["metadata"]["px"]["generate"]["generator_name"] =
format!("app_{}", self.name_hash).into();
persist_if_changed(
&application_dir.join("Cargo.toml"),
toml::to_string(&cargo_toml)?.as_bytes(),
Expand Down Expand Up @@ -838,6 +843,10 @@ fn application_code_test(test_name: &str, test: &TestData) -> Trial {

fn build_integration_tests(test_dir: &Path, test_name2test_data: &BTreeMap<String, TestData>) {
let n_integration_tests = test_name2test_data.len();
if n_integration_tests == 0 {
return;
}

let timer = std::time::Instant::now();
println!("Building {n_integration_tests} integration tests, without running them");
let mut cmd = std::process::Command::new("cargo");
Expand Down
10 changes: 6 additions & 4 deletions libs/pavexc/build.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use anyhow::Result;
use vergen_gitcl::{
Emitter, GitclBuilder,
};
use vergen_gitcl::{Emitter, GitclBuilder};

pub fn main() -> Result<()> {
Emitter::default()
.add_instructions(&GitclBuilder::default().describe(true, false, None).build()?)?
.add_instructions(
&GitclBuilder::default()
.describe(true, false, None)
.build()?,
)?
.emit()?;
Ok(())
}
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ fn emit_ancestor_descendant_borrow_error(
if let Some(user_component_id) = component_db.user_component_id(component_id) {
let help_msg = format!(
"Allow me to clone `{contended_type:?}` in order to satisfy the borrow checker.\n\
You can do so by invoking `.cloning(CloningStrategy::CloneIfNecessary)` on the type returned by `.constructor`.",
You can do so by invoking `.clone_if_necessary()` after having registered your constructor.",
);
let location = component_db
.user_component_db()
Expand Down
11 changes: 9 additions & 2 deletions libs/pavexc/src/compiler/analyses/processing_pipeline/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl RequestHandlerPipeline {

let invocations = {
let mut invocations = vec![];
for id in &ordered_by_invocation {
for (index, id) in ordered_by_invocation.iter().enumerate() {
let fn_ = &id2codegened_fn[id].fn_;
if component_db.is_post_processing_middleware(*id) {
input_bindings.0.push(Binding {
Expand Down Expand Up @@ -117,7 +117,14 @@ impl RequestHandlerPipeline {
Input bindings: {bindings}",
input_type)
}
Some(i) => i,
Some(i) => {
let mut output = i.to_token_stream();
if let Some(cloning_indexes) = stage.type2cloning_indexes.get(input_type) {
if cloning_indexes.contains(&index) {
output = quote! { #i.clone() };
} }
output
},
}
});
let await_ = fn_.sig.asyncness.and_then(|_| Some(quote! { .await }));
Expand Down
Loading