-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Optimize integral pattern matching #65089
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
Changes from all commits
9a1a3b9
62ea39a
a69e0e0
5515a97
2a3a544
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 |
---|---|---|
|
@@ -13,7 +13,7 @@ use rustc_macros::HashStable; | |
use crate::ty::subst::{InternalSubsts, Subst, SubstsRef, GenericArg, GenericArgKind}; | ||
use crate::ty::{self, AdtDef, Discr, DefIdTree, TypeFlags, Ty, TyCtxt, TypeFoldable}; | ||
use crate::ty::{List, TyS, ParamEnvAnd, ParamEnv}; | ||
use crate::ty::layout::{Size, Integer, IntegerExt, VariantIdx}; | ||
use crate::ty::layout::VariantIdx; | ||
use crate::util::captures::Captures; | ||
use crate::mir::interpret::{Scalar, GlobalId}; | ||
|
||
|
@@ -24,7 +24,6 @@ use std::marker::PhantomData; | |
use std::ops::Range; | ||
use rustc_target::spec::abi; | ||
use syntax::ast::{self, Ident}; | ||
use syntax::attr::{SignedInt, UnsignedInt}; | ||
use syntax::symbol::{kw, InternedString}; | ||
|
||
use self::InferTy::*; | ||
|
@@ -2299,20 +2298,7 @@ impl<'tcx> Const<'tcx> { | |
ty: Ty<'tcx>, | ||
) -> Option<u128> { | ||
assert_eq!(self.ty, ty); | ||
// This is purely an optimization -- layout_of is a pretty expensive operation, | ||
// but if we can determine the size without calling it, we don't need all that complexity | ||
// (hashing, caching, etc.). As such, try to skip it. | ||
let size = match ty.kind { | ||
ty::Bool => Size::from_bytes(1), | ||
ty::Char => Size::from_bytes(4), | ||
ty::Int(ity) => { | ||
Integer::from_attr(&tcx, SignedInt(ity)).size() | ||
} | ||
ty::Uint(uty) => { | ||
Integer::from_attr(&tcx, UnsignedInt(uty)).size() | ||
} | ||
_ => tcx.layout_of(param_env.with_reveal_all().and(ty)).ok()?.size, | ||
}; | ||
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. A quick grep shows a few more sites that call 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. yea, this could just be a method on |
||
let size = tcx.layout_of(param_env.with_reveal_all().and(ty)).ok()?.size; | ||
// if `ty` does not depend on generic parameters, use an empty param_env | ||
self.eval(tcx, param_env).val.try_to_bits(size) | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.