diff --git a/src/v2.5/04_infer.dag b/src/v2.5/04_infer.dag new file mode 100644 index 00000000000..0123118c650 --- /dev/null +++ b/src/v2.5/04_infer.dag @@ -0,0 +1,83 @@ +module v2_5.compiler.infer + +import v2_5.std.node { Symbol } +import v2_5.std.stage_types { + NormalizedModule, + InferredModule, + InferredOtherItem +} + +type ExprDataDissolution + = NoExprDataRetired + | LiteralCase + | ErrorCase + | VarCase + | FieldAccessCase + | CallCase + | MethodCallCase + | MatchCase + | IfCase + | LetCase + | RecordLitCase + | ListLitCase + | BinOpCase + | UnaryOpCase + | LambdaCase + | StringInterpCase + | BlockCase + | CastCase + | ForEachCase + | IndexCase + | SliceCase + | ReturnCase + +type InferCarrierClosure + = ClosedExprDataDissolution + | ClosedInferReadiness + | ClosedBinderScopeFold + | ClosedRecursiveExprFold + +type InferReadiness + = AwaitingTier1StageTypes { gate: Symbol } + | AwaitingRecursiveExprFold { gate: Symbol } + | BoundToTier1StageTypes + +type BinderScopeFold + = AwaitingPreChildScopeHook { gate: Symbol } + | HasPreChildScopeHook + +data v25_infer_tier1_gate: Symbol = v25_infer_tier1_gate +data recursive_expr_fold_gate: Symbol = recursive_expr_fold_gate +data binder_scope_fold_gate: Symbol = binder_scope_fold_gate + +data infer_readiness: InferReadiness = AwaitingRecursiveExprFold { gate: recursive_expr_fold_gate } +data binder_scope_fold_status: BinderScopeFold = AwaitingPreChildScopeHook { gate: binder_scope_fold_gate } +data infer_carrier_closure: List = [ + ClosedExprDataDissolution, + ClosedInferReadiness, + ClosedBinderScopeFold, + ClosedRecursiveExprFold +] + +fn infer(module: NormalizedModule) -> InferredModule { + match infer_readiness { + AwaitingTier1StageTypes { gate: _ } => + infer_unavailable(module: module, keyword: "infer-awaiting-tier1-stage-types") + AwaitingRecursiveExprFold { gate: _ } => + infer_unavailable(module: module, keyword: "infer-awaiting-recursive-expression-fold") + BoundToTier1StageTypes => + infer_unavailable(module: module, keyword: "infer-bound-without-recursive-expression-fold") + } +} + +fn infer_unavailable(module: NormalizedModule, keyword: String) -> InferredModule { + InferredModule { + name: module.name, + imports: [], + items: [InferredOtherItem { + keyword: keyword, + raw_span: module.span + }], + span: module.span + } +} diff --git a/src/v2.5/std/diagnostic.dag b/src/v2.5/std/diagnostic.dag new file mode 100644 index 00000000000..2f27e5b6c87 --- /dev/null +++ b/src/v2.5/std/diagnostic.dag @@ -0,0 +1,42 @@ +// src/v2.5/std/diagnostic.dag +// Scope: fail-closed diagnostic schema for v2.5. +// Owns: Diagnostic, Outcome, Locus, Extent, Correction, NoCorrectionReason. +// Consumes: v2_5.std.node. +// Status: v2.5 Tier 0 draft. + +module v2_5.std.diagnostic + +import v2_5.std.node { Symbol, Nat, Node, Path } + +// 🟡 coproduct dissolution — feature:byte-range-ordering-witness +type Extent + = WholeFile + | ByteRange { start: Nat, end: Nat } + +// 🟢 coproduct dissolution +type Locus + = Textual { file: Symbol, extent: Extent } + | NodeLocus { node: Node } + | PortLocus { path: Path } + +// 🟢 coproduct dissolution +type NoCorrectionReason + = UserInputBoundary + | AmbiguousIntent + | ExternalContractUnknown + +// 🟢 coproduct dissolution +type Correction + = Suggested { node: Node } + | Unavailable { reason: NoCorrectionReason } + +type Diagnostic { + reason: Symbol + at: Locus + correction: Correction +} + +// 🟢 coproduct dissolution +type Outcome + = Produced { value: T } + | Rejected { diagnostic: Diagnostic } diff --git a/src/v2.5/std/identity.dag b/src/v2.5/std/identity.dag new file mode 100644 index 00000000000..306f48b88fe --- /dev/null +++ b/src/v2.5/std/identity.dag @@ -0,0 +1,22 @@ +// v2.5 identity and provenance — shared across all pipeline phases. +// Parse phases use AuthoredName; post-resolve phases use Symbol (from node). + +module v2_5.std.identity + +import v2_5.std.node { Symbol } + +type SourceSpan { + start: Int + end: Int + file: String +} + +type AuthoredName { + text: String + span: SourceSpan +} + +type BoundName { + symbol: Symbol + span: SourceSpan +} diff --git a/src/v2.5/std/node.dag b/src/v2.5/std/node.dag new file mode 100644 index 00000000000..6722178f876 --- /dev/null +++ b/src/v2.5/std/node.dag @@ -0,0 +1,146 @@ +// src/v2.5/std/node.dag +// Scope: v2.5 substrate root — type kernel for the forked tree. +// Owns: Symbol, Hash, Nat, Connective, Behavior, NodeKind, EdgeLabel, Edge, Node, NodeFold, fold_node, EdgeDiscipline, connective_edge_discipline, all_edges_named, all_edges_positional, name_occurrences, all_names_distinct, edges_conform, node_locally_well_formed, node_well_formed, PathStep, Path, Edit, Diff. +// Consumes: none. +// Status: v2.5 Tier 0 draft. + +module v2_5.std.node + +type Symbol +type Hash +type Nat + +// 🟢 coproduct dissolution +type Connective + = Atom { identity: Symbol } + | Conj + | Disj + | Arrow + | Cardinality + | Instantiation + +// 🟢 coproduct dissolution +type Behavior + = Value + | Transform + | Branch + | Loop + | Bind + +// 🟢 coproduct dissolution +type NodeKind + = TypeForm { connective: Connective } + | Computation { behavior: Behavior } + +// 🟢 coproduct dissolution +type EdgeLabel + = Named { name: Symbol } + | Positional + +type Edge { + label: EdgeLabel + target: Node +} + +type Node { + kind: NodeKind + children: List +} + +type NodeFold { + init: fn(Node) -> R + step: fn(R, Edge, R) -> R +} + +fn fold_node(n: Node, algebra: NodeFold) -> R { + fold(n.children, init: algebra.init(n), f: (acc, e) => + algebra.step(acc, e, fold_node(n: e.target, algebra: algebra)) + ) +} + +// 🟢 coproduct dissolution +type EdgeDiscipline + = NoEdges + | LabeledEdges + | PositionalEdges + +fn connective_edge_discipline(c: Connective) -> EdgeDiscipline { + match c { + Atom { identity: _ } => NoEdges + Conj => LabeledEdges + Disj => LabeledEdges + Arrow => PositionalEdges + Cardinality => PositionalEdges + Instantiation => PositionalEdges + } +} + +fn all_edges_named(children: List) -> Bool { + fold(children, init: true, f: (acc, e) => match e.label { + Named { name: _ } => acc + Positional => false + }) +} + +fn all_edges_positional(children: List) -> Bool { + fold(children, init: true, f: (acc, e) => match e.label { + Named { name: _ } => false + Positional => acc + }) +} + +fn name_occurrences(name: Symbol, children: List) -> Int { + fold(children, init: 0, f: (acc, e) => match e.label { + Named { name: n } => if n == name { acc + 1 } else { acc } + Positional => acc + }) +} + +fn all_names_distinct(children: List) -> Bool { + fold(children, init: true, f: (acc, e) => match e.label { + Named { name: n } => acc && (name_occurrences(name: n, children: children) == 1) + Positional => acc + }) +} + +fn edges_conform(children: List, d: EdgeDiscipline) -> Bool { + match d { + NoEdges => count(children) == 0 + LabeledEdges => + all_edges_named(children: children) && all_names_distinct(children: children) + PositionalEdges => all_edges_positional(children: children) + } +} + +fn node_locally_well_formed(n: Node) -> Bool { + match n.kind { + TypeForm { connective: c } => + edges_conform(children: n.children, d: connective_edge_discipline(c: c)) + Computation { behavior: _ } => true + } +} + +fn node_well_formed(n: Node) -> Bool { + fold_node(n: n, algebra: NodeFold { + init: n0 => node_locally_well_formed(n: n0), + step: (acc, edge, child_ok) => acc && child_ok + }) +} + +// 🟢 coproduct dissolution +type PathStep + = NamedStep { name: Symbol } + | PositionalStep { index: Nat } + +type Path { + steps: List +} + +type Edit { + at: Path + replacement: Node +} + +type Diff { + edits: List +} diff --git a/src/v2.5/std/stage_types.dag b/src/v2.5/std/stage_types.dag new file mode 100644 index 00000000000..79f43fbea43 --- /dev/null +++ b/src/v2.5/std/stage_types.dag @@ -0,0 +1,1155 @@ +// v2.5 phase-typed pipeline interface kit (Tier 1). +// Each stage owns a distinct closed-sum root type. No optional fields acting +// as kind discriminators; no inferred? on pre-infer phases; no NodeId side tables. +// +// Phase AST shapes live here; substrate is v2_5.std.node only (PR #3422, cool-bee-832). +// NodeKind = TypeForm | Computation (2-variant, THESIS-faithful). Declarations, wrappers, +// and module structure are stage-level variants (ParseItem, ParseExpr, …), not substrate. +// Reconcile: calm-crane-724 normalize seam (Seam* types). +// Lowering: phase AST → Node { kind, children: List } at stage boundaries. +// +// Pipeline (type signatures are the contract): +// tokenize : SourceText -> TokenStream +// parse : TokenStream -> ParseModule +// resolve : ParseModule -> ResolvedModule +// normalize: ResolvedModule -> NormalizedModule +// infer : NormalizedModule -> InferredModule +// emit : InferredModule -> TargetSource + +module v2_5.std.stage_types + +import v2_5.std.identity { SourceSpan, AuthoredName, BoundName } +import v2_5.std.node { + Symbol, + Connective, + Behavior, + EdgeLabel +} +import v2_5.std.syntax { + BinOp, UnaryOpKind, LiteralValue, OperationModifier, ExprErrorKind, AlgebraFieldKind +} +import v2_5.std.token { TokenStream } + +// Param presence (v2 Required/CardOptional) — distinct from Connective::Cardinality. +type ParamCardinality + = Required + | CardOptional + +type SurfaceSugarKind + = ServiceSugar + | FnSugar + | TypeSugar + | OperationSugar + +data c3_surface_sugar_service: Symbol = c3_surface_sugar_service +data c3_surface_sugar_fn: Symbol = c3_surface_sugar_fn +data c3_surface_sugar_type: Symbol = c3_surface_sugar_type +data c3_surface_sugar_operation: Symbol = c3_surface_sugar_operation + +// THESIS-faithful discrimination (stage-types only; substrate stays TypeForm | Computation): +// ParseModule / ParseImport / ParseFn / ParseTypeDecl / ParseService → ParseItem variants +// ParseMatchArm / ParsePattern / ParseArg / ParseFieldInit → nested under ParseExpr +// Lowering to substrate: module items → TypeForm { connective: Conj }; expr bodies → Computation + +// ========================================================================= +// Parse phase — syntax only, no binding or typing +// ========================================================================= + +type ParsePattern + = ParsePatBind { name: AuthoredName } + | ParsePatLit { value: LiteralValue } + | ParsePatVariant { + name: AuthoredName + parent_enum: AuthoredName? + field_bindings: List + } + | ParsePatWildcard + +type ParseFieldBinding { + field: AuthoredName + pattern: ParsePattern +} + +type ParseParam { + name: AuthoredName + type_expr: ParseTypeExpr + default_expr: ParseExpr? + cardinality: ParamCardinality +} + +type ParseArg { + name: AuthoredName? + value: ParseExpr +} + +type ParseFieldInit { + name: AuthoredName + value: ParseExpr +} + +type ParseMatchArm { + pattern: ParsePattern + guard: ParseExpr? + body: ParseExpr +} + +type ParseTypeField { + name: AuthoredName + type_expr: ParseTypeExpr + cardinality: ParamCardinality + default_expr: ParseExpr? + from_key: AuthoredName? +} + +type ParseTypeVariant { + name: AuthoredName + fields: List +} + +type ParseTypeExpr + = ParseTypeAtom { name: AuthoredName } + | ParseTypeConj { fields: List } + | ParseTypeDisj { variants: List } + | ParseTypeArrow { + params: List + return_type: ParseTypeExpr + } + | ParseTypeError { message: String, span: SourceSpan } + +type ParseExpr + = ParseLit { value: LiteralValue, span: SourceSpan } + | ParseError { kind: ExprErrorKind, message: String, span: SourceSpan } + | ParseVar { name: AuthoredName } + | ParseFieldAccess { + receiver: ParseExpr + field: AuthoredName + } + | ParseCall { + callee: AuthoredName + args: List + } + | ParseMethodCall { + receiver: ParseExpr + method: AuthoredName + args: List + } + | ParseMatch { + scrutinee: ParseExpr + arms: List + } + | ParseIf { + condition: ParseExpr + then_expr: ParseExpr + else_expr: ParseExpr + } + | ParseLet { + name: AuthoredName + value: ParseExpr + body: ParseExpr + } + | ParseRecordLit { + type_name: AuthoredName? + fields: List + } + | ParseListLit { elements: List } + | ParseBinOp { + op: BinOp + left: ParseExpr + right: ParseExpr + algebra_field: AlgebraFieldKind? + } + | ParseUnaryOp { op: UnaryOpKind, operand: ParseExpr } + | ParseLambda { + params: List + body: ParseExpr + } + | ParseStringInterp { + parts: List + } + | ParseBlock { statements: List } + | ParseCast { + expr: ParseExpr + target_type: ParseTypeExpr + } + | ParseForEach { + variable: AuthoredName + iterable: ParseExpr + body: ParseExpr + } + | ParseIndex { + base: ParseExpr + index: ParseExpr + } + | ParseSlice { + base: ParseExpr + start: ParseExpr? + end: ParseExpr? + } + | ParseReturn { value: ParseExpr? } + +type ParseStringPart + = ParseStrText { value: String } + | ParseStrInterp { expr: ParseExpr } + +type ParseBlock { + statements: List + span: SourceSpan +} + +type ParseTransport + = ParseTransportRest { properties: List } + | ParseTransportShell { properties: List } + | ParseTransportFile { properties: List } + | ParseTransportLocal { properties: List } + +type ParseTransportProperty { + key: AuthoredName + value: ParseExpr +} + +type ParseOperation { + name: AuthoredName + params: List + outputs: List + modifiers: List + body: ParseBlock? +} + +type ParseResourceUse { + name: AuthoredName + resource_type: ParseTypeExpr +} + +type ParseImport + = ParseImportAll { module_path: String, span: SourceSpan } + | ParseImportNames { + module_path: String + names: List + span: SourceSpan + } + +type ParseItem + = ParseFn { + name: AuthoredName + type_params: List + params: List + return_type: ParseTypeExpr? + uses: List + body: ParseBlock + span: SourceSpan + } + | ParseFunc { + name: AuthoredName + type_params: List + params: List + return_type: ParseTypeExpr? + uses: List + body: ParseBlock + span: SourceSpan + } + | ParseTypeDecl { + name: AuthoredName + type_params: List + definition: ParseTypeExpr + span: SourceSpan + } + | ParseDataDecl { + name: AuthoredName + type_annotation: ParseTypeExpr + value: ParseExpr + span: SourceSpan + } + | ParseService { + name: AuthoredName + transport: ParseTransport + operations: List + span: SourceSpan + } + | ParseOtherItem { + keyword: String + raw_span: SourceSpan + } + +type ParseModule { + name: AuthoredName + imports: List + items: List + span: SourceSpan +} + +// ========================================================================= +// Resolve phase — names bound; still no typing +// ========================================================================= + +type ResolvedPattern + = ResolvedPatBind { name: BoundName } + | ResolvedPatLit { value: LiteralValue } + | ResolvedPatVariant { + name: BoundName + parent_enum: BoundName? + field_bindings: List + } + | ResolvedPatWildcard + +type ResolvedFieldBinding { + field: BoundName + pattern: ResolvedPattern +} + +type ResolvedParam { + name: BoundName + type_expr: ResolvedTypeExpr + default_expr: ResolvedExpr? + cardinality: ParamCardinality +} + +type ResolvedArg { + name: BoundName? + value: ResolvedExpr +} + +type ResolvedFieldInit { + name: BoundName + value: ResolvedExpr +} + +type ResolvedMatchArm { + pattern: ResolvedPattern + guard: ResolvedExpr? + body: ResolvedExpr +} + +type ResolvedTypeField { + name: BoundName + type_expr: ResolvedTypeExpr + cardinality: ParamCardinality + default_expr: ResolvedExpr? + from_key: BoundName? +} + +type ResolvedTypeVariant { + name: BoundName + fields: List +} + +type ResolvedTypeExpr + = ResolvedTypeAtom { name: BoundName } + | ResolvedTypeConj { fields: List } + | ResolvedTypeDisj { variants: List } + | ResolvedTypeArrow { + params: List + return_type: ResolvedTypeExpr + } + | ResolvedTypeError { message: String, span: SourceSpan } + +type ResolvedExpr + = ResolvedLit { value: LiteralValue, span: SourceSpan } + | ResolvedError { kind: ExprErrorKind, message: String, span: SourceSpan } + | ResolvedVar { name: BoundName } + | ResolvedFieldAccess { + receiver: ResolvedExpr + field: BoundName + } + | ResolvedCall { + callee: BoundName + args: List + } + | ResolvedMethodCall { + receiver: ResolvedExpr + method: BoundName + args: List + } + | ResolvedMatch { + scrutinee: ResolvedExpr + arms: List + } + | ResolvedIf { + condition: ResolvedExpr + then_expr: ResolvedExpr + else_expr: ResolvedExpr + } + | ResolvedLet { + name: BoundName + value: ResolvedExpr + body: ResolvedExpr + } + | ResolvedRecordLit { + type_name: BoundName? + fields: List + } + | ResolvedListLit { elements: List } + | ResolvedBinOp { + op: BinOp + left: ResolvedExpr + right: ResolvedExpr + algebra_field: AlgebraFieldKind? + } + | ResolvedUnaryOp { op: UnaryOpKind, operand: ResolvedExpr } + | ResolvedLambda { + params: List + body: ResolvedExpr + } + | ResolvedStringInterp { + parts: List + } + | ResolvedBlock { statements: List } + | ResolvedCast { + expr: ResolvedExpr + target_type: ResolvedTypeExpr + } + | ResolvedForEach { + variable: BoundName + iterable: ResolvedExpr + body: ResolvedExpr + } + | ResolvedIndex { + base: ResolvedExpr + index: ResolvedExpr + } + | ResolvedSlice { + base: ResolvedExpr + start: ResolvedExpr? + end: ResolvedExpr? + } + | ResolvedReturn { value: ResolvedExpr? } + +type ResolvedStringPart + = ResolvedStrText { value: String } + | ResolvedStrInterp { expr: ResolvedExpr } + +type ResolvedBlock { + statements: List + span: SourceSpan +} + +type ResolvedTransport + = ResolvedTransportRest { properties: List } + | ResolvedTransportShell { properties: List } + | ResolvedTransportFile { properties: List } + | ResolvedTransportLocal { properties: List } + +type ResolvedTransportProperty { + key: BoundName + value: ResolvedExpr +} + +type ResolvedOperation { + name: BoundName + params: List + outputs: List + modifiers: List + body: ResolvedBlock? +} + +type ResolvedResourceUse { + name: BoundName + resource_type: ResolvedTypeExpr +} + +type ResolvedImport + = ResolvedImportAll { module_path: Symbol, span: SourceSpan } + | ResolvedImportNames { + module_path: Symbol + names: List + span: SourceSpan + } + +type ResolvedItemCore + = ResolvedFn { + name: BoundName + type_params: List + params: List + return_type: ResolvedTypeExpr? + uses: List + body: ResolvedBlock + span: SourceSpan + } + | ResolvedFunc { + name: BoundName + type_params: List + params: List + return_type: ResolvedTypeExpr? + uses: List + body: ResolvedBlock + span: SourceSpan + } + | ResolvedTypeDecl { + name: BoundName + type_params: List + definition: ResolvedTypeExpr + span: SourceSpan + } + | ResolvedDataDecl { + name: BoundName + type_annotation: ResolvedTypeExpr + value: ResolvedExpr + span: SourceSpan + } + | ResolvedService { + name: BoundName + transport: ResolvedTransport + operations: List + span: SourceSpan + } + | ResolvedOtherItem { + keyword: String + raw_span: SourceSpan + } + +type ResolvedModuleItem + = ResolvedSugared { + sugar: SurfaceSugarKind + inner: ResolvedItemCore + span: SourceSpan + } + | ResolvedCore { item: ResolvedItemCore } + +type ResolvedModule { + name: BoundName + imports: List + items: List + span: SourceSpan +} + +// ========================================================================= +// Normalize phase — surface sugar stripped; items are ResolvedItemCore only +// ========================================================================= + +type NormalizedPattern + = NormalizedPatBind { name: BoundName } + | NormalizedPatLit { value: LiteralValue } + | NormalizedPatVariant { + name: BoundName + parent_enum: BoundName? + field_bindings: List + } + | NormalizedPatWildcard + +type NormalizedFieldBinding { + field: BoundName + pattern: NormalizedPattern +} + +type NormalizedParam { + name: BoundName + type_expr: NormalizedTypeExpr + default_expr: NormalizedExpr? + cardinality: ParamCardinality +} + +type NormalizedArg { + name: BoundName? + value: NormalizedExpr +} + +type NormalizedFieldInit { + name: BoundName + value: NormalizedExpr +} + +type NormalizedMatchArm { + pattern: NormalizedPattern + guard: NormalizedExpr? + body: NormalizedExpr +} + +type NormalizedTypeField { + name: BoundName + type_expr: NormalizedTypeExpr + cardinality: ParamCardinality + default_expr: NormalizedExpr? + from_key: BoundName? +} + +type NormalizedTypeVariant { + name: BoundName + fields: List +} + +type NormalizedTypeExpr + = NormalizedTypeAtom { name: BoundName } + | NormalizedTypeConj { fields: List } + | NormalizedTypeDisj { variants: List } + | NormalizedTypeArrow { + params: List + return_type: NormalizedTypeExpr + } + | NormalizedTypeError { message: String, span: SourceSpan } + +type NormalizedExpr + = NormalizedLit { value: LiteralValue, span: SourceSpan } + | NormalizedError { kind: ExprErrorKind, message: String, span: SourceSpan } + | NormalizedVar { name: BoundName } + | NormalizedFieldAccess { + receiver: NormalizedExpr + field: BoundName + } + | NormalizedCall { + callee: BoundName + args: List + } + | NormalizedMethodCall { + receiver: NormalizedExpr + method: BoundName + args: List + } + | NormalizedMatch { + scrutinee: NormalizedExpr + arms: List + } + | NormalizedIf { + condition: NormalizedExpr + then_expr: NormalizedExpr + else_expr: NormalizedExpr + } + | NormalizedLet { + name: BoundName + value: NormalizedExpr + body: NormalizedExpr + } + | NormalizedRecordLit { + type_name: BoundName? + fields: List + } + | NormalizedListLit { elements: List } + | NormalizedBinOp { + op: BinOp + left: NormalizedExpr + right: NormalizedExpr + algebra_field: AlgebraFieldKind? + } + | NormalizedUnaryOp { op: UnaryOpKind, operand: NormalizedExpr } + | NormalizedLambda { + params: List + body: NormalizedExpr + } + | NormalizedStringInterp { + parts: List + } + | NormalizedBlock { statements: List } + | NormalizedCast { + expr: NormalizedExpr + target_type: NormalizedTypeExpr + } + | NormalizedForEach { + variable: BoundName + iterable: NormalizedExpr + body: NormalizedExpr + } + | NormalizedIndex { + base: NormalizedExpr + index: NormalizedExpr + } + | NormalizedSlice { + base: NormalizedExpr + start: NormalizedExpr? + end: NormalizedExpr? + } + | NormalizedReturn { value: NormalizedExpr? } + +type NormalizedStringPart + = NormalizedStrText { value: String } + | NormalizedStrInterp { expr: NormalizedExpr } + +type NormalizedBlock { + statements: List + span: SourceSpan +} + +type NormalizedTransport + = NormalizedTransportRest { properties: List } + | NormalizedTransportShell { properties: List } + | NormalizedTransportFile { properties: List } + | NormalizedTransportLocal { properties: List } + +type NormalizedTransportProperty { + key: BoundName + value: NormalizedExpr +} + +type NormalizedOperation { + name: BoundName + params: List + outputs: List + modifiers: List + body: NormalizedBlock? +} + +type NormalizedResourceUse { + name: BoundName + resource_type: NormalizedTypeExpr +} + +type NormalizedImport + = NormalizedImportAll { module_path: Symbol, span: SourceSpan } + | NormalizedImportNames { + module_path: Symbol + names: List + span: SourceSpan + } + +type NormalizedItem + = NormalizedFn { + name: BoundName + type_params: List + params: List + return_type: NormalizedTypeExpr? + uses: List + body: NormalizedBlock + span: SourceSpan + } + | NormalizedFunc { + name: BoundName + type_params: List + params: List + return_type: NormalizedTypeExpr? + uses: List + body: NormalizedBlock + span: SourceSpan + } + | NormalizedTypeDecl { + name: BoundName + type_params: List + definition: NormalizedTypeExpr + span: SourceSpan + } + | NormalizedDataDecl { + name: BoundName + type_annotation: NormalizedTypeExpr + value: NormalizedExpr + span: SourceSpan + } + | NormalizedService { + name: BoundName + transport: NormalizedTransport + operations: List + span: SourceSpan + } + | NormalizedOtherItem { + keyword: String + raw_span: SourceSpan + } + +type NormalizedModule { + name: BoundName + imports: List + items: List + span: SourceSpan +} + +// ========================================================================= +// Infer phase — typing is structural fact on every expression variant +// ========================================================================= + +type InferredType + = InferredTypeOk { form: TypeForm } + | InferredTypeError { message: String, span: SourceSpan } + | InferredTypeVariable { id: Symbol } + +type TypeForm + = TypeAtom { name: BoundName } + | TypeConj { fields: List } + | TypeDisj { variants: List } + | TypeArrow { + params: List + return_type: TypeForm + } + +type InferredTypeField { + name: BoundName + field_type: InferredType + cardinality: ParamCardinality +} + +type InferredTypeVariant { + name: BoundName + fields: List +} + +type InferredTypeParam { + name: BoundName + param_type: InferredType + cardinality: ParamCardinality +} + +type TailRecursionFacts + = NotRecursive + | SelfRecursive { tail_only: Bool } + +type InferredPattern + = InferredPatBind { name: BoundName, pattern_type: InferredType } + | InferredPatLit { value: LiteralValue, pattern_type: InferredType } + | InferredPatVariant { + name: BoundName + parent_enum: BoundName? + field_bindings: List + pattern_type: InferredType + } + | InferredPatWildcard { pattern_type: InferredType } + +type InferredFieldBinding { + field: BoundName + pattern: InferredPattern +} + +type InferredParam { + name: BoundName + type_expr: InferredType + default_expr: InferredExpr? + cardinality: ParamCardinality +} + +type InferredArg { + name: BoundName? + value: InferredExpr +} + +type InferredFieldInit { + name: BoundName + value: InferredExpr +} + +type InferredMatchArm { + pattern: InferredPattern + guard: InferredExpr? + body: InferredExpr +} + +type InferredExpr + = InferredLit { value: LiteralValue, span: SourceSpan, expr_type: InferredType } + | InferredError { kind: ExprErrorKind, message: String, span: SourceSpan } + | InferredVar { name: BoundName, expr_type: InferredType } + | InferredFieldAccess { + receiver: InferredExpr + field: BoundName + expr_type: InferredType + } + | InferredCall { + callee: BoundName + args: List + expr_type: InferredType + } + | InferredMethodCall { + receiver: InferredExpr + method: BoundName + args: List + expr_type: InferredType + } + | InferredMatch { + scrutinee: InferredExpr + arms: List + expr_type: InferredType + } + | InferredIf { + condition: InferredExpr + then_expr: InferredExpr + else_expr: InferredExpr + expr_type: InferredType + } + | InferredLet { + name: BoundName + value: InferredExpr + body: InferredExpr + expr_type: InferredType + } + | InferredRecordLit { + type_name: BoundName? + fields: List + expr_type: InferredType + } + | InferredListLit { + elements: List + expr_type: InferredType + } + | InferredBinOp { + op: BinOp + left: InferredExpr + right: InferredExpr + algebra_field: AlgebraFieldKind? + expr_type: InferredType + } + | InferredUnaryOp { + op: UnaryOpKind + operand: InferredExpr + expr_type: InferredType + } + | InferredLambda { + params: List + body: InferredExpr + expr_type: InferredType + } + | InferredStringInterp { + parts: List + expr_type: InferredType + } + | InferredBlock { + statements: List + expr_type: InferredType + } + | InferredCast { + expr: InferredExpr + target_type: InferredType + expr_type: InferredType + } + | InferredForEach { + variable: BoundName + iterable: InferredExpr + body: InferredExpr + expr_type: InferredType + } + | InferredIndex { + base: InferredExpr + index: InferredExpr + expr_type: InferredType + } + | InferredSlice { + base: InferredExpr + start: InferredExpr? + end: InferredExpr? + expr_type: InferredType + } + | InferredReturn { + value: InferredExpr? + expr_type: InferredType + } + +type InferredStringPart + = InferredStrText { value: String } + | InferredStrInterp { expr: InferredExpr } + +type InferredBlock { + statements: List + span: SourceSpan + block_type: InferredType +} + +type InferredTransport + = InferredTransportRest { properties: List } + | InferredTransportShell { properties: List } + | InferredTransportFile { properties: List } + | InferredTransportLocal { properties: List } + +type InferredTransportProperty { + key: BoundName + value: InferredExpr +} + +type InferredOperation { + name: BoundName + params: List + outputs: List + modifiers: List + body: InferredBlock? +} + +type InferredResourceUse { + name: BoundName + resource_type: InferredType +} + +type InferredImport + = InferredImportAll { module_path: Symbol, span: SourceSpan } + | InferredImportNames { + module_path: Symbol + names: List + span: SourceSpan + } + +type InferredItem + = InferredFn { + name: BoundName + type_params: List + params: List + return_type: InferredType + uses: List + body: InferredBlock + recursion: TailRecursionFacts + span: SourceSpan + } + | InferredFunc { + name: BoundName + type_params: List + params: List + return_type: InferredType + uses: List + body: InferredBlock + recursion: TailRecursionFacts + span: SourceSpan + } + | InferredTypeDecl { + name: BoundName + type_params: List + definition: InferredType + span: SourceSpan + } + | InferredDataDecl { + name: BoundName + type_annotation: InferredType + value: InferredExpr + span: SourceSpan + } + | InferredService { + name: BoundName + transport: InferredTransport + operations: List + span: SourceSpan + } + | InferredOtherItem { + keyword: String + raw_span: SourceSpan + } + +type InferredModule { + name: BoundName + imports: List + items: List + span: SourceSpan +} + +// ========================================================================= +// Pipeline stage ports — distinct types enforce phase ordering +// ========================================================================= + +type ParseStageIn { + tokens: TokenStream +} + +type ParseStageOut { + module: ParseModule +} + +type ResolveStageIn { + module: ParseModule +} + +type ResolveStageOut { + module: ResolvedModule +} + +type NormalizeStageIn { + module: ResolvedModule +} + +type NormalizeStageOut { + module: NormalizedModule +} + +type InferStageIn { + module: NormalizedModule +} + +type InferStageOut { + module: InferredModule +} + +type EmitStageIn { + module: InferredModule +} + +type TargetArtifact { + path: String + content: String +} + +type TargetSource { + artifacts: List +} + +type EmitStageOut { + output: TargetSource +} + +// ========================================================================= +// Normalize seam — substrate projection (reconcile calm-crane-724 + node.dag) +// Uses Connective / Behavior / EdgeLabel from v2_5.std.node. Targets are seam +// nodes (not Node) until full AST lowering lands. +// ========================================================================= + +type SeamResolvedEdge { + label: EdgeLabel + target: SeamResolvedNode +} + +type SeamNormalizedEdge { + label: EdgeLabel + target: SeamNormalizedNode +} + +type ResolvedTypeForm + = ResolvedSugarForm { + kind: SurfaceSugarKind + span: SourceSpan + children: List + } + | ResolvedCoreForm { + connective: Connective + children: List + } + +type NormalizedTypeForm { + connective: Connective + children: List +} + +type ResolvedComputationForm { + behavior: Behavior + span: SourceSpan + children: List +} + +type NormalizedComputationForm { + behavior: Behavior + span: SourceSpan + children: List +} + +type SeamResolvedItem { + name: Symbol + form: SeamResolvedItemForm +} + +type SeamResolvedItemForm + = SeamItemType { type_form: ResolvedTypeForm } + | SeamItemComputation { computation_form: ResolvedComputationForm } + +type SeamNormalizedItem { + name: Symbol + form: SeamNormalizedItemForm +} + +type SeamNormalizedItemForm + = SeamItemType { type_form: NormalizedTypeForm } + | SeamItemComputation { computation_form: NormalizedComputationForm } + +type SeamResolvedModule { + name: Symbol + items: List +} + +type SeamNormalizedModule { + name: Symbol + items: List +} + +type SeamResolvedNode + = SeamResolvedModuleNode { module: SeamResolvedModule } + | SeamResolvedItemNode { item: SeamResolvedItem } + +type SeamNormalizedNode + = SeamNormalizedModuleNode { module: SeamNormalizedModule } + | SeamNormalizedItemNode { item: SeamNormalizedItem } + +// ========================================================================= +// v2 field → v2.5 variant mapping (reference for stage workers) +// ========================================================================= +// +// v2 Node.expr_data (22 cases) → ParseExpr / ResolvedExpr / ... (one variant each) +// v2 Node.match_pattern → ParseMatchArm.pattern (not a field on expr nodes) +// v2 Node.params/body/transport/uses → ParseFn | ParseFunc | ParseService variants +// v2 Node.inferred? → eliminated; InferredExpr.expr_type is required per variant +// v2 is_self_recursive / has_non_tail_self_call → InferredFn.recursion only +// v2 item_kind() cascade → ParseItem closed sum (ParseFn | ParseFunc | ...) +// v2 connective on flat Node → ParseTypeExpr | TypeForm (phase AST; lower to Connective+Edge) +// calm-crane-724 SeamResolvedNode → normalize sugar strip → SeamNormalizedNode +// full pipeline: ResolvedSugared / ResolvedCore → NormalizedItem (core only) +// node.dag (PR #3422): NodeKind = TypeForm | Computation; Node { kind, children: List } diff --git a/src/v2.5/std/syntax.dag b/src/v2.5/std/syntax.dag new file mode 100644 index 00000000000..4f032f779d8 --- /dev/null +++ b/src/v2.5/std/syntax.dag @@ -0,0 +1,29 @@ +// v2.5 syntax carriers — closed sums for operators and literals. +// Authority for expression/type surface metadata used by stage_types. +// Does not import v2, v3, v4, or dsl. + +module v2_5.std.syntax + +type BinOp + = Add | Sub | Mul | Div | Mod + | Eq | Ne | Lt | Gt | Le | Ge + | And | Or | NullCoalesce + +type UnaryOpKind + = Not | Neg + +type LiteralValue + = LitStr { value: String } + | LitInt { value: Int } + | LitFloat { value: String } + | LitBool { value: Bool } + | LitNull + +type OperationModifier + = Idempotent | Readonly | Hermetic + +type ExprErrorKind + = ParseRecoveryError | SemanticExprError | InternalExprError + +type AlgebraFieldKind + = AlgAdd | AlgMul | AlgReciprocal | AlgQuotient | AlgRemainder | AlgCompare | AlgMeet | AlgJoin diff --git a/src/v2.5/std/token.dag b/src/v2.5/std/token.dag new file mode 100644 index 00000000000..b5220dbab1d --- /dev/null +++ b/src/v2.5/std/token.dag @@ -0,0 +1,31 @@ +// v2.5 token contract — interim until 01_tokenize.dag lands. +// nimble-swift-454 owns tokenizer implementation; this file owns the type. + +module v2_5.std.token + +import v2_5.std.identity { SourceSpan } + +type TokenShape + = ShKeyword + | ShLBrace | ShRBrace | ShLParen | ShRParen | ShLBracket | ShRBracket + | ShLt | ShGt | ShLe | ShGe | ShFatArrow | ShArrow + | ShColon | ShComma | ShDot | ShDotDot + | ShEq | ShEqEq | ShNe + | ShPlus | ShMinus | ShStar | ShSlash | ShPercent + | ShBang | ShAnd | ShOr + | ShQuestion | ShNullCoalesce + | ShPipe | ShPipeArrow + | ShLitStr | ShLitInt | ShLitFloat | ShIdent + | ShStrBegin | ShStrMid | ShStrEnd + | ShNewline | ShEof + | ShUnknown + +type Token { + text: String + span: SourceSpan + shape: TokenShape +} + +type TokenStream { + tokens: List +}