Skip to content

Allow any mapping for locals.#3314

Merged
DimitrisJim merged 2 commits into
RustPython:mainfrom
DimitrisJim:mapping_locals
Oct 16, 2021
Merged

Allow any mapping for locals.#3314
DimitrisJim merged 2 commits into
RustPython:mainfrom
DimitrisJim:mapping_locals

Conversation

@DimitrisJim

Copy link
Copy Markdown
Member

No description provided.

Comment thread vm/src/frame.rs
Comment thread vm/src/frame.rs Outdated
Comment thread vm/src/frame.rs Outdated
Comment thread vm/src/stdlib/builtins.rs Outdated
@DimitrisJim DimitrisJim force-pushed the mapping_locals branch 2 times, most recently from 6361512 to 067bb73 Compare October 15, 2021 17:49
Comment thread vm/src/frame.rs Outdated
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) {

@youknowone youknowone Oct 16, 2021

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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.

@DimitrisJim DimitrisJim Oct 16, 2021

Copy link
Copy Markdown
Member Author

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
Copy Markdown
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