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

Replace usage of std::intrinsics::discriminant_value with `match` #11884

Merged
merged 2 commits into from Jun 28, 2016

Conversation

@SimonSapin
Copy link
Member

SimonSapin commented Jun 27, 2016

Replace usage of std::intrinsics::discriminant_value with per-enum generated code that uses match expressions. The LLVM IR shows that this optimizes well in release mode.


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix part of #11815.
  • There are tests for these changes OR
  • These changes do not require new tests because they shouldn’t change any behavior.

This change is Reviewable

@highfive
Copy link

highfive commented Jun 27, 2016

Heads up! This PR modifies the following files:

  • @bholley: components/style/properties/properties.mako.rs
@highfive
Copy link

highfive commented Jun 27, 2016

warning Warning warning

  • These commits modify style code, but no tests are modified. Please consider adding a test!
@SimonSapin
Copy link
Member Author

SimonSapin commented Jun 27, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Jun 27, 2016

Trying commit 5fe3e85 with merge fdbcd64...

bors-servo added a commit that referenced this pull request Jun 27, 2016
Replace usage of std::intrinsics::discriminant_value in properties.mako.rs

<!-- Please describe your changes on the following line: -->

**WIP, do not merge yet.**

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

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] 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. -->
@SimonSapin
Copy link
Member Author

SimonSapin commented Jun 27, 2016

Test crate:

#![feature(core_intrinsics)]

extern crate style;

use std::intrinsics::discriminant_value;

pub fn with_match(decl: &style::properties::PropertyDeclaration) -> usize {
    decl.discriminant_value()
}

pub fn with_intrinsic(decl: &style::properties::PropertyDeclaration) -> usize {
    unsafe { discriminant_value(decl) as usize }
}

cargo rustc -- --emit=llvm-ir produces a .ll file that has 6843 lines.

cargo rustc --release -- --emit=llvm-ir produces this :)

; ModuleID = 'style_stable.0.rs'
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%"11.style::properties::PropertyDeclaration" = type { i64, [0 x i64], [60 x i64] }

; Function Attrs: norecurse nounwind readonly uwtable
define i64 @_ZN12style_stable10with_match17h5ee51730fa1d4ed4E(%"11.style::properties::PropertyDeclaration"* noalias nocapture readonly dereferenceable(488)) unnamed_addr #0 {
entry-block:
  %.idx = getelementptr %"11.style::properties::PropertyDeclaration", %"11.style::properties::PropertyDeclaration"* %0, i64 0, i32 0
  %.idx.val = load i64, i64* %.idx, align 8
  ret i64 %.idx.val
}

; Function Attrs: norecurse nounwind readonly uwtable
define i64 @_ZN12style_stable14with_intrinsic17h38553922905ee296E(%"11.style::properties::PropertyDeclaration"* noalias nocapture readonly dereferenceable(488)) unnamed_addr #0 {
entry-block:
  %1 = getelementptr inbounds %"11.style::properties::PropertyDeclaration", %"11.style::properties::PropertyDeclaration"* %0, i64 0, i32 0
  %2 = load i64, i64* %1, align 8, !range !0
  ret i64 %2
}

attributes #0 = { norecurse nounwind readonly uwtable }

!0 = !{i64 0, i64 129}
@bors-servo
Copy link
Contributor

bors-servo commented Jun 27, 2016

@SimonSapin SimonSapin force-pushed the antidiscrimination branch from 5fe3e85 to 4453909 Jun 27, 2016
@SimonSapin SimonSapin changed the title Replace usage of std::intrinsics::discriminant_value in properties.mako.rs Replace usage of std::intrinsics::discriminant_value with `match` Jun 27, 2016
@SimonSapin SimonSapin mentioned this pull request Jun 27, 2016
7 of 7 tasks complete
@SimonSapin
Copy link
Member Author

SimonSapin commented Jun 27, 2016

@highfive highfive assigned bholley and unassigned jdm Jun 27, 2016
@bors-servo
Copy link
Contributor

bors-servo commented Jun 27, 2016

The latest upstream changes (presumably #11834) made this pull request unmergeable. Please resolve the merge conflicts.

@SimonSapin SimonSapin force-pushed the antidiscrimination branch from 4453909 to 3932a82 Jun 28, 2016
@nox
Copy link
Member

nox commented Jun 28, 2016

@bors-servo r+


Reviewed 2 of 2 files at r1, 1 of 1 files at r2, 2 of 2 files at r3, 2 of 2 files at r4, 2 of 2 files at r5.
Review status: all files reviewed at latest revision, all discussions resolved.


Comments from Reviewable

@bors-servo
Copy link
Contributor

bors-servo commented Jun 28, 2016

📌 Commit 3932a82 has been approved by nox

@highfive highfive assigned nox and unassigned bholley Jun 28, 2016
@bors-servo
Copy link
Contributor

bors-servo commented Jun 28, 2016

Testing commit 3932a82 with merge 810735a...

bors-servo added a commit that referenced this pull request Jun 28, 2016
Replace usage of std::intrinsics::discriminant_value with `match`

<!-- Please describe your changes on the following line: -->

Replace usage of `std::intrinsics::discriminant_value` with per-enum generated code that uses `match` expressions. The LLVM IR shows that this optimizes well in release mode.

---
<!-- 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 part of #11815.

<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require new tests because they shouldn’t change any behavior.

<!-- 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="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11884)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Jun 28, 2016

@bors-servo bors-servo merged commit 3932a82 into master Jun 28, 2016
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@SimonSapin SimonSapin deleted the antidiscrimination branch Jun 28, 2016
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.

None yet

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