Skip to content

Commit e859f10

Browse files
authored
Merge pull request #571 from rustcoreutils/updates
CC cleanups
2 parents aecc388 + 4a6ae75 commit e859f10

File tree

17 files changed

+8803
-8653
lines changed

17 files changed

+8803
-8653
lines changed

bugs.md

Lines changed: 0 additions & 104 deletions
This file was deleted.

cc/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Key source files:
3434
| `parse/parser.rs` | Recursive descent parser producing AST |
3535
| `parse/ast.rs` | AST node definitions |
3636
| `types.rs` | C type system |
37+
| `strings.rs` | String interning (StringId), pre-interns keywords at startup |
38+
| `kw.rs` | Pre-interned keyword constants and tag-based classification |
3739
| `symbol.rs` | Symbol table with scope management |
3840
| `ir/linearize.rs` | AST → IR conversion, SSA construction |
3941
| `ir/mod.rs` | Intermediate representation definitions |

cc/arch/aarch64/regalloc.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,8 @@ impl RegAlloc {
10191019

10201020
// Stack slot reuse uses block-level interference checks
10211021
// (live_in/live_out from dataflow fixpoint) which are correct
1022-
// for all CFG shapes. Addr-taken syms need stable addresses.
1022+
// for all CFG shapes. Addr-taken syms need stable addresses
1023+
// because symaddr-derived pointers may escape to callees.
10231024
let reusable = !self.addr_taken_syms.contains(&interval.pseudo);
10241025

10251026
self.alloc_stack_slot(&interval, aligned_size, alignment, reusable);

cc/arch/mapping.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1838,7 +1838,7 @@ mod tests {
18381838
fn test_run_mapping_empty() {
18391839
let target = Target::new(Arch::X86_64, Os::Linux);
18401840
let types = TypeTable::new(&target);
1841-
let mut module = Module::new();
1841+
let mut module = Module::default();
18421842

18431843
run_mapping(&mut module, &types, &target);
18441844
}
@@ -1848,7 +1848,7 @@ mod tests {
18481848
let target = Target::new(Arch::X86_64, Os::Linux);
18491849
let types = TypeTable::new(&target);
18501850

1851-
let mut module = Module::new();
1851+
let mut module = Module::default();
18521852
module.add_function(make_test_func(&types));
18531853
module.add_function(make_test_func(&types));
18541854

@@ -1860,7 +1860,7 @@ mod tests {
18601860
let target = Target::new(Arch::X86_64, Os::Linux);
18611861
let types = TypeTable::new(&target);
18621862

1863-
let mut module = Module::new();
1863+
let mut module = Module::default();
18641864
module.add_function(make_test_func(&types));
18651865

18661866
run_mapping(&mut module, &types, &target);
@@ -1879,7 +1879,7 @@ mod tests {
18791879

18801880
for target in &targets {
18811881
let types = TypeTable::new(target);
1882-
let mut module = Module::new();
1882+
let mut module = Module::default();
18831883
module.add_function(make_test_func(&types));
18841884
run_mapping(&mut module, &types, target);
18851885
}
@@ -1890,7 +1890,7 @@ mod tests {
18901890
let target = Target::new(Arch::X86_64, Os::Linux);
18911891
let types = TypeTable::new(&target);
18921892

1893-
let mut module = Module::new();
1893+
let mut module = Module::default();
18941894
module.add_function(make_test_func(&types));
18951895
let orig_insn_count = module.functions[0].blocks[0].insns.len();
18961896

@@ -1905,7 +1905,7 @@ mod tests {
19051905
let target = Target::new(Arch::Aarch64, Os::Linux);
19061906
let types = TypeTable::new(&target);
19071907

1908-
let mut module = Module::new();
1908+
let mut module = Module::default();
19091909
module.add_function(make_test_func(&types));
19101910
let orig_insn_count = module.functions[0].blocks[0].insns.len();
19111911

@@ -1943,7 +1943,7 @@ mod tests {
19431943
func.add_block(bb);
19441944
func.entry = BasicBlockId(0);
19451945

1946-
let mut module = Module::new();
1946+
let mut module = Module::default();
19471947
module.add_function(func);
19481948
run_mapping(&mut module, &types, &target);
19491949

@@ -1984,7 +1984,7 @@ mod tests {
19841984
func.add_block(bb);
19851985
func.entry = BasicBlockId(0);
19861986

1987-
let mut module = Module::new();
1987+
let mut module = Module::default();
19881988
module.add_function(func);
19891989
run_mapping(&mut module, &types, &target);
19901990

cc/arch/x86_64/regalloc.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,8 @@ impl RegAlloc {
10521052

10531053
// Stack slot reuse uses block-level interference checks
10541054
// (live_in/live_out from dataflow fixpoint) which are correct
1055-
// for all CFG shapes. Addr-taken syms need stable addresses.
1055+
// for all CFG shapes. Addr-taken syms need stable addresses
1056+
// because symaddr-derived pointers may escape to callees.
10561057
let reusable = !self.addr_taken_syms.contains(&interval.pseudo);
10571058

10581059
self.alloc_stack_slot(&interval, aligned_size, alignment, reusable);

cc/cxref.rs

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,14 @@ struct SymbolRef {
7777
}
7878

7979
/// Information about a symbol across files
80-
#[derive(Debug, Clone)]
80+
#[derive(Debug, Clone, Default)]
8181
struct SymbolInfo {
8282
/// References organized by file, then by function scope
8383
/// Map: file -> Map: function (or empty for global) -> refs
8484
refs: BTreeMap<String, BTreeMap<String, BTreeSet<SymbolRef>>>,
8585
}
8686

8787
impl SymbolInfo {
88-
fn new() -> Self {
89-
Self {
90-
refs: BTreeMap::new(),
91-
}
92-
}
93-
9488
fn add_ref(&mut self, file: &str, function: &str, line: u32, is_definition: bool) {
9589
self.refs
9690
.entry(file.to_string())
@@ -105,6 +99,7 @@ impl SymbolInfo {
10599
}
106100

107101
/// Cross-reference table
102+
#[derive(Default)]
108103
struct CrossRef {
109104
/// All symbols: name -> info
110105
symbols: BTreeMap<String, SymbolInfo>,
@@ -115,14 +110,6 @@ struct CrossRef {
115110
}
116111

117112
impl CrossRef {
118-
fn new() -> Self {
119-
Self {
120-
symbols: BTreeMap::new(),
121-
current_file: String::new(),
122-
current_function: String::new(),
123-
}
124-
}
125-
126113
fn set_file(&mut self, file: &str) {
127114
self.current_file = file.to_string();
128115
}
@@ -132,17 +119,21 @@ impl CrossRef {
132119
}
133120

134121
fn add_definition(&mut self, name: &str, line: u32) {
135-
self.symbols
136-
.entry(name.to_string())
137-
.or_insert_with(SymbolInfo::new)
138-
.add_ref(&self.current_file, &self.current_function, line, true);
122+
self.symbols.entry(name.to_string()).or_default().add_ref(
123+
&self.current_file,
124+
&self.current_function,
125+
line,
126+
true,
127+
);
139128
}
140129

141130
fn add_reference(&mut self, name: &str, line: u32) {
142-
self.symbols
143-
.entry(name.to_string())
144-
.or_insert_with(SymbolInfo::new)
145-
.add_ref(&self.current_file, &self.current_function, line, false);
131+
self.symbols.entry(name.to_string()).or_default().add_ref(
132+
&self.current_file,
133+
&self.current_function,
134+
line,
135+
false,
136+
);
146137
}
147138
}
148139

@@ -561,7 +552,7 @@ fn main() -> ExitCode {
561552
}
562553

563554
// Build cross-reference
564-
let mut xref = CrossRef::new();
555+
let mut xref = CrossRef::default();
565556
let mut streams = StreamTable::new();
566557

567558
for file in &args.files {
@@ -586,7 +577,7 @@ fn main() -> ExitCode {
586577
// In non-combined mode, print and reset after each file
587578
if !args.combined {
588579
print_xref(&xref, args.width, args.silent, &mut *output_file);
589-
xref = CrossRef::new();
580+
xref = CrossRef::default();
590581
}
591582
}
592583
_ => {

0 commit comments

Comments
 (0)