Skip to content

Migrate context accessors to std::ctx / std::prog, reserve Self, enable const generics on final fn#29553

Open
IGI-111 wants to merge 4 commits into
masterfrom
IGI-111/remove_self
Open

Migrate context accessors to std::ctx / std::prog, reserve Self, enable const generics on final fn#29553
IGI-111 wants to merge 4 commits into
masterfrom
IGI-111/remove_self

Conversation

@IGI-111

@IGI-111 IGI-111 commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

Removes the parser-level sugar for execution-context (self.caller, self.signer, self.address, self.id, self.checksum, self.edition, self.program_owner, block.height, block.timestamp, network.id) and for imported-program metadata (Program::checksum, Program::edition, Program::program_owner, Program::function_checksum) in favour of stdlib functions. A new crates/leo-std/src/leo/prog.leo module exposes the program-metadata intrinsics as final fn wrappers parameterised on const generic args (e.g.
std::prog::checksum::[credits.aleo]()).

Each removed form parses as a targeted compiler error pointing at the std::ctx::* or std::prog::* replacement.

Self is promoted to a real lexer keyword so it can be reserved for future use (impl blocks); it errors at every use site.

Three new annotations underpin this migration:

  • @offchain propagates an off-chain-only scope restriction from a wrapper to its callers (applied to std::ctx::caller and std::ctx::signer), restoring the access-scope check the parser used to enforce on self.caller / self.signer.
  • Compiler-internal @_caller_annotation lets the type checker recognise wrappers that ultimately return _self_caller, so the "caller-as-record-owner" warning fires through arbitrary wrapper chains.
  • Compiler-internal @_program_id_arg and @_callable_function_arg fire the program-ID-literal and entry/view-function checks at the user's call site, where the const generic argument is concrete.

Some other required changes and bugfixes:

  • std::ctx::id() is now a regular fn (off-chain accessor) rather than a final fn.
  • final fns may now declare const generic parameters; they are always inlined into their final {} callsite, so monomorphisation works the same as for regular fns.
  • identifier is now an allowed type for const generic parameters (used by std::prog::function_checksum).
  • Entry-point fns calling a final fn outside a final {} block are rejected at type-check time, replacing a stale snarkVM diagnostic at deploy time.
  • inject_std_library registers every other stub in import_stubs as a parent of std, so dependency programs see std::* as one of their imports.

Migration of in-repo Leo source (tests, examples, doc snippets) and documentation (operator reference, standard-library reference, upgradability and testing guides) is included. New tests cover the removed-syntax errors, Self reservation, std::prog usage, and the now-allowed final fn + const-generic patterns.

There is a companion PR updating the examples here: ProvableHQ/leo-examples#46

@IGI-111 IGI-111 requested a review from mohammadfawaz June 24, 2026 04:23
@codspeed-hq

codspeed-hq Bot commented Jun 24, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by ×2.9

⚡ 8 improved benchmarks
✅ 9 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
07_type_checking[contrived_settlement] 693.9 ms 75.3 ms ×9.2
frontend_single_file/control_flow_matrix 997.2 ms 380.3 ms ×2.6
dependency_chain[01_primitives] 1,023.1 ms 404.6 ms ×2.5
dependency_chain[02_registry] 1,026.8 ms 414.9 ms ×2.5
dependency_chain[03_policy] 1,039.3 ms 425.5 ms ×2.4
dependency_chain[04_router] 1,055.3 ms 439.9 ms ×2.4
frontend_with_deps/contrived_settlement 1,074.5 ms 456.6 ms ×2.4
dependency_chain[05_settlement] 1,073.1 ms 458.3 ms ×2.3

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing IGI-111/remove_self (30aec8a) with master (65b8b50)

Open in CodSpeed

@IGI-111 IGI-111 force-pushed the IGI-111/remove_self branch from 800c64a to 595294c Compare June 24, 2026 04:31
@IGI-111 IGI-111 changed the title Migrate context accessors to std::ctx / std::prog, reserve Self Migrate context accessors to std::ctx / std::prog, reserve Self, enable const generics on final fn Jun 24, 2026
@IGI-111 IGI-111 force-pushed the IGI-111/remove_self branch from 595294c to b7fff27 Compare June 24, 2026 07:53
Removes the parser-level sugar for execution-context (`self.caller`,
`self.signer`, `self.address`, `self.id`, `self.checksum`, `self.edition`,
`self.program_owner`, `block.height`, `block.timestamp`, `network.id`) and
for imported-program metadata (`Program::checksum`, `Program::edition`,
`Program::program_owner`, `Program::function_checksum`) in favour of
stdlib functions. A new `crates/leo-std/src/leo/prog.leo` module
exposes the program-metadata intrinsics as `final fn` wrappers
parameterised on const generic args (e.g.
`std::prog::checksum::[credits.aleo]()`).

Each removed form parses as a targeted compiler error pointing at
the `std::ctx::*` or `std::prog::*` replacement.

`Self` is promoted to a real lexer keyword so it can be reserved for
future use (`impl` blocks); it errors at every use site.

Three new annotations underpin this migration:

* `@offchain` propagates an off-chain-only scope restriction from
  a wrapper to its callers (applied to `std::ctx::caller` and
  `std::ctx::signer`), restoring the access-scope check the parser
  used to enforce on `self.caller` / `self.signer`.
* Compiler-internal `@_caller_annotation` lets the type checker
  recognise wrappers that ultimately return `_self_caller`, so the
  "caller-as-record-owner" warning fires through arbitrary
  wrapper chains.
* Compiler-internal `@_program_id_arg` and `@_callable_function_arg`
  fire the program-ID-literal and entry/view-function checks at
  the user's call site, where the const generic argument is
  concrete.

Some other required changes and bugfixes:

* `std::ctx::id()` is now a regular `fn` (off-chain accessor)
  rather than a `final fn`.
* `final fn`s may now declare const generic parameters; they are
  always inlined into their `final {}` callsite, so monomorphisation
  works the same as for regular `fn`s.
* `identifier` is now an allowed type for const generic parameters
  (used by `std::prog::function_checksum`).
* Entry-point fns calling a `final fn` outside a `final {}` block
  are rejected at type-check time, replacing a stale snarkVM
  diagnostic at deploy time.
* `inject_std_library` registers every other stub in `import_stubs`
  as a parent of `std`, so dependency programs see `std::*` as one
  of their imports.

Migration of in-repo Leo source (tests, examples, doc snippets) and
documentation (operator reference, standard-library reference,
upgradability and testing guides) is included. New tests cover the
removed-syntax errors, `Self` reservation, `std::prog` usage, and
the now-allowed `final fn` + const-generic patterns.
@IGI-111 IGI-111 force-pushed the IGI-111/remove_self branch from b7fff27 to 7633b60 Compare June 24, 2026 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant