pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/RustPython/RustPython/commit/be6025ab034b7673b8d6dfe722f47a21b55eaec3

.css" /> Adapt bitflagset to use enum (#7419) · RustPython/RustPython@be6025a · GitHub
Skip to content

Commit be6025a

Browse files
authored
Adapt bitflagset to use enum (#7419)
1 parent 7d63f65 commit be6025a

File tree

11 files changed

+193
-154
lines changed

11 files changed

+193
-154
lines changed

.cspell.dict/rust-more.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ biguint
55
bindgen
66
bitand
77
bitflags
8+
bitflagset
89
bitor
910
bitvec
1011
bitxor

Cargo.lock

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ phf = { version = "0.13.1", default-features = false, features = ["macros"]}
167167
ahash = "0.8.12"
168168
ascii = "1.1"
169169
bitflags = "2.11.0"
170+
bitflagset = "0.0.3"
170171
bstr = "1"
171172
bytes = "1.11.1"
172173
cfg-if = "1.0"

crates/codegen/src/compile.rs

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2509,7 +2509,7 @@ impl Compiler {
25092509
self.compile_expression(value)?;
25102510
emit!(self, Instruction::ReturnValue);
25112511
let value_code = self.exit_scope();
2512-
self.make_closure(value_code, bytecode::MakeFunctionFlags::empty())?;
2512+
self.make_closure(value_code, bytecode::MakeFunctionFlags::new())?;
25132513
// Stack: [type_params_tuple, value_closure]
25142514

25152515
// Swap so unpack_sequence reverse gives correct order
@@ -2522,7 +2522,7 @@ impl Compiler {
25222522

25232523
let code = self.exit_scope();
25242524
self.ctx = prev_ctx;
2525-
self.make_closure(code, bytecode::MakeFunctionFlags::empty())?;
2525+
self.make_closure(code, bytecode::MakeFunctionFlags::new())?;
25262526
emit!(self, Instruction::PushNull);
25272527
emit!(self, Instruction::Call { argc: 0 });
25282528

@@ -2561,7 +2561,7 @@ impl Compiler {
25612561

25622562
let code = self.exit_scope();
25632563
self.ctx = prev_ctx;
2564-
self.make_closure(code, bytecode::MakeFunctionFlags::empty())?;
2564+
self.make_closure(code, bytecode::MakeFunctionFlags::new())?;
25652565
// Stack: [name, None, closure]
25662566
}
25672567

@@ -2725,7 +2725,7 @@ impl Compiler {
27252725
self.ctx = prev_ctx;
27262726

27272727
// Create closure for lazy evaluation
2728-
self.make_closure(code, bytecode::MakeFunctionFlags::empty())?;
2728+
self.make_closure(code, bytecode::MakeFunctionFlags::new())?;
27292729

27302730
Ok(())
27312731
}
@@ -3649,7 +3649,7 @@ impl Compiler {
36493649
&mut self,
36503650
parameters: &ast::Parameters,
36513651
) -> CompileResult<bytecode::MakeFunctionFlags> {
3652-
let mut funcflags = bytecode::MakeFunctionFlags::empty();
3652+
let mut funcflags = bytecode::MakeFunctionFlags::new();
36533653

36543654
// Handle positional defaults
36553655
let defaults: Vec<_> = core::iter::empty()
@@ -3669,7 +3669,7 @@ impl Compiler {
36693669
count: defaults.len().to_u32()
36703670
}
36713671
);
3672-
funcflags |= bytecode::MakeFunctionFlags::DEFAULTS;
3672+
funcflags.insert(bytecode::MakeFunctionFlag::Defaults);
36733673
}
36743674

36753675
// Handle keyword-only defaults
@@ -3694,7 +3694,7 @@ impl Compiler {
36943694
count: kw_with_defaults.len().to_u32(),
36953695
}
36963696
);
3697-
funcflags |= bytecode::MakeFunctionFlags::KW_ONLY_DEFAULTS;
3697+
funcflags.insert(bytecode::MakeFunctionFlag::KwOnlyDefaults);
36983698
}
36993699

37003700
Ok(funcflags)
@@ -3844,7 +3844,7 @@ impl Compiler {
38443844
let annotate_code = self.exit_annotation_scope(saved_ctx);
38453845

38463846
// Make a closure from the code object
3847-
self.make_closure(annotate_code, bytecode::MakeFunctionFlags::empty())?;
3847+
self.make_closure(annotate_code, bytecode::MakeFunctionFlags::new())?;
38483848

38493849
Ok(true)
38503850
}
@@ -4054,7 +4054,7 @@ impl Compiler {
40544054
);
40554055

40564056
// Make a closure from the code object
4057-
self.make_closure(annotate_code, bytecode::MakeFunctionFlags::empty())?;
4057+
self.make_closure(annotate_code, bytecode::MakeFunctionFlags::new())?;
40584058

40594059
// Store as __annotate_func__ for classes, __annotate__ for modules
40604060
let name = if parent_scope_type == CompilerScope::Class {
@@ -4092,10 +4092,10 @@ impl Compiler {
40924092

40934093
if is_generic {
40944094
// Count args to pass to type params scope
4095-
if funcflags.contains(bytecode::MakeFunctionFlags::DEFAULTS) {
4095+
if funcflags.contains(&bytecode::MakeFunctionFlag::Defaults) {
40964096
num_typeparam_args += 1;
40974097
}
4098-
if funcflags.contains(bytecode::MakeFunctionFlags::KW_ONLY_DEFAULTS) {
4098+
if funcflags.contains(&bytecode::MakeFunctionFlag::KwOnlyDefaults) {
40994099
num_typeparam_args += 1;
41004100
}
41014101

@@ -4120,13 +4120,13 @@ impl Compiler {
41204120
// Add parameter names to varnames for the type params scope
41214121
// These will be passed as arguments when the closure is called
41224122
let current_info = self.current_code_info();
4123-
if funcflags.contains(bytecode::MakeFunctionFlags::DEFAULTS) {
4123+
if funcflags.contains(&bytecode::MakeFunctionFlag::Defaults) {
41244124
current_info
41254125
.metadata
41264126
.varnames
41274127
.insert(".defaults".to_owned());
41284128
}
4129-
if funcflags.contains(bytecode::MakeFunctionFlags::KW_ONLY_DEFAULTS) {
4129+
if funcflags.contains(&bytecode::MakeFunctionFlag::KwOnlyDefaults) {
41304130
current_info
41314131
.metadata
41324132
.varnames
@@ -4144,11 +4144,10 @@ impl Compiler {
41444144
}
41454145

41464146
// Compile annotations as closure (PEP 649)
4147-
let annotations_flag = if self.compile_annotations_closure(name, parameters, returns)? {
4148-
bytecode::MakeFunctionFlags::ANNOTATE
4149-
} else {
4150-
bytecode::MakeFunctionFlags::empty()
4151-
};
4147+
let mut annotations_flag = bytecode::MakeFunctionFlags::new();
4148+
if self.compile_annotations_closure(name, parameters, returns)? {
4149+
annotations_flag.insert(bytecode::MakeFunctionFlag::Annotate);
4150+
}
41524151

41534152
// Compile function body
41544153
let final_funcflags = funcflags | annotations_flag;
@@ -4179,7 +4178,7 @@ impl Compiler {
41794178
self.ctx = saved_ctx;
41804179

41814180
// Make closure for type params code
4182-
self.make_closure(type_params_code, bytecode::MakeFunctionFlags::empty())?;
4181+
self.make_closure(type_params_code, bytecode::MakeFunctionFlags::new())?;
41834182

41844183
// Call the type params closure with defaults/kwdefaults as arguments.
41854184
// Call protocol: [callable, self_or_null, arg1, ..., argN]
@@ -4347,57 +4346,57 @@ impl Compiler {
43474346
emit!(
43484347
self,
43494348
Instruction::SetFunctionAttribute {
4350-
flag: bytecode::MakeFunctionFlags::CLOSURE
4349+
flag: bytecode::MakeFunctionFlag::Closure
43514350
}
43524351
);
43534352
}
43544353

43554354
// Set annotations if present
4356-
if flags.contains(bytecode::MakeFunctionFlags::ANNOTATIONS) {
4355+
if flags.contains(&bytecode::MakeFunctionFlag::Annotations) {
43574356
emit!(
43584357
self,
43594358
Instruction::SetFunctionAttribute {
4360-
flag: bytecode::MakeFunctionFlags::ANNOTATIONS
4359+
flag: bytecode::MakeFunctionFlag::Annotations
43614360
}
43624361
);
43634362
}
43644363

43654364
// Set __annotate__ closure if present (PEP 649)
4366-
if flags.contains(bytecode::MakeFunctionFlags::ANNOTATE) {
4365+
if flags.contains(&bytecode::MakeFunctionFlag::Annotate) {
43674366
emit!(
43684367
self,
43694368
Instruction::SetFunctionAttribute {
4370-
flag: bytecode::MakeFunctionFlags::ANNOTATE
4369+
flag: bytecode::MakeFunctionFlag::Annotate
43714370
}
43724371
);
43734372
}
43744373

43754374
// Set kwdefaults if present
4376-
if flags.contains(bytecode::MakeFunctionFlags::KW_ONLY_DEFAULTS) {
4375+
if flags.contains(&bytecode::MakeFunctionFlag::KwOnlyDefaults) {
43774376
emit!(
43784377
self,
43794378
Instruction::SetFunctionAttribute {
4380-
flag: bytecode::MakeFunctionFlags::KW_ONLY_DEFAULTS
4379+
flag: bytecode::MakeFunctionFlag::KwOnlyDefaults
43814380
}
43824381
);
43834382
}
43844383

43854384
// Set defaults if present
4386-
if flags.contains(bytecode::MakeFunctionFlags::DEFAULTS) {
4385+
if flags.contains(&bytecode::MakeFunctionFlag::Defaults) {
43874386
emit!(
43884387
self,
43894388
Instruction::SetFunctionAttribute {
4390-
flag: bytecode::MakeFunctionFlags::DEFAULTS
4389+
flag: bytecode::MakeFunctionFlag::Defaults
43914390
}
43924391
);
43934392
}
43944393

43954394
// Set type_params if present
4396-
if flags.contains(bytecode::MakeFunctionFlags::TYPE_PARAMS) {
4395+
if flags.contains(&bytecode::MakeFunctionFlag::TypeParams) {
43974396
emit!(
43984397
self,
43994398
Instruction::SetFunctionAttribute {
4400-
flag: bytecode::MakeFunctionFlags::TYPE_PARAMS
4399+
flag: bytecode::MakeFunctionFlag::TypeParams
44014400
}
44024401
);
44034402
}
@@ -4689,14 +4688,14 @@ impl Compiler {
46894688
emit!(self, Instruction::PushNull);
46904689

46914690
// Set up the class function with type params
4692-
let mut func_flags = bytecode::MakeFunctionFlags::empty();
4691+
let mut func_flags = bytecode::MakeFunctionFlags::new();
46934692
emit!(
46944693
self,
46954694
Instruction::LoadName {
46964695
namei: dot_type_params
46974696
}
46984697
);
4699-
func_flags |= bytecode::MakeFunctionFlags::TYPE_PARAMS;
4698+
func_flags.insert(bytecode::MakeFunctionFlag::TypeParams);
47004699

47014700
// Create class function with closure
47024701
self.make_closure(class_code, func_flags)?;
@@ -4819,7 +4818,7 @@ impl Compiler {
48194818
self.ctx = saved_ctx;
48204819

48214820
// Execute the type params function
4822-
self.make_closure(type_params_code, bytecode::MakeFunctionFlags::empty())?;
4821+
self.make_closure(type_params_code, bytecode::MakeFunctionFlags::new())?;
48234822
emit!(self, Instruction::PushNull);
48244823
emit!(self, Instruction::Call { argc: 0 });
48254824
} else {
@@ -4828,7 +4827,7 @@ impl Compiler {
48284827
emit!(self, Instruction::PushNull);
48294828

48304829
// Create class function with closure
4831-
self.make_closure(class_code, bytecode::MakeFunctionFlags::empty())?;
4830+
self.make_closure(class_code, bytecode::MakeFunctionFlags::new())?;
48324831
self.emit_load_const(ConstantData::Str { value: name.into() });
48334832

48344833
if let Some(arguments) = arguments {
@@ -7096,12 +7095,12 @@ impl Compiler {
70967095
}
70977096

70987097
self.enter_function(&name, params)?;
7099-
let mut func_flags = bytecode::MakeFunctionFlags::empty();
7098+
let mut func_flags = bytecode::MakeFunctionFlags::new();
71007099
if have_defaults {
7101-
func_flags |= bytecode::MakeFunctionFlags::DEFAULTS;
7100+
func_flags.insert(bytecode::MakeFunctionFlag::Defaults);
71027101
}
71037102
if have_kwdefaults {
7104-
func_flags |= bytecode::MakeFunctionFlags::KW_ONLY_DEFAULTS;
7103+
func_flags.insert(bytecode::MakeFunctionFlag::KwOnlyDefaults);
71057104
}
71067105

71077106
// Set qualname for lambda
@@ -7785,7 +7784,7 @@ impl Compiler {
77857784
self.ctx = prev_ctx;
77867785

77877786
// Create comprehension function with closure
7788-
self.make_closure(code, bytecode::MakeFunctionFlags::empty())?;
7787+
self.make_closure(code, bytecode::MakeFunctionFlags::new())?;
77897788
emit!(self, Instruction::PushNull);
77907789

77917790
// Evaluate iterated item:

crates/compiler-core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ ruff_source_file = { workspace = true }
1414
rustpython-wtf8 = { workspace = true }
1515

1616
bitflags = { workspace = true }
17+
bitflagset = { workspace = true }
1718
itertools = { workspace = true }
1819
malachite-bigint = { workspace = true }
1920
num-complex = { workspace = true }

crates/compiler-core/src/bytecode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ pub use crate::bytecode::{
2626
oparg::{
2727
BinaryOperator, BuildSliceArgCount, CommonConstant, ComparisonOperator, ConvertValueOparg,
2828
IntrinsicFunction1, IntrinsicFunction2, Invert, Label, LoadAttr, LoadSuperAttr,
29-
MakeFunctionFlags, NameIdx, OpArg, OpArgByte, OpArgState, OpArgType, RaiseKind, ResumeType,
30-
SpecialMethod, UnpackExArgs,
29+
MakeFunctionFlag, MakeFunctionFlags, NameIdx, OpArg, OpArgByte, OpArgState, OpArgType,
30+
RaiseKind, ResumeType, SpecialMethod, UnpackExArgs,
3131
},
3232
};
3333

crates/compiler-core/src/bytecode/instruction.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{
66
oparg::{
77
self, BinaryOperator, BuildSliceArgCount, CommonConstant, ComparisonOperator,
88
ConvertValueOparg, IntrinsicFunction1, IntrinsicFunction2, Invert, Label, LoadAttr,
9-
LoadSuperAttr, MakeFunctionFlags, NameIdx, OpArg, OpArgByte, OpArgType, RaiseKind,
9+
LoadSuperAttr, MakeFunctionFlag, NameIdx, OpArg, OpArgByte, OpArgType, RaiseKind,
1010
SpecialMethod, StoreFastLoadFast, UnpackExArgs,
1111
},
1212
},
@@ -264,7 +264,7 @@ pub enum Instruction {
264264
i: Arg<u32>,
265265
} = 107,
266266
SetFunctionAttribute {
267-
flag: Arg<MakeFunctionFlags>,
267+
flag: Arg<MakeFunctionFlag>,
268268
} = 108,
269269
SetUpdate {
270270
i: Arg<u32>,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy