Skip to content

Commit 8045884

Browse files
committed
Resolve name collision
1 parent e04b88d commit 8045884

File tree

5 files changed

+52
-51
lines changed

5 files changed

+52
-51
lines changed

crates/codegen/src/compile.rs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,22 @@ use malachite_bigint::BigInt;
2121
use num_complex::Complex;
2222
use num_traits::{Num, ToPrimitive};
2323
use ruff_python_ast::{
24-
Alias, Arguments, BoolOp, CmpOp, Comprehension, DebugText, Decorator, DictItem, ExceptHandler,
25-
ExceptHandlerExceptHandler, Expr, ExprAttribute, ExprBoolOp, ExprContext, ExprFString,
26-
ExprList, ExprName, ExprSlice, ExprStarred, ExprSubscript, ExprTuple, ExprUnaryOp, FString,
27-
FStringFlags, FStringPart, Identifier, Int, InterpolatedElement, InterpolatedStringElement,
28-
InterpolatedStringElements, Keyword, MatchCase, ModExpression, ModModule, Operator, Parameters,
29-
Pattern, PatternMatchAs, PatternMatchClass, PatternMatchMapping, PatternMatchOr,
30-
PatternMatchSequence, PatternMatchSingleton, PatternMatchStar, PatternMatchValue, Singleton,
31-
Stmt, StmtExpr, TypeParam, TypeParamParamSpec, TypeParamTypeVar, TypeParamTypeVarTuple,
32-
TypeParams, UnaryOp, WithItem,
24+
Alias, Arguments, BoolOp, CmpOp, Comprehension, ConversionFlag, DebugText, Decorator, DictItem,
25+
ExceptHandler, ExceptHandlerExceptHandler, Expr, ExprAttribute, ExprBoolOp, ExprContext,
26+
ExprFString, ExprList, ExprName, ExprSlice, ExprStarred, ExprSubscript, ExprTuple, ExprUnaryOp,
27+
FString, FStringFlags, FStringPart, Identifier, Int, InterpolatedElement,
28+
InterpolatedStringElement, InterpolatedStringElements, Keyword, MatchCase, ModExpression,
29+
ModModule, Operator, Parameters, Pattern, PatternMatchAs, PatternMatchClass,
30+
PatternMatchMapping, PatternMatchOr, PatternMatchSequence, PatternMatchSingleton,
31+
PatternMatchStar, PatternMatchValue, Singleton, Stmt, StmtExpr, TypeParam, TypeParamParamSpec,
32+
TypeParamTypeVar, TypeParamTypeVarTuple, TypeParams, UnaryOp, WithItem,
3333
};
3434
use ruff_text_size::{Ranged, TextRange};
3535
use rustpython_compiler_core::{
3636
Mode, OneIndexed, PositionEncoding, SourceFile, SourceLocation,
3737
bytecode::{
3838
self, Arg as OpArgMarker, BinaryOperator, BuildSliceArgCount, CodeObject,
39-
ComparisonOperator, ConstantData, ConversionFlag, Instruction, Invert, OpArg, OpArgType,
39+
ComparisonOperator, ConstantData, ConvertValueOparg, Instruction, Invert, OpArg, OpArgType,
4040
UnpackExArgs,
4141
},
4242
};
@@ -5638,10 +5638,10 @@ impl Compiler {
56385638
}
56395639
InterpolatedStringElement::Interpolation(fstring_expr) => {
56405640
let mut conversion = match fstring_expr.conversion {
5641-
ruff_python_ast::ConversionFlag::None => ConversionFlag::None,
5642-
ruff_python_ast::ConversionFlag::Str => ConversionFlag::Str,
5643-
ruff_python_ast::ConversionFlag::Repr => ConversionFlag::Repr,
5644-
ruff_python_ast::ConversionFlag::Ascii => ConversionFlag::Ascii,
5641+
ConversionFlag::None => ConvertValueOparg::None,
5642+
ConversionFlag::Str => ConvertValueOparg::Str,
5643+
ConversionFlag::Repr => ConvertValueOparg::Repr,
5644+
ConversionFlag::Ascii => ConvertValueOparg::Ascii,
56455645
};
56465646

56475647
if let Some(DebugText { leading, trailing }) = &fstring_expr.debug_text {
@@ -5657,17 +5657,19 @@ impl Compiler {
56575657
// See: https://github.com/python/cpython/blob/f61afca262d3a0aa6a8a501db0b1936c60858e35/Parser/action_helpers.c#L1456
56585658
if matches!(
56595659
(conversion, &fstring_expr.format_spec),
5660-
(ConversionFlag::None, None)
5660+
(ConvertValueOparg::None, None)
56615661
) {
5662-
conversion = ConversionFlag::Repr;
5662+
conversion = ConvertValueOparg::Repr;
56635663
}
56645664
}
56655665

56665666
self.compile_expression(&fstring_expr.expression)?;
56675667

56685668
match conversion {
5669-
ConversionFlag::None => {}
5670-
ConversionFlag::Str | ConversionFlag::Repr | ConversionFlag::Ascii => {
5669+
ConvertValueOparg::None => {}
5670+
ConvertValueOparg::Str
5671+
| ConvertValueOparg::Repr
5672+
| ConvertValueOparg::Ascii => {
56715673
emit!(self, Instruction::ConvertValue { oparg: conversion })
56725674
}
56735675
}

crates/codegen/src/snapshots/rustpython_codegen__compile__tests__nested_double_async_with.snap

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

crates/compiler-core/src/bytecode.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ use std::{collections::BTreeSet, fmt, hash, marker::PhantomData, mem, num::NonZe
1919
/// - [CPython FVC_* flags](https://github.com/python/cpython/blob/8183fa5e3f78ca6ab862de7fb8b14f3d929421e0/Include/ceval.h#L129-L132)
2020
#[repr(u8)]
2121
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
22-
pub enum ConversionFlag {
23-
/// No conversion flag.
22+
pub enum ConvertValueOparg {
23+
/// No conversion.
2424
///
2525
/// ```python
2626
/// f"{x}"
@@ -50,7 +50,7 @@ pub enum ConversionFlag {
5050
Ascii = 3,
5151
}
5252

53-
impl fmt::Display for ConversionFlag {
53+
impl fmt::Display for ConvertValueOparg {
5454
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
5555
let out = match self {
5656
Self::Str => "1 (str)",
@@ -514,7 +514,7 @@ impl fmt::Display for Label {
514514
}
515515
}
516516

517-
impl OpArgType for ConversionFlag {
517+
impl OpArgType for ConvertValueOparg {
518518
#[inline]
519519
fn from_op_arg(x: u32) -> Option<Self> {
520520
Some(match x {
@@ -825,7 +825,7 @@ pub enum Instruction {
825825
///
826826
/// Used for implementing formatted string literals (f-strings).
827827
ConvertValue {
828-
oparg: Arg<ConversionFlag>,
828+
oparg: Arg<ConvertValueOparg>,
829829
},
830830
/// Formats the value on top of stack:
831831
///

crates/vm/src/frame.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2254,16 +2254,16 @@ impl ExecutingFrame<'_> {
22542254

22552255
fn convert_value(
22562256
&mut self,
2257-
conversion: bytecode::ConversionFlag,
2257+
conversion: bytecode::ConvertValueOparg,
22582258
vm: &VirtualMachine,
22592259
) -> FrameResult {
2260-
use bytecode::ConversionFlag;
2260+
use bytecode::ConvertValueOparg;
22612261
let value = self.pop_value();
22622262
let value = match conversion {
2263-
ConversionFlag::Str => value.str(vm)?.into(),
2264-
ConversionFlag::Repr => value.repr(vm)?.into(),
2265-
ConversionFlag::Ascii => vm.ctx.new_str(builtins::ascii(value, vm)?).into(),
2266-
ConversionFlag::None => value,
2263+
ConvertValueOparg::Str => value.str(vm)?.into(),
2264+
ConvertValueOparg::Repr => value.repr(vm)?.into(),
2265+
ConvertValueOparg::Ascii => vm.ctx.new_str(builtins::ascii(value, vm)?).into(),
2266+
ConvertValueOparg::None => value,
22672267
};
22682268

22692269
self.push_value(value);

crates/vm/src/stdlib/ast/other.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ impl Node for ruff::ConversionFlag {
1414
) -> PyResult<Self> {
1515
i32::try_from_object(vm, object)?
1616
.to_u32()
17-
.and_then(bytecode::ConversionFlag::from_op_arg)
17+
.and_then(bytecode::ConvertValueOparg::from_op_arg)
1818
.map(|flag| match flag {
19-
bytecode::ConversionFlag::None => Self::None,
20-
bytecode::ConversionFlag::Str => Self::Str,
21-
bytecode::ConversionFlag::Ascii => Self::Ascii,
22-
bytecode::ConversionFlag::Repr => Self::Repr,
19+
bytecode::ConvertValueOparg::None => Self::None,
20+
bytecode::ConvertValueOparg::Str => Self::Str,
21+
bytecode::ConvertValueOparg::Repr => Self::Repr,
22+
bytecode::ConvertValueOparg::Ascii => Self::Ascii,
2323
})
2424
.ok_or_else(|| vm.new_value_error("invalid conversion flag"))
2525
}

0 commit comments

Comments
 (0)