-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Ensure that static initializers are acyclic for NVPTX #150569
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
Ensure that static initializers are acyclic for NVPTX #150569
Conversation
|
@rustbot label: +O-NVPTX |
This comment has been minimized.
This comment has been minimized.
10f31cc to
18143a8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing this. Haven't checked the logic closely yet.
compiler/rustc_const_eval/src/check_static_initializer_acyclic.rs
Outdated
Show resolved
Hide resolved
|
Thank you for the reviews so far! I will address them over the next few days. I am happy to receive comments and suggestions, especially since this is my first larger contribution to the compiler. This is still an early version, but I wanted to ensure that my implementation does not negatively affect other components of the compiler. I also wanted to gather feedback on the general approach and the optimal location for this analysis within the code. I plan to add more tests and documentation as well. On that note, would documenting this restriction inside the target description be sufficient? Is there a place to document nonconformity in general? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think that putting it in the platform support documentation would be fine. Or at least, I'm not aware of a better place at the moment.
compiler/rustc_const_eval/src/check_static_initializer_acyclic.rs
Outdated
Show resolved
Hide resolved
compiler/rustc_const_eval/src/check_static_initializer_acyclic.rs
Outdated
Show resolved
Hide resolved
compiler/rustc_const_eval/src/check_static_initializer_acyclic.rs
Outdated
Show resolved
Hide resolved
compiler/rustc_const_eval/src/check_static_initializer_acyclic.rs
Outdated
Show resolved
Hide resolved
18143a8 to
639e93f
Compare
This comment has been minimized.
This comment has been minimized.
6ab2f24 to
2a1afe3
Compare
|
Some changes occurred in src/doc/rustc/src/platform-support cc @Noratrieb This PR modifies cc @jieyouxu These commits modify compiler targets. These commits modify the If this was unintentional then you should revert the changes before this PR is merged. |
|
r? @nnethercote rustbot has assigned @nnethercote. Use |
This comment has been minimized.
This comment has been minimized.
|
I think I now have a simpler implementation. Instead of computing the graph myself, I'm using the mono item graph. Since this is the first check in cc @kjetilkjeka |
|
cc @FractalFir, who filed #146787. |
f4c3911 to
800dc45
Compare
NVPTX does not support cycles in static initializers. LLVM produces an error when attempting to codegen such constructs (like self referential structs). To not produce LLVM UB we instead emit a post-monomorphization error on Rust side before reaching codegen. This is achieved by analysing a subgraph of the "mono item graph" that only contains statics: 1. Calculate the strongly connected components (SCCs) of the graph 2. Check for cycles (more than one node in a SCC or exactly one node which references itself)
800dc45 to
630c759
Compare
| } | ||
| }; | ||
| // Emit errors for all cycles | ||
| for nodes in nodes_of_sccs.iter_mut().filter(|nodes| is_cyclic(nodes)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor adjustment:
I now iterate directly over the SCC-grouped nodes and check for cyclicality instead of acyclicality, which makes it possible to filter.
|
|
||
| mod statics; | ||
|
|
||
| pub(super) fn target_specific_checks<'tcx, 'a, 'b>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a way this is sort of a misnomer because target feature checks are also target-specific but they're also kinda not?
I'm not gonna stress over it.
|
The test looks good. I know that this is in a safe place now. The code cleaned up nicely. I have been previously assigned other PRs that add target-informed checks so I know there is at least appetite for adding similar-ish constraints. LLVM does currently error on this case, so this is technically a "no-op" change. If it does have consequence, it will be because LLVM removed the error... which is something they have previously done, expecting frontends to handle some target-specific check instead. So the only thing this can do, as far as I can tell, is protect us from UB. With all that in mind, @bors r+ rollup But this is a novel sort of check, affecting how sound, safe Rust code builds for a specific target. That is one of the things highlighted by our review policy. So despite being a no-op, I feel I should also cc @davidtwco @wesleywiser so that they know a rustc target has impaired functionality. |
…clic, r=workingjubilee Ensure that static initializers are acyclic for NVPTX NVPTX does not support cycles in static initializers (see rust-lang#146787). LLVM produces an error when attempting to generate code for such constructs, like self-referential structs. To avoid LLVM UB, we emit a post-monomorphization error on the Rust side before reaching codegen. This is achieved by analyzing a subgraph of the "mono item graph" that only contains statics. 1. Calculate the strongly connected components (SCCs) of the graph. 2. Check for cycles (more than one node in an SCC or one node that references itself).
…uwer Rollup of 3 pull requests Successful merges: - #150094 (`c_variadic`: provide our own `va_arg` implementation for more targets) - #150569 (Ensure that static initializers are acyclic for NVPTX) - #150668 (Unix implementation for stdio set/take/replace) r? `@ghost` `@rustbot` modify labels: rollup
Ensure that static initializers are acyclic for NVPTX Commit rust-lang#147526 removed the following code and replaced it with the `AllocatorMethod`. However, its input is empty, resulting in behavior inconsistent with the previous code. ```rust create_wrapper_function( tcx, &cx, &mangle_internal_symbol(tcx, "__rust_alloc_error_handler"), Some(&mangle_internal_symbol(tcx, alloc_error_handler_name(alloc_error_handler_kind))), &[usize, usize], // size, align None, true, &CodegenFnAttrs::new(), ); ``` resolves rust-lang#150755
Ensure that static initializers are acyclic for NVPTX With this, we should no longer need to turn off the default features, so we can undo rust-lang#149550. @bjorn3 you seem to have a test setup to check if this works properly in terms of skipping all the work that should not be required -- could you test if this PR works as intended? FWIW we could now remove `default_features` from `run_tool_check_step`. Not sure if that's worth it.
…r=workingjubilee Ensure that static initializers are acyclic for NVPTX NVPTX does not support cycles in static initializers (see rust-lang#146787). LLVM produces an error when attempting to generate code for such constructs, like self-referential structs. To avoid LLVM UB, we emit a post-monomorphization error on the Rust side before reaching codegen. This is achieved by analyzing a subgraph of the "mono item graph" that only contains statics. 1. Calculate the strongly connected components (SCCs) of the graph. 2. Check for cycles (more than one node in an SCC or one node that references itself).
…r=workingjubilee Ensure that static initializers are acyclic for NVPTX NVPTX does not support cycles in static initializers (see rust-lang#146787). LLVM produces an error when attempting to generate code for such constructs, like self-referential structs. To avoid LLVM UB, we emit a post-monomorphization error on the Rust side before reaching codegen. This is achieved by analyzing a subgraph of the "mono item graph" that only contains statics. 1. Calculate the strongly connected components (SCCs) of the graph. 2. Check for cycles (more than one node in an SCC or one node that references itself).
…r=workingjubilee Ensure that static initializers are acyclic for NVPTX NVPTX does not support cycles in static initializers (see rust-lang#146787). LLVM produces an error when attempting to generate code for such constructs, like self-referential structs. To avoid LLVM UB, we emit a post-monomorphization error on the Rust side before reaching codegen. This is achieved by analyzing a subgraph of the "mono item graph" that only contains statics. 1. Calculate the strongly connected components (SCCs) of the graph. 2. Check for cycles (more than one node in an SCC or one node that references itself).
…r=workingjubilee Ensure that static initializers are acyclic for NVPTX NVPTX does not support cycles in static initializers (see rust-lang#146787). LLVM produces an error when attempting to generate code for such constructs, like self-referential structs. To avoid LLVM UB, we emit a post-monomorphization error on the Rust side before reaching codegen. This is achieved by analyzing a subgraph of the "mono item graph" that only contains statics. 1. Calculate the strongly connected components (SCCs) of the graph. 2. Check for cycles (more than one node in an SCC or one node that references itself).
…r=workingjubilee Ensure that static initializers are acyclic for NVPTX NVPTX does not support cycles in static initializers (see rust-lang#146787). LLVM produces an error when attempting to generate code for such constructs, like self-referential structs. To avoid LLVM UB, we emit a post-monomorphization error on the Rust side before reaching codegen. This is achieved by analyzing a subgraph of the "mono item graph" that only contains statics. 1. Calculate the strongly connected components (SCCs) of the graph. 2. Check for cycles (more than one node in an SCC or one node that references itself).
Rollup of 11 pull requests Successful merges: - #149976 (Add waker_fn and local_waker_fn to std::task) - #150074 (Update provider API docs) - #150094 (`c_variadic`: provide our own `va_arg` implementation for more targets) - #150164 (rustc: Fix `-Zexport-executable-symbols` on wasm) - #150569 (Ensure that static initializers are acyclic for NVPTX) - #150607 (Add amdgpu_dispatch_ptr intrinsic) - #150694 (./x check miri: enable check_only feature) - #150717 (Thread `--jobs` from `bootstrap` -> `compiletest` -> `run-make-support`) - #150736 (Add AtomicPtr::null) - #150787 (Add myself as co-maintainer for s390x-unknown-linux-musl) - #150789 (Fix copy-n-paste error in `vtable_for` docs) r? @ghost
Rollup of 10 pull requests Successful merges: - #149976 (Add waker_fn and local_waker_fn to std::task) - #150074 (Update provider API docs) - #150094 (`c_variadic`: provide our own `va_arg` implementation for more targets) - #150164 (rustc: Fix `-Zexport-executable-symbols` on wasm) - #150569 (Ensure that static initializers are acyclic for NVPTX) - #150694 (./x check miri: enable check_only feature) - #150717 (Thread `--jobs` from `bootstrap` -> `compiletest` -> `run-make-support`) - #150736 (Add AtomicPtr::null) - #150787 (Add myself as co-maintainer for s390x-unknown-linux-musl) - #150789 (Fix copy-n-paste error in `vtable_for` docs) r? @ghost
Rollup merge of #150569 - check_static_initializer_acyclic, r=workingjubilee Ensure that static initializers are acyclic for NVPTX NVPTX does not support cycles in static initializers (see #146787). LLVM produces an error when attempting to generate code for such constructs, like self-referential structs. To avoid LLVM UB, we emit a post-monomorphization error on the Rust side before reaching codegen. This is achieved by analyzing a subgraph of the "mono item graph" that only contains statics. 1. Calculate the strongly connected components (SCCs) of the graph. 2. Check for cycles (more than one node in an SCC or one node that references itself).
NVPTX does not support cycles in static initializers (see #146787). LLVM produces an error when attempting to generate code for such constructs, like self-referential structs.
To avoid LLVM UB, we emit a post-monomorphization error on the Rust side before reaching codegen.
This is achieved by analyzing a subgraph of the "mono item graph" that only contains statics.