Skip to content

Commit a4bbb8d

Browse files
committed
use ty::Unevaluated<'tcx, ()> in type system
1 parent 7098c18 commit a4bbb8d

File tree

32 files changed

+301
-189
lines changed

32 files changed

+301
-189
lines changed

Cargo.lock

+46-38
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ dependencies = [
288288

289289
[[package]]
290290
name = "cargo"
291-
version = "0.66.0"
291+
version = "0.65.0"
292292
dependencies = [
293293
"anyhow",
294294
"atty",
@@ -299,6 +299,7 @@ dependencies = [
299299
"cargo-util",
300300
"clap",
301301
"crates-io",
302+
"crossbeam-utils",
302303
"curl",
303304
"curl-sys",
304305
"env_logger 0.9.0",
@@ -322,6 +323,7 @@ dependencies = [
322323
"libgit2-sys",
323324
"log",
324325
"memchr",
326+
"num_cpus",
325327
"opener",
326328
"openssl",
327329
"os_info",
@@ -381,7 +383,6 @@ dependencies = [
381383
name = "cargo-miri"
382384
version = "0.1.0"
383385
dependencies = [
384-
"cargo_metadata 0.15.0",
385386
"directories",
386387
"rustc-workspace-hack",
387388
"rustc_version",
@@ -430,7 +431,6 @@ dependencies = [
430431
"termcolor",
431432
"toml_edit",
432433
"url",
433-
"winapi",
434434
]
435435

436436
[[package]]
@@ -1003,6 +1003,16 @@ dependencies = [
10031003
"quote",
10041004
]
10051005

1006+
[[package]]
1007+
name = "ctor"
1008+
version = "0.1.22"
1009+
source = "registry+https://github.com/rust-lang/crates.io-index"
1010+
checksum = "f877be4f7c9f246b183111634f75baa039715e3f46ce860677d3b19a69fb229c"
1011+
dependencies = [
1012+
"quote",
1013+
"syn",
1014+
]
1015+
10061016
[[package]]
10071017
name = "curl"
10081018
version = "0.4.43"
@@ -1560,9 +1570,9 @@ dependencies = [
15601570

15611571
[[package]]
15621572
name = "git2"
1563-
version = "0.15.0"
1573+
version = "0.14.4"
15641574
source = "registry+https://github.com/rust-lang/crates.io-index"
1565-
checksum = "2994bee4a3a6a51eb90c218523be382fd7ea09b16380b9312e9dbe955ff7c7d1"
1575+
checksum = "d0155506aab710a86160ddb504a480d2964d7ab5b9e62419be69e0032bc5931c"
15661576
dependencies = [
15671577
"bitflags",
15681578
"libc",
@@ -1575,9 +1585,9 @@ dependencies = [
15751585

15761586
[[package]]
15771587
name = "git2-curl"
1578-
version = "0.16.0"
1588+
version = "0.15.0"
15791589
source = "registry+https://github.com/rust-lang/crates.io-index"
1580-
checksum = "ed817a00721e2f8037ba722e60358d4956dae9cca10315fc982f967907d3b0cd"
1590+
checksum = "1ee51709364c341fbb6fe2a385a290fb9196753bdde2fc45447d27cd31b11b13"
15811591
dependencies = [
15821592
"curl",
15831593
"git2",
@@ -1934,30 +1944,11 @@ dependencies = [
19341944
"rustc-std-workspace-core",
19351945
]
19361946

1937-
[[package]]
1938-
name = "libffi"
1939-
version = "3.0.1"
1940-
source = "registry+https://github.com/rust-lang/crates.io-index"
1941-
checksum = "1e454b3efb16fba3b17810ae5e41df02b649e564ab3c5a34b3b93ed07ad287e6"
1942-
dependencies = [
1943-
"libc",
1944-
"libffi-sys",
1945-
]
1946-
1947-
[[package]]
1948-
name = "libffi-sys"
1949-
version = "2.0.0"
1950-
source = "registry+https://github.com/rust-lang/crates.io-index"
1951-
checksum = "ab4106b7f09d7b87d021334d5618fac1dfcfb824d4c5fe111ff0074dfd242e15"
1952-
dependencies = [
1953-
"cc",
1954-
]
1955-
19561947
[[package]]
19571948
name = "libgit2-sys"
1958-
version = "0.14.0+1.5.0"
1949+
version = "0.13.4+1.4.2"
19591950
source = "registry+https://github.com/rust-lang/crates.io-index"
1960-
checksum = "47a00859c70c8a4f7218e6d1cc32875c4b55f6799445b842b0d8ed5e4c3d959b"
1951+
checksum = "d0fa6563431ede25f5cc7f6d803c6afbc1c5d3ad3d4925d12c882bf2b526f5d1"
19611952
dependencies = [
19621953
"cc",
19631954
"libc",
@@ -2247,8 +2238,6 @@ dependencies = [
22472238
"getrandom 0.2.0",
22482239
"lazy_static",
22492240
"libc",
2250-
"libffi",
2251-
"libloading",
22522241
"log",
22532242
"measureme",
22542243
"rand 0.8.5",
@@ -2421,6 +2410,15 @@ version = "6.0.0"
24212410
source = "registry+https://github.com/rust-lang/crates.io-index"
24222411
checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64"
24232412

2413+
[[package]]
2414+
name = "output_vt100"
2415+
version = "0.1.3"
2416+
source = "registry+https://github.com/rust-lang/crates.io-index"
2417+
checksum = "628223faebab4e3e40667ee0b2336d34a5b960ff60ea743ddfdbcf7770bcfb66"
2418+
dependencies = [
2419+
"winapi",
2420+
]
2421+
24242422
[[package]]
24252423
name = "owo-colors"
24262424
version = "3.4.0"
@@ -2662,6 +2660,18 @@ version = "0.1.1"
26622660
source = "registry+https://github.com/rust-lang/crates.io-index"
26632661
checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c"
26642662

2663+
[[package]]
2664+
name = "pretty_assertions"
2665+
version = "1.3.0"
2666+
source = "registry+https://github.com/rust-lang/crates.io-index"
2667+
checksum = "a25e9bcb20aa780fd0bb16b72403a9064d6b3f22f026946029acb941a50af755"
2668+
dependencies = [
2669+
"ctor",
2670+
"diff",
2671+
"output_vt100",
2672+
"yansi",
2673+
]
2674+
26652675
[[package]]
26662676
name = "pretty_env_logger"
26672677
version = "0.4.0"
@@ -4540,9 +4550,9 @@ checksum = "da73c8f77aebc0e40c300b93f0a5f1bece7a248a36eee287d4e095f35c7b7d6e"
45404550

45414551
[[package]]
45424552
name = "snapbox"
4543-
version = "0.3.3"
4553+
version = "0.2.10"
45444554
source = "registry+https://github.com/rust-lang/crates.io-index"
4545-
checksum = "44d199ccf8f606592df2d145db26f2aa45344e23c64b074cc5a4047f1d99b0f7"
4555+
checksum = "767a1d5da232b6959cd1bd5c9e8db8a7cce09c3038e89deedb49a549a2aefd93"
45464556
dependencies = [
45474557
"concolor",
45484558
"content_inspector",
@@ -4558,9 +4568,9 @@ dependencies = [
45584568

45594569
[[package]]
45604570
name = "snapbox-macros"
4561-
version = "0.3.0"
4571+
version = "0.2.1"
45624572
source = "registry+https://github.com/rust-lang/crates.io-index"
4563-
checksum = "8a253e6f894cfa440cba00600a249fa90869d8e0ec45ab274a456e043a0ce8f2"
4573+
checksum = "c01dea7e04cbb27ef4c86e9922184608185f7cd95c1763bc30d727cda4a5e930"
45644574

45654575
[[package]]
45664576
name = "socket2"
@@ -5039,16 +5049,14 @@ checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c"
50395049

50405050
[[package]]
50415051
name = "ui_test"
5042-
version = "0.3.1"
5043-
source = "registry+https://github.com/rust-lang/crates.io-index"
5044-
checksum = "7d1f546a5883ae78da735bba529ec1116661e2f73582f23920d994dc97da3a22"
5052+
version = "0.1.0"
50455053
dependencies = [
50465054
"cargo_metadata 0.15.0",
50475055
"color-eyre",
50485056
"colored",
50495057
"crossbeam",
5050-
"diff",
50515058
"lazy_static",
5059+
"pretty_assertions",
50525060
"regex",
50535061
"rustc_version",
50545062
"serde",

compiler/rustc_borrowck/src/type_check/mod.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -354,11 +354,13 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
354354
let tcx = self.tcx();
355355
let maybe_uneval = match constant.literal {
356356
ConstantKind::Ty(ct) => match ct.kind() {
357-
ty::ConstKind::Unevaluated(uv) => Some(uv),
357+
ty::ConstKind::Unevaluated(uv) => Some(uv.expand()),
358358
_ => None,
359359
},
360+
ConstantKind::Unevaluated(uv, _) => Some(uv),
360361
_ => None,
361362
};
363+
362364
if let Some(uv) = maybe_uneval {
363365
if let Some(promoted) = uv.promoted {
364366
let check_err = |verifier: &mut TypeVerifier<'a, 'b, 'tcx>,
@@ -1813,11 +1815,13 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
18131815
if let Operand::Constant(constant) = op {
18141816
let maybe_uneval = match constant.literal {
18151817
ConstantKind::Ty(ct) => match ct.kind() {
1816-
ty::ConstKind::Unevaluated(uv) => Some(uv),
1818+
ty::ConstKind::Unevaluated(uv) => Some(uv.expand()),
18171819
_ => None,
18181820
},
1821+
ConstantKind::Unevaluated(uv, _) => Some(uv),
18191822
_ => None,
18201823
};
1824+
18211825
if let Some(uv) = maybe_uneval {
18221826
if uv.promoted.is_none() {
18231827
let tcx = self.tcx();

compiler/rustc_codegen_cranelift/src/constant.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -124,26 +124,33 @@ pub(crate) fn codegen_constant<'tcx>(
124124
) -> CValue<'tcx> {
125125
let const_ = match fx.monomorphize(constant.literal) {
126126
ConstantKind::Ty(ct) => ct,
127-
ConstantKind::Val(val, ty) => return codegen_const_value(fx, val, ty),
128-
};
129-
let const_val = match const_.kind() {
130-
ConstKind::Value(valtree) => fx.tcx.valtree_to_const_val((const_.ty(), valtree)),
131-
ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted })
127+
ConstantKind::Unevaluated(mir::Unevaluated { def, substs, promoted })
132128
if fx.tcx.is_static(def.did) =>
133129
{
134130
assert!(substs.is_empty());
135131
assert!(promoted.is_none());
136132

137133
return codegen_static_ref(fx, def.did, fx.layout_of(const_.ty())).to_cvalue(fx);
138134
}
139-
ConstKind::Unevaluated(unevaluated) => {
135+
ConstantKind::Unevaluated(unevaluated) => {
140136
match fx.tcx.const_eval_resolve(ParamEnv::reveal_all(), unevaluated, None) {
141137
Ok(const_val) => const_val,
142138
Err(_) => {
143139
span_bug!(constant.span, "erroneous constant not captured by required_consts");
144140
}
145141
}
146142
}
143+
ConstantKind::Val(val, ty) => return codegen_const_value(fx, val, ty),
144+
};
145+
let const_val = match const_.kind() {
146+
ConstKind::Value(valtree) => fx.tcx.valtree_to_const_val((const_.ty(), valtree)),
147+
ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted })
148+
if fx.tcx.is_static(def.did) =>
149+
{
150+
assert!(substs.is_empty());
151+
assert!(promoted.is_none());
152+
return codegen_static_ref(fx, def.did, fx.layout_of(const_.ty())).to_cvalue(fx);
153+
}
147154
ConstKind::Param(_)
148155
| ConstKind::Infer(_)
149156
| ConstKind::Bound(_, _)

compiler/rustc_codegen_ssa/src/mir/constant.rs

+18-18
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,26 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
2525
constant: &mir::Constant<'tcx>,
2626
) -> Result<ConstValue<'tcx>, ErrorHandled> {
2727
let ct = self.monomorphize(constant.literal);
28-
let ct = match ct {
29-
mir::ConstantKind::Ty(ct) => ct,
28+
let uv = match ct {
29+
mir::ConstantKind::Ty(ct) => match ct.kind() {
30+
ty::ConstKind::Unevaluated(uv) => uv.expand(),
31+
ty::ConstKind::Value(val) => {
32+
return Ok(self.cx.tcx().valtree_to_const_val((ct.ty(), val)));
33+
}
34+
err => span_bug!(
35+
constant.span,
36+
"encountered bad ConstKind after monomorphizing: {:?}",
37+
err
38+
),
39+
},
40+
mir::ConstantKind::Unevaluated(uv, _) => uv,
3041
mir::ConstantKind::Val(val, _) => return Ok(val),
3142
};
32-
match ct.kind() {
33-
ty::ConstKind::Unevaluated(ct) => self
34-
.cx
35-
.tcx()
36-
.const_eval_resolve(ty::ParamEnv::reveal_all(), ct, None)
37-
.map_err(|err| {
38-
self.cx.tcx().sess.span_err(constant.span, "erroneous constant encountered");
39-
err
40-
}),
41-
ty::ConstKind::Value(val) => Ok(self.cx.tcx().valtree_to_const_val((ct.ty(), val))),
42-
err => span_bug!(
43-
constant.span,
44-
"encountered bad ConstKind after monomorphizing: {:?}",
45-
err
46-
),
47-
}
43+
44+
self.cx.tcx().const_eval_resolve(ty::ParamEnv::reveal_all(), uv, None).map_err(|err| {
45+
self.cx.tcx().sess.span_err(constant.span, "erroneous constant encountered");
46+
err
47+
})
4848
}
4949

5050
/// process constant containing SIMD shuffle indices

compiler/rustc_const_eval/src/interpret/operand.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
565565
}
566566
ty::ConstKind::Unevaluated(uv) => {
567567
let instance = self.resolve(uv.def, uv.substs)?;
568-
Ok(self.eval_to_allocation(GlobalId { instance, promoted: uv.promoted })?.into())
568+
Ok(self.eval_to_allocation(GlobalId { instance, promoted: None })?.into())
569569
}
570570
ty::ConstKind::Bound(..) | ty::ConstKind::Infer(..) => {
571571
span_bug!(self.cur_span(), "const_to_op: Unexpected ConstKind {:?}", c)
@@ -578,6 +578,16 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
578578
}
579579
}
580580

581+
/// Tries to evaluate an unevaluated constant from the MIR (and not the type-system).
582+
#[inline]
583+
pub fn uneval_to_op(
584+
&self,
585+
uneval: &ty::Unevaluated<'tcx>,
586+
) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> {
587+
let instance = self.resolve(uneval.def, uneval.substs)?;
588+
Ok(self.eval_to_allocation(GlobalId { instance, promoted: None })?.into())
589+
}
590+
581591
pub fn mir_const_to_op(
582592
&self,
583593
val: &mir::ConstantKind<'tcx>,
@@ -586,6 +596,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
586596
match val {
587597
mir::ConstantKind::Ty(ct) => self.const_to_op(*ct, layout),
588598
mir::ConstantKind::Val(val, ty) => self.const_val_to_op(*val, *ty, layout),
599+
mir::ConstantKind::Unevaluated(uv, _) => self.uneval_to_op(uv),
589600
}
590601
}
591602

compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -347,14 +347,15 @@ where
347347

348348
// Check the qualifs of the value of `const` items.
349349
if let Some(ct) = constant.literal.const_for_ty() {
350-
if let ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs: _, promoted }) = ct.kind()
350+
if let ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs: _, promoted: _ }) =
351+
ct.kind()
351352
{
352353
// Use qualifs of the type for the promoted. Promoteds in MIR body should be possible
353354
// only for `NeedsNonConstDrop` with precise drop checking. This is the only const
354355
// check performed after the promotion. Verify that with an assertion.
355-
assert!(promoted.is_none() || Q::ALLOW_PROMOTED);
356+
356357
// Don't peek inside trait associated constants.
357-
if promoted.is_none() && cx.tcx.trait_of_item(def.did).is_none() {
358+
if cx.tcx.trait_of_item(def.did).is_none() {
358359
let qualifs = if let Some((did, param_did)) = def.as_const_arg() {
359360
cx.tcx.at(constant.span).mir_const_qualif_const_arg((did, param_did))
360361
} else {

compiler/rustc_const_eval/src/transform/promote_consts.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -840,21 +840,15 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
840840
promoted.span = span;
841841
promoted.local_decls[RETURN_PLACE] = LocalDecl::new(ty, span);
842842
let substs = tcx.erase_regions(InternalSubsts::identity_for_item(tcx, def.did));
843-
let _const = tcx.mk_const(ty::ConstS {
844-
ty,
845-
kind: ty::ConstKind::Unevaluated(ty::Unevaluated {
846-
def,
847-
substs,
848-
promoted: Some(promoted_id),
849-
}),
850-
});
843+
let uneval = ty::Unevaluated { def, substs, promoted: Some(promoted_id) };
851844

852845
Operand::Constant(Box::new(Constant {
853846
span,
854847
user_ty: None,
855-
literal: ConstantKind::from_const(_const, tcx),
848+
literal: ConstantKind::Unevaluated(uneval, ty),
856849
}))
857850
};
851+
858852
let blocks = self.source.basic_blocks.as_mut();
859853
let local_decls = &mut self.source.local_decls;
860854
let loc = candidate.location;

0 commit comments

Comments
 (0)