Skip to content

Commit

Permalink
refactor(es): Make the code compile with miri (#8836)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Apr 10, 2024
1 parent c90c199 commit 3a51140
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 35 deletions.
2 changes: 0 additions & 2 deletions crates/swc_ecma_codegen/src/comments.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use swc_common::comments::CommentKind;

use super::*;

macro_rules! write_comments {
Expand Down
2 changes: 0 additions & 2 deletions crates/swc_ecma_codegen/src/text_writer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use swc_common::Span;

pub use self::{basic_impl::JsWriter, semicolon::omit_trailing_semi};
use super::*;

Expand Down
1 change: 0 additions & 1 deletion crates/swc_ecma_parser/src/lexer/jsx.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use either::Either;

use super::*;
use crate::token::Token;

impl<'a> Lexer<'a> {
pub(super) fn read_jsx_token(&mut self) -> LexResult<Option<Token>> {
Expand Down
3 changes: 1 addition & 2 deletions crates/swc_ecma_parser/src/lexer/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ use std::{borrow::Cow, fmt::Write};
use either::Either;
use num_bigint::BigInt as BigIntValue;
use num_traits::{Num as NumTrait, ToPrimitive};
use smartstring::{LazyCompact, SmartString};
use smartstring::LazyCompact;
use swc_common::SyntaxContext;
use tracing::trace;

use super::*;
use crate::error::SyntaxError;

struct LazyBigInt<const RADIX: u8> {
value: String,
Expand Down
10 changes: 8 additions & 2 deletions crates/swc_ecma_parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,14 +509,20 @@ expose!(parse_file_as_script, Script, |p| { p.parse_script() });
expose!(parse_file_as_program, Program, |p| { p.parse_program() });

#[inline(always)]
#[cfg(any(target_arch = "wasm32", target_arch = "arm", not(feature = "stacker")))]
#[cfg(any(
target_arch = "wasm32",
target_arch = "arm",
not(feature = "stacker"),
// miri does not work with stacker
miri
))]
fn maybe_grow<R, F: FnOnce() -> R>(_red_zone: usize, _stack_size: usize, callback: F) -> R {
callback()
}

#[inline(always)]
#[cfg(all(
not(any(target_arch = "wasm32", target_arch = "arm")),
not(any(target_arch = "wasm32", target_arch = "arm", miri)),
feature = "stacker"
))]
fn maybe_grow<R, F: FnOnce() -> R>(red_zone: usize, stack_size: usize, callback: F) -> R {
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_parser/src/parser/class_and_fn.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use swc_common::{Spanned, SyntaxContext};

use super::*;
use crate::{error::SyntaxError, lexer::TokenContext, Tokens};
use crate::lexer::TokenContext;

/// Parser for function expression and function declaration.
impl<I: Tokens> Parser<I> {
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_ecma_parser/src/parser/expr.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use either::Either;
use swc_common::{ast_node, collections::AHashMap, util::take::Take, Spanned};
use swc_common::{ast_node, util::take::Take, Spanned};

use super::{pat::PatType, util::ExprExt, *};
use crate::{lexer::TokenContext, parser::class_and_fn::IsSimpleParameterList};
Expand Down
1 change: 0 additions & 1 deletion crates/swc_ecma_parser/src/parser/expr/ops.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//! Parser for unary operations and binary operations.
use swc_common::Spanned;
use tracing::trace;

use super::*;
Expand Down
23 changes: 1 addition & 22 deletions crates/swc_ecma_parser/src/parser/jsx.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use either::Either;
use swc_common::{Span, Spanned, SyntaxContext};
use swc_common::{Spanned, SyntaxContext};

use super::*;

Expand Down Expand Up @@ -439,27 +439,6 @@ impl<I: Tokens> Parser<I> {
}
}

trait IsFragment {
fn is_fragment(&self) -> bool;
}

impl IsFragment for Either<JSXOpeningFragment, JSXOpeningElement> {
fn is_fragment(&self) -> bool {
matches!(*self, Either::Left(..))
}
}

impl IsFragment for Either<JSXClosingFragment, JSXClosingElement> {
fn is_fragment(&self) -> bool {
matches!(*self, Either::Left(..))
}
}
impl<T: IsFragment> IsFragment for Option<T> {
fn is_fragment(&self) -> bool {
self.as_ref().map(|s| s.is_fragment()).unwrap_or(false)
}
}

fn get_qualified_jsx_name(name: &JSXElementName) -> JsWord {
fn get_qualified_obj_name(obj: &JSXObject) -> JsWord {
match *obj {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use swc_common::{
util::take::Take,
Mark, Span, Spanned, SyntaxContext, DUMMY_SP,
};
use swc_ecma_ast::{Ident, Lit, *};
use swc_ecma_ast::*;
use swc_ecma_transforms_base::{
ext::ExprRefExt,
pass::RepeatedJsPass,
Expand Down

0 comments on commit 3a51140

Please sign in to comment.