Skip to content

Commit 167b460

Browse files
committed
add a table to track user-provided signatures
1 parent a66dc8a commit 167b460

File tree

4 files changed

+59
-6
lines changed

4 files changed

+59
-6
lines changed

src/librustc/ty/context.rs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ use ty::query;
5050
use ty::steal::Steal;
5151
use ty::BindingMode;
5252
use ty::CanonicalTy;
53+
use ty::CanonicalPolyFnSig;
5354
use util::nodemap::{DefIdSet, ItemLocalMap};
5455
use util::nodemap::{FxHashMap, FxHashSet};
5556
use smallvec::SmallVec;
@@ -344,10 +345,6 @@ pub struct TypeckTables<'tcx> {
344345
/// belongs, but it may not exist if it's a tuple field (`tuple.0`).
345346
field_indices: ItemLocalMap<usize>,
346347

347-
/// Stores the canonicalized types provided by the user. See also
348-
/// `AscribeUserType` statement in MIR.
349-
user_provided_tys: ItemLocalMap<CanonicalTy<'tcx>>,
350-
351348
/// Stores the types for various nodes in the AST. Note that this table
352349
/// is not guaranteed to be populated until after typeck. See
353350
/// typeck::check::fn_ctxt for details.
@@ -359,6 +356,14 @@ pub struct TypeckTables<'tcx> {
359356
/// other items.
360357
node_substs: ItemLocalMap<&'tcx Substs<'tcx>>,
361358

359+
/// Stores the canonicalized types provided by the user. See also
360+
/// `AscribeUserType` statement in MIR.
361+
user_provided_tys: ItemLocalMap<CanonicalTy<'tcx>>,
362+
363+
/// Stores the canonicalized types provided by the user. See also
364+
/// `AscribeUserType` statement in MIR.
365+
user_provided_sigs: ItemLocalMap<CanonicalPolyFnSig<'tcx>>,
366+
362367
/// Stores the substitutions that the user explicitly gave (if any)
363368
/// attached to `id`. These will not include any inferred
364369
/// values. The canonical form is used to capture things like `_`
@@ -442,6 +447,7 @@ impl<'tcx> TypeckTables<'tcx> {
442447
type_dependent_defs: ItemLocalMap(),
443448
field_indices: ItemLocalMap(),
444449
user_provided_tys: ItemLocalMap(),
450+
user_provided_sigs: Default::default(),
445451
node_types: ItemLocalMap(),
446452
node_substs: ItemLocalMap(),
447453
user_substs: ItemLocalMap(),
@@ -513,6 +519,20 @@ impl<'tcx> TypeckTables<'tcx> {
513519
}
514520
}
515521

522+
pub fn user_provided_sigs(&self) -> LocalTableInContext<'_, CanonicalPolyFnSig<'tcx>> {
523+
LocalTableInContext {
524+
local_id_root: self.local_id_root,
525+
data: &self.user_provided_sigs
526+
}
527+
}
528+
529+
pub fn user_provided_sigs_mut(&mut self) -> LocalTableInContextMut<'_, CanonicalPolyFnSig<'tcx>> {
530+
LocalTableInContextMut {
531+
local_id_root: self.local_id_root,
532+
data: &mut self.user_provided_sigs
533+
}
534+
}
535+
516536
pub fn node_types(&self) -> LocalTableInContext<'_, Ty<'tcx>> {
517537
LocalTableInContext {
518538
local_id_root: self.local_id_root,
@@ -748,6 +768,7 @@ impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for TypeckTables<'gcx> {
748768
ref type_dependent_defs,
749769
ref field_indices,
750770
ref user_provided_tys,
771+
ref user_provided_sigs,
751772
ref node_types,
752773
ref node_substs,
753774
ref user_substs,
@@ -771,6 +792,7 @@ impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for TypeckTables<'gcx> {
771792
type_dependent_defs.hash_stable(hcx, hasher);
772793
field_indices.hash_stable(hcx, hasher);
773794
user_provided_tys.hash_stable(hcx, hasher);
795+
user_provided_sigs.hash_stable(hcx, hasher);
774796
node_types.hash_stable(hcx, hasher);
775797
node_substs.hash_stable(hcx, hasher);
776798
user_substs.hash_stable(hcx, hasher);

src/librustc/ty/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ use rustc_data_structures::stable_hasher::{StableHasher, StableHasherResult,
6464
use hir;
6565

6666
pub use self::sty::{Binder, BoundTy, BoundTyIndex, DebruijnIndex, INNERMOST};
67-
pub use self::sty::{FnSig, GenSig, PolyFnSig, PolyGenSig};
67+
pub use self::sty::{FnSig, GenSig, CanonicalPolyFnSig, PolyFnSig, PolyGenSig};
6868
pub use self::sty::{InferTy, ParamTy, ProjectionTy, ExistentialPredicate};
6969
pub use self::sty::{ClosureSubsts, GeneratorSubsts, UpvarSubsts, TypeAndMut};
7070
pub use self::sty::{TraitRef, TyKind, PolyTraitRef};

src/librustc/ty/sty.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//! This module contains TyKind and its major components
1212
1313
use hir::def_id::DefId;
14-
14+
use infer::canonical::Canonical;
1515
use mir::interpret::ConstValue;
1616
use middle::region;
1717
use polonius_engine::Atom;
@@ -980,6 +980,9 @@ impl<'tcx> PolyFnSig<'tcx> {
980980
}
981981
}
982982

983+
pub type CanonicalPolyFnSig<'tcx> = Canonical<'tcx, Binder<FnSig<'tcx>>>;
984+
985+
983986
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
984987
pub struct ParamTy {
985988
pub idx: u32,

src/librustc_typeck/check/writeback.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
5252
wbcx.visit_cast_types();
5353
wbcx.visit_free_region_map();
5454
wbcx.visit_user_provided_tys();
55+
wbcx.visit_user_provided_sigs();
5556

5657
let used_trait_imports = mem::replace(
5758
&mut self.tables.borrow_mut().used_trait_imports,
@@ -388,6 +389,33 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
388389
}
389390
}
390391

392+
fn visit_user_provided_sigs(&mut self) {
393+
let fcx_tables = self.fcx.tables.borrow();
394+
debug_assert_eq!(fcx_tables.local_id_root, self.tables.local_id_root);
395+
let common_local_id_root = fcx_tables.local_id_root.unwrap();
396+
397+
for (&local_id, c_sig) in fcx_tables.user_provided_sigs().iter() {
398+
let hir_id = hir::HirId {
399+
owner: common_local_id_root.index,
400+
local_id,
401+
};
402+
403+
let c_sig = if let Some(c_sig) = self.tcx().lift_to_global(c_sig) {
404+
c_sig
405+
} else {
406+
span_bug!(
407+
hir_id.to_span(&self.fcx.tcx),
408+
"writeback: `{:?}` missing from the global type context",
409+
c_sig
410+
);
411+
};
412+
413+
self.tables
414+
.user_provided_sigs_mut()
415+
.insert(hir_id, c_sig.clone());
416+
}
417+
}
418+
391419
fn visit_opaque_types(&mut self, span: Span) {
392420
for (&def_id, opaque_defn) in self.fcx.opaque_types.borrow().iter() {
393421
let node_id = self.tcx().hir.as_local_node_id(def_id).unwrap();

0 commit comments

Comments
 (0)