julia-script / julia-script/silk
type-system: Add tuple types and tuple expressions
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 48
- Forks
- 0
- Avg merge
- 4h 49m
- Merged PRs (30d)
- 213
Description
Context
Silk has exactly 12 type constructors: the builtin scalars, string, the bottom type,
nominal types, type parameters, failure projections, fixed arrays, slices, references,
callables, effects, and structural unions
(packages/compiler/src/Type.ts:179-191). None of them is a tuple. A function that must
return two values therefore needs a named struct, even when the pair has no meaning
outside the one call.
Current behavior
A user declares a struct for one use:
pub struct DivisionResult {
quotient: u32
remainder: u32
}
pub fn divide(value: u32, divisor: u32) -> DivisionResult {
return DivisionResult {
quotient: u32.divide(value, divisor),
remainder: u32.remainder(value, divisor)
}
}
The struct adds a public name, a declaration, and an import for every consumer. The names
quotient and remainder are useful, but the type name is not.
The syntax (u32, u32) does not parse as a type. The parser reads (T) as a
parenthesized type, so a single element in parentheses already has a meaning.
Requirements
- The type grammar must accept a tuple type with two or more element types.
- The expression grammar must accept a tuple expression with two or more elements.
- The parser must keep
(T)as a parenthesized type, not a one-element tuple. - The parser must keep
(expression)as a grouped expression. - The parser must accept a trailing comma in a tuple type and in a tuple expression.
- A tuple element must be reachable by an index, such as
pair.0. - A
matchpattern must accept a tuple pattern that binds each element. - Two tuple types must be the same type when every element type is the same.
- The layout must place the elements in declaration order, as a struct does.
- A tuple must follow the existing move, borrow, and drop rules of a struct.
- The empty tuple
()must keep its current meaning as the unit type.
Example
pub fn divide(value: u32, divisor: u32) -> (u32, u32) {
return (u32.divide(value, divisor), u32.remainder(value, divisor))
}
pub fn showRemainder(value: u32) -> u32 {
let result = divide(value, 10)
return result.1
}
Out of scope
- A one-element tuple. The syntax
(T)keeps its current meaning. - A named tuple field. A struct covers that case.
- A tuple with more than a fixed number of elements at runtime.
- A conversion between a tuple and a struct with the same element types.
- A generic function over the length of a tuple.
Dependencies
None.
Acceptance criteria
- The parser accepts
(u32, u32)as a type and keeps the syntax tree lossless. - The parser accepts
(a, b)as an expression. - A parser test shows that
(T)stays a parenthesized type. - A parser test shows that
(expression)stays a grouped expression. - A parser test shows that a trailing comma is accepted in both positions.
- A semantic test shows that
pair.0selects the first element with its exact type. - A semantic test shows that an index outside the length gets a diagnostic.
- A test shows that a tuple pattern in a
matchbinds every element. - A layout test shows the element offsets in declaration order.
-
openspec/specs/bootstrap-syntax/spec.mdgets a new type-grammar requirement.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with packages/compiler/src/Type.ts:179-191 and openspec/specs/bootstrap-syntax/spec.md, then trace the existing parser, struct semantics, matching, and layout handling. Add the parser, semantic, pattern, and layout tests listed in the acceptance criteria. Done means tuples support construction, indexing, matching, type equality, layout, and existing ownership rules without changing one-element or unit syntax.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100