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

Factoring bigint, rational, and complex out of libextra into libnum. #12154

Conversation

pnkfelix
Copy link
Member

Removed use of globs present in earlier versions of modules.

Fix tutorial.md to reflect extra::rational ==> num::rational.

@pnkfelix
Copy link
Member Author

This is the revised version of PR #12141 ; note that there was some discussion on that PR regarding the motivation for this change. (The big one being enabling faster iteration on bigint improvements such as pnkfelix/rust@d669822 )

In particular, I continue to assert that the decision of whether to change the defaults so that bigint is based on GMP is orthogonal to the changes proposed here.

The question of whether to remove bigint entirely is a separate question, but I'm going to leave it aside for now. (I think removing bigint entirely will be a more reasonable option once we have deployed a replacement for rustpkg, but until then I think we should keep a bigint implementation here for now.)


pub mod bigint;
pub mod rational;
pub mod complex;
Copy link
Member

Choose a reason for hiding this comment

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

We've been moving towards private inner modules and reexports of their contents, so perhaps these could be mod foo; with pub use bigint::{BigInt, BigUint}; etc at the top?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm. When importing via globs, it is nicer I think to have these things actually collected together like this.

But I can see that this does lead to the stuttering problem.

Is it reasonable to re-export the contents from the num crate, but to have the inner modules be public, to allow such usage? Or is that just asking for trouble?

Copy link
Member

Choose a reason for hiding this comment

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

That's a good point, I suppose globs really do want to import num::bigint::*, not num::*. Then again, globs are feature-gated...

One part about pub mod foo; is that the reexport doesn't have its documentation inlined at the reexport site, but rather it's a redirect. That's not necessarily a downside, but it is something to consider.

Let's go with this for now, and see how it turns out.

@alexcrichton
Copy link
Member

r=me with a squash

Removed use of globs present in earlier versions of modules.

Fix tutorial.md to reflect `extra::rational` ==> `num::rational`.
bors added a commit that referenced this pull request Feb 11, 2014
…-libextra, r=alexcrichton

Removed use of globs present in earlier versions of modules.

Fix tutorial.md to reflect `extra::rational` ==> `num::rational`.
@bors bors closed this Feb 11, 2014
@pnkfelix
Copy link
Member Author

Odd, I was able to compile pidigits after applying my original version of this PR (#12141), but now that this has landed in master, my direct invocations of rustc on src/test/bench/shootout-pidigits.rs are having trouble resolving the extern mod num reference.

And worse, explicitly trying to help rustc by providing a -L <dir> option to the invocation causes this:

% rustc -Lx86_64-apple-darwin/stage2/lib/rustlib/x86_64-apple-darwin/lib ../src/test/bench/shootout-pidigits.rs -o pidigits
error: internal compiler error: unexpected failure
This message reflects a bug in the Rust compiler. 
We would appreciate a bug report: http://static.rust-lang.org/doc/master/complement-bugreport.html
note: the compiler hit an unexpected failure path. this is a bug
Ok(task 'rustc' failed at 'assertion failed: lib.rlib.is_none()', /Users/pnkfelix/Dev/Mozilla/rust.git/src/librustc/metadata/loader.rs:192
)

(edit: Ah: I was trying to run rustc directly out of the build tree, but I guess one needs to do make install before using rustc when referencing external libraries? Really? There should be a way to support running rustc in general from the build tree without installing it though, maybe I just need to find the right invocation command line.)

(edit^2: wait, that command line above isn't running rustc out of the build tree anyway, its grabbing it from my path. ugh, wake up felix...)

@alexcrichton
Copy link
Member

That should be fixed by #12164 (the assertion error)

flip1995 pushed a commit to flip1995/rust that referenced this pull request Feb 8, 2024
[`unconditional_recursion`]: compare by `Ty`s instead of `DefId`s

Fixes rust-lang#12154
Fixes rust-lang#12181 (this was later edited in, so the rest of the description refers to the first linked issue)

Before this change, the lint would work with `DefId`s and use those to compare types. This PR changes it to compare types directly. It fixes the linked issue, but also other false positives I found in a lintcheck run. For example, one of the issues is that some types don't have `DefId`s (primitives, references, etc., leading to possible FNs), and the helper function used to extract a `DefId` didn't handle type parameters.

Another issue was that the lint would use `.peel_refs()` in a few places where that could lead to false positives (one such FP was in the `http` crate). See the doc comment on one of the added functions and also the test case for what I mean.

The code in the linked issue was linted because the receiver type is `T` (a `ty::Param`), which was not handled in `get_ty_def_id` and returned `None`, so this wouldn't actually *get* to comparing `self_arg != ty_id` here, and skip the early-return:
https://github.com/rust-lang/rust-clippy/blob/70573af31eb9b8431c2e7923325c82ba0304cbb2/clippy_lints/src/unconditional_recursion.rs#L171-L178

This alone could be fixed by doing something like `&& get_ty_def_id(ty).map_or(true, |ty_id)| self_arg != ty_id)`, but we don't really need to work with `DefId`s in the first place, I don't think.

changelog: [`unconditional_recursion`]: avoid linting when the other comparison type is a type parameter
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.

None yet

3 participants