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
Open
Migrate context accessors to std::ctx / std::prog, reserve Self, enable const generics on final fn#29553IGI-111 wants to merge 4 commits into
std::ctx / std::prog, reserve Self, enable const generics on final fn#29553IGI-111 wants to merge 4 commits into
Conversation
Merging this PR will improve performance by ×2.9
Performance Changes
Tip Curious why this is faster? Comment Comparing |
800c64a to
595294c
Compare
std::ctx / std::prog, reserve Self, enable const generics on final fn
595294c to
b7fff27
Compare
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.
b7fff27 to
7633b60
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 newcrates/leo-std/src/leo/prog.leomodule exposes the program-metadata intrinsics asfinal fnwrappers 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::*orstd::prog::*replacement.Selfis promoted to a real lexer keyword so it can be reserved for future use (implblocks); it errors at every use site.Three new annotations underpin this migration:
@offchainpropagates an off-chain-only scope restriction from a wrapper to its callers (applied tostd::ctx::callerandstd::ctx::signer), restoring the access-scope check the parser used to enforce onself.caller/self.signer.@_caller_annotationlets the type checker recognise wrappers that ultimately return_self_caller, so the "caller-as-record-owner" warning fires through arbitrary wrapper chains.@_program_id_argand@_callable_function_argfire 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 regularfn(off-chain accessor) rather than afinal fn.final fns may now declare const generic parameters; they are always inlined into theirfinal {}callsite, so monomorphisation works the same as for regularfns.identifieris now an allowed type for const generic parameters (used bystd::prog::function_checksum).final fnoutside afinal {}block are rejected at type-check time, replacing a stale snarkVM diagnostic at deploy time.inject_std_libraryregisters every other stub inimport_stubsas a parent ofstd, so dependency programs seestd::*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,
Selfreservation,std::progusage, and the now-allowedfinal fn+ const-generic patterns.There is a companion PR updating the examples here: ProvableHQ/leo-examples#46