feat(pbs): add concrete generic structs and free functions
This commit is contained in:
@@ -189,3 +189,10 @@ Array syntax uses `array<T>` with compositional nesting. Explicit `new array<T>(
|
||||
Contract declarations and barrel items preserve ordered type-parameter names and individual spans. Applied type references preserve ordered child arguments and spans. Implements and as carry a complete target type reference. Semantic imported bindings retain the original declaration and importing lexical scope rather than inventing nominal origins. Existing visitors must traverse type arguments as well as inner/group/Fn/tuple children.
|
||||
|
||||
See [PBS generic contracts](../../../compiler/pbs/specs/generic-contracts.md).
|
||||
|
||||
|
||||
## Concrete generic structs and free functions
|
||||
|
||||
Structs and free functions preserve ordered parameter declarations and spans. Explicit applied function references preserve type arguments and their source span. Implements preserves its binder, full applied owner and target. Substitution rewrites every field, signature, annotation and executable body/capture position with a declaration-local environment. Concrete application provenance retains original declaration, canonical logical arguments and requesting use; it is not an executable runtime template.
|
||||
|
||||
See [Concrete generic structs and free functions](../../../compiler/pbs/specs/generic-structs-and-free-functions.md).
|
||||
|
||||
@@ -313,3 +313,10 @@ Array syntax uses `array<T>` with compositional nesting. Explicit `new array<T>(
|
||||
Parameterized contract diagnostics distinguish exact arity (E_SEM_CONTRACT_ARITY), undeclared/duplicate parameters (E_SEM_CONTRACT_PARAMETER), invalid applications (E_SEM_CONTRACT_ARGUMENT), incompatible or incomplete implementations (E_SEM_CONTRACT_SIGNATURE), duplicate pairs (E_SEM_CONTRACT_DUPLICATE_IMPLEMENTATION), invalid owners/modules (E_SEM_CONTRACT_OWNER / E_SEM_CONTRACT_OWNER_MODULE), invalid coercions (E_SEM_CONTRACT_COERCION), and bounded expansion/resource exhaustion (E_SEM_CONTRACT_EXPANSION). Barrel parameter disagreement uses E_LINK_CONTRACT_PARAMETERS. Existing invalid Array/Fn/optional/Self diagnostics also apply after substitution.
|
||||
|
||||
See [PBS generic contracts](../../../compiler/pbs/specs/generic-contracts.md).
|
||||
|
||||
|
||||
## Concrete generic structs and free functions
|
||||
|
||||
Generic diagnostics distinguish duplicate/unbound parameters, exact arity, raw or improperly inferred application, unjustified symbolic capabilities, invalid substituted positions, constructor errors, collapsed overloads, invalid bound owners, overlap and bounded expansion. Preserve declaration and requesting-use locations with a short instantiation chain. Editor projections retain symbolic parameter, concrete argument and generic origin identities. Generated instance names and host stacks do not replace source explanations.
|
||||
|
||||
See [Concrete generic structs and free functions](../../../compiler/pbs/specs/generic-structs-and-free-functions.md).
|
||||
|
||||
@@ -255,3 +255,10 @@ Array syntax uses `array<T>` with compositional nesting. Explicit `new array<T>(
|
||||
The frontend substitutes each closed application and emits a concrete nominal Trait descriptor shared by equivalent uses. Distinct logical applications remain distinct despite shared physical carriers. Concrete implementation functions take the receiver first. CALL_TRAIT evaluates and roots the receiver before arguments, evaluates arguments left to right, then places the complete receiver/ImplementationId view after the argument groups as required by the runtime ABI. Preserve exact signatures, absence, ImplementationId zero, ownership, GC and quotas; generic calls do not add a Dynamic ABI or adaptation wrapper.
|
||||
|
||||
See [PBS generic contracts](../../../compiler/pbs/specs/generic-contracts.md).
|
||||
|
||||
|
||||
## Concrete generic structs and free functions
|
||||
|
||||
Instantiate structs, free functions and owner-bound implementations within PBS before publishing executable descriptors. Registry receives concrete fields, signatures, bodies, capture groups and targets. Specialized free-function references use existing empty-environment Closure values; Fn remains structural. Preserve receiver identity, implementation zero, singletons, rooting, GC, ownership, evaluation/fault order and quotas. No generic Dynamic/boxing ABI, opcode, descriptor category or runtime instantiation engine is introduced.
|
||||
|
||||
See [Concrete generic structs and free functions](../../../compiler/pbs/specs/generic-structs-and-free-functions.md).
|
||||
|
||||
@@ -165,8 +165,8 @@ BarrelItem ::= BarrelFnItem
|
||||
| BarrelConstItem
|
||||
BarrelVisibility ::= 'mod' | 'pub'
|
||||
|
||||
BarrelFnItem ::= BarrelVisibility 'fn' Identifier ParamList ReturnAnn? ';'
|
||||
BarrelStructItem ::= BarrelVisibility 'struct' Identifier ';'
|
||||
BarrelFnItem ::= BarrelVisibility 'fn' Identifier TypeParameters? ParamList ReturnAnn? ';'
|
||||
BarrelStructItem ::= BarrelVisibility 'struct' Identifier TypeParameters? ';'
|
||||
BarrelContractItem ::= BarrelVisibility 'contract' Identifier TypeParameters? ';'
|
||||
BarrelHostItem ::= BarrelVisibility 'host' Identifier ';'
|
||||
BarrelErrorItem ::= BarrelVisibility 'error' Identifier ';'
|
||||
@@ -280,7 +280,7 @@ Top-level `let` forms and top-level executable statements are forbidden.
|
||||
|
||||
```ebnf
|
||||
TypeDecl ::= StructDecl | ServiceDecl | ContractDecl | HostDecl | BuiltinTypeDecl | ErrorDecl | EnumDecl
|
||||
StructDecl ::= 'declare' 'struct' Identifier '(' StructFieldList? ')' (StructMethodBody | ';')
|
||||
StructDecl ::= 'declare' 'struct' Identifier TypeParameters? '(' StructFieldList? ')' (StructMethodBody | ';')
|
||||
ServiceDecl ::= 'declare' 'service' Identifier ServiceBody
|
||||
ContractDecl ::= 'declare' 'contract' Identifier TypeParameters? ContractBody
|
||||
TypeParameters ::= '<' Identifier (',' Identifier)* '>'
|
||||
@@ -390,7 +390,7 @@ Rules:
|
||||
### 7.4 Functions
|
||||
|
||||
```ebnf
|
||||
FunctionDecl ::= 'fn' Identifier ParamList ReturnAnn? Block
|
||||
FunctionDecl ::= 'fn' Identifier TypeParameters? ParamList ReturnAnn? Block
|
||||
ParamList ::= '(' (Param (',' Param)*)? ')'
|
||||
Param ::= Identifier ':' TypeRef
|
||||
ReturnAnn ::= '->' ReturnSpec
|
||||
@@ -467,7 +467,7 @@ Rules:
|
||||
- Named tuple arity is 1..6 in v1 core syntax.
|
||||
- Tuple types in PBS core are always named.
|
||||
- Single-slot tuple types are allowed only in type/signature surface, not as tuple literals.
|
||||
- User-defined parameterized declarations are supported for contracts. General generic structs and functions remain outside PBS core v1.
|
||||
- User-defined parameterized declarations are supported for contracts. Generic structs and explicit generic free functions follow the concrete generic application extension linked below.
|
||||
- `SimpleType` may denote either a visible nominal type identifier or one of the predeclared builtin simple types.
|
||||
- The predeclared builtin simple types in v1 core are `int`, `float`, `bool`, and `str`.
|
||||
- Builtin simple types are always available in type position and do not require import.
|
||||
@@ -574,10 +574,10 @@ ArgList ::= Expr (',' Expr)*
|
||||
|
||||
Literal ::= IntLit | FloatLit | StringLit | BoolLit
|
||||
BoolLit ::= 'true' | 'false'
|
||||
PrimaryExpr ::= Literal | Identifier | ThisExpr | NewExpr | LambdaExpr | SomeExpr | NoneExpr | OkExpr | ErrExpr | UnitExpr | TupleExpr | GroupExpr | Block
|
||||
PrimaryExpr ::= Literal | Identifier TypeArguments? | ThisExpr | NewExpr | LambdaExpr | SomeExpr | NoneExpr | OkExpr | ErrExpr | UnitExpr | TupleExpr | GroupExpr | Block
|
||||
ThisExpr ::= 'this'
|
||||
NewExpr ::= 'new' NewTarget '(' ArgList? ')'
|
||||
NewTarget ::= Identifier ('.' Identifier)?
|
||||
NewTarget ::= Identifier (TypeArguments | '<' '>')? ('.' Identifier)?
|
||||
LambdaExpr ::= 'fn' '[' CaptureNames? ']' ParamList '->' TypeRef Block
|
||||
CaptureNames ::= Identifier (',' Identifier)*
|
||||
FnType ::= 'Fn' '(' (TypeRef (',' TypeRef)*)? ')' '->' TypeRef
|
||||
@@ -1211,3 +1211,10 @@ Array syntax uses `array<T>` with compositional nesting. Explicit `new array<T>(
|
||||
Parameterized contracts use explicit angular arguments in annotations, nested types, implements and as. Barrels export the ordered parameter list. Raw generic uses, empty argument lists and default arguments are invalid; existing contextual closers and Array construction sugars remain unchanged.
|
||||
|
||||
See [PBS generic contracts](../../../compiler/pbs/specs/generic-contracts.md).
|
||||
|
||||
|
||||
## Concrete generic structs and free functions
|
||||
|
||||
Struct and module-level free-function declarations and their barrel items accept ordered type parameters. Explicit function applications are reference expressions; calls use existing parentheses/apply. Generic construction supports explicit arguments and contextual diamond/omission. Owner-bound `implements` accepts its own parameter binder and a full applied owner. Independent method parameters, function diamond/inference and polymorphic Fn remain invalid. The owner specification defines exact arity, comparison disambiguation and recovery.
|
||||
|
||||
See [Concrete generic structs and free functions](../../../compiler/pbs/specs/generic-structs-and-free-functions.md).
|
||||
|
||||
@@ -830,3 +830,10 @@ Array syntax uses `array<T>` with compositional nesting. Explicit `new array<T>(
|
||||
Application identity combines the defining nominal declaration with ordered canonical logical arguments after alias resolution. Applications are invariant. Substitution preserves existing type-position restrictions, names, labels and complete groups across Array, Fn, optional, tuples and nested contracts. A struct/service may implement several applications, with complete unique implementations in its owner module. Finite instance recursion is accepted within resource limits; unbounded expansion receives a bounded diagnostic.
|
||||
|
||||
See [PBS generic contracts](../../../compiler/pbs/specs/generic-contracts.md).
|
||||
|
||||
|
||||
## Concrete generic structs and free functions
|
||||
|
||||
Templates are checked symbolically in definition scope. Required concrete owners validate all methods and constructors, including unused methods. Substitute complete bodies and applied Self; preserve position restrictions, invariant nominal/phantom identity and logical groups. Explicit function applications filter generic overloads by type arity; ordinary calls never infer them. Bound owner implementations require complete exact signatures and symbolic overlap rejection before use. Finite recursive applications are anchored; expanding type/body families are bounded errors.
|
||||
|
||||
See [Concrete generic structs and free functions](../../../compiler/pbs/specs/generic-structs-and-free-functions.md).
|
||||
|
||||
+7
@@ -563,3 +563,10 @@ new coverage; existing behavior MUST NOT regress.
|
||||
A barrel exports a parameterized contract declaration with the same ordered parameters as its source declaration. Imported bindings retain the original declaration and lexical source scope, including aliases in signatures of dependencies. A local alias never creates another nominal type. Implementations remain in the declaring module of the concrete struct/service owner.
|
||||
|
||||
See [PBS generic contracts](../../../compiler/pbs/specs/generic-contracts.md).
|
||||
|
||||
|
||||
## Concrete generic structs and free functions
|
||||
|
||||
Generic struct/function barrels export declarations and ordered parameters, including complete function signatures, rather than enumerated specializations. Imports and aliases preserve nominal origins and definition-scoped bodies/private helpers. Specializations are shared across equivalent uses and do not export private dependencies. SDK and program sources use the same language machinery.
|
||||
|
||||
See [Concrete generic structs and free functions](../../../compiler/pbs/specs/generic-structs-and-free-functions.md).
|
||||
|
||||
Reference in New Issue
Block a user