Auto merge of #38479 - michaelwoerister:extern_mod_ich, r=nikomatsakis
ICH: Fix and test foreign mod hashing. r? @nikomatsakis
This commit is contained in:
commit
a9ab778815
@ -264,6 +264,9 @@ pub trait Visitor<'v> : Sized {
|
||||
fn visit_where_predicate(&mut self, predicate: &'v WherePredicate) {
|
||||
walk_where_predicate(self, predicate)
|
||||
}
|
||||
fn visit_fn_decl(&mut self, fd: &'v FnDecl) {
|
||||
walk_fn_decl(self, fd)
|
||||
}
|
||||
fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v FnDecl, b: ExprId, s: Span, id: NodeId) {
|
||||
walk_fn(self, fk, fd, b, s, id)
|
||||
}
|
||||
@ -531,7 +534,7 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) {
|
||||
walk_list!(visitor, visit_ty, tuple_element_types);
|
||||
}
|
||||
TyBareFn(ref function_declaration) => {
|
||||
walk_fn_decl(visitor, &function_declaration.decl);
|
||||
visitor.visit_fn_decl(&function_declaration.decl);
|
||||
walk_list!(visitor, visit_lifetime_def, &function_declaration.lifetimes);
|
||||
}
|
||||
TyPath(ref qpath) => {
|
||||
@ -660,7 +663,7 @@ pub fn walk_foreign_item<'v, V: Visitor<'v>>(visitor: &mut V, foreign_item: &'v
|
||||
|
||||
match foreign_item.node {
|
||||
ForeignItemFn(ref function_declaration, ref generics) => {
|
||||
walk_fn_decl(visitor, function_declaration);
|
||||
visitor.visit_fn_decl(function_declaration);
|
||||
visitor.visit_generics(generics)
|
||||
}
|
||||
ForeignItemStatic(ref typ, _) => visitor.visit_ty(typ),
|
||||
@ -764,7 +767,7 @@ pub fn walk_fn<'v, V: Visitor<'v>>(visitor: &mut V,
|
||||
_span: Span,
|
||||
id: NodeId) {
|
||||
visitor.visit_id(id);
|
||||
walk_fn_decl(visitor, function_declaration);
|
||||
visitor.visit_fn_decl(function_declaration);
|
||||
walk_fn_kind(visitor, function_kind);
|
||||
visitor.visit_body(body_id)
|
||||
}
|
||||
@ -776,7 +779,7 @@ pub fn walk_fn_with_body<'v, V: Visitor<'v>>(visitor: &mut V,
|
||||
_span: Span,
|
||||
id: NodeId) {
|
||||
visitor.visit_id(id);
|
||||
walk_fn_decl(visitor, function_declaration);
|
||||
visitor.visit_fn_decl(function_declaration);
|
||||
walk_fn_kind(visitor, function_kind);
|
||||
visitor.visit_expr(body)
|
||||
}
|
||||
@ -793,7 +796,7 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v Trai
|
||||
MethodTraitItem(ref sig, None) => {
|
||||
visitor.visit_id(trait_item.id);
|
||||
visitor.visit_generics(&sig.generics);
|
||||
walk_fn_decl(visitor, &sig.decl);
|
||||
visitor.visit_fn_decl(&sig.decl);
|
||||
}
|
||||
MethodTraitItem(ref sig, Some(body_id)) => {
|
||||
visitor.visit_fn(FnKind::Method(trait_item.name,
|
||||
|
@ -238,9 +238,4 @@ impl<'a, 'tcx> Visitor<'tcx> for HashItemsVisitor<'a, 'tcx> {
|
||||
self.calculate_node_id(impl_item.id, |v| v.visit_impl_item(impl_item));
|
||||
visit::walk_impl_item(self, impl_item);
|
||||
}
|
||||
|
||||
fn visit_foreign_item(&mut self, item: &'tcx hir::ForeignItem) {
|
||||
self.calculate_node_id(item.id, |v| v.visit_foreign_item(item));
|
||||
visit::walk_foreign_item(self, item);
|
||||
}
|
||||
}
|
||||
|
@ -180,9 +180,10 @@ enum SawAbiComponent<'a> {
|
||||
SawLifetimeDef(usize),
|
||||
|
||||
SawMod,
|
||||
SawForeignItem,
|
||||
SawForeignItem(SawForeignItemComponent),
|
||||
SawItem(SawItemComponent),
|
||||
SawTy(SawTyComponent),
|
||||
SawFnDecl(bool),
|
||||
SawGenerics,
|
||||
SawTraitItem(SawTraitOrImplItemComponent),
|
||||
SawImplItem(SawTraitOrImplItemComponent),
|
||||
@ -363,7 +364,7 @@ enum SawItemComponent {
|
||||
SawItemConst,
|
||||
SawItemFn(Unsafety, Constness, Abi),
|
||||
SawItemMod,
|
||||
SawItemForeignMod,
|
||||
SawItemForeignMod(Abi),
|
||||
SawItemTy,
|
||||
SawItemEnum,
|
||||
SawItemStruct,
|
||||
@ -381,7 +382,7 @@ fn saw_item(node: &Item_) -> SawItemComponent {
|
||||
ItemConst(..) =>SawItemConst,
|
||||
ItemFn(_, unsafety, constness, abi, _, _) => SawItemFn(unsafety, constness, abi),
|
||||
ItemMod(..) => SawItemMod,
|
||||
ItemForeignMod(..) => SawItemForeignMod,
|
||||
ItemForeignMod(ref fm) => SawItemForeignMod(fm.abi),
|
||||
ItemTy(..) => SawItemTy,
|
||||
ItemEnum(..) => SawItemEnum,
|
||||
ItemStruct(..) => SawItemStruct,
|
||||
@ -392,6 +393,12 @@ fn saw_item(node: &Item_) -> SawItemComponent {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Hash)]
|
||||
enum SawForeignItemComponent {
|
||||
Static { mutable: bool },
|
||||
Fn,
|
||||
}
|
||||
|
||||
#[derive(Hash)]
|
||||
enum SawPatComponent {
|
||||
SawPatWild,
|
||||
@ -641,7 +648,17 @@ impl<'a, 'hash, 'tcx> visit::Visitor<'tcx> for StrictVersionHashVisitor<'a, 'has
|
||||
fn visit_foreign_item(&mut self, i: &'tcx ForeignItem) {
|
||||
debug!("visit_foreign_item: st={:?}", self.st);
|
||||
|
||||
SawForeignItem.hash(self.st);
|
||||
match i.node {
|
||||
ForeignItemFn(..) => {
|
||||
SawForeignItem(SawForeignItemComponent::Fn)
|
||||
}
|
||||
ForeignItemStatic(_, mutable) => {
|
||||
SawForeignItem(SawForeignItemComponent::Static {
|
||||
mutable: mutable
|
||||
})
|
||||
}
|
||||
}.hash(self.st);
|
||||
|
||||
hash_span!(self, i.span);
|
||||
hash_attrs!(self, &i.attrs);
|
||||
visit::walk_foreign_item(self, i)
|
||||
@ -678,6 +695,12 @@ impl<'a, 'hash, 'tcx> visit::Visitor<'tcx> for StrictVersionHashVisitor<'a, 'has
|
||||
visit::walk_generics(self, g)
|
||||
}
|
||||
|
||||
fn visit_fn_decl(&mut self, fd: &'tcx FnDecl) {
|
||||
debug!("visit_fn_decl: st={:?}", self.st);
|
||||
SawFnDecl(fd.variadic).hash(self.st);
|
||||
visit::walk_fn_decl(self, fd)
|
||||
}
|
||||
|
||||
fn visit_trait_item(&mut self, ti: &'tcx TraitItem) {
|
||||
debug!("visit_trait_item: st={:?}", self.st);
|
||||
|
||||
|
272
src/test/incremental/hashes/extern_mods.rs
Normal file
272
src/test/incremental/hashes/extern_mods.rs
Normal file
@ -0,0 +1,272 @@
|
||||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
// This test case tests the incremental compilation hash (ICH) implementation
|
||||
// for `extern` modules.
|
||||
|
||||
// The general pattern followed here is: Change one thing between rev1 and rev2
|
||||
// and make sure that the hash has changed, then change nothing between rev2 and
|
||||
// rev3 and make sure that the hash has not changed.
|
||||
|
||||
// must-compile-successfully
|
||||
// revisions: cfail1 cfail2 cfail3
|
||||
// compile-flags: -Z query-dep-graph
|
||||
|
||||
#![allow(warnings)]
|
||||
#![feature(rustc_attrs)]
|
||||
#![feature(unboxed_closures)]
|
||||
#![feature(link_args)]
|
||||
#![crate_type="rlib"]
|
||||
|
||||
|
||||
// Change function name --------------------------------------------------------
|
||||
#[cfg(cfail1)]
|
||||
extern {
|
||||
pub fn change_function_name1(c: i64) -> i32;
|
||||
}
|
||||
|
||||
#[cfg(not(cfail1))]
|
||||
#[rustc_dirty(label="Hir", cfg="cfail2")]
|
||||
#[rustc_clean(label="Hir", cfg="cfail3")]
|
||||
#[rustc_metadata_dirty(cfg="cfail2")]
|
||||
#[rustc_metadata_clean(cfg="cfail3")]
|
||||
extern {
|
||||
pub fn change_function_name2(c: i64) -> i32;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Change parameter name -------------------------------------------------------
|
||||
#[cfg(cfail1)]
|
||||
extern {
|
||||
pub fn change_parameter_name(c: i64) -> i32;
|
||||
}
|
||||
|
||||
#[cfg(not(cfail1))]
|
||||
#[rustc_dirty(label="Hir", cfg="cfail2")]
|
||||
#[rustc_clean(label="Hir", cfg="cfail3")]
|
||||
#[rustc_metadata_dirty(cfg="cfail2")]
|
||||
#[rustc_metadata_clean(cfg="cfail3")]
|
||||
extern {
|
||||
pub fn change_parameter_name(d: i64) -> i32;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Change parameter type -------------------------------------------------------
|
||||
#[cfg(cfail1)]
|
||||
extern {
|
||||
pub fn change_parameter_type(c: i64) -> i32;
|
||||
}
|
||||
|
||||
#[cfg(not(cfail1))]
|
||||
#[rustc_dirty(label="Hir", cfg="cfail2")]
|
||||
#[rustc_clean(label="Hir", cfg="cfail3")]
|
||||
#[rustc_metadata_dirty(cfg="cfail2")]
|
||||
#[rustc_metadata_clean(cfg="cfail3")]
|
||||
extern {
|
||||
pub fn change_parameter_type(c: i32) -> i32;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Change return type ----------------------------------------------------------
|
||||
#[cfg(cfail1)]
|
||||
extern {
|
||||
pub fn change_return_type(c: i32) -> i32;
|
||||
}
|
||||
|
||||
#[cfg(not(cfail1))]
|
||||
#[rustc_dirty(label="Hir", cfg="cfail2")]
|
||||
#[rustc_clean(label="Hir", cfg="cfail3")]
|
||||
#[rustc_metadata_dirty(cfg="cfail2")]
|
||||
#[rustc_metadata_clean(cfg="cfail3")]
|
||||
extern {
|
||||
pub fn change_return_type(c: i32) -> i8;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Add parameter ---------------------------------------------------------------
|
||||
#[cfg(cfail1)]
|
||||
extern {
|
||||
pub fn add_parameter(c: i32) -> i32;
|
||||
}
|
||||
|
||||
#[cfg(not(cfail1))]
|
||||
#[rustc_dirty(label="Hir", cfg="cfail2")]
|
||||
#[rustc_clean(label="Hir", cfg="cfail3")]
|
||||
#[rustc_metadata_dirty(cfg="cfail2")]
|
||||
#[rustc_metadata_clean(cfg="cfail3")]
|
||||
extern {
|
||||
pub fn add_parameter(c: i32, d: i32) -> i32;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Add return type -------------------------------------------------------------
|
||||
#[cfg(cfail1)]
|
||||
extern {
|
||||
pub fn add_return_type(c: i32);
|
||||
}
|
||||
|
||||
#[cfg(not(cfail1))]
|
||||
#[rustc_dirty(label="Hir", cfg="cfail2")]
|
||||
#[rustc_clean(label="Hir", cfg="cfail3")]
|
||||
#[rustc_metadata_dirty(cfg="cfail2")]
|
||||
#[rustc_metadata_clean(cfg="cfail3")]
|
||||
extern {
|
||||
pub fn add_return_type(c: i32) -> i32;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Make function variadic ------------------------------------------------------
|
||||
#[cfg(cfail1)]
|
||||
extern {
|
||||
pub fn make_function_variadic(c: i32);
|
||||
}
|
||||
|
||||
#[cfg(not(cfail1))]
|
||||
#[rustc_dirty(label="Hir", cfg="cfail2")]
|
||||
#[rustc_clean(label="Hir", cfg="cfail3")]
|
||||
#[rustc_metadata_dirty(cfg="cfail2")]
|
||||
#[rustc_metadata_clean(cfg="cfail3")]
|
||||
extern {
|
||||
pub fn make_function_variadic(c: i32, ...);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Change calling convention ---------------------------------------------------
|
||||
#[cfg(cfail1)]
|
||||
extern "C" {
|
||||
pub fn change_calling_convention(c: i32);
|
||||
}
|
||||
|
||||
#[cfg(not(cfail1))]
|
||||
#[rustc_dirty(label="Hir", cfg="cfail2")]
|
||||
#[rustc_clean(label="Hir", cfg="cfail3")]
|
||||
#[rustc_metadata_dirty(cfg="cfail2")]
|
||||
#[rustc_metadata_clean(cfg="cfail3")]
|
||||
extern "rust-call" {
|
||||
pub fn change_calling_convention(c: i32);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Make function public --------------------------------------------------------
|
||||
#[cfg(cfail1)]
|
||||
extern {
|
||||
fn make_function_public(c: i32);
|
||||
}
|
||||
|
||||
#[cfg(not(cfail1))]
|
||||
#[rustc_dirty(label="Hir", cfg="cfail2")]
|
||||
#[rustc_clean(label="Hir", cfg="cfail3")]
|
||||
#[rustc_metadata_dirty(cfg="cfail2")]
|
||||
#[rustc_metadata_clean(cfg="cfail3")]
|
||||
extern {
|
||||
pub fn make_function_public(c: i32);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Add function ----------------------------------------------------------------
|
||||
#[cfg(cfail1)]
|
||||
extern {
|
||||
pub fn add_function1(c: i32);
|
||||
}
|
||||
|
||||
#[cfg(not(cfail1))]
|
||||
#[rustc_dirty(label="Hir", cfg="cfail2")]
|
||||
#[rustc_clean(label="Hir", cfg="cfail3")]
|
||||
#[rustc_metadata_dirty(cfg="cfail2")]
|
||||
#[rustc_metadata_clean(cfg="cfail3")]
|
||||
extern {
|
||||
pub fn add_function1(c: i32);
|
||||
pub fn add_function2();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Change link-args ------------------------------------------------------------
|
||||
#[cfg(cfail1)]
|
||||
#[link_args = "-foo -bar"]
|
||||
extern {
|
||||
pub fn change_link_args(c: i32);
|
||||
}
|
||||
|
||||
#[cfg(not(cfail1))]
|
||||
#[rustc_dirty(label="Hir", cfg="cfail2")]
|
||||
#[rustc_clean(label="Hir", cfg="cfail3")]
|
||||
#[rustc_metadata_dirty(cfg="cfail2")]
|
||||
#[rustc_metadata_clean(cfg="cfail3")]
|
||||
#[link_args = "-foo -bar -baz"]
|
||||
extern {
|
||||
pub fn change_link_args(c: i32);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Change link-name ------------------------------------------------------------
|
||||
#[cfg(cfail1)]
|
||||
#[link(name = "foo")]
|
||||
extern {
|
||||
pub fn change_link_name(c: i32);
|
||||
}
|
||||
|
||||
#[cfg(not(cfail1))]
|
||||
#[rustc_dirty(label="Hir", cfg="cfail2")]
|
||||
#[rustc_clean(label="Hir", cfg="cfail3")]
|
||||
#[rustc_metadata_dirty(cfg="cfail2")]
|
||||
#[rustc_metadata_clean(cfg="cfail3")]
|
||||
#[link(name = "bar")]
|
||||
extern {
|
||||
pub fn change_link_name(c: i32);
|
||||
}
|
||||
|
||||
type c_i32 = i32;
|
||||
type c_i64 = i64;
|
||||
|
||||
// Indirectly change parameter type --------------------------------------------
|
||||
mod indirectly_change_parameter_type {
|
||||
#[cfg(cfail1)]
|
||||
use super::c_i32 as c_int;
|
||||
#[cfg(not(cfail1))]
|
||||
use super::c_i64 as c_int;
|
||||
|
||||
#[rustc_dirty(label="Hir", cfg="cfail2")]
|
||||
#[rustc_clean(label="Hir", cfg="cfail3")]
|
||||
#[rustc_metadata_dirty(cfg="cfail2")]
|
||||
#[rustc_metadata_clean(cfg="cfail3")]
|
||||
extern {
|
||||
pub fn indirectly_change_parameter_type(c: c_int);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Indirectly change return type --------------------------------------------
|
||||
mod indirectly_change_return_type {
|
||||
#[cfg(cfail1)]
|
||||
use super::c_i32 as c_int;
|
||||
#[cfg(not(cfail1))]
|
||||
use super::c_i64 as c_int;
|
||||
|
||||
#[rustc_dirty(label="Hir", cfg="cfail2")]
|
||||
#[rustc_clean(label="Hir", cfg="cfail3")]
|
||||
#[rustc_metadata_dirty(cfg="cfail2")]
|
||||
#[rustc_metadata_clean(cfg="cfail3")]
|
||||
extern {
|
||||
pub fn indirectly_change_return_type() -> c_int;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user