2018-10-03 16:56:24 +02:00
|
|
|
use rustc_codegen_ssa::debuginfo::{FunctionDebugContext, FunctionDebugContextData, MirDebugScope};
|
2015-04-29 18:14:37 +12:00
|
|
|
use super::metadata::file_metadata;
|
2016-04-07 22:35:11 +03:00
|
|
|
use super::utils::{DIB, span_start};
|
2015-04-29 18:14:37 +12:00
|
|
|
|
2019-02-18 03:58:58 +09:00
|
|
|
use crate::llvm;
|
|
|
|
use crate::llvm::debuginfo::{DIScope, DISubprogram};
|
|
|
|
use crate::common::CodegenCx;
|
2018-05-28 14:16:09 +03:00
|
|
|
use rustc::mir::{Mir, SourceScope};
|
2015-04-29 18:14:37 +12:00
|
|
|
|
|
|
|
use libc::c_uint;
|
2016-04-07 22:35:11 +03:00
|
|
|
|
2016-08-16 17:41:38 +03:00
|
|
|
use syntax_pos::Pos;
|
2015-07-31 00:04:06 -07:00
|
|
|
|
Merge indexed_set.rs into bitvec.rs, and rename it bit_set.rs.
Currently we have two files implementing bitsets (and 2D bit matrices).
This commit combines them into one, taking the best features from each.
This involves renaming a lot of things. The high level changes are as
follows.
- bitvec.rs --> bit_set.rs
- indexed_set.rs --> (removed)
- BitArray + IdxSet --> BitSet (merged, see below)
- BitVector --> GrowableBitSet
- {,Sparse,Hybrid}IdxSet --> {,Sparse,Hybrid}BitSet
- BitMatrix --> BitMatrix
- SparseBitMatrix --> SparseBitMatrix
The changes within the bitset types themselves are as follows.
```
OLD OLD NEW
BitArray<C> IdxSet<T> BitSet<T>
-------- ------ ------
grow - grow
new - (remove)
new_empty new_empty new_empty
new_filled new_filled new_filled
- to_hybrid to_hybrid
clear clear clear
set_up_to set_up_to set_up_to
clear_above - clear_above
count - count
contains(T) contains(&T) contains(T)
contains_all - superset
is_empty - is_empty
insert(T) add(&T) insert(T)
insert_all - insert_all()
remove(T) remove(&T) remove(T)
words words words
words_mut words_mut words_mut
- overwrite overwrite
merge union union
- subtract subtract
- intersect intersect
iter iter iter
```
In general, when choosing names I went with:
- names that are more obvious (e.g. `BitSet` over `IdxSet`).
- names that are more like the Rust libraries (e.g. `T` over `C`,
`insert` over `add`);
- names that are more set-like (e.g. `union` over `merge`, `superset`
over `contains_all`, `domain_size` over `num_bits`).
Also, using `T` for index arguments seems more sensible than `&T` --
even though the latter is standard in Rust collection types -- because
indices are always copyable. It also results in fewer `&` and `*`
sigils in practice.
2018-09-14 15:07:25 +10:00
|
|
|
use rustc_data_structures::bit_set::BitSet;
|
2016-06-07 17:28:36 +03:00
|
|
|
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
|
2015-04-29 18:14:37 +12:00
|
|
|
|
2016-08-24 19:34:31 -07:00
|
|
|
use syntax_pos::BytePos;
|
|
|
|
|
2019-02-08 14:53:55 +01:00
|
|
|
/// Produces DIScope DIEs for each MIR Scope which has variables defined in it.
|
2016-04-07 22:35:11 +03:00
|
|
|
/// If debuginfo is disabled, the returned vector is empty.
|
2018-07-17 18:26:58 +03:00
|
|
|
pub fn create_mir_scopes(
|
|
|
|
cx: &CodegenCx<'ll, '_>,
|
2019-02-25 08:40:18 +01:00
|
|
|
mir: &Mir<'_>,
|
2018-09-20 15:47:22 +02:00
|
|
|
debug_context: &FunctionDebugContext<&'ll DISubprogram>,
|
|
|
|
) -> IndexVec<SourceScope, MirDebugScope<&'ll DIScope>> {
|
2016-08-24 19:34:31 -07:00
|
|
|
let null_scope = MirDebugScope {
|
2018-06-27 13:12:47 +03:00
|
|
|
scope_metadata: None,
|
2016-08-24 19:34:31 -07:00
|
|
|
file_start_pos: BytePos(0),
|
|
|
|
file_end_pos: BytePos(0)
|
|
|
|
};
|
2018-05-28 14:16:09 +03:00
|
|
|
let mut scopes = IndexVec::from_elem(null_scope, &mir.source_scopes);
|
2016-04-07 22:35:11 +03:00
|
|
|
|
2017-04-24 19:01:19 +02:00
|
|
|
let debug_context = match *debug_context {
|
|
|
|
FunctionDebugContext::RegularContext(ref data) => data,
|
2016-04-07 22:35:11 +03:00
|
|
|
FunctionDebugContext::DebugInfoDisabled |
|
|
|
|
FunctionDebugContext::FunctionWithoutDebugInfo => {
|
|
|
|
return scopes;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Find all the scopes with variables defined in them.
|
Merge indexed_set.rs into bitvec.rs, and rename it bit_set.rs.
Currently we have two files implementing bitsets (and 2D bit matrices).
This commit combines them into one, taking the best features from each.
This involves renaming a lot of things. The high level changes are as
follows.
- bitvec.rs --> bit_set.rs
- indexed_set.rs --> (removed)
- BitArray + IdxSet --> BitSet (merged, see below)
- BitVector --> GrowableBitSet
- {,Sparse,Hybrid}IdxSet --> {,Sparse,Hybrid}BitSet
- BitMatrix --> BitMatrix
- SparseBitMatrix --> SparseBitMatrix
The changes within the bitset types themselves are as follows.
```
OLD OLD NEW
BitArray<C> IdxSet<T> BitSet<T>
-------- ------ ------
grow - grow
new - (remove)
new_empty new_empty new_empty
new_filled new_filled new_filled
- to_hybrid to_hybrid
clear clear clear
set_up_to set_up_to set_up_to
clear_above - clear_above
count - count
contains(T) contains(&T) contains(T)
contains_all - superset
is_empty - is_empty
insert(T) add(&T) insert(T)
insert_all - insert_all()
remove(T) remove(&T) remove(T)
words words words
words_mut words_mut words_mut
- overwrite overwrite
merge union union
- subtract subtract
- intersect intersect
iter iter iter
```
In general, when choosing names I went with:
- names that are more obvious (e.g. `BitSet` over `IdxSet`).
- names that are more like the Rust libraries (e.g. `T` over `C`,
`insert` over `add`);
- names that are more set-like (e.g. `union` over `merge`, `superset`
over `contains_all`, `domain_size` over `num_bits`).
Also, using `T` for index arguments seems more sensible than `&T` --
even though the latter is standard in Rust collection types -- because
indices are always copyable. It also results in fewer `&` and `*`
sigils in practice.
2018-09-14 15:07:25 +10:00
|
|
|
let mut has_variables = BitSet::new_empty(mir.source_scopes.len());
|
2016-09-26 22:50:03 +02:00
|
|
|
for var in mir.vars_iter() {
|
2016-09-25 01:38:27 +02:00
|
|
|
let decl = &mir.local_decls[var];
|
2018-07-22 19:23:39 +03:00
|
|
|
has_variables.insert(decl.visibility_scope);
|
2016-04-07 22:35:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Instantiate all scopes.
|
2018-05-28 14:16:09 +03:00
|
|
|
for idx in 0..mir.source_scopes.len() {
|
|
|
|
let scope = SourceScope::new(idx);
|
2018-01-05 07:04:08 +02:00
|
|
|
make_mir_scope(cx, &mir, &has_variables, debug_context, scope, &mut scopes);
|
2016-04-07 22:35:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
scopes
|
|
|
|
}
|
|
|
|
|
2018-07-04 16:36:49 +03:00
|
|
|
fn make_mir_scope(cx: &CodegenCx<'ll, '_>,
|
2019-02-25 08:40:18 +01:00
|
|
|
mir: &Mir<'_>,
|
Merge indexed_set.rs into bitvec.rs, and rename it bit_set.rs.
Currently we have two files implementing bitsets (and 2D bit matrices).
This commit combines them into one, taking the best features from each.
This involves renaming a lot of things. The high level changes are as
follows.
- bitvec.rs --> bit_set.rs
- indexed_set.rs --> (removed)
- BitArray + IdxSet --> BitSet (merged, see below)
- BitVector --> GrowableBitSet
- {,Sparse,Hybrid}IdxSet --> {,Sparse,Hybrid}BitSet
- BitMatrix --> BitMatrix
- SparseBitMatrix --> SparseBitMatrix
The changes within the bitset types themselves are as follows.
```
OLD OLD NEW
BitArray<C> IdxSet<T> BitSet<T>
-------- ------ ------
grow - grow
new - (remove)
new_empty new_empty new_empty
new_filled new_filled new_filled
- to_hybrid to_hybrid
clear clear clear
set_up_to set_up_to set_up_to
clear_above - clear_above
count - count
contains(T) contains(&T) contains(T)
contains_all - superset
is_empty - is_empty
insert(T) add(&T) insert(T)
insert_all - insert_all()
remove(T) remove(&T) remove(T)
words words words
words_mut words_mut words_mut
- overwrite overwrite
merge union union
- subtract subtract
- intersect intersect
iter iter iter
```
In general, when choosing names I went with:
- names that are more obvious (e.g. `BitSet` over `IdxSet`).
- names that are more like the Rust libraries (e.g. `T` over `C`,
`insert` over `add`);
- names that are more set-like (e.g. `union` over `merge`, `superset`
over `contains_all`, `domain_size` over `num_bits`).
Also, using `T` for index arguments seems more sensible than `&T` --
even though the latter is standard in Rust collection types -- because
indices are always copyable. It also results in fewer `&` and `*`
sigils in practice.
2018-09-14 15:07:25 +10:00
|
|
|
has_variables: &BitSet<SourceScope>,
|
2018-09-20 15:47:22 +02:00
|
|
|
debug_context: &FunctionDebugContextData<&'ll DISubprogram>,
|
2018-05-28 14:16:09 +03:00
|
|
|
scope: SourceScope,
|
2018-09-20 15:47:22 +02:00
|
|
|
scopes: &mut IndexVec<SourceScope, MirDebugScope<&'ll DIScope>>) {
|
2016-08-24 19:34:31 -07:00
|
|
|
if scopes[scope].is_valid() {
|
2016-04-07 22:35:11 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-28 14:16:09 +03:00
|
|
|
let scope_data = &mir.source_scopes[scope];
|
2016-04-07 22:35:11 +03:00
|
|
|
let parent_scope = if let Some(parent) = scope_data.parent_scope {
|
2018-01-05 07:04:08 +02:00
|
|
|
make_mir_scope(cx, mir, has_variables, debug_context, parent, scopes);
|
2016-06-07 17:28:36 +03:00
|
|
|
scopes[parent]
|
2016-04-07 22:35:11 +03:00
|
|
|
} else {
|
|
|
|
// The root is the function itself.
|
2018-01-05 07:04:08 +02:00
|
|
|
let loc = span_start(cx, mir.span);
|
2016-08-24 19:34:31 -07:00
|
|
|
scopes[scope] = MirDebugScope {
|
2018-07-04 16:36:49 +03:00
|
|
|
scope_metadata: Some(debug_context.fn_metadata),
|
2016-08-24 19:34:31 -07:00
|
|
|
file_start_pos: loc.file.start_pos,
|
|
|
|
file_end_pos: loc.file.end_pos,
|
|
|
|
};
|
2016-04-07 22:35:11 +03:00
|
|
|
return;
|
|
|
|
};
|
|
|
|
|
2018-07-22 19:23:39 +03:00
|
|
|
if !has_variables.contains(scope) {
|
2016-04-07 22:35:11 +03:00
|
|
|
// Do not create a DIScope if there are no variables
|
|
|
|
// defined in this MIR Scope, to avoid debuginfo bloat.
|
2016-04-16 21:51:26 +03:00
|
|
|
|
|
|
|
// However, we don't skip creating a nested scope if
|
|
|
|
// our parent is the root, because we might want to
|
|
|
|
// put arguments in the root and not have shadowing.
|
2018-07-04 16:36:49 +03:00
|
|
|
if parent_scope.scope_metadata.unwrap() != debug_context.fn_metadata {
|
2016-06-07 17:28:36 +03:00
|
|
|
scopes[scope] = parent_scope;
|
2016-04-16 21:51:26 +03:00
|
|
|
return;
|
2016-04-07 22:35:11 +03:00
|
|
|
}
|
2016-04-16 21:51:26 +03:00
|
|
|
}
|
|
|
|
|
2018-01-05 07:04:08 +02:00
|
|
|
let loc = span_start(cx, scope_data.span);
|
|
|
|
let file_metadata = file_metadata(cx,
|
2017-04-24 19:01:19 +02:00
|
|
|
&loc.file.name,
|
|
|
|
debug_context.defining_crate);
|
|
|
|
|
2016-08-24 19:34:31 -07:00
|
|
|
let scope_metadata = unsafe {
|
2018-07-04 16:36:49 +03:00
|
|
|
Some(llvm::LLVMRustDIBuilderCreateLexicalBlock(
|
2018-01-05 07:04:08 +02:00
|
|
|
DIB(cx),
|
2018-07-04 16:36:49 +03:00
|
|
|
parent_scope.scope_metadata.unwrap(),
|
2016-04-16 21:51:26 +03:00
|
|
|
file_metadata,
|
|
|
|
loc.line as c_uint,
|
2018-06-27 13:12:47 +03:00
|
|
|
loc.col.to_usize() as c_uint))
|
2016-04-07 22:35:11 +03:00
|
|
|
};
|
2016-08-24 19:34:31 -07:00
|
|
|
scopes[scope] = MirDebugScope {
|
2017-08-06 22:54:09 -07:00
|
|
|
scope_metadata,
|
2016-08-24 19:34:31 -07:00
|
|
|
file_start_pos: loc.file.start_pos,
|
|
|
|
file_end_pos: loc.file.end_pos,
|
|
|
|
};
|
2016-04-07 22:35:11 +03:00
|
|
|
}
|