-
Notifications
You must be signed in to change notification settings - Fork 13k
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
reimplement ~const Trait
bounds via a fourth kind of generic param
#101900
Changes from all commits
37f6e29
8f57f7a
1cd3a64
57ec943
230f0ad
e523a95
23f8475
82f2130
6d5c679
490c462
200b34d
5da0201
93b00a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ use rustc_hir::{LangItem, CRATE_HIR_ID}; | |
use rustc_middle::mir; | ||
use rustc_middle::mir::interpret::PointerArithmetic; | ||
use rustc_middle::ty::layout::FnAbiOf; | ||
use rustc_middle::ty::{self, Ty, TyCtxt}; | ||
use rustc_middle::ty::{self, Instance, Ty, TyCtxt}; | ||
use rustc_session::lint::builtin::INVALID_ALIGNMENT; | ||
use std::borrow::Borrow; | ||
use std::hash::Hash; | ||
|
@@ -202,14 +202,16 @@ impl<'mir, 'tcx: 'mir> CompileTimeEvalContext<'mir, 'tcx> { | |
} else if Some(def_id) == self.tcx.lang_items().panic_fmt() { | ||
// For panic_fmt, call const_panic_fmt instead. | ||
let const_def_id = self.tcx.require_lang_item(LangItem::ConstPanicFmt, None); | ||
let new_instance = ty::Instance::resolve( | ||
*self.tcx, | ||
ty::ParamEnv::reveal_all(), | ||
const_def_id, | ||
instance.substs, | ||
) | ||
.unwrap() | ||
.unwrap(); | ||
let substs = if self.tcx.effects() { | ||
self.tcx | ||
.mk_substs(instance.substs.iter().chain([self.tcx.effects.always_const.into()])) | ||
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.
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. I explicitly named it this way (it would be |
||
} else { | ||
instance.substs | ||
}; | ||
let new_instance = | ||
ty::Instance::resolve(*self.tcx, ty::ParamEnv::reveal_all(), const_def_id, substs) | ||
.unwrap() | ||
.unwrap(); | ||
|
||
return Ok(Some(new_instance)); | ||
} else if Some(def_id) == self.tcx.lang_items().align_offset_fn() { | ||
|
@@ -425,8 +427,6 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir, | |
|
||
if new_instance != instance { | ||
// We call another const fn instead. | ||
// However, we return the *original* instance to make backtraces work out | ||
// (and we hope this does not confuse the FnAbi checks too much). | ||
return Ok(Self::find_mir_or_eval_fn( | ||
ecx, | ||
new_instance, | ||
|
@@ -436,7 +436,11 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir, | |
ret, | ||
_unwind, | ||
)? | ||
.map(|(body, _instance)| (body, instance))); | ||
.map(|(body, new_instance)| { | ||
// However, we return the *original* instance to make backtraces work out | ||
// (and we hope this does not confuse the FnAbi checks too much). | ||
(body, Instance::new(instance.def_id(), new_instance.substs)) | ||
})); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -384,6 +384,8 @@ declare_features! ( | |||||
(active, doc_masked, "1.21.0", Some(44027), None), | ||||||
/// Allows `dyn* Trait` objects. | ||||||
(incomplete, dyn_star, "1.65.0", Some(102425), None), | ||||||
// Uses generic effect parameters for ~const bounds | ||||||
(active, effects, "1.62.0", Some(102090), None), | ||||||
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.
Suggested change
? |
||||||
/// Allows `X..Y` patterns. | ||||||
(active, exclusive_range_pattern, "1.11.0", Some(37854), None), | ||||||
/// Allows exhaustive pattern matching on types that contain uninhabited types. | ||||||
|
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.
or something like that?
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.
why are u using
mk_trait_ref
instead ofmk_trait_ref_with_effect
here?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.
Hmm... I do get the naming confusing between this not returning the effect kind, but a value of the host effect... I'll try out a few namings
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.
for diagnostics I opted to just always fall back to host-on. Many times we don't have any context information available anyway