Skip to content

Conversation

AMS21
Copy link
Contributor

@AMS21 AMS21 commented Oct 8, 2025

Since it can easily be implemented using the existing LLVM C API in
terms of LLVMAddGlobal and LLVMSetLinkage and define_private_global
was only used in one place.

Work towards #46437

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. 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 Oct 8, 2025
@rustbot
Copy link
Collaborator

rustbot commented Oct 8, 2025

r? @SparrowLii

rustbot has assigned @SparrowLii.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

…obal`

Since it can easily be implemented using the existing LLVM C API in
terms of `LLVMAddGlobal` and `LLVMSetLinkage` and `define_private_global`
was only used in one place.
@AMS21 AMS21 force-pushed the remove_llvm_rust_insert_private_global branch from 101b8d5 to 036ab3a Compare October 8, 2025 20:00
@AMS21 AMS21 changed the title refactor: Remove LLVMRustInsertPrivateGlobal refactor: Remove LLVMRustInsertPrivateGlobal and define_private_global Oct 8, 2025
@nikic
Copy link
Contributor

nikic commented Oct 9, 2025

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Oct 9, 2025

📌 Commit 036ab3a has been approved by nikic

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 Oct 9, 2025
bors added a commit that referenced this pull request Oct 9, 2025
Rollup of 12 pull requests

Successful merges:

 - #146568 (Port the implemention of SIMD intrinsics from Miri to const-eval)
 - #147373 (give a better example why `std` modules named like primitives are needed)
 - #147419 (bootstrap: add `Builder::rustc_cmd` that includes the lib path)
 - #147420 (Add diagnostic items for `pub mod consts` of FP types)
 - #147457 (specialize slice::fill to use memset when possible)
 - #147467 (Fix double warnings on `#[no_mangle]`)
 - #147470 (Clarify how to remediate the panic_immediate_abort error)
 - #147480 (Do not invalidate CFG caches in CtfeLimit.)
 - #147481 (format: some small cleanup)
 - #147488 (refactor: Remove `LLVMRustInsertPrivateGlobal` and `define_private_global`)
 - #147489 (Prefer to use repeat_n over repeat().take())
 - #147506 (compiletest: Isolate public APIs and minimize public surface area)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 4dfd977 into rust-lang:master Oct 9, 2025
10 checks passed
@rustbot rustbot added this to the 1.92.0 milestone Oct 9, 2025
rust-timer added a commit that referenced this pull request Oct 9, 2025
Rollup merge of #147488 - AMS21:remove_llvm_rust_insert_private_global, r=nikic

refactor: Remove `LLVMRustInsertPrivateGlobal` and `define_private_global`

Since it can easily be implemented using the existing LLVM C API in
terms of `LLVMAddGlobal` and `LLVMSetLinkage` and `define_private_global`
was only used in one place.

Work towards #46437
@AMS21 AMS21 deleted the remove_llvm_rust_insert_private_global branch October 9, 2025 11:01
RalfJung pushed a commit to RalfJung/miri that referenced this pull request Oct 13, 2025
Rollup of 12 pull requests

Successful merges:

 - rust-lang/rust#146568 (Port the implemention of SIMD intrinsics from Miri to const-eval)
 - rust-lang/rust#147373 (give a better example why `std` modules named like primitives are needed)
 - rust-lang/rust#147419 (bootstrap: add `Builder::rustc_cmd` that includes the lib path)
 - rust-lang/rust#147420 (Add diagnostic items for `pub mod consts` of FP types)
 - rust-lang/rust#147457 (specialize slice::fill to use memset when possible)
 - rust-lang/rust#147467 (Fix double warnings on `#[no_mangle]`)
 - rust-lang/rust#147470 (Clarify how to remediate the panic_immediate_abort error)
 - rust-lang/rust#147480 (Do not invalidate CFG caches in CtfeLimit.)
 - rust-lang/rust#147481 (format: some small cleanup)
 - rust-lang/rust#147488 (refactor: Remove `LLVMRustInsertPrivateGlobal` and `define_private_global`)
 - rust-lang/rust#147489 (Prefer to use repeat_n over repeat().take())
 - rust-lang/rust#147506 (compiletest: Isolate public APIs and minimize public surface area)

r? `@ghost`
`@rustbot` modify labels: rollup
gv
}
_ => self.define_private_global(self.val_ty(cv)),
_ => self.define_global("", self.val_ty(cv)).unwrap_or_else(|| {
Copy link
Member

@RalfJung RalfJung Oct 16, 2025

Choose a reason for hiding this comment

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

What on Earth does it mean to give a global the empty string as the name?!? This is not documented anywhere that I could find. (I checked define_global and a few of the functions it calls.)

Copy link
Contributor

Choose a reason for hiding this comment

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

The change done after @nikic's review comment doesn't seem to match what was suggested.

Copy link
Contributor

@nikic nikic Oct 16, 2025

Choose a reason for hiding this comment

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

An empty string name is how you create an anonymous symbol.

This is the same thing the old code did, it was just hidden behind a const Twine &Name = "" default value.

Copy link
Member

@RalfJung RalfJung Oct 16, 2025

Choose a reason for hiding this comment

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

Does "anonymous" mean "guaranteed fresh"?
And get_defined_value("") always returns None?

The bug! below this line makes it sound like "anonymous global symbol is already defined" is an actual error condition, but if it is truly fresh then that adds to my confusion.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. This kind of global is considered "unnamed" and will be rendered as @42 or similar when printed. The bug! here can't fail.

Do I understand correctly that the suggestion here is to replace the call to define_global() with declare_global(), which doesn't check existence of the global first, which also means we don't need this unwrap?

Copy link
Member

Choose a reason for hiding this comment

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

I hadn't even though of that, but that sounds like a good idea -- together with documentation for declare_global that says what happens when the name is empty.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. 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