Skip to content

Commit d046f0f

Browse files
committed
---
yaml --- r: 273931 b: refs/heads/beta c: 57e5d43 h: refs/heads/master i: 273929: 9865dfd 273927: 8ddf612
1 parent 05be47e commit d046f0f

File tree

7 files changed

+75
-90
lines changed

7 files changed

+75
-90
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ refs/tags/0.9: 36870b185fc5f5486636d4515f0e22677493f225
2323
refs/tags/0.10: ac33f2b15782272ae348dbd7b14b8257b2148b5a
2424
refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
26-
refs/heads/beta: e8ab71fa00f2264f4587ca536e93b909a9358e27
26+
refs/heads/beta: 57e5d43c770201d837298175a2d55818867bdb33
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
2828
refs/heads/tmp: e06d2ad9fcd5027bcaac5b08fc9aa39a49d0ecd3
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f

branches/beta/src/librustc/ty/fold.rs

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -116,21 +116,9 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
116116
pub trait TypeFolder<'tcx> : Sized {
117117
fn tcx<'a>(&'a self) -> &'a TyCtxt<'tcx>;
118118

119-
/// Invoked by the `super_*` routines when we enter a region
120-
/// binding level (for example, when entering a function
121-
/// signature). This is used by clients that want to track the
122-
/// Debruijn index nesting level.
123-
fn enter_region_binder(&mut self) { }
124-
125-
/// Invoked by the `super_*` routines when we exit a region
126-
/// binding level. This is used by clients that want to
127-
/// track the Debruijn index nesting level.
128-
fn exit_region_binder(&mut self) { }
129-
130119
fn fold_binder<T>(&mut self, t: &Binder<T>) -> Binder<T>
131120
where T : TypeFoldable<'tcx>
132121
{
133-
// FIXME(#20526) this should replace `enter_region_binder`/`exit_region_binder`.
134122
t.super_fold_with(self)
135123
}
136124

@@ -197,8 +185,9 @@ pub trait TypeFolder<'tcx> : Sized {
197185
}
198186

199187
pub trait TypeVisitor<'tcx> : Sized {
200-
fn enter_region_binder(&mut self) { }
201-
fn exit_region_binder(&mut self) { }
188+
fn visit_binder<T: TypeFoldable<'tcx>>(&mut self, t: &Binder<T>) -> bool {
189+
t.super_visit_with(self)
190+
}
202191

203192
fn visit_ty(&mut self, t: Ty<'tcx>) -> bool {
204193
t.super_visit_with(self)
@@ -296,12 +285,11 @@ impl<'a, 'tcx> TypeFolder<'tcx> for RegionFolder<'a, 'tcx>
296285
{
297286
fn tcx(&self) -> &TyCtxt<'tcx> { self.tcx }
298287

299-
fn enter_region_binder(&mut self) {
288+
fn fold_binder<T: TypeFoldable<'tcx>>(&mut self, t: &ty::Binder<T>) -> ty::Binder<T> {
300289
self.current_depth += 1;
301-
}
302-
303-
fn exit_region_binder(&mut self) {
290+
let t = t.super_fold_with(self);
304291
self.current_depth -= 1;
292+
t
305293
}
306294

307295
fn fold_region(&mut self, r: ty::Region) -> ty::Region {
@@ -438,12 +426,11 @@ impl<'a, 'tcx> TypeFolder<'tcx> for RegionReplacer<'a, 'tcx>
438426
{
439427
fn tcx(&self) -> &TyCtxt<'tcx> { self.tcx }
440428

441-
fn enter_region_binder(&mut self) {
429+
fn fold_binder<T: TypeFoldable<'tcx>>(&mut self, t: &ty::Binder<T>) -> ty::Binder<T> {
442430
self.current_depth += 1;
443-
}
444-
445-
fn exit_region_binder(&mut self) {
431+
let t = t.super_fold_with(self);
446432
self.current_depth -= 1;
433+
t
447434
}
448435

449436
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
@@ -596,12 +583,11 @@ struct HasEscapingRegionsVisitor {
596583
}
597584

598585
impl<'tcx> TypeVisitor<'tcx> for HasEscapingRegionsVisitor {
599-
fn enter_region_binder(&mut self) {
586+
fn visit_binder<T: TypeFoldable<'tcx>>(&mut self, t: &Binder<T>) -> bool {
600587
self.depth += 1;
601-
}
602-
603-
fn exit_region_binder(&mut self) {
588+
let result = t.super_visit_with(self);
604589
self.depth -= 1;
590+
result
605591
}
606592

607593
fn visit_ty(&mut self, t: Ty<'tcx>) -> bool {

branches/beta/src/librustc/ty/structural_impls.rs

Lines changed: 8 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -190,21 +190,19 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Vec<T> {
190190

191191
impl<'tcx, T:TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::Binder<T> {
192192
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
193-
folder.enter_region_binder();
194-
let result = ty::Binder(self.0.fold_with(folder));
195-
folder.exit_region_binder();
196-
result
193+
ty::Binder(self.0.fold_with(folder))
197194
}
198195

199196
fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
200197
folder.fold_binder(self)
201198
}
202199

203200
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
204-
visitor.enter_region_binder();
205-
if self.0.visit_with(visitor) { return true }
206-
visitor.exit_region_binder();
207-
false
201+
self.0.visit_with(visitor)
202+
}
203+
204+
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
205+
visitor.visit_binder(self)
208206
}
209207
}
210208

@@ -220,39 +218,11 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for P<[T]> {
220218

221219
impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for VecPerParamSpace<T> {
222220
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
223-
224-
// Things in the Fn space take place under an additional level
225-
// of region binding relative to the other spaces. This is
226-
// because those entries are attached to a method, and methods
227-
// always introduce a level of region binding.
228-
229-
let result = self.map_enumerated(|(space, index, elem)| {
230-
if space == subst::FnSpace && index == 0 {
231-
// enter new level when/if we reach the first thing in fn space
232-
folder.enter_region_binder();
233-
}
234-
elem.fold_with(folder)
235-
});
236-
if result.len(subst::FnSpace) > 0 {
237-
// if there was anything in fn space, exit the region binding level
238-
folder.exit_region_binder();
239-
}
240-
result
221+
self.map(|elem| elem.fold_with(folder))
241222
}
242223

243224
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
244-
let mut entered_region_binder = false;
245-
let result = self.iter_enumerated().any(|(space, index, t)| {
246-
if space == subst::FnSpace && index == 0 {
247-
visitor.enter_region_binder();
248-
entered_region_binder = true;
249-
}
250-
t.visit_with(visitor)
251-
});
252-
if entered_region_binder {
253-
visitor.exit_region_binder();
254-
}
255-
result
225+
self.iter().any(|elem| elem.visit_with(visitor))
256226
}
257227
}
258228

branches/beta/src/librustc/ty/subst.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -582,12 +582,11 @@ struct SubstFolder<'a, 'tcx: 'a> {
582582
impl<'a, 'tcx> TypeFolder<'tcx> for SubstFolder<'a, 'tcx> {
583583
fn tcx(&self) -> &TyCtxt<'tcx> { self.tcx }
584584

585-
fn enter_region_binder(&mut self) {
585+
fn fold_binder<T: TypeFoldable<'tcx>>(&mut self, t: &ty::Binder<T>) -> ty::Binder<T> {
586586
self.region_binders_passed += 1;
587-
}
588-
589-
fn exit_region_binder(&mut self) {
587+
let t = t.super_fold_with(self);
590588
self.region_binders_passed -= 1;
589+
t
591590
}
592591

593592
fn fold_region(&mut self, r: ty::Region) -> ty::Region {

branches/beta/src/librustc_trans/callee.rs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -541,14 +541,6 @@ fn get_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
541541
}
542542
};
543543

544-
let llfn = declare::declare_fn(ccx, &sym, ty);
545-
attributes::from_fn_attrs(ccx, attrs, llfn);
546-
if let Some(id) = local_item {
547-
// FIXME(eddyb) Doubt all extern fn should allow unwinding.
548-
attributes::unwind(llfn, true);
549-
ccx.item_symbols().borrow_mut().insert(id, sym);
550-
}
551-
552544
// This is subtle and surprising, but sometimes we have to bitcast
553545
// the resulting fn pointer. The reason has to do with external
554546
// functions. If you have two crates that both bind the same C
@@ -572,12 +564,32 @@ fn get_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
572564
// This can occur on either a crate-local or crate-external
573565
// reference. It also occurs when testing libcore and in some
574566
// other weird situations. Annoying.
567+
575568
let llptrty = type_of::type_of(ccx, fn_ptr_ty);
576-
let llfn = if common::val_ty(llfn) != llptrty {
577-
debug!("get_fn: casting {:?} to {:?}", llfn, llptrty);
578-
consts::ptrcast(llfn, llptrty)
569+
let llfn = if let Some(llfn) = declare::get_declared_value(ccx, &sym) {
570+
if common::val_ty(llfn) != llptrty {
571+
if local_item.is_some() {
572+
bug!("symbol `{}` previously declared as {:?}, now wanted as {:?}",
573+
sym, Value(llfn), llptrty);
574+
}
575+
debug!("get_fn: casting {:?} to {:?}", llfn, llptrty);
576+
consts::ptrcast(llfn, llptrty)
577+
} else {
578+
debug!("get_fn: not casting pointer!");
579+
llfn
580+
}
579581
} else {
582+
let llfn = declare::declare_fn(ccx, &sym, ty);
583+
assert_eq!(common::val_ty(llfn), llptrty);
580584
debug!("get_fn: not casting pointer!");
585+
586+
attributes::from_fn_attrs(ccx, attrs, llfn);
587+
if let Some(id) = local_item {
588+
// FIXME(eddyb) Doubt all extern fn should allow unwinding.
589+
attributes::unwind(llfn, true);
590+
ccx.item_symbols().borrow_mut().insert(id, sym);
591+
}
592+
581593
llfn
582594
};
583595

branches/beta/src/librustc_trans/declare.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use abi::{Abi, FnType};
2626
use attributes;
2727
use context::CrateContext;
2828
use type_::Type;
29+
use value::Value;
2930

3031
use std::ffi::CString;
3132

@@ -146,27 +147,33 @@ pub fn define_internal_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
146147
}
147148

148149

149-
/// Get defined or externally defined (AvailableExternally linkage) value by
150-
/// name.
151-
pub fn get_defined_value(ccx: &CrateContext, name: &str) -> Option<ValueRef> {
152-
debug!("get_defined_value(name={:?})", name);
150+
/// Get declared value by name.
151+
pub fn get_declared_value(ccx: &CrateContext, name: &str) -> Option<ValueRef> {
152+
debug!("get_declared_value(name={:?})", name);
153153
let namebuf = CString::new(name).unwrap_or_else(|_|{
154154
bug!("name {:?} contains an interior null byte", name)
155155
});
156156
let val = unsafe { llvm::LLVMGetNamedValue(ccx.llmod(), namebuf.as_ptr()) };
157157
if val.is_null() {
158-
debug!("get_defined_value: {:?} value is null", name);
158+
debug!("get_declared_value: {:?} value is null", name);
159159
None
160160
} else {
161+
debug!("get_declared_value: {:?} => {:?}", name, Value(val));
162+
Some(val)
163+
}
164+
}
165+
166+
/// Get defined or externally defined (AvailableExternally linkage) value by
167+
/// name.
168+
pub fn get_defined_value(ccx: &CrateContext, name: &str) -> Option<ValueRef> {
169+
get_declared_value(ccx, name).and_then(|val|{
161170
let declaration = unsafe {
162171
llvm::LLVMIsDeclaration(val) != 0
163172
};
164-
debug!("get_defined_value: found {:?} value (declaration: {})",
165-
name, declaration);
166173
if !declaration {
167174
Some(val)
168175
} else {
169176
None
170177
}
171-
}
178+
})
172179
}

branches/beta/src/test/run-pass/foreign-dupe.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,20 @@ mod rustrt2 {
3131
}
3232
}
3333

34+
mod rustrt3 {
35+
// Different type, but same ABI (on all supported platforms).
36+
// Ensures that we don't ICE or trigger LLVM asserts when
37+
// importing the same symbol under different types.
38+
// See https://github.com/rust-lang/rust/issues/32740.
39+
extern {
40+
pub fn rust_get_test_int() -> *const u8;
41+
}
42+
}
43+
3444
pub fn main() {
3545
unsafe {
36-
rustrt1::rust_get_test_int();
37-
rustrt2::rust_get_test_int();
46+
let x = rustrt1::rust_get_test_int();
47+
assert_eq!(x, rustrt2::rust_get_test_int());
48+
assert_eq!(x as *const _, rustrt3::rust_get_test_int());
3849
}
3950
}

0 commit comments

Comments
 (0)