-
-
Notifications
You must be signed in to change notification settings - Fork 15.5k
Add type-check to offload intrinisc calls #158693
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,6 +76,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |
| wbcx.visit_user_provided_sigs(); | ||
| wbcx.visit_coroutine_interior(); | ||
| wbcx.visit_transmutes(); | ||
| wbcx.visit_offloads(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Sa4dUs Can you try self.tcx here as well? |
||
| wbcx.visit_offset_of_container_types(); | ||
| wbcx.visit_potentially_region_dependent_goals(); | ||
|
|
||
|
|
@@ -544,6 +545,21 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { | |
| } | ||
| } | ||
|
|
||
| fn visit_offloads(&mut self) { | ||
| let tcx = self.tcx(); | ||
| let fcx_typeck_results = self.fcx.typeck_results.borrow(); | ||
| assert_eq!(fcx_typeck_results.hir_owner, self.typeck_results.hir_owner); | ||
| for &(kernel_ty, args_ty, ret_ty, hir_id) in | ||
| self.fcx.deferred_offload_checks.borrow().iter() | ||
| { | ||
| let span = tcx.hir_span(hir_id); | ||
| let kernel_ty = self.resolve(kernel_ty, &span); | ||
| let args_ty = self.resolve(args_ty, &span); | ||
| let ret_ty = self.resolve(ret_ty, &span); | ||
| self.typeck_results.offloads_to_check.push((kernel_ty, args_ty, ret_ty, hir_id)); | ||
| } | ||
| } | ||
|
|
||
| fn visit_opaque_types_next(&mut self) { | ||
| let mut fcx_typeck_results = self.fcx.typeck_results.borrow_mut(); | ||
| assert_eq!(fcx_typeck_results.hir_owner, self.typeck_results.hir_owner); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1123,6 +1123,11 @@ rustc_queries! { | |
| desc { "check transmute calls inside `{}`", tcx.def_path_str(key) } | ||
| } | ||
|
|
||
| /// Unsafety-check this `LocalDefId`. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment is probably copypaste leftover from the query below? Or does this actually check some unsafety, too? |
||
| query check_offloads(key: LocalDefId) -> Result<(), ErrorGuaranteed> { | ||
| desc { "check offload calls inside `{}`", tcx.def_path_str(key) } | ||
| } | ||
|
|
||
| /// Unsafety-check this `LocalDefId`. | ||
| query check_unsafety(key: LocalDefId) { | ||
| desc { "unsafety-checking `{}`", tcx.def_path_str(key) } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| //@ compile-flags: -Zunstable-options -Zoffload=Device -Clto=fat | ||
|
|
||
| #![feature(core_intrinsics)] | ||
|
|
||
| fn main() { | ||
| // args_ty is not a tuple | ||
| core::intrinsics::offload::<_, _, ()>(kernel_0, [1, 1, 1], [1, 1, 1], 0, 42); | ||
| //~^ ERROR `{integer}` is not a tuple | ||
| } | ||
|
|
||
| fn kernel_0() {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| error[E0277]: `{integer}` is not a tuple | ||
| --> $DIR/non_tuple_args.rs:7:36 | ||
| | | ||
| LL | core::intrinsics::offload::<_, _, ()>(kernel_0, [1, 1, 1], [1, 1, 1], 0, 42); | ||
| | ^ the nightly-only, unstable trait `std::marker::Tuple` is not implemented for `{integer}` | ||
| | | ||
| note: required by a bound in `offload` | ||
| --> $SRC_DIR/core/src/intrinsics/mod.rs:LL:COL | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
||
| For more information about this error, try `rustc --explain E0277`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| //@ compile-flags: -Zunstable-options -Zoffload=Device -Clto=fat | ||
|
|
||
| #![feature(core_intrinsics)] | ||
|
|
||
| fn main() { | ||
| // kernel_ty is not a function item | ||
| let not_fn = 42; | ||
| core::intrinsics::offload::<_, _, ()>(not_fn, [1, 1, 1], [1, 1, 1], 0, ()); | ||
| //~^ ERROR expected a function item for the offload kernel, found `i32` | ||
|
|
||
| // argument count mismatch | ||
| core::intrinsics::offload::<_, _, ()>(kernel_1, [1, 1, 1], [1, 1, 1], 0, ()); | ||
| //~^ ERROR offload kernel expects 1 arguments, but 0 arguments were provided | ||
|
|
||
| // argument type mismatch | ||
| core::intrinsics::offload::<_, _, ()>(kernel_1, [1, 1, 1], [1, 1, 1], 0, (42.0f64,)); | ||
| //~^ ERROR type mismatch in offload kernel argument 0: expected `f32`, found `f64` | ||
|
|
||
| // return type mismatch | ||
| let _: f64 = core::intrinsics::offload::<_, _, f64>(kernel_0, [1, 1, 1], [1, 1, 1], 0, ()); | ||
| //~^ ERROR offload kernel return type mismatch: kernel returns `()`, but offload call expects `f64` | ||
|
|
||
| // multiple argument type mismatch | ||
| core::intrinsics::offload::<_, _, ()>(kernel_2, [1, 1, 1], [1, 1, 1], 0, (42.0f64, 42.0f64)); | ||
| //~^ ERROR type mismatch in offload kernel argument 0: expected `f32`, found `f64` | ||
| //~| ERROR type mismatch in offload kernel argument 1: expected `f32`, found `f64` | ||
| } | ||
|
|
||
| fn kernel_0() {} | ||
| fn kernel_1(_x: f32) {} | ||
| fn kernel_2(_x: f32, _y: f32) {} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.