Skip to content

Commit 60322dd

Browse files
authored
Merge pull request #3257 from ProvableHQ/mohammadfawaz/rename_query_to_view
refactor: rename `query` to `view`
2 parents 1084555 + 08a95fd commit 60322dd

28 files changed

Lines changed: 510 additions & 510 deletions

File tree

.circleci/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -905,8 +905,8 @@ jobs:
905905
steps:
906906
- run_test:
907907
workspace_member: snarkvm-synthesizer
908-
# `history` enables the per-key historical update map that the `query` evaluation path
909-
# depends on; gating it here ensures the v15 query tests are exercised in CI.
908+
# `history` enables the per-key historical update map that the `view` evaluation path
909+
# depends on; gating it here ensures the v15 view tests are exercised in CI.
910910
flags: >
911911
--lib --bins --features test,history
912912
--partition count:1/2

console/network/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ pub trait Network:
226226
const MAX_RECORDS: usize = 10 * Self::MAX_FUNCTIONS;
227227
/// The maximum number of closures in a program.
228228
const MAX_CLOSURES: usize = 2 * Self::MAX_FUNCTIONS;
229-
/// The maximum number of query functions in a program.
230-
const MAX_QUERIES: usize = 2 * Self::MAX_FUNCTIONS;
229+
/// The maximum number of view functions in a program.
230+
const MAX_VIEWS: usize = 2 * Self::MAX_FUNCTIONS;
231231
/// The maximum number of operands in an instruction.
232232
const MAX_OPERANDS: usize = Self::MAX_INPUTS;
233233
/// The maximum number of instructions in a closure or function.

synthesizer/process/src/cost.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -259,16 +259,16 @@ pub fn deployment_cost_v2<N: Network>(
259259
);
260260
}
261261

262-
// Bound each query function's worst-case compute. Queries are off-consensus and have no
262+
// Bound each view function's worst-case compute. Views are off-consensus and have no
263263
// dedicated fee component beyond what is already counted in `storage_cost` (their bytes
264264
// contribute to `size_in_bytes`). The bound below is purely a deploy-time sanity check
265-
// to keep pathological queries from being accepted.
266-
for query in deployment.program().queries().values() {
267-
let query_cost = query_cost_for_single_query(&stack, query.name(), ConsensusFeeVersion::V3)?;
265+
// to keep pathological views from being accepted.
266+
for view in deployment.program().views().values() {
267+
let view_cost = view_cost_for_single_view(&stack, view.name(), ConsensusFeeVersion::V3)?;
268268
ensure!(
269-
query_cost <= N::TRANSACTION_SPEND_LIMIT[1].1,
270-
"Query '{}' has a cost '{query_cost}' which exceeds the transaction spend limit '{}'",
271-
query.name(),
269+
view_cost <= N::TRANSACTION_SPEND_LIMIT[1].1,
270+
"View '{}' has a cost '{view_cost}' which exceeds the transaction spend limit '{}'",
271+
view.name(),
272272
N::TRANSACTION_SPEND_LIMIT[1].1
273273
);
274274
}
@@ -1014,28 +1014,28 @@ fn finalize_cost_for_single_function_raw<N: Network>(
10141014
Ok(finalize_cost)
10151015
}
10161016

1017-
/// Returns the maximum compute cost (in microcredits) of a single query function's body.
1017+
/// Returns the maximum compute cost (in microcredits) of a single view function's body.
10181018
///
1019-
/// Queries do not run as part of consensus, so this cost is not paid by anyone — it is only
1019+
/// Views do not run as part of consensus, so this cost is not paid by anyone — it is only
10201020
/// used as a deploy-time sanity bound (mirrors the per-function `TRANSACTION_SPEND_LIMIT`
1021-
/// check) to prevent deploying queries whose worst-case compute is unreasonable.
1022-
fn query_cost_for_single_query<N: Network>(
1021+
/// check) to prevent deploying views whose worst-case compute is unreasonable.
1022+
fn view_cost_for_single_view<N: Network>(
10231023
stack: &Stack<N>,
1024-
query_name: &Identifier<N>,
1024+
view_name: &Identifier<N>,
10251025
consensus_fee_version: ConsensusFeeVersion,
10261026
) -> Result<u64> {
1027-
let query = stack.program().get_query_ref(query_name)?;
1027+
let view = stack.program().get_view_ref(view_name)?;
10281028

1029-
// Query types are not cached on the stack today; recompute them here for the cost walk.
1030-
let query_types = FinalizeTypes::from_query(stack, query)?;
1029+
// View types are not cached on the stack today; recompute them here for the cost walk.
1030+
let view_types = FinalizeTypes::from_view(stack, view)?;
10311031

1032-
let mut query_cost = 0u64;
1033-
for command in query.commands() {
1034-
query_cost = query_cost
1035-
.checked_add(cost_per_command(stack, &query_types, command, consensus_fee_version)?)
1036-
.ok_or(anyhow!("Query cost overflowed"))?;
1032+
let mut view_cost = 0u64;
1033+
for command in view.commands() {
1034+
view_cost = view_cost
1035+
.checked_add(cost_per_command(stack, &view_types, command, consensus_fee_version)?)
1036+
.ok_or(anyhow!("View cost overflowed"))?;
10371037
}
1038-
Ok(query_cost)
1038+
Ok(view_cost)
10391039
}
10401040

10411041
/// Returns the total finalize cost for an execution by iterating over all concrete transitions.

synthesizer/process/src/finalize.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -445,12 +445,12 @@ fn finalize_transition<N: Network, P: FinalizeStorage<N>>(
445445

446446
// Get the transition ID used to initialize the finalize registers.
447447
// If the block height is greater than or equal to `ConsensusVersion::V3`, then use the top-level transition ID.
448-
// Otherwise, query the call graph for the child transition ID corresponding to the future that is being awaited.
448+
// Otherwise, view the call graph for the child transition ID corresponding to the future that is being awaited.
449449
let consensus_version = N::CONSENSUS_VERSION(state.block_height())?;
450450
let transition_id = if (ConsensusVersion::V1..=ConsensusVersion::V2).contains(&consensus_version) {
451451
// Get the current transition ID. The finalize path always initializes
452-
// registers with `Some(transition_id)`; only the query path uses `None`,
453-
// and `await` is forbidden on the query path, so this is unreachable
452+
// registers with `Some(transition_id)`; only the view path uses `None`,
453+
// and `await` is forbidden on the view path, so this is unreachable
454454
// there. Treat `None` as a logic error.
455455
let transition_id = registers
456456
.transition_id()
@@ -596,7 +596,7 @@ fn initialize_finalize_state<N: Network>(
596596

597597
// A helper function to finalize all commands except `await`, updating the finalize operations and the counter.
598598
//
599-
// Generic over the store so the query evaluator (which passes either the canonical
599+
// Generic over the store so the view evaluator (which passes either the canonical
600600
// `FinalizeStore` or a read-only historic adapter) can reuse this dispatch.
601601
#[inline]
602602
pub(crate) fn finalize_command_except_await<N: Network>(

synthesizer/process/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ mod evaluate;
3737
mod execute;
3838
mod finalize;
3939
#[cfg(feature = "history")]
40-
mod query;
40+
mod view;
4141
#[cfg(feature = "history")]
42-
pub use query::evaluate_query_at_height;
42+
pub use view::evaluate_view_at_height;
4343
mod verify_deployment;
4444
mod verify_execution;
4545
mod verify_fee;

synthesizer/process/src/stack/finalize_registers/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub struct FinalizeRegisters<N: Network> {
3030
/// The global state for the finalize scope.
3131
state: FinalizeGlobalState,
3232
/// The transition ID for the finalize scope.
33-
/// `None` on the query path (queries have no associated transition); always `Some(...)`
33+
/// `None` on the view path (views have no associated transition); always `Some(...)`
3434
/// on the finalize / constructor paths.
3535
transition_id: Option<N::TransitionID>,
3636
/// The function name for the finalize scope.
@@ -41,7 +41,7 @@ pub struct FinalizeRegisters<N: Network> {
4141
/// The mapping of assigned registers to their values.
4242
registers: IndexMap<u64, Value<N>>,
4343
/// A nonce for finalize registers.
44-
/// `None` on the query path; always `Some(...)` on the finalize / constructor paths.
44+
/// `None` on the view path; always `Some(...)` on the finalize / constructor paths.
4545
nonce: Option<u64>,
4646
/// The tracker for the last register locator.
4747
last_register: Option<u64>,
@@ -51,7 +51,7 @@ impl<N: Network> FinalizeRegisters<N> {
5151
/// Initializes a new set of registers, given the finalize types.
5252
///
5353
/// `transition_id` and `nonce` are `Option`s so that callers can express "no transition is
54-
/// associated with this scope" (the query path) without needing a sentinel default value.
54+
/// associated with this scope" (the view path) without needing a sentinel default value.
5555
/// On the finalize / constructor paths, both are always `Some(...)` and the absence of a
5656
/// transition ID at any read site (e.g. `rand.chacha`) is treated as a runtime error.
5757
#[inline]

synthesizer/process/src/stack/finalize_types/initialize.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,35 +43,35 @@ impl<N: Network> FinalizeTypes<N> {
4343
Ok(finalize_types)
4444
}
4545

46-
/// Initializes a new instance of `FinalizeTypes` for the given query function.
47-
/// Checks that the given query is well-formed for the given stack.
46+
/// Initializes a new instance of `FinalizeTypes` for the given view function.
47+
/// Checks that the given view is well-formed for the given stack.
4848
///
49-
/// Queries share the finalize register/command shape, but cannot await futures and cannot
49+
/// Views share the finalize register/command shape, but cannot await futures and cannot
5050
/// produce side effects. The forbidden-command list (writes, async, await, call, rand.chacha)
51-
/// is enforced at `QueryCore` construction; this function only needs to type-check the body.
51+
/// is enforced at `ViewCore` construction; this function only needs to type-check the body.
5252
#[inline]
53-
pub(super) fn initialize_finalize_types_from_query(
53+
pub(super) fn initialize_finalize_types_from_view(
5454
stack: &Stack<N>,
55-
query: &snarkvm_synthesizer_program::QueryCore<N>,
55+
view: &snarkvm_synthesizer_program::ViewCore<N>,
5656
) -> Result<Self> {
5757
let mut finalize_types = Self { inputs: IndexMap::new(), destinations: IndexMap::new() };
5858

59-
// Type-check the inputs. Query inputs are guaranteed to be plaintext at construction time.
60-
for input in query.inputs() {
59+
// Type-check the inputs. View inputs are guaranteed to be plaintext at construction time.
60+
for input in view.inputs() {
6161
finalize_types.check_input(stack, input.register(), input.finalize_type())?;
6262
}
6363

6464
// Type-check the commands.
65-
for command in query.commands() {
66-
finalize_types.check_command(stack, query.positions(), command)?;
65+
for command in view.commands() {
66+
finalize_types.check_command(stack, view.positions(), command)?;
6767
}
6868

6969
// Type-check the outputs: each output operand must resolve and match the declared type.
70-
for output in query.outputs() {
70+
for output in view.outputs() {
7171
let actual = finalize_types.get_type_from_operand(stack, output.operand())?;
7272
if &actual != output.finalize_type() {
7373
bail!(
74-
"Query output type mismatch: declared '{}' but operand '{}' has type '{}'",
74+
"View output type mismatch: declared '{}' but operand '{}' has type '{}'",
7575
output.finalize_type(),
7676
output.operand(),
7777
actual,

synthesizer/process/src/stack/finalize_types/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ impl<N: Network> FinalizeTypes<N> {
8787
Self::initialize_finalize_types_from_finalize(stack, finalize)
8888
}
8989

90-
/// Initializes a new instance of `FinalizeTypes` for the given query function.
91-
/// Checks that the given query is well-formed for the given stack.
90+
/// Initializes a new instance of `FinalizeTypes` for the given view function.
91+
/// Checks that the given view is well-formed for the given stack.
9292
#[inline]
93-
pub fn from_query(stack: &Stack<N>, query: &snarkvm_synthesizer_program::QueryCore<N>) -> Result<Self> {
94-
Self::initialize_finalize_types_from_query(stack, query)
93+
pub fn from_view(stack: &Stack<N>, view: &snarkvm_synthesizer_program::ViewCore<N>) -> Result<Self> {
94+
Self::initialize_finalize_types_from_view(stack, view)
9595
}
9696

9797
/// Returns `true` if the given register exists.

synthesizer/process/src/stack/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -379,11 +379,11 @@ impl<N: Network> Stack<N> {
379379
}
380380
}
381381

382-
// Type-check every query function. The result is not cached on the stack here;
383-
// it is recomputed by the query evaluator. This is acceptable for the prototype
384-
// and ensures that ill-typed queries are rejected at deploy time.
385-
for query in self.program.queries().values() {
386-
let _ = FinalizeTypes::from_query(self, query)?;
382+
// Type-check every view function. The result is not cached on the stack here;
383+
// it is recomputed by the view evaluator. This is acceptable for the prototype
384+
// and ensures that ill-typed views are rejected at deploy time.
385+
for view in self.program.views().values() {
386+
let _ = FinalizeTypes::from_view(self, view)?;
387387
}
388388

389389
// Drop the locks since the types have been initialized.

0 commit comments

Comments
 (0)