Skip to content
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

Eliminate a mem::transmute in CodeGen #15659

Merged
merged 1 commit into from Feb 21, 2017
Merged

Conversation

@gregkatz
Copy link
Contributor

gregkatz commented Feb 20, 2017

Eliminate a mem::transmute in CodeGen by changing the find_enum_string_index function to take a slice of pairs and return an enum value.


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #15587 (github issue number if applicable).
  • There are tests for these changes OR
  • These changes do not require tests because _____

This change is Reviewable

@highfive
Copy link

highfive commented Feb 20, 2017

Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @mbrubeck (or someone else) soon.

@highfive
Copy link

highfive commented Feb 20, 2017

Heads up! This PR modifies the following files:

  • @fitzgen: components/script/dom/bindings/codegen/CodegenRust.py, components/script/dom/bindings/utils.rs
  • @KiChjang: components/script/dom/bindings/codegen/CodegenRust.py, components/script/dom/bindings/utils.rs
@highfive
Copy link

highfive commented Feb 20, 2017

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!
  • These commits modify script code, but no tests are modified. Please consider adding a test!
""" % (",\n ".join(['"%s"' % val for val in enum.values()]), enum.identifier.name, enum.identifier.name)

""" % (ident,
",\n ".join(['("%s", super::%s::%s)' % (val, ident, getEnumValueName(val)) for val in enum.values()]),

This comment has been minimized.

Copy link
@Ms2ger

Ms2ger Feb 20, 2017

Contributor

Maybe define this in a local variable

pub unsafe fn find_enum_value<T: Copy>(cx: *mut JSContext,
v: HandleValue,
pairs: &[(&'static str, T)])
-> Result<(Option<T>, DOMString), ()> {

This comment has been minimized.

Copy link
@Ms2ger

Ms2ger Feb 20, 2017

Contributor

I think we can avoid the Copy bound by doing

                                       pairs: &'a [(&'static str, T)])
                                       -> Result<(Option<&'a T>, DOMString), ()> {

and then in the generated code

Ok((Some(&value), _)) => value,

This comment has been minimized.

Copy link
@gregkatz

gregkatz Feb 20, 2017

Author Contributor

Thanks for the comments! I'll work on them.

/// Returns `Err(())` on JSAPI failure (there is a pending exception), and
/// `Ok((None, value))` if there was no matching string.
pub unsafe fn find_enum_string_index(cx: *mut JSContext,
pub unsafe fn find_enum_value<'a, T>(cx: *mut JSContext,

This comment has been minimized.

Copy link
@nox

nox Feb 21, 2017

Member

I don't think you need the explicit 'a here, lifetime elision should do the job.

@Ms2ger
Copy link
Contributor

Ms2ger commented Feb 21, 2017

I think it's fine.

@bors-servo r+

@bors-servo
Copy link
Contributor

bors-servo commented Feb 21, 2017

📌 Commit 214db8d has been approved by Ms2ger

@highfive highfive assigned Ms2ger and unassigned mbrubeck Feb 21, 2017
@bors-servo
Copy link
Contributor

bors-servo commented Feb 21, 2017

Testing commit 214db8d with merge af6353d...

bors-servo added a commit that referenced this pull request Feb 21, 2017
Eliminate a mem::transmute in CodeGen

<!-- Please describe your changes on the following line: -->
Eliminate a mem::transmute in CodeGen by changing the find_enum_string_index function to take a slice of pairs and return an enum value.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #15587 (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [X] These changes do not require tests because _____

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15659)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Feb 21, 2017

@bors-servo bors-servo merged commit 214db8d into servo:master Feb 21, 2017
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

6 participants
You can’t perform that action at this time.