Skip to content

Commit 44f6446

Browse files
committed
End of IntoPyStrRef
1 parent dfb37d9 commit 44f6446

File tree

7 files changed

+16
-63
lines changed

7 files changed

+16
-63
lines changed

vm/src/builtins/str.rs

Lines changed: 3 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -143,52 +143,6 @@ impl fmt::Display for PyStr {
143143
}
144144
}
145145

146-
pub trait IntoPyStrRef {
147-
fn into_pystr_ref(self, vm: &VirtualMachine) -> PyStrRef;
148-
}
149-
150-
impl IntoPyStrRef for PyStrRef {
151-
#[inline]
152-
fn into_pystr_ref(self, _vm: &VirtualMachine) -> PyRef<PyStr> {
153-
self
154-
}
155-
}
156-
157-
impl IntoPyStrRef for PyStr {
158-
#[inline]
159-
fn into_pystr_ref(self, vm: &VirtualMachine) -> PyRef<PyStr> {
160-
self.into_ref(vm)
161-
}
162-
}
163-
164-
impl IntoPyStrRef for AsciiString {
165-
#[inline]
166-
fn into_pystr_ref(self, vm: &VirtualMachine) -> PyRef<PyStr> {
167-
PyStr::from(self).into_ref(vm)
168-
}
169-
}
170-
171-
impl IntoPyStrRef for String {
172-
#[inline]
173-
fn into_pystr_ref(self, vm: &VirtualMachine) -> PyRef<PyStr> {
174-
PyStr::from(self).into_ref(vm)
175-
}
176-
}
177-
178-
impl IntoPyStrRef for &str {
179-
#[inline]
180-
fn into_pystr_ref(self, vm: &VirtualMachine) -> PyRef<PyStr> {
181-
PyStr::from(self).into_ref(vm)
182-
}
183-
}
184-
185-
impl IntoPyStrRef for &'static PyStrInterned {
186-
#[inline]
187-
fn into_pystr_ref(self, _vm: &VirtualMachine) -> PyRef<PyStr> {
188-
self.to_owned()
189-
}
190-
}
191-
192146
pub trait AsPyStr<'a>
193147
where
194148
Self: 'a,
@@ -655,7 +609,7 @@ impl PyStr {
655609
if s == stripped {
656610
zelf
657611
} else {
658-
stripped.into_pystr_ref(vm)
612+
vm.ctx.new_str(stripped)
659613
}
660614
}
661615

@@ -674,7 +628,7 @@ impl PyStr {
674628
if s == stripped {
675629
zelf
676630
} else {
677-
stripped.into_pystr_ref(vm)
631+
vm.ctx.new_str(stripped)
678632
}
679633
}
680634

@@ -985,7 +939,7 @@ impl PyStr {
985939
}
986940
Err(iter) => zelf.as_str().py_join(iter)?,
987941
};
988-
Ok(joined.into_pystr_ref(vm))
942+
Ok(vm.ctx.new_str(joined))
989943
}
990944

991945
// FIXME: two traversals of str is expensive

vm/src/frame.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,7 @@ impl ExecutingFrame<'_> {
11441144
fn import_from(&mut self, vm: &VirtualMachine, idx: bytecode::NameIdx) -> PyResult {
11451145
let module = self.last_value();
11461146
let name = self.code.names[idx as usize];
1147-
let err = || vm.new_import_error(format!("cannot import name '{name}'"), name);
1147+
let err = || vm.new_import_error(format!("cannot import name '{name}'"), name.to_owned());
11481148
// Load attribute, and transform any error into import error.
11491149
if let Some(obj) = vm.get_attribute_opt(module.clone(), name)? {
11501150
return Ok(obj);

vm/src/import.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,12 @@ pub(crate) fn init_importlib_package(
7373
}
7474

7575
pub fn make_frozen(vm: &VirtualMachine, name: &str) -> PyResult<PyRef<PyCode>> {
76-
let frozen =
77-
vm.state.frozen.get(name).ok_or_else(|| {
78-
vm.new_import_error(format!("No such frozen object named {name}"), name)
79-
})?;
76+
let frozen = vm.state.frozen.get(name).ok_or_else(|| {
77+
vm.new_import_error(
78+
format!("No such frozen object named {name}"),
79+
vm.ctx.new_str(name),
80+
)
81+
})?;
8082
Ok(vm.ctx.new_code(frozen.code))
8183
}
8284

@@ -92,7 +94,7 @@ pub fn import_builtin(vm: &VirtualMachine, module_name: &str) -> PyResult {
9294
let make_module_func = vm.state.module_inits.get(module_name).ok_or_else(|| {
9395
vm.new_import_error(
9496
format!("Cannot import builtin module {module_name}"),
95-
module_name,
97+
vm.ctx.new_str(module_name),
9698
)
9799
})?;
98100
let module = make_module_func(vm);

vm/src/scope.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl Scope {
141141
// impl Sealed for super::PyStrRef {}
142142
// }
143143
// pub trait PyName:
144-
// sealed::Sealed + crate::dictdatatype::DictKey + Clone + ToPyObject + IntoPyStrRef
144+
// sealed::Sealed + crate::dictdatatype::DictKey + Clone + ToPyObject
145145
// {
146146
// }
147147
// impl PyName for str {}

vm/src/stdlib/imp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl FrozenError {
6969
Excluded => format!("Excluded frozen object named {mod_name}"),
7070
Invalid => format!("Frozen object named {mod_name} is invalid"),
7171
};
72-
vm.new_import_error(msg, mod_name)
72+
vm.new_import_error(msg, vm.ctx.new_str(mod_name))
7373
}
7474
}
7575

vm/src/stdlib/sys.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ mod sys {
367367
_ => return print_unimportable_module_warn(),
368368
};
369369

370-
let (module_path, attr_name) = if last.eq(&env_var) {
370+
let (module_path, attr_name) = if last == env_var {
371371
("builtins", env_var.as_str())
372372
} else {
373373
(&env_var[..(env_var.len() - last.len() - 1)], last)

vm/src/vm/vm_new.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::{
22
builtins::{
3-
pystr::IntoPyStrRef,
43
tuple::{IntoPyTuple, PyTupleRef},
54
PyBaseException, PyBaseExceptionRef, PyDictRef, PyModule, PyStrRef, PyType, PyTypeRef,
65
},
@@ -268,12 +267,10 @@ impl VirtualMachine {
268267
syntax_error
269268
}
270269

271-
pub fn new_import_error(&self, msg: String, name: impl IntoPyStrRef) -> PyBaseExceptionRef {
270+
pub fn new_import_error(&self, msg: String, name: PyStrRef) -> PyBaseExceptionRef {
272271
let import_error = self.ctx.exceptions.import_error.to_owned();
273272
let exc = self.new_exception_msg(import_error, msg);
274-
exc.as_object()
275-
.set_attr("name", name.into_pystr_ref(self), self)
276-
.unwrap();
273+
exc.as_object().set_attr("name", name, self).unwrap();
277274
exc
278275
}
279276

0 commit comments

Comments
 (0)