mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 00:01:16 +00:00
be smarter about returning References
This commit is contained in:
parent
9866feeb5d
commit
4668cf506b
1 changed files with 38 additions and 64 deletions
|
@ -528,11 +528,7 @@ pub(crate) fn canonicalize_defs<'a>(
|
||||||
|
|
||||||
defs.push(Some(temp_output.def));
|
defs.push(Some(temp_output.def));
|
||||||
|
|
||||||
def_ordering.insert_symbol_references(
|
def_ordering.insert_symbol_references(def_id as u32, &temp_output.references)
|
||||||
def_id as u32,
|
|
||||||
&temp_output.references,
|
|
||||||
temp_output.closure_references,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is now mostly responsible for adding type names and ability members
|
// this is now mostly responsible for adding type names and ability members
|
||||||
|
@ -740,13 +736,12 @@ impl DefOrdering {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn insert_symbol_references(
|
fn insert_symbol_references(&mut self, def_id: u32, def_references: &DefReferences) {
|
||||||
&mut self,
|
match def_references {
|
||||||
def_id: u32,
|
DefReferences::Value(references) => {
|
||||||
references: &References,
|
let it = references.value_lookups().chain(references.calls());
|
||||||
closure_references: Option<References>,
|
|
||||||
) {
|
for referenced in it {
|
||||||
for referenced in references.value_lookups() {
|
|
||||||
if let Some(ref_id) = self.get_id(*referenced) {
|
if let Some(ref_id) = self.get_id(*referenced) {
|
||||||
self.references
|
self.references
|
||||||
.set_row_col(def_id as usize, ref_id as usize, true);
|
.set_row_col(def_id as usize, ref_id as usize, true);
|
||||||
|
@ -755,30 +750,19 @@ impl DefOrdering {
|
||||||
.set_row_col(def_id as usize, ref_id as usize, true);
|
.set_row_col(def_id as usize, ref_id as usize, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for referenced in references.calls() {
|
|
||||||
if let Some(ref_id) = self.get_id(*referenced) {
|
|
||||||
self.references
|
|
||||||
.set_row_col(def_id as usize, ref_id as usize, true);
|
|
||||||
|
|
||||||
self.direct_references
|
|
||||||
.set_row_col(def_id as usize, ref_id as usize, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
DefReferences::Function(references) => {
|
||||||
|
let it = references.value_lookups().chain(references.calls());
|
||||||
|
|
||||||
if let Some(references) = closure_references {
|
for referenced in it {
|
||||||
for referenced in references.value_lookups() {
|
|
||||||
if let Some(ref_id) = self.get_id(*referenced) {
|
if let Some(ref_id) = self.get_id(*referenced) {
|
||||||
self.references
|
self.references
|
||||||
.set_row_col(def_id as usize, ref_id as usize, true);
|
.set_row_col(def_id as usize, ref_id as usize, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for referenced in references.calls() {
|
|
||||||
if let Some(ref_id) = self.get_id(*referenced) {
|
|
||||||
self.references
|
|
||||||
.set_row_col(def_id as usize, ref_id as usize, true);
|
|
||||||
}
|
}
|
||||||
|
DefReferences::Empty => {
|
||||||
|
// produced by annotations without bodies
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1188,11 +1172,19 @@ fn add_annotation_aliases(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Functions' references don't count in defs.
|
||||||
|
// See 3d5a2560057d7f25813112dfa5309956c0f9e6a9 and its
|
||||||
|
// parent commit for the bug this fixed!
|
||||||
|
enum DefReferences {
|
||||||
|
Value(References),
|
||||||
|
Function(References),
|
||||||
|
Empty,
|
||||||
|
}
|
||||||
|
|
||||||
struct TempOutput {
|
struct TempOutput {
|
||||||
output: Output,
|
output: Output,
|
||||||
def: Def,
|
def: Def,
|
||||||
references: References,
|
references: DefReferences,
|
||||||
closure_references: Option<References>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO trim down these arguments!
|
// TODO trim down these arguments!
|
||||||
|
@ -1309,8 +1301,7 @@ fn canonicalize_pending_value_def_new<'a>(
|
||||||
|
|
||||||
TempOutput {
|
TempOutput {
|
||||||
output,
|
output,
|
||||||
references: References::default(),
|
references: DefReferences::Empty,
|
||||||
closure_references: None,
|
|
||||||
def,
|
def,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1410,13 +1401,6 @@ fn canonicalize_pending_value_def_new<'a>(
|
||||||
loc_body: body.clone(),
|
loc_body: body.clone(),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Functions' references don't count in defs.
|
|
||||||
// See 3d5a2560057d7f25813112dfa5309956c0f9e6a9 and its
|
|
||||||
// parent commit for the bug this fixed!
|
|
||||||
//
|
|
||||||
// NOTE: this is where we lose reference information for closure bodies.
|
|
||||||
let refs = References::new();
|
|
||||||
|
|
||||||
let def = single_can_def(
|
let def = single_can_def(
|
||||||
loc_can_pattern,
|
loc_can_pattern,
|
||||||
loc_can_expr,
|
loc_can_expr,
|
||||||
|
@ -1429,8 +1413,7 @@ fn canonicalize_pending_value_def_new<'a>(
|
||||||
|
|
||||||
TempOutput {
|
TempOutput {
|
||||||
output,
|
output,
|
||||||
references: refs,
|
references: DefReferences::Function(closure_references),
|
||||||
closure_references: Some(closure_references),
|
|
||||||
def,
|
def,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1448,8 +1431,7 @@ fn canonicalize_pending_value_def_new<'a>(
|
||||||
|
|
||||||
TempOutput {
|
TempOutput {
|
||||||
output,
|
output,
|
||||||
references: refs,
|
references: DefReferences::Value(refs),
|
||||||
closure_references: None,
|
|
||||||
def,
|
def,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1468,8 +1450,7 @@ fn canonicalize_pending_value_def_new<'a>(
|
||||||
|
|
||||||
TempOutput {
|
TempOutput {
|
||||||
output,
|
output,
|
||||||
references: refs,
|
references: DefReferences::Value(refs),
|
||||||
closure_references: None,
|
|
||||||
def,
|
def,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1549,11 +1530,6 @@ fn canonicalize_pending_value_def_new<'a>(
|
||||||
loc_body: body.clone(),
|
loc_body: body.clone(),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Functions' references don't count in defs.
|
|
||||||
// See 3d5a2560057d7f25813112dfa5309956c0f9e6a9 and its
|
|
||||||
// parent commit for the bug this fixed!
|
|
||||||
let refs = References::new();
|
|
||||||
|
|
||||||
let def = single_can_def(
|
let def = single_can_def(
|
||||||
loc_can_pattern,
|
loc_can_pattern,
|
||||||
loc_can_expr,
|
loc_can_expr,
|
||||||
|
@ -1566,8 +1542,7 @@ fn canonicalize_pending_value_def_new<'a>(
|
||||||
|
|
||||||
TempOutput {
|
TempOutput {
|
||||||
output,
|
output,
|
||||||
references: refs,
|
references: DefReferences::Function(closure_references),
|
||||||
closure_references: Some(closure_references),
|
|
||||||
def,
|
def,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1585,8 +1560,7 @@ fn canonicalize_pending_value_def_new<'a>(
|
||||||
|
|
||||||
TempOutput {
|
TempOutput {
|
||||||
output,
|
output,
|
||||||
references: refs,
|
references: DefReferences::Value(refs),
|
||||||
closure_references: None,
|
|
||||||
def,
|
def,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue