-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
Improve pretty-printing for ConstVal in MIR.
#30734
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Contributor
|
(rust_highfive has picked a reviewer for you, use r? to override) |
Contributor
|
@bors r+ |
Collaborator
|
📌 Commit b2903d8 has been approved by |
Collaborator
|
⌛ Testing commit b2903d8 with merge 8ab9c47... |
Collaborator
|
💔 Test failed - auto-linux-64-opt |
Contributor
|
@bors retry |
Collaborator
|
⌛ Testing commit b2903d8 with merge 03f4950... |
bors
added a commit
that referenced
this pull request
Jan 7, 2016
* Put `const` in front of every `ConstVal`.
* Pretty-print bytestrings as they appear in Rust source.
* Pretty-print `ConstVal::{Struct, Tuple, Array, Repeat}` by pretty-printing the `ast::NodeId`. This is a temporary measure, and probably not perfect, but I'm avoiding anything more complex since I hear the const evaluator might not be AST-based in the near future.
```rust
struct Point {
x: i32,
y: i32,
}
fn consts() {
let _float = 3.14159;
let _non_const_int = -42;
const INT: i32 = -42;
let _int = INT;
let _uint = 42u32;
let _str = "a string";
let _bytestr = b"a bytes\xFF\n\ttri\'\"\\ng";
let _bool = true;
const STRUCT: Point = Point { x: 42, y: 42 };
let _struct = STRUCT;
const EXTERNAL_STRUCT: std::sync::atomic::AtomicUsize = std::sync::atomic::ATOMIC_USIZE_INIT;
let _external_struct = EXTERNAL_STRUCT;
const TUPLE: (i32, &'static str, &'static [u8; 5]) = (1, "two", b"three");
let _tuple = TUPLE;
const FUNC: fn() = consts;
let _function = FUNC;
let _non_const_function = consts;
const ARRAY: [&'static str; 3] = ["a", "b", "c"];
let _array = ARRAY;
const REPEAT: [&'static [u8; 3]; 10] = [b"foo"; 10];
let _repeat = REPEAT;
}
```
```diff
--- consts-old.mir 2016-01-05 23:23:14.163807017 -0600
+++ consts-new.mir 2016-01-05 23:04:51.121386151 -0600
@@ -1,45 +1,45 @@
fn() -> () {
let var0: f64; // _float
let var1: i32; // _non_const_int
let var2: i32; // _int
let var3: u32; // _uint
let var4: &str; // _str
let var5: &[u8; 18]; // _bytestr
let var6: bool; // _bool
let var7: Point; // _struct
let var8: core::sync::atomic::AtomicUsize; // _external_struct
let var9: (i32, &str, &[u8; 5]); // _tuple
let var10: fn(); // _function
let var11: fn() {consts}; // _non_const_function
let var12: [&str; 3]; // _array
let var13: [&[u8; 3]; 10]; // _repeat
let mut tmp0: ();
bb0: {
- var0 = 3.14159;
- var1 = Neg(42);
- var2 = -42;
- var3 = 42;
- var4 = Str("a string");
- var5 = ByteStr[97, 32, 98, 121, 116, 101, 115, 255, 10, 9, 116, 114, 105, 39, 34, 92, 110, 103];
- var6 = true;
- var7 = Struct(51);
+ var0 = const 3.14159;
+ var1 = Neg(const 42);
+ var2 = const -42;
+ var3 = const 42;
+ var4 = const "a string";
+ var5 = const b"a bytes\xff\n\ttri\'\"\\ng";
+ var6 = const true;
+ var7 = const expr Point{x: 42, y: 42,};
var8 = consts::EXTERNAL_STRUCT;
- var9 = Tuple(78);
- var10 = Function(DefId { krate: 0, node: DefIndex(7) => consts });
+ var9 = const expr (1, "two", b"three");
+ var10 = const consts;
var11 = consts;
- var12 = Array(105, 3);
- var13 = Repeat(122, 10);
+ var12 = const expr ["a", "b", "c"];
+ var13 = const expr [b"foo"; 10];
drop var8;
drop var7;
goto -> bb1;
}
bb1: {
return;
}
bb2: {
diverge;
}
}
```
Collaborator
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
constin front of everyConstVal.ConstVal::{Struct, Tuple, Array, Repeat}by pretty-printing theast::NodeId. This is a temporary measure, and probably not perfect, but I'm avoiding anything more complex since I hear the const evaluator might not be AST-based in the near future.consts.rs
consts.mir diff