Skip to content

Commit 940cd15

Browse files
authored
Merge pull request #32 from PyNumLab/new_semantics_pyi
update pyi for fortran
2 parents f6e904e + 3eae2e9 commit 940cd15

37 files changed

Lines changed: 6931 additions & 1736 deletions

README.md

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,10 @@ File: tests/data/fortran/general/modern_pyi_example.f90
430430
class particle:
431431
id: Int32
432432
mass: Float64
433-
position: Float64[Shape('3'), ORDER_F]
433+
position: Float64[3]
434434

435435
class vector3:
436-
values: Float64[Shape('3'), ORDER_F]
436+
values: Float64[3]
437437

438438
@private
439439
class hidden_state:
@@ -443,46 +443,47 @@ counter: Int32
443443

444444
hidden_scale: private[Float64]
445445

446-
@native_call([Return(0), Arg(0), Arg(1), Arg(2), Arg(3), Arg(4)])
447446
def init_particle(
448-
pid: Int32,
449-
mass: Float64,
450-
x: Float64,
451-
y: Float64,
452-
z: Float64
453-
) -> particle: ...
447+
p: Annotated[Ptr(particle), Intent('out')],
448+
pid: Ptr(Const(Int32)),
449+
mass: Ptr(Const(Float64)),
450+
x: Ptr(Const(Float64)),
451+
y: Ptr(Const(Float64)),
452+
z: Ptr(Const(Float64))
453+
) -> None: ...
454454

455455
def kinetic_energy(
456-
p: particle,
457-
vx: Float64,
458-
vy: Float64,
459-
vz: Float64
456+
p: Ptr(Const(particle)),
457+
vx: Ptr(Const(Float64)),
458+
vy: Ptr(Const(Float64)),
459+
vz: Ptr(Const(Float64))
460460
) -> Float64: ...
461461

462462
def scale_vector(
463-
v: Float64[Shape(':'), ORDER_F],
464-
alpha: Float64
465-
) -> Returns["v", Float64[Shape(':'), ORDER_F]]: ...
463+
v: Float64[::Strided],
464+
alpha: Ptr(Const(Float64))
465+
) -> None: ...
466466

467467
def dot3(
468-
a: Float64[Shape('3'), ORDER_F],
469-
b: Float64[Shape('3'), ORDER_F]
468+
a: Const(Float64[3]),
469+
b: Const(Float64[3])
470470
) -> Float64: ...
471471

472-
@native_call([Return(0)])
473-
def fill_identity3() -> Float64[Shape('3', '3'), ORDER_F]: ...
472+
def fill_identity3(
473+
a: Annotated[Float64[3, 3], ORDER_F, Intent('out')]
474+
) -> None: ...
474475

475476
def normalize_particle(
476-
p: particle
477-
) -> Returns["p", particle]: ...
477+
p: Ptr(particle)
478+
) -> None: ...
478479

479480
@private
480481
def hidden_proc(
481-
x: Int32
482+
x: Ptr(Const(Int32))
482483
) -> None: ...
483484
```
484485

485-
This snapshot is also verified in `tests/pyi/test_pyi_printer_modern_example.py`.
486+
This snapshot is also verified in `tests/semantics/test_pyi_printer_modern_example.py`.
486487

487488
Parse output for the same fixture now includes the derived type definition and field list:
488489

docs/architecture/semantic_multilanguage_wrapper_runtime_architecture.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,13 +327,13 @@ def solve(
327327
From(np.ndarray),
328328
ORDER_F,
329329
Writable,
330-
Shape("N", "N"),
330+
"N", "N",
331331
],
332332
b: Float64Vector[
333333
From(np.ndarray),
334-
Shape("N"),
334+
"N",
335335
],
336-
) -> Float64Vector[Shape("N")]: ...
336+
) -> Float64Vector["N"]: ...
337337
```
338338

339339
This means:
@@ -366,7 +366,7 @@ Examples:
366366
* `ORDER_F`
367367
* `ORDER_C`
368368
* `CPUResident`
369-
* `Shape(N, N)`
369+
* shape subscriptions such as `Float64["N", "N"]`
370370
* `Aligned(64)`
371371
* `Finite`
372372
* `NonNull`

docs/c_parser/c_parser_architecture.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,8 @@ Planned mapping:
683683
- C parameter -> `SemanticArgument`
684684
- C primitive -> `SemanticType`
685685
- C pointer -> constraints and ownership metadata
686-
- C array -> `Shape(...)`, `ORDER_C`, and pointer/extent metadata
686+
- C array -> subscription shape notation such as `T[n]`, order metadata such as
687+
`ORDER_C`, and pointer/extent metadata
687688
- `const` -> read-only ownership/constraint metadata
688689
- `restrict` -> aliasing metadata
689690
- structs/unions -> `SemanticClass` or named opaque semantic type
@@ -712,10 +713,11 @@ Likely stub patterns:
712713
- plain scalar functions:
713714
- `def f(x: Int32) -> Float64: ...`
714715
- pointer arguments:
715-
- use semantic constraints such as `Pointer`, `Writable`, `Const`, `Shape`
716-
only after the IR supports them cleanly
716+
- use storage/calling contracts such as `Ptr(...)`, `Const(...)`, writable
717+
metadata, and explicit extent metadata only after the IR supports them
718+
cleanly
717719
- arrays:
718-
- `Float64[Shape("n"), ORDER_C]`
720+
- `Annotated[Float64[n], ORDER_C]`
719721
- opaque handles:
720722
- classes or named semantic types with ownership constraints
721723
- structs:
@@ -727,9 +729,9 @@ Likely stub patterns:
727729
- `Final[...]`
728730

729731
The existing `.pyi` parser already supports `Final`, `private`, `native_call`,
730-
imports, classes, functions, shapes, and native projection entries. C-specific
731-
work should extend the semantic model intentionally before changing `.pyi`
732-
syntax.
732+
imports, classes, functions, shape subscriptions, storage contracts, metadata,
733+
and native projection entries. C-specific work should extend the semantic model
734+
intentionally before changing `.pyi` syntax.
733735

734736
For function pointers and callbacks, parser extraction and later wrappability
735737
are separate decisions. The parser should extract the function pointer type into

docs/semantics/c_pyi_self_contained_specification.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,16 @@ runnable C Phase 1 wrapper requires the corresponding native routine to
188188
accept that storage layout directly. For a rank-one array, `ORDER_C` and
189189
`ORDER_F` do not distinguish storage, contiguous or strided, so no order
190190
constraint is written.
191-
For a multidimensional strided annotation, `ORDER_F` is orientation metadata,
192-
not a requirement that NumPy report `F_CONTIGUOUS`; non-unit strides remain
193-
part of the contract.
191+
For a multidimensional strided annotation, `ORDER_F` is orientation metadata,
192+
not a requirement that NumPy report `F_CONTIGUOUS`; non-unit strides remain
193+
part of the contract.
194+
Source frontends may retain original declaration dimensions, source bounds
195+
or native dummy categories as internal provenance. Those source facts are
196+
not part of the canonical public array annotation unless they produce an
197+
actual storage constraint. In particular, Fortran dummy bounds are
198+
established by native association rather than supplied as Python array
199+
metadata. This does not add C semantic conversion support; C conversion
200+
remains deferred.
194201

195202
Stride-aware dimensions use a slice step marker:
196203

0 commit comments

Comments
 (0)