10000 Macro stuff by coolreader18 · Pull Request #4687 · RustPython/RustPython · GitHub
[go: up one dir, main page]

Skip to content

Macro stuff #4687

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Parallel lib compilation(!?)
  • Loading branch information
coolreader18 committed May 8, 2025
commit dca98249734b22b11a78a301fdbe6e0242281188
45 changes: 37 additions & 8 deletions derive-impl/src/compile_bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,13 @@
LibPath(PathBuf),
}

#[derive(Clone)]
struct CompiledModule {
code: CodeObject,
package: bool,
}

pub trait Compiler {
pub trait Compiler: Sync {
fn compile(
&self,
source: &str,
Expand Down Expand Up @@ -95,13 +96,15 @@
return Ok(vec![(module_name, module)]);
}
}
dir.modules
.into_iter()
.map(|(module_name, (path, package))| {
let code = Self::compile_file(&path, mode, &module_name, compiler)?;
Ok((module_name, CompiledModule { code, package }))
})
.collect()
let do_compile = |(module_name, (path, package)): (String, (PathBuf, _))| {
let code = Self::compile_file(&path, mode, &module_name, compiler)?;
Ok((module_name, CompiledModule { code, package }))
};
if dir.modules.len() > 32 {
par_map(dir.modules, do_compile).collect()
} else {
dir.modules.into_iter().map(do_compile).collect()
}
}

fn compile_file(
Expand Down Expand Up @@ -152,6 +155,32 @@
}
}

fn par_map<T, U, I, F>(it: I, f: F) -> impl Iterator<Item = U>
where
I: IntoIterator<Item = T, IntoIter: ExactSizeIterator + Send>,
F: Fn(T) -> U + Sync,
U: Send,
{
let it = it.into_iter();
let mut out = Vec::from_iter(std::iter::repeat_with(|| None).take(it.len()));
let it = std::sync::Mutex::new(std::iter::zip(&mut out, it));
let task = || {
while let Some((out, x)) = { it.lock().unwrap().next() } {
*out = Some(f(x));
}
};
std::thread::scope(|s| {
let nproc = std::thread::available_parallelism().unwrap().get();
for _ in 0..nproc {
std::thread::Builder::new()
.stack_size(4 * 1024 * 1024)
.spawn_scoped(s, task)
.unwrap();
}
});
out.into_iter().map(Option::unwrap)
D7EF }

#[derive(Default)]
struct DirWalker<'a> {
excludes: &'a [pattern::ModulePattern],
Expand Down Expand Up @@ -492,21 +521,21 @@
fn test_pattern() {
let pattern: ModulePattern = "x.bar.foo_*.a".parse().unwrap();
assert!(pattern.matches("x.bar.foo_asdf.a"));
assert!(pattern.matches("x.bar.foo_bazzzz.a"));

Check warning on line 524 in derive-impl/src/compile_bytecode.rs

View workflow job for this annotation

GitHub Actions / Check Rust code with rustfmt and clippy

Unknown word (bazzzz)
assert!(pattern.matches("x.bar.foo_.a"));
assert!(!pattern.matches("x.bar.foo_"));
assert!(!pattern.matches("x.bar.foo_quxxx"));

Check warning on line 527 in derive-impl/src/compile_bytecode.rs

View workflow job for this annotation

GitHub Actions / Check Rust code with rustfmt and clippy

Unknown word (quxxx)
assert!(!pattern.matches("foo_b.a"));

let pattern: ModulePattern = "**.foo.**".parse().unwrap();
assert!(pattern.matches("ba.bazzz.foo.quux"));

Check warning on line 531 in derive-impl/src/compile_bytecode.rs

View workflow job for this annotation

GitHub Actions / Check Rust code with rustfmt and clippy

Unknown word (bazzz)

let pattern: ModulePattern = "*.foo.**".parse().unwrap();
assert!(pattern.matches("ba.foo.baz.quux"));
assert!(pattern.matches("asdf.foo.barrr"));

Check warning on line 535 in derive-impl/src/compile_bytecode.rs

View workflow job for this annotation

GitHub Actions / Check Rust code with rustfmt and clippy

Unknown word (barrr)

let pattern: ModulePattern = "foo.**".parse().unwrap();
assert!(pattern.matches("foo.baaar.qx"));

Check warning on line 538 in derive-impl/src/compile_bytecode.rs

View workflow job for this annotation

GitHub Actions / Check Rust code with rustfmt and clippy

Unknown word (baaar)
assert!(!pattern.matches("asdf.foo.brrrr"));

let pattern: ModulePattern = "foo.**.bar*".parse().unwrap();
Expand Down
Loading
0