|
|
|
|
@@ -218,14 +218,18 @@ pub const Lowering = struct {
|
|
|
|
|
/// gate would reject it) — so the bare TYPE leaf falls open here (F1).
|
|
|
|
|
emitting_default_context: bool = false,
|
|
|
|
|
/// Names declared as a BLOCK-LOCAL type (a `Foo :: struct/enum/union/error_set`
|
|
|
|
|
/// or bare type-decl statement inside a fn / init body). A local type registers
|
|
|
|
|
/// into the global type table and CLOBBERS a same-name top-level entry
|
|
|
|
|
/// (`registerStructDecl`'s `findByName … orelse intern` + `updatePreservingKey`),
|
|
|
|
|
/// so after it lowers the name IS the local type program-wide (single-author,
|
|
|
|
|
/// pre-E2). The source-aware bare-TYPE gate consults this so a legitimately
|
|
|
|
|
/// block-local type is never mistaken for a namespaced-only leak — even when a
|
|
|
|
|
/// namespaced-only import happens to author a top-level type of the same name.
|
|
|
|
|
local_type_names: std.StringHashMap(void) = std.StringHashMap(void).init(std.heap.page_allocator),
|
|
|
|
|
/// or bare type-decl statement inside a fn / init body), keyed by the DECLARING
|
|
|
|
|
/// source. A local type registers into the global type table and CLOBBERS a
|
|
|
|
|
/// same-name top-level entry (`registerStructDecl`'s `findByName … orelse intern`
|
|
|
|
|
/// + `updatePreservingKey`), so after it lowers the name IS the local type
|
|
|
|
|
/// program-wide (single-author, pre-E2). The source-aware bare-TYPE gate consults
|
|
|
|
|
/// this so a legitimately block-local type resolves in ITS OWN source (never
|
|
|
|
|
/// mistaken for a namespaced-only leak, even when a namespaced-only import authors
|
|
|
|
|
/// a same-name top-level type — R2). It is keyed by source because a local is
|
|
|
|
|
/// visible ONLY within the source that declares it: an imported template's field
|
|
|
|
|
/// resolution (run in the template's source context, E3 attempt-4) must NOT bind a
|
|
|
|
|
/// name the CALLER declared block-local (E3 attempt-5).
|
|
|
|
|
local_type_names: std.StringHashMap(std.StringHashMap(void)) = std.StringHashMap(std.StringHashMap(void)).init(std.heap.page_allocator),
|
|
|
|
|
struct_defaults_map: std.StringHashMap([]const ?*const Node) = std.StringHashMap([]const ?*const Node).init(std.heap.page_allocator), // struct name → field defaults
|
|
|
|
|
struct_instance_bindings: std.StringHashMap(std.StringHashMap(TypeId)) = std.StringHashMap(std.StringHashMap(TypeId)).init(std.heap.page_allocator), // mangled struct name → type param bindings
|
|
|
|
|
struct_instance_template: std.StringHashMap([]const u8) = std.StringHashMap([]const u8).init(std.heap.page_allocator), // mangled struct name → template name
|
|
|
|
|
@@ -1977,12 +1981,20 @@ pub const Lowering = struct {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 2. A block-local type (declared inside a fn / init body) clobbers the
|
|
|
|
|
// global entry for its name, so `existing` IS that local type — never a
|
|
|
|
|
// namespaced-only leak. Resolve it ungated (R2): a legitimately-scoped
|
|
|
|
|
// local must not be rejected just because a namespaced-only import also
|
|
|
|
|
// authors a top-level type of the same name.
|
|
|
|
|
if (self.local_type_names.contains(name)) {
|
|
|
|
|
// global entry for its name, so `existing` IS that local type. A local is
|
|
|
|
|
// visible ONLY in its OWN source. Resolve it ungated when the query
|
|
|
|
|
// originates in the local's source (R2): a legitimately-scoped local must
|
|
|
|
|
// not be rejected just because a namespaced-only import also authors a
|
|
|
|
|
// top-level type of the same name. When the same name is a block-local of a
|
|
|
|
|
// DIFFERENT source — e.g. an imported template's field (resolved in the
|
|
|
|
|
// template's source context, E3 attempt-4) naming a type the CALLER
|
|
|
|
|
// declared block-local — the local is NOT visible here: route to the
|
|
|
|
|
// undeclared path so the leak surfaces, never the `registered` catch-all
|
|
|
|
|
// (arm 4) which would resolve the globally-registered cross-source local.
|
|
|
|
|
if (self.localTypeInSource(from, name)) {
|
|
|
|
|
if (registered) |existing| return .{ .resolved = existing };
|
|
|
|
|
} else if (self.localTypeInAnySource(name)) {
|
|
|
|
|
return self.forwardAliasOrUndeclared(name, from);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 3. Authored as a TYPE (named OR alias) in some module, but NOT flat-
|
|
|
|
|
@@ -2184,9 +2196,29 @@ pub const Lowering = struct {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Record a name declared as a BLOCK-LOCAL type so the bare-TYPE gate never
|
|
|
|
|
/// mistakes it for a namespaced-only leak (see `local_type_names`).
|
|
|
|
|
/// mistakes it for a namespaced-only leak (see `local_type_names`). Keyed by the
|
|
|
|
|
/// declaring source (the function being lowered) so the local is visible only
|
|
|
|
|
/// within that source.
|
|
|
|
|
fn recordLocalTypeName(self: *Lowering, name: []const u8) void {
|
|
|
|
|
self.local_type_names.put(name, {}) catch {};
|
|
|
|
|
const src = self.current_source_file orelse self.main_file orelse return;
|
|
|
|
|
const gop = self.local_type_names.getOrPut(src) catch return;
|
|
|
|
|
if (!gop.found_existing) gop.value_ptr.* = std.StringHashMap(void).init(std.heap.page_allocator);
|
|
|
|
|
gop.value_ptr.put(name, {}) catch {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// TRUE iff `name` is a block-local type declared in `source`.
|
|
|
|
|
fn localTypeInSource(self: *Lowering, source: []const u8, name: []const u8) bool {
|
|
|
|
|
if (self.local_type_names.get(source)) |inner| return inner.contains(name);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// TRUE iff `name` is a block-local type declared in ANY source. A name that is a
|
|
|
|
|
/// local SOMEWHERE but not in the querying source is a cross-source local — not
|
|
|
|
|
/// visible from the querying source.
|
|
|
|
|
fn localTypeInAnySource(self: *Lowering, name: []const u8) bool {
|
|
|
|
|
var it = self.local_type_names.valueIterator();
|
|
|
|
|
while (it.next()) |inner| if (inner.contains(name)) return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Resolve the bare TYPE leaf to a `TypeId` for `resolveTypeWithBindings`.
|
|
|
|
|
|