Compare commits
No commits in common. "ab41d49a3d2d5f689de880faf5f7c21f54df6c38" and "8984dce0e7d72be3624931a19e0e93ca712c9fe5" have entirely different histories.
ab41d49a3d
...
8984dce0e7
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,4 +2,3 @@
|
|||
/hbbytecode/src/opcode.rs
|
||||
/hbbytecode/src/ops.rs
|
||||
/hblang/src/instrs.rs
|
||||
rust-ice-*
|
||||
|
|
|
@ -1,19 +1,24 @@
|
|||
#![feature(
|
||||
let_chains,
|
||||
if_let_guard,
|
||||
macro_metavar_expr,
|
||||
anonymous_lifetime_in_impl_trait,
|
||||
core_intrinsics,
|
||||
new_uninit,
|
||||
never_type,
|
||||
unwrap_infallible,
|
||||
slice_partition_dedup,
|
||||
portable_simd,
|
||||
iter_collect_into,
|
||||
ptr_metadata,
|
||||
slice_ptr_get
|
||||
)]
|
||||
#![allow(internal_features, clippy::format_collect)]
|
||||
#![feature(vec_pop_if)]
|
||||
#![feature(get_many_mut)]
|
||||
#![feature(core_intrinsics)]
|
||||
#![feature(new_uninit)]
|
||||
#![feature(anonymous_lifetime_in_impl_trait)]
|
||||
#![feature(inline_const_pat)]
|
||||
#![feature(pattern)]
|
||||
#![feature(never_type)]
|
||||
#![feature(unwrap_infallible)]
|
||||
#![feature(if_let_guard)]
|
||||
#![feature(slice_partition_dedup)]
|
||||
#![feature(noop_waker)]
|
||||
#![feature(portable_simd)]
|
||||
#![feature(iter_collect_into)]
|
||||
#![feature(macro_metavar_expr)]
|
||||
#![feature(let_chains)]
|
||||
#![feature(ptr_metadata)]
|
||||
#![feature(const_mut_refs)]
|
||||
#![feature(slice_ptr_get)]
|
||||
#![allow(internal_features)]
|
||||
#![allow(clippy::format_collect)]
|
||||
|
||||
use {
|
||||
parser::Ast,
|
||||
|
@ -212,7 +217,7 @@ impl<T> TaskQueueInner<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn parse_from_fs(extra_threads: usize, root: &str) -> io::Result<Vec<Ast>> {
|
||||
pub fn parse_from_fs(threads: usize, root: &str) -> io::Result<Vec<Ast>> {
|
||||
const GIT_DEPS_DIR: &str = "git-deps";
|
||||
|
||||
enum Chk<'a> {
|
||||
|
@ -222,6 +227,7 @@ pub fn parse_from_fs(extra_threads: usize, root: &str) -> io::Result<Vec<Ast>> {
|
|||
}
|
||||
|
||||
enum ImportPath<'a> {
|
||||
Root { path: &'a str },
|
||||
Rel { path: &'a str },
|
||||
Git { link: &'a str, path: &'a str, chk: Option<Chk<'a>> },
|
||||
}
|
||||
|
@ -233,7 +239,8 @@ pub fn parse_from_fs(extra_threads: usize, root: &str) -> io::Result<Vec<Ast>> {
|
|||
let (prefix, path) = value.split_once(':').unwrap_or(("", value));
|
||||
|
||||
match prefix {
|
||||
"rel" | "" => Ok(Self::Rel { path }),
|
||||
"" => Ok(Self::Root { path }),
|
||||
"rel" => Ok(Self::Rel { path }),
|
||||
"git" => {
|
||||
let (link, path) =
|
||||
path.split_once(':').ok_or(ParseImportError::ExpectedPath)?;
|
||||
|
@ -259,22 +266,24 @@ pub fn parse_from_fs(extra_threads: usize, root: &str) -> io::Result<Vec<Ast>> {
|
|||
}
|
||||
|
||||
impl<'a> ImportPath<'a> {
|
||||
fn resolve(&self, from: &str) -> Result<PathBuf, CantLoadFile> {
|
||||
fn resolve(&self, from: &str, root: &str) -> Result<PathBuf, CantLoadFile> {
|
||||
let path = match self {
|
||||
Self::Rel { path } => match Path::new(from).parent() {
|
||||
Some(parent) => PathBuf::from_iter([parent, Path::new(path)]),
|
||||
None => PathBuf::from(path),
|
||||
},
|
||||
Self::Root { path } => {
|
||||
PathBuf::from_iter([Path::new(root).parent().unwrap(), Path::new(path)])
|
||||
}
|
||||
Self::Rel { path } => {
|
||||
PathBuf::from_iter([Path::new(from).parent().unwrap(), Path::new(path)])
|
||||
}
|
||||
Self::Git { path, link, .. } => {
|
||||
let link = preprocess_git(link);
|
||||
PathBuf::from_iter([GIT_DEPS_DIR, link, path])
|
||||
}
|
||||
};
|
||||
|
||||
path.canonicalize().map_err(|source| CantLoadFile {
|
||||
path,
|
||||
path.canonicalize().map_err(|e| CantLoadFile {
|
||||
file_name: path,
|
||||
directory: PathBuf::from(root),
|
||||
from: PathBuf::from(from),
|
||||
source,
|
||||
source: e,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -306,14 +315,21 @@ pub fn parse_from_fs(extra_threads: usize, root: &str) -> io::Result<Vec<Ast>> {
|
|||
|
||||
#[derive(Debug)]
|
||||
struct CantLoadFile {
|
||||
path: PathBuf,
|
||||
file_name: PathBuf,
|
||||
directory: PathBuf,
|
||||
from: PathBuf,
|
||||
source: io::Error,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for CantLoadFile {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
write!(f, "can't load file: {} (from: {})", self.path.display(), self.from.display(),)
|
||||
write!(
|
||||
f,
|
||||
"can't load file: {} (dir: {}) (from: {})",
|
||||
self.file_name.display(),
|
||||
self.directory.display(),
|
||||
self.from.display(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -353,13 +369,13 @@ pub fn parse_from_fs(extra_threads: usize, root: &str) -> io::Result<Vec<Ast>> {
|
|||
type Task = (u32, PathBuf, Option<std::process::Command>);
|
||||
|
||||
let seen = Mutex::new(HashMap::<PathBuf, u32>::default());
|
||||
let tasks = TaskQueue::<Task>::new(extra_threads);
|
||||
let tasks = TaskQueue::<Task>::new(threads);
|
||||
let ast = Mutex::new(Vec::<io::Result<Ast>>::new());
|
||||
|
||||
let loader = |path: &str, from: &str| {
|
||||
let path = ImportPath::try_from(path)?;
|
||||
|
||||
let physiscal_path = path.resolve(from)?;
|
||||
let physiscal_path = path.resolve(from, root)?;
|
||||
|
||||
let id = {
|
||||
let mut seen = seen.lock().unwrap();
|
||||
|
@ -444,11 +460,7 @@ pub fn parse_from_fs(extra_threads: usize, root: &str) -> io::Result<Vec<Ast>> {
|
|||
seen.lock().unwrap().insert(path.clone(), 0);
|
||||
tasks.push((0, path, None));
|
||||
|
||||
if extra_threads == 0 {
|
||||
thread();
|
||||
} else {
|
||||
std::thread::scope(|s| (0..extra_threads + 1).for_each(|_| _ = s.spawn(thread)));
|
||||
}
|
||||
std::thread::scope(|s| (0..threads).for_each(|_| _ = s.spawn(thread)));
|
||||
|
||||
ast.into_inner().unwrap().into_iter().collect::<io::Result<Vec<_>>>()
|
||||
}
|
||||
|
@ -539,7 +551,6 @@ pub fn run_test(
|
|||
pub struct Options {
|
||||
pub fmt: bool,
|
||||
pub fmt_current: bool,
|
||||
pub extra_threads: usize,
|
||||
}
|
||||
|
||||
pub fn run_compiler(
|
||||
|
@ -547,7 +558,7 @@ pub fn run_compiler(
|
|||
options: Options,
|
||||
out: &mut impl std::io::Write,
|
||||
) -> io::Result<()> {
|
||||
let parsed = parse_from_fs(options.extra_threads, root_file)?;
|
||||
let parsed = parse_from_fs(1, root_file)?;
|
||||
|
||||
fn format_to_stdout(ast: parser::Ast) -> std::io::Result<()> {
|
||||
let source = std::fs::read_to_string(&*ast.path)?;
|
||||
|
@ -607,6 +618,7 @@ mod test {
|
|||
std::thread::spawn(move || {
|
||||
for _ in 0..100 {
|
||||
queue.extend([queue.pop().unwrap()]);
|
||||
//dbg!();
|
||||
}
|
||||
})
|
||||
})
|
||||
|
|
|
@ -3,8 +3,5 @@ name = "xtask"
|
|||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies.argh]
|
||||
git = "https://github.com/google/argh.git"
|
||||
branch = "master"
|
||||
default-features = false
|
||||
features = ["help"]
|
||||
[dependencies]
|
||||
argh = { git = "https://github.com/google/argh.git", branch = "master", default-features = false, features = ["help"] }
|
||||
|
|
Loading…
Reference in a new issue