Skip to content

Commit

Permalink
[cleanup] Remove BinaryIndexView (#17117)
Browse files Browse the repository at this point in the history
## Description 

- Removing unnecessary enum following `CompiledScript` removal #17113 

## Test plan 

- CI

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
  • Loading branch information
tnowacki authored Apr 11, 2024
1 parent af0bc22 commit 65a8ccf
Show file tree
Hide file tree
Showing 105 changed files with 1,118 additions and 1,580 deletions.
4 changes: 1 addition & 3 deletions crates/sui-graphql-rpc/src/types/move_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
use async_graphql::connection::{Connection, CursorType, Edge};
use async_graphql::*;
use move_binary_format::access::ModuleAccess;
use move_binary_format::binary_views::BinaryIndexedView;
use move_disassembler::disassembler::Disassembler;
use move_ir_types::location::Loc;

Expand Down Expand Up @@ -273,9 +272,8 @@ impl MoveModule {

/// Textual representation of the module's bytecode.
async fn disassembly(&self) -> Result<Option<String>> {
let view = BinaryIndexedView::Module(self.parsed.bytecode());
Ok(Some(
Disassembler::from_view(view, Loc::invalid())
Disassembler::from_view(self.parsed.bytecode(), Loc::invalid())
.map_err(|e| Error::Internal(format!("Error creating disassembler: {e}")))
.extend()?
.disassemble()
Expand Down
4 changes: 1 addition & 3 deletions crates/sui-json-rpc-types/src/sui_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use tabled::{

use fastcrypto::encoding::Base64;
use move_binary_format::access::ModuleAccess;
use move_binary_format::binary_views::BinaryIndexedView;
use move_binary_format::CompiledModule;
use move_bytecode_utils::module_cache::GetModule;
use move_core_types::annotated_value::MoveTypeLayout;
Expand Down Expand Up @@ -1774,7 +1773,6 @@ fn get_signature_types(
use std::borrow::Borrow;
if let Ok(Some(module)) = module_cache.get_module_by_id(&id) {
let module: &CompiledModule = module.borrow();
let view = BinaryIndexedView::Module(module);
let func = module
.function_handles
.iter()
Expand All @@ -1784,7 +1782,7 @@ fn get_signature_types(
.signature_at(func.parameters)
.0
.iter()
.map(|s| primitive_type(&view, &[], s).1)
.map(|s| primitive_type(module, &[], s).1)
.collect(),
)
} else {
Expand Down
20 changes: 10 additions & 10 deletions crates/sui-json/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use std::str::FromStr;

use anyhow::{anyhow, bail};
use fastcrypto::encoding::{Encoding, Hex};
use move_binary_format::CompiledModule;
use move_binary_format::{
access::ModuleAccess, binary_config::BinaryConfig, binary_views::BinaryIndexedView,
file_format::SignatureToken,
access::ModuleAccess, binary_config::BinaryConfig, file_format::SignatureToken,
};
use move_bytecode_utils::resolve_struct;
use move_core_types::account_address::AccountAddress;
Expand Down Expand Up @@ -552,7 +552,7 @@ fn check_valid_homogeneous_rec(curr_q: &mut VecDeque<&JsonValue>) -> Result<(),
/// can be signature tokens that represent primitives but that do not have corresponding
/// MoveTypeLayout (e.g., SignatureToken::StructInstantiation).
pub fn primitive_type(
view: &BinaryIndexedView,
view: &CompiledModule,
type_args: &[TypeTag],
param: &SignatureToken,
) -> (bool, Option<MoveTypeLayout>) {
Expand Down Expand Up @@ -708,7 +708,7 @@ fn resolve_object_vec_arg(idx: usize, arg: &SuiJsonValue) -> Result<Vec<ObjectID
}

fn resolve_call_arg(
view: &BinaryIndexedView,
view: &CompiledModule,
type_args: &[TypeTag],
idx: usize,
arg: &SuiJsonValue,
Expand Down Expand Up @@ -778,7 +778,7 @@ fn resolve_call_arg(
}
}

pub fn is_receiving_argument(view: &BinaryIndexedView, arg_type: &SignatureToken) -> bool {
pub fn is_receiving_argument(view: &CompiledModule, arg_type: &SignatureToken) -> bool {
use SignatureToken as ST;

// Progress down into references to determine if the underlying type is a receiving
Expand All @@ -795,7 +795,7 @@ pub fn is_receiving_argument(view: &BinaryIndexedView, arg_type: &SignatureToken
}

fn resolve_call_args(
view: &BinaryIndexedView,
view: &CompiledModule,
type_args: &[TypeTag],
json_args: &[SuiJsonValue],
parameter_types: &[SignatureToken],
Expand Down Expand Up @@ -836,11 +836,11 @@ pub fn resolve_move_function_args(
let function_signature = module.function_handle_at(fdef.function);
let parameters = &module.signature_at(function_signature.parameters).0;

let view = BinaryIndexedView::Module(&module);

// Lengths have to match, less one, due to TxContext
let expected_len = match parameters.last() {
Some(param) if TxContext::kind(&view, param) != TxContextKind::None => parameters.len() - 1,
Some(param) if TxContext::kind(&module, param) != TxContextKind::None => {
parameters.len() - 1
}
_ => parameters.len(),
};
if combined_args_json.len() != expected_len {
Expand All @@ -851,7 +851,7 @@ pub fn resolve_move_function_args(
);
}
// Check that the args are valid and convert to the correct format
let call_args = resolve_call_args(&view, type_args, &combined_args_json, parameters)?;
let call_args = resolve_call_args(&module, type_args, &combined_args_json, parameters)?;
let tupled_call_args = call_args
.into_iter()
.zip(parameters.iter())
Expand Down
5 changes: 2 additions & 3 deletions crates/sui-move/src/disassemble.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

use clap::Parser;
use move_binary_format::{binary_views::BinaryIndexedView, CompiledModule};
use move_binary_format::CompiledModule;
use move_cli::base;
use move_disassembler::disassembler::Disassembler;
use move_ir_types::location::Spanned;
Expand Down Expand Up @@ -65,8 +65,7 @@ impl Disassemble {
if self.debug {
println!("{module:#?}");
} else {
let view = BinaryIndexedView::Module(&module);
let d = Disassembler::from_view(view, Spanned::unsafe_no_loc(()).loc)?;
let d = Disassembler::from_view(&module, Spanned::unsafe_no_loc(()).loc)?;
println!("{}", d.disassemble()?);
}

Expand Down
9 changes: 4 additions & 5 deletions crates/sui-transaction-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use anyhow::{anyhow, bail, ensure, Ok};
use async_trait::async_trait;
use futures::future::join_all;
use move_binary_format::binary_config::BinaryConfig;
use move_binary_format::binary_views::BinaryIndexedView;
use move_binary_format::file_format::SignatureToken;
use move_binary_format::CompiledModule;
use move_core_types::identifier::Identifier;
use move_core_types::language_storage::{StructTag, TypeTag};

Expand Down Expand Up @@ -332,7 +332,7 @@ impl TransactionBuilder {
id: ObjectID,
objects: &mut BTreeMap<ObjectID, Object>,
is_mutable_ref: bool,
view: &BinaryIndexedView<'_>,
view: &CompiledModule,
arg_type: &SignatureToken,
) -> Result<ObjectArg, anyhow::Error> {
let response = self
Expand Down Expand Up @@ -401,7 +401,6 @@ impl TransactionBuilder {
let mut args = Vec::new();
let mut objects = BTreeMap::new();
let module = package.deserialize_module(module, &BinaryConfig::standard())?;
let view = BinaryIndexedView::Module(&module);
for (arg, expected_type) in json_args_and_tokens {
args.push(match arg {
ResolvedCallArg::Pure(p) => builder.input(CallArg::Pure(p)),
Expand All @@ -413,7 +412,7 @@ impl TransactionBuilder {
// Is mutable if passed by mutable reference or by value
matches!(expected_type, SignatureToken::MutableReference(_))
|| !expected_type.is_reference(),
&view,
&module,
&expected_type,
)
.await?,
Expand All @@ -427,7 +426,7 @@ impl TransactionBuilder {
id,
&mut objects,
/* is_mutable_ref */ false,
&view,
&module,
&expected_type,
)
.await?,
Expand Down
4 changes: 2 additions & 2 deletions crates/sui-types/src/base_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ use fastcrypto::encoding::{Encoding, Hex};
use fastcrypto::hash::HashFunction;
use fastcrypto::traits::AllowedRng;
use fastcrypto_zkp::bn254::zk_login::ZkLoginInputs;
use move_binary_format::binary_views::BinaryIndexedView;
use move_binary_format::file_format::SignatureToken;
use move_binary_format::CompiledModule;
use move_bytecode_utils::resolve_struct;
use move_core_types::account_address::AccountAddress;
use move_core_types::ident_str;
Expand Down Expand Up @@ -915,7 +915,7 @@ impl TxContext {
}

/// Returns whether the type signature is &mut TxContext, &TxContext, or none of the above.
pub fn kind(view: &BinaryIndexedView<'_>, s: &SignatureToken) -> TxContextKind {
pub fn kind(view: &CompiledModule, s: &SignatureToken) -> TxContextKind {
use SignatureToken as S;
let (kind, s) = match s {
S::MutableReference(s) => (TxContextKind::Mutable, s),
Expand Down
4 changes: 2 additions & 2 deletions crates/sui-types/src/clock.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use move_binary_format::{binary_views::BinaryIndexedView, file_format::SignatureToken};
use move_binary_format::{file_format::SignatureToken, CompiledModule};
use move_bytecode_utils::resolve_struct;
use move_core_types::{
account_address::AccountAddress, ident_str, identifier::IdentStr, language_storage::StructTag,
Expand Down Expand Up @@ -38,7 +38,7 @@ impl Clock {
}

/// Detects a `&mut sui::clock::Clock` or `sui::clock::Clock` in the signature.
pub fn is_mutable(view: &BinaryIndexedView<'_>, s: &SignatureToken) -> bool {
pub fn is_mutable(view: &CompiledModule, s: &SignatureToken) -> bool {
use SignatureToken as S;
match s {
S::MutableReference(inner) => Self::is_mutable(view, inner),
Expand Down
11 changes: 6 additions & 5 deletions crates/sui-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
)]

use base_types::{SequenceNumber, SuiAddress};
use move_binary_format::binary_views::BinaryIndexedView;
use move_binary_format::access::ModuleAccess;
use move_binary_format::file_format::{AbilitySet, SignatureToken};
use move_binary_format::CompiledModule;
use move_bytecode_utils::resolve_struct;
use move_core_types::language_storage::ModuleId;
use move_core_types::{account_address::AccountAddress, language_storage::StructTag};
Expand Down Expand Up @@ -273,7 +274,7 @@ impl<T: MoveTypeTagTrait> MoveTypeTagTrait for Vec<T> {
}

pub fn is_primitive(
view: &BinaryIndexedView<'_>,
view: &CompiledModule,
function_type_args: &[AbilitySet],
s: &SignatureToken,
) -> bool {
Expand Down Expand Up @@ -302,7 +303,7 @@ pub fn is_primitive(
}

pub fn is_object(
view: &BinaryIndexedView<'_>,
view: &CompiledModule,
function_type_args: &[AbilitySet],
t: &SignatureToken,
) -> Result<bool, String> {
Expand All @@ -316,7 +317,7 @@ pub fn is_object(
}

pub fn is_object_vector(
view: &BinaryIndexedView<'_>,
view: &CompiledModule,
function_type_args: &[AbilitySet],
t: &SignatureToken,
) -> Result<bool, String> {
Expand All @@ -328,7 +329,7 @@ pub fn is_object_vector(
}

fn is_object_struct(
view: &BinaryIndexedView<'_>,
view: &CompiledModule,
function_type_args: &[AbilitySet],
s: &SignatureToken,
) -> Result<bool, String> {
Expand Down
4 changes: 1 addition & 3 deletions crates/sui-types/src/move_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use derive_more::Display;
use fastcrypto::hash::HashFunction;
use move_binary_format::access::ModuleAccess;
use move_binary_format::binary_config::BinaryConfig;
use move_binary_format::binary_views::BinaryIndexedView;
use move_binary_format::file_format::CompiledModule;
use move_binary_format::normalized;
use move_core_types::language_storage::ModuleId;
Expand Down Expand Up @@ -586,8 +585,7 @@ where
error: error.to_string(),
}
})?;
let view = BinaryIndexedView::Module(&module);
let d = Disassembler::from_view(view, Spanned::unsafe_no_loc(()).loc).map_err(|e| {
let d = Disassembler::from_view(&module, Spanned::unsafe_no_loc(()).loc).map_err(|e| {
SuiError::ObjectSerializationError {
error: e.to_string(),
}
Expand Down
13 changes: 6 additions & 7 deletions crates/sui-types/src/randomness_state.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use move_binary_format::binary_views::BinaryIndexedView;
use move_binary_format::file_format::SignatureToken;
use move_binary_format::{file_format::SignatureToken, CompiledModule};
use move_bytecode_utils::resolve_struct;
use move_core_types::{account_address::AccountAddress, ident_str, identifier::IdentStr};

use crate::base_types::SequenceNumber;

use crate::error::SuiResult;
use crate::object::Owner;
use crate::storage::ObjectStore;
use crate::{SUI_FRAMEWORK_ADDRESS, SUI_RANDOMNESS_STATE_OBJECT_ID};
use crate::{
error::SuiResult, object::Owner, storage::ObjectStore, SUI_FRAMEWORK_ADDRESS,
SUI_RANDOMNESS_STATE_OBJECT_ID,
};

pub const RANDOMNESS_MODULE_NAME: &IdentStr = ident_str!("random");
pub const RANDOMNESS_STATE_STRUCT_NAME: &IdentStr = ident_str!("Random");
Expand All @@ -36,7 +35,7 @@ pub fn get_randomness_state_obj_initial_shared_version(
}))
}

pub fn is_mutable_random(view: &BinaryIndexedView<'_>, s: &SignatureToken) -> bool {
pub fn is_mutable_random(view: &CompiledModule, s: &SignatureToken) -> bool {
match s {
SignatureToken::MutableReference(inner) => is_mutable_random(view, inner),
SignatureToken::Struct(idx) => resolve_struct(view, *idx) == RESOLVED_SUI_RANDOMNESS_STATE,
Expand Down
4 changes: 2 additions & 2 deletions crates/sui-types/src/transfer.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use move_binary_format::{binary_views::BinaryIndexedView, file_format::SignatureToken};
use move_binary_format::{file_format::SignatureToken, CompiledModule};
use move_bytecode_utils::resolve_struct;
use move_core_types::{
account_address::AccountAddress,
Expand Down Expand Up @@ -60,7 +60,7 @@ impl Receiving {
TypeTag::Struct(Box::new(Self::struct_tag()))
}

pub fn is_receiving(view: &BinaryIndexedView<'_>, s: &SignatureToken) -> bool {
pub fn is_receiving(view: &CompiledModule, s: &SignatureToken) -> bool {
use SignatureToken as S;
match s {
S::MutableReference(inner) | S::Reference(inner) => Self::is_receiving(view, inner),
Expand Down
10 changes: 4 additions & 6 deletions crates/sui/src/client_ptb/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ use async_recursion::async_recursion;
use async_trait::async_trait;
use miette::Severity;
use move_binary_format::{
access::ModuleAccess, binary_config::BinaryConfig, binary_views::BinaryIndexedView,
file_format::SignatureToken,
access::ModuleAccess, binary_config::BinaryConfig, file_format::SignatureToken, CompiledModule,
};
use move_command_line_common::{
address::{NumericalAddress, ParsedAddress},
Expand Down Expand Up @@ -431,7 +430,7 @@ impl<'a> PTBBuilder<'a> {
/// called.
async fn resolve_move_call_arg(
&mut self,
view: &BinaryIndexedView<'_>,
view: &CompiledModule,
ty_args: &[TypeTag],
sp!(loc, arg): Spanned<PTBArg>,
param: &SignatureToken,
Expand Down Expand Up @@ -550,13 +549,12 @@ impl<'a> PTBBuilder<'a> {
}
})?;
let function_signature = module.function_handle_at(fdef.function);
let view = BinaryIndexedView::Module(&module);
let parameters: Vec<_> = module
.signature_at(function_signature.parameters)
.0
.clone()
.into_iter()
.filter(|tok| matches!(TxContext::kind(&view, tok), TxContextKind::None))
.filter(|tok| matches!(TxContext::kind(&module, tok), TxContextKind::None))
.collect();

if parameters.len() != args.len() {
Expand All @@ -577,7 +575,7 @@ impl<'a> PTBBuilder<'a> {
let mut call_args = vec![];
for (param, arg) in parameters.iter().zip(args.into_iter()) {
let call_arg = self
.resolve_move_call_arg(&view, ty_args, arg, param)
.resolve_move_call_arg(&module, ty_args, arg, param)
.await?;
call_args.push(call_arg);
}
Expand Down
Loading

0 comments on commit 65a8ccf

Please sign in to comment.