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

Miri and miri-related code contains repetitions of (n << amt) >> amt #49937

Closed
oli-obk opened this issue Apr 13, 2018 · 20 comments
Closed

Miri and miri-related code contains repetitions of (n << amt) >> amt #49937

oli-obk opened this issue Apr 13, 2018 · 20 comments
Labels
A-const-eval Area: constant evaluation (mir interpretation) C-enhancement Category: An issue proposing an enhancement or a PR with one. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@oli-obk
Copy link
Contributor

oli-obk commented Apr 13, 2018

All of these should be deduplicated under a common set of functions that do sign extension or truncation of integers.

The functions should live somewhere in librustc, so probably librustc::mir::interpret, because they are also needed in librustc::ty::layout.

The parts that need to be figured out:

  • what information is needed in each function (so we don't have to prepend all function calls with an "almost the same" computation of e.g. type layouts.
  • are there many uses of sign extension followed by truncation and should these be a single function, too?
@oli-obk oli-obk added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. A-const-eval Area: constant evaluation (mir interpretation) labels Apr 13, 2018
@stevepentland
Copy link
Contributor

This sounds pretty interesting and I may like to take it on, but I don't really understand the scope of what will be changed at the moment.

@oli-obk
Copy link
Contributor Author

oli-obk commented May 6, 2018

@stevepentland the goal is to reduce code repetition. Essentially all code that looks similar to the title code should be calling dedicated functions for either sign or zero extension. These methods already exist on the EvalContext, but we need to move them to rustc::mir::interpret so we can also use them for the code in the file that declares struct Discr<'tcx>.

@QuestofIranon
Copy link

I'm interested in taking this on if anything still needs to be done for it.

@oli-obk
Copy link
Contributor Author

oli-obk commented Jun 26, 2018

I think we have the appropriate functions now, but we aren't using them everywhere, and they don't live in librustc yet (they are still in rustc_mir::interpret)

@kostrowski
Copy link

I believe these are all the locations that do sign extensions or truncates:

In each case the operations are preceded by usage of either rustc_target::abi::TyLayout via fn TyCtxt::layout_of(...) or rustc_target::abi::Integer via fn IntegerExt::from_attr(...) to get the size of the type that's needed to perform the bit shifts.

Since an Integer can be extracted from a TyLayout for integer layouts, I believe that the best location for the sign_extend and truncate functions would be as instance methods on Integer. The instance methods internally would have access to the size, so we could de-duplicate quite a bit of code at each call site.

I think there are two options for where to locate the method implementations:

  1. Within the impl block here in 'librustc_target.
  2. Within the impl IntegerExt for Integer block here in librust.

I'm happy to work on a pull request if this seems like a reasonable way to refactor. I haven't contributed to the project before, so might need some guidance.

@oli-obk
Copy link
Contributor Author

oli-obk commented Aug 10, 2018

Great writeup of the current state!

I think it can live directly in the impl block, because it's not something that requires any types beyond u128.

How verbose and common would it be to need to extract the Integer from the TyLayout? Maybe a helper method on TyLayout could make sense.

I'm happy to work on a pull request if this seems like a reasonable way to refactor. I haven't contributed to the project before, so might need some guidance.

Feel free to ask anything here or on discord/zulip/irc. General build instructions can be found at https://github.com/rust-lang/rust#building-from-source and https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#the-build-system

I also can advise to set incremental = true in the config.toml (file is described in https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#configuration). Incremental will speed up your build process a lot, even if tests run a little slower then.

@kostrowski
Copy link

Okay, I'll take a look at it and hopefully have something shortly. Thank you for the tip about incremental = true; I've been building okay but didn't have that setting.

How verbose and common would it be to need to extract the Integer from the TyLayout? Maybe a helper method on TyLayout could make sense.

I think it has to peel back enough layers of TyLayout to warrant a helper method. There are already helper methods on both TyLayout and Abi. Abi has is_unsized and is_signed while TyLayout has is_unsized (a simple wrapper around Abi::is_unsized) and is_zst. Given that TyLayout derefs to LayoutDetails which has the abi: Abi field, it really isn't much different for the call sites to use one or the other (e.g. either layout.as_integer() or layout.abi.as_integer()).

I figure the helper method (as_integer()?) can return an Option<Integer> and let the call sites decide what to do when the layout isn't for an integer (likely just panic on unwrapping).

@oli-obk
Copy link
Contributor Author

oli-obk commented Aug 16, 2018

@XAMPPRocky XAMPPRocky added C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 27, 2018
@kenta7777
Copy link
Contributor

I'd like to tackle this issue. How shall we begin?

@oli-obk
Copy link
Contributor Author

oli-obk commented Oct 30, 2018

I am actually not sure right now. There were a lot of changes to the compiler.

You can start by going through this list and seeing whether there are any left that need to be addressed

@kenta7777
Copy link
Contributor

@oli-obk Thank you for your advice. I' ll try.

@varkor
Copy link
Member

varkor commented Dec 10, 2018

How shall we begin?

There are also some comments // FIXME(49937) in the code that you should take a look at.

@kenta7777
Copy link
Contributor

@varkor Sorry for the delay in replying. Thanks!

Centril added a commit to Centril/rust that referenced this issue Jan 25, 2019
Miri and miri-related code contains repetitions of `(n << amt) >> amt`

I reduced some code repetitions contains `(n << amt) >> amt`.
This pull request is related to rust-lang#49937.
kennytm added a commit to kennytm/rust that referenced this issue Feb 20, 2019
…=oli-obk

Reduce Some Code Repetitions like `(n << amt) >> amt`

This Pull Request is related to [rust-lang#49937](rust-lang#49937).
This Pull Request has reduced repetition of `(n << amt) >> amt`.
Centril added a commit to Centril/rust that referenced this issue Feb 23, 2019
…n, r=petrochenkov

Reduce Miri-related Code Repetition `like (n << amt) >> amt`

This Pull Request fixes a part of [rust-lang#49937](rust-lang#49937).
Centril added a commit to Centril/rust that referenced this issue Feb 23, 2019
…n, r=petrochenkov

Reduce Miri-related Code Repetition `like (n << amt) >> amt`

This Pull Request fixes a part of [rust-lang#49937](rust-lang#49937).
Centril added a commit to Centril/rust that referenced this issue Feb 25, 2019
…on, r=oli-obk

Reduce Miri Code Repetition like `(n << amt) >> amt`

This Pull Request fixes a part of [rust-lang#49937](rust-lang#49937).
Centril added a commit to Centril/rust that referenced this issue Feb 25, 2019
…ri-related, r=oli-obk

Reduce a Code Repetition like `(n << amt) >> amt`

Fixes a part of [rust-lang#49937](rust-lang#49937).
Centril added a commit to Centril/rust that referenced this issue Feb 25, 2019
…on, r=oli-obk

Reduce Miri Code Repetition like `(n << amt) >> amt`

This Pull Request fixes a part of [rust-lang#49937](rust-lang#49937).
Centril added a commit to Centril/rust that referenced this issue Feb 25, 2019
…ri-related, r=oli-obk

Reduce a Code Repetition like `(n << amt) >> amt`

Fixes a part of [rust-lang#49937](rust-lang#49937).
Centril added a commit to Centril/rust that referenced this issue Feb 25, 2019
…on, r=oli-obk

Reduce Miri Code Repetition like `(n << amt) >> amt`

This Pull Request fixes a part of [rust-lang#49937](rust-lang#49937).
Centril added a commit to Centril/rust that referenced this issue Feb 25, 2019
…ri-related, r=oli-obk

Reduce a Code Repetition like `(n << amt) >> amt`

Fixes a part of [rust-lang#49937](rust-lang#49937).
Centril added a commit to Centril/rust that referenced this issue Feb 27, 2019
Centril added a commit to Centril/rust that referenced this issue Feb 27, 2019
Centril added a commit to Centril/rust that referenced this issue Feb 27, 2019
Centril added a commit to Centril/rust that referenced this issue Feb 27, 2019
Centril added a commit to Centril/rust that referenced this issue Feb 27, 2019
@kenta7777
Copy link
Contributor

I think Reducing the repetition of this list has almost finished.
Are the remaining repetition marked by // FIXME(49937) only?

@oli-obk
Copy link
Contributor Author

oli-obk commented Mar 1, 2019

I think Reducing the repetition of this list has almost finished

Awesome! Thank you

Are the remaining repetition marked by // FIXME(49937) only
?

There might be more, but I'm fine closing this issue after the known ones are done.

@kenta7777
Copy link
Contributor

I understand. I'll keep working on this issue until the repetition of // FIXME(49937) codes are reduced.

kennytm added a commit to kennytm/rust that referenced this issue Mar 11, 2019
…=oli-obk

Reduces Code Repetitions like `!n >> amt`

Fixes rust-lang#49937 .
This PR contains defining a function which operates bit inversion and reducing bit operation like `!0u128 >> (128 - size.bits())`.
pietroalbini added a commit to pietroalbini/rust that referenced this issue Mar 12, 2019
…=oli-obk

Reduces Code Repetitions like `!n >> amt`

Fixes rust-lang#49937 .
This PR contains defining a function which operates bit inversion and reducing bit operation like `!0u128 >> (128 - size.bits())`.
Centril added a commit to Centril/rust that referenced this issue Mar 13, 2019
…=oli-obk

Reduces Code Repetitions like `!n >> amt`

Fixes rust-lang#49937 .
This PR contains defining a function which operates bit inversion and reducing bit operation like `!0u128 >> (128 - size.bits())`.
@kenta7777
Copy link
Contributor

@oli-obk Could you open this issue because codes which should be fixed still remain?

@oli-obk oli-obk reopened this Mar 13, 2019
@kenta7777
Copy link
Contributor

Thanks!

Centril added a commit to Centril/rust that referenced this issue Mar 16, 2019
…=oli-obk

Reduce a Code Repetition Related to Bit Operation

This PR is related to [rust-lang#49937](rust-lang#49937).
Should I do more commits about [`FIXME(49937)`](https://github.com/rust-lang/rust/search?q=FIXME%2849937%29&unscoped_q=FIXME%2849937%29) in this PR?
kennytm added a commit to kennytm/rust that referenced this issue Mar 16, 2019
…=oli-obk

Reduce a Code Repetition Related to Bit Operation

This PR is related to [rust-lang#49937](rust-lang#49937).
Should I do more commits about [`FIXME(49937)`](https://github.com/rust-lang/rust/search?q=FIXME%2849937%29&unscoped_q=FIXME%2849937%29) in this PR?
@kenta7777
Copy link
Contributor

I think refactoring codes marked as FIXME(49937) was done.

@oli-obk
Copy link
Contributor Author

oli-obk commented Mar 17, 2019

Super! Thanks for all the work you put into cleaning up this issue!

@oli-obk oli-obk closed this as completed Mar 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: constant evaluation (mir interpretation) C-enhancement Category: An issue proposing an enhancement or a PR with one. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants