docs(ir): mark sema/types as editor-only, not compiler truth (A1.2)
Architecture phase A1.2 — documentation/comment only, no behavior change. Resolve the ambiguity over which type model compiler decisions trust: - src/sema.zig: file-level module doc stating it is the editor symbol/type index for the language server (navigation/completion), NOT a compiler semantic pass. Its Type values are editor metadata; the compiler uses the canonical TypeId/TypeTable model in src/ir/. sx requires no as-you-type type checking -- authoritative diagnostics are produced on save by the canonical pipeline. Added notes on SemaResult, Analyzer, resolveTypeNode, inferExprType. No public API renamed (would churn LSP call sites). - src/types.zig: note that Type is editor metadata only, not compiler truth; do not expand for new compiler semantics (A8 deletes/reduces it). - src/ir/types.zig: fix stale TypeTable.aliases comment -- it borrows Lowering.program_index.type_alias_map (post-A1.1b). Deleting the LSP's parallel sema diagnostic stream is A8.1, not this step. Gate green: zig build, zig build test, bash tests/run_examples.sh (350 passed).
This commit is contained in:
@@ -332,7 +332,7 @@ pub const TypeTable = struct {
|
||||
slice_arena: std.heap.ArenaAllocator,
|
||||
/// Target pointer size in bytes (4 for wasm32, 8 for 64-bit targets).
|
||||
pointer_size: u8 = 8,
|
||||
/// Borrowed pointer to Lowering's `type_alias_map`. When set,
|
||||
/// Borrowed pointer to `Lowering.program_index.type_alias_map`. When set,
|
||||
/// `resolveTypeName` consults it before falling through to
|
||||
/// the empty-struct-stub default — so a name like `ShaderHandle`
|
||||
/// (defined `ShaderHandle :: u32`) resolves to `u32` rather than
|
||||
|
||||
27
src/sema.zig
27
src/sema.zig
@@ -1,3 +1,19 @@
|
||||
//! Editor-facing symbol/type INDEX for the language server — not a compiler
|
||||
//! semantic pass.
|
||||
//!
|
||||
//! Powers editor navigation and completion (go-to-definition, find-references,
|
||||
//! hover, member/field lookup) by building a best-effort, resilient view of a
|
||||
//! file's symbols and approximate types. The `Type` values here come from
|
||||
//! `src/types.zig`, which is editor metadata only.
|
||||
//!
|
||||
//! This is NOT the compiler's source of truth. Compiler type resolution,
|
||||
//! lowering, and codegen consume the canonical `TypeId` / `TypeTable` model in
|
||||
//! `src/ir/`, never this module. sx does not require as-you-type type checking;
|
||||
//! authoritative diagnostics are produced on save by running the canonical
|
||||
//! compiler pipeline (`src/lsp/server.zig`), not by this analyzer. The public
|
||||
//! names below (`Analyzer`, `analyze`, `inferExprType`, `resolveTypeNode`,
|
||||
//! `SemaResult`) name an editor index, not compiler authority.
|
||||
|
||||
const std = @import("std");
|
||||
const ast = @import("ast.zig");
|
||||
const Node = ast.Node;
|
||||
@@ -60,6 +76,9 @@ pub const StructTypeInfo = struct {
|
||||
|
||||
pub const TypeMap = std.AutoHashMap(*const Node, Type);
|
||||
|
||||
/// Editor index for one file: symbols, references, member refs, approximate
|
||||
/// types, and best-effort diagnostics for navigation/completion. Not consumed
|
||||
/// by the compiler pipeline (see module doc).
|
||||
pub const SemaResult = struct {
|
||||
symbols: []const Symbol,
|
||||
references: []const Reference,
|
||||
@@ -72,6 +91,8 @@ pub const SemaResult = struct {
|
||||
type_map: TypeMap,
|
||||
};
|
||||
|
||||
/// Builds the editor symbol/type index (see module doc). Not a compiler
|
||||
/// semantic pass — its `Type` results are editor metadata, not compiler truth.
|
||||
pub const Analyzer = struct {
|
||||
allocator: std.mem.Allocator,
|
||||
symbols: std.ArrayList(Symbol),
|
||||
@@ -328,7 +349,8 @@ pub const Analyzer = struct {
|
||||
try self.fn_signatures.put(key, .{ .param_types = &.{}, .return_type = ret });
|
||||
}
|
||||
|
||||
/// Resolve a type annotation node to a Type.
|
||||
/// Resolve a type annotation node to an editor `Type` (metadata only — the
|
||||
/// compiler resolves type nodes to canonical `TypeId` in `src/ir/`).
|
||||
/// Handles primitives, type_expr, array_type_expr, parameterized_type_expr,
|
||||
/// type aliases, enum types, and struct types.
|
||||
pub fn resolveTypeNode(self: *Analyzer, type_node: ?*Node) Type {
|
||||
@@ -540,7 +562,8 @@ pub const Analyzer = struct {
|
||||
return .{ .struct_type = mangled };
|
||||
}
|
||||
|
||||
/// Infer the type of an expression node without LLVM.
|
||||
/// Infer an approximate editor `Type` for an expression (hover/completion;
|
||||
/// metadata only — NOT a compiler type decision, which uses `TypeId`).
|
||||
/// Uses fn_signatures for call return types, struct_types for field access,
|
||||
/// symbols for identifier types, and Type.widen for arithmetic promotion.
|
||||
pub fn inferExprType(self: *Analyzer, node: *const Node) Type {
|
||||
|
||||
@@ -2,6 +2,12 @@ const std = @import("std");
|
||||
const ast = @import("ast.zig");
|
||||
const Node = ast.Node;
|
||||
|
||||
/// Editor metadata type model, used only by `src/sema.zig` (the language-server
|
||||
/// symbol/type index) for navigation, completion, and hover. NOT the compiler's
|
||||
/// source of truth: lowering, codegen, and layout use the canonical
|
||||
/// `TypeId` / `TypeTable` model in `src/ir/types.zig`. Do not expand this to
|
||||
/// carry new compiler semantics; the architecture endpoint (phase A8) is to
|
||||
/// delete it or reduce it to display-only data derived from `TypeId`.
|
||||
pub const Type = union(enum) {
|
||||
// Variable-width integers (1–64 bits)
|
||||
signed: u8,
|
||||
|
||||
Reference in New Issue
Block a user