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
29 changes: 28 additions & 1 deletion src/v1/04_infer.dag
Original file line number Diff line number Diff line change
Expand Up @@ -13042,6 +13042,31 @@ fn rewire_str_binding_overlay(str_bindings: Map<String, TypeBinding>, rewrites:
)
}

// THE KERNEL LAYER IS NOT AN IMPORT IDENTITY TO CANONICALIZE (2026-08-31, frontier receipt 1
// follow-up). This rewire replaces an inherited binding with the corpus-wide canonical EXPORTED
// declaration when exactly one module exports the name. A KERNEL binding in ancestry is not an
// inherited import identity: it is the precedence layer build_ancestry_precedence installed ABOVE
// the import union (locals > kernel > direct-selected > union), and String has exactly one
// corpus exporter (v2.std.text), so the unguarded rewrite substituted the structural declaration
// for the kernel identity in every module's persisted env -- inference (pre-rewire) answered
// kernel while emit (post-rewire) read the substituted authority, the divergence behind the
// pub-use String shadow measured as 139 of receipt 1's 146 E0308 rows. The guard is keyed on the
// BINDING'S OWN identity (the kernel span file), never on a name roster: a module that locally
// declares or genuinely imports a kernel-spelled name keeps its ordinary rewire, because its
// binding does not carry the kernel span. The confirming discriminator was measured before the
// fix: v2.std.compilers.target_model imports v2.std.text in TWO import statements, so its
// direct-exporter count for String is 2, the rewrite skipped it, and it was the one module whose
// emit-time lookup still answered kernel.
fn ancestry_binding_is_kernel_identity(bindings: Map<String, TypeBinding>, name: String) -> Bool {
match map_get(bindings, name) {
Absent => false
Present { value: binding } => match binding.resolved.ident_span {
Present { value: sp } => sp.file == concat("<kernel:", concat(name, ">"))
Absent => false
}
}
}

fn rewire_type_env_import_str_binding_identity(modules: List<TypedModule>, source_indices: Map<String, NewlineIndex>) -> List<TypedModule> {
let export_indexes = build_export_indexes(modules: modules, source_indices: source_indices)
let type_name_index = export_indexes.by_name
Expand All @@ -13053,7 +13078,9 @@ fn rewire_type_env_import_str_binding_identity(modules: List<TypedModule>, sourc
}
let import_export_names = direct_import_export_name_sets(m: m, export_name_index: export_name_index, source_indices: source_indices)
let exporter_counts = direct_import_exporter_counts(import_export_names: import_export_names)
let ancestry_keys = m.type_env.ancestry_str_bindings |> map_keys
let ancestry_keys = m.type_env.ancestry_str_bindings
|> map_keys
|> filter(name => !ancestry_binding_is_kernel_identity(bindings: m.type_env.ancestry_str_bindings, name: name))
let str_keys = m.type_env.str_bindings |> map_keys
let inherited_keys = concat(ancestry_keys, str_keys)
let rewrites = rewire_canonical_rewrites(
Expand Down
57 changes: 50 additions & 7 deletions src/v1/05_emit_rust.dag
Original file line number Diff line number Diff line change
Expand Up @@ -4712,7 +4712,11 @@ fn reference_derived_use_line_plan(items: List<Node>, unlisted_type_names: List<
Absent => false
}
)
let block = emit_specific_import_block(import_module: provider, mod_name: module_to_filename(name: provider), filtered_names: names, emit_info: emit_info, registry: registry, local_names: local_type_names, export_sets: export_sets, typed_modules: typed_modules, source_indices: source_indices, module_index: module_index)
let plan_module_env = match map_get(module_index.by_name, this_module_name) {
Present { value: tm } => Present { value: tm.type_env }
Absent => none
}
let block = emit_specific_import_block(import_module: provider, mod_name: module_to_filename(name: provider), filtered_names: names, emit_info: emit_info, registry: registry, local_names: local_type_names, export_sets: export_sets, typed_modules: typed_modules, source_indices: source_indices, module_index: module_index, module_env: plan_module_env)
let block_lines = if block == "" { [] } else { block |> split(delimiter: "\n") }
let emitted_here = block_lines |> flat_map(l => imported_names_in_use_line(line: l))
let fallback = names |> flat_map(nm =>
Expand Down Expand Up @@ -4860,7 +4864,7 @@ fn emit_module_full(typed_module: TypedModule, registry: Map<String, ItemInfo>,
|> map(item => emit_typed_item(item: item, module_name: authored_name(env: scope.type_env, node: m), registry: registry, scope: scope, shared_types: shared_types, emit_info: emit_info, wire_contract_item: wire_contract_item, data_items: scoped_data_items, module_items: wire_context_items, imports: wire_context_imports, export_sets: export_sets, typed_modules: typed_modules, module_index: module_index))
|> join(separator: "\n\n")
let prelude = emit_prelude(imported_names: prelude_imported_names, local_type_names: local_type_names)
let imports_str = emit_imports(imports: module_imports(n: m), emit_info: emit_info, registry: registry, local_names: local_type_names, export_sets: export_sets, typed_modules: typed_modules, source_indices: scope.type_env.source_indices, module_index: module_index, supplement_items: typed_module.items)
let imports_str = emit_imports(imports: module_imports(n: m), emit_info: emit_info, registry: registry, local_names: local_type_names, export_sets: export_sets, typed_modules: typed_modules, source_indices: scope.type_env.source_indices, module_index: module_index, supplement_items: typed_module.items, module_env: Present { value: scope.type_env })
let dag_import_lines = if imports_str == "" { [] } else { imports_str |> split(delimiter: "\n") }
let carrier_import_lines = if module_needs_faithful_carrier_imports(
items: typed_module.items,
Expand Down Expand Up @@ -5752,9 +5756,46 @@ fn import_variant_parent_for_name(n: String, import_module: String, registry: Ma
}
}

fn emit_specific_import_block(import_module: String, mod_name: String, filtered_names: List<String>, emit_info: EmitGraphInfo, registry: Map<String, ItemInfo>, local_names: List<String>, export_sets: Map<String, Map<String, Bool>>, typed_modules: List<TypedModule>, source_indices: Map<String, NewlineIndex>, module_index: ModuleIndex) -> String {
// EMISSION FOLLOWS RESOLUTION AT THE AUTHORED-IMPORT BOUNDARY (#9813's contract, 2026-08-31).
// A name in an authored import list earns a use-line only if the module's RESOLVED binding for
// that bare spelling is the imported declaration. Post-#9813 the kernel overlay sits above the
// direct-import layer unconditionally, so a kernel-spelled name (String from v2.std.text, Bool
// from std.types) binds the kernel identity while the emitted `pub use` re-bound the spelling to
// the provider's structural type -- the shadow measured as 139 of the 146 E0308 rows in frontier
// receipt 1 (host std::string::String vs Rc<im::Vector<i64>>). The question is asked of the
// resolver's own lookup over the module's typed environment and decided by the BINDING'S IDENTITY
// -- the kernel span file marker -- never by a name roster or arm order: a name that is both a
// graph type and a kernel spelling answers by what its binding IS. Absent binding or absent env
// keeps the line: ignorance must not widen a drop (DESIGN section 5). Structural consumers whose
// binding declares in the provider (Witness) keep their lines by the same comparison. The drop is
// further keyed to the binding's own STRUCTURE: a kernel binding that is a bare synthetic scalar
// (no connective, no children -- String, Int, Float, Bytes) realizes as a host type the emitted
// module reaches with no import, so its use-line can only shadow; a kernel binding that carries
// declared structure (Bool's True|False Disj, Optional) realizes THROUGH the cited declaration,
// so its use-line is the path to that realization and stays -- measured in the seed mirror, whose
// bodies consume the structural Bool enum by bare spelling.
fn import_name_resolves_to_kernel(name: String, module_env: TypeEnv?) -> Bool {
match module_env {
Absent => false
Present { value: env } =>
match lookup_type_by_name(env: env, name: name) {
Absent => false
Present { value: n } => match n.ident_span {
Present { value: sp } =>
string_contains(s: sp.file, pattern: "<kernel:")
&& n.connective == NoConnective
&& (n.children |> count) == 0
Absent => false
}
}
}
}

fn emit_specific_import_block(import_module: String, mod_name: String, filtered_names: List<String>, emit_info: EmitGraphInfo, registry: Map<String, ItemInfo>, local_names: List<String>, export_sets: Map<String, Map<String, Bool>>, typed_modules: List<TypedModule>, source_indices: Map<String, NewlineIndex>, module_index: ModuleIndex, module_env: TypeEnv?) -> String {
let type_summaries = emit_info.type_summaries
let deduped_names = unique_strings(items: filtered_names |> filter(n => local_names |> all(ln => ln != n)))
let deduped_names = unique_strings(items: filtered_names
|> filter(n => local_names |> all(ln => ln != n))
|> filter(n => !import_name_resolves_to_kernel(name: n, module_env: module_env)))
if deduped_names |> count == 0 {
""
} else {
Expand Down Expand Up @@ -6185,7 +6226,7 @@ fn dedupe_rust_import_lines(lines: List<String>) -> List<String> {
strip_repeated_use_symbols(lines: covered)
}

fn emit_imports(imports: List<Node>, emit_info: EmitGraphInfo, registry: Map<String, ItemInfo>, local_names: List<String>, export_sets: Map<String, Map<String, Bool>>, typed_modules: List<TypedModule>, source_indices: Map<String, NewlineIndex>, module_index: ModuleIndex, supplement_items: List<Node>) -> String {
fn emit_imports(imports: List<Node>, emit_info: EmitGraphInfo, registry: Map<String, ItemInfo>, local_names: List<String>, export_sets: Map<String, Map<String, Bool>>, typed_modules: List<TypedModule>, source_indices: Map<String, NewlineIndex>, module_index: ModuleIndex, supplement_items: List<Node>, module_env: TypeEnv?) -> String {
if imports |> count == 0 {
""
} else {
Expand Down Expand Up @@ -6213,7 +6254,8 @@ fn emit_imports(imports: List<Node>, emit_info: EmitGraphInfo, registry: Map<Str
export_sets: export_sets,
typed_modules: typed_modules,
source_indices: source_indices,
module_index: module_index)
module_index: module_index,
module_env: module_env)
if specific_block != "" {
concat(wildcard_line, "\n", specific_block)
} else {
Expand All @@ -6233,7 +6275,8 @@ fn emit_imports(imports: List<Node>, emit_info: EmitGraphInfo, registry: Map<Str
export_sets: export_sets,
typed_modules: typed_modules,
source_indices: source_indices,
module_index: module_index)
module_index: module_index,
module_env: module_env)
}
block |> split(delimiter: "\n")
)
Expand Down
61 changes: 49 additions & 12 deletions src/v1/stage0/src/v1_compiler_emit_rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9246,7 +9246,11 @@ pub fn reference_derived_use_line_plan(
Some(info) => (info.module_name.clone() == provider.clone()),
std::option::Option::None => false,
} { __result.push(name); } } __result });
let block = emit_specific_import_block(provider.clone(), crate::v1_compiler_emit_core_support::module_to_filename(provider.clone()), names.clone(), emit_info.clone(), registry.clone(), local_type_names.clone(), export_sets.clone(), typed_modules.clone(), source_indices.clone(), module_index.clone());
let plan_module_env = match v1_rt::map_get(&module_index.by_name.clone(), this_module_name.clone()) {
Some(tm) => Some(tm.type_env.clone()),
std::option::Option::None => std::option::Option::None,
};
let block = emit_specific_import_block(provider.clone(), crate::v1_compiler_emit_core_support::module_to_filename(provider.clone()), names.clone(), emit_info.clone(), registry.clone(), local_type_names.clone(), export_sets.clone(), typed_modules.clone(), source_indices.clone(), module_index.clone(), plan_module_env.clone());
let block_lines = if (block.clone() == "".to_string()) {
Rc::new(vec![])
} else {
Expand Down Expand Up @@ -9690,6 +9694,7 @@ pub fn emit_module_full(
scope.type_env.clone().source_indices.clone(),
module_index.clone(),
typed_module.items.clone(),
Some(scope.type_env.clone()),
);
let dag_import_lines = if (imports_str.clone() == "".to_string()) {
Rc::new(vec![])
Expand Down Expand Up @@ -11986,6 +11991,25 @@ pub fn import_variant_parent_for_name(
}
}

pub fn import_name_resolves_to_kernel(name: String, module_env: Option<Rc<TypeEnv>>) -> bool {
match module_env.clone() {
std::option::Option::None => false,
Some(env) => {
match crate::v1_compiler_infer_env::lookup_type_by_name(env.clone(), name.clone()) {
std::option::Option::None => false,
Some(n) => match n.ident_span.clone() {
Some(sp) => {
((v1_rt::string_contains(&sp.file.clone(), "<kernel:".to_string())
&& (n.connective.clone() == Connective::NoConnective))
&& ((n.children.clone().len() as i64) == 0))
}
std::option::Option::None => false,
},
}
}
}
}

pub fn emit_specific_import_block(
import_module: String,
mod_name: String,
Expand All @@ -11997,22 +12021,34 @@ pub fn emit_specific_import_block(
typed_modules: Rc<Vec<Rc<TypedModule>>>,
source_indices: Rc<HashMap<String, Rc<NewlineIndex>>>,
module_index: Rc<ModuleIndex>,
module_env: Option<Rc<TypeEnv>>,
) -> String {
{
let type_summaries = emit_info.type_summaries.clone();
let deduped_names = crate::v1_compiler_emit_core_support::unique_strings(Rc::new({
let mut __result = Vec::new();
for n in filtered_names.iter().cloned() {
if {
let mut __all = true;
for ln in local_names.iter().cloned() {
if !(ln.clone() != n.clone()) {
__all = false;
break;
for n in Rc::new({
let mut __result = Vec::new();
for n in filtered_names.iter().cloned() {
if {
let mut __all = true;
for ln in local_names.iter().cloned() {
if !(ln.clone() != n.clone()) {
__all = false;
break;
}
}
__all
} {
__result.push(n);
}
__all
} {
}
__result
})
.iter()
.cloned()
{
if !import_name_resolves_to_kernel(n.clone(), module_env.clone()) {
__result.push(n);
}
}
Expand Down Expand Up @@ -13250,6 +13286,7 @@ pub fn emit_imports(
source_indices: Rc<HashMap<String, Rc<NewlineIndex>>>,
module_index: Rc<ModuleIndex>,
supplement_items: Rc<Vec<Rc<Node>>>,
module_env: Option<Rc<TypeEnv>>,
) -> String {
if ((imports.clone().len() as i64) == 0) {
"".to_string()
Expand Down Expand Up @@ -13277,7 +13314,7 @@ let block = if mod_has_wildcard.clone() {
let wildcard_line = v1_rt::concat(v1_rt::concat("use crate::".to_string(), mod_name.clone()), "::*;".to_string());
let reexport_surface = wildcard_reexport_surface_names(import_module.clone(), export_sets.clone(), typed_modules.clone(), source_indices.clone(), module_index.clone());
let merged_specific = crate::v1_compiler_emit_core_support::unique_strings(v1_rt::concat(Rc::new({ let mut __result = Vec::new(); for imp in Rc::new({ let mut __result = Vec::new(); for imp in mod_imports.iter().cloned() { if (crate::v1_std_core::import_is_all(imp.clone()) == false) { __result.push(imp); } } __result }).iter().cloned() { __result.extend((*crate::v1_std_core::import_specific_names_at(imp.clone(), source_indices.clone())).iter().cloned()); } __result }), reexport_surface.clone()));
let specific_block = emit_specific_import_block(import_module.clone(), mod_name.clone(), merged_specific.clone(), emit_info.clone(), registry.clone(), local_names.clone(), export_sets.clone(), typed_modules.clone(), source_indices.clone(), module_index.clone());
let specific_block = emit_specific_import_block(import_module.clone(), mod_name.clone(), merged_specific.clone(), emit_info.clone(), registry.clone(), local_names.clone(), export_sets.clone(), typed_modules.clone(), source_indices.clone(), module_index.clone(), module_env.clone());
if (specific_block.clone() != "".to_string()) {
v1_rt::concat(v1_rt::concat(wildcard_line.clone(), "\n".to_string()), specific_block.clone())
} else {
Expand All @@ -13289,7 +13326,7 @@ if (specific_block.clone() != "".to_string()) {
let specific_names = Rc::new({ let mut __result = Vec::new(); for imp in mod_imports.iter().cloned() { __result.extend((*crate::v1_std_core::import_specific_names_at(imp.clone(), source_indices.clone())).iter().cloned()); } __result });
let synth_for_module = module_data_field_struct_import_names(supplement_items.clone(), emit_info.type_summaries.clone(), import_module.clone(), export_sets.clone(), typed_modules.clone(), source_indices.clone(), module_index.clone());
let merged_specific = crate::v1_compiler_emit_core_support::unique_strings(v1_rt::concat(specific_names.clone(), synth_for_module.clone()));
emit_specific_import_block(import_module.clone(), mod_name.clone(), merged_specific.clone(), emit_info.clone(), registry.clone(), local_names.clone(), export_sets.clone(), typed_modules.clone(), source_indices.clone(), module_index.clone())
emit_specific_import_block(import_module.clone(), mod_name.clone(), merged_specific.clone(), emit_info.clone(), registry.clone(), local_names.clone(), export_sets.clone(), typed_modules.clone(), source_indices.clone(), module_index.clone(), module_env.clone())
}
};
Rc::new(block.clone().split(&"\n".to_string()).map(|s| s.to_string()).collect::<Vec<_>>())
Expand Down
Loading
Loading