Skip to content

Commit b269acf

Browse files
committed
---
yaml --- r: 147278 b: refs/heads/try2 c: c2c2c4d h: refs/heads/master v: v3
1 parent a729bb0 commit b269acf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+877
-309
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: d9525530482f12f9814f46148ba02d3d1ecebee5
8+
refs/heads/try2: c2c2c4d6f3dae07134858266b7f037ea110a6f82
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/doc/rust.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2177,7 +2177,11 @@ Expressions are divided into two main categories: _lvalues_ and _rvalues_.
21772177
Likewise within each expression, sub-expressions may occur in _lvalue context_ or _rvalue context_.
21782178
The evaluation of an expression depends both on its own category and the context it occurs within.
21792179

2180-
[Path](#path-expressions), [field](#field-expressions) and [index](#index-expressions) expressions are lvalues.
2180+
An lvalue is an expression that represents a memory location. These
2181+
expressions are [paths](#path-expressions) (which refer to local
2182+
variables, function and method arguments, or static variables),
2183+
dereferences (`*expr`), [indexing expressions](#index-expressions)
2184+
(`expr[expr]`), and [field references](#field-expressions) (`expr.f`).
21812185
All other expressions are rvalues.
21822186

21832187
The left operand of an [assignment](#assignment-expressions),

branches/try2/src/libextra/lib.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,14 @@ Rust extras are part of the standard Rust distribution.
2020
2121
*/
2222

23-
#[pkgid="extra#0.9-pre"];
24-
// NOTE: remove after the next snapshot
25-
#[link(name = "extra",
26-
package_id = "extra",
27-
vers = "0.9-pre",
28-
uuid = "122bed0b-c19b-4b82-b0b7-7ae8aead7297",
29-
url = "https://github.com/mozilla/rust/tree/master/src/libextra")];
30-
31-
#[doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk.png",
32-
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
33-
html_root_url = "http://static.rust-lang.org/doc/master")];
34-
23+
#[pkgid = "extra#0.9-pre"];
3524
#[comment = "Rust extras"];
3625
#[license = "MIT/ASL2"];
3726
#[crate_type = "rlib"];
3827
#[crate_type = "dylib"];
28+
#[doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk.png",
29+
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
30+
html_root_url = "http://static.rust-lang.org/doc/master")];
3931

4032
#[feature(macro_rules, globs, managed_boxes)];
4133

branches/try2/src/librustc/front/test.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,8 @@ fn mk_tests(cx: &TestCtxt) -> @ast::item {
375375
}
376376

377377
fn is_extra(crate: &ast::Crate) -> bool {
378-
let items = attr::find_linkage_metas(crate.attrs);
379-
match attr::last_meta_item_value_str_by_name(items, "name") {
380-
Some(s) if "extra" == s => true,
378+
match attr::find_pkgid(crate.attrs) {
379+
Some(ref s) if "extra" == s.name => true,
381380
_ => false
382381
}
383382
}

branches/try2/src/librustc/lib.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#[pkgid="rustc#0.9-pre"];
12-
// NOTE: remove after the next snapshot
13-
#[link(name = "rustc",
14-
package_id = "rustc",
15-
vers = "0.9-pre",
16-
uuid = "0ce89b41-2f92-459e-bbc1-8f5fe32f16cf",
17-
url = "https://github.com/mozilla/rust/tree/master/src/rustc")];
18-
11+
#[pkgid = "rustc#0.9-pre"];
1912
#[comment = "The Rust compiler"];
2013
#[license = "MIT/ASL2"];
2114
#[crate_type = "dylib"];

branches/try2/src/librustc/middle/dead.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ impl MarkSymbolVisitor {
107107
match item.node {
108108
ast::item_fn(..)
109109
| ast::item_ty(..)
110+
| ast::item_enum(..)
111+
| ast::item_struct(..)
110112
| ast::item_static(..) => {
111113
visit::walk_item(self, item, ());
112114
}

branches/try2/src/librustc/middle/trans/_match.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ use util::common::indenter;
220220
use util::ppaux::{Repr, vec_map_to_str};
221221

222222
use std::hashmap::HashMap;
223+
use std::ptr;
223224
use std::vec;
224225
use syntax::ast;
225226
use syntax::ast::Ident;
@@ -2046,7 +2047,10 @@ pub fn store_arg(mut bcx: @mut Block,
20462047
// Debug information (the llvm.dbg.declare intrinsic to be precise) always expects to get an
20472048
// alloca, which only is the case on the general path, so lets disable the optimized path when
20482049
// debug info is enabled.
2049-
let fast_path = !bcx.ccx().sess.opts.extra_debuginfo && simple_identifier(pat).is_some();
2050+
let arg_is_alloca = unsafe { llvm::LLVMIsAAllocaInst(llval) != ptr::null() };
2051+
2052+
let fast_path = (arg_is_alloca || !bcx.ccx().sess.opts.extra_debuginfo)
2053+
&& simple_identifier(pat).is_some();
20502054

20512055
if fast_path {
20522056
// Optimized path for `x: T` case. This just adopts

branches/try2/src/librustc/middle/trans/base.rs

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ pub fn opaque_box_body(bcx: @mut Block,
303303
let _icx = push_ctxt("opaque_box_body");
304304
let ccx = bcx.ccx();
305305
let ty = type_of(ccx, body_t);
306-
let ty = Type::box(ccx, &ty);
306+
let ty = Type::smart_ptr(ccx, &ty);
307307
let boxptr = PointerCast(bcx, boxptr, ty.ptr_to());
308308
GEPi(bcx, boxptr, [0u, abi::box_field_body])
309309
}
@@ -385,20 +385,24 @@ pub fn malloc_raw(bcx: @mut Block, t: ty::t, heap: heap) -> Result {
385385

386386
pub struct MallocResult {
387387
bcx: @mut Block,
388-
box: ValueRef,
388+
smart_ptr: ValueRef,
389389
body: ValueRef
390390
}
391391

392-
// malloc_general_dyn: usefully wraps malloc_raw_dyn; allocates a box,
393-
// and pulls out the body
392+
// malloc_general_dyn: usefully wraps malloc_raw_dyn; allocates a smart
393+
// pointer, and pulls out the body
394394
pub fn malloc_general_dyn(bcx: @mut Block, t: ty::t, heap: heap, size: ValueRef)
395395
-> MallocResult {
396396
assert!(heap != heap_exchange);
397397
let _icx = push_ctxt("malloc_general");
398398
let Result {bcx: bcx, val: llbox} = malloc_raw_dyn(bcx, t, heap, size);
399399
let body = GEPi(bcx, llbox, [0u, abi::box_field_body]);
400400

401-
MallocResult { bcx: bcx, box: llbox, body: body }
401+
MallocResult {
402+
bcx: bcx,
403+
smart_ptr: llbox,
404+
body: body,
405+
}
402406
}
403407

404408
pub fn malloc_general(bcx: @mut Block, t: ty::t, heap: heap) -> MallocResult {
@@ -871,8 +875,11 @@ pub fn trans_external_path(ccx: &mut CrateContext, did: ast::DefId, t: ty::t) ->
871875
}
872876
}
873877
874-
pub fn invoke(bcx: @mut Block, llfn: ValueRef, llargs: ~[ValueRef],
875-
attributes: &[(uint, lib::llvm::Attribute)])
878+
pub fn invoke(bcx: @mut Block,
879+
llfn: ValueRef,
880+
llargs: ~[ValueRef],
881+
attributes: &[(uint, lib::llvm::Attribute)],
882+
call_info: Option<NodeInfo>)
876883
-> (ValueRef, @mut Block) {
877884
let _icx = push_ctxt("invoke_");
878885
if bcx.unreachable {
@@ -895,11 +902,18 @@ pub fn invoke(bcx: @mut Block, llfn: ValueRef, llargs: ~[ValueRef],
895902
}
896903
}
897904
let normal_bcx = sub_block(bcx, "normal return");
905+
let landing_pad = get_landing_pad(bcx);
906+
907+
match call_info {
908+
Some(info) => debuginfo::set_source_location(bcx.fcx, info.id, info.span),
909+
None => debuginfo::clear_source_location(bcx.fcx)
910+
};
911+
898912
let llresult = Invoke(bcx,
899913
llfn,
900914
llargs,
901915
normal_bcx.llbb,
902-
get_landing_pad(bcx),
916+
landing_pad,
903917
attributes);
904918
return (llresult, normal_bcx);
905919
} else {
@@ -909,6 +923,12 @@ pub fn invoke(bcx: @mut Block, llfn: ValueRef, llargs: ~[ValueRef],
909923
debug!("arg: {}", llarg);
910924
}
911925
}
926+
927+
match call_info {
928+
Some(info) => debuginfo::set_source_location(bcx.fcx, info.id, info.span),
929+
None => debuginfo::clear_source_location(bcx.fcx)
930+
};
931+
912932
let llresult = Call(bcx, llfn, llargs, attributes);
913933
return (llresult, bcx);
914934
}
@@ -1547,6 +1567,7 @@ pub fn alloca_maybe_zeroed(cx: @mut Block, ty: Type, name: &str, zero: bool) ->
15471567
return llvm::LLVMGetUndef(ty.ptr_to().to_ref());
15481568
}
15491569
}
1570+
debuginfo::clear_source_location(cx.fcx);
15501571
let p = Alloca(cx, ty, name);
15511572
if zero {
15521573
let b = cx.fcx.ccx.builder();
@@ -1563,6 +1584,7 @@ pub fn arrayalloca(cx: @mut Block, ty: Type, v: ValueRef) -> ValueRef {
15631584
return llvm::LLVMGetUndef(ty.to_ref());
15641585
}
15651586
}
1587+
debuginfo::clear_source_location(cx.fcx);
15661588
return ArrayAlloca(cx, ty, v);
15671589
}
15681590

@@ -1806,6 +1828,7 @@ pub fn finish_fn(fcx: @mut FunctionContext, last_bcx: @mut Block) {
18061828
None => last_bcx
18071829
};
18081830
build_return_block(fcx, ret_cx);
1831+
debuginfo::clear_source_location(fcx);
18091832
fcx.cleanup();
18101833
}
18111834

branches/try2/src/librustc/middle/trans/callee.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ pub fn trans_call_inner(in_cx: @mut Block,
697697
}
698698

699699
// Invoke the actual rust fn and update bcx/llresult.
700-
let (llret, b) = base::invoke(bcx, llfn, llargs, attrs);
700+
let (llret, b) = base::invoke(bcx, llfn, llargs, attrs, call_info);
701701
bcx = b;
702702
llresult = llret;
703703

branches/try2/src/librustc/middle/trans/debuginfo.rs

Lines changed: 62 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,43 @@ continuation, storing all state needed to continue traversal at the type members
8585
been registered with the cache. (This implementation approach might be a tad over-engineered and
8686
may change in the future)
8787
88+
89+
## Source Locations and Line Information
90+
In addition to data type descriptions the debugging information must also allow to map machine code
91+
locations back to source code locations in order to be useful. This functionality is also handled in
92+
this module. The following functions allow to control source mappings:
93+
94+
+ set_source_location()
95+
+ clear_source_location()
96+
+ start_emitting_source_locations()
97+
98+
`set_source_location()` allows to set the current source location. All IR instructions created after
99+
a call to this function will be linked to the given source location, until another location is
100+
specified with `set_source_location()` or the source location is cleared with
101+
`clear_source_location()`. In the later case, subsequent IR instruction will not be linked to any
102+
source location. As you can see, this is a stateful API (mimicking the one in LLVM), so be careful
103+
with source locations set by previous calls. It's probably best to not rely on any specific state
104+
being present at a given point in code.
105+
106+
One topic that deserves some extra attention is *function prologues*. At the beginning of a
107+
function's machine code there are typically a few instructions for loading argument values into
108+
allocas and checking if there's enough stack space for the function to execute. This *prologue* is
109+
not visible in the source code and LLVM puts a special PROLOGUE END marker into the line table at
110+
the first non-prologue instruction of the function. In order to find out where the prologue ends,
111+
LLVM looks for the first instruction in the function body that is linked to a source location. So,
112+
when generating prologue instructions we have to make sure that we don't emit source location
113+
information until the 'real' function body begins. For this reason, source location emission is
114+
disabled by default for any new function being translated and is only activated after a call to the
115+
third function from the list above, `start_emitting_source_locations()`. This function should be
116+
called right before regularly starting to translate the top-level block of the given function.
117+
118+
There is one exception to the above rule: `llvm.dbg.declare` instruction must be linked to the
119+
source location of the variable being declared. For function parameters these `llvm.dbg.declare`
120+
instructions typically occur in the middle of the prologue, however, they are ignored by LLVM's
121+
prologue detection. The `create_argument_metadata()` and related functions take care of linking the
122+
`llvm.dbg.declare` instructions to the correct source locations even while source location emission
123+
is still disabled, so there is no need to do anything special with source location handling here.
124+
88125
*/
89126

90127

@@ -651,7 +688,16 @@ pub fn create_function_debug_context(cx: &mut CrateContext,
651688
(function_name.clone(), file_metadata)
652689
};
653690

654-
let scope_line = get_scope_line(cx, top_level_block, loc.line);
691+
// Clang sets this parameter to the opening brace of the function's block, so let's do this too.
692+
let scope_line = span_start(cx, top_level_block.span).line;
693+
694+
// The is_local_to_unit flag indicates whether a function is local to the current compilation
695+
// unit (i.e. if it is *static* in the C-sense). The *reachable* set should provide a good
696+
// approximation of this, as it contains everything that might leak out of the current crate
697+
// (by being externally visible or by being inlined into something externally visible). It might
698+
// better to use the `exported_items` set from `driver::CrateAnalysis` in the future, but (atm)
699+
// this set is not available in the translation pass.
700+
let is_local_to_unit = !cx.reachable.contains(&fn_ast_id);
655701

656702
let fn_metadata = function_name.with_c_str(|function_name| {
657703
linkage_name.with_c_str(|linkage_name| {
@@ -664,7 +710,7 @@ pub fn create_function_debug_context(cx: &mut CrateContext,
664710
file_metadata,
665711
loc.line as c_uint,
666712
function_type_metadata,
667-
false,
713+
is_local_to_unit,
668714
true,
669715
scope_line as c_uint,
670716
FlagPrototyped as c_uint,
@@ -687,6 +733,9 @@ pub fn create_function_debug_context(cx: &mut CrateContext,
687733
let arg_pats = fn_decl.inputs.map(|arg_ref| arg_ref.pat);
688734
populate_scope_map(cx, arg_pats, top_level_block, fn_metadata, &mut fn_debug_context.scope_map);
689735

736+
// Clear the debug location so we don't assign them in the function prelude
737+
set_debug_location(cx, UnknownLocation);
738+
690739
return FunctionDebugContext(fn_debug_context);
691740

692741
fn get_function_signature(cx: &mut CrateContext,
@@ -837,21 +886,6 @@ pub fn create_function_debug_context(cx: &mut CrateContext,
837886

838887
return create_DIArray(DIB(cx), template_params);
839888
}
840-
841-
fn get_scope_line(cx: &CrateContext,
842-
top_level_block: &ast::Block,
843-
default: uint)
844-
-> uint {
845-
match *top_level_block {
846-
ast::Block { stmts: ref statements, .. } if statements.len() > 0 => {
847-
span_start(cx, statements[0].span).line
848-
}
849-
ast::Block { expr: Some(@ref expr), .. } => {
850-
span_start(cx, expr.span).line
851-
}
852-
_ => default
853-
}
854-
}
855889
}
856890

857891
//=-------------------------------------------------------------------------------------------------
@@ -1683,7 +1717,7 @@ fn boxed_type_metadata(cx: &mut CrateContext,
16831717
None => ~"BoxedType"
16841718
};
16851719

1686-
let box_llvm_type = Type::box(cx, &content_llvm_type);
1720+
let box_llvm_type = Type::smart_ptr(cx, &content_llvm_type);
16871721
let member_llvm_types = box_llvm_type.field_types();
16881722
assert!(box_layout_is_correct(cx, member_llvm_types, content_llvm_type));
16891723

@@ -2128,7 +2162,8 @@ fn set_debug_location(cx: &mut CrateContext, debug_location: DebugLocation) {
21282162
let metadata_node;
21292163

21302164
match debug_location {
2131-
KnownLocation { scope, line, col } => {
2165+
KnownLocation { scope, line, .. } => {
2166+
let col = 0; // Always set the column to zero like Clang and GCC
21322167
debug!("setting debug location to {} {}", line, col);
21332168
let elements = [C_i32(line as i32), C_i32(col as i32), scope, ptr::null()];
21342169
unsafe {
@@ -2244,7 +2279,14 @@ fn populate_scope_map(cx: &mut CrateContext,
22442279
})
22452280
}
22462281

2247-
walk_block(cx, fn_entry_block, &mut scope_stack, scope_map);
2282+
// Clang creates a separate scope for function bodies, so let's do this too
2283+
with_new_scope(cx,
2284+
fn_entry_block.span,
2285+
&mut scope_stack,
2286+
scope_map,
2287+
|cx, scope_stack, scope_map| {
2288+
walk_block(cx, fn_entry_block, scope_stack, scope_map);
2289+
});
22482290

22492291
// local helper functions for walking the AST.
22502292
fn with_new_scope(cx: &mut CrateContext,

branches/try2/src/librustc/middle/trans/expr.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,8 +1396,11 @@ fn trans_unary_datum(bcx: @mut Block,
13961396
revoke_clean(bcx, val);
13971397
return immediate_rvalue_bcx(bcx, val, box_ty);
13981398
} else {
1399-
let base::MallocResult { bcx, box: bx, body } =
1400-
base::malloc_general(bcx, contents_ty, heap);
1399+
let base::MallocResult {
1400+
bcx,
1401+
smart_ptr: bx,
1402+
body
1403+
} = base::malloc_general(bcx, contents_ty, heap);
14011404
add_clean_free(bcx, bx, heap);
14021405
let bcx = trans_into(bcx, contents, SaveIn(body));
14031406
revoke_clean(bcx, bx);

branches/try2/src/librustc/middle/trans/glue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ pub fn trans_struct_drop(bcx: @mut Block, t: ty::t, v0: ValueRef, dtor_did: ast:
429429
add_clean(bcx, llfld_a, fld.mt.ty);
430430
}
431431

432-
let (_, bcx) = invoke(bcx, dtor_addr, args, []);
432+
let (_, bcx) = invoke(bcx, dtor_addr, args, [], None);
433433
bcx
434434
})
435435
}

branches/try2/src/librustc/middle/trans/tvec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub fn alloc_raw(bcx: @mut Block, unit_ty: ty::t,
9898
Store(bcx, alloc, GEPi(bcx, val, [0u, abi::vec_elt_alloc]));
9999
return rslt(bcx, val);
100100
} else {
101-
let base::MallocResult {bcx, box: bx, body} =
101+
let base::MallocResult {bcx, smart_ptr: bx, body} =
102102
base::malloc_general_dyn(bcx, vecbodyty, heap, vecsize);
103103
Store(bcx, fill, GEPi(bcx, body, [0u, abi::vec_elt_fill]));
104104
Store(bcx, alloc, GEPi(bcx, body, [0u, abi::vec_elt_alloc]));

0 commit comments

Comments
 (0)