feat(pbs): add concrete generic structs and free functions
This commit is contained in:
@@ -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).
|
||||
|
||||
Reference in New Issue
Block a user