Skip to content

Commit 01d0dc8

Browse files
committed
introduce infcx.at(..).normalize(..) operation [VIC]
It is backed by the new `normalize_projection_ty` query, which uses canonicalization.
1 parent 7f495d9 commit 01d0dc8

File tree

24 files changed

+716
-18
lines changed

24 files changed

+716
-18
lines changed

src/Cargo.lock

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/librustc/dep_graph/dep_node.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,17 @@
6060
//! user of the `DepNode` API of having to know how to compute the expected
6161
//! fingerprint for a given set of node parameters.
6262
63+
use ich::{Fingerprint, StableHashingContext};
64+
use infer::canonical::Canonical;
6365
use hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX};
6466
use hir::map::DefPathHash;
6567
use hir::{HirId, ItemLocalId};
66-
67-
use ich::Fingerprint;
68-
use ty::{TyCtxt, Instance, InstanceDef, ParamEnv, ParamEnvAnd, PolyTraitRef, Ty};
69-
use ty::subst::Substs;
7068
use rustc_data_structures::stable_hasher::{StableHasher, HashStable};
71-
use ich::StableHashingContext;
7269
use std::fmt;
7370
use std::hash::Hash;
7471
use syntax_pos::symbol::InternedString;
72+
use ty::{self, TyCtxt, Instance, InstanceDef, ParamEnv, ParamEnvAnd, PolyTraitRef, Ty};
73+
use ty::subst::Substs;
7574

7675
// erase!() just makes tokens go away. It's used to specify which macro argument
7776
// is repeated (i.e. which sub-expression of the macro we are in) but don't need
@@ -633,6 +632,8 @@ define_dep_nodes!( <'tcx>
633632
[] CompileCodegenUnit(InternedString),
634633
[input] OutputFilenames,
635634
[anon] NormalizeTy,
635+
[] NormalizeProjectionTy { ty: &'tcx Canonical<ParamEnvAnd<'tcx, ty::ProjectionTy<'tcx>>> },
636+
636637
// We use this for most things when incr. comp. is turned off.
637638
[] Null,
638639

src/librustc/infer/at.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ use super::*;
4040
use ty::relate::{Relate, TypeRelation};
4141

4242
pub struct At<'a, 'gcx: 'tcx, 'tcx: 'a> {
43-
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
44-
cause: &'a ObligationCause<'tcx>,
45-
param_env: ty::ParamEnv<'tcx>,
43+
pub infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
44+
pub cause: &'a ObligationCause<'tcx>,
45+
pub param_env: ty::ParamEnv<'tcx>,
4646
}
4747

4848
pub struct Trace<'a, 'gcx: 'tcx, 'tcx: 'a> {

src/librustc/infer/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ pub mod type_variable;
6969
pub mod unify_key;
7070

7171
#[must_use]
72+
#[derive(Debug)]
7273
pub struct InferOk<'tcx, T> {
7374
pub value: T,
7475
pub obligations: PredicateObligations<'tcx>,
@@ -1256,6 +1257,16 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
12561257
self.borrow_region_constraints().take_and_reset_data()
12571258
}
12581259

1260+
/// Gives temporary access to the region constraint data.
1261+
#[allow(non_camel_case_types)] // bug with impl trait
1262+
pub fn with_region_constraints<R>(
1263+
&self,
1264+
op: impl FnOnce(&RegionConstraintData<'tcx>) -> R,
1265+
) -> R {
1266+
let region_constraints = self.borrow_region_constraints();
1267+
op(region_constraints.data())
1268+
}
1269+
12591270
/// Takes ownership of the list of variable regions. This implies
12601271
/// that all the region constriants have already been taken, and
12611272
/// hence that `resolve_regions_and_report_errors` can never be

src/librustc/infer/outlives/obligations.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,16 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
9999
.push((body_id, obligation));
100100
}
101101

102+
/// Trait queries just want to pass back type obligations "as is"
103+
pub fn take_registered_region_obligations(
104+
&self,
105+
) -> Vec<(ast::NodeId, RegionObligation<'tcx>)> {
106+
::std::mem::replace(
107+
&mut *self.region_obligations.borrow_mut(),
108+
vec![],
109+
)
110+
}
111+
102112
/// Process the region obligations that must be proven (during
103113
/// `regionck`) for the given `body_id`, given information about
104114
/// the region bounds in scope and so forth. This function must be

src/librustc/infer/region_constraints/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,10 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
350350
mem::replace(data, RegionConstraintData::default())
351351
}
352352

353+
pub fn data(&self) -> &RegionConstraintData<'tcx> {
354+
&self.data
355+
}
356+
353357
fn in_snapshot(&self) -> bool {
354358
!self.undo_log.is_empty()
355359
}

src/librustc/session/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ pub struct PerfStats {
162162
pub decode_def_path_tables_time: Cell<Duration>,
163163
/// Total number of values canonicalized queries constructed.
164164
pub queries_canonicalized: Cell<usize>,
165+
/// Number of times we canonicalized a value and found that the
166+
/// result had already been canonicalized.
167+
pub canonicalized_values_allocated: Cell<usize>,
168+
/// Number of times this query is invoked.
169+
pub normalize_projection_ty: Cell<usize>,
165170
}
166171

167172
/// Enum to support dispatch of one-time diagnostics (in Session.diag_once)
@@ -768,6 +773,10 @@ impl Session {
768773
duration_to_secs_str(self.perf_stats.decode_def_path_tables_time.get()));
769774
println!("Total queries canonicalized: {}",
770775
self.perf_stats.queries_canonicalized.get());
776+
println!("Total canonical values interned: {}",
777+
self.perf_stats.canonicalized_values_allocated.get());
778+
println!("normalize_projection_ty: {}",
779+
self.perf_stats.normalize_projection_ty.get());
771780
}
772781

773782
/// We want to know if we're allowed to do an optimization for crate foo from -z fuel=foo=n.
@@ -1031,6 +1040,8 @@ pub fn build_session_(sopts: config::Options,
10311040
symbol_hash_time: Cell::new(Duration::from_secs(0)),
10321041
decode_def_path_tables_time: Cell::new(Duration::from_secs(0)),
10331042
queries_canonicalized: Cell::new(0),
1043+
canonicalized_values_allocated: Cell::new(0),
1044+
normalize_projection_ty: Cell::new(0),
10341045
},
10351046
code_stats: RefCell::new(CodeStats::new()),
10361047
optimization_fuel_crate,

src/librustc/traits/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ mod structural_impls;
6060
pub mod trans;
6161
mod util;
6262

63+
pub mod query;
64+
6365
// Whether to enable bug compatibility with issue #43355
6466
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
6567
pub enum IntercrateMode {

src/librustc/traits/query/mod.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
//! Experimental types for the trait query interface. The methods
12+
//! defined in this module are all based on **canonicalization**,
13+
//! which makes a canonical query by replacing unbound inference
14+
//! variables and regions, so that results can be reused more broadly.
15+
//! The providers for the queries defined here can be found in
16+
//! `librustc_traits`.
17+
18+
pub mod normalize;
19+
20+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
21+
pub struct NoSolution;
22+
23+
pub type Fallible<T> = Result<T, NoSolution>;
24+
25+
impl_stable_hash_for!(struct NoSolution { });

0 commit comments

Comments
 (0)