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

tighten sanity checks around Scalar and ScalarPair #96220

Merged
merged 6 commits into from
May 11, 2022

Conversation

RalfJung
Copy link
Member

@RalfJung RalfJung commented Apr 19, 2022

While investigating #96185 I noticed codegen has tighter sanity checks here than Miri does, so I added some more assertions. Strangely, some of them fail, so I also needed to add a HACK... that is probably worth looking into.

This does not fix that issue, but it changes the ICE messages, making it quite clear that we have a scalar whose size is not the same as that of the surrounding layout.

r? @oli-obk

@rust-highfive
Copy link
Collaborator

Some changes occured to the CTFE / Miri engine

cc @rust-lang/miri

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 19, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 19, 2022
// FIXME: Can we check anything here?
}
}
}
Copy link
Member Author

Choose a reason for hiding this comment

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

I removed all this since I think it is redundant with the scalar size check in to_bits that alloc.write_scalar does.

@rust-log-analyzer

This comment has been minimized.

// HACK to support buggy enums whose variants have Aggregate ABI
// (see https://github.com/rust-lang/rust/issues/96185).
// codegen doesn't do this, not sure why.
(Immediate::ScalarPair(a_val, b_val), Abi::Aggregate { .. }) => {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the odd one -- a ScalarPair at Aggregate ABI just doesn't seem right.

I added sanity checking in operand_downcast, and my theory was confirmed: when downcasting std::option::Option<*mut std::ffi::c_void> to variant 1, the ABI changes from ScalarPair to Aggegreate.

downcast to 1 turned ScalarPair layout into non-scalar layout: TyAndLayout {
    ty: std::option::Option<*mut std::ffi::c_void>,
    layout: Layout {
        fields: Arbitrary {
            offsets: [
                Size {
                    raw: 0,
                },
            ],
            memory_index: [
                0,
            ],
        },
        variants: Multiple {
            tag: Initialized {
                value: Int(
                    I64,
                    false,
                ),
                valid_range: 0..=1,
            },
            tag_encoding: Direct,
            tag_field: 0,
            variants: [
                Layout {
                    fields: Arbitrary {
                        offsets: [],
                        memory_index: [],
                    },
                    variants: Single {
                        index: 0,
                    },
                    abi: Aggregate {
                        sized: true,
                    },
                    largest_niche: None,
                    align: AbiAndPrefAlign {
                        abi: Align {
                            pow2: 0,
                        },
                        pref: Align {
                            pow2: 3,
                        },
                    },
                    size: Size {
                        raw: 8,
                    },
                },
                Layout {
                    fields: Arbitrary {
                        offsets: [
                            Size {
                                raw: 8,
                            },
                        ],
                        memory_index: [
                            0,
                        ],
                    },
                    variants: Single {
                        index: 1,
                    },
                    abi: Aggregate {
                        sized: true,
                    },
                    largest_niche: None,
                    align: AbiAndPrefAlign {
                        abi: Align {
                            pow2: 3,
                        },
                        pref: Align {
                            pow2: 3,
                        },
                    },
                    size: Size {
                        raw: 16,
                    },
                },
            ],
        },
        abi: ScalarPair(
            Initialized {
                value: Int(
                    I64,
                    false,
                ),
                valid_range: 0..=1,
            },
            Initialized {
                value: Pointer,
                valid_range: 0..=18446744073709551615,
            },
        ),
        largest_niche: Some(
            Niche {
                offset: Size {
                    raw: 0,
                },
                value: Int(
                    I64,
                    false,
                ),
                valid_range: 0..=1,
            },
        ),
        align: AbiAndPrefAlign {
            abi: Align {
                pow2: 3,
            },
            pref: Align {
                pow2: 3,
            },
        },
        size: Size {
            raw: 16,
        },
    },
} to TyAndLayout {
    ty: std::option::Option<*mut std::ffi::c_void>,
    layout: Layout {
        fields: Arbitrary {
            offsets: [
                Size {
                    raw: 8,
                },
            ],
            memory_index: [
                0,
            ],
        },
        variants: Single {
            index: 1,
        },
        abi: Aggregate {
            sized: true,
        },
        largest_niche: None,
        align: AbiAndPrefAlign {
            abi: Align {
                pow2: 3,
            },
            pref: Align {
                pow2: 3,
            },
        },
        size: Size {
            raw: 16,
        },
    },
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Reported as #96221.

@rust-log-analyzer

This comment has been minimized.

@RalfJung
Copy link
Member Author

Ah, I guess this is enough to anger const-eval on the runtime version of this example.^^

I guess this is blocked on fixing that enum layout then.

@rust-log-analyzer

This comment has been minimized.

@oli-obk oli-obk added the S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. label Apr 20, 2022
@oli-obk
Copy link
Contributor

oli-obk commented Apr 20, 2022

Const prop strikes again 🙈

@RalfJung
Copy link
Member Author

The curious part is that const prop managed to dodge the assertions we had in place before. I guess that goes to show some extra assertions are really needed. ;)

@bors
Copy link
Contributor

bors commented May 5, 2022

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

@rust-log-analyzer

This comment has been minimized.

@RalfJung
Copy link
Member Author

I rebased and commented out the things that are broken by #96185. @oli-obk I think this is ready for review.

Also let's ensure this does not cost too much perf.
@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 May 10, 2022
@bors
Copy link
Contributor

bors commented May 10, 2022

⌛ Trying commit aef8a93 with merge e20aa27db438b844d57419af48c40860d88dbcda...

@RalfJung RalfJung removed the S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. label May 10, 2022
@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 May 11, 2022
@bors
Copy link
Contributor

bors commented May 11, 2022

⌛ Trying commit 14f6daf with merge bae4e5b81419bd94533a9428d118973194da792b...

@bors
Copy link
Contributor

bors commented May 11, 2022

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

@rust-timer
Copy link
Collaborator

Queued bae4e5b81419bd94533a9428d118973194da792b with parent f296b9a, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (bae4e5b81419bd94533a9428d118973194da792b): comparison url.

Summary:

  • Primary benchmarks: no relevant changes found
  • Secondary benchmarks: 😿 relevant regressions found
Regressions 😿
(primary)
Regressions 😿
(secondary)
Improvements 🎉
(primary)
Improvements 🎉
(secondary)
All 😿 🎉
(primary)
count1 0 3 0 0 0
mean2 N/A 1.4% N/A N/A N/A
max N/A 1.5% N/A N/A N/A

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

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

Footnotes

  1. number of relevant changes

  2. the arithmetic mean of the percent change

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label May 11, 2022
@RalfJung
Copy link
Member Author

Hm, well, that did not help...

Maybe the match on a pair (*base, base.layout.abi) compiles less nicely than the previous code?
All but one arm of this match is _, so I could probably rewrite it in different style. Not sure if that's worth it though, LLVM will probably realize that this is what the control flow boils down to.

@oli-obk
Copy link
Contributor

oli-obk commented May 11, 2022

mir interpret is always hitting LLVM inlining thresholds, I don't think it's worth looking into further in this PR

@bors r+

@bors
Copy link
Contributor

bors commented May 11, 2022

📌 Commit 14f6daf has been approved by oli-obk

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 11, 2022
@bors
Copy link
Contributor

bors commented May 11, 2022

⌛ Testing commit 14f6daf with merge 3e2c8514996fffe0081afd8cd6dcf2fcf362d4ff...

@rust-log-analyzer
Copy link
Collaborator

A job failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

@bors
Copy link
Contributor

bors commented May 11, 2022

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 11, 2022
@oli-obk
Copy link
Contributor

oli-obk commented May 11, 2022

@bors retry timeout, logs empty/stuck

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 11, 2022
@bors
Copy link
Contributor

bors commented May 11, 2022

⌛ Testing commit 14f6daf with merge 6dd6840...

@bors
Copy link
Contributor

bors commented May 11, 2022

☀️ Test successful - checks-actions
Approved by: oli-obk
Pushing 6dd6840 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 11, 2022
@bors bors merged commit 6dd6840 into rust-lang:master May 11, 2022
@rustbot rustbot added this to the 1.62.0 milestone May 11, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (6dd6840): comparison url.

Summary:

  • Primary benchmarks: no relevant changes found
  • Secondary benchmarks: 😿 relevant regressions found
Regressions 😿
(primary)
Regressions 😿
(secondary)
Improvements 🎉
(primary)
Improvements 🎉
(secondary)
All 😿 🎉
(primary)
count1 0 4 0 0 0
mean2 N/A 1.1% N/A N/A N/A
max N/A 1.5% N/A N/A N/A

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

@rustbot label: -perf-regression

Footnotes

  1. number of relevant changes

  2. the arithmetic mean of the percent change

@RalfJung RalfJung deleted the scalar-no-padding branch May 12, 2022 07:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants