Skip to content

Commit

Permalink
AST transfer WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Feb 22, 2024
1 parent 8ab667c commit 862a1e8
Show file tree
Hide file tree
Showing 40 changed files with 177,581 additions and 612 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ target/

npm/cli-*

/napi/parser/deserialize.js
/napi/parser/*.chart.html

# Ignore accidental files from the root
/*.js
/*.jsx
Expand Down
1 change: 1 addition & 0 deletions .typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ extend-exclude = [
"crates/oxc_linter/fixtures",
"crates/oxc_linter/src/rules/jsx_a11y/img_redundant_alt.rs",
"crates/oxc_syntax/src/xml_entities.rs",
"napi/parser/fixtures",
"**/*.snap",
"pnpm-lock.yaml",
]
Expand Down
60 changes: 60 additions & 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ futures = { version = "0.3.30" }
ignore = { version = "0.4.22" }
itertools = { version = "0.12.1" }
jemallocator = { version = "0.5.4" }
layout_inspect = { git = "https://github.com/overlookmotel/layout_inspect", rev = "c126662" }
lazy_static = { version = "1.4.0" }
miette = { version = "5.10.0", features = ["fancy-no-backtrace"] }
mimalloc = { version = "0.1.39" }
Expand Down
2 changes: 2 additions & 0 deletions crates/oxc_allocator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ doctest = false
bumpalo = { workspace = true, features = ["collections"] }
serde = { workspace = true }

layout_inspect = { workspace = true, features = ["unique_names"] }

[dev-dependencies]
serde_json = { workspace = true }
50 changes: 50 additions & 0 deletions crates/oxc_allocator/src/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ use std::{

use bumpalo::collections;
pub use bumpalo::collections::String;
use layout_inspect::{
defs::{DefBox, DefType, DefVec},
Inspect, TypesCollector,
};
use serde::{ser::SerializeSeq, Serialize, Serializer};

use crate::Allocator;
Expand All @@ -31,6 +35,29 @@ impl<'alloc, T> Box<'alloc, T> {
}
}

impl<'alloc, T: Inspect + 'alloc> Inspect for Box<'alloc, T> {
fn name() -> std::string::String {
"Box<".to_string() + &<T as Inspect>::name() + ">"
}

fn size() -> Option<usize> {
Some(std::mem::size_of::<Self>())
}

fn align() -> Option<usize> {
Some(std::mem::align_of::<Self>())
}

fn def(collector: &mut TypesCollector) -> DefType {
DefType::Box(DefBox {
name: <Self as Inspect>::name(),
size: <Self as Inspect>::size().unwrap(),
align: <Self as Inspect>::align().unwrap(),
value_type_id: collector.collect::<T>(),
})
}
}

impl<'alloc, T: ?Sized> ops::Deref for Box<'alloc, T> {
type Target = T;

Expand Down Expand Up @@ -100,6 +127,29 @@ impl<'alloc, T> Vec<'alloc, T> {
}
}

impl<'alloc, T: Inspect + 'alloc> Inspect for Vec<'alloc, T> {
fn name() -> std::string::String {
"Vec<".to_string() + &<T as Inspect>::name() + ">"
}

fn size() -> Option<usize> {
Some(std::mem::size_of::<Self>())
}

fn align() -> Option<usize> {
Some(std::mem::align_of::<Self>())
}

fn def(collector: &mut TypesCollector) -> DefType {
DefType::Vec(DefVec {
name: <Self as Inspect>::name(),
size: <Self as Inspect>::size().unwrap(),
align: <Self as Inspect>::align().unwrap(),
value_type_id: collector.collect::<T>(),
})
}
}

impl<'alloc, T> ops::Deref for Vec<'alloc, T> {
type Target = collections::Vec<'alloc, T>;

Expand Down
6 changes: 6 additions & 0 deletions crates/oxc_allocator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ pub struct Allocator {
bump: Bump,
}

impl Allocator {
pub fn into_bump(self) -> Bump {
self.bump
}
}

impl From<Bump> for Allocator {
fn from(bump: Bump) -> Self {
Self { bump }
Expand Down
2 changes: 2 additions & 0 deletions crates/oxc_ast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ oxc_index = { workspace = true }
bitflags = { workspace = true }
num-bigint = { workspace = true }

layout_inspect = { workspace = true, features = ["unique_names"] }

serde = { workspace = true, features = ["derive"], optional = true }
serde_json = { workspace = true, optional = true }
ryu-js = { workspace = true, optional = true }
Expand Down
Loading

0 comments on commit 862a1e8

Please sign in to comment.