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

Use ValTree in all type level constants #83234

Closed
wants to merge 6 commits into from

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Mar 17, 2021

based on #83207

r? @lcnr

best reviewed commit by commit, as some of the refactoring commits are noisy but don't change anything significant.

cc @rust-lang/wg-const-eval

Type level constants are now fully backed by value trees, so it is impossible for two constants to have the same value but a different representation.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 17, 2021
Comment on lines 526 to 516
(ty::ConstKind::Value(a_val), ty::ConstKind::Value(b_val)) => {
check_const_value_eq(relation, a_val, b_val, a, b)?
}
(ty::ConstKind::Value(a_val), ty::ConstKind::Value(b_val)) => a_val == b_val,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the essence of this PR. There is no more special logic for relating constants, we can just compare them with the derived PartialEq impl.

Comment on lines 25 to 28
// + val: Value(Slice { data: Allocation { bytes: [101, 120, 112, 108, 105, 99, 105, 116, 32, 112, 97, 110, 105, 99], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [16383], len: Size { raw: 14 } }, size: Size { raw: 14 }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 14 })
// + val: Value(Branch([Leaf(0x65), Leaf(0x78), Leaf(0x70), Leaf(0x6c), Leaf(0x69), Leaf(0x63), Leaf(0x69), Leaf(0x74), Leaf(0x20), Leaf(0x70), Leaf(0x61), Leaf(0x6e), Leaf(0x69), Leaf(0x63)]))
// mir::Constant
// + span: $SRC_DIR/std/src/panic.rs:LL:COL
// + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [101, 120, 112, 108, 105, 99, 105, 116, 32, 112, 97, 110, 105, 99], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [16383], len: Size { raw: 14 } }, size: Size { raw: 14 }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 14 }) }
// + literal: Const { ty: &str, val: Value(Branch([Leaf(0x65), Leaf(0x78), Leaf(0x70), Leaf(0x6c), Leaf(0x69), Leaf(0x63), Leaf(0x69), Leaf(0x74), Leaf(0x20), Leaf(0x70), Leaf(0x61), Leaf(0x6e), Leaf(0x69), Leaf(0x63)])) }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we should probably stop printing string constants in mir dumps.. their stringly printed representation is sufficient

Copy link
Member

Choose a reason for hiding this comment

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

Can we tie this to -Zverbose or so?

Comment on lines 21 to 23
- _2 = Eq(move _3, const 17_i8); // scope 0 at $DIR/if-condition-int.rs:44:13: 44:20
- StorageDead(_3); // scope 0 at $DIR/if-condition-int.rs:44:19: 44:20
- switchInt(_2) -> [false: bb2, otherwise: bb1]; // scope 1 at $DIR/if-condition-int.rs:46:9: 46:14
+ _2 = Eq(_3, const 17_i8); // scope 0 at $DIR/if-condition-int.rs:44:13: 44:20
+ nop; // scope 0 at $DIR/if-condition-int.rs:44:19: 44:20
+ switchInt(move _3) -> [17_i8: bb1, otherwise: bb2]; // scope 1 at $DIR/if-condition-int.rs:46:9: 46:14
_2 = Eq(move _3, const 17_i8); // scope 0 at $DIR/if-condition-int.rs:44:13: 44:20
StorageDead(_3); // scope 0 at $DIR/if-condition-int.rs:44:19: 44:20
switchInt(_2) -> [false: bb2, otherwise: bb1]; // scope 1 at $DIR/if-condition-int.rs:46:9: 46:14
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one is interesting... this change by itself enabled an optimization to trigger more often

@@ -1,6 +1,6 @@
fn main() {
let A = 3;
//~^ ERROR refutable pattern in local binding: `i32::MIN..=1_i32` and
//~^ ERROR refutable pattern in local binding: `i32::MIN..=1` and
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change is because we're now using ConstInt instead of ty::Const printing for these errors

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Mar 17, 2021

☔ The latest upstream changes (presumably #82122) made this pull request unmergeable. Please resolve the merge conflicts.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@oli-obk
Copy link
Contributor Author

oli-obk commented Mar 19, 2021

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 19, 2021
@bors
Copy link
Contributor

bors commented Mar 19, 2021

⌛ Trying commit 5cf5addca286bfde62041568f38117ceafc84e4c with merge 437ebfc4e9d5c202057e1c2509e25c70d2fc67eb...

@bors
Copy link
Contributor

bors commented Mar 19, 2021

☀️ Try build successful - checks-actions
Build commit: 437ebfc4e9d5c202057e1c2509e25c70d2fc67eb (437ebfc4e9d5c202057e1c2509e25c70d2fc67eb)

@rust-timer
Copy link
Collaborator

Queued 437ebfc4e9d5c202057e1c2509e25c70d2fc67eb with parent b97fd3e, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (437ebfc4e9d5c202057e1c2509e25c70d2fc67eb): comparison url.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying rollup- to bors.

Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 19, 2021
@oli-obk
Copy link
Contributor Author

oli-obk commented Mar 20, 2021

oof. that's some results... Some good, some very bad results (stress tests). I gotta analyze the stress tests to see which part is problematic. It may be string related, as strings are now encoded as valtree branches (so one valtree leaf per byte in the string), making them rather expensive to be converted back into allocations. Since one of the tests does this a lot, that may just be the root of the regression. Not sure how to address this though. Ideally we would just have a Str(Symbol) variant. This works just fine for str, as there is not equivalent valtree representation that could conflict. But we can't do the same for byte strings, as they really are just arrays of bytes, which already have a defined representation in valtrees (namely a branch full of single-char leafs).

I'll experiment with just fixing strings for now and we'll see whether we can at least not regress our benchmarks, even if we'll still have a regression for byte strings (but no benchmark for them).

@lcnr
Copy link
Contributor

lcnr commented May 24, 2021

I am not able to review any PRs in the near future.

We need both impl work (as @oli-obk is also on a break) and review for this PR, so it probably doesn't make much sense to reassign, but

r? @varkor

@rust-highfive rust-highfive assigned varkor and unassigned lcnr May 24, 2021
@crlf0710 crlf0710 added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 11, 2021
@JohnCSimon JohnCSimon added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 27, 2021
@JohnCSimon JohnCSimon added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 12, 2021
@JohnCSimon JohnCSimon added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 15, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 26, 2021
…woerister,oli-obk

rustc_symbol_mangling: support structural constants and &str in v0.

This PR should unblock rust-lang#85530 (except for float `const` generics, which AFAIK should've never worked).
(cc `@tmiasko` could the rust-lang#85530 (comment) failures be retried with a quick crater "subset" run of this PR + changing the default to `v0`? Just to make sure I didn't miss anything other than the floats)

The encoding is the one suggested before in e.g. rust-lang#61486 (comment), tho this PR won't by itself finish rust-lang#61486, before closing that we'd likely want to move to `@oli-obk's` "valtrees" (i.e. rust-lang#83234 and other associated work).

<hr>

**EDITs**:
1. switched unit/tuple/braced-with-named-fields `<const-fields>` prefixes from `"u"`/`"T"`/`""` to `"U"`/`"T"`/`"S"` to avoid the ambiguity reported by `@tmiasko` in rust-lang#87194 (comment).

2. `rustc-demangle` PR: rust-lang/rustc-demangle#55

3. RFC amendment PR: rust-lang/rfcs#3161
    * also removed the grammar changes included in that PR, from this description

4. added tests (temporarily using my fork of `rustc-demangle`)

<hr>

r? `@michaelwoerister`
@lcnr lcnr self-assigned this Aug 27, 2021
@JohnCSimon
Copy link
Member

triage: merge conflicts

@JohnCSimon JohnCSimon added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 3, 2021
@oli-obk
Copy link
Contributor Author

oli-obk commented Oct 5, 2021

I'm going to close this for now. I'm going to need another few months before I get to this, so we don't need to keep it open

@oli-obk oli-obk closed this Oct 5, 2021
@tshepang
Copy link
Member

see #96591

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.