Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2352,6 +2352,7 @@ if(BUILD_TESTING)
LABELS "typecheck;analysis;rc" TIMEOUT 120)
foreach(parity_fixture IN ITEMS scientific-literals scientific-literals-matrix
formatted-text formatted-text-matrix
tuple-arrays tuple-arrays-matrix
signed-numbers-matrix
integer-literal-widths integer-literal-widths-matrix
checked-text-spans checked-text-spans-matrix
Expand Down Expand Up @@ -2409,6 +2410,22 @@ if(BUILD_TESTING)
--llvm "${NIL_ENABLE_LLVM}")
set_tests_properties(nil.tuple-contract PROPERTIES
LABELS "ny;matrix;analysis;tuples;routes" TIMEOUT 180)
add_test(NAME nil.tuple-array-contract
COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/tools/tuple_array_contract.py"
--compiler $<TARGET_FILE:nilcompiler> --interpreter $<TARGET_FILE:nilinterpreter>
--stdlib "${CMAKE_CURRENT_SOURCE_DIR}/nilstd/src"
--llvm "${NIL_ENABLE_LLVM}")
set_tests_properties(nil.tuple-array-contract PROPERTIES
LABELS "ny;matrix;analysis;tuples;arrays;routes" TIMEOUT 240)
if(TARGET nilassembler AND TARGET nillinker)
add_test(NAME nil.tuple-array-nil-contract
COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/tools/tuple_array_nil_contract.py"
--interpreter $<TARGET_FILE:nilinterpreter> --assembler $<TARGET_FILE:nilassembler>
--linker $<TARGET_FILE:nillinker> --runtime $<TARGET_FILE:nilruntime>
--llvm "${NIL_ENABLE_LLVM}")
set_tests_properties(nil.tuple-array-nil-contract PROPERTIES
LABELS "nil;native;interpreter;arrays;tuples" TIMEOUT 120)
endif()
add_test(
NAME ny.scientific-literals-contract
COMMAND "${Python3_EXECUTABLE}"
Expand Down
18 changes: 11 additions & 7 deletions docs/advanced/nil-format.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,14 @@ can type-check but still fails if it reads before initialization.
## Native arrays and aggregate references

Native arrays are runtime descriptors with exact element kinds for `i32`,
`i64`, `bool`, `u8`, `f64`, and NUL-free `text`. `f64` values retain their bits;
text elements hold traced text pointers, not integer values. Function and
field boundaries preserve array element identity. An out-of-range read yields
the element's zero value (`0.0` or empty text for the added kinds); an
out-of-range write is a no-op. Nested array elements remain unsupported.
`i64`, `bool`, `u8`, `f64`, NUL-free `text`, and supported structural tuples.
`f64` values retain their bits; text and tuple elements hold traced pointers.
Tuple metadata preserves the exact ordered `@nil_tuple` schema, including
nominal type names. Function and field boundaries preserve array element
identity. Scalar out-of-range reads yield the element's zero value; tuple reads
fail on an invalid index or uninitialized element rather than fabricating a
default tuple. Out-of-range writes are no-ops. Arrays of records, enums and
nested arrays remain unsupported natively.

The public STL array primitives lower to
`INTEROP_CALL intrinsic operation arity result_type element_type`, where
Expand All @@ -260,7 +263,8 @@ is exact element metadata, not an FFI calling convention. Constructors return
Size and index arguments use the `i32` contract; constructors reject negative
sizes and raw NIL values outside that range instead of truncating or clamping.
The historical four-operand `array.length 1 i64` form remains readable.
Declared `f32` helpers and aggregate-element constructors reject explicitly.
Declared `f32` helpers and unsupported aggregate-element constructors reject
explicitly. Tuple constructors, getters and setters require matching schemas.

Nested struct fields hold nominally typed object handles, matching the VM's
reference semantics. `ref<Struct>` and aggregate-only `REF_LOCAL` preserve that
Expand All @@ -283,7 +287,7 @@ allocators themselves do not collect. Return values are spilled by the caller
before another safepoint can run. The same instrumentation is used by JIT,
native compilation and standalone assembly.

The runtime traces owned blocks and text-array elements, including reachable
The runtime traces owned blocks and text/tuple-array elements, including reachable
cycles and nested aggregate/enum payloads. It follows only known owned address
ranges, not arbitrary words as host pointers. Numeric words that resemble
addresses may conservatively retain an object. Static root slots are reused
Expand Down
47 changes: 42 additions & 5 deletions docs/design/NIL-0015-structural-tuples.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,33 @@ array unpacking retains its separate interpreter behavior. Static positional
access must be within the shape's arity. Numeric member tokenization keeps
`value.0.1` distinct from decimal literals.

## Tuple arrays

Native tuple arrays use a distinct managed element kind containing traced tuple
handles. Their exact `tuple<T1,T2,...>` metadata selects the annotated record
schema; names of nominal types inside the shape retain their case. Empty arrays
materialize the schema too. Construction, indexed replacement, append and the
generic array intrinsics validate the same element shape, including when source
type checking is disabled. A tuple handle cannot be substituted for a different
ordered shape. Fresh literals may apply checked element conversions at a
declared construction boundary; existing tuple values and arrays remain invariant.

The container is mutable while tuple slots remain immutable. Replacing an array
element leaves extracted tuple handles intact. Shared record/reference fields
retain identity through aliasing, copying, array growth and function returns.
Native tracing follows tuple handles and their transitive text/aggregate fields.

Ordinary and destructuring loops evaluate their array expression once. Literal,
named and function-returned arrays use indexed traversal of the selected array;
rebinding a source variable does not retarget the running loop. Bindings keep
their normal scope and control-flow behavior, including `break` and `continue`.

Tuple-array reads require a valid initialized element. Out-of-range reads fail
instead of manufacturing a tuple with default fields. Out-of-range writes remain
no-ops, and existing scalar-array bounds behavior is unchanged. This extension
does not enable native arrays with record, enum or array elements, nor arbitrary
pointer-valued array storage.

## Boundaries

- No empty tuple/unit value; existing Ny `()` remains the `void` type.
Expand All @@ -53,8 +80,8 @@ access must be within the shape's arity. Numeric member tokenization keeps
destructured with another declaration. Module/global destructuring is not
supported.
- Owned buffers and borrows cannot be tuple elements.
- Arrays of tuples execute only in the interpreter until native aggregate
arrays receive their own qualified layout contract.
- Tuple arrays require one exact supported schema. Native arrays of records,
enums and nested arrays remain outside this layout contract.
- Tuple patterns support bindings, wildcards, scalar literals and nested
tuples. This does not expand nested enum-payload patterns.
- A tuple inside a public signature has its canonical structural shape, but
Expand All @@ -68,6 +95,16 @@ reference identity, discarded positions and match forms through executable
text/binary NIL, bundles and LLVM routes. `tests/tools/tuple_contract.py` checks
invalid shapes, slot writes, huge/out-of-range positions and arity errors,
verifies cross-language consumers using source and binary libraries with the
original source files removed, and tests the interpreter/native tuple-array
boundary. Interpreter loop coverage includes named and literal arrays as well
as singleton tuples in both frontends.
original source files removed. Its tuple-array loop cases cover direct, named
and returned arrays, singleton tuples, discarded positions, evaluation order
and control flow in both frontends and execution modes.

`tests/language/tuple-arrays.ny`, `tests/language/tuple-arrays-matrix.matrix` and
`tests/tools/tuple_array_contract.py` cover indexing, whole-tuple replacement,
scalar/text/nested fields, shared record identities, growth and returned values,
concrete and generic enum fields, typed base/interior/one-past pointers,
generic standard-library primitives and overlapping checked copies. The contract
also exercises cross-language source/binary-library consumers, exact schema
rejection before output replacement, tuple bounds failures and remaining native
aggregate-array exclusions. Native runtime tests inspect transitive collection
and reclamation through tuple arrays.
4 changes: 2 additions & 2 deletions docs/getting-started/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ modules, `nilstd` with the matching Ny and Matrix sources, compiled HTML in `doc
hash-bearing `manifest.json`.

The complete command set is `nilcompiler`, `nilinterpreter`, `nilassembler`,
`nillinker`, `nillsp`, `nildebugger`, `nilschema`, `nilagent`, and `nilbuild` (with the host
`nillinker`, `nillsp`, `nildebugger`, `nilschema`, `nilagent`, `nilbuild`, and `aperture` (with the host
platform's executable suffix where needed). The helper validates this layout
and only replaces the active SDK after the entire standard library and smoke
path pass.
Expand Down Expand Up @@ -103,7 +103,7 @@ LLVM is optional. If CMake cannot find it, configure with
compiler, NIL interpreter, debugger, language server, assembler, and linker are
always built. `NIL_BUILD_EXPERIMENTAL_TOOLS=OFF` omits only `nilschema` and
`nilagent` in a direct developer build. The SDK helper keeps the option enabled
because the complete SDK includes all nine commands.
because the complete SDK includes all ten commands. Aperture is a separately versioned preview.

When tests are enabled, CMake requires Python rather than silently omitting the
route matrix and application contracts. Set `NIL_RUN_TESTS=OFF` with the helper,
Expand Down
3 changes: 2 additions & 1 deletion docs/language-reference/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ end fn

Supported native function boundaries currently include integer and boolean
words, `f64`, named/concrete generic enums, text, `array<i32/i64/u8/bool/f64/text>`,
`ptr<i32/i64/u8/bool>`, and validated concrete struct layouts. Generic struct
arrays of supported structural tuples, `ptr<i32/i64/u8/bool>`, and validated
concrete struct layouts. Generic struct
schemas are materialized for supported field layouts, including `f64`/`u8`
fields, nested struct handles and `ref<Struct>`. These references preserve shared object identity;
they are not scalar stack references or a borrow checker. Scalar references,
Expand Down
51 changes: 43 additions & 8 deletions docs/language-reference/tuples.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,54 @@ a mutable record field without replacing the tuple's slot. This follows the
existing record-handle contract, not C by-value aggregate layout.

Tuples can nest and participate in generic function signatures. Scalar, text,
and supported record/reference elements use the existing native field layouts.
and supported record/reference, enum and typed-pointer elements use the existing
native field layouts.
Owned buffers and borrows cannot be hidden inside tuples. Record field,
pointer, and foreign-call restrictions still apply; tuples do not establish a
C-compatible ABI.

Tuple patterns support binding names, `_`, scalar literals and nested tuple
patterns in Ny `match` and Matrix `consider`. Guards execute after the pattern
has bound its names. Tuple-array loops can unpack elements in the interpreter;
arrays of tuple handles remain outside the native array contract and are
rejected by native compilation. Loop unpacking requires tuple elements with
matching arity; scalar arrays and numeric ranges cannot be unpacked. Existing
interpreter unpacking of homogeneous nested arrays remains available.
Declaration destructuring is local only.
has bound its names. Declaration destructuring is local only.

## Arrays of tuples

Tuple arrays work in interpreted and native code. Every element has the same
ordered tuple schema. The array is mutable: indexing, whole-element replacement,
`push`, and the shared `nil.std.collections` array primitives preserve that
schema. The tuple slots themselves remain immutable. Array aliases observe
replacement and growth, while a previously extracted tuple keeps its value.
Contained record and reference values keep their shared identities.

```ny
let points: array<(f64, f64)> = [(1.0, 2.0), (3.0, 4.0)]
points[0] = (-1.5, 2.5)
points.push((5.0, 6.0))
for (x, y) in points
println(x + y)
end for
```

Ny `for (x, y) in points` and Matrix `repeat for each (x, y) in points`
unpack tuples with matching arity. A loop evaluates its array expression once,
including a function call returning the array. Rebinding the source variable
inside the body does not change that selected array. Ordinary iteration binds
the entire tuple; `_` can discard individual positions. Scalar arrays and
numeric ranges cannot be unpacked into tuple bindings. Existing interpreter
unpacking of homogeneous nested arrays remains available.

An out-of-range tuple-array read is a runtime error, including reads through
`get<T>`. A tuple has no synthetic zero/default value. Out-of-range writes are
no-ops, and scalar arrays keep their existing zero-valued read behavior. Use
checked collection operations or validate bounds before reading. Native arrays
whose elements are records, enums or arrays remain unsupported; a supported
tuple may itself contain supported record/reference elements or nested tuples.
Declared enum fields retain their concrete type, including generic arguments.
Typed raw-pointer fields preserve the pointer value, including an interior or
one-past pointer; storing a pointer in a tuple does not transfer ownership or
permit dereferencing one-past storage. Release the original allocation explicitly
after its final use.

See [NIL-0015](../design/NIL-0015-structural-tuples.md) for the representation and
[tuple contract tests](../../tests/tools/tuple_contract.py) for route coverage.
the [tuple](../../tests/tools/tuple_contract.py) and
[tuple-array](../../tests/tools/tuple_array_contract.py) contracts for route coverage.
12 changes: 8 additions & 4 deletions docs/language-reference/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,16 @@ array, tuple, and native-call layouts have narrower contracts than a general
C-compatible ABI. Standard-library collections are separate APIs, not an
implied built-in map literal or interchangeable `vec<T>` syntax.

The evidenced native array elements are `i32`, `i64`, `u8`, `bool`, `f64`, and
NUL-free text. Typed out-of-range reads return the element's zero value;
out-of-range writes do nothing. `push` requires a compatible element and
Native array elements include `i32`, `i64`, `u8`, `bool`, `f64`, NUL-free text,
and supported structural tuples. Scalar out-of-range reads return the element's
zero value; tuple-array reads fail because a tuple has no default zero value.
Out-of-range writes do nothing. `push` requires a compatible element and
preserves aliases when the descriptor grows. Use an explicit cast before
pushing an integer into `array<f64>`; storage does not reinterpret its bits.
Nested arrays and raw `ptr<f64>`/`ptr<text>` remain outside this native subset.
Tuple arrays retain one exact ordered schema and permit whole-element
replacement while tuple slots stay immutable. See the [tuple reference](tuples.md).
Native arrays of records, enums and nested arrays, and raw
`ptr<f64>`/`ptr<text>`, remain outside this subset.

## Structs and generic enums

Expand Down
8 changes: 5 additions & 3 deletions docs/release/v1-profile.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,11 @@ parallel map, and sleep. The manuals define their precise limits:
Source `println` has exactly one argument on every route, including unchecked
frontend mode. Use `println("")` for a blank line.

The nine SDK commands are `nilcompiler`, `nilinterpreter`, `nilassembler`,
`nillinker`, `nildebugger`, `nillsp`, `nilbuild`, `nilschema`, and `nilagent`. The last two are
experimental utilities, not v1 language guarantees. The LSP has a deliberately
The ten SDK commands are `nilcompiler`, `nilinterpreter`, `nilassembler`,
`nillinker`, `nildebugger`, `nillsp`, `nilbuild`, `nilschema`, `nilagent`, and `aperture`.
`nilschema` and `nilagent` are experimental utilities, not v1 language guarantees.
Aperture is a separately versioned analysis/debugging preview; packaging it does
not extend the v1 language or debugger guarantees. The LSP has a deliberately
limited capability set. `nilbuild` supports the [local-project profile](../tools/projects.md),
with process execution qualified on Linux. `nypm` and `nilaix` are not part of this release.

Expand Down
17 changes: 11 additions & 6 deletions docs/standard-library/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,16 @@ end paragraph
The output is `1` then `3`; the array becomes `[1, 1, 2, 3]`. Ny calls the same
function as `try_copy_range(pixels, 0, pixels, 1, 3)`.

The supported test slice covers `i32`, `i64`, `u8`, `bool`, `f64`, and NUL-free
`text`. It does not expand native support for record arrays, nested arrays, or
other scalar layouts. Checked byte stores retain the existing `u8` conversion
The scalar test slice covers `i32`, `i64`, `u8`, `bool`, `f64`, and NUL-free
`text`. The [tuple-array contract](../../tests/tools/tuple_array_contract.py)
adds generic construction, indexed/intrinsic access and overlapping checked
copies with exact tuple schemas. Copies preserve tuple values and contained
reference identities. Native record, enum and nested-array element arrays
remain unsupported. Checked byte stores retain the existing `u8` conversion
rules; these APIs validate indices and ranges, not numeric conversions.
The older raw array accessors keep their existing zero/no-op bounds behavior.
Raw scalar array accessors retain their zero/no-op bounds behavior. Raw tuple
reads outside the array fail because no default tuple exists; use checked
operations or validate bounds before reading.

The related `copy_to` guards on `list`, `queue`, `stack`, `hash_set`, and
`dictionary` now check remaining destination space by subtraction. Invalid
Expand All @@ -229,8 +234,8 @@ write. This fixes the extreme-offset overflow identified by the independent
3D validation project. Its copied SDK remains a historical test subject.

Further array work remains: real vector reservation/resizing, strided buffer
views with ownership rules, and native aggregate arrays. None is implied by
these helpers.
views with ownership rules, and native record/enum/nested-array element layouts.
None is implied by these helpers.

## Stable index ordering

Expand Down
14 changes: 13 additions & 1 deletion docs/tools/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ A complete SDK has the following top-level shape:
```text
nilcompiler nilinterpreter nilassembler nillinker
nillsp nildebugger nilschema nilagent
nilbuild
nilbuild aperture
nillib/ nilstd/ docs/ manifest.json
```

Expand All @@ -35,6 +35,18 @@ and regenerates imported bodies. Direct compiled-body linking is a later format
step, so `nillib` is a source-independent distribution today, not yet a
zero-recompilation module cache.

Earlier sealed `nil.sdk.v1` generations contain the original nine commands;
validation continues to accept that complete inventory. New SDK builds require
Aperture, include its digest in the manifest and build evidence, and check its
help/version identity. Aperture retains its own preview version.

## `aperture`

Aperture is the framework's analysis and debugging preview, with `explore`,
`memory`, `trace`, and `agent` commands. Run `aperture --help` for its command
interface. Its prototype capabilities are separate from the v1 language and
`nildebugger` contracts. See the [Aperture overview](../../aperture/README.md).

## `nilbuild`

The [project driver](projects.md) provides `describe`, `check`, `build` and
Expand Down
Loading
Loading