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
4 changes: 2 additions & 2 deletions src/v1/04_infer.dag
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ import v1.compiler.infer_patterns {
}
import v1.compiler.infer_lookup {
KnownMethodResolution,
resolve_known_method_node, resolve_scrutinee_type_node,
resolve_known_method_node, resolve_scrutinee_type_node, resolve_method_receiver_type,
field_summary_for_type,
lookup_field_type_node, lookup_coproduct_common_field_node, product_field_result_type,
map_value_type_in_env, map_key_type_in_env, set_element_type_in_env,
Expand Down Expand Up @@ -1874,7 +1874,7 @@ fn infer_expr(texpr: Node, scope: InferScope, expected: Node?) -> InferResult {
let recv_result = infer_expr(texpr: recv, scope: scope, expected: none)
let recv_typed = recv_result.typed
let recv_diags = recv_result.diagnostics
let recv_rt = resolved_type(n: recv_typed)
let recv_rt = resolve_method_receiver_type(receiver_type: resolved_type(n: recv_typed), env: scope.type_env)
let recv_elem_type = for_each_element_type_node(n: recv_rt, source_indices: scope.type_env.source_indices)
let mc_method_name = Present { value: method_name }
let fold_info = extract_fold_init_info(method_name: mc_method_name, method_args: mc_args, min_args: 2, scope: scope, expected: expected)
Expand Down
17 changes: 16 additions & 1 deletion src/v1/04_lookup.dag
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import v1.compiler.infer_types {
normalize_access_type_node, node_is_keyed_collection, node_is_set_collection,
method_receiver_element_node,
emit_map_has,
enrich_kernel_type
enrich_kernel_type, is_declared_container_alias_spelling, reground_alias_carrier_identity
}
import v1.compiler.infer_env {
TypeEnv, TypeBinding, authored_name,
Expand Down Expand Up @@ -138,6 +138,21 @@ fn resolve_scrutinee_type_node(env: TypeEnv, n: Node) -> Node {
resolve_scrutinee_type_node_seen(env: env, n: n, seen: empty_map())
}

fn resolve_method_receiver_type(receiver_type: Node, env: TypeEnv) -> Node {
let raw_name = authored_name_at(source_indices: env.source_indices, node: receiver_type)
if receiver_type.connective == Conj || is_declared_container_alias_spelling(name: raw_name) {
receiver_type
} else {
let resolved = reground_alias_carrier_identity(n: resolve_scrutinee_type_node(env: env, n: receiver_type), source_indices: env.source_indices)
let resolved_name = authored_name_at(source_indices: env.source_indices, node: resolved)
if resolved_name != raw_name && is_declared_container_alias_spelling(name: resolved_name) {
resolved
} else {
receiver_type
}
}
}

fn resolve_scrutinee_type_node_seen(env: TypeEnv, n: Node, seen: Map<String, Bool>) -> Node {
let n_is_type_var = if n.inferred != none { is_type_variable(inferred: n.inferred.value) } else { false }
if n_is_type_var { return n }
Expand Down
15 changes: 15 additions & 0 deletions src/v1/04_types.dag
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,21 @@ fn is_declared_container_alias_spelling(name: String) -> Bool {
}
}

fn reground_alias_carrier_identity(n: Node, source_indices: Map<String, NewlineIndex>) -> Node {
if n.name != "" && n.name != authored_name_at(source_indices: source_indices, node: n) && is_declared_container_alias_spelling(name: n.name) {
Node {
name: n.name, span: n.span, ident_span: Present { value: kernel_span(name: n.name) },
children: n.children, connective: n.connective, params: n.params, inferred: n.inferred,
return_cardinality: n.return_cardinality, uses: n.uses, body: n.body, transport: n.transport,
properties: n.properties, type_annotation: n.type_annotation,
is_self_recursive: n.is_self_recursive, has_non_tail_self_call: n.has_non_tail_self_call,
match_pattern: n.match_pattern, expr_data: n.expr_data
}
} else {
n
}
}

fn structural_carrier_template_name(n: Node, source_indices: Map<String, NewlineIndex>) -> String {
if n.name != "" {
canonical_template_name(n: Node {
Expand Down
9 changes: 6 additions & 3 deletions src/v1/stage0/src/v1_compiler_infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ pub use crate::v1_compiler_infer_lookup::KnownMethodResolution;
pub use crate::v1_compiler_infer_lookup::{
field_summary_for_type, lookup_coproduct_common_field_node, lookup_field_type_node,
lookup_func_sig, lookup_in_scope, map_key_type_in_env, map_value_type_in_env,
product_field_result_type, resolve_known_method_node, resolve_scrutinee_type_node,
set_element_type_in_env,
product_field_result_type, resolve_known_method_node, resolve_method_receiver_type,
resolve_scrutinee_type_node, set_element_type_in_env,
};
pub use crate::v1_compiler_infer_method::{
builtin_kernel_seed_diagnostics, infer_builtin_call_type, resolve_builtin_call_type,
Expand Down Expand Up @@ -3673,7 +3673,10 @@ match bare_s {
let recv_result = infer_expr(recv, scope.clone(), None);
let recv_typed = recv_result.typed.clone();
let recv_diags = recv_result.diagnostics.clone();
let recv_rt = resolved_type(recv_typed.clone());
let recv_rt = resolve_method_receiver_type(
resolved_type(recv_typed.clone()),
scope.type_env.clone(),
);
let recv_elem_type = for_each_element_type_node(
recv_rt.clone(),
scope.type_env.clone().source_indices.clone(),
Expand Down
29 changes: 26 additions & 3 deletions src/v1/stage0/src/v1_compiler_infer_lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ pub use crate::v1_compiler_infer_service::check_service_method_call_node;
pub use crate::v1_compiler_infer_service::{OpEntry, ServiceMethodResult};
pub use crate::v1_compiler_infer_sigs::{ResolvedFuncEnv, ResolvedFuncSig};
pub use crate::v1_compiler_infer_types::{
child_type_node, emit_map_has, enrich_kernel_type, make_container_type,
method_receiver_element_node, node_is_keyed_collection, node_is_set_collection,
nominal_type_ref, normalize_access_type_node,
child_type_node, emit_map_has, enrich_kernel_type, is_declared_container_alias_spelling,
make_container_type, method_receiver_element_node, node_is_keyed_collection,
node_is_set_collection, nominal_type_ref, normalize_access_type_node,
reground_alias_carrier_identity,
};
use crate::v1_rt;
use crate::v1_rt::Witness;
Expand Down Expand Up @@ -201,6 +202,28 @@ pub fn resolve_scrutinee_type_node(env: Rc<TypeEnv>, n: Rc<Node>) -> Rc<Node> {
resolve_scrutinee_type_node_seen(env, n, v1_rt::rc_empty_map::<String, bool>())
}

pub fn resolve_method_receiver_type(receiver_type: Rc<Node>, env: Rc<TypeEnv>) -> Rc<Node> {
let raw_name = authored_name_at(env.source_indices.clone(), receiver_type.clone());
if ((receiver_type.connective.clone() == Connective::Conj)
|| is_declared_container_alias_spelling(raw_name.clone()))
{
receiver_type.clone()
} else {
let resolved = reground_alias_carrier_identity(
resolve_scrutinee_type_node(env.clone(), receiver_type.clone()),
env.source_indices.clone(),
);
let resolved_name = authored_name_at(env.source_indices.clone(), resolved.clone());
if ((resolved_name.clone().as_str() != raw_name.clone().as_str())
&& is_declared_container_alias_spelling(resolved_name.clone()))
{
resolved
} else {
receiver_type.clone()
}
}
}

pub fn resolve_scrutinee_type_node_seen(
env: Rc<TypeEnv>,
n: Rc<Node>,
Expand Down
34 changes: 34 additions & 0 deletions src/v1/stage0/src/v1_compiler_infer_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,40 @@ pub fn is_declared_container_alias_spelling(name: String) -> bool {
}
}

pub fn reground_alias_carrier_identity(
n: Rc<Node>,
source_indices: Rc<HashMap<String, Rc<NewlineIndex>>>,
) -> Rc<Node> {
if (((n.name.clone().as_str() != "".to_string().as_str())
&& (n.name.clone().as_str()
!= authored_name_at(source_indices.clone(), n.clone()).as_str()))
&& is_declared_container_alias_spelling(n.name.clone()))
{
Rc::new(Node {
name: n.name.clone(),
span: n.span.clone(),
ident_span: Some(kernel_span(n.name.clone())),
children: n.children.clone(),
connective: n.connective.clone(),
params: n.params.clone(),
inferred: n.inferred.clone(),
return_cardinality: n.return_cardinality.clone(),
uses: n.uses.clone(),
body: n.body.clone(),
transport: n.transport.clone(),
properties: n.properties.clone(),
type_annotation: n.type_annotation.clone(),
is_self_recursive: n.is_self_recursive.clone(),
has_non_tail_self_call: n.has_non_tail_self_call.clone(),
match_pattern: n.match_pattern.clone(),
expr_data: n.expr_data.clone(),
ident: None,
})
} else {
n.clone()
}
}

pub fn structural_carrier_template_name(
n: Rc<Node>,
source_indices: Rc<HashMap<String, Rc<NewlineIndex>>>,
Expand Down
Loading