mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 00:01:16 +00:00
Add Annotation::add_to
This commit is contained in:
parent
593d634455
commit
e6a72578c1
2 changed files with 32 additions and 30 deletions
|
@ -1,4 +1,5 @@
|
||||||
use crate::env::Env;
|
use crate::env::Env;
|
||||||
|
use crate::procedure::References;
|
||||||
use crate::scope::Scope;
|
use crate::scope::Scope;
|
||||||
use roc_collections::{ImMap, MutSet, SendMap, VecMap, VecSet};
|
use roc_collections::{ImMap, MutSet, SendMap, VecMap, VecSet};
|
||||||
use roc_module::ident::{Ident, Lowercase, TagName};
|
use roc_module::ident::{Ident, Lowercase, TagName};
|
||||||
|
@ -20,6 +21,27 @@ pub struct Annotation {
|
||||||
pub aliases: SendMap<Symbol, Alias>,
|
pub aliases: SendMap<Symbol, Alias>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Annotation {
|
||||||
|
pub fn add_to(
|
||||||
|
&self,
|
||||||
|
aliases: &mut VecMap<Symbol, Alias>,
|
||||||
|
references: &mut References,
|
||||||
|
introduced_variables: &mut IntroducedVariables,
|
||||||
|
) {
|
||||||
|
for symbol in self.references.iter() {
|
||||||
|
references.insert_type_lookup(*symbol);
|
||||||
|
}
|
||||||
|
|
||||||
|
introduced_variables.union(&self.introduced_variables);
|
||||||
|
|
||||||
|
for (name, alias) in self.aliases.iter() {
|
||||||
|
if !aliases.contains_key(name) {
|
||||||
|
aliases.insert(*name, alias.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub enum NamedOrAbleVariable<'a> {
|
pub enum NamedOrAbleVariable<'a> {
|
||||||
Named(&'a NamedVariable),
|
Named(&'a NamedVariable),
|
||||||
|
|
|
@ -966,17 +966,6 @@ fn single_can_def(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_annotation_aliases(
|
|
||||||
type_annotation: &crate::annotation::Annotation,
|
|
||||||
aliases: &mut VecMap<Symbol, Alias>,
|
|
||||||
) {
|
|
||||||
for (name, alias) in type_annotation.aliases.iter() {
|
|
||||||
if !aliases.contains_key(name) {
|
|
||||||
aliases.insert(*name, alias.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Functions' references don't count in defs.
|
// Functions' references don't count in defs.
|
||||||
// See 3d5a2560057d7f25813112dfa5309956c0f9e6a9 and its
|
// See 3d5a2560057d7f25813112dfa5309956c0f9e6a9 and its
|
||||||
// parent commit for the bug this fixed!
|
// parent commit for the bug this fixed!
|
||||||
|
@ -1029,16 +1018,11 @@ fn canonicalize_pending_value_def<'a>(
|
||||||
);
|
);
|
||||||
|
|
||||||
// Record all the annotation's references in output.references.lookups
|
// Record all the annotation's references in output.references.lookups
|
||||||
|
type_annotation.add_to(
|
||||||
for symbol in type_annotation.references.iter() {
|
aliases,
|
||||||
output.references.insert_type_lookup(*symbol);
|
&mut output.references,
|
||||||
}
|
&mut output.introduced_variables,
|
||||||
|
);
|
||||||
add_annotation_aliases(&type_annotation, aliases);
|
|
||||||
|
|
||||||
output
|
|
||||||
.introduced_variables
|
|
||||||
.union(&type_annotation.introduced_variables);
|
|
||||||
|
|
||||||
pattern_to_vars_by_symbol(&mut vars_by_symbol, &loc_can_pattern.value, expr_var);
|
pattern_to_vars_by_symbol(&mut vars_by_symbol, &loc_can_pattern.value, expr_var);
|
||||||
|
|
||||||
|
@ -1131,15 +1115,11 @@ fn canonicalize_pending_value_def<'a>(
|
||||||
);
|
);
|
||||||
|
|
||||||
// Record all the annotation's references in output.references.lookups
|
// Record all the annotation's references in output.references.lookups
|
||||||
for symbol in type_annotation.references.iter() {
|
type_annotation.add_to(
|
||||||
output.references.insert_type_lookup(*symbol);
|
aliases,
|
||||||
}
|
&mut output.references,
|
||||||
|
&mut output.introduced_variables,
|
||||||
add_annotation_aliases(&type_annotation, aliases);
|
);
|
||||||
|
|
||||||
output
|
|
||||||
.introduced_variables
|
|
||||||
.union(&type_annotation.introduced_variables);
|
|
||||||
|
|
||||||
canonicalize_pending_body(
|
canonicalize_pending_body(
|
||||||
env,
|
env,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue