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

Add compiler flag to force color output #14040

Merged
merged 1 commit into from
May 15, 2014
Merged

Add compiler flag to force color output #14040

merged 1 commit into from
May 15, 2014

Conversation

hannobraun
Copy link

This pull request fixes #12881.

Two caveats:

  1. As explained in the commit message, this doesn't include a regression test. If this is unacceptable, please let me know, I'll see what I can do.
  2. I'm getting some test failures on make check, all from debuginfo. I suspect this is due to Not all debuginfo tests work on GDB 7.2 #13680 and not related to my changes (I have GDB 7.7). This is the list of failed tests:

[debuginfo-gdb] debuginfo/basic-types-globals.rs
[debuginfo-gdb] debuginfo/basic-types-mut-globals.rs
[debuginfo-gdb] debuginfo/basic-types.rs
[debuginfo-gdb] debuginfo/borrowed-basic.rs
[debuginfo-gdb] debuginfo/borrowed-managed-basic.rs
[debuginfo-gdb] debuginfo/borrowed-struct.rs
[debuginfo-gdb] debuginfo/borrowed-unique-basic.rs
[debuginfo-gdb] debuginfo/box.rs
[debuginfo-gdb] debuginfo/by-value-non-immediate-argument.rs
[debuginfo-gdb] debuginfo/by-value-self-argument-in-trait-impl.rs
[debuginfo-gdb] debuginfo/closure-in-generic-function.rs
[debuginfo-gdb] debuginfo/evec-in-struct.rs
[debuginfo-gdb] debuginfo/function-arg-initialization.rs
[debuginfo-gdb] debuginfo/function-prologue-stepping-no-split-stack.rs
[debuginfo-gdb] debuginfo/generic-function.rs
[debuginfo-gdb] debuginfo/generic-functions-nested.rs
[debuginfo-gdb] debuginfo/generic-method-on-generic-struct.rs
[debuginfo-gdb] debuginfo/generic-static-method-on-struct-and-enum.rs
[debuginfo-gdb] debuginfo/generic-struct.rs
[debuginfo-gdb] debuginfo/lexical-scope-in-stack-closure.rs
[debuginfo-gdb] debuginfo/lexical-scope-in-unique-closure.rs
[debuginfo-gdb] debuginfo/method-on-generic-struct.rs
[debuginfo-gdb] debuginfo/method-on-tuple-struct.rs
[debuginfo-gdb] debuginfo/name-shadowing-and-scope-nesting.rs
[debuginfo-gdb] debuginfo/recursive-struct.rs
[debuginfo-gdb] debuginfo/self-in-generic-default-method.rs
[debuginfo-gdb] debuginfo/shadowed-argument.rs
[debuginfo-gdb] debuginfo/shadowed-variable.rs
[debuginfo-gdb] debuginfo/simd.rs
[debuginfo-gdb] debuginfo/simple-lexical-scope.rs
[debuginfo-gdb] debuginfo/simple-struct.rs
[debuginfo-gdb] debuginfo/simple-tuple.rs
[debuginfo-gdb] debuginfo/static-method-on-struct-and-enum.rs
[debuginfo-gdb] debuginfo/tuple-struct.rs
[debuginfo-gdb] debuginfo/var-captured-in-nested-closure.rs
[debuginfo-gdb] debuginfo/var-captured-in-sendable-closure.rs
[debuginfo-gdb] debuginfo/var-captured-in-stack-closure.rs

I can provide the full output on request.

@alexcrichton
Copy link
Member

When I've seen a flag like this previously, it's normally --color or --color=never or something like that. Perhaps the flag could be --color and turning it off could be --no-color? We don't currently handle --color[=foo] well right now because if you do something like rustc --color foo.rs it'll end up interpreting "foo.rs" as the argument to color.

@hannobraun
Copy link
Author

Sounds good to me. If I understand you correctly, you want the default behaviour to stay the same? That is, if none of the flags are there, the code should check if stderr is a tty?

@alexcrichton
Copy link
Member

That sounds good to me!

@sfackler
Copy link
Member

sfackler commented May 8, 2014

As one example, ag uses --color to force coloring, --nocolor to force no coloring and the default is to color if stdout is a tty.

@hannobraun
Copy link
Author

Great! I've renamed the argument to --color and will push that later today (I need to get going now and make will take a while on my machine).

Do you want me to send a separate PR for --no-color or should I update this one? Either way is fine with me, but it might take a week or two until I can find the time to work on this again.

@alexcrichton
Copy link
Member

Feel free to add it to this PR, it's a small enough change.

@hannobraun
Copy link
Author

Okay, will do.

@hannobraun
Copy link
Author

I've changed the argument from --force-color-output to --color. I'll implement --no-color as soon as I find some time.

@huonw
Copy link
Member

huonw commented May 8, 2014

Another option is --color=always ...=auto and ...=never.

@alexcrichton
Copy link
Member

Hm, I think I like @huonw's suggestion because it only adds one flag, and --color=always probably won't be too, too common.

@hannobraun
Copy link
Author

Yes, that sounds even better.

hannobraun added a commit to hannobraun/vndf-2016 that referenced this pull request May 9, 2014
Upgrade to latest Rust. This includes a local change for Zwobot:
rust-lang/rust#14040
hannobraun added a commit to hannobraun/vndf-2016 that referenced this pull request May 9, 2014
Please note that this includes two pending pull requests in Rust and
glfw-rs:
- rust-lang/rust#14040
- PistonDevelopers/glfw-rs#151
This adds the flag --color, which allows the user to force coloring or
turn it off. The default behavior stays the same as before (colorize, if
output goes to tty).
Why this is beneficial is explained in issue #12881.

Please note that this commit doesn't include any regression tests. I
thought about how I'd write a test for this and it doesn't seem to be
worth the effort to me for a UI change like this.

Fixes #12881.
@hannobraun
Copy link
Author

I've implemented --color=auto|always|never as per @huonw's suggestion. Please let me know, if there any further objections against merging this.

bors added a commit that referenced this pull request May 15, 2014
…hton

This pull request fixes #12881.

Two caveats:

1. As explained in the commit message, this doesn't include a regression test. If this is unacceptable, please let me know, I'll see what I can do.
1. I'm getting some test failures on make check, all from debuginfo. I suspect this is due to #13680 and  not related to my changes (I have GDB 7.7). This is the list of failed tests:

> [debuginfo-gdb] debuginfo/basic-types-globals.rs
> [debuginfo-gdb] debuginfo/basic-types-mut-globals.rs
> [debuginfo-gdb] debuginfo/basic-types.rs
> [debuginfo-gdb] debuginfo/borrowed-basic.rs
> [debuginfo-gdb] debuginfo/borrowed-managed-basic.rs
> [debuginfo-gdb] debuginfo/borrowed-struct.rs
> [debuginfo-gdb] debuginfo/borrowed-unique-basic.rs
> [debuginfo-gdb] debuginfo/box.rs
> [debuginfo-gdb] debuginfo/by-value-non-immediate-argument.rs
> [debuginfo-gdb] debuginfo/by-value-self-argument-in-trait-impl.rs
> [debuginfo-gdb] debuginfo/closure-in-generic-function.rs
> [debuginfo-gdb] debuginfo/evec-in-struct.rs
> [debuginfo-gdb] debuginfo/function-arg-initialization.rs
> [debuginfo-gdb] debuginfo/function-prologue-stepping-no-split-stack.rs
> [debuginfo-gdb] debuginfo/generic-function.rs
> [debuginfo-gdb] debuginfo/generic-functions-nested.rs
> [debuginfo-gdb] debuginfo/generic-method-on-generic-struct.rs
> [debuginfo-gdb] debuginfo/generic-static-method-on-struct-and-enum.rs
> [debuginfo-gdb] debuginfo/generic-struct.rs
> [debuginfo-gdb] debuginfo/lexical-scope-in-stack-closure.rs
> [debuginfo-gdb] debuginfo/lexical-scope-in-unique-closure.rs
> [debuginfo-gdb] debuginfo/method-on-generic-struct.rs
> [debuginfo-gdb] debuginfo/method-on-tuple-struct.rs
> [debuginfo-gdb] debuginfo/name-shadowing-and-scope-nesting.rs
> [debuginfo-gdb] debuginfo/recursive-struct.rs
> [debuginfo-gdb] debuginfo/self-in-generic-default-method.rs
> [debuginfo-gdb] debuginfo/shadowed-argument.rs
> [debuginfo-gdb] debuginfo/shadowed-variable.rs
> [debuginfo-gdb] debuginfo/simd.rs
> [debuginfo-gdb] debuginfo/simple-lexical-scope.rs
> [debuginfo-gdb] debuginfo/simple-struct.rs
> [debuginfo-gdb] debuginfo/simple-tuple.rs
> [debuginfo-gdb] debuginfo/static-method-on-struct-and-enum.rs
> [debuginfo-gdb] debuginfo/tuple-struct.rs
> [debuginfo-gdb] debuginfo/var-captured-in-nested-closure.rs
> [debuginfo-gdb] debuginfo/var-captured-in-sendable-closure.rs
> [debuginfo-gdb] debuginfo/var-captured-in-stack-closure.rs

I can provide the full output on request.
@bors bors closed this May 15, 2014
@bors bors merged commit b7676f2 into rust-lang:master May 15, 2014
@hannobraun hannobraun deleted the force-color-output branch May 16, 2014 07:49
lnicola pushed a commit to lnicola/rust that referenced this pull request Mar 13, 2023
Beginning of MIR

This pull request introduces the initial implementation of MIR lowering and interpreting in Rust Analyzer.

The implementation of MIR has potential to bring several benefits:
- Executing a unit test without compiling it: This is my main goal. It can be useful for quickly testing code changes and print-debugging unit tests without the need for a full compilation (ideally in almost zero time, similar to languages like python and js). There is a probability that it goes nowhere, it might become slower than rustc, or it might need some unreasonable amount of memory, or we may fail to support a common pattern/function that make it unusable for most of the codes.
- Constant evaluation: MIR allows for easier and more correct constant evaluation, on par with rustc. If r-a wants to fully support the type system, it needs full const eval, which means arbitrary code execution, which needs MIR or something similar.
- Supporting more diagnostics: MIR can be used to detect errors, most famously borrow checker and lifetime errors,  but also mutability errors and uninitialized variables, which can be difficult/impossible to detect in HIR.
- Lowering closures: With MIR we can find out closure capture modes, which is useful in detecting if a closure implements the `FnMut` or `Fn` traits, and calculating its size and data layout.

But the current PR implements no diagnostics and doesn't support closures. About const eval, I removed the old const eval code and it now uses the mir interpreter. Everything that is supported in stable rustc is either implemented or is super easy to implement. About interpreting unit tests, I added an experimental config, disabled by default, that shows a `pass` or `fail` on hover of unit tests (ideally it should be a button similar to `Run test` button, but I didn't figured out how to add them). Currently, no real world test works, due to missing features including closures, heap allocation, `dyn Trait` and ... so at this point it is only useful for me selecting what to implement next.

The implementation of MIR is based on the design of rustc, the data structures are almost copy paste (so it should be easy to migrate it to a possible future stable-mir), but the lowering and interpreting code is from me.
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.

Provide force coloring option for rustc
5 participants