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

refactor(traverse): speed up tests #4538

Merged
merged 1 commit into from
Jul 29, 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
76 changes: 0 additions & 76 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ textwrap = "0.16.1"
tokio = "1.38.0"
tower-lsp = "0.20.0"
tracing-subscriber = "0.3.18"
trybuild = "1.0.96"
tsify = "0.4.5"
unicode-id-start = "1" # Relaxed version so the user can decide which unicode version to use.
unicode-width = "0.1.13"
Expand Down
7 changes: 3 additions & 4 deletions crates/oxc_traverse/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ include = ["/src"]
workspace = true

[lib]
test = false
test = false
# Doctests must be enabled for this crate as they are used to run tests
# which check the soundness of its code
doctest = true

[dependencies]
Expand All @@ -29,6 +31,3 @@ oxc_syntax = { workspace = true }

compact_str = { workspace = true }
memoffset = { workspace = true }

[dev-dependencies]
trybuild = { workspace = true }
81 changes: 81 additions & 0 deletions crates/oxc_traverse/src/compile_fail_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#![cfg(doctest)]

//! Tests to ensure lifetimes prevent references to escape visitor functions.
//! If they could, it'd allow aliasing, which would be undefined behavior.
//!
//! These tests were originally implemented using `trybuild` crate,
//! but it disproportionately hurt time taken to run tests.
//! So using `compile_fail` doc tests instead.
//! <https://github.com/oxc-project/oxc/issues/4537>

/**
```compile_fail
use oxc_ast::ast::IdentifierReference;
use oxc_traverse::{Ancestor, Traverse, TraverseCtx};

struct Trans<'a, 'b> {
ancestor: Option<&'b Ancestor<'a>>,
}

impl<'a, 'b> Traverse<'a> for Trans<'a, 'b> {
fn enter_identifier_reference(
&mut self,
_node: &mut IdentifierReference<'a>,
ctx: &mut TraverseCtx<'a>,
) {
self.ancestor = Some(ctx.parent());
}
}
```
*/
const CANNOT_HOLD_ONTO_ANCESTOR: () = ();

/**
```compile_fail
use oxc_ast::ast::IdentifierReference;
use oxc_traverse::{ancestor::ProgramWithoutDirectives, Ancestor, Traverse, TraverseCtx};

struct Trans<'a, 'b> {
program: Option<&'b ProgramWithoutDirectives<'a>>,
}

impl<'a, 'b> Traverse<'a> for Trans<'a, 'b> {
fn enter_identifier_reference(
&mut self,
_node: &mut IdentifierReference<'a>,
ctx: &mut TraverseCtx<'a>,
) {
if let Ancestor::ProgramDirectives(program) = ctx.parent() {
self.program = Some(program);
}
}
}
```
*/
const CANNOT_HOLD_ONTO_ANCESTOR_NODE: () = ();

/**
```compile_fail
use oxc_ast::ast::{IdentifierReference, Statement};
use oxc_traverse::{Ancestor, Traverse, TraverseCtx};

struct Trans<'a, 'b> {
stmt: Option<&'b Statement<'a>>,
}

impl<'a, 'b> Traverse<'a> for Trans<'a, 'b> {
fn enter_identifier_reference(
&mut self,
_node: &mut IdentifierReference<'a>,
ctx: &mut TraverseCtx<'a>,
) {
if let Ancestor::ProgramDirectives(program) = ctx.parent() {
let body = program.body();
let stmt = &body[0];
self.stmt = Some(stmt);
}
}
}
```
*/
const CANNOT_HOLD_ONTO_AST_NODE: () = ();
2 changes: 2 additions & 0 deletions crates/oxc_traverse/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ mod traverse;
pub use traverse::Traverse;
mod walk;

mod compile_fail_tests;

/// Traverse AST with a [`Traverse`] impl.
///
/// This allows:
Expand Down
5 changes: 0 additions & 5 deletions crates/oxc_traverse/tests/compile_fail.rs

This file was deleted.

18 changes: 0 additions & 18 deletions crates/oxc_traverse/tests/compile_fail/ancestor_lifetime1.rs

This file was deleted.

This file was deleted.

20 changes: 0 additions & 20 deletions crates/oxc_traverse/tests/compile_fail/ancestor_lifetime2.rs

This file was deleted.

This file was deleted.

21 changes: 0 additions & 21 deletions crates/oxc_traverse/tests/compile_fail/ancestor_lifetime3.rs

This file was deleted.

This file was deleted.

Loading