Skip to content

Commit

Permalink
make intrinsic query legal for any DefId
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Mar 4, 2024
1 parent bf5fc6e commit c04f0ca
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
14 changes: 6 additions & 8 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1051,17 +1051,15 @@ fn should_encode_mir(
// Coroutines require optimized MIR to compute layout.
DefKind::Closure if tcx.is_coroutine(def_id.to_def_id()) => (false, true),
// Full-fledged functions + closures
def_kind @ (DefKind::AssocFn | DefKind::Fn | DefKind::Closure) => {
DefKind::AssocFn | DefKind::Fn | DefKind::Closure => {
let generics = tcx.generics_of(def_id);
let mut opt = tcx.sess.opts.unstable_opts.always_encode_mir
|| (tcx.sess.opts.output_types.should_codegen()
&& reachable_set.contains(&def_id)
&& (generics.requires_monomorphization(tcx)
|| tcx.cross_crate_inlinable(def_id)));
if matches!(def_kind, DefKind::AssocFn | DefKind::Fn) {
if let Some(intrinsic) = tcx.intrinsic(def_id) {
opt &= !intrinsic.must_be_overridden;
}
if let Some(intrinsic) = tcx.intrinsic(def_id) {
opt &= !intrinsic.must_be_overridden;
}
// The function has a `const` modifier or is in a `#[const_trait]`.
let is_const_fn = tcx.is_const_fn_raw(def_id.to_def_id())
Expand Down Expand Up @@ -1414,9 +1412,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
if let DefKind::Fn | DefKind::AssocFn = def_kind {
self.tables.asyncness.set_some(def_id.index, tcx.asyncness(def_id));
record_array!(self.tables.fn_arg_names[def_id] <- tcx.fn_arg_names(def_id));
if let Some(name) = tcx.intrinsic(def_id) {
record!(self.tables.intrinsic[def_id] <- name);
}
}
if let Some(name) = tcx.intrinsic(def_id) {
record!(self.tables.intrinsic[def_id] <- name);
}
if let DefKind::TyParam = def_kind {
let default = self.tcx.object_lifetime_default(def_id);
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_middle/src/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1643,6 +1643,10 @@ pub fn is_doc_notable_trait(tcx: TyCtxt<'_>, def_id: DefId) -> bool {

/// Determines whether an item is an intrinsic (which may be via Abi or via the `rustc_intrinsic` attribute)
pub fn intrinsic(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<ty::IntrinsicDef> {
match tcx.def_kind(def_id) {
DefKind::Fn | DefKind::AssocFn => {}
_ => return None,
}
if matches!(tcx.fn_sig(def_id).skip_binder().abi(), Abi::RustIntrinsic)
|| tcx.has_attr(def_id, sym::rustc_intrinsic)
{
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_ty_utils/src/instance.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use rustc_errors::ErrorGuaranteed;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::DefId;
use rustc_infer::infer::TyCtxtInferExt;
use rustc_middle::query::Providers;
Expand Down Expand Up @@ -28,8 +27,7 @@ fn resolve_instance<'tcx>(
tcx.normalize_erasing_regions(param_env, args),
)
} else {
let def = if matches!(tcx.def_kind(def_id), DefKind::Fn) && tcx.intrinsic(def_id).is_some()
{
let def = if tcx.intrinsic(def_id).is_some() {
debug!(" => intrinsic");
ty::InstanceDef::Intrinsic(def_id)
} else if Some(def_id) == tcx.lang_items().drop_in_place_fn() {
Expand Down

0 comments on commit c04f0ca

Please sign in to comment.