Vendor things

This commit is contained in:
John Doty 2024-03-08 11:03:01 -08:00
parent 5deceec006
commit 977e3c17e5
19434 changed files with 10682014 additions and 0 deletions

View file

@ -0,0 +1 @@
{"files":{"Cargo.toml":"863388734a97e3383435bb2319939c432acb8726140c10b6088c64ea14707557","build.rs":"05d911fc8edcd96bb80112d6499d1623c9a7541f17b6dc02dd3a6794a2f3374c","scripts/_/sort.py":"a15e9fb013e718d0a4074bbd7534b2e4effe4f3a25d596fb0500e041f847e881","scripts/add-from-cargo-check.sh":"37bba1bef88f66fa5b7444fbf4f45635dce807839a8746e3d384ff5491313030","scripts/sort.sh":"933de1c53c931e32f9fecc22ed3856ad21afe7f1efea16695185d0ea9bfd5656","src/lib.rs":"fa0a1245eb3d8d635c58478d2c65ec0463082fba106cac6a3a2fcfe85a9cb1d3","words.txt":"5a3114ae4da8666130b5925d24bfb2eb90c0d03857e9cf03ac1ffaf877cbbfb3"},"package":"9f54563d7dcba626d4acfe14ed12def7ecc28e004debe3ecd2c3ee07cc47e449"}

63
third-party/vendor/swc_atoms/Cargo.toml vendored Normal file
View file

@ -0,0 +1,63 @@
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies.
#
# If you are reading this file be aware that the original Cargo.toml
# will likely look very different (and much more reasonable).
# See Cargo.toml.orig for the original contents.
[package]
edition = "2021"
name = "swc_atoms"
version = "0.5.9"
authors = ["강동윤 <kdy1997.dev@gmail.com>"]
build = "build.rs"
description = "Atoms for the swc project."
documentation = "https://rustdoc.swc.rs/swc_atoms/"
license = "Apache-2.0"
repository = "https://github.com/swc-project/swc.git"
[lib]
bench = false
[dependencies.bytecheck]
version = "0.6.10"
optional = true
[dependencies.once_cell]
version = "1"
[dependencies.rkyv]
version = "=0.7.42"
features = [
"strict",
"validation",
]
optional = true
package = "rkyv"
[dependencies.rustc-hash]
version = "1.1.0"
[dependencies.serde]
version = "1"
[dependencies.string_cache]
version = "0.8.7"
[dependencies.triomphe]
version = "0.1.8"
[build-dependencies.string_cache_codegen]
version = "0.5.2"
[features]
__rkyv = []
rkyv-impl = [
"__rkyv",
"rkyv",
"bytecheck",
]

29
third-party/vendor/swc_atoms/build.rs vendored Normal file
View file

@ -0,0 +1,29 @@
use std::{env, path::Path};
fn main() {
let strs = include_str!("words.txt")
.lines()
.map(|l| l.trim())
.collect::<Vec<_>>();
gen("js_word", "JsWord", &strs);
}
fn gen(mac_name: &str, type_name: &str, atoms: &[&str]) {
string_cache_codegen::AtomType::new(type_name, &format!("{}!", mac_name))
.atoms(atoms)
.with_atom_doc(
"
[JsWord] is an interned string.
This type should be used instead of [String] for values, because lots of
values are duplicated. For example, if an identifier is named `myVariable`,
there will be lots of identifier usages with the value `myVariable`.
This type
- makes equality comparison faster.
- reduces memory usage.
",
)
.write_to_file(&Path::new(&env::var("OUT_DIR").unwrap()).join(format!("{}.rs", mac_name)))
.unwrap();
}

View file

@ -0,0 +1,7 @@
#!/usr/bin/env python3
import sys
lines = sys.stdin.readlines()
lines.sort()
for line in lines:
print(line,end='')

View file

@ -0,0 +1,6 @@
#!/usr/bin/env bash
set -eu
export CARGO_TERM_COLOR=never
cargo check 2>&1 | grep 'no rules expected the token' | sed -e 's/error: no rules expected the token `"//' | sed -e 's/"`//'

View file

@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -eu
cat words.txt | sed '/^[[:space:]]*$/d' | awk '{$1=$1};1' | uniq | ./scripts/_/sort.py > words_sorted.txt
mv words_sorted.txt words.txt

419
third-party/vendor/swc_atoms/src/lib.rs vendored Normal file
View file

@ -0,0 +1,419 @@
//! See [JsWord] and [Atom]
#![allow(clippy::unreadable_literal)]
/// Not a publish API.
#[doc(hidden)]
pub extern crate once_cell;
use std::{
borrow::{Borrow, Cow},
fmt::{self, Display, Formatter},
hash::Hash,
ops::Deref,
rc::Rc,
};
use rustc_hash::FxHashSet;
use serde::Serializer;
use triomphe::{Arc, HeaderWithLength, ThinArc};
include!(concat!(env!("OUT_DIR"), "/js_word.rs"));
/// An (optionally) interned string.
///
/// Use [AtomGenerator], [`Atom::new`] or `.into()` to create [Atom]s.
/// If you think the same value will be used multiple time, use [AtomGenerator].
/// Othrwise, create an [Atom] using `.into()`.
///
/// # Comparison with [JsWord][]
///
/// [JsWord][] is a globally interned string with phf support, while [Atom] is a
/// locally interened string. Global interning results in a less memory usage,
/// but global means a mutex. Because of the mutex, [Atom] performs better in
/// multi-thread environments. But due to lack of phf or global interning,
/// comparison and hashing of [Atom] is slower than them of [JsWord].
///
/// # Usages
///
/// This should be used instead of [JsWord] for
///
/// - Long texts, which is **not likely to be duplicated**. This does not mean
/// "longer than xx" as this is a type.
/// - Raw values.
#[derive(Clone)]
#[cfg_attr(feature = "rkyv-impl", derive(rkyv::bytecheck::CheckBytes))]
#[cfg_attr(feature = "rkyv-impl", repr(C))]
pub struct Atom(ThinArc<HeaderWithLength<()>, u8>);
fn _assert_size() {
let _static_assert_size_eq = std::mem::transmute::<Atom, usize>;
}
impl Atom {
/// Creates a bad [Atom] from a string.
///
/// This [Atom] is bad because it doesn't help reducing memory usage.
///
/// # Note
///
/// Although this is called `bad`, it's fine to use this if a string is
/// unlikely to be duplicated.
///
/// e.g. Texts in template literals or comments are unlikely to benefit from
/// interning.
pub fn new<S>(s: S) -> Self
where
Arc<str>: From<S>,
S: AsRef<str>,
{
let len = s.as_ref().as_bytes().len();
Self(ThinArc::from_header_and_slice(
HeaderWithLength::new((), len),
s.as_ref().as_bytes(),
))
}
}
impl Deref for Atom {
type Target = str;
#[inline]
fn deref(&self) -> &Self::Target {
unsafe {
// Safety: We only consturct this type from valid str
std::str::from_utf8_unchecked(&self.0.slice)
}
}
}
macro_rules! impl_eq {
($T:ty) => {
impl PartialEq<$T> for Atom {
fn eq(&self, other: &$T) -> bool {
&**self == &**other
}
}
};
}
macro_rules! impl_from {
($T:ty) => {
impl From<$T> for Atom {
fn from(s: $T) -> Self {
Atom::new(s)
}
}
};
}
macro_rules! impl_from_deref {
($T:ty) => {
impl From<$T> for Atom {
fn from(s: $T) -> Self {
Atom::new(&*s)
}
}
};
}
impl PartialEq<str> for Atom {
fn eq(&self, other: &str) -> bool {
&**self == other
}
}
impl_eq!(&'_ str);
impl_eq!(Box<str>);
impl_eq!(std::sync::Arc<str>);
impl_eq!(Rc<str>);
impl_eq!(Cow<'_, str>);
impl_eq!(String);
impl_eq!(JsWord);
impl_from!(&'_ str);
impl_from_deref!(Box<str>);
impl_from!(Arc<str>);
impl_from_deref!(Cow<'_, str>);
impl_from!(String);
impl From<JsWord> for Atom {
fn from(v: JsWord) -> Self {
Self::new(&*v)
}
}
impl AsRef<str> for Atom {
fn as_ref(&self) -> &str {
self
}
}
impl Borrow<str> for Atom {
fn borrow(&self) -> &str {
self
}
}
impl fmt::Debug for Atom {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(&**self, f)
}
}
impl Display for Atom {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
Display::fmt(&**self, f)
}
}
impl Default for Atom {
fn default() -> Self {
atom!("")
}
}
impl PartialOrd for Atom {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
(**self).partial_cmp(&**other)
}
}
impl Ord for Atom {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
(**self).cmp(&**other)
}
}
impl PartialEq for Atom {
fn eq(&self, other: &Self) -> bool {
// Fast path
if self.0.as_ptr() == other.0.as_ptr() {
return true;
}
(**self).eq(&**other)
}
}
impl Eq for Atom {}
impl Hash for Atom {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
(**self).hash(state)
}
}
/// Generator for an interned strings.
///
/// A lexer is expected to store this in it.
#[derive(Debug, Default, Clone)]
pub struct AtomGenerator {
inner: FxHashSet<Atom>,
}
impl AtomGenerator {
/// Get an interned [Atom] or create one from `s`.
pub fn intern<S>(&mut self, s: S) -> Atom
where
Arc<str>: From<S>,
S: Eq + Hash,
S: AsRef<str>,
{
if let Some(v) = self.inner.get(s.as_ref()).cloned() {
return v;
}
let new = Atom::new(s);
self.inner.insert(new.clone());
new
}
}
impl serde::ser::Serialize for Atom {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(self)
}
}
impl<'de> serde::de::Deserialize<'de> for Atom {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
String::deserialize(deserializer).map(Self::new)
}
}
/// Creates an atom from a constant.
#[macro_export]
macro_rules! atom {
($s:literal) => {{
static CACHE: $crate::once_cell::sync::Lazy<$crate::Atom> =
$crate::once_cell::sync::Lazy::new(|| $crate::Atom::new($s));
$crate::Atom::clone(&*CACHE)
}};
}
#[test]
fn _assert() {
let mut g = AtomGenerator::default();
g.intern("str");
g.intern(String::new());
}
impl PartialEq<Atom> for str {
fn eq(&self, other: &Atom) -> bool {
*self == **other
}
}
/// NOT A PUBLIC API
#[cfg(feature = "rkyv-impl")]
impl rkyv::Archive for Atom {
type Archived = rkyv::string::ArchivedString;
type Resolver = rkyv::string::StringResolver;
#[allow(clippy::unit_arg)]
unsafe fn resolve(&self, pos: usize, resolver: Self::Resolver, out: *mut Self::Archived) {
rkyv::string::ArchivedString::resolve_from_str(self, pos, resolver, out)
}
}
/// NOT A PUBLIC API
#[cfg(feature = "rkyv-impl")]
impl<S: rkyv::ser::Serializer + ?Sized> rkyv::Serialize<S> for Atom {
fn serialize(&self, serializer: &mut S) -> Result<Self::Resolver, S::Error> {
String::serialize(&self.to_string(), serializer)
}
}
/// NOT A PUBLIC API
#[cfg(feature = "rkyv-impl")]
impl<D> rkyv::Deserialize<Atom, D> for rkyv::string::ArchivedString
where
D: ?Sized + rkyv::Fallible,
{
fn deserialize(&self, deserializer: &mut D) -> Result<Atom, <D as rkyv::Fallible>::Error> {
let s: String = self.deserialize(deserializer)?;
Ok(Atom::new(s))
}
}
/// NOT A PUBLIC API.
///
/// This type exists to allow serializing [JsWord] using `rkyv`.
#[cfg(feature = "rkyv-impl")]
#[derive(Debug, Clone, Copy)]
#[cfg_attr(feature = "rkyv-impl", derive(rkyv::bytecheck::CheckBytes))]
#[cfg_attr(feature = "rkyv-impl", repr(C))]
pub struct EncodeJsWord;
#[cfg(feature = "rkyv-impl")]
impl rkyv::with::ArchiveWith<crate::JsWord> for EncodeJsWord {
type Archived = rkyv::Archived<String>;
type Resolver = rkyv::Resolver<String>;
unsafe fn resolve_with(
field: &crate::JsWord,
pos: usize,
resolver: Self::Resolver,
out: *mut Self::Archived,
) {
use rkyv::Archive;
let s = field.to_string();
s.resolve(pos, resolver, out);
}
}
#[cfg(feature = "rkyv-impl")]
impl<S> rkyv::with::SerializeWith<crate::JsWord, S> for EncodeJsWord
where
S: ?Sized + rkyv::ser::Serializer,
{
fn serialize_with(
field: &crate::JsWord,
serializer: &mut S,
) -> Result<Self::Resolver, S::Error> {
rkyv::string::ArchivedString::serialize_from_str(field, serializer)
}
}
#[cfg(feature = "rkyv-impl")]
impl<D> rkyv::with::DeserializeWith<rkyv::Archived<String>, crate::JsWord, D> for EncodeJsWord
where
D: ?Sized + rkyv::Fallible,
{
fn deserialize_with(
field: &rkyv::Archived<String>,
deserializer: &mut D,
) -> Result<crate::JsWord, D::Error> {
use rkyv::Deserialize;
let s: String = field.deserialize(deserializer)?;
Ok(s.into())
}
}
#[cfg(feature = "rkyv-impl")]
impl rkyv::with::ArchiveWith<Option<crate::JsWord>> for EncodeJsWord {
type Archived = rkyv::Archived<Option<String>>;
type Resolver = rkyv::Resolver<Option<String>>;
unsafe fn resolve_with(
field: &Option<crate::JsWord>,
pos: usize,
resolver: Self::Resolver,
out: *mut Self::Archived,
) {
use rkyv::Archive;
let s = field.as_ref().map(|s| s.to_string());
s.resolve(pos, resolver, out);
}
}
#[cfg(feature = "rkyv-impl")]
impl<S> rkyv::with::SerializeWith<Option<crate::JsWord>, S> for EncodeJsWord
where
S: ?Sized + rkyv::ser::Serializer,
{
fn serialize_with(
value: &Option<crate::JsWord>,
serializer: &mut S,
) -> Result<Self::Resolver, S::Error> {
value
.as_ref()
.map(|value| rkyv::string::ArchivedString::serialize_from_str(value, serializer))
.transpose()
}
}
#[cfg(feature = "rkyv-impl")]
impl<D> rkyv::with::DeserializeWith<rkyv::Archived<Option<String>>, Option<crate::JsWord>, D>
for EncodeJsWord
where
D: ?Sized + rkyv::Fallible,
{
fn deserialize_with(
field: &rkyv::Archived<Option<String>>,
deserializer: &mut D,
) -> Result<Option<crate::JsWord>, D::Error> {
use rkyv::Deserialize;
let s: Option<String> = field.deserialize(deserializer)?;
Ok(s.map(|s| s.into()))
}
}

2454
third-party/vendor/swc_atoms/words.txt vendored Normal file

File diff suppressed because it is too large Load diff