Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 13 additions & 25 deletions src/v1/04_infer.dag
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ type CycleDetectState {
}

type InferScopeComponents {
func_sigs: Map<String, DeclaredFuncSig>
imported_sigs: Map<String, ResolvedFuncSig>
svc_registry: Map<String, List<OpEntry>>
svc_locals: Map<String, TypeBinding>
}
Expand All @@ -295,32 +295,20 @@ type LocalContributionState {
}

fn merge_scope_from_imports(remaining: List<ResolvedImport>, parent_index: Map<String, TypedModule>, env: TypeEnv,
func_sigs: Map<String, DeclaredFuncSig>,
imported_sigs: Map<String, ResolvedFuncSig>,
svc_registry: Map<String, List<OpEntry>>,
svc_locals: Map<String, TypeBinding>) -> InferScopeComponents {
match remaining |> first {
Absent => InferScopeComponents {
func_sigs: func_sigs, svc_registry: svc_registry,
imported_sigs: imported_sigs, svc_registry: svc_registry,
svc_locals: svc_locals
}
Present { value: imp } =>
match map_get(parent_index, imp.module_path) {
Present { value: typed_parent } =>
let next_func_sigs = fold(typed_parent.func_env.signatures |> map_values, init: func_sigs, f: (acc, rsig) =>
let sig_key = rsig.name
let sig_params = rsig.params
let sig_rt = rsig.inferred
let sig_async = rsig.is_async
map_insert(acc, sig_key, DeclaredFuncSig {
name: sig_key, params: sig_params,
inferred: Present { value: sig_rt },
is_async: sig_async,
output_provenance: rsig.output_provenance,
variant_provenance: rsig.variant_provenance
})
)
let next_imported_sigs = map_merge(imported_sigs, typed_parent.func_env.signatures)
let parent_result = fold(typed_parent.items, init: InferScopeComponents {
func_sigs: next_func_sigs, svc_registry: svc_registry,
imported_sigs: next_imported_sigs, svc_registry: svc_registry,
svc_locals: svc_locals
}, f: (acc, titem) =>
if titem.transport != none && titem.children |> count > 0 {
Expand All @@ -329,14 +317,14 @@ fn merge_scope_from_imports(remaining: List<ResolvedImport>, parent_index: Map<S
)
let root = namespace_root_from_properties(properties: titem.properties, name: authored_name_at(source_indices: env.source_indices, node: titem), source_indices: env.source_indices)
InferScopeComponents {
func_sigs: acc.func_sigs,
imported_sigs: acc.imported_sigs,
svc_registry: map_insert(acc.svc_registry, authored_name_at(source_indices: env.source_indices, node: titem), entries),
svc_locals: map_insert(acc.svc_locals, root, nominal_type_binding(name: root))
}
}
else if titem.body != none && (titem.params |> count == 0) && titem.transport == none && titem.connective == NoConnective && titem.inferred != none {
InferScopeComponents {
func_sigs: acc.func_sigs,
imported_sigs: acc.imported_sigs,
svc_registry: acc.svc_registry,
svc_locals: map_insert(acc.svc_locals, authored_name_at(source_indices: env.source_indices, node: titem), TypeBinding { name: authored_name_at(source_indices: env.source_indices, node: titem), resolved: resolved_type(n: titem), provenance: SubValueUnknown })
}
Expand All @@ -346,11 +334,11 @@ fn merge_scope_from_imports(remaining: List<ResolvedImport>, parent_index: Map<S
}
)
merge_scope_from_imports(remaining: remaining |> skip(1), parent_index: parent_index, env: env,
func_sigs: parent_result.func_sigs, svc_registry: parent_result.svc_registry,
imported_sigs: parent_result.imported_sigs, svc_registry: parent_result.svc_registry,
svc_locals: parent_result.svc_locals)
Absent =>
merge_scope_from_imports(remaining: remaining |> skip(1), parent_index: parent_index, env: env,
func_sigs: func_sigs, svc_registry: svc_registry,
imported_sigs: imported_sigs, svc_registry: svc_registry,
svc_locals: svc_locals)
}
}
Expand Down Expand Up @@ -5836,16 +5824,16 @@ fn build_module_context(contributions: List<ItemContribution>,
remaining: resolved_imports,
parent_index: parent_index,
env: env,
func_sigs: empty_map(),
imported_sigs: empty_map(),
svc_registry: local.svc_registry,
svc_locals: local.svc_locals
)
let all_declared_sigs = map_merge(merged_scope.func_sigs, local.func_sigs)
let resolve_result = resolve_func_sigs(
declared_sigs: all_declared_sigs,
declared_sigs: local.func_sigs,
items: local.resolved_items,
module_name: module_name,
source_indices: env.source_indices
source_indices: env.source_indices,
parent_sigs: merged_scope.imported_sigs
)
let all_locals = fold(merged_scope.svc_locals |> map_values, init: env_variant_locals, f: (acc, binding) =>
map_insert(acc, binding.name, binding)
Expand Down
22 changes: 7 additions & 15 deletions src/v1/04_sigs.dag
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,6 @@ fn build_name_set(names: List<String>) -> Map<String, Bool> {
fold(names, init: empty_map(), f: (acc, name) => map_insert(acc, name, true))
}

fn collect_parent_resolved_sigs(declared_sigs: Map<String, DeclaredFuncSig>, local_func_set: Map<String, Bool>) -> Map<String, ResolvedFuncSig> {
fold(map_values(declared_sigs), init: empty_map(), f: (acc, dsig) =>
if emit_map_has(m: local_func_set, key: dsig.name) {
acc
} else if dsig.inferred != none {
map_insert(acc, dsig.name, declared_to_resolved(dsig: dsig))
} else {
acc
}
)
}

fn declared_to_resolved(dsig: DeclaredFuncSig) -> ResolvedFuncSig {
ResolvedFuncSig { name: dsig.name, params: dsig.params, inferred: dsig.inferred.value, is_async: dsig.is_async, output_provenance: dsig.output_provenance, variant_provenance: dsig.variant_provenance }
}
Expand Down Expand Up @@ -189,17 +177,21 @@ fn resolve_func_sigs(
declared_sigs: Map<String, DeclaredFuncSig>,
items: List<Node>,
module_name: String,
source_indices: Map<String, NewlineIndex>
source_indices: Map<String, NewlineIndex>,
parent_sigs: Map<String, ResolvedFuncSig>
) -> ResolveFuncSigsResult {
let local_func_names = items
|> filter(item => item.params |> count > 0 && item.body != none)
|> map(item => authored_name_at(source_indices: source_indices, node: item))
let local_func_set = build_name_set(names: local_func_names)
let call_edges = collect_func_call_edges(items: items, local_func_set: local_func_set, source_indices: source_indices)
let parent_resolved = collect_parent_resolved_sigs(declared_sigs: declared_sigs, local_func_set: local_func_set)
let parent_sigs_filtered = fold(map_values(parent_sigs), init: empty_map(), f: (acc, rsig) =>
if emit_map_has(m: local_func_set, key: rsig.name) { acc }
else { map_insert(acc, rsig.name, rsig) }
)
topo_resolve_loop(
remaining: local_func_names,
resolved: parent_resolved,
resolved: parent_sigs_filtered,
declared_sigs: declared_sigs,
call_edges: call_edges,
local_func_set: local_func_set,
Expand Down
52 changes: 14 additions & 38 deletions src/v1/stage0/src/v1_compiler_infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ pub struct CycleDetectState {

#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct InferScopeComponents {
pub func_sigs: Rc<HashMap<String, Rc<DeclaredFuncSig>>>,
pub imported_sigs: Rc<HashMap<String, Rc<ResolvedFuncSig>>>,
pub svc_registry: Rc<HashMap<String, Rc<Vec<Rc<OpEntry>>>>>,
pub svc_locals: Rc<HashMap<String, Rc<TypeBinding>>>,
}
Expand All @@ -353,51 +353,28 @@ pub fn merge_scope_from_imports(
mut remaining: Rc<Vec<Rc<ResolvedImport>>>,
mut parent_index: Rc<HashMap<String, Rc<TypedModule>>>,
mut env: Rc<TypeEnv>,
mut func_sigs: Rc<HashMap<String, Rc<DeclaredFuncSig>>>,
mut imported_sigs: Rc<HashMap<String, Rc<ResolvedFuncSig>>>,
mut svc_registry: Rc<HashMap<String, Rc<Vec<Rc<OpEntry>>>>>,
mut svc_locals: Rc<HashMap<String, Rc<TypeBinding>>>,
) -> Rc<InferScopeComponents> {
loop {
match remaining.clone().first().cloned() {
None => {
break Rc::new(InferScopeComponents {
func_sigs: func_sigs,
imported_sigs: imported_sigs,
svc_registry: svc_registry,
svc_locals: svc_locals,
});
}
Some(imp) => match v1_rt::map_get(&parent_index, imp.module_path.clone()) {
Some(typed_parent) => {
let next_func_sigs = Rc::new(v1_rt::map_values(
&typed_parent.func_env.clone().signatures.clone(),
))
.iter()
.cloned()
.fold(
func_sigs,
|acc: Rc<HashMap<String, Rc<DeclaredFuncSig>>>,
rsig: Rc<ResolvedFuncSig>| {
let sig_key = rsig.name.clone();
let sig_params = rsig.params.clone();
let sig_rt = rsig.inferred.clone();
let sig_async = rsig.is_async.clone();
v1_rt::rc_map_insert(
acc,
sig_key.clone(),
Rc::new(DeclaredFuncSig {
name: sig_key.clone(),
params: sig_params.clone(),
inferred: Some(sig_rt.clone()),
is_async: sig_async.clone(),
output_provenance: rsig.output_provenance.clone(),
variant_provenance: rsig.variant_provenance.clone(),
}),
)
},
let next_imported_sigs = v1_rt::rc_map_merge(
imported_sigs,
typed_parent.func_env.clone().signatures.clone(),
);
let parent_result = typed_parent.items.clone().iter().cloned().fold(
Rc::new(InferScopeComponents {
func_sigs: next_func_sigs,
imported_sigs: next_imported_sigs,
svc_registry: svc_registry,
svc_locals: svc_locals,
}),
Expand Down Expand Up @@ -430,7 +407,7 @@ pub fn merge_scope_from_imports(
env.source_indices.clone(),
);
Rc::new(InferScopeComponents {
func_sigs: acc.func_sigs.clone(),
imported_sigs: acc.imported_sigs.clone(),
svc_registry: v1_rt::rc_map_insert(
acc.svc_registry.clone(),
authored_name_at(
Expand All @@ -454,7 +431,7 @@ pub fn merge_scope_from_imports(
&& (titem.inferred.clone() != None))
{
Rc::new(InferScopeComponents {
func_sigs: acc.func_sigs.clone(),
imported_sigs: acc.imported_sigs.clone(),
svc_registry: acc.svc_registry.clone(),
svc_locals: v1_rt::rc_map_insert(
acc.svc_locals.clone(),
Expand Down Expand Up @@ -488,11 +465,11 @@ pub fn merge_scope_from_imports(
.skip(1 as usize)
.collect::<Vec<_>>(),
);
let __tco_1 = parent_result.func_sigs.clone();
let __tco_1 = parent_result.imported_sigs.clone();
let __tco_2 = parent_result.svc_registry.clone();
let __tco_3 = parent_result.svc_locals.clone();
remaining = __tco_0;
func_sigs = __tco_1;
imported_sigs = __tco_1;
svc_registry = __tco_2;
svc_locals = __tco_3;
continue;
Expand Down Expand Up @@ -13107,17 +13084,16 @@ pub fn build_module_context(
resolved_imports.clone(),
parent_index,
env.clone(),
v1_rt::rc_empty_map::<String, Rc<DeclaredFuncSig>>(),
v1_rt::rc_empty_map::<String, Rc<ResolvedFuncSig>>(),
local.svc_registry.clone(),
local.svc_locals.clone(),
);
let all_declared_sigs =
v1_rt::rc_map_merge(merged_scope.func_sigs.clone(), local.func_sigs.clone());
let resolve_result = resolve_func_sigs(
all_declared_sigs,
local.func_sigs.clone(),
local.resolved_items.clone(),
module_name.clone(),
env.source_indices.clone(),
merged_scope.imported_sigs.clone(),
);
let all_locals = Rc::new(v1_rt::map_values(&merged_scope.svc_locals.clone()))
.iter()
Expand Down
45 changes: 15 additions & 30 deletions src/v1/stage0/src/v1_compiler_infer_sigs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,33 +182,6 @@ pub fn build_name_set(names: Rc<Vec<String>>) -> Rc<HashMap<String, bool>> {
)
}

pub fn collect_parent_resolved_sigs(
declared_sigs: Rc<HashMap<String, Rc<DeclaredFuncSig>>>,
local_func_set: Rc<HashMap<String, bool>>,
) -> Rc<HashMap<String, Rc<ResolvedFuncSig>>> {
Rc::new(v1_rt::map_values(&declared_sigs))
.iter()
.cloned()
.fold(
v1_rt::rc_empty_map::<String, Rc<ResolvedFuncSig>>(),
|acc: Rc<HashMap<String, Rc<ResolvedFuncSig>>>, dsig: Rc<DeclaredFuncSig>| {
if emit_map_has(local_func_set.clone(), dsig.name.clone()) {
acc.clone()
} else {
if (dsig.inferred.clone() != None) {
v1_rt::rc_map_insert(
acc.clone(),
dsig.name.clone(),
declared_to_resolved(dsig.clone()),
)
} else {
acc.clone()
}
}
},
)
}

pub fn declared_to_resolved(dsig: Rc<DeclaredFuncSig>) -> Rc<ResolvedFuncSig> {
Rc::new(ResolvedFuncSig {
name: dsig.name.clone(),
Expand Down Expand Up @@ -474,6 +447,7 @@ pub fn resolve_func_sigs(
items: Rc<Vec<Rc<Node>>>,
module_name: String,
source_indices: Rc<HashMap<String, Rc<NewlineIndex>>>,
parent_sigs: Rc<HashMap<String, Rc<ResolvedFuncSig>>>,
) -> Rc<ResolveFuncSigsResult> {
{
let local_func_names = Rc::new({
Expand All @@ -500,11 +474,22 @@ pub fn resolve_func_sigs(
local_func_set.clone(),
source_indices.clone(),
);
let parent_resolved =
collect_parent_resolved_sigs(declared_sigs.clone(), local_func_set.clone());
let parent_sigs_filtered = Rc::new(v1_rt::map_values(&parent_sigs))
.iter()
.cloned()
.fold(
v1_rt::rc_empty_map::<String, Rc<ResolvedFuncSig>>(),
|acc: Rc<HashMap<String, Rc<ResolvedFuncSig>>>, rsig: Rc<ResolvedFuncSig>| {
if emit_map_has(local_func_set.clone(), rsig.name.clone()) {
acc.clone()
} else {
v1_rt::rc_map_insert(acc.clone(), rsig.name.clone(), rsig.clone())
}
},
);
topo_resolve_loop(
local_func_names.clone(),
parent_resolved,
parent_sigs_filtered,
declared_sigs.clone(),
call_edges,
local_func_set.clone(),
Expand Down