8000 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
Show file tree
Hide file tree
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
Next Next commit
Switch from HashMap/Set to {BTree,Index}Map/Set in derive (for where …
…it affects output order)
  • Loading branch information
coolreader18 committed May 8, 2025
commit a710e65ffbb198ac5834db77e2103e8469fc7cd4
8 changes: 1 addition & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion derive-impl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ rustpython-doc = { workspace = true }
itertools = { workspace = true }
syn = { workspace = true, features = ["full", "extra-traits"] }

maplit = "1.0.2"
proc-macro2 = { workspace = true }
quote = { workspace = true }
syn-ext = { version = "0.5.0&qu 8000 ot;, features = ["full"] }
textwrap = { version = "0.16.1", default-features = false }
indexmap = { workspace = true }

[lints]
workspace = true
15 changes: 8 additions & 7 deletions derive-impl/src/compile_bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use quote::quote;
use rustpython_compiler_core::{Mode, bytecode::CodeObject, frozen};
use std::sync::LazyLock;
use std::{
collections::HashMap,
collections::BTreeMap,
env, fs,
path::{Path, PathBuf},
};
Expand Down Expand Up @@ -83,20 +83,21 @@ impl CompilationSource {
mode: Mode,
module_name: String,
compiler: &dyn Compiler,
) -> Result<HashMap<String, CompiledModule>, Diagnostic> {
) -> Result<BTreeMap<String, CompiledModule>, Diagnostic> {
match &self.kind {
CompilationSourceKind::Dir(rel_path) => self.compile_dir(
&CARGO_MANIFEST_DIR.join(rel_path),
String::new(),
mode,
compiler,
),
_ => Ok(hashmap! {
module_name.clone() => CompiledModule {
_ => Ok(BTreeMap::from([(
module_name.clone(),
CompiledModule {
code: self.compile_single(mode, module_name, compiler)?,
package: false,
},
}),
)])),
}
}

Expand Down Expand Up @@ -136,8 +137,8 @@ impl CompilationSource {
parent: String,
mode: Mode,
compiler: &dyn Compiler,
) -> Result<HashMap<String, CompiledModule>, Diagnostic> {
let mut code_map = HashMap::new();
) -> Result<BTreeMap<String, CompiledModule>, Diagnostic> {
let mut code_map = BTreeMap::new();
let paths = fs::read_dir(path)
.or_else(|e| {
if cfg!(windows) {
Expand Down
3 changes: 0 additions & 3 deletions derive-impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

extern crate proc_macro;

#[macro_use]
extern crate maplit;

#[macro_use]
mod error;
#[macro_use]
Expand Down
9 changes: 5 additions & 4 deletions derive-impl/src/pyclass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ use crate::util::{
ItemMeta, ItemMetaInner, ItemNursery, SimpleItemMeta, format_doc, pyclass_ident_and_attrs,
pyexception_ident_and_attrs, text_signature,
};
use indexmap::IndexMap;
use proc_macro2::{Delimiter, Group, Span, TokenStream, TokenTree};
use quote::{ToTokens, quote, quote_spanned};
use std::collections::{HashMap, HashSet};
use std::collections::{BTreeMap, HashMap, HashSet};
use std::str::FromStr;
use syn::{Attribute, Ident, Item, Result, parse_quote, spanned::Spanned};
use syn_ext::ext::*;
Expand Down Expand Up @@ -1028,7 +1029,7 @@ impl ToTokens for MethodNursery {
#[derive(Default)]
#[allow(clippy::type_complexity)]
struct GetSetNursery {
map: HashMap<(String, Vec<Attribute>), (Option<Ident>, Option<Ident>, Option<Ident>)>,
map: IndexMap<(String, Vec<Attribute>), (Option<Ident>, Option<Ident>, Option<Ident>)>,
validated: bool,
}

Expand Down Expand Up @@ -1121,7 +1122,7 @@ impl ToTokens for GetSetNursery {
#[derive(Default)]
#[allow(clippy::type_complexity)]
struct MemberNursery {
map: HashMap<(String, MemberKind), (Option<Ident>, Option<Ident>)>,
map: BTreeMap<(String, MemberKind), (Option<Ident>, Option<Ident>)>,
validated: bool,
}

Expand All @@ -1130,7 +1131,7 @@ enum MemberItemKind {
Set,
}

#[derive(Eq, PartialEq, Hash)]
#[derive(Eq, PartialEq, Ord, PartialOrd)]
enum MemberKind {
Bool,
ObjectEx,
Expand Down
5 changes: 3 additions & 2 deletions derive-impl/src/pymodule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use crate::util::{
};
use proc_macro2::{Delimiter, Group, TokenStream, TokenTree};
use quote::{ToTokens, quote, quote_spanned};
use std::{collections::HashSet, str::FromStr};
use std::collections::{BTreeSet, HashSet};
use std::str::FromStr;
use syn::{Attribute, Ident, Item, Result, parse_quote, spanned::Spanned};
use syn_ext::ext::*;
use syn_ext::types::PunctuatedNestedMeta;
Expand Down Expand Up @@ -472,7 +473,7 @@ impl ModuleItem for FunctionItem {
if self.py_attrs.is_empty() {
vec![py_name]
} else {
let mut py_names = HashSet::new();
let mut py_names = BTreeSet::new();
py_names.insert(py_name);
for attr_index in self.py_attrs.iter().rev() {
let mut loop_unit = || {
Expand Down
0