mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 00:01:16 +00:00
move identids into Scope
This commit is contained in:
parent
37cb9279f5
commit
7fb5b23fb0
10 changed files with 123 additions and 181 deletions
|
@ -277,7 +277,7 @@ fn make_apply_symbol(
|
|||
}
|
||||
}
|
||||
} else {
|
||||
match env.qualified_lookup(module_name, ident, region) {
|
||||
match env.qualified_lookup(scope, module_name, ident, region) {
|
||||
Ok(symbol) => Ok(symbol),
|
||||
Err(problem) => {
|
||||
// Either the module wasn't imported, or
|
||||
|
@ -579,7 +579,7 @@ fn can_annotation_help(
|
|||
vars: loc_vars,
|
||||
},
|
||||
) => {
|
||||
let symbol = match scope.introduce(name.value.into(), &mut env.ident_ids, region) {
|
||||
let symbol = match scope.introduce(name.value.into(), region) {
|
||||
Ok(symbol) => symbol,
|
||||
|
||||
Err((original_region, shadow, _new_symbol)) => {
|
||||
|
|
|
@ -243,7 +243,7 @@ pub(crate) fn canonicalize_defs<'a>(
|
|||
}
|
||||
|
||||
if cfg!(debug_assertions) {
|
||||
env.home.register_debug_idents(&env.ident_ids);
|
||||
scope.register_debug_idents();
|
||||
}
|
||||
|
||||
enum TypeDef<'a> {
|
||||
|
@ -278,7 +278,8 @@ pub(crate) fn canonicalize_defs<'a>(
|
|||
} => {
|
||||
let referenced_symbols = crate::annotation::find_type_def_symbols(
|
||||
env.home,
|
||||
&mut env.ident_ids,
|
||||
// TODO IDENT_IDS
|
||||
&mut scope.ident_ids,
|
||||
&ann.value,
|
||||
);
|
||||
|
||||
|
@ -295,7 +296,8 @@ pub(crate) fn canonicalize_defs<'a>(
|
|||
// definition.
|
||||
referenced_symbols.extend(crate::annotation::find_type_def_symbols(
|
||||
env.home,
|
||||
&mut env.ident_ids,
|
||||
// TODO IDENT_IDS
|
||||
&mut scope.ident_ids,
|
||||
&member.typ.value,
|
||||
));
|
||||
}
|
||||
|
@ -569,8 +571,7 @@ fn resolve_abilities<'a>(
|
|||
let name_region = member.name.region;
|
||||
let member_name = member.name.extract_spaces().item;
|
||||
|
||||
let member_sym =
|
||||
match scope.introduce(member_name.into(), &mut env.ident_ids, name_region) {
|
||||
let member_sym = match scope.introduce(member_name.into(), name_region) {
|
||||
Ok(sym) => sym,
|
||||
Err((original_region, shadow, _new_symbol)) => {
|
||||
env.problem(roc_problem::can::Problem::Shadowing {
|
||||
|
@ -1072,7 +1073,7 @@ fn canonicalize_pending_value_def<'a>(
|
|||
region: loc_ann.region,
|
||||
}
|
||||
} else {
|
||||
let symbol = env.gen_unique_symbol();
|
||||
let symbol = scope.gen_unique_symbol();
|
||||
|
||||
// generate a fake pattern for each argument. this makes signatures
|
||||
// that are functions only crash when they are applied.
|
||||
|
@ -1359,11 +1360,7 @@ fn to_pending_type_def<'a>(
|
|||
|
||||
let region = Region::span_across(&name.region, &ann.region);
|
||||
|
||||
match scope.introduce_without_shadow_symbol(
|
||||
&Ident::from(name.value),
|
||||
&mut env.ident_ids,
|
||||
region,
|
||||
) {
|
||||
match scope.introduce_without_shadow_symbol(&Ident::from(name.value), region) {
|
||||
Ok(symbol) => {
|
||||
let mut can_rigids: Vec<Loc<Lowercase>> = Vec::with_capacity(vars.len());
|
||||
|
||||
|
@ -1438,11 +1435,9 @@ fn to_pending_type_def<'a>(
|
|||
members,
|
||||
loc_has: _,
|
||||
} => {
|
||||
let name = match scope.introduce_without_shadow_symbol(
|
||||
&Ident::from(name.value),
|
||||
&mut env.ident_ids,
|
||||
name.region,
|
||||
) {
|
||||
let name = match scope
|
||||
.introduce_without_shadow_symbol(&Ident::from(name.value), name.region)
|
||||
{
|
||||
Ok(symbol) => Loc::at(name.region, symbol),
|
||||
Err((original_region, shadowed_symbol)) => {
|
||||
env.problem(Problem::Shadowing {
|
||||
|
|
|
@ -87,15 +87,13 @@ pub(crate) fn build_effect_builtins(
|
|||
// show up with their name. We have to register them like below to make the names show up in
|
||||
// debug prints
|
||||
if false {
|
||||
env.home.register_debug_idents(&env.ident_ids);
|
||||
scope.register_debug_idents();
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! new_symbol {
|
||||
($scope:expr, $env:expr, $name:expr) => {{
|
||||
$scope
|
||||
.introduce($name.into(), &mut $env.ident_ids, Region::zero())
|
||||
.unwrap()
|
||||
$scope.introduce($name.into(), Region::zero()).unwrap()
|
||||
}};
|
||||
}
|
||||
|
||||
|
@ -109,29 +107,17 @@ fn build_effect_always(
|
|||
|
||||
let value_symbol = {
|
||||
scope
|
||||
.introduce(
|
||||
"effect_always_value".into(),
|
||||
&mut env.ident_ids,
|
||||
Region::zero(),
|
||||
)
|
||||
.introduce("effect_always_value".into(), Region::zero())
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
let inner_closure_symbol = {
|
||||
scope
|
||||
.introduce(
|
||||
"effect_always_inner".into(),
|
||||
&mut env.ident_ids,
|
||||
Region::zero(),
|
||||
)
|
||||
.introduce("effect_always_inner".into(), Region::zero())
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
let always_symbol = {
|
||||
scope
|
||||
.introduce("always".into(), &mut env.ident_ids, Region::zero())
|
||||
.unwrap()
|
||||
};
|
||||
let always_symbol = { scope.introduce("always".into(), Region::zero()).unwrap() };
|
||||
|
||||
// \{} -> value
|
||||
let const_closure = {
|
||||
|
@ -247,29 +233,17 @@ fn build_effect_map(
|
|||
|
||||
let thunk_symbol = {
|
||||
scope
|
||||
.introduce(
|
||||
"effect_map_thunk".into(),
|
||||
&mut env.ident_ids,
|
||||
Region::zero(),
|
||||
)
|
||||
.introduce("effect_map_thunk".into(), Region::zero())
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
let mapper_symbol = {
|
||||
scope
|
||||
.introduce(
|
||||
"effect_map_mapper".into(),
|
||||
&mut env.ident_ids,
|
||||
Region::zero(),
|
||||
)
|
||||
.introduce("effect_map_mapper".into(), Region::zero())
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
let map_symbol = {
|
||||
scope
|
||||
.introduce("map".into(), &mut env.ident_ids, Region::zero())
|
||||
.unwrap()
|
||||
};
|
||||
let map_symbol = { scope.introduce("map".into(), Region::zero()).unwrap() };
|
||||
|
||||
// `thunk {}`
|
||||
let force_thunk_call = {
|
||||
|
@ -299,11 +273,7 @@ fn build_effect_map(
|
|||
|
||||
let inner_closure_symbol = {
|
||||
scope
|
||||
.introduce(
|
||||
"effect_map_inner".into(),
|
||||
&mut env.ident_ids,
|
||||
Region::zero(),
|
||||
)
|
||||
.introduce("effect_map_inner".into(), Region::zero())
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
|
@ -457,29 +427,17 @@ fn build_effect_after(
|
|||
|
||||
let thunk_symbol = {
|
||||
scope
|
||||
.introduce(
|
||||
"effect_after_thunk".into(),
|
||||
&mut env.ident_ids,
|
||||
Region::zero(),
|
||||
)
|
||||
.introduce("effect_after_thunk".into(), Region::zero())
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
let to_effect_symbol = {
|
||||
scope
|
||||
.introduce(
|
||||
"effect_after_toEffect".into(),
|
||||
&mut env.ident_ids,
|
||||
Region::zero(),
|
||||
)
|
||||
.introduce("effect_after_toEffect".into(), Region::zero())
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
let after_symbol = {
|
||||
scope
|
||||
.introduce("after".into(), &mut env.ident_ids, Region::zero())
|
||||
.unwrap()
|
||||
};
|
||||
let after_symbol = { scope.introduce("after".into(), Region::zero()).unwrap() };
|
||||
|
||||
// `thunk {}`
|
||||
let force_thunk_call = {
|
||||
|
@ -762,17 +720,9 @@ fn build_effect_forever(
|
|||
//
|
||||
// Making `foreverInner` perfectly tail-call optimizable
|
||||
|
||||
let forever_symbol = {
|
||||
scope
|
||||
.introduce("forever".into(), &mut env.ident_ids, Region::zero())
|
||||
.unwrap()
|
||||
};
|
||||
let forever_symbol = { scope.introduce("forever".into(), Region::zero()).unwrap() };
|
||||
|
||||
let effect = {
|
||||
scope
|
||||
.introduce("effect".into(), &mut env.ident_ids, Region::zero())
|
||||
.unwrap()
|
||||
};
|
||||
let effect = { scope.introduce("effect".into(), Region::zero()).unwrap() };
|
||||
|
||||
let body =
|
||||
build_effect_forever_body(env, scope, effect_symbol, forever_symbol, effect, var_store);
|
||||
|
@ -860,7 +810,7 @@ fn build_effect_forever_body(
|
|||
) -> Expr {
|
||||
let closure_name = {
|
||||
scope
|
||||
.introduce("forever_inner".into(), &mut env.ident_ids, Region::zero())
|
||||
.introduce("forever_inner".into(), Region::zero())
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
|
@ -891,17 +841,9 @@ fn build_effect_forever_inner_body(
|
|||
effect: Symbol,
|
||||
var_store: &mut VarStore,
|
||||
) -> Expr {
|
||||
let thunk1_symbol = {
|
||||
scope
|
||||
.introduce("thunk1".into(), &mut env.ident_ids, Region::zero())
|
||||
.unwrap()
|
||||
};
|
||||
let thunk1_symbol = { scope.introduce("thunk1".into(), Region::zero()).unwrap() };
|
||||
|
||||
let thunk2_symbol = {
|
||||
scope
|
||||
.introduce("thunk2".into(), &mut env.ident_ids, Region::zero())
|
||||
.unwrap()
|
||||
};
|
||||
let thunk2_symbol = { scope.introduce("thunk2".into(), Region::zero()).unwrap() };
|
||||
|
||||
// @Effect thunk1 = effect
|
||||
let thunk_from_effect = {
|
||||
|
@ -1138,7 +1080,7 @@ fn build_effect_loop_body(
|
|||
) -> Expr {
|
||||
let closure_name = {
|
||||
scope
|
||||
.introduce("loop_inner".into(), &mut env.ident_ids, Region::zero())
|
||||
.introduce("loop_inner".into(), Region::zero())
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
|
@ -1352,9 +1294,7 @@ pub fn build_host_exposed_def(
|
|||
|
||||
let arg_symbol = {
|
||||
let ident = name.clone().into();
|
||||
scope
|
||||
.introduce(ident, &mut env.ident_ids, Region::zero())
|
||||
.unwrap()
|
||||
scope.introduce(ident, Region::zero()).unwrap()
|
||||
};
|
||||
|
||||
let arg_var = var_store.fresh();
|
||||
|
@ -1376,9 +1316,7 @@ pub fn build_host_exposed_def(
|
|||
let name = format!("effect_closure_{}", ident);
|
||||
|
||||
let ident = name.into();
|
||||
scope
|
||||
.introduce(ident, &mut env.ident_ids, Region::zero())
|
||||
.unwrap()
|
||||
scope.introduce(ident, Region::zero()).unwrap()
|
||||
};
|
||||
|
||||
let effect_closure = Expr::Closure(ClosureData {
|
||||
|
@ -1433,9 +1371,7 @@ pub fn build_host_exposed_def(
|
|||
let name = format!("effect_closure_{}", ident);
|
||||
|
||||
let ident = name.into();
|
||||
scope
|
||||
.introduce(ident, &mut env.ident_ids, Region::zero())
|
||||
.unwrap()
|
||||
scope.introduce(ident, Region::zero()).unwrap()
|
||||
};
|
||||
|
||||
let empty_record_pattern = Pattern::RecordDestructure {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use crate::procedure::References;
|
||||
use crate::scope::Scope;
|
||||
use roc_collections::{MutMap, VecSet};
|
||||
use roc_module::ident::{Ident, Lowercase, ModuleName};
|
||||
use roc_module::symbol::{IdentIds, IdentIdsByModule, ModuleId, ModuleIds, Symbol};
|
||||
|
@ -32,7 +33,7 @@ pub struct Env<'a> {
|
|||
|
||||
pub top_level_symbols: VecSet<Symbol>,
|
||||
|
||||
pub ident_ids: IdentIds,
|
||||
ident_ids: IdentIds,
|
||||
}
|
||||
|
||||
impl<'a> Env<'a> {
|
||||
|
@ -59,6 +60,7 @@ impl<'a> Env<'a> {
|
|||
/// Returns Err if the symbol resolved, but it was not exposed by the given module
|
||||
pub fn qualified_lookup(
|
||||
&mut self,
|
||||
scope: &Scope,
|
||||
module_name_str: &str,
|
||||
ident: &str,
|
||||
region: Region,
|
||||
|
@ -79,7 +81,7 @@ impl<'a> Env<'a> {
|
|||
// You can do qualified lookups on your own module, e.g.
|
||||
// if I'm in the Foo module, I can do a `Foo.bar` lookup.
|
||||
if module_id == self.home {
|
||||
match self.ident_ids.get_id(&ident) {
|
||||
match scope.ident_ids.get_id(&ident) {
|
||||
Some(ident_id) => {
|
||||
let symbol = Symbol::new(module_id, ident_id);
|
||||
|
||||
|
@ -97,7 +99,8 @@ impl<'a> Env<'a> {
|
|||
value: ident,
|
||||
region,
|
||||
},
|
||||
self.ident_ids
|
||||
scope
|
||||
.ident_ids
|
||||
.ident_strs()
|
||||
.map(|(_, string)| string.into())
|
||||
.collect(),
|
||||
|
@ -167,6 +170,7 @@ impl<'a> Env<'a> {
|
|||
///
|
||||
/// This is used, for example, during canonicalization of an Expr::Closure
|
||||
/// to generate a unique symbol to refer to that closure.
|
||||
// TODO IDENT_IDS
|
||||
pub fn gen_unique_symbol(&mut self) -> Symbol {
|
||||
let ident_id = self.ident_ids.gen_unique();
|
||||
|
||||
|
|
|
@ -407,6 +407,7 @@ pub fn canonicalize_expr<'a>(
|
|||
fields,
|
||||
update: loc_update,
|
||||
} => {
|
||||
dbg!(&loc_update);
|
||||
let (can_update, update_out) =
|
||||
canonicalize_expr(env, var_store, scope, loc_update.region, &loc_update.value);
|
||||
if let Var(symbol) = &can_update.value {
|
||||
|
@ -437,6 +438,7 @@ pub fn canonicalize_expr<'a>(
|
|||
),
|
||||
}
|
||||
} else {
|
||||
dbg!(&can_update.value);
|
||||
// only (optionally qualified) variables can be updated, not arbitrary expressions
|
||||
|
||||
let error = roc_problem::can::RuntimeError::InvalidRecordUpdate {
|
||||
|
@ -731,7 +733,7 @@ pub fn canonicalize_expr<'a>(
|
|||
}
|
||||
ast::Expr::AccessorFunction(field) => (
|
||||
Accessor(AccessorData {
|
||||
name: env.gen_unique_symbol(),
|
||||
name: scope.gen_unique_symbol(),
|
||||
function_var: var_store.fresh(),
|
||||
record_var: var_store.fresh(),
|
||||
ext_var: var_store.fresh(),
|
||||
|
@ -746,7 +748,7 @@ pub fn canonicalize_expr<'a>(
|
|||
let variant_var = var_store.fresh();
|
||||
let ext_var = var_store.fresh();
|
||||
|
||||
let symbol = env.gen_unique_symbol();
|
||||
let symbol = scope.gen_unique_symbol();
|
||||
|
||||
(
|
||||
ZeroArgumentTag {
|
||||
|
@ -976,7 +978,7 @@ fn canonicalize_closure_inner_scope<'a>(
|
|||
) -> (ClosureData, Output) {
|
||||
// The globally unique symbol that will refer to this closure once it gets converted
|
||||
// into a top-level procedure for code gen.
|
||||
let symbol = opt_def_name.unwrap_or_else(|| env.gen_unique_symbol());
|
||||
let symbol = opt_def_name.unwrap_or_else(|| scope.gen_unique_symbol());
|
||||
|
||||
let mut can_args = Vec::with_capacity(loc_arg_patterns.len());
|
||||
let mut output = Output::default();
|
||||
|
@ -1273,7 +1275,7 @@ fn canonicalize_var_lookup(
|
|||
} else {
|
||||
// Since module_name was nonempty, this is a qualified var.
|
||||
// Look it up in the env!
|
||||
match env.qualified_lookup(module_name, ident, region) {
|
||||
match env.qualified_lookup(scope, module_name, ident, region) {
|
||||
Ok(symbol) => {
|
||||
output.references.insert_value_lookup(symbol);
|
||||
|
||||
|
|
|
@ -107,9 +107,7 @@ impl GeneratedInfo {
|
|||
env.problem(Problem::UnknownGeneratesWith(unknown));
|
||||
}
|
||||
|
||||
let effect_symbol = scope
|
||||
.introduce(name.into(), &mut env.ident_ids, Region::zero())
|
||||
.unwrap();
|
||||
let effect_symbol = scope.introduce(name.into(), Region::zero()).unwrap();
|
||||
|
||||
{
|
||||
let a_var = var_store.fresh();
|
||||
|
@ -409,7 +407,7 @@ pub fn canonicalize_module_defs<'a>(
|
|||
let symbol = def.pattern_vars.iter().next().unwrap().0;
|
||||
let ident_id = symbol.ident_id();
|
||||
let ident =
|
||||
env.ident_ids.get_name(ident_id).unwrap().to_string();
|
||||
scope.ident_ids.get_name(ident_id).unwrap().to_string();
|
||||
let def_annotation = def.annotation.clone().unwrap();
|
||||
let annotation = crate::annotation::Annotation {
|
||||
typ: def_annotation.signature,
|
||||
|
@ -537,6 +535,8 @@ pub fn canonicalize_module_defs<'a>(
|
|||
}
|
||||
}
|
||||
|
||||
let ident_ids = scope.ident_ids.clone();
|
||||
|
||||
let output = ModuleOutput {
|
||||
scope,
|
||||
aliases,
|
||||
|
@ -547,7 +547,7 @@ pub fn canonicalize_module_defs<'a>(
|
|||
exposed_imports: can_exposed_imports,
|
||||
problems: env.problems,
|
||||
lookups,
|
||||
ident_ids: env.ident_ids,
|
||||
ident_ids,
|
||||
};
|
||||
|
||||
Ok(output)
|
||||
|
|
|
@ -190,11 +190,8 @@ pub fn canonicalize_def_header_pattern<'a>(
|
|||
|
||||
match pattern {
|
||||
// Identifiers that shadow ability members may appear (and may only appear) at the header of a def.
|
||||
Identifier(name) => match scope.introduce_or_shadow_ability_member(
|
||||
(*name).into(),
|
||||
&mut env.ident_ids,
|
||||
region,
|
||||
) {
|
||||
Identifier(name) => {
|
||||
match scope.introduce_or_shadow_ability_member((*name).into(), region) {
|
||||
Ok((symbol, shadowing_ability_member)) => {
|
||||
output.references.insert_bound(symbol);
|
||||
let can_pattern = match shadowing_ability_member {
|
||||
|
@ -219,7 +216,8 @@ pub fn canonicalize_def_header_pattern<'a>(
|
|||
let can_pattern = Pattern::Shadowed(original_region, shadow, new_symbol);
|
||||
Loc::at(region, can_pattern)
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
_ => canonicalize_pattern(env, var_store, scope, output, pattern_type, pattern, region),
|
||||
}
|
||||
}
|
||||
|
@ -237,7 +235,7 @@ pub fn canonicalize_pattern<'a>(
|
|||
use PatternType::*;
|
||||
|
||||
let can_pattern = match pattern {
|
||||
Identifier(name) => match scope.introduce((*name).into(), &mut env.ident_ids, region) {
|
||||
Identifier(name) => match scope.introduce((*name).into(), region) {
|
||||
Ok(symbol) => {
|
||||
output.references.insert_bound(symbol);
|
||||
|
||||
|
@ -457,7 +455,7 @@ pub fn canonicalize_pattern<'a>(
|
|||
for loc_pattern in patterns.iter() {
|
||||
match loc_pattern.value {
|
||||
Identifier(label) => {
|
||||
match scope.introduce(label.into(), &mut env.ident_ids, region) {
|
||||
match scope.introduce(label.into(), region) {
|
||||
Ok(symbol) => {
|
||||
output.references.insert_bound(symbol);
|
||||
|
||||
|
@ -490,7 +488,7 @@ pub fn canonicalize_pattern<'a>(
|
|||
|
||||
RequiredField(label, loc_guard) => {
|
||||
// a guard does not introduce the label into scope!
|
||||
let symbol = scope.ignore(&Ident::from(label), &mut env.ident_ids);
|
||||
let symbol = scope.ignore(&Ident::from(label));
|
||||
let can_guard = canonicalize_pattern(
|
||||
env,
|
||||
var_store,
|
||||
|
@ -513,7 +511,7 @@ pub fn canonicalize_pattern<'a>(
|
|||
}
|
||||
OptionalField(label, loc_default) => {
|
||||
// an optional DOES introduce the label into scope!
|
||||
match scope.introduce(label.into(), &mut env.ident_ids, region) {
|
||||
match scope.introduce(label.into(), region) {
|
||||
Ok(symbol) => {
|
||||
let (can_default, expr_output) = canonicalize_expr(
|
||||
env,
|
||||
|
|
|
@ -24,7 +24,7 @@ pub struct Scope {
|
|||
home: ModuleId,
|
||||
|
||||
exposed_ident_ids: IdentIds,
|
||||
all_ident_ids: IdentIds,
|
||||
pub ident_ids: IdentIds,
|
||||
}
|
||||
|
||||
fn add_aliases(var_store: &mut VarStore) -> SendMap<Symbol, Alias> {
|
||||
|
@ -71,7 +71,7 @@ impl Scope {
|
|||
pub fn new(home: ModuleId, _var_store: &mut VarStore, initial_ident_ids: IdentIds) -> Scope {
|
||||
Scope {
|
||||
home,
|
||||
all_ident_ids: initial_ident_ids.clone(),
|
||||
ident_ids: initial_ident_ids.clone(),
|
||||
exposed_ident_ids: initial_ident_ids,
|
||||
idents: IdentStore::new(),
|
||||
aliases: SendMap::default(),
|
||||
|
@ -87,7 +87,7 @@ impl Scope {
|
|||
) -> Scope {
|
||||
Scope {
|
||||
home,
|
||||
all_ident_ids: initial_ident_ids.clone(),
|
||||
ident_ids: initial_ident_ids.clone(),
|
||||
exposed_ident_ids: initial_ident_ids,
|
||||
idents: IdentStore::new(),
|
||||
aliases: add_aliases(var_store),
|
||||
|
@ -202,13 +202,12 @@ impl Scope {
|
|||
pub fn introduce(
|
||||
&mut self,
|
||||
ident: Ident,
|
||||
all_ident_ids: &mut IdentIds,
|
||||
region: Region,
|
||||
) -> Result<Symbol, (Region, Loc<Ident>, Symbol)> {
|
||||
match self.introduce_without_shadow_symbol(&ident, all_ident_ids, region) {
|
||||
match self.introduce_without_shadow_symbol(&ident, region) {
|
||||
Ok(symbol) => Ok(symbol),
|
||||
Err((original_region, shadow)) => {
|
||||
let ident_id = all_ident_ids.add_ident(&ident);
|
||||
let ident_id = self.ident_ids.add_ident(&ident);
|
||||
let symbol = Symbol::new(self.home, ident_id);
|
||||
|
||||
Err((original_region, shadow, symbol))
|
||||
|
@ -220,7 +219,6 @@ impl Scope {
|
|||
pub fn introduce_without_shadow_symbol(
|
||||
&mut self,
|
||||
ident: &Ident,
|
||||
all_ident_ids: &mut IdentIds,
|
||||
region: Region,
|
||||
) -> Result<Symbol, (Region, Loc<Ident>)> {
|
||||
match self.idents.get_symbol_and_region(ident) {
|
||||
|
@ -231,7 +229,7 @@ impl Scope {
|
|||
};
|
||||
Err((original_region, shadow))
|
||||
}
|
||||
None => Ok(self.commit_introduction(ident, all_ident_ids, region)),
|
||||
None => Ok(self.commit_introduction(ident, region)),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -245,7 +243,6 @@ impl Scope {
|
|||
pub fn introduce_or_shadow_ability_member(
|
||||
&mut self,
|
||||
ident: Ident,
|
||||
all_ident_ids: &mut IdentIds,
|
||||
region: Region,
|
||||
) -> Result<(Symbol, Option<Symbol>), (Region, Loc<Ident>, Symbol)> {
|
||||
match self.idents.get_index(&ident) {
|
||||
|
@ -253,7 +250,7 @@ impl Scope {
|
|||
let original_symbol = self.idents.symbols[index];
|
||||
let original_region = self.idents.regions[index];
|
||||
|
||||
let shadow_ident_id = all_ident_ids.add_ident(&ident);
|
||||
let shadow_ident_id = self.ident_ids.add_ident(&ident);
|
||||
let shadow_symbol = Symbol::new(self.home, shadow_ident_id);
|
||||
|
||||
if self.abilities_store.is_ability_member_name(original_symbol) {
|
||||
|
@ -276,24 +273,19 @@ impl Scope {
|
|||
}
|
||||
}
|
||||
None => {
|
||||
let new_symbol = self.commit_introduction(&ident, all_ident_ids, region);
|
||||
let new_symbol = self.commit_introduction(&ident, region);
|
||||
Ok((new_symbol, None))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn commit_introduction(
|
||||
&mut self,
|
||||
ident: &Ident,
|
||||
all_ident_ids: &mut IdentIds,
|
||||
region: Region,
|
||||
) -> Symbol {
|
||||
fn commit_introduction(&mut self, ident: &Ident, region: Region) -> Symbol {
|
||||
// If this IdentId was already added previously
|
||||
// when the value was exposed in the module header,
|
||||
// use that existing IdentId. Otherwise, create a fresh one.
|
||||
let ident_id = match self.exposed_ident_ids.get_id(ident) {
|
||||
Some(ident_id) => ident_id,
|
||||
None => all_ident_ids.add_ident(ident),
|
||||
None => self.ident_ids.add_ident(ident),
|
||||
};
|
||||
|
||||
let symbol = Symbol::new(self.home, ident_id);
|
||||
|
@ -306,8 +298,8 @@ impl Scope {
|
|||
/// Ignore an identifier.
|
||||
///
|
||||
/// Used for record guards like { x: Just _ }
|
||||
pub fn ignore(&mut self, ident: &Ident, all_ident_ids: &mut IdentIds) -> Symbol {
|
||||
let ident_id = all_ident_ids.add_ident(ident);
|
||||
pub fn ignore(&mut self, ident: &Ident) -> Symbol {
|
||||
let ident_id = self.ident_ids.add_ident(ident);
|
||||
Symbol::new(self.home, ident_id)
|
||||
}
|
||||
|
||||
|
@ -365,6 +357,21 @@ impl Scope {
|
|||
|
||||
result
|
||||
}
|
||||
|
||||
pub fn register_debug_idents(&self) {
|
||||
self.home.register_debug_idents(&self.ident_ids)
|
||||
}
|
||||
|
||||
/// Generates a unique, new symbol like "$1" or "$5",
|
||||
/// using the home module as the module_id.
|
||||
///
|
||||
/// This is used, for example, during canonicalization of an Expr::Closure
|
||||
/// to generate a unique symbol to refer to that closure.
|
||||
pub fn gen_unique_symbol(&mut self) -> Symbol {
|
||||
let ident_id = self.ident_ids.gen_unique();
|
||||
|
||||
Symbol::new(self.home, ident_id)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_alias(
|
||||
|
|
|
@ -55,7 +55,7 @@ pub fn can_expr_with(arena: &Bump, home: ModuleId, expr_str: &str) -> CanExprOut
|
|||
// rules multiple times unnecessarily.
|
||||
let loc_expr = operator::desugar_expr(arena, &loc_expr);
|
||||
|
||||
let mut scope = Scope::new(home, &mut var_store, dep_idents.clone());
|
||||
let mut scope = Scope::new(home, &mut var_store, IdentIds::default());
|
||||
scope.add_alias(
|
||||
Symbol::NUM_INT,
|
||||
Region::zero(),
|
||||
|
@ -75,7 +75,7 @@ pub fn can_expr_with(arena: &Bump, home: ModuleId, expr_str: &str) -> CanExprOut
|
|||
);
|
||||
|
||||
let mut all_ident_ids = IdentIds::exposed_builtins(1);
|
||||
all_ident_ids.insert(home, env.ident_ids);
|
||||
all_ident_ids.insert(home, scope.ident_ids);
|
||||
|
||||
let interns = Interns {
|
||||
module_ids: env.module_ids.clone(),
|
||||
|
|
|
@ -184,7 +184,7 @@ pub fn can_expr_with<'a>(
|
|||
introduce_builtin_imports(&mut constraints, imports, constraint, &mut var_store);
|
||||
|
||||
let mut all_ident_ids = IdentIds::exposed_builtins(1);
|
||||
all_ident_ids.insert(home, env.ident_ids);
|
||||
all_ident_ids.insert(home, scope.ident_ids);
|
||||
|
||||
let interns = Interns {
|
||||
module_ids: env.module_ids.clone(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue