Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.

Some rustups #227

Merged
merged 8 commits into from
Oct 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -27,13 +27,13 @@ repository and compiled from source or installed from
of the nightly toolchain is supported at any given time.

<!-- NOTE: Keep in sync with nightly date on rust-toolchain. -->
It's recommended to use `nightly-2021-07-23` toolchain.
You can install it by using `rustup install nightly-2021-07-23` if you already have rustup.
It's recommended to use `nightly-2021-09-30` toolchain.
You can install it by using `rustup install nightly-2021-09-30` if you already have rustup.
Then you can do:

```sh
$ rustup component add rustc-dev llvm-tools-preview --toolchain nightly-2021-07-23
$ cargo +nightly-2021-07-23 install --git https://github.com/rust-lang/rust-semverver
$ rustup component add rustc-dev llvm-tools-preview --toolchain nightly-2021-09-30
$ cargo +nightly-2021-09-30 install --git https://github.com/rust-lang/rust-semverver
```

You'd also need `cmake` for some dependencies, and a few common libraries (if you hit
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# NOTE: Keep in sync with nightly date on README
[toolchain]
channel = "nightly-2021-07-23"
channel = "nightly-2021-09-30"
components = ["llvm-tools-preview", "rustc-dev"]
24 changes: 12 additions & 12 deletions src/changes.rs
Original file line number Diff line number Diff line change
@@ -1230,7 +1230,7 @@ pub mod tests {
use std::cmp::{max, min};

use rustc_span::hygiene::SyntaxContext;
use rustc_span::symbol::Interner;
use rustc_span::symbol::sym;
use rustc_span::BytePos;

/// A wrapper for `Span` that can be randomly generated.
@@ -1239,7 +1239,12 @@ pub mod tests {

impl Span_ {
pub fn inner(self) -> Span {
Span::new(BytePos(self.0), BytePos(self.1), SyntaxContext::root())
Span::new(
BytePos(self.0),
BytePos(self.1),
SyntaxContext::root(),
None,
)
}
}

@@ -1460,8 +1465,7 @@ pub mod tests {
output: bool,
changes: Vec<(ChangeType_, Option<Span_>)>,
) -> Change<'a> {
let mut interner = Interner::default();
let mut change = Change::new(Name::Symbol(RSymbol(interner.intern("test"))), s1, output);
let mut change = Change::new(Name::Symbol(RSymbol(sym::test)), s1, output);

for (type_, span) in changes {
change.insert(type_.inner(), span.map(|s| s.inner()));
@@ -1475,8 +1479,7 @@ pub mod tests {

/// Construct `PathChange`s from things that can be generated.
fn build_path_change(s1: Span, spans: Vec<(bool, Span)>) -> PathChange {
let mut interner = Interner::default();
let mut change = PathChange::new(interner.intern("test"), s1);
let mut change = PathChange::new(sym::test, s1);

for (add, span) in spans {
change.insert(span, add);
@@ -1546,8 +1549,7 @@ pub mod tests {
rustc_span::create_default_session_globals_then(|| {
let mut set = ChangeSet::default();

let mut interner = Interner::default();
let name = interner.intern("test");
let name = sym::test;

let max = changes
.iter()
@@ -1579,8 +1581,7 @@ pub mod tests {
rustc_span::create_default_session_globals_then(|| {
let mut set = ChangeSet::default();

let mut interner = Interner::default();
let name = interner.intern("test");
let name = sym::test;

let max = changes
.iter()
@@ -1614,8 +1615,7 @@ pub mod tests {
rustc_span::create_default_session_globals_then(|| {
let mut set = ChangeSet::default();

let mut interner = Interner::default();
let name = interner.intern("test");
let name = sym::test;

let max = pchanges
.iter()
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -7,10 +7,10 @@
#![allow(clippy::unnested_or_patterns)]
#![deny(warnings)]

extern crate rustc_hir; // Requires `rustup component add rustc-dev`
extern crate rustc_const_eval; // Requires `rustup component add rustc-dev`
extern crate rustc_hir;
extern crate rustc_infer;
extern crate rustc_middle;
extern crate rustc_mir;
extern crate rustc_session;
extern crate rustc_span;
extern crate rustc_trait_selection;
12 changes: 5 additions & 7 deletions src/mapping.rs
Original file line number Diff line number Diff line change
@@ -325,7 +325,7 @@ impl IdMapping {
}

/// An export that could be missing from one of the crate versions.
type OptionalExport = Option<Export<HirId>>;
type OptionalExport = Option<Export>;

/// A mapping from names to pairs of old and new exports.
///
@@ -343,11 +343,11 @@ pub struct NameMapping {

impl NameMapping {
/// Insert a single export in the appropriate map, at the appropriate position.
fn insert(&mut self, item: Export<HirId>, old: bool) {
fn insert(&mut self, item: Export, old: bool) {
use rustc_hir::def::DefKind::*;
use rustc_hir::def::Res::*;

let map = match item.res {
let map = match item.res.expect_non_local::<HirId>() {
Def(kind, _) => match kind {
Mod |
Struct |
@@ -396,7 +396,7 @@ impl NameMapping {
}

/// Add all items from two vectors of old/new exports.
pub fn add(&mut self, old_items: Vec<Export<HirId>>, new_items: Vec<Export<HirId>>) {
pub fn add(&mut self, old_items: Vec<Export>, new_items: Vec<Export>) {
for item in old_items {
self.insert(item, true);
}
@@ -407,9 +407,7 @@ impl NameMapping {
}

/// Drain the item pairs being stored.
pub fn drain(
&mut self,
) -> impl Iterator<Item = (Option<Export<HirId>>, Option<Export<HirId>>)> + '_ {
pub fn drain(&mut self) -> impl Iterator<Item = (Option<Export>, Option<Export>)> + '_ {
self.type_map
.drain()
.chain(self.value_map.drain())
174 changes: 88 additions & 86 deletions src/translate.rs
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ use rustc_infer::infer::InferCtxt;
use rustc_middle::ty::{
fold::{BottomUpFolder, TypeFoldable, TypeFolder},
subst::{GenericArg, InternalSubsts, SubstsRef},
GenericParamDefKind, ParamEnv, Predicate, Region, TraitRef, Ty, TyCtxt,
GenericParamDefKind, ParamEnv, Predicate, Region, TraitRef, Ty, TyCtxt, Unevaluated,
};
use std::collections::HashMap;

@@ -376,97 +376,99 @@ impl<'a, 'tcx> TranslationContext<'a, 'tcx> {
predicate: Predicate<'tcx>,
) -> Option<Predicate<'tcx>> {
use rustc_middle::ty::{
OutlivesPredicate, PredicateKind, ProjectionPredicate, ProjectionTy, SubtypePredicate,
ToPredicate, TraitPredicate, WithOptConstParam,
self, CoercePredicate, OutlivesPredicate, PredicateKind, ProjectionPredicate,
ProjectionTy, SubtypePredicate, ToPredicate, TraitPredicate, WithOptConstParam,
};

Some(
match predicate.kind().skip_binder() {
PredicateKind::Trait(pred, constness) => PredicateKind::Trait(
if let Some((target_def_id, target_substs)) = self.translate_orig_substs(
index_map,
pred.trait_ref.def_id,
pred.trait_ref.substs,
) {
TraitPredicate {
trait_ref: TraitRef {
def_id: target_def_id,
substs: target_substs,
},
}
} else {
return None;
},
constness,
),
PredicateKind::RegionOutlives(pred) => PredicateKind::RegionOutlives({
let l = self.translate_region(pred.0);
let r = self.translate_region(pred.1);
OutlivesPredicate(l, r)
}),
PredicateKind::TypeOutlives(pred) => PredicateKind::TypeOutlives({
let l = self.translate(index_map, pred.0);
let r = self.translate_region(pred.1);
OutlivesPredicate(l, r)
}),
PredicateKind::Projection(pred) => PredicateKind::Projection(
if let Some((target_def_id, target_substs)) = self.translate_orig_substs(
index_map,
pred.projection_ty.item_def_id,
pred.projection_ty.substs,
) {
ProjectionPredicate {
projection_ty: ProjectionTy {
substs: target_substs,
item_def_id: target_def_id,
},
ty: self.translate(index_map, pred.ty),
}
} else {
return None;
},
),
PredicateKind::WellFormed(ty) => {
PredicateKind::WellFormed(self.translate(index_map, ty))
}
PredicateKind::ObjectSafe(did) => {
PredicateKind::ObjectSafe(self.translate_orig(did))
}
PredicateKind::ClosureKind(did, substs, kind) => PredicateKind::ClosureKind(
self.translate_orig(did),
self.translate(index_map, substs),
kind,
),
PredicateKind::Subtype(pred) => PredicateKind::Subtype({
let l = self.translate(index_map, pred.a);
let r = self.translate(index_map, pred.b);
SubtypePredicate {
a_is_expected: pred.a_is_expected,
a: l,
b: r,
let pred = match predicate.kind().skip_binder() {
PredicateKind::Trait(pred) => PredicateKind::Trait(
if let Some((target_def_id, target_substs)) = self.translate_orig_substs(
index_map,
pred.trait_ref.def_id,
pred.trait_ref.substs,
) {
TraitPredicate {
trait_ref: TraitRef {
def_id: target_def_id,
substs: target_substs,
},
constness: pred.constness,
}
}),
PredicateKind::ConstEvaluatable(param, orig_substs) => {
if let Some((target_def_id, target_substs)) =
self.translate_orig_substs(index_map, param.did, orig_substs)
{
// TODO: We could probably use translated version for
// `WithOptConstParam::const_param_did`
let const_param = WithOptConstParam::unknown(target_def_id);
PredicateKind::ConstEvaluatable(const_param, target_substs)
} else {
return None;
} else {
return None;
},
),
PredicateKind::RegionOutlives(pred) => PredicateKind::RegionOutlives({
let l = self.translate_region(pred.0);
let r = self.translate_region(pred.1);
OutlivesPredicate(l, r)
}),
PredicateKind::TypeOutlives(pred) => PredicateKind::TypeOutlives({
let l = self.translate(index_map, pred.0);
let r = self.translate_region(pred.1);
OutlivesPredicate(l, r)
}),
PredicateKind::Projection(pred) => PredicateKind::Projection(
if let Some((target_def_id, target_substs)) = self.translate_orig_substs(
index_map,
pred.projection_ty.item_def_id,
pred.projection_ty.substs,
) {
ProjectionPredicate {
projection_ty: ProjectionTy {
substs: target_substs,
item_def_id: target_def_id,
},
ty: self.translate(index_map, pred.ty),
}
} else {
return None;
},
),
PredicateKind::WellFormed(ty) => {
PredicateKind::WellFormed(self.translate(index_map, ty))
}
PredicateKind::ObjectSafe(did) => PredicateKind::ObjectSafe(self.translate_orig(did)),
PredicateKind::ClosureKind(did, substs, kind) => PredicateKind::ClosureKind(
self.translate_orig(did),
self.translate(index_map, substs),
kind,
),
PredicateKind::Subtype(pred) => PredicateKind::Subtype({
let l = self.translate(index_map, pred.a);
let r = self.translate(index_map, pred.b);
SubtypePredicate {
a_is_expected: pred.a_is_expected,
a: l,
b: r,
}
}),
PredicateKind::Coerce(pred) => PredicateKind::Coerce({
let a = self.translate(index_map, pred.a);
let b = self.translate(index_map, pred.b);
CoercePredicate { a, b }
}),
PredicateKind::ConstEvaluatable(uv) => {
if let Some((target_def_id, target_substs)) =
self.translate_orig_substs(index_map, uv.def.did, uv.substs(self.tcx))
{
// TODO: We could probably use translated version for
// `WithOptConstParam::const_param_did`
let const_param = WithOptConstParam::unknown(target_def_id);
PredicateKind::ConstEvaluatable(Unevaluated::new(const_param, target_substs))
} else {
return None;
}
PredicateKind::ConstEquate(c1, c2) => PredicateKind::ConstEquate(
self.translate(index_map, c1),
self.translate(index_map, c2),
),
// NOTE: Only used for Chalk trait solver
PredicateKind::TypeWellFormedFromEnv(_) => unimplemented!(),
}
.to_predicate(self.tcx),
)
PredicateKind::ConstEquate(c1, c2) => PredicateKind::ConstEquate(
self.translate(index_map, c1),
self.translate(index_map, c2),
),
// NOTE: Only used for Chalk trait solver
PredicateKind::TypeWellFormedFromEnv(_) => unimplemented!(),
};

Some(ty::Binder::dummy(pred).to_predicate(self.tcx))
}

/// Translate a slice of predicates in the context of an item.
31 changes: 16 additions & 15 deletions src/traverse.rs
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ use crate::{
typeck::{BoundContext, TypeComparisonContext},
};
use log::{debug, info};
use rustc_const_eval::const_eval::is_const_fn;
use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res, Res::Def};
use rustc_hir::def_id::DefId;
use rustc_hir::hir_id::HirId;
@@ -31,7 +32,6 @@ use rustc_middle::{
Visibility::Public,
},
};
use rustc_mir::const_eval::is_const_fn;
use std::collections::{BTreeMap, HashSet, VecDeque};

/// The main entry point to our analysis passes.
@@ -68,7 +68,7 @@ pub fn run_analysis(tcx: TyCtxt, old: DefId, new: DefId) -> ChangeSet {
}

// Get the visibility of the inner item, given the outer item's visibility.
fn get_vis(outer_vis: Visibility, def: Export<HirId>) -> Visibility {
fn get_vis(outer_vis: Visibility, def: Export) -> Visibility {
if outer_vis == Public {
def.vis
} else {
@@ -156,7 +156,8 @@ fn diff_structure<'tcx>(
match items {
// an item pair is found
(Some(o), Some(n)) => {
if let (Def(Mod, o_def_id), Def(Mod, n_def_id)) = (o.res, n.res) {
let (o_res, n_res) = (o.res.expect_non_local(), n.res.expect_non_local());
if let (Def(Mod, o_def_id), Def(Mod, n_def_id)) = (o_res, n_res) {
if visited.insert((o_def_id, n_def_id)) {
let o_vis = get_vis(old_vis, o);
let n_vis = get_vis(new_vis, n);
@@ -182,16 +183,16 @@ fn diff_structure<'tcx>(

mod_queue.push_back((o_def_id, n_def_id, o_vis, n_vis));
}
} else if id_mapping.add_export(o.res, n.res) {
} else if id_mapping.add_export(o_res, n_res) {
// struct constructors are weird/hard - let's go shopping!
if let (Def(Ctor(CtorOf::Struct, _), _), Def(Ctor(CtorOf::Struct, _), _)) =
(o.res, n.res)
(o_res, n_res)
{
continue;
}

let o_def_id = o.res.def_id();
let n_def_id = n.res.def_id();
let o_def_id = o_res.def_id();
let n_def_id = n_res.def_id();
let o_vis = get_vis(old_vis, o);
let n_vis = get_vis(new_vis, n);

@@ -211,7 +212,7 @@ fn diff_structure<'tcx>(
changes.add_change(ChangeType::ItemMadePublic, o_def_id, None);
}

let (o_kind, n_kind) = match (o.res, n.res) {
let (o_kind, n_kind) = match (o_res, n_res) {
(Res::Def(o_kind, _), Res::Def(n_kind, _)) => (o_kind, n_kind),
_ => {
// a non-matching item pair (seriously broken though) -
@@ -257,7 +258,7 @@ fn diff_structure<'tcx>(
// that need to be compared
(Fn, Fn) => {
diff_generics(changes, id_mapping, tcx, true, o_def_id, n_def_id);
diff_fn(changes, tcx, o.res, n.res);
diff_fn(changes, tcx, o_res, n_res);
}
// type aliases can declare generics, too
(TyAlias, TyAlias) => {
@@ -268,7 +269,7 @@ fn diff_structure<'tcx>(
// fields
(Struct, Struct) | (Union, Union) | (Enum, Enum) => {
diff_generics(changes, id_mapping, tcx, false, o_def_id, n_def_id);
diff_adts(changes, id_mapping, tcx, o.res, n.res);
diff_adts(changes, id_mapping, tcx, o_res, n_res);
}
// trait definitions can declare generics and require us to check
// for trait item addition and removal, as well as changes to their
@@ -298,7 +299,7 @@ fn diff_structure<'tcx>(
// only an old item is found
(Some(o), None) => {
// struct constructors are weird/hard - let's go shopping!
if let Def(Ctor(CtorOf::Struct, _), _) = o.res {
if let Def(Ctor(CtorOf::Struct, _), _) = o.res.expect_non_local::<HirId>() {
continue;
}

@@ -310,7 +311,7 @@ fn diff_structure<'tcx>(
// only a new item is found
(None, Some(n)) => {
// struct constructors are weird/hard - let's go shopping!
if let Def(Ctor(CtorOf::Struct, _), _) = n.res {
if let Def(Ctor(CtorOf::Struct, _), _) = n.res.expect_non_local::<HirId>() {
continue;
}

@@ -327,7 +328,7 @@ fn diff_structure<'tcx>(

// finally, process item additions and removals
for n in additions {
let n_def_id = n.res.def_id();
let n_def_id = n.res.expect_non_local::<HirId>().def_id();

if !id_mapping.contains_new_id(n_def_id) {
id_mapping.add_non_mapped(n_def_id);
@@ -338,7 +339,7 @@ fn diff_structure<'tcx>(
}

for o in removals {
let o_def_id = o.res.def_id();
let o_def_id = o.res.expect_non_local::<HirId>().def_id();

// reuse an already existing path change entry, if possible
if id_mapping.contains_old_id(o_def_id) {
@@ -590,7 +591,7 @@ fn diff_traits<'tcx>(
let old_param_env = tcx.param_env(old);

for bound in old_param_env.caller_bounds() {
if let PredicateKind::Trait(pred, _) = bound.kind().skip_binder() {
if let PredicateKind::Trait(pred) = bound.kind().skip_binder() {
let trait_ref = pred.trait_ref;

debug!("trait_ref substs (old): {:?}", trait_ref.substs);
15 changes: 6 additions & 9 deletions src/typeck.rs
Original file line number Diff line number Diff line change
@@ -72,15 +72,12 @@ impl<'a, 'tcx> BoundContext<'a, 'tcx> {

/// Register the trait bound represented by a `TraitRef`.
pub fn register_trait_ref(&mut self, checked_trait_ref: TraitRef<'tcx>) {
use rustc_hir::Constness;
use rustc_middle::ty::{ToPredicate, TraitPredicate};

let predicate = PredicateKind::Trait(
TraitPredicate {
trait_ref: checked_trait_ref,
},
Constness::NotConst,
)
use rustc_middle::ty::{self, BoundConstness, ToPredicate, TraitPredicate};

let predicate = ty::Binder::dummy(PredicateKind::Trait(TraitPredicate {
trait_ref: checked_trait_ref,
constness: BoundConstness::NotConst,
}))
.to_predicate(self.infcx.tcx);
let obligation = Obligation::new(ObligationCause::dummy(), self.given_param_env, predicate);
self.fulfill_cx