Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Refactor and new sequence traits, generic sequence operation#3445

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
qingshi163 merged 7 commits intoRustPython:mainfromqingshi163:main
Nov 22, 2021

Conversation

qingshi163
Copy link
Contributor

No description provided.

@qingshi163
Copy link
ContributorAuthor

#3316

@qingshi163qingshi163 marked this pull request as ready for reviewNovember 19, 2021 06:02
@qingshi163qingshi163 changed the title[WIP] Refactor and new sequence traits, generic sequence operationRefactor and new sequence traits, generic sequence operationNov 19, 2021
let mul = sequence::seq_mul(vm, &deque, value)?;
fn _mul(&self, n: isize, vm: &VirtualMachine) -> PyResult<VecDeque<PyObjectRef>> {
let deque = self.borrow_deque();
let n = vm.check_repeat_or_memory_error(deque.len(), n)?;
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

bit confuse, should it return overflow error rather than memory error?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

after reading the issue 45044 from cpython, I think we should replace all the memory error with overflow error because currently we did not catch the malloc failing.
What do you think?@DimitrisJim@youknowone

Copy link
Member

Choose a reason for hiding this comment

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

that sounds like reasonable

Comment on lines 102 to 104
#[inline]
fn _mut_iter_equal_skeleton<F, const SHORT: bool>(
Copy link
Contributor

Choose a reason for hiding this comment

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

This method seems somewhat complex despite it declared asinline. How do you think?

qingshi163 reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

This one is the skeleton for other related function, only few place is calling it. Also as it is generic, so it should be duplicate for each generic parameters. I mark it inline to try to hint the compiler to optimize out the const bool condition check and the closure it called. I don't know what exactly code the compiler produce but inline is what I expected.

Snowapril reacted with thumbs up emoji
Copy link
Member

Choose a reason for hiding this comment

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

I don't think#[inline] make any difference forSHORT. const generic paremeter must be a constant regardless of inlining.

sequence::cmp(vm, a.boxed_iter(), b.boxed_iter(), op).map(PyComparisonValue::Implemented)
let a = &*zelf.borrow_vec();
let b = &*other.borrow_vec();
// sequence::cmp(vm, a.boxed_iter(), b.boxed_iter(), op).map(PyComparisonValue::Implemented)
Copy link
Member

Choose a reason for hiding this comment

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

outdated comment?

Comment on lines 18 to 27
if lhs.len() == rhs.len() {
for (a, b) in lhs.zip_eq(rhs) {
if !vm.identical_or_equal(a, b)? {
return Ok(false);
}
}
Ok(true)
} else {
Ok(false)
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if lhs.len() == rhs.len(){
for(a, b)in lhs.zip_eq(rhs){
if !vm.identical_or_equal(a, b)?{
returnOk(false);
}
}
Ok(true)
}else{
Ok(false)
}
if lhs.len() != rhs.len(){
returnOk(false);
}
for(a, b)in lhs.zip_eq(rhs){
if !vm.identical_or_equal(a, b)?{
returnOk(false);
}
}
Ok(true)

to reduce intent level

Comment on lines 263 to 267
impl SequenceOp<u8> for &str {
fn as_slice(&self) -> &[u8] {
self.as_bytes()
}
}
Copy link
Member

Choose a reason for hiding this comment

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

I think this doesn't fit the convention ofas_slice() - whenself isstr but return type is&[u8].
The only place this is called isPyStr::mul. I'd rather suggest to usezelf.as_str().as_bytes().mul(..) there than implicitly regarding str as sequence of u8.

Suggested change
implSequenceOp<u8>for&str{
fn as_slice(&self) ->&[u8]{
self.as_bytes()
}
}

qingshi163 reacted with thumbs up emoji
Comment on lines 102 to 104
#[inline]
fn _mut_iter_equal_skeleton<F, const SHORT: bool>(
Copy link
Member

Choose a reason for hiding this comment

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

I don't think#[inline] make any difference forSHORT. const generic paremeter must be a constant regardless of inlining.

@qingshi163qingshi163 merged commit908b239 intoRustPython:mainNov 22, 2021
@qingshi163qingshi163 deleted the main branchNovember 22, 2021 07:21
youknowone added a commit to youknowone/RustPython that referenced this pull requestNov 26, 2021
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@SnowaprilSnowaprilSnowapril left review comments

@youknowoneyouknowoneyouknowone approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@qingshi163@youknowone@Snowapril

[8]ページ先頭

©2009-2025 Movatter.jp