Skip to content

Allow any mapping for locals. #3314

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

Merged
merged 2 commits into from
Oct 16, 2021
Merged

Conversation

DimitrisJim
Copy link
Member

No description provided.

@DimitrisJim DimitrisJim force-pushed the mapping_locals branch 2 times, most recently from 6361512 to 067bb73 Compare October 15, 2021 17:49
vm/src/frame.rs Outdated
@@ -559,7 +578,7 @@ impl ExecutingFrame<'_> {
}
bytecode::Instruction::DeleteLocal(idx) => {
let name = &self.code.names[*idx as usize];
match self.locals.del_item(name.clone(), vm) {
match self.locals.clone().into_object().del_item(name.clone(), vm) {
Copy link
Member

@youknowone youknowone Oct 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is calling del_item from ItemProtocol. The ideal way to do this would be impl ItemProtocol for PyBuffer. Then self.locals.del_item will work.
Actually, most of the code from ItemProtocol for PyObjectRef looks PyMapping's.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, not that simple due to sequence protocol.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, when #3316 lands, get/set/del item should be amended to try and and also use the sequence protocol, as CPython does.

Copy link
Member Author

@DimitrisJim DimitrisJim Oct 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but I didn't use the check here to try the dict method first (which is what is going to get used most of the times), I'll add that now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After reviewing ItemProtocol, I now feel like it is almost useless. ItemProcotol for PyDict includes the dict-first branch. Because it is there, we cannot reuse the code here.

@DimitrisJim DimitrisJim merged commit 45290b1 into RustPython:main Oct 16, 2021
@DimitrisJim DimitrisJim deleted the mapping_locals branch November 7, 2021 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants