Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upRemove redundant integer suffixes. #22501
Comments
eddyb
added
E-easy
C-cleanup
E-mentor
labels
Feb 18, 2015
This comment has been minimized.
This comment has been minimized.
|
I'd like to look into this one, though I'm not sure how to modify the compiler in the way that you mention. Any suggestions on where to start? |
This comment has been minimized.
This comment has been minimized.
|
The entry-point into the pretty printer seems to be this call in let src_name = source_name(input);
let src = sess.codemap().get_filemap(&src_name)
.src.as_bytes().to_vec();
// For this you'd have to make TypedAnnotation's analysis field public.
let annotation = TypedAnnotation { analysis: analysis };
pprust::print_crate(sess.codemap(),
sess.diagnostic(),
ast_map.krate(),
src_name.to_string(),
&mut MemReader::new(src),
box old_io::File::create(&pp_out).unwrap(),
&annotation
true).unwrap();
let analysis = annotation.analysis;which can be inserted at this point in compile_input.
let pp_out = outputs.with_extension("rs");
let pp_out_file = pp_out.as_str().expect("non-utf8 pp output file").replace("/", "--");
// If this doesn't work, hardcode an absolute path here.
let pp_out_path = Path::new(concat!(env!(CFG_BUILD_DIR), "int-suffix-pp")).join(pp_out_file);Aside from that, you would also need to hack the pretty-printer so it doesn't output integer suffixes - should be easy to treat them just like the unsuffixed cases. |
This comment has been minimized.
This comment has been minimized.
|
Since I didn't hear back from @gchp, I implemented what I mentioned in a branch of mine - I intend to open a PR soon. rm -rf test-pretty-dump; mkdir test-pretty-dump
# compile stage1 rustc first, with no flags, to avoid errors as stage0 doesn't have them
make x86_64-unknown-linux-gnu/stage1/bin/rustc
make check-stage1 RUSTFLAGS="-Z unstable-options -Z pretty-keep-going -Z pretty-dump-dir=test-pretty-dump --xpretty=typed,unsuffixed_literals"This gives me a bunch of files (I didn't run this build for long - an almost full one with tests had over 2600):
An example from libcollections: // source
static TAG_CONT_U8: u8 = 128u8;
// pretty-printed
static TAG_CONT_U8: u8 = (128: u8);The flag-based approach has two big problems, though: it messes up My invocation would thus become: # no bootstrapping issues!
make check-stage1 RUSTC_PRETTY_DUMP="typed,unsuffixed_literals:test-pretty-dump" |
This comment has been minimized.
This comment has been minimized.
|
I've rebased my branch and added the env var functionality - oh and I think I have an almost-perfect way to remove integer literal suffixes everywhere: sed -i -r -e 's/\b(0x[0-9a-fA-F_]*[0-9a-fA-F]|0o[0-7_]*[0-7]|0b[01_]*[01]|[0-9]([0-9_]*[0-9])?)_*([ui](8|16|32|64|s(ize)?)?|uint|int)/\1/g' **.rs |
eddyb
removed
the
E-mentor
label
Mar 1, 2015
This comment has been minimized.
This comment has been minimized.
|
This is working out! I have some stats (cc @huonw @aturon @alexcrichton):
How I did the diffs: # make a fresh git working dir
cd ..; mkdir rust-unsuffix-data; cd rust-unsuffix-data; git init
# add a commit for the "before" dataset (sed removes comments which are only diff noise)
cp ../rust/before-int-suffix-removal/* .; sed -i -e 's|//.*$||' *.rs; git add *; git commit -m 'before'
# add a commit for the "after" dataset, on top of "before" (same sed to remove comments)
git rm *; cp ../rust/after-int-suffix-removal/* .; sed -i -e 's|//.*$||' *.rs; git add *; git commit -m 'after' |
This comment has been minimized.
This comment has been minimized.
|
@eddyb Just want to say, this is awesome |
This was referenced Mar 3, 2015
bors
added a commit
that referenced
this issue
Mar 4, 2015
Manishearth
added a commit
to Manishearth/rust
that referenced
this issue
Mar 4, 2015
Manishearth
added a commit
to Manishearth/rust
that referenced
this issue
Mar 4, 2015
Manishearth
added a commit
to Manishearth/rust
that referenced
this issue
Mar 4, 2015
Manishearth
added a commit
to Manishearth/rust
that referenced
this issue
Mar 5, 2015
Manishearth
added a commit
to Manishearth/rust
that referenced
this issue
Mar 5, 2015
bors
added a commit
that referenced
this issue
Mar 5, 2015
Manishearth
added a commit
to Manishearth/rust
that referenced
this issue
Mar 5, 2015
This comment has been minimized.
This comment has been minimized.
|
closed by #22994 yeah? |
This comment has been minimized.
This comment has been minimized.
|
I would think. Could someone with authority close this? |
This comment has been minimized.
This comment has been minimized.
|
Thanks! |
huonw
closed this
Apr 12, 2015
This comment has been minimized.
This comment has been minimized.
|
Somehow I forgot to comment that this was never finished, #22994 contained merely the easy cases. |
eddyb
reopened this
Apr 16, 2015
This comment has been minimized.
This comment has been minimized.
|
So, what are the hard cases? Is this bug still E-Easy? |
This comment has been minimized.
This comment has been minimized.
|
@eddyb Just found this-- what's the current status? Still easy? |
This comment has been minimized.
This comment has been minimized.
|
@cramertj Well, I gave up on trying to remove integer suffixes from the language, before 1.0 I was convinced we could replace them with type ascription. One can still clean up existing code by hand, of course. |
brson
removed
the
E-easy
label
Jun 27, 2016
This comment has been minimized.
This comment has been minimized.
|
Making any more progress on this will requiring hacking up new tools in the compiler to detect them. It would be a nice generally to be able to detect unused suffixes (maybe clippy could do it cc @llogiq @Manishearth). |
brson
added
the
P-low
label
Jun 27, 2016
This comment has been minimized.
This comment has been minimized.
|
Works for me in clippy. @eddyb, could you file an issue there with heuristics on how to detect an unnecessary suffix? |
This comment has been minimized.
This comment has been minimized.
|
@brson It doesn't really work out within a lint. Although it could be possible to take out each suffix and pass the function through typeck to see how it infers, but that seems slow and painful. |
This comment has been minimized.
This comment has been minimized.
|
I see two options:
|
This comment has been minimized.
This comment has been minimized.
|
@llogiq That information is not there during error reporting. Obligations are put in a graph of sorts so you can tell what caused an obligation to be in the graph, but sources of type inference information are lost, as the set of inference variables is directly updated. |
This comment has been minimized.
This comment has been minimized.
This is what I was imagining. Doesn't matter if it's slow if it's the only way to get that useful info! |
This comment has been minimized.
This comment has been minimized.
|
@eddyb: Then it's probably heuristics to speed up easy cases and type inference for harder ones. |
This comment has been minimized.
This comment has been minimized.
|
Triage: it seems this issue has mutated since the original issue, is it still relevant? I know that the idea, long ago, was that type ascription could replace suffixes in general, but that never came to fruition. |
This comment has been minimized.
This comment has been minimized.
|
Since it seems this issue has migrated to a feature request for a lint that warns on integer suffixes that aren't used in code, I'm going to close it as we want those to go through RFCs and it also seems like without that lint there's not going to be traction within the compiler codebase either. |
eddyb commentedFeb 18, 2015
As #21511 has shown, there are lots of cases in which integer suffixes aren't needed at all.
Usually audits are needed to make sure the intended type is inferred, and disabling the fallback to
i32wouldn't really work for tests and whatnot.It should be easy to modify the compiler to dump the equivalent of
--pretty=typed(with pretty-printing showing no suffixes on expressions) into some temporary directory, then compare the results from twomake checkruns, one with all the suffixes removed.