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

add more tracing to transforms and parsing #8346

Merged
merged 2 commits into from
Jun 6, 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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/turbopack-ecmascript-plugins/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ indexmap = { workspace = true }
lightningcss = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
tracing = { workspace = true }

turbo-tasks = { workspace = true }
turbo-tasks-fs = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ impl ClientDirectiveTransformer {

#[async_trait]
impl CustomTransformer for ClientDirectiveTransformer {
#[tracing::instrument(level = tracing::Level::TRACE, name = "client_directive", skip_all)]
async fn transform(&self, program: &mut Program, ctx: &TransformContext<'_>) -> Result<()> {
if is_client_module(program) {
let transition_name = &*self.transition_name.await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ impl ServerDirectiveTransformer {

#[async_trait]
impl CustomTransformer for ServerDirectiveTransformer {
#[tracing::instrument(level = tracing::Level::TRACE, name = "server_directive", skip_all)]
async fn transform(&self, program: &mut Program, ctx: &TransformContext<'_>) -> Result<()> {
if is_server_module(program) {
let stmt = quote!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ impl EmotionTransformer {

#[async_trait]
impl CustomTransformer for EmotionTransformer {
#[tracing::instrument(level = tracing::Level::TRACE, name = "emotion", skip_all)]
async fn transform(&self, program: &mut Program, ctx: &TransformContext<'_>) -> Result<()> {
#[cfg(feature = "transform_emotion")]
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ impl ModularizeImportsTransformer {

#[async_trait]
impl CustomTransformer for ModularizeImportsTransformer {
#[tracing::instrument(level = tracing::Level::TRACE, name = "modularize_imports", skip_all)]
async fn transform(&self, program: &mut Program, _ctx: &TransformContext<'_>) -> Result<()> {
let p = std::mem::replace(program, Program::Module(Module::dummy()));
*program = p.fold_with(&mut modularize_imports(Config {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ impl RelayTransformer {

#[async_trait]
impl CustomTransformer for RelayTransformer {
#[tracing::instrument(level = tracing::Level::TRACE, name = "relay", skip_all)]
async fn transform(&self, program: &mut Program, ctx: &TransformContext<'_>) -> Result<()> {
// If user supplied artifact_directory, it should be resolvable already.
// Otherwise, supply default relative path (./__generated__)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ impl StyledComponentsTransformer {

#[async_trait]
impl CustomTransformer for StyledComponentsTransformer {
#[tracing::instrument(level = tracing::Level::TRACE, name = "styled_components", skip_all)]
async fn transform(&self, program: &mut Program, ctx: &TransformContext<'_>) -> Result<()> {
program.visit_mut_with(&mut styled_components::styled_components(
FileName::Real(PathBuf::from(ctx.file_path_str)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ impl StyledJsxTransformer {

#[async_trait]
impl CustomTransformer for StyledJsxTransformer {
#[tracing::instrument(level = tracing::Level::TRACE, name = "styled_jsx", skip_all)]
async fn transform(&self, program: &mut Program, ctx: &TransformContext<'_>) -> Result<()> {
let p = std::mem::replace(program, Program::Module(Module::dummy()));
*program = p.fold_with(&mut styled_jsx::visitor::styled_jsx(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ impl SwcEcmaTransformPluginsTransformer {
#[async_trait]
impl CustomTransformer for SwcEcmaTransformPluginsTransformer {
#[cfg_attr(not(feature = "swc_ecma_transform_plugin"), allow(unused))]
#[tracing::instrument(level = tracing::Level::TRACE, name = "swc_ecma_transform_plugin", skip_all)]
async fn transform(&self, program: &mut Program, ctx: &TransformContext<'_>) -> Result<()> {
#[cfg(feature = "swc_ecma_transform_plugin")]
{
Expand Down
22 changes: 18 additions & 4 deletions crates/turbopack-ecmascript/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,9 @@ async fn parse_content(
);

let mut parser = Parser::new_from(lexer);
let span = tracing::trace_span!("swc_parse").entered();
let program_result = parser.parse_program();
drop(span);

let mut has_errors = vec![];
for e in parser.take_errors() {
Expand Down Expand Up @@ -360,11 +362,16 @@ async fn parse_content(
EcmascriptModuleAssetType::Typescript { .. }
| EcmascriptModuleAssetType::TypescriptDeclaration
);
let span = tracing::trace_span!("swc_resolver").entered();

parsed_program.visit_mut_with(&mut resolver(
unresolved_mark,
top_level_mark,
is_typescript,
));
drop(span);

let span = tracing::trace_span!("swc_lint").entered();

let lint_config = LintConfig::default();
let rules = swc_core::ecma::lints::rules::all(LintParams {
Expand All @@ -377,6 +384,7 @@ async fn parse_content(
});
parsed_program =
parsed_program.fold_with(&mut swc_core::ecma::lints::rules::lint_to_fold(rules));
drop(span);

let transform_context = TransformContext {
comments: &comments,
Expand All @@ -388,11 +396,17 @@ async fn parse_content(
file_name_hash: file_path_hash,
file_path: fs_path_vc,
};
for transform in transforms.iter() {
transform
.apply(&mut parsed_program, &transform_context)
.await?;
let span = tracing::trace_span!("transforms");
async {
for transform in transforms.iter() {
transform
.apply(&mut parsed_program, &transform_context)
.await?;
}
anyhow::Ok(())
}
.instrument(span)
.await?;

if parser_handler.has_errors() {
let messages = if let Some(error) = emitter.emitted_issues.last() {
Expand Down
Loading