Skip to content

Commit

Permalink
[Turbopack] Revert "refactor filesystem writes to an effect based sys…
Browse files Browse the repository at this point in the history
…tem" (#73287)

Revert "Turbopack: apply effects in tests (#72952)"

This reverts commit b6b5ab8.

Revert "[Turbopack] fix effects tracing (#72928)"

This reverts commit 0714c45.

Revert "[Turbopack] refactor filesystem writes to an effect based system (#72847)"

This reverts commit be9b2dd.

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the PR.
- Read the Docs Contribution Guide to ensure your contribution follows the docs guidelines: https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See: https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. (A discussion must be opened, see https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added (https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to understand the PR)
- When linking to a Slack thread, you might want to share details of the conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->
  • Loading branch information
sokra authored Nov 27, 2024
1 parent fdaf35b commit 491e9c1
Show file tree
Hide file tree
Showing 31 changed files with 556 additions and 913 deletions.
31 changes: 10 additions & 21 deletions crates/napi/src/next_api/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use next_api::{
route::{Endpoint, WrittenEndpoint},
};
use tracing::Instrument;
use turbo_tasks::{get_effects, Completion, Effects, ReadRef, Vc, VcValueType};
use turbo_tasks::{Completion, ReadRef, Vc, VcValueType};
use turbopack_core::{
diagnostics::PlainDiagnostic,
error::PrettyPrintError,
Expand Down Expand Up @@ -104,42 +104,38 @@ async fn strongly_consistent_catch_collectables<R: VcValueType + Send>(
Option<ReadRef<R>>,
Arc<Vec<ReadRef<PlainIssue>>>,
Arc<Vec<ReadRef<PlainDiagnostic>>>,
Arc<Effects>,
)> {
let result = source.strongly_consistent().await;
let issues = get_issues(source).await?;
let diagnostics = get_diagnostics(source).await?;
let effects = Arc::new(get_effects(source).await?);

let result = if result.is_err() && issues.iter().any(|i| i.severity <= IssueSeverity::Error) {
None
} else {
Some(result?)
};

Ok((result, issues, diagnostics, effects))
Ok((result, issues, diagnostics))
}

#[turbo_tasks::value(serialization = "none")]
struct WrittenEndpointWithIssues {
written: Option<ReadRef<WrittenEndpoint>>,
issues: Arc<Vec<ReadRef<PlainIssue>>>,
diagnostics: Arc<Vec<ReadRef<PlainDiagnostic>>>,
effects: Arc<Effects>,
}

#[turbo_tasks::function]
async fn get_written_endpoint_with_issues(
endpoint: Vc<Box<dyn Endpoint>>,
) -> Result<Vc<WrittenEndpointWithIssues>> {
let write_to_disk = endpoint.write_to_disk();
let (written, issues, diagnostics, effects) =
let (written, issues, diagnostics) =
strongly_consistent_catch_collectables(write_to_disk).await?;
Ok(WrittenEndpointWithIssues {
written,
issues,
diagnostics,
effects,
}
.cell())
}
Expand All @@ -153,15 +149,13 @@ pub async fn endpoint_write_to_disk(
let endpoint = ***endpoint;
let (written, issues, diags) = turbo_tasks
.run_once(async move {
let operation = get_written_endpoint_with_issues(endpoint);
let WrittenEndpointWithIssues {
written,
issues,
diagnostics,
effects,
} = &*operation.strongly_consistent().await?;
effects.apply().await?;

} = &*get_written_endpoint_with_issues(endpoint)
.strongly_consistent()
.await?;
Ok((written.clone(), issues.clone(), diagnostics.clone()))
})
.await
Expand All @@ -186,10 +180,9 @@ pub fn endpoint_server_changed_subscribe(
func,
move || {
async move {
let operation = subscribe_issues_and_diags(endpoint, issues);
let result = operation.strongly_consistent().await?;
result.effects.apply().await?;
Ok(result)
subscribe_issues_and_diags(endpoint, issues)
.strongly_consistent()
.await
}
.instrument(tracing::info_span!("server changes subscription"))
},
Expand All @@ -198,7 +191,6 @@ pub fn endpoint_server_changed_subscribe(
changed: _,
issues,
diagnostics,
effects: _,
} = &*ctx.value;

Ok(vec![TurbopackResult {
Expand All @@ -218,7 +210,6 @@ struct EndpointIssuesAndDiags {
changed: Option<ReadRef<Completion>>,
issues: Arc<Vec<ReadRef<PlainIssue>>>,
diagnostics: Arc<Vec<ReadRef<PlainDiagnostic>>>,
effects: Arc<Effects>,
}

impl PartialEq for EndpointIssuesAndDiags {
Expand All @@ -242,13 +233,12 @@ async fn subscribe_issues_and_diags(
let changed = endpoint.server_changed();

if should_include_issues {
let (changed_value, issues, diagnostics, effects) =
let (changed_value, issues, diagnostics) =
strongly_consistent_catch_collectables(changed).await?;
Ok(EndpointIssuesAndDiags {
changed: changed_value,
issues,
diagnostics,
effects,
}
.cell())
} else {
Expand All @@ -257,7 +247,6 @@ async fn subscribe_issues_and_diags(
changed: Some(changed_value),
issues: Arc::new(vec![]),
diagnostics: Arc::new(vec![]),
effects: Arc::new(Effects::default()),
}
.cell())
}
Expand Down
32 changes: 10 additions & 22 deletions crates/napi/src/next_api/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use tokio::{io::AsyncWriteExt, time::Instant};
use tracing::Instrument;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter, Registry};
use turbo_rcstr::RcStr;
use turbo_tasks::{get_effects, Completion, Effects, ReadRef, TransientInstance, UpdateInfo, Vc};
use turbo_tasks::{Completion, ReadRef, TransientInstance, UpdateInfo, Vc};
use turbo_tasks_fs::{
util::uri_from_file, DiskFileSystem, FileContent, FileSystem, FileSystemPath,
};
Expand Down Expand Up @@ -623,7 +623,6 @@ struct EntrypointsWithIssues {
entrypoints: ReadRef<Entrypoints>,
issues: Arc<Vec<ReadRef<PlainIssue>>>,
diagnostics: Arc<Vec<ReadRef<PlainDiagnostic>>>,
effects: Arc<Effects>,
}

#[turbo_tasks::function]
Expand All @@ -634,12 +633,10 @@ async fn get_entrypoints_with_issues(
let entrypoints = entrypoints_operation.strongly_consistent().await?;
let issues = get_issues(entrypoints_operation).await?;
let diagnostics = get_diagnostics(entrypoints_operation).await?;
let effects = Arc::new(get_effects(entrypoints_operation).await?);
Ok(EntrypointsWithIssues {
entrypoints,
issues,
diagnostics,
effects,
}
.cell())
}
Expand All @@ -656,14 +653,13 @@ pub fn project_entrypoints_subscribe(
func,
move || {
async move {
let operation = get_entrypoints_with_issues(container);
let EntrypointsWithIssues {
entrypoints,
issues,
diagnostics,
effects,
} = &*operation.strongly_consistent().await?;
effects.apply().await?;
} = &*get_entrypoints_with_issues(container)
.strongly_consistent()
.await?;
Ok((entrypoints.clone(), issues.clone(), diagnostics.clone()))
}
.instrument(tracing::info_span!("entrypoints subscription"))
Expand Down Expand Up @@ -722,7 +718,6 @@ struct HmrUpdateWithIssues {
update: ReadRef<Update>,
issues: Arc<Vec<ReadRef<PlainIssue>>>,
diagnostics: Arc<Vec<ReadRef<PlainDiagnostic>>>,
effects: Arc<Effects>,
}

#[turbo_tasks::function]
Expand All @@ -735,12 +730,10 @@ async fn hmr_update(
let update = update_operation.strongly_consistent().await?;
let issues = get_issues(update_operation).await?;
let diagnostics = get_diagnostics(update_operation).await?;
let effects = Arc::new(get_effects(update_operation).await?);
Ok(HmrUpdateWithIssues {
update,
issues,
diagnostics,
effects,
}
.cell())
}
Expand All @@ -767,15 +760,14 @@ pub fn project_hmr_events(
let project = project.project().resolve().await?;
let state = project.hmr_version_state(identifier.clone(), session);

let operation = hmr_update(project, identifier.clone(), state);
let update = operation.strongly_consistent().await?;
let update = hmr_update(project, identifier.clone(), state)
.strongly_consistent()
.await?;
let HmrUpdateWithIssues {
update,
issues,
diagnostics,
effects,
} = &*update;
effects.apply().await?;
match &**update {
Update::Missing | Update::None => {}
Update::Total(TotalUpdate { to }) => {
Expand Down Expand Up @@ -840,7 +832,6 @@ struct HmrIdentifiersWithIssues {
identifiers: ReadRef<Vec<RcStr>>,
issues: Arc<Vec<ReadRef<PlainIssue>>>,
diagnostics: Arc<Vec<ReadRef<PlainDiagnostic>>>,
effects: Arc<Effects>,
}

#[turbo_tasks::function]
Expand All @@ -851,12 +842,10 @@ async fn get_hmr_identifiers_with_issues(
let hmr_identifiers = hmr_identifiers_operation.strongly_consistent().await?;
let issues = get_issues(hmr_identifiers_operation).await?;
let diagnostics = get_diagnostics(hmr_identifiers_operation).await?;
let effects = Arc::new(get_effects(hmr_identifiers_operation).await?);
Ok(HmrIdentifiersWithIssues {
identifiers: hmr_identifiers,
issues,
diagnostics,
effects,
}
.cell())
}
Expand All @@ -872,14 +861,13 @@ pub fn project_hmr_identifiers_subscribe(
turbo_tasks.clone(),
func,
move || async move {
let operation = get_hmr_identifiers_with_issues(container);
let HmrIdentifiersWithIssues {
identifiers,
issues,
diagnostics,
effects,
} = &*operation.strongly_consistent().await?;
effects.apply().await?;
} = &*get_hmr_identifiers_with_issues(container)
.strongly_consistent()
.await?;

Ok((identifiers.clone(), issues.clone(), diagnostics.clone()))
},
Expand Down
6 changes: 3 additions & 3 deletions crates/next-api/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1633,10 +1633,10 @@ impl Endpoint for AppEndpoint {

let node_root_ref = &node_root.await?;

let _ = this
.app_project
this.app_project
.project()
.emit_all_output_assets(Vc::cell(output_assets));
.emit_all_output_assets(Vc::cell(output_assets))
.await?;

let (server_paths, client_paths) = if this
.app_project
Expand Down
4 changes: 3 additions & 1 deletion crates/next-api/src/instrumentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,9 @@ impl Endpoint for InstrumentationEndpoint {
let this = self.await?;
let output_assets = self.output_assets();
let _ = output_assets.resolve().await?;
let _ = this.project.emit_all_output_assets(Vc::cell(output_assets));
this.project
.emit_all_output_assets(Vc::cell(output_assets))
.await?;

let server_paths = if this.project.next_mode().await?.is_development() {
let node_root = this.project.node_root();
Expand Down
4 changes: 3 additions & 1 deletion crates/next-api/src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,9 @@ impl Endpoint for MiddlewareEndpoint {
let this = self.await?;
let output_assets = self.output_assets();
let _ = output_assets.resolve().await?;
let _ = this.project.emit_all_output_assets(Vc::cell(output_assets));
this.project
.emit_all_output_assets(Vc::cell(output_assets))
.await?;

let (server_paths, client_paths) = if this.project.next_mode().await?.is_development() {
let node_root = this.project.node_root();
Expand Down
6 changes: 3 additions & 3 deletions crates/next-api/src/pages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1277,10 +1277,10 @@ impl Endpoint for PageEndpoint {
// single operation
let output_assets = self.output_assets();

let _ = this
.pages_project
this.pages_project
.project()
.emit_all_output_assets(Vc::cell(output_assets));
.emit_all_output_assets(Vc::cell(output_assets))
.await?;

let node_root = this.pages_project.project().node_root();

Expand Down
26 changes: 15 additions & 11 deletions crates/next-api/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,7 @@ impl Project {
pub async fn emit_all_output_assets(
self: Vc<Self>,
output_assets: Vc<OutputAssetsOperation>,
) -> Result<()> {
) -> Result<Vc<()>> {
let span = tracing::info_span!("emitting");
async move {
let all_output_assets = all_assets_from_entries_operation(output_assets);
Expand All @@ -1179,23 +1179,27 @@ impl Project {
let node_root = self.node_root();

if let Some(map) = self.await?.versioned_content_map {
let _ = map.insert_output_assets(
all_output_assets,
node_root,
client_relative_path,
node_root,
);
let _ = map
.insert_output_assets(
all_output_assets,
node_root,
client_relative_path,
node_root,
)
.resolve()
.await?;

Ok(())
Ok(Vc::cell(()))
} else {
let _ = emit_assets(
*all_output_assets.await?,
node_root,
client_relative_path,
node_root,
);

Ok(())
)
.resolve()
.await?;
Ok(Vc::cell(()))
}
}
.instrument(span)
Expand Down
Loading

0 comments on commit 491e9c1

Please sign in to comment.