forked from swc-project/swc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Although it's quite naive at the moment, I added two optimization passes. - dead code elimination (Closes swc-project#607) - inlining
- Loading branch information
Showing
38 changed files
with
8,160 additions
and
2,583 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "swc_common" | ||
version = "0.5.2" | ||
version = "0.5.3" | ||
authors = ["강동윤 <[email protected]>"] | ||
license = "Apache-2.0/MIT" | ||
repository = "https://github.com/swc-project/swc.git" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
use crate::{Fold, FoldWith}; | ||
use serde::export::PhantomData; | ||
use std::borrow::Cow; | ||
|
||
pub trait CompilerPass { | ||
/// Name should follow hyphen-case | ||
/// | ||
/// TODO: timing | ||
fn name() -> Cow<'static, str>; | ||
} | ||
|
||
pub trait Repeated: CompilerPass { | ||
/// Should run again? | ||
fn changed(&self) -> bool; | ||
|
||
/// Reset. | ||
fn reset(&mut self); | ||
} | ||
|
||
pub trait RepeatedPass<At>: Repeated + CompilerPass {} | ||
|
||
impl<T, P> RepeatedPass<T> for P where P: CompilerPass + Repeated {} | ||
|
||
#[derive(Debug, Copy, Clone)] | ||
pub struct Repeat<P, At> | ||
where | ||
P: RepeatedPass<At>, | ||
{ | ||
pass: P, | ||
at: PhantomData<At>, | ||
} | ||
|
||
impl<P, At> Repeat<P, At> | ||
where | ||
P: RepeatedPass<At>, | ||
{ | ||
pub fn new(pass: P) -> Self { | ||
Self { | ||
pass, | ||
at: PhantomData, | ||
} | ||
} | ||
} | ||
|
||
impl<P, At> CompilerPass for Repeat<P, At> | ||
where | ||
P: RepeatedPass<At>, | ||
{ | ||
fn name() -> Cow<'static, str> { | ||
format!("Repeat({})", P::name()).into() | ||
} | ||
} | ||
|
||
impl<P, At> Repeated for Repeat<P, At> | ||
where | ||
P: RepeatedPass<At>, | ||
{ | ||
fn changed(&self) -> bool { | ||
self.pass.changed() | ||
} | ||
|
||
fn reset(&mut self) { | ||
self.pass.reset() | ||
} | ||
} | ||
|
||
#[cfg(feature = "fold")] | ||
impl<P, At> Fold<At> for Repeat<P, At> | ||
where | ||
At: FoldWith<Self> + FoldWith<P>, | ||
P: RepeatedPass<At>, | ||
{ | ||
fn fold(&mut self, mut node: At) -> At { | ||
loop { | ||
self.pass.reset(); | ||
node = node.fold_with(&mut self.pass); | ||
|
||
if !self.pass.changed() { | ||
break; | ||
} | ||
} | ||
|
||
node | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,5 @@ | ||
pub use self::{ | ||
inline_globals::InlineGlobals, | ||
json_parse::JsonParse, | ||
simplify::{expr_simplifier, simplifier}, | ||
}; | ||
pub use self::{inline_globals::InlineGlobals, json_parse::JsonParse, simplify::simplifier}; | ||
|
||
mod inline_globals; | ||
mod json_parse; | ||
mod simplify; | ||
pub mod simplify; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.