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

Implement intrinsics with fallback bodies #120500

Merged
merged 13 commits into from
Feb 16, 2024
Merged

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Jan 30, 2024

fixes #93145 (though we can port many more intrinsics)
cc #63585

The way this works is that the backend logic for generating custom code for intrinsics has been made fallible. The only failure path is "this intrinsic is unknown". The Instance (that was InstanceDef::Intrinsic) then gets converted to InstanceDef::Item, which represents the fallback body. A regular function call to that body is then codegenned. This is currently implemented for

  • codegen_ssa (so llvm and gcc)
  • codegen_cranelift

other backends will need to adjust, but they can just keep doing what they were doing if they prefer (though adding new intrinsics to the compiler will then require them to implement them, instead of getting the fallback body).

cc @scottmcm @WaffleLapkin

todo

  • miri support
  • default intrinsic name to name of function instead of requiring it to be specified in attribute
  • make sure that the bodies are always available (must be collected for metadata)

@rustbot
Copy link
Collaborator

rustbot commented Jan 30, 2024

r? @Mark-Simulacrum

(rustbot has picked a reviewer for you, use r? to override)

@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. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jan 30, 2024
@rustbot
Copy link
Collaborator

rustbot commented Jan 30, 2024

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo, @GuillaumeGomez

Some changes occurred in compiler/rustc_codegen_cranelift

cc @bjorn3

Some changes occurred to the CTFE / Miri engine

cc @rust-lang/miri

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@WaffleLapkin WaffleLapkin left a 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, really glad someone finally found time for this! :3

r=me, modulo couple nits (did not notice bjorn's concern, you might want to address it)

compiler/rustc_middle/src/ty/util.rs Outdated Show resolved Hide resolved
compiler/rustc_middle/src/ty/util.rs Outdated Show resolved Hide resolved
@rust-log-analyzer

This comment has been minimized.

@scottmcm
Copy link
Member

Thanks for working on this, Oli! I'm really excited 🎉

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Jan 31, 2024

Some changes occurred in src/librustdoc/clean/types.rs

cc @camelid

@rust-log-analyzer

This comment has been minimized.

@oli-obk
Copy link
Contributor Author

oli-obk commented Jan 31, 2024

Should finally be ready. We don't need miri support from the get go, so I'd rather do it in a separate PR.

fx.tcx
.dcx()
.span_fatal(source_info.span, format!("unsupported intrinsic {}", intrinsic));
}
Copy link
Member

Choose a reason for hiding this comment

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

What will the error message be for intrinsics that are neither implemented by cg_clif nor have a fallback body?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

probably gonna ICE 😆

@bjorn3
Copy link
Member

bjorn3 commented Feb 1, 2024

cg_clif changes LGTM

@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@WaffleLapkin WaffleLapkin left a comment

Choose a reason for hiding this comment

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

r=me with or without nits

@rustbot
Copy link
Collaborator

rustbot commented Feb 2, 2024

The Miri subtree was changed

cc @rust-lang/miri

@oli-obk
Copy link
Contributor Author

oli-obk commented Feb 2, 2024

@bors r=WaffleLapkin

@bors
Copy link
Contributor

bors commented Feb 2, 2024

📌 Commit 585e76a has been approved by WaffleLapkin

It is now in the queue for this repository.

bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 13, 2024
Rollup of 6 pull requests

Successful merges:

 - rust-lang#120486 (Use generic `NonZero` internally.)
 - rust-lang#120500 (Implement intrinsics with fallback bodies)
 - rust-lang#120530 (Be less confident when `dyn` suggestion is not checked for object safety)
 - rust-lang#120563 (Make `NonZero::get` generic.)
 - rust-lang#120847 (Continue compilation after check_mod_type_wf errors)
 - rust-lang#120959 (Remove good path delayed bugs)

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

The default log presentation was not expanding for me; below is what I think was causing the failure according to what I saw from skimming the raw log itself.

Snippet of raw log output with ui test failures
2024-02-13T12:28:04.4476978Z failures:
2024-02-13T12:28:04.4477808Z 
2024-02-13T12:28:04.4479578Z ---- [ui] tests/ui/const-generics/issues/issue-72352.rs#full stdout ----
2024-02-13T12:28:04.4482070Z diff of stderr:
2024-02-13T12:28:04.4482964Z 
2024-02-13T12:28:04.4485008Z 4	LL | unsafe fn unsafely_do_the_thing<const F: fn(&CStr) -> usize>(ptr: *const i8) -> usize {
2024-02-13T12:28:04.4488162Z 5	   |                                          ^^^^^^^^^^^^^^^^^^
2024-02-13T12:28:04.4490088Z 6	
2024-02-13T12:28:04.4491728Z -	error: aborting due to 1 previous error
2024-02-13T12:28:04.4493731Z +	error[E0308]: mismatched types
2024-02-13T12:28:04.4495708Z +	  --> $DIR/issue-72352.rs:9:22
2024-02-13T12:28:04.4497415Z +	   |
2024-02-13T12:28:04.4498807Z +	LL |     F(CStr::from_ptr(ptr))
2024-02-13T12:28:04.4501203Z +	   |       -------------- ^^^ expected `*const u8`, found `*const i8`
2024-02-13T12:28:04.4503355Z +	   |       |
2024-02-13T12:28:04.4505005Z +	   |       arguments to this function are incorrect
2024-02-13T12:28:04.4506988Z +	   |
2024-02-13T12:28:04.4508470Z +	   = note: expected raw pointer `*const u8`
2024-02-13T12:28:04.4510583Z +	              found raw pointer `*const i8`
2024-02-13T12:28:04.4512929Z +	note: associated function defined here
2024-02-13T12:28:04.4515276Z +	  --> $SRC_DIR/core/src/ffi/c_str.rs:LL:COL
2024-02-13T12:28:04.4517475Z 8	
2024-02-13T12:28:04.4519699Z -	For more information about this error, try `rustc --explain E0741`.
2024-02-13T12:28:04.4522252Z +	error[E0308]: mismatched types
2024-02-13T12:28:04.4524182Z +	  --> $DIR/issue-72352.rs:20:54
2024-02-13T12:28:04.4525830Z +	   |
2024-02-13T12:28:04.4527561Z +	LL |         unsafely_do_the_thing::<safely_do_the_thing>(ptr)
2024-02-13T12:28:04.4531361Z +	   |         -------------------------------------------- ^^^ expected `*const i8`, found `*const u8`
2024-02-13T12:28:04.4534060Z +	   |         |
2024-02-13T12:28:04.4535739Z +	   |         arguments to this function are incorrect
2024-02-13T12:28:04.4537734Z +	   |
2024-02-13T12:28:04.4539214Z +	   = note: expected raw pointer `*const i8`
2024-02-13T12:28:04.4541319Z +	              found raw pointer `*const u8`
2024-02-13T12:28:04.4543304Z +	note: function defined here
2024-02-13T12:28:04.4545220Z +	  --> $DIR/issue-72352.rs:7:11
2024-02-13T12:28:04.4547111Z +	   |
2024-02-13T12:28:04.4550071Z +	LL | unsafe fn unsafely_do_the_thing<const F: fn(&CStr) -> usize>(ptr: *const i8) -> usize {
2024-02-13T12:28:04.4556378Z +	   |           ^^^^^^^^^^^^^^^^^^^^^                              --------------
2024-02-13T12:28:04.4557222Z +	
2024-02-13T12:28:04.4557813Z +	error: aborting due to 3 previous errors
2024-02-13T12:28:04.4558827Z +	
2024-02-13T12:28:04.4559555Z +	Some errors have detailed explanations: E0308, E0741.
2024-02-13T12:28:04.4560833Z +	For more information about an error, try `rustc --explain E0308`.
2024-02-13T12:28:04.4561804Z 10	
2024-02-13T12:28:04.4562095Z 
2024-02-13T12:28:04.4562109Z 
2024-02-13T12:28:04.4562506Z The actual stderr differed from the expected stderr.
2024-02-13T12:28:04.4564491Z Actual stderr saved to /checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/const-generics/issues/issue-72352.full/issue-72352.full.stderr
2024-02-13T12:28:04.4566511Z To update references, rerun the tests and pass the `--bless` flag
2024-02-13T12:28:04.4568098Z To only update this specific test, also pass `--test-args const-generics/issues/issue-72352.rs`
2024-02-13T12:28:04.4569099Z 
2024-02-13T12:28:04.4572343Z error in revision `full`: 1 errors occurred comparing output.
2024-02-13T12:28:04.4573352Z status: exit status: 1
2024-02-13T12:28:04.4583124Z command: RUSTC_ICE="0" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/const-generics/issues/issue-72352.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--cfg" "full" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/const-generics/issues/issue-72352.full" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/const-generics/issues/issue-72352.full/auxiliary"
2024-02-13T12:28:04.4592201Z stdout: none
2024-02-13T12:28:04.4592920Z --- stderr -------------------------------
2024-02-13T12:28:04.4603660Z error[E0741]: using function pointers as const generic parameters is forbidden
2024-02-13T12:28:04.4628644Z ##[error]  --> /checkout/tests/ui/const-generics/issues/issue-72352.rs:7:42
2024-02-13T12:28:04.4640736Z    |
2024-02-13T12:28:04.4641973Z LL | unsafe fn unsafely_do_the_thing<const F: fn(&CStr) -> usize>(ptr: *const i8) -> usize {
2024-02-13T12:28:04.4643233Z    |                                          ^^^^^^^^^^^^^^^^^^
2024-02-13T12:28:04.4643816Z 
2024-02-13T12:28:04.4644155Z error[E0308]: mismatched types
2024-02-13T12:28:04.4645829Z ##[error]  --> /checkout/tests/ui/const-generics/issues/issue-72352.rs:9:22
2024-02-13T12:28:04.4647776Z    |
2024-02-13T12:28:04.4648364Z LL |     F(CStr::from_ptr(ptr))
2024-02-13T12:28:04.4649339Z    |       -------------- ^^^ expected `*const u8`, found `*const i8`
2024-02-13T12:28:04.4650196Z    |       |
2024-02-13T12:28:04.4650858Z    |       arguments to this function are incorrect
2024-02-13T12:28:04.4651665Z    |
2024-02-13T12:28:04.4652258Z    = note: expected raw pointer `*const u8`
2024-02-13T12:28:04.4653463Z               found raw pointer `*const i8`
2024-02-13T12:28:04.4654444Z note: associated function defined here
2024-02-13T12:28:04.4655515Z   --> /rustc/FAKE_PREFIX/library/core/src/ffi/c_str.rs:263:25
2024-02-13T12:28:04.4656196Z 
2024-02-13T12:28:04.4656523Z error[E0308]: mismatched types
2024-02-13T12:28:04.4658038Z ##[error]  --> /checkout/tests/ui/const-generics/issues/issue-72352.rs:20:54
2024-02-13T12:28:04.4659960Z    |
2024-02-13T12:28:04.4660675Z LL |         unsafely_do_the_thing::<safely_do_the_thing>(ptr)
2024-02-13T12:28:04.4662135Z    |         -------------------------------------------- ^^^ expected `*const i8`, found `*const u8`
2024-02-13T12:28:04.4663140Z    |         |
2024-02-13T12:28:04.4663829Z    |         arguments to this function are incorrect
2024-02-13T12:28:04.4664638Z    |
2024-02-13T12:28:04.4665232Z    = note: expected raw pointer `*const i8`
2024-02-13T12:28:04.4666224Z               found raw pointer `*const u8`
2024-02-13T12:28:04.4667077Z note: function defined here
2024-02-13T12:28:04.4668101Z   --> /checkout/tests/ui/const-generics/issues/issue-72352.rs:7:11
2024-02-13T12:28:04.4669037Z    |
2024-02-13T12:28:04.4670116Z LL | unsafe fn unsafely_do_the_thing<const F: fn(&CStr) -> usize>(ptr: *const i8) -> usize {
2024-02-13T12:28:04.4671483Z    |           ^^^^^^^^^^^^^^^^^^^^^                              --------------
2024-02-13T12:28:04.4673499Z 
2024-02-13T12:28:04.4673830Z error: aborting due to 3 previous errors
2024-02-13T12:28:04.4674310Z 
2024-02-13T12:28:04.4674660Z Some errors have detailed explanations: E0308, E0741.
2024-02-13T12:28:04.4675894Z For more information about an error, try `rustc --explain E0308`.
2024-02-13T12:28:04.4676850Z ------------------------------------------
2024-02-13T12:28:04.4677292Z 
2024-02-13T12:28:04.4677304Z 
2024-02-13T12:28:04.4677834Z ---- [ui] tests/ui/const-generics/issues/issue-72352.rs#min stdout ----
2024-02-13T12:28:04.4678678Z diff of stderr:
2024-02-13T12:28:04.4678975Z 
2024-02-13T12:28:04.4679173Z 6	   |
2024-02-13T12:28:04.4679830Z 7	   = note: the only supported types are integers, `bool` and `char`
2024-02-13T12:28:04.4680630Z 8	
2024-02-13T12:28:04.4681198Z -	error: aborting due to 1 previous error
2024-02-13T12:28:04.4681889Z +	error[E0308]: mismatched types
2024-02-13T12:28:04.4682566Z +	  --> $DIR/issue-72352.rs:9:22
2024-02-13T12:28:04.4683136Z +	   |
2024-02-13T12:28:04.4683627Z +	LL |     F(CStr::from_ptr(ptr))
2024-02-13T12:28:04.4684453Z +	   |       -------------- ^^^ expected `*const u8`, found `*const i8`
2024-02-13T12:28:04.4685192Z +	   |       |
2024-02-13T12:28:04.4685778Z +	   |       arguments to this function are incorrect
2024-02-13T12:28:04.4686467Z +	   |
2024-02-13T12:28:04.4686981Z +	   = note: expected raw pointer `*const u8`
2024-02-13T12:28:04.4687723Z +	              found raw pointer `*const i8`
2024-02-13T12:28:04.4688447Z +	note: associated function defined here
2024-02-13T12:28:04.4689242Z +	  --> $SRC_DIR/core/src/ffi/c_str.rs:LL:COL
2024-02-13T12:28:04.4689900Z 10	
2024-02-13T12:28:04.4690363Z +	error[E0308]: mismatched types
2024-02-13T12:28:04.4691052Z +	  --> $DIR/issue-72352.rs:20:54
2024-02-13T12:28:04.4691628Z +	   |
2024-02-13T12:28:04.4692237Z +	LL |         unsafely_do_the_thing::<safely_do_the_thing>(ptr)
2024-02-13T12:28:04.4693312Z +	   |         -------------------------------------------- ^^^ expected `*const i8`, found `*const u8`
2024-02-13T12:28:04.4694137Z +	   |         |
2024-02-13T12:28:04.4694758Z +	   |         arguments to this function are incorrect
2024-02-13T12:28:04.4695447Z +	   |
2024-02-13T12:28:04.4695961Z +	   = note: expected raw pointer `*const i8`
2024-02-13T12:28:04.4696698Z +	              found raw pointer `*const u8`
2024-02-13T12:28:04.4697380Z +	note: function defined here
2024-02-13T12:28:04.4698039Z +	  --> $DIR/issue-72352.rs:7:11
2024-02-13T12:28:04.4698615Z +	   |
2024-02-13T12:28:04.4699542Z +	LL | unsafe fn unsafely_do_the_thing<const F: fn(&CStr) -> usize>(ptr: *const i8) -> usize {
2024-02-13T12:28:04.4701286Z +	   |           ^^^^^^^^^^^^^^^^^^^^^                              --------------
2024-02-13T12:28:04.4702167Z +	
2024-02-13T12:28:04.4702740Z +	error: aborting due to 3 previous errors
2024-02-13T12:28:04.4703412Z +	
2024-02-13T12:28:04.4704190Z +	For more information about this error, try `rustc --explain E0308`.
2024-02-13T12:28:04.4705020Z 11	
2024-02-13T12:28:04.4705268Z 
2024-02-13T12:28:04.4705280Z 
2024-02-13T12:28:04.4705610Z The actual stderr differed from the expected stderr.
2024-02-13T12:28:04.4707450Z Actual stderr saved to /checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/const-generics/issues/issue-72352.min/issue-72352.min.stderr
2024-02-13T12:28:04.4709224Z To update references, rerun the tests and pass the `--bless` flag
2024-02-13T12:28:04.4710583Z To only update this specific test, also pass `--test-args const-generics/issues/issue-72352.rs`
2024-02-13T12:28:04.4711437Z 
2024-02-13T12:28:04.4712152Z error in revision `min`: 1 errors occurred comparing output.
2024-02-13T12:28:04.4712997Z status: exit status: 1
2024-02-13T12:28:04.4721405Z command: RUSTC_ICE="0" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/const-generics/issues/issue-72352.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--cfg" "min" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/const-generics/issues/issue-72352.min" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/const-generics/issues/issue-72352.min/auxiliary"
2024-02-13T12:28:04.4729416Z stdout: none
2024-02-13T12:28:04.4730029Z --- stderr -------------------------------
2024-02-13T12:28:04.4730992Z error: using function pointers as const generic parameters is forbidden
2024-02-13T12:28:04.4732840Z ##[error]  --> /checkout/tests/ui/const-generics/issues/issue-72352.rs:7:42
2024-02-13T12:28:04.4734505Z    |
2024-02-13T12:28:04.4735446Z LL | unsafe fn unsafely_do_the_thing<const F: fn(&CStr) -> usize>(ptr: *const i8) -> usize {
2024-02-13T12:28:04.4736512Z    |                                          ^^^^^^^^^^^^^^^^^^
2024-02-13T12:28:04.4737171Z    |
2024-02-13T12:28:04.4737822Z    = note: the only supported types are integers, `bool` and `char`
2024-02-13T12:28:04.4738453Z 
2024-02-13T12:28:04.4738732Z error[E0308]: mismatched types
2024-02-13T12:28:04.4740014Z ##[error]  --> /checkout/tests/ui/const-generics/issues/issue-72352.rs:9:22
2024-02-13T12:28:04.4741656Z    |
2024-02-13T12:28:04.4742134Z LL |     F(CStr::from_ptr(ptr))
2024-02-13T12:28:04.4742957Z    |       -------------- ^^^ expected `*const u8`, found `*const i8`
2024-02-13T12:28:04.4743703Z    |       |
2024-02-13T12:28:04.4744257Z    |       arguments to this function are incorrect
2024-02-13T12:28:04.4744934Z    |
2024-02-13T12:28:04.4745437Z    = note: expected raw pointer `*const u8`
2024-02-13T12:28:04.4746163Z               found raw pointer `*const i8`
2024-02-13T12:28:04.4746864Z note: associated function defined here
2024-02-13T12:28:04.4747750Z   --> /rustc/FAKE_PREFIX/library/core/src/ffi/c_str.rs:263:25
2024-02-13T12:28:04.4748325Z 
2024-02-13T12:28:04.4748614Z error[E0308]: mismatched types
2024-02-13T12:28:04.4749920Z ##[error]  --> /checkout/tests/ui/const-generics/issues/issue-72352.rs:20:54
2024-02-13T12:28:04.4751590Z    |
2024-02-13T12:28:04.4752333Z LL |         unsafely_do_the_thing::<safely_do_the_thing>(ptr)
2024-02-13T12:28:04.4753436Z    |         -------------------------------------------- ^^^ expected `*const i8`, found `*const u8`
2024-02-13T12:28:04.4754574Z    |         |
2024-02-13T12:28:04.4755156Z    |         arguments to this function are incorrect
2024-02-13T12:28:04.4756289Z    |
2024-02-13T12:28:04.4756814Z    = note: expected raw pointer `*const i8`
2024-02-13T12:28:04.4757546Z               found raw pointer `*const u8`
2024-02-13T12:28:04.4758228Z note: function defined here
2024-02-13T12:28:04.4759111Z   --> /checkout/tests/ui/const-generics/issues/issue-72352.rs:7:11
2024-02-13T12:28:04.4759895Z    |
2024-02-13T12:28:04.4760806Z LL | unsafe fn unsafely_do_the_thing<const F: fn(&CStr) -> usize>(ptr: *const i8) -> usize {
2024-02-13T12:28:04.4762194Z    |           ^^^^^^^^^^^^^^^^^^^^^                              --------------
2024-02-13T12:28:04.4762746Z 
2024-02-13T12:28:04.4763072Z error: aborting due to 3 previous errors
2024-02-13T12:28:04.4763545Z 
2024-02-13T12:28:04.4764221Z For more information about this error, try `rustc --explain E0308`.
2024-02-13T12:28:04.4765220Z ------------------------------------------
2024-02-13T12:28:04.4765659Z 
2024-02-13T12:28:04.4765672Z 
2024-02-13T12:28:04.4765696Z 
2024-02-13T12:28:04.4765889Z failures:
2024-02-13T12:28:04.4766586Z     [ui] tests/ui/const-generics/issues/issue-72352.rs#full
2024-02-13T12:28:04.4767547Z     [ui] tests/ui/const-generics/issues/issue-72352.rs#min
2024-02-13T12:28:04.4768097Z 
2024-02-13T12:28:04.4768776Z test result: FAILED. 15965 passed; 2 failed; 184 ignored; 0 measured; 0 filtered out; finished in 178.97s

@oli-obk
Copy link
Contributor Author

oli-obk commented Feb 14, 2024

That's an error from a different PR: #120847 (see last commit)

oli-obk added a commit to oli-obk/rust that referenced this pull request Feb 15, 2024
Implement intrinsics with fallback bodies

fixes rust-lang#93145 (though we can port many more intrinsics)
cc rust-lang#63585

The way this works is that the backend logic for generating custom code for intrinsics has been made fallible. The only failure path is "this intrinsic is unknown". The `Instance` (that was `InstanceDef::Intrinsic`) then gets converted to `InstanceDef::Item`, which represents the fallback body. A regular function call to that body is then codegenned. This is currently implemented for

* codegen_ssa (so llvm and gcc)
* codegen_cranelift

other backends will need to adjust, but they can just keep doing what they were doing if they prefer (though adding new intrinsics to the compiler will then require them to implement them, instead of getting the fallback body).

cc `@scottmcm` `@WaffleLapkin`

### todo

* [ ] miri support
* [x] default intrinsic name to name of function instead of requiring it to be specified in attribute
* [x] make sure that the bodies are always available (must be collected for metadata)
@bors
Copy link
Contributor

bors commented Feb 16, 2024

⌛ Testing commit 164b9c3 with merge dfa88b3...

@bors
Copy link
Contributor

bors commented Feb 16, 2024

☀️ Test successful - checks-actions
Approved by: WaffleLapkin
Pushing dfa88b3 to master...

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (dfa88b3): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
2.2% [1.4%, 2.9%] 2
Regressions ❌
(secondary)
2.5% [2.5%, 2.5%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.2% [1.4%, 2.9%] 2

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 637.782s -> 637.11s (-0.11%)
Artifact size: 306.29 MiB -> 306.35 MiB (0.02%)

@oli-obk oli-obk deleted the intrinsics2.0 branch February 16, 2024 14:43
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 22, 2024
Add a scheme for moving away from `extern "rust-intrinsic"` entirely

All `rust-intrinsic`s can become free functions now, either with a fallback body, or with a dummy body and an attribute, requiring backends to actually implement the intrinsic.

This PR demonstrates the dummy-body scheme with the `vtable_size` intrinsic.

cc rust-lang#63585

follow-up to rust-lang#120500

MCP at rust-lang/compiler-team#720
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 22, 2024
Add a scheme for moving away from `extern "rust-intrinsic"` entirely

All `rust-intrinsic`s can become free functions now, either with a fallback body, or with a dummy body and an attribute, requiring backends to actually implement the intrinsic.

This PR demonstrates the dummy-body scheme with the `vtable_size` intrinsic.

cc rust-lang#63585

follow-up to rust-lang#120500

MCP at rust-lang/compiler-team#720
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 23, 2024
Add a scheme for moving away from `extern "rust-intrinsic"` entirely

All `rust-intrinsic`s can become free functions now, either with a fallback body, or with a dummy body and an attribute, requiring backends to actually implement the intrinsic.

This PR demonstrates the dummy-body scheme with the `vtable_size` intrinsic.

cc rust-lang#63585

follow-up to rust-lang#120500

MCP at rust-lang/compiler-team#720
celinval added a commit to model-checking/kani that referenced this pull request Feb 26, 2024
Upgrade toolchain to 2024-02-17. Relevant PR:

- rust-lang/rust#120500
- rust-lang/rust#100603

Fixes #87
Fixes #3034
Fixes #3037
flip1995 pushed a commit to flip1995/rust that referenced this pull request Feb 26, 2024
Implement intrinsics with fallback bodies

fixes rust-lang#93145 (though we can port many more intrinsics)
cc rust-lang#63585

The way this works is that the backend logic for generating custom code for intrinsics has been made fallible. The only failure path is "this intrinsic is unknown". The `Instance` (that was `InstanceDef::Intrinsic`) then gets converted to `InstanceDef::Item`, which represents the fallback body. A regular function call to that body is then codegenned. This is currently implemented for

* codegen_ssa (so llvm and gcc)
* codegen_cranelift

other backends will need to adjust, but they can just keep doing what they were doing if they prefer (though adding new intrinsics to the compiler will then require them to implement them, instead of getting the fallback body).

cc `@scottmcm` `@WaffleLapkin`

### todo

* [ ] miri support
* [x] default intrinsic name to name of function instead of requiring it to be specified in attribute
* [x] make sure that the bodies are always available (must be collected for metadata)
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 4, 2024
Add a scheme for moving away from `extern "rust-intrinsic"` entirely

All `rust-intrinsic`s can become free functions now, either with a fallback body, or with a dummy body and an attribute, requiring backends to actually implement the intrinsic.

This PR demonstrates the dummy-body scheme with the `vtable_size` intrinsic.

cc rust-lang#63585

follow-up to rust-lang#120500

MCP at rust-lang/compiler-team#720
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 5, 2024
Add a scheme for moving away from `extern "rust-intrinsic"` entirely

All `rust-intrinsic`s can become free functions now, either with a fallback body, or with a dummy body and an attribute, requiring backends to actually implement the intrinsic.

This PR demonstrates the dummy-body scheme with the `vtable_size` intrinsic.

cc rust-lang#63585

follow-up to rust-lang#120500

MCP at rust-lang/compiler-team#720
flip1995 pushed a commit to flip1995/rust that referenced this pull request Mar 7, 2024
Add a scheme for moving away from `extern "rust-intrinsic"` entirely

All `rust-intrinsic`s can become free functions now, either with a fallback body, or with a dummy body and an attribute, requiring backends to actually implement the intrinsic.

This PR demonstrates the dummy-body scheme with the `vtable_size` intrinsic.

cc rust-lang#63585

follow-up to rust-lang#120500

MCP at rust-lang/compiler-team#720
@NCGThompson
Copy link
Contributor

NCGThompson commented Apr 28, 2024

Turn is_val_statically_known into such an intrinsic to demonstrate. It is perfectly safe to call after all.

@oli-obk I'm trying to catch up, and I don't understand why is_val_statically_known doesn't need an unsafe marker. I do see that this is consistent with const_eval_select not having an unsafe marker, but I don't understand why that is allowed either.

While the function will never directly cause UB, it allows a library to violate assumptions that other libraries might depend upon.

Sorry, I just now realized that const_eval_select has only recently been marked safe again and has updated documentation.

@RalfJung
Copy link
Member

RalfJung commented Apr 28, 2024 via email

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. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wishlist: allow adding intrinsics in a way that doesn't break every backend