Skip to content

Check signature WF when lowering MIR body #137298

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 3 commits into from
Mar 5, 2025
Merged

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Feb 20, 2025

Alternative to #137233.

#137233 (comment)

Fixes #137186

We do this check in mir_drops_elaborated_and_const_checked and not during mir_promoted because that may result in borrowck cycles if WF requires looking into an opaque hidden type. This causes some TAIT tests to fail unnecessarily.

r? lcnr

try-job: test-various

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 20, 2025
@rustbot
Copy link
Collaborator

rustbot commented Feb 20, 2025

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@lcnr
Copy link
Contributor

lcnr commented Feb 20, 2025

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Feb 20, 2025

📌 Commit bb7b912 has been approved by lcnr

It is now in the queue for this repository.

@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 Feb 20, 2025
workingjubilee added a commit to workingjubilee/rustc that referenced this pull request Feb 20, 2025
Check signature WF when lowering MIR body

Alternative to rust-lang#137233.

rust-lang#137233 (comment)

Fixes rust-lang#137186

We do this check in `mir_drops_elaborated_and_const_checked` and not during `mir_promoted` because that may result in borrowck cycles if WF requires looking into an opaque hidden type. This causes some TAIT tests to fail unnecessarily.

r? lcnr
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 20, 2025
…kingjubilee

Rollup of 14 pull requests

Successful merges:

 - rust-lang#131651 (Create a generic AVR target: avr-none)
 - rust-lang#136473 (infer linker flavor by linker name if it's sufficiently specific)
 - rust-lang#136608 (Pass through of target features to llvm-bitcode-linker and handling them)
 - rust-lang#136985 (Do not ignore uninhabited types for function-call ABI purposes. (Remove BackendRepr::Uninhabited))
 - rust-lang#137192 (Remove obsolete Windows ThinLTO+TLS workaround)
 - rust-lang#137204 (Clarify MIR dialects and phases)
 - rust-lang#137270 (Fix `*-win7-windows-msvc` target since 26eeac1)
 - rust-lang#137298 (Check signature WF when lowering MIR body)
 - rust-lang#137299 (Simplify `Postorder` customization.)
 - rust-lang#137312 (Update references to cc_detect.rs)
 - rust-lang#137313 (Some codegen_llvm cleanups)
 - rust-lang#137318 (Workaround Cranelift not yet properly supporting vectors smaller than 128bit)
 - rust-lang#137322 (Update docs for default features of wasm targets)
 - rust-lang#137324 (Make x86 QNX target name consistent with other Rust targets)

r? `@ghost`
`@rustbot` modify labels: rollup
@workingjubilee
Copy link
Member

#137339 (comment)
@bors r- rollup=maybe
@bors try

@bors bors 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Feb 20, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 20, 2025
Check signature WF when lowering MIR body

Alternative to rust-lang#137233.

rust-lang#137233 (comment)

Fixes rust-lang#137186

We do this check in `mir_drops_elaborated_and_const_checked` and not during `mir_promoted` because that may result in borrowck cycles if WF requires looking into an opaque hidden type. This causes some TAIT tests to fail unnecessarily.

r? lcnr

try-job: test-various
@bors
Copy link
Collaborator

bors commented Feb 20, 2025

⌛ Trying commit bb7b912 with merge 7527550...

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Feb 20, 2025

💔 Test failed - checks-actions

@jieyouxu
Copy link
Member

Hm, the wasm tests may have symbol redefinition problems? 🤔

@lcnr
Copy link
Contributor

lcnr commented Feb 21, 2025

I think that's a proper error, we somehow depend on the value of a static when checking that it's well-formed 🤔 this is surprising to me (and even more surprising that we don't have a separate UI test which triggers this)

@rustbot rustbot added the A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) label Feb 21, 2025
@compiler-errors
Copy link
Member Author

@bors try

@compiler-errors compiler-errors removed the A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) label Feb 21, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 21, 2025
Check signature WF when lowering MIR body

Alternative to rust-lang#137233.

rust-lang#137233 (comment)

Fixes rust-lang#137186

We do this check in `mir_drops_elaborated_and_const_checked` and not during `mir_promoted` because that may result in borrowck cycles if WF requires looking into an opaque hidden type. This causes some TAIT tests to fail unnecessarily.

r? lcnr

try-job: test-various
@bors
Copy link
Collaborator

bors commented Feb 21, 2025

⌛ Trying commit eb94a63 with merge e7267fa...

@compiler-errors
Copy link
Member Author

It's

fn maybe_check_static_with_link_section(tcx: TyCtxt<'_>, id: LocalDefId) {
// Only restricted on wasm target for now
if !tcx.sess.target.is_like_wasm {
return;
}
// If `#[link_section]` is missing, then nothing to verify
let attrs = tcx.codegen_fn_attrs(id);
if attrs.link_section.is_none() {
return;
}
// For the wasm32 target statics with `#[link_section]` other than `.init_array`
// are placed into custom sections of the final output file, but this isn't like
// custom sections of other executable formats. Namely we can only embed a list
// of bytes, nothing with provenance (pointers to anything else). If any
// provenance show up, reject it here.
// `#[link_section]` may contain arbitrary, or even undefined bytes, but it is
// the consumer's responsibility to ensure all bytes that have been read
// have defined values.
//
// The `.init_array` section is left to go through the normal custom section code path.
// When dealing with `.init_array` wasm-ld currently has several limitations. This manifests
// in workarounds in user-code.
//
// * The linker fails to merge multiple items in a crate into the .init_array section.
// To work around this, a single array can be used placing multiple items in the array.
// #[link_section = ".init_array"]
// static FOO: [unsafe extern "C" fn(); 2] = [ctor, ctor];
// * Even symbols marked used get gc'd from dependant crates unless at least one symbol
// in the crate is marked with an `#[export_name]`
//
// Once `.init_array` support in wasm-ld is complete, the user code workarounds should
// continue to work, but would no longer be necessary.
if let Ok(alloc) = tcx.eval_static_initializer(id.to_def_id())
&& alloc.inner().provenance().ptrs().len() != 0
&& attrs
.link_section
.map(|link_section| !link_section.as_str().starts_with(".init_array"))
.unwrap()
{
let msg = "statics with a custom `#[link_section]` must be a \
simple list of bytes on the wasm target with no \
extra levels of indirection such as references";
tcx.dcx().span_err(tcx.def_span(id), msg);
}
}

I'll move that out of WF and into the regular "checks".

@compiler-errors
Copy link
Member Author

@bors try

bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 22, 2025
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#135501 (Inject `compiler_builtins` during postprocessing and ensure it is made private)
 - rust-lang#136543 (intrinsics: unify rint, roundeven, nearbyint in a single round_ties_even intrinsic)
 - rust-lang#137121 (stabilize `(const_)ptr_sub_ptr`)
 - rust-lang#137180 (Give `global_asm` a fake body to store typeck results, represent `sym fn` as a hir expr to fix `sym fn` operands with lifetimes)
 - rust-lang#137256 (compiler: untangle SIMD alignment assumptions)
 - rust-lang#137298 (Check signature WF when lowering MIR body)
 - rust-lang#137415 (Remove invalid suggestion of into_iter for extern macro)

r? `@ghost`
`@rustbot` modify labels: rollup
@compiler-errors
Copy link
Member Author

@bors r-

@bors bors 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Feb 22, 2025
@alexcrichton
Copy link
Member

There was a bit of discussion on Zulip on what's going on here wasm-wise, and while it looks like you've diagnosed and solved it I wanted to lend a helping hand in that respect where if anything else wasm-related comes up here feel free to ping me and I can try to help discover what's going on if any extra help is needed

@rust-log-analyzer

This comment has been minimized.

@@ -7,4 +7,5 @@

struct A;
struct B;
const S: A = B;

pub const S: A = B;
Copy link
Member Author

Choose a reason for hiding this comment

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

A side-effect of this is that consts are only required to typeck if they're being documented.

Copy link
Contributor

@lcnr lcnr Mar 4, 2025

Choose a reason for hiding this comment

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

in rustdoc

Copy link
Member Author

Choose a reason for hiding this comment

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

oh 💀 yes in roblox

@@ -2,4 +2,4 @@

#![feature(const_transmute)]

const ZST: &[u8] = unsafe { std::mem::transmute(1usize) }; //~ ERROR cannot transmute between types of different sizes, or dependently-sized types
pub const ZST: &[u8] = unsafe { std::mem::transmute(1usize) }; //~ ERROR cannot transmute between types of different sizes, or dependently-sized types
Copy link
Contributor

Choose a reason for hiding this comment

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

why this pub?

Copy link
Member Author

Choose a reason for hiding this comment

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

so we can keep the error

@lcnr
Copy link
Contributor

lcnr commented Mar 4, 2025

@bors

@lcnr
Copy link
Contributor

lcnr commented Mar 4, 2025

@bors r+

@bors
Copy link
Collaborator

bors commented Mar 4, 2025

📌 Commit 0baee24 has been approved by lcnr

It is now in the queue for this repository.

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 4, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 5, 2025
Rollup of 20 pull requests

Successful merges:

 - rust-lang#134063 (dec2flt: Clean up float parsing modules)
 - rust-lang#136581 (Retire the legacy `Makefile`-based `run-make` test infra)
 - rust-lang#136662 (Count char width at most once in `Formatter::pad`)
 - rust-lang#136764 (Make `ptr_cast_add_auto_to_object` lint into hard error)
 - rust-lang#136798 (Added documentation for flushing per rust-lang#74348)
 - rust-lang#136865 (Perform deeper compiletest path normalization for `$TEST_BUILD_DIR` to account for compare-mode/debugger cases, and normalize long type file filename hashes)
 - rust-lang#136975 (Look for `python3` first on MacOS, not `py`)
 - rust-lang#136977 (Upload Datadog metrics with citool)
 - rust-lang#137240 (Slightly reformat `std::fs::remove_dir_all` error docs)
 - rust-lang#137298 (Check signature WF when lowering MIR body)
 - rust-lang#137463 ([illumos] attempt to use posix_spawn to spawn processes)
 - rust-lang#137477 (uefi: Add Service Binding Protocol abstraction)
 - rust-lang#137569 (Stabilize `string_extend_from_within`)
 - rust-lang#137633 (Only use implied bounds hack if bevy, and use deeply normalize in implied bounds hack)
 - rust-lang#137679 (Various coretests improvements)
 - rust-lang#137723 (Make `rust.description` more general-purpose and pass `CFG_VER_DESCRIPTION`)
 - rust-lang#137728 (Remove unsizing coercions for tuples)
 - rust-lang#137731 (Resume one waiter at once in deadlock handler)
 - rust-lang#137875 (mir_build: Integrate "simplification" steps into match-pair-tree creation)
 - rust-lang#138028 (compiler: add `ExternAbi::is_rustic_abi`)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 5df9a9f into rust-lang:master Mar 5, 2025
6 checks passed
@rustbot rustbot added this to the 1.87.0 milestone Mar 5, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Mar 5, 2025
Rollup merge of rust-lang#137298 - compiler-errors:mir-wf, r=lcnr

Check signature WF when lowering MIR body

Alternative to rust-lang#137233.

rust-lang#137233 (comment)

Fixes rust-lang#137186

We do this check in `mir_drops_elaborated_and_const_checked` and not during `mir_promoted` because that may result in borrowck cycles if WF requires looking into an opaque hidden type. This causes some TAIT tests to fail unnecessarily.

r? lcnr

try-job: test-various
@rustbot rustbot added the beta-nominated Nominated for backporting to the compiler in the beta channel. label Mar 5, 2025
@rustbot rustbot added the beta-accepted Accepted for backporting to the compiler in the beta channel. label Mar 6, 2025
@apiraino apiraino removed beta-accepted Accepted for backporting to the compiler in the beta channel. beta-nominated Nominated for backporting to the compiler in the beta channel. labels Mar 6, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
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.

ICE: assertion failed: layout.is_sized()
9 participants