diff --git a/forc-pkg/src/pkg.rs b/forc-pkg/src/pkg.rs index 50d8b24c703..19291e0d0ce 100644 --- a/forc-pkg/src/pkg.rs +++ b/forc-pkg/src/pkg.rs @@ -46,7 +46,7 @@ use sway_core::{ transform::AttributeKind, write_dwarf, BuildTarget, Engines, FinalizedEntry, LspConfig, }; -use sway_core::{set_bytecode_configurables_offset, PrintAsm, PrintIr}; +use sway_core::{PrintAsm, PrintIr}; use sway_error::{error::CompileError, handler::Handler, warning::CompileWarning}; use sway_features::ExperimentalFeatures; use sway_types::constants::{CORE, PRELUDE, STD}; @@ -1914,7 +1914,7 @@ pub fn compile( let errored = handler.has_errors() || (handler.has_warnings() && profile.error_on_warnings); - let mut compiled = match bc_res { + let compiled = match bc_res { Ok(compiled) if !errored => compiled, _ => return fail(handler), }; @@ -1923,12 +1923,9 @@ pub fn compile( print_warnings(engines.se(), terse_mode, &pkg.name, &warnings, &tree_type); - // Metadata to be placed into the binary. - let mut md = [0u8, 0, 0, 0, 0, 0, 0, 0]; // TODO: This should probably be in `fuel_abi_json::generate_json_abi_program`? // If ABI requires knowing config offsets, they should be inputs to ABI gen. if let ProgramABI::Fuel(ref mut program_abi) = program_abi { - let mut configurables_offset = compiled.bytecode.len() as u64; if let Some(ref mut configurables) = program_abi.configurables { // Filter out all dead configurables (i.e. ones without offsets in the bytecode) configurables.retain(|c| { @@ -1937,22 +1934,12 @@ pub fn compile( .contains_key(&c.name) }); // Set the actual offsets in the JSON object - for (config, offset) in &compiled.named_data_section_entries_offsets { - if *offset < configurables_offset { - configurables_offset = *offset; - } - if let Some(idx) = configurables.iter().position(|c| &c.name == config) { - configurables[idx].offset = *offset; + for (config, offset) in compiled.named_data_section_entries_offsets { + if let Some(idx) = configurables.iter().position(|c| c.name == config) { + configurables[idx].offset = offset; } } } - - md = configurables_offset.to_be_bytes(); - } - - // We know to set the metadata only for fuelvm right now. - if let BuildTarget::Fuel = pkg.target { - set_bytecode_configurables_offset(&mut compiled, &md); } metrics.bytecode_size = compiled.bytecode.len(); diff --git a/forc-plugins/forc-client/test/data/deployed_script/deployed_script-loader-abi.json b/forc-plugins/forc-client/test/data/deployed_script/deployed_script-loader-abi.json index c51c80ae2e9..81b65c43cd7 100644 --- a/forc-plugins/forc-client/test/data/deployed_script/deployed_script-loader-abi.json +++ b/forc-plugins/forc-client/test/data/deployed_script/deployed_script-loader-abi.json @@ -251,62 +251,62 @@ { "name": "BOOL", "concreteTypeId": "b760f44fa5965c2474a3b471467a22c43185152129295af588b022ae50b50903", - "offset": 240 + "offset": 136 }, { "name": "U8", "concreteTypeId": "c89951a24c6ca28c13fd1cfdc646b2b656d69e61a92b91023be7eb58eb914b6b", - "offset": 352 + "offset": 248 }, { "name": "U16", "concreteTypeId": "29881aad8730c5ab11d275376323d8e4ff4179aae8ccb6c13fe4902137e162ef", - "offset": 296 + "offset": 192 }, { "name": "U32", "concreteTypeId": "d7649d428b9ff33d188ecbf38a7e4d8fd167fa01b2e10fe9a8f9308e52f1d7cc", - "offset": 336 + "offset": 232 }, { "name": "U64", "concreteTypeId": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0", - "offset": 344 + "offset": 240 }, { "name": "U256", "concreteTypeId": "1b5759d94094368cfd443019e7ca5ec4074300e544e5ea993a979f5da627261e", - "offset": 304 + "offset": 200 }, { "name": "B256", "concreteTypeId": "7c5ee1cecf5f8eacd1284feb5f0bf2bdea533a51e2f0c9aabe9236d335989f3b", - "offset": 208 + "offset": 104 }, { "name": "STR_4", "concreteTypeId": "94f0fa95c830be5e4f711963e83259fe7e8bc723278ab6ec34449e791a99b53a", - "offset": 280 + "offset": 176 }, { "name": "TUPLE", "concreteTypeId": "e0128f7be9902d1fe16326cafe703b52038064a7997b03ebfc1c9dd607e1536c", - "offset": 288 + "offset": 184 }, { "name": "ARRAY", "concreteTypeId": "d9fac01ab38fe10950758ae9604da330d6406a71fda3ef1ea818121261132d56", - "offset": 192 + "offset": 88 }, { "name": "STRUCT", "concreteTypeId": "563310524b4f4447a10d0e50556310253dfb3b5eb4b29c3773222b737c8b7075", - "offset": 264 + "offset": 160 }, { "name": "ENUM", "concreteTypeId": "37cd1cba311039a851ac8bfa614cc41359b4ad95c8656fcef2e8f504fe7a1272", - "offset": 248 + "offset": 144 } ] } \ No newline at end of file diff --git a/forc-test/src/execute.rs b/forc-test/src/execute.rs index 76e89324903..3436261af94 100644 --- a/forc-test/src/execute.rs +++ b/forc-test/src/execute.rs @@ -9,7 +9,7 @@ use fuel_vm::{ self as vm, checked_transaction::builder::TransactionBuilderExt, interpreter::{Interpreter, NotSupportedEcal}, - prelude::SecretKey, + prelude::{Instruction, SecretKey}, storage::MemoryStorage, }; use rand::{Rng, SeedableRng}; @@ -246,21 +246,18 @@ impl TestExecutor { /// The following is how the beginning of the bytecode is laid out: /// /// ```ignore -/// [ 0] ji i(4 + 2) ; Jumps to the data section setup. -/// [ 1] noop -/// [ 2] DATA_SECTION_OFFSET[0..32] -/// [ 3] DATA_SECTION_OFFSET[32..64] -/// [ 4] CONFIGURABLES_OFFSET[0..32] -/// [ 5] CONFIGURABLES_OFFSET[32..64] -/// [ 6] lw $ds $is 1 ; The data section setup, i.e. where the first ji lands. -/// [ 7] add $$ds $$ds $is -/// [ 8] ; This is where we want to jump from to our test code! +/// [0] ji i4 ; Jumps to the data section setup. +/// [1] noop +/// [2] DATA_SECTION_OFFSET[0..32] +/// [3] DATA_SECTION_OFFSET[32..64] +/// [4] lw $ds $is 1 ; The data section setup, i.e. where the first ji lands. +/// [5] add $$ds $$ds $is +/// [6] ; This is where we want to jump from to our test code! /// ``` fn patch_test_bytecode(bytecode: &[u8], test_offset: u32) -> std::borrow::Cow<[u8]> { - // Each instruction is 4 bytes, - // so we divide the total byte-size by 4 to get the instruction offset. - const PROGRAM_START_INST_OFFSET: u32 = (sway_core::PRELUDE_SIZE_IN_BYTES / 4) as u32; - const PROGRAM_START_BYTE_OFFSET: usize = sway_core::PRELUDE_SIZE_IN_BYTES; + // TODO: Standardize this or add metadata to bytecode. + const PROGRAM_START_INST_OFFSET: u32 = 6; + const PROGRAM_START_BYTE_OFFSET: usize = PROGRAM_START_INST_OFFSET as usize * Instruction::SIZE; // If our desired entry point is the program start, no need to jump. if test_offset == PROGRAM_START_INST_OFFSET { diff --git a/forc/src/cli/commands/parse_bytecode.rs b/forc/src/cli/commands/parse_bytecode.rs index 4d5ecf0bdb6..f4a30c82d6d 100644 --- a/forc/src/cli/commands/parse_bytecode.rs +++ b/forc/src/cli/commands/parse_bytecode.rs @@ -59,14 +59,6 @@ pub(crate) fn exec(command: Command) -> ForcResult<()> { parsed_raw ) } - Err(fuel_asm::InvalidOpcode) if word_ix == 4 || word_ix == 5 => { - let parsed_raw = u32::from_be_bytes([raw[0], raw[1], raw[2], raw[3]]); - format!( - "configurables offset {} ({})", - if word_ix == 4 { "lo" } else { "hi" }, - parsed_raw - ) - } Ok(_) | Err(fuel_asm::InvalidOpcode) => "".into(), }; table.add_row(Row::new(vec![ diff --git a/forc/tests/cli_integration.rs b/forc/tests/cli_integration.rs index 422e9f18f9c..1f1248a2205 100644 --- a/forc/tests/cli_integration.rs +++ b/forc/tests/cli_integration.rs @@ -49,10 +49,10 @@ fn test_forc_test_raw_logs() -> Result<(), rexpect::error::Error> { // Assert that the output is correct process.exp_string(" test test_log_4")?; process.exp_string("Raw logs:")?; - process.exp_string(r#"[{"LogData":{"data":"0000000000000004","digest":"8005f02d43fa06e7d0585fb64c961d57e318b27a145c857bcd3a6bdb413ff7fc","id":"0000000000000000000000000000000000000000000000000000000000000000","is":10368,"len":8,"pc":12672,"ptr":67107840,"ra":0,"rb":1515152261580153489}}]"#)?; + process.exp_string(r#"[{"LogData":{"data":"0000000000000004","digest":"8005f02d43fa06e7d0585fb64c961d57e318b27a145c857bcd3a6bdb413ff7fc","id":"0000000000000000000000000000000000000000000000000000000000000000","is":10368,"len":8,"pc":12664,"ptr":67107840,"ra":0,"rb":1515152261580153489}}]"#)?; process.exp_string(" test test_log_2")?; process.exp_string("Raw logs:")?; - process.exp_string(r#"[{"LogData":{"data":"0000000000000002","digest":"cd04a4754498e06db5a13c5f371f1f04ff6d2470f24aa9bd886540e5dce77f70","id":"0000000000000000000000000000000000000000000000000000000000000000","is":10368,"len":8,"pc":12672,"ptr":67107840,"ra":0,"rb":1515152261580153489}}]"#)?; + process.exp_string(r#"[{"LogData":{"data":"0000000000000002","digest":"cd04a4754498e06db5a13c5f371f1f04ff6d2470f24aa9bd886540e5dce77f70","id":"0000000000000000000000000000000000000000000000000000000000000000","is":10368,"len":8,"pc":12664,"ptr":67107840,"ra":0,"rb":1515152261580153489}}]"#)?; process.process.exit()?; Ok(()) @@ -74,11 +74,11 @@ fn test_forc_test_both_logs() -> Result<(), rexpect::error::Error> { process.exp_string(" test test_log_4")?; process.exp_string("Decoded log value: 4, log rb: 1515152261580153489")?; process.exp_string("Raw logs:")?; - process.exp_string(r#"[{"LogData":{"data":"0000000000000004","digest":"8005f02d43fa06e7d0585fb64c961d57e318b27a145c857bcd3a6bdb413ff7fc","id":"0000000000000000000000000000000000000000000000000000000000000000","is":10368,"len":8,"pc":12672,"ptr":67107840,"ra":0,"rb":1515152261580153489}}]"#)?; + process.exp_string(r#"[{"LogData":{"data":"0000000000000004","digest":"8005f02d43fa06e7d0585fb64c961d57e318b27a145c857bcd3a6bdb413ff7fc","id":"0000000000000000000000000000000000000000000000000000000000000000","is":10368,"len":8,"pc":12664,"ptr":67107840,"ra":0,"rb":1515152261580153489}}]"#)?; process.exp_string(" test test_log_2")?; process.exp_string("Decoded log value: 2, log rb: 1515152261580153489")?; process.exp_string("Raw logs:")?; - process.exp_string(r#"[{"LogData":{"data":"0000000000000002","digest":"cd04a4754498e06db5a13c5f371f1f04ff6d2470f24aa9bd886540e5dce77f70","id":"0000000000000000000000000000000000000000000000000000000000000000","is":10368,"len":8,"pc":12672,"ptr":67107840,"ra":0,"rb":1515152261580153489}}]"#)?; + process.exp_string(r#"[{"LogData":{"data":"0000000000000002","digest":"cd04a4754498e06db5a13c5f371f1f04ff6d2470f24aa9bd886540e5dce77f70","id":"0000000000000000000000000000000000000000000000000000000000000000","is":10368,"len":8,"pc":12664,"ptr":67107840,"ra":0,"rb":1515152261580153489}}]"#)?; process.process.exit()?; Ok(()) } diff --git a/sway-core/src/asm_generation/finalized_asm.rs b/sway-core/src/asm_generation/finalized_asm.rs index c132d687855..ce3c81e3a56 100644 --- a/sway-core/src/asm_generation/finalized_asm.rs +++ b/sway-core/src/asm_generation/finalized_asm.rs @@ -3,8 +3,8 @@ use super::{ fuel::{checks, data_section::DataSection}, ProgramABI, ProgramKind, }; -use crate::asm_generation::fuel::data_section::{Datum, Entry, EntryName}; -use crate::asm_lang::allocated_ops::{AllocatedOp, AllocatedOpcode, FuelAsmData}; +use crate::asm_generation::fuel::data_section::{DataId, Datum, Entry}; +use crate::asm_lang::allocated_ops::{AllocatedOp, AllocatedOpcode}; use crate::decl_engine::DeclRefFunction; use crate::source_map::SourceMap; use crate::BuildConfig; @@ -16,6 +16,7 @@ use sway_error::handler::{ErrorEmitted, Handler}; use sway_types::span::Span; use sway_types::SourceEngine; +use either::Either; use std::{collections::BTreeMap, fmt}; /// Represents an ASM set which has had register allocation, jump elimination, and optimization @@ -111,7 +112,6 @@ fn to_bytecode_mut( { 8 } - AllocatedOpcode::ConfigurablesOffsetPlaceholder => 8, AllocatedOpcode::DataSectionOffsetPlaceholder => 8, AllocatedOpcode::BLOB(count) => count.value as u64 * 4, AllocatedOpcode::CFEI(i) | AllocatedOpcode::CFSI(i) if i.value == 0 => 0, @@ -141,29 +141,6 @@ fn to_bytecode_mut( &ops_padded }; - let mut offset_from_instr_start = 0; - for op in ops.iter() { - match &op.opcode { - AllocatedOpcode::LoadDataId(_reg, data_label) - if !data_section - .has_copy_type(data_label) - .expect("data label references non existent data -- internal error") => - { - // For non-copy type loads, pre-insert pointers into the data_section so that - // from this point on, the data_section remains immutable. This is necessary - // so that when we take addresses of configurables, that address doesn't change - // later on if a non-configurable is added to the data-section. - let offset_bytes = data_section.data_id_to_offset(data_label) as u64; - // The -4 is because $pc is added in the *next* instruction. - let pointer_offset_from_current_instr = - offset_to_data_section_in_bytes - offset_from_instr_start + offset_bytes - 4; - data_section.append_pointer(pointer_offset_from_current_instr); - } - _ => (), - } - offset_from_instr_start += op_size_in_bytes(data_section, op); - } - let mut bytecode = Vec::with_capacity(offset_to_data_section_in_bytes as usize); if build_config.print_bytecode { @@ -189,7 +166,7 @@ fn to_bytecode_mut( offset_from_instr_start += op_size_in_bytes(data_section, op); match fuel_op { - FuelAsmData::DatasectionOffset(data) => { + Either::Right(data) => { if build_config.print_bytecode { print!("{}{:#010x} ", " ".repeat(indentation), bytecode.len()); println!( @@ -205,23 +182,7 @@ fn to_bytecode_mut( bytecode.extend(data.iter().cloned()); half_word_ix += 2; } - FuelAsmData::ConfigurablesOffset(data) => { - if build_config.print_bytecode { - print!("{}{:#010x} ", " ".repeat(indentation), bytecode.len()); - println!( - " ;; {:?}", - data - ); - } - - // Static assert to ensure that we're only dealing with ConfigurablesOffsetPlaceholder, - // a 1-word (8 bytes) data within the code. No other uses are known. - let _: [u8; 8] = data; - - bytecode.extend(data.iter().cloned()); - half_word_ix += 2; - } - FuelAsmData::Instructions(instructions) => { + Either::Left(instructions) => { for instruction in instructions { // Print original source span only once if build_config.print_bytecode_spans { @@ -334,9 +295,9 @@ fn to_bytecode_mut( }; } - for (i, entry) in data_section.iter_all_entries().enumerate() { - let entry_offset = data_section.absolute_idx_to_offset(i); - print_entry(indentation, offset + entry_offset, &entry); + for (i, entry) in data_section.value_pairs.iter().enumerate() { + let entry_offset = data_section.data_id_to_offset(&DataId(i as u32)); + print_entry(indentation, offset + entry_offset, entry); } println!(";; --- END OF TARGET BYTECODE ---\n"); @@ -345,19 +306,16 @@ fn to_bytecode_mut( assert_eq!(half_word_ix * 4, offset_to_data_section_in_bytes as usize); assert_eq!(bytecode.len(), offset_to_data_section_in_bytes as usize); - let num_nonconfigurables = data_section.non_configurables.len(); let named_data_section_entries_offsets = data_section - .configurables + .value_pairs .iter() .enumerate() + .filter(|entry| entry.1.name.is_some()) .map(|(id, entry)| { - let EntryName::Configurable(name) = &entry.name else { - panic!("Non-configurable in configurables part of datasection"); - }; ( - name.clone(), + entry.name.as_ref().unwrap().clone(), offset_to_data_section_in_bytes - + data_section.absolute_idx_to_offset(id + num_nonconfigurables) as u64, + + data_section.raw_data_id_to_offset(id as u32) as u64, ) }) .collect::>(); diff --git a/sway-core/src/asm_generation/fuel/allocated_abstract_instruction_set.rs b/sway-core/src/asm_generation/fuel/allocated_abstract_instruction_set.rs index a0e53c98cce..0865687f5c8 100644 --- a/sway-core/src/asm_generation/fuel/allocated_abstract_instruction_set.rs +++ b/sway-core/src/asm_generation/fuel/allocated_abstract_instruction_set.rs @@ -1,10 +1,7 @@ -use crate::{ - asm_generation::fuel::data_section::EntryName, - asm_lang::{ - allocated_ops::{AllocatedOpcode, AllocatedRegister}, - AllocatedAbstractOp, ConstantRegister, ControlFlowOp, Label, RealizedOp, - VirtualImmediate12, VirtualImmediate18, VirtualImmediate24, - }, +use crate::asm_lang::{ + allocated_ops::{AllocatedOpcode, AllocatedRegister}, + AllocatedAbstractOp, ConstantRegister, ControlFlowOp, Label, RealizedOp, VirtualImmediate12, + VirtualImmediate18, VirtualImmediate24, }; use super::{ @@ -351,13 +348,6 @@ impl AllocatedAbstractInstructionSet { comment: String::new(), }); } - ControlFlowOp::ConfigurablesOffsetPlaceholder => { - realized_ops.push(RealizedOp { - opcode: AllocatedOpcode::ConfigurablesOffsetPlaceholder, - owning_span: None, - comment: String::new(), - }); - } ControlFlowOp::LoadLabel(r1, ref lab) => { // LoadLabel ops are inserted by `rewrite_far_jumps`. // So the next instruction must be a relative jump. @@ -373,11 +363,8 @@ impl AllocatedAbstractInstructionSet { // We compute the relative offset w.r.t the actual jump. // Sub 1 because the relative jumps add a 1. let offset = rel_offset(curr_offset + 1, lab) - 1; - let data_id = data_section.insert_data_value(Entry::new_word( - offset, - EntryName::NonConfigurable, - None, - )); + let data_id = + data_section.insert_data_value(Entry::new_word(offset, None, None)); realized_ops.push(RealizedOp { opcode: AllocatedOpcode::LoadDataId(r1, data_id), owning_span, @@ -486,8 +473,6 @@ impl AllocatedAbstractInstructionSet { 2 } - Either::Right(ConfigurablesOffsetPlaceholder) => 2, - Either::Right(PushAll(_)) | Either::Right(PopAll(_)) => unreachable!( "fix me, pushall and popall don't really belong in control flow ops \ since they're not about control flow" diff --git a/sway-core/src/asm_generation/fuel/data_section.rs b/sway-core/src/asm_generation/fuel/data_section.rs index e442dcf5ac1..3db12443f4f 100644 --- a/sway-core/src/asm_generation/fuel/data_section.rs +++ b/sway-core/src/asm_generation/fuel/data_section.rs @@ -1,30 +1,16 @@ -use rustc_hash::FxHashMap; use sway_ir::{size_bytes_round_up_to_word_alignment, Constant, ConstantValue, Context, Padding}; use std::{fmt, iter::repeat}; -#[derive(Clone, Debug, PartialEq, Eq)] -pub enum EntryName { - NonConfigurable, - Configurable(String), -} - -impl fmt::Display for EntryName { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - EntryName::NonConfigurable => write!(f, "NonConfigurable"), - EntryName::Configurable(name) => write!(f, "", name), - } - } -} - // An entry in the data section. It's important for the size to be correct, especially for unions // where the size could be larger than the represented value. #[derive(Clone, Debug)] pub struct Entry { pub value: Datum, pub padding: Padding, - pub name: EntryName, + // It is assumed, for now, that only configuration-time constants have a name. Otherwise, this + // is `None`. + pub name: Option, } #[derive(Clone, Debug)] @@ -37,7 +23,7 @@ pub enum Datum { } impl Entry { - pub(crate) fn new_byte(value: u8, name: EntryName, padding: Option) -> Entry { + pub(crate) fn new_byte(value: u8, name: Option, padding: Option) -> Entry { Entry { value: Datum::Byte(value), padding: padding.unwrap_or(Padding::default_for_u8(value)), @@ -45,7 +31,7 @@ impl Entry { } } - pub(crate) fn new_word(value: u64, name: EntryName, padding: Option) -> Entry { + pub(crate) fn new_word(value: u64, name: Option, padding: Option) -> Entry { Entry { value: Datum::Word(value), padding: padding.unwrap_or(Padding::default_for_u64(value)), @@ -55,7 +41,7 @@ impl Entry { pub(crate) fn new_byte_array( bytes: Vec, - name: EntryName, + name: Option, padding: Option, ) -> Entry { Entry { @@ -65,7 +51,11 @@ impl Entry { } } - pub(crate) fn new_slice(bytes: Vec, name: EntryName, padding: Option) -> Entry { + pub(crate) fn new_slice( + bytes: Vec, + name: Option, + padding: Option, + ) -> Entry { Entry { padding: padding.unwrap_or(Padding::default_for_byte_array(&bytes)), value: Datum::Slice(bytes), @@ -75,7 +65,7 @@ impl Entry { pub(crate) fn new_collection( elements: Vec, - name: EntryName, + name: Option, padding: Option, ) -> Entry { Entry { @@ -90,7 +80,7 @@ impl Entry { pub(crate) fn from_constant( context: &Context, constant: &Constant, - name: EntryName, + name: Option, padding: Option, ) -> Entry { // We need a special handling in case of enums. @@ -99,9 +89,8 @@ impl Entry { .enum_tag_and_value_with_paddings(context) .expect("Constant is an enum."); - let tag_entry = Entry::from_constant(context, tag.0, EntryName::NonConfigurable, tag.1); - let value_entry = - Entry::from_constant(context, value.0, EntryName::NonConfigurable, value.1); + let tag_entry = Entry::from_constant(context, tag.0, None, tag.1); + let value_entry = Entry::from_constant(context, value.0, None, value.1); return Entry::new_collection(vec![tag_entry, value_entry], name, padding); } @@ -129,9 +118,7 @@ impl Entry { .array_elements_with_padding(context) .expect("Constant is an array.") .into_iter() - .map(|(elem, padding)| { - Entry::from_constant(context, elem, EntryName::NonConfigurable, padding) - }) + .map(|(elem, padding)| Entry::from_constant(context, elem, None, padding)) .collect(), name, padding, @@ -141,9 +128,7 @@ impl Entry { .struct_fields_with_padding(context) .expect("Constant is a struct.") .into_iter() - .map(|(elem, padding)| { - Entry::from_constant(context, elem, EntryName::NonConfigurable, padding) - }) + .map(|(elem, padding)| Entry::from_constant(context, elem, None, padding)) .collect(), name, padding, @@ -213,92 +198,45 @@ impl Entry { } } -#[derive(Clone, Debug)] -pub enum DataIdEntryKind { - NonConfigurable, - Configurable, -} - -impl fmt::Display for DataIdEntryKind { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - DataIdEntryKind::NonConfigurable => write!(f, "NonConfigurable"), - DataIdEntryKind::Configurable => write!(f, "Configurable"), - } - } -} - /// An address which refers to a value in the data section of the asm. #[derive(Clone, Debug)] -pub(crate) struct DataId { - pub(crate) idx: u32, - pub(crate) kind: DataIdEntryKind, -} +pub(crate) struct DataId(pub(crate) u32); impl fmt::Display for DataId { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "data_{}_{}", self.kind, self.idx) + write!(f, "data_{}", self.0) } } -/// The data to be put in the data section of the asm #[derive(Default, Clone, Debug)] pub struct DataSection { - pub non_configurables: Vec, - pub configurables: Vec, - pub(crate) pointer_id: FxHashMap, + /// the data to be put in the data section of the asm + pub value_pairs: Vec, } impl DataSection { - /// Get the number of entries - pub(crate) fn num_entries(&self) -> usize { - self.non_configurables.len() + self.configurables.len() - } - - /// Iterate over all entries, non-configurables followed by configurables - pub(crate) fn iter_all_entries(&self) -> impl Iterator + '_ { - self.non_configurables - .iter() - .chain(self.configurables.iter()) - .cloned() - } - - /// Get the absolute index of an id - fn absolute_idx(&self, id: &DataId) -> usize { - match id.kind { - DataIdEntryKind::NonConfigurable => id.idx as usize, - DataIdEntryKind::Configurable => id.idx as usize + self.non_configurables.len(), - } - } - - /// Get entry at id - fn get(&self, id: &DataId) -> Option<&Entry> { - match id.kind { - DataIdEntryKind::NonConfigurable => self.non_configurables.get(id.idx as usize), - DataIdEntryKind::Configurable => self.configurables.get(id.idx as usize), - } - } - /// Given a [DataId], calculate the offset _from the beginning of the data section_ to the data /// in bytes. pub(crate) fn data_id_to_offset(&self, id: &DataId) -> usize { - let idx = self.absolute_idx(id); - self.absolute_idx_to_offset(idx) + self.raw_data_id_to_offset(id.0) } - /// Given an absolute index, calculate the offset _from the beginning of the data section_ to the data + /// Given a [DataId], calculate the offset _from the beginning of the data section_ to the data /// in bytes. - pub(crate) fn absolute_idx_to_offset(&self, idx: usize) -> usize { - self.iter_all_entries().take(idx).fold(0, |offset, entry| { - //entries must be word aligned - size_bytes_round_up_to_word_alignment!(offset + entry.to_bytes().len()) - }) + pub(crate) fn raw_data_id_to_offset(&self, id: u32) -> usize { + self.value_pairs + .iter() + .take(id as usize) + .fold(0, |offset, entry| { + //entries must be word aligned + size_bytes_round_up_to_word_alignment!(offset + entry.to_bytes().len()) + }) } pub(crate) fn serialize_to_bytes(&self) -> Vec { // not the exact right capacity but serves as a lower bound - let mut buf = Vec::with_capacity(self.num_entries()); - for entry in self.iter_all_entries() { + let mut buf = Vec::with_capacity(self.value_pairs.len()); + for entry in &self.value_pairs { buf.append(&mut entry.to_bytes()); //entries must be word aligned @@ -310,12 +248,16 @@ impl DataSection { /// Returns whether a specific [DataId] value has a copy type (fits in a register). pub(crate) fn has_copy_type(&self, id: &DataId) -> Option { - self.get(id).map(|entry| entry.has_copy_type()) + self.value_pairs + .get(id.0 as usize) + .map(|entry| entry.has_copy_type()) } /// Returns whether a specific [DataId] value is a byte entry. pub(crate) fn is_byte(&self, id: &DataId) -> Option { - self.get(id).map(|entry| entry.is_byte()) + self.value_pairs + .get(id.0 as usize) + .map(|entry| entry.is_byte()) } /// When generating code, sometimes a hard-coded data pointer is needed to reference @@ -326,57 +268,31 @@ impl DataSection { /// relative to the current (load) instruction. pub(crate) fn append_pointer(&mut self, pointer_value: u64) -> DataId { // The 'pointer' is just a literal 64 bit address. - let data_id = self.insert_data_value(Entry::new_word( - pointer_value, - EntryName::NonConfigurable, - None, - )); - self.pointer_id.insert(pointer_value, data_id.clone()); - data_id - } - - /// Get the [DataId] for a pointer, if it exists. - /// The pointer must've been inserted with append_pointer. - pub(crate) fn data_id_of_pointer(&self, pointer_value: u64) -> Option { - self.pointer_id.get(&pointer_value).cloned() + self.insert_data_value(Entry::new_word(pointer_value, None, None)) } /// Given any data in the form of a [Literal] (using this type mainly because it includes type - /// information and debug spans), insert it into the data section and return its handle as + /// information and debug spans), insert it into the data section and return its offset as a /// [DataId]. pub(crate) fn insert_data_value(&mut self, new_entry: Entry) -> DataId { // if there is an identical data value, use the same id - - let (value_pairs, kind) = match new_entry.name { - EntryName::NonConfigurable => ( - &mut self.non_configurables, - DataIdEntryKind::NonConfigurable, - ), - EntryName::Configurable(_) => (&mut self.configurables, DataIdEntryKind::Configurable), - }; - match value_pairs.iter().position(|entry| entry.equiv(&new_entry)) { - Some(num) => DataId { - idx: num as u32, - kind, - }, + match self + .value_pairs + .iter() + .position(|entry| entry.equiv(&new_entry)) + { + Some(num) => DataId(num as u32), None => { - value_pairs.push(new_entry); + self.value_pairs.push(new_entry); // the index of the data section where the value is stored - DataId { - idx: (value_pairs.len() - 1) as u32, - kind, - } + DataId((self.value_pairs.len() - 1) as u32) } } } // If the stored data is Datum::Word, return the inner value. pub(crate) fn get_data_word(&self, data_id: &DataId) -> Option { - let value_pairs = match data_id.kind { - DataIdEntryKind::NonConfigurable => &self.non_configurables, - DataIdEntryKind::Configurable => &self.configurables, - }; - value_pairs.get(data_id.idx as usize).and_then(|entry| { + self.value_pairs.get(data_id.0 as usize).and_then(|entry| { if let Datum::Word(w) = entry.value { Some(w) } else { @@ -406,12 +322,11 @@ impl fmt::Display for DataSection { use std::fmt::Write; let mut data_buf = String::new(); - for (ix, entry) in self.iter_all_entries().enumerate() { + for (ix, entry) in self.value_pairs.iter().enumerate() { writeln!( data_buf, - "data_{}_{} {}", - entry.name, - ix, + "{} {}", + DataId(ix as u32), display_entry(&entry.value) )?; } diff --git a/sway-core/src/asm_generation/fuel/fuel_asm_builder.rs b/sway-core/src/asm_generation/fuel/fuel_asm_builder.rs index 5c98c09411e..0e56e87d33f 100644 --- a/sway-core/src/asm_generation/fuel/fuel_asm_builder.rs +++ b/sway-core/src/asm_generation/fuel/fuel_asm_builder.rs @@ -1,5 +1,4 @@ use super::{ - data_section::EntryName, globals_section::GlobalsSection, programs::{AbstractEntry, AbstractProgram}, }; @@ -99,12 +98,7 @@ impl<'ir, 'eng> AsmBuilder for FuelAsmBuilder<'ir, 'eng> { fn compile_configurable(&mut self, config: &ConfigContent) { match config { ConfigContent::V0 { name, constant, .. } => { - let entry = Entry::from_constant( - self.context, - constant, - EntryName::Configurable(name.clone()), - None, - ); + let entry = Entry::from_constant(self.context, constant, Some(name.clone()), None); let dataid = self.data_section.insert_data_value(entry); self.configurable_v0_data_id.insert(name.clone(), dataid); } @@ -123,7 +117,7 @@ impl<'ir, 'eng> AsmBuilder for FuelAsmBuilder<'ir, 'eng> { let (decode_fn_label, _) = self.func_label_map.get(&decode_fn.get()).unwrap(); let dataid = self.data_section.insert_data_value(Entry::new_byte_array( encoded_bytes.clone(), - EntryName::Configurable(name.clone()), + Some(name.clone()), None, )); @@ -2063,11 +2057,6 @@ impl<'ir, 'eng> FuelAsmBuilder<'ir, 'eng> { _otherwise => { // Get the constant into the namespace. - let config_name = if let Some(name) = config_name { - EntryName::Configurable(name) - } else { - EntryName::NonConfigurable - }; let entry = Entry::from_constant(self.context, constant, config_name, None); let data_id = self.data_section.insert_data_value(entry); @@ -2188,11 +2177,9 @@ impl<'ir, 'eng> FuelAsmBuilder<'ir, 'eng> { } } else { let comment = comment.into(); - let data_id = self.data_section.insert_data_value(Entry::new_word( - imm, - EntryName::NonConfigurable, - None, - )); + let data_id = self + .data_section + .insert_data_value(Entry::new_word(imm, None, None)); self.cur_bytecode.push(Op { opcode: Either::Left(VirtualOp::LoadDataId(reg.clone(), data_id)), owning_span: span.clone(), diff --git a/sway-core/src/asm_generation/fuel/functions.rs b/sway-core/src/asm_generation/fuel/functions.rs index f217a4e8396..42577c543d6 100644 --- a/sway-core/src/asm_generation/fuel/functions.rs +++ b/sway-core/src/asm_generation/fuel/functions.rs @@ -26,7 +26,7 @@ use sway_error::{ }; use sway_types::{Ident, Span}; -use super::{compiler_constants::NUM_ARG_REGISTERS, data_section::EntryName}; +use super::compiler_constants::NUM_ARG_REGISTERS; /// A summary of the adopted calling convention: /// @@ -830,13 +830,9 @@ impl<'ir, 'eng> FuelAsmBuilder<'ir, 'eng> { ); } _ => { - let data_id = - self.data_section.insert_data_value(Entry::from_constant( - self.context, - constant, - EntryName::NonConfigurable, - None, - )); + let data_id = self.data_section.insert_data_value( + Entry::from_constant(self.context, constant, None, None), + ); self.ptr_map.insert(*ptr, Storage::Data(data_id)); } } @@ -862,13 +858,9 @@ impl<'ir, 'eng> FuelAsmBuilder<'ir, 'eng> { }); } _ => { - let data_id = - self.data_section.insert_data_value(Entry::from_constant( - self.context, - constant, - EntryName::NonConfigurable, - None, - )); + let data_id = self.data_section.insert_data_value( + Entry::from_constant(self.context, constant, None, None), + ); init_mut_vars.push(InitMutVars { stack_base_words, diff --git a/sway-core/src/asm_generation/fuel/programs/abstract.rs b/sway-core/src/asm_generation/fuel/programs/abstract.rs index 3256da242bb..b5a8a12e302 100644 --- a/sway-core/src/asm_generation/fuel/programs/abstract.rs +++ b/sway-core/src/asm_generation/fuel/programs/abstract.rs @@ -5,7 +5,7 @@ use crate::{ abstract_instruction_set::AbstractInstructionSet, allocated_abstract_instruction_set::AllocatedAbstractInstructionSet, compiler_constants, - data_section::{DataSection, Entry, EntryName}, + data_section::{DataSection, Entry}, globals_section::GlobalsSection, register_sequencer::RegisterSequencer, }, @@ -75,7 +75,7 @@ impl AbstractProgram { pub(crate) fn is_empty(&self) -> bool { self.non_entries.is_empty() && self.entries.is_empty() - && self.data_section.iter_all_entries().next().is_none() + && self.data_section.value_pairs.is_empty() } /// Adds prologue, globals allocation, before entries, contract method switch, and allocates virtual register. @@ -164,28 +164,14 @@ impl AbstractProgram { /// Right now, it looks like this: /// /// WORD OP - /// 1 MOV $scratch $pc - /// - JMPF $zero i10 - /// 2 DATA_START (0-32) (in bytes, offset from $is) - /// - DATA_START (32-64) - /// 3 CONFIGURABLES_OFFSET (0-32) - /// - CONFIGURABLES_OFFSET (32-64) - /// 4 LW $ds $scratch 1 - /// - ADD $ds $ds $scratch - /// 5 .program_start: + /// [1] MOV $scratch $pc + /// [-] JMPF $zero i2 + /// [2] DATA_START (0-32) (in bytes, offset from $is) + /// [-] DATA_START (32-64) + /// [3] LW $ds $scratch 1 + /// [-] ADD $ds $ds $scratch + /// [4] .program_start: fn build_prologue(&mut self) -> AllocatedAbstractInstructionSet { - const _: () = assert!( - crate::PRELUDE_CONFIGURABLES_OFFSET_IN_BYTES == 16, - "Inconsistency in the assumption of prelude organisation" - ); - const _: () = assert!( - crate::PRELUDE_CONFIGURABLES_SIZE_IN_BYTES == 8, - "Inconsistency in the assumption of prelude organisation" - ); - const _: () = assert!( - crate::PRELUDE_SIZE_IN_BYTES == 32, - "Inconsistency in the assumption of prelude organisation" - ); let label = self.reg_seqr.get_label(); AllocatedAbstractInstructionSet { ops: [ @@ -209,18 +195,12 @@ impl AbstractProgram { comment: "data section offset".into(), owning_span: None, }, - // word 3 -- full word u64 placeholder - AllocatedAbstractOp { - opcode: Either::Right(ControlFlowOp::ConfigurablesOffsetPlaceholder), - comment: "configurables offset".into(), - owning_span: None, - }, AllocatedAbstractOp { opcode: Either::Right(ControlFlowOp::Label(label)), - comment: "end of configurables offset".into(), + comment: "end of metadata".into(), owning_span: None, }, - // word 4 -- load the data offset into $ds + // word 3 -- load the data offset into $ds AllocatedAbstractOp { opcode: Either::Left(AllocatedOpcode::LW( AllocatedRegister::Constant(ConstantRegister::DataSectionStart), @@ -230,7 +210,7 @@ impl AbstractProgram { comment: "".into(), owning_span: None, }, - // word 4.5 -- add $ds $ds $is + // word 3.5 -- add $ds $ds $is AllocatedAbstractOp { opcode: Either::Left(AllocatedOpcode::ADD( AllocatedRegister::Constant(ConstantRegister::DataSectionStart), @@ -301,7 +281,7 @@ impl AbstractProgram { // Put the selector in the data section. let data_label = self.data_section.insert_data_value(Entry::new_word( u32::from_be_bytes(selector) as u64, - EntryName::NonConfigurable, + None, None, )); diff --git a/sway-core/src/asm_lang/allocated_ops.rs b/sway-core/src/asm_lang/allocated_ops.rs index 31220a0900d..b78ba37b2db 100644 --- a/sway-core/src/asm_lang/allocated_ops.rs +++ b/sway-core/src/asm_lang/allocated_ops.rs @@ -17,6 +17,7 @@ use crate::{ }, fuel_prelude::fuel_asm::{self, op}, }; +use either::Either; use fuel_vm::fuel_asm::{op::ADDI, Imm12}; use std::fmt::{self, Write}; use sway_types::span::Span; @@ -272,7 +273,6 @@ pub(crate) enum AllocatedOpcode { /* Non-VM Instructions */ BLOB(VirtualImmediate24), - ConfigurablesOffsetPlaceholder, DataSectionOffsetPlaceholder, LoadDataId(AllocatedRegister, DataId), AddrDataId(AllocatedRegister, DataId), @@ -397,7 +397,6 @@ impl AllocatedOpcode { /* Non-VM Instructions */ BLOB(_imm) => vec![], - ConfigurablesOffsetPlaceholder => vec![], DataSectionOffsetPlaceholder => vec![], LoadDataId(r1, _i) => vec![r1], AddrDataId(r1, _i) => vec![r1], @@ -526,10 +525,6 @@ impl fmt::Display for AllocatedOpcode { /* Non-VM Instructions */ BLOB(a) => write!(fmtr, "blob {a}"), - ConfigurablesOffsetPlaceholder => write!( - fmtr, - "CONFIGURABLES_OFFSET[0..32]\nCONFIGURABLES_OFFSET[32..64]" - ), DataSectionOffsetPlaceholder => { write!( fmtr, @@ -567,21 +562,17 @@ impl fmt::Display for AllocatedOp { } } -pub(crate) enum FuelAsmData { - ConfigurablesOffset([u8; 8]), - DatasectionOffset([u8; 8]), - Instructions(Vec), -} +type DoubleWideData = [u8; 8]; impl AllocatedOp { pub(crate) fn to_fuel_asm( &self, offset_to_data_section: u64, offset_from_instr_start: u64, - data_section: &DataSection, - ) -> FuelAsmData { + data_section: &mut DataSection, + ) -> Either, DoubleWideData> { use AllocatedOpcode::*; - FuelAsmData::Instructions(vec![match &self.opcode { + Either::Left(vec![match &self.opcode { /* Arithmetic/Logic (ALU) Instructions */ ADD(a, b, c) => op::ADD::new(a.to_reg_id(), b.to_reg_id(), c.to_reg_id()).into(), ADDI(a, b, c) => op::ADDI::new(a.to_reg_id(), b.to_reg_id(), c.value.into()).into(), @@ -650,9 +641,9 @@ impl AllocatedOp { /* Memory Instructions */ ALOC(a) => op::ALOC::new(a.to_reg_id()).into(), - CFEI(a) if a.value == 0 => return FuelAsmData::Instructions(vec![]), + CFEI(a) if a.value == 0 => return Either::Left(vec![]), CFEI(a) => op::CFEI::new(a.value.into()).into(), - CFSI(a) if a.value == 0 => return FuelAsmData::Instructions(vec![]), + CFSI(a) if a.value == 0 => return Either::Left(vec![]), CFSI(a) => op::CFSI::new(a.value.into()).into(), CFE(a) => op::CFE::new(a.to_reg_id()).into(), CFS(a) => op::CFS::new(a.to_reg_id()).into(), @@ -736,20 +727,17 @@ impl AllocatedOp { /* Non-VM Instructions */ BLOB(a) => { - return FuelAsmData::Instructions( + return Either::Left( std::iter::repeat(op::NOOP::new().into()) .take(a.value as usize) .collect(), ) } - ConfigurablesOffsetPlaceholder => { - return FuelAsmData::ConfigurablesOffset([0, 0, 0, 0, 0, 0, 0, 0]) - } DataSectionOffsetPlaceholder => { - return FuelAsmData::DatasectionOffset(offset_to_data_section.to_be_bytes()) + return Either::Right(offset_to_data_section.to_be_bytes()) } LoadDataId(a, b) => { - return FuelAsmData::Instructions(realize_load( + return Either::Left(realize_load( a, b, data_section, @@ -757,7 +745,7 @@ impl AllocatedOp { offset_from_instr_start, )) } - AddrDataId(a, b) => return FuelAsmData::Instructions(addr_of(a, b, data_section)), + AddrDataId(a, b) => return Either::Left(addr_of(a, b, data_section)), Undefined => unreachable!("Sway cannot generate undefined ASM opcodes"), }]) } @@ -767,7 +755,7 @@ impl AllocatedOp { fn addr_of( dest: &AllocatedRegister, data_id: &DataId, - data_section: &DataSection, + data_section: &mut DataSection, ) -> Vec { let offset_bytes = data_section.data_id_to_offset(data_id) as u64; vec![fuel_asm::Instruction::ADDI(ADDI::new( @@ -784,7 +772,7 @@ fn addr_of( fn realize_load( dest: &AllocatedRegister, data_id: &DataId, - data_section: &DataSection, + data_section: &mut DataSection, offset_to_data_section: u64, offset_from_instr_start: u64, ) -> Vec { @@ -827,9 +815,7 @@ fn realize_load( offset_to_data_section - offset_from_instr_start + offset_bytes - 4; // insert the pointer as bytes as a new data section entry at the end of the data - let data_id_for_pointer = data_section - .data_id_of_pointer(pointer_offset_from_current_instr) - .expect("Pointer offset must be in data_section"); + let data_id_for_pointer = data_section.append_pointer(pointer_offset_from_current_instr); // now load the pointer we just created into the `dest`ination let mut buf = Vec::with_capacity(2); diff --git a/sway-core/src/asm_lang/mod.rs b/sway-core/src/asm_lang/mod.rs index 71e09cc2290..5e1bcaded52 100644 --- a/sway-core/src/asm_lang/mod.rs +++ b/sway-core/src/asm_lang/mod.rs @@ -1248,7 +1248,6 @@ impl fmt::Display for VirtualOp { /* Non-VM Instructions */ BLOB(a) => write!(fmtr, "blob {a}"), DataSectionOffsetPlaceholder => write!(fmtr, "data section offset placeholder"), - ConfigurablesOffsetPlaceholder => write!(fmtr, "configurables offset placeholder"), LoadDataId(a, b) => write!(fmtr, "load {a} {b}"), AddrDataId(a, b) => write!(fmtr, "addr {a} {b}"), Undefined => write!(fmtr, "undefined op"), @@ -1278,8 +1277,6 @@ pub(crate) enum ControlFlowOp { Call(Label), // Save a return label address in a register. SaveRetAddr(Reg, Label), - // Placeholder for the offset into the configurables section. - ConfigurablesOffsetPlaceholder, // placeholder for the DataSection offset DataSectionOffsetPlaceholder, // Placeholder for loading an address from the data section. @@ -1307,8 +1304,6 @@ impl fmt::Display for ControlFlowOp { SaveRetAddr(r1, lab) => format!("mova {r1} {lab}"), DataSectionOffsetPlaceholder => "DATA SECTION OFFSET[0..32]\nDATA SECTION OFFSET[32..64]".into(), - ConfigurablesOffsetPlaceholder => - "CONFIGURABLES_OFFSET[0..32]\nCONFIGURABLES_OFFSET[32..64]".into(), LoadLabel(r1, lab) => format!("lwlab {r1} {lab}"), PushAll(lab) => format!("pusha {lab}"), PopAll(lab) => format!("popa {lab}"), @@ -1326,7 +1321,6 @@ impl ControlFlowOp { | Jump(_) | Call(_) | DataSectionOffsetPlaceholder - | ConfigurablesOffsetPlaceholder | PushAll(_) | PopAll(_) => vec![], @@ -1345,7 +1339,6 @@ impl ControlFlowOp { | Call(_) | SaveRetAddr(..) | DataSectionOffsetPlaceholder - | ConfigurablesOffsetPlaceholder | LoadLabel(..) | PushAll(_) | PopAll(_) => vec![], @@ -1367,7 +1360,6 @@ impl ControlFlowOp { | JumpIfNotZero(..) | Call(_) | DataSectionOffsetPlaceholder - | ConfigurablesOffsetPlaceholder | PushAll(_) | PopAll(_) => vec![], }) @@ -1389,7 +1381,6 @@ impl ControlFlowOp { | Jump(_) | Call(_) | DataSectionOffsetPlaceholder - | ConfigurablesOffsetPlaceholder | PushAll(_) | PopAll(_) => self.clone(), @@ -1419,7 +1410,6 @@ impl ControlFlowOp { | Call(_) | SaveRetAddr(..) | DataSectionOffsetPlaceholder - | ConfigurablesOffsetPlaceholder | LoadLabel(..) | PushAll(_) | PopAll(_) => (), @@ -1476,7 +1466,6 @@ impl ControlFlowOp { Jump(label) => Jump(*label), Call(label) => Call(*label), DataSectionOffsetPlaceholder => DataSectionOffsetPlaceholder, - ConfigurablesOffsetPlaceholder => ConfigurablesOffsetPlaceholder, PushAll(label) => PushAll(*label), PopAll(label) => PopAll(*label), diff --git a/sway-core/src/asm_lang/virtual_ops.rs b/sway-core/src/asm_lang/virtual_ops.rs index 3d041713a4f..ffe3509b7cd 100644 --- a/sway-core/src/asm_lang/virtual_ops.rs +++ b/sway-core/src/asm_lang/virtual_ops.rs @@ -226,7 +226,6 @@ pub(crate) enum VirtualOp { /* Non-VM Instructions */ BLOB(VirtualImmediate24), - ConfigurablesOffsetPlaceholder, DataSectionOffsetPlaceholder, // LoadDataId takes a virtual register and a DataId, which points to a labeled piece // of data in the data section. Note that the ASM op corresponding to a LW is @@ -348,7 +347,6 @@ impl VirtualOp { /* Non-VM Instructions */ BLOB(_imm) => vec![], DataSectionOffsetPlaceholder => vec![], - ConfigurablesOffsetPlaceholder => vec![], LoadDataId(r1, _i) => vec![r1], AddrDataId(r1, _) => vec![r1], @@ -467,7 +465,6 @@ impl VirtualOp { // Virtual OPs | BLOB(_) | DataSectionOffsetPlaceholder - | ConfigurablesOffsetPlaceholder | Undefined => true } } @@ -574,7 +571,6 @@ impl VirtualOp { | GTF(_, _, _) | BLOB(_) | DataSectionOffsetPlaceholder - | ConfigurablesOffsetPlaceholder | LoadDataId(_, _) | AddrDataId(_, _) | Undefined => vec![], @@ -696,7 +692,6 @@ impl VirtualOp { /* Non-VM Instructions */ BLOB(_imm) => vec![], DataSectionOffsetPlaceholder => vec![], - ConfigurablesOffsetPlaceholder => vec![], LoadDataId(_r1, _i) => vec![], AddrDataId(_r1, _i) => vec![], @@ -820,7 +815,6 @@ impl VirtualOp { LoadDataId(r1, _i) => vec![r1], AddrDataId(r1, _i) => vec![r1], DataSectionOffsetPlaceholder => vec![], - ConfigurablesOffsetPlaceholder => vec![], Undefined => vec![], }) .into_iter() @@ -1269,7 +1263,6 @@ impl VirtualOp { /* Non-VM Instructions */ BLOB(i) => Self::BLOB(i.clone()), DataSectionOffsetPlaceholder => Self::DataSectionOffsetPlaceholder, - ConfigurablesOffsetPlaceholder => Self::ConfigurablesOffsetPlaceholder, LoadDataId(r1, i) => Self::LoadDataId(update_reg(reg_to_reg_map, r1), i.clone()), AddrDataId(r1, i) => Self::AddrDataId(update_reg(reg_to_reg_map, r1), i.clone()), Undefined => Self::Undefined, @@ -1750,7 +1743,6 @@ impl VirtualOp { /* Non-VM Instructions */ BLOB(imm) => AllocatedOpcode::BLOB(imm.clone()), DataSectionOffsetPlaceholder => AllocatedOpcode::DataSectionOffsetPlaceholder, - ConfigurablesOffsetPlaceholder => AllocatedOpcode::ConfigurablesOffsetPlaceholder, LoadDataId(reg1, label) => { AllocatedOpcode::LoadDataId(map_reg(&mapping, reg1), label.clone()) } diff --git a/sway-core/src/lib.rs b/sway-core/src/lib.rs index ac6b7d54d34..d66b8e779eb 100644 --- a/sway-core/src/lib.rs +++ b/sway-core/src/lib.rs @@ -992,28 +992,6 @@ pub fn compile_to_bytecode( asm_to_bytecode(handler, asm_res, source_map, engines.se(), build_config) } -/// Size of the prelude's CONFIGURABLES_OFFSET section, in bytes. -pub const PRELUDE_CONFIGURABLES_SIZE_IN_BYTES: usize = 8; -/// Offset (in bytes) of the CONFIGURABLES_OFFSET section in the prelude. -pub const PRELUDE_CONFIGURABLES_OFFSET_IN_BYTES: usize = 16; -/// Total size of the prelude in bytes. Instructions start right after. -pub const PRELUDE_SIZE_IN_BYTES: usize = 32; - -/// Given bytecode, overwrite the existing offset to configurables offset in the prelude with the given one. -pub fn set_bytecode_configurables_offset( - compiled_bytecode: &mut CompiledBytecode, - md: &[u8; PRELUDE_CONFIGURABLES_SIZE_IN_BYTES], -) { - assert!( - compiled_bytecode.bytecode.len() - >= PRELUDE_CONFIGURABLES_OFFSET_IN_BYTES + PRELUDE_CONFIGURABLES_SIZE_IN_BYTES - ); - let code = &mut compiled_bytecode.bytecode; - for (index, byte) in md.iter().enumerate() { - code[index + PRELUDE_CONFIGURABLES_OFFSET_IN_BYTES] = *byte; - } -} - /// Given the assembly (opcodes), compile to [CompiledBytecode], containing the asm in bytecode form. pub fn asm_to_bytecode( handler: &Handler, diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_consts/json_abi_oracle_new_encoding.json b/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_consts/json_abi_oracle_new_encoding.json index 4447c387c37..2daeaffdc6a 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_consts/json_abi_oracle_new_encoding.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_consts/json_abi_oracle_new_encoding.json @@ -62,82 +62,82 @@ { "concreteTypeId": "b760f44fa5965c2474a3b471467a22c43185152129295af588b022ae50b50903", "name": "BOOL", - "offset": 7056 + "offset": 6896 }, { "concreteTypeId": "c89951a24c6ca28c13fd1cfdc646b2b656d69e61a92b91023be7eb58eb914b6b", "name": "U8", - "offset": 7248 + "offset": 7088 }, { "concreteTypeId": "c89951a24c6ca28c13fd1cfdc646b2b656d69e61a92b91023be7eb58eb914b6b", "name": "ANOTHER_U8", - "offset": 6984 + "offset": 6824 }, { "concreteTypeId": "29881aad8730c5ab11d275376323d8e4ff4179aae8ccb6c13fe4902137e162ef", "name": "U16", - "offset": 7192 + "offset": 7032 }, { "concreteTypeId": "d7649d428b9ff33d188ecbf38a7e4d8fd167fa01b2e10fe9a8f9308e52f1d7cc", "name": "U32", - "offset": 7232 + "offset": 7072 }, { "concreteTypeId": "d7649d428b9ff33d188ecbf38a7e4d8fd167fa01b2e10fe9a8f9308e52f1d7cc", "name": "U64", - "offset": 7240 + "offset": 7080 }, { "concreteTypeId": "1b5759d94094368cfd443019e7ca5ec4074300e544e5ea993a979f5da627261e", "name": "U256", - "offset": 7200 + "offset": 7040 }, { "concreteTypeId": "7c5ee1cecf5f8eacd1284feb5f0bf2bdea533a51e2f0c9aabe9236d335989f3b", "name": "B256", - "offset": 7024 + "offset": 6864 }, { "concreteTypeId": "81fc10c4681a3271cf2d66b2ec6fbc8ed007a442652930844fcf11818c295bff", "name": "CONFIGURABLE_STRUCT", - "offset": 7144 + "offset": 6984 }, { "concreteTypeId": "a2922861f03be8a650595dd76455b95383a61b46dd418f02607fa2e00dc39d5c", "name": "CONFIGURABLE_ENUM_A", - "offset": 7064 + "offset": 6904 }, { "concreteTypeId": "a2922861f03be8a650595dd76455b95383a61b46dd418f02607fa2e00dc39d5c", "name": "CONFIGURABLE_ENUM_B", - "offset": 7104 + "offset": 6944 }, { "concreteTypeId": "4926d35d1a5157936b0a29bc126b8aace6d911209a5c130e9b716b0c73643ea6", "name": "ARRAY_BOOL", - "offset": 6992 + "offset": 6832 }, { "concreteTypeId": "776fb5a3824169d6736138565fdc20aad684d9111266a5ff6d5c675280b7e199", "name": "ARRAY_U64", - "offset": 7000 + "offset": 6840 }, { "concreteTypeId": "c998ca9a5f221fe7b5c66ae70c8a9562b86d964408b00d17f883c906bc1fe4be", "name": "TUPLE_BOOL_U64", - "offset": 7176 + "offset": 7016 }, { "concreteTypeId": "94f0fa95c830be5e4f711963e83259fe7e8bc723278ab6ec34449e791a99b53a", "name": "STR_4", - "offset": 7168 + "offset": 7008 }, { "concreteTypeId": "c89951a24c6ca28c13fd1cfdc646b2b656d69e61a92b91023be7eb58eb914b6b", "name": "NOT_USED", - "offset": 7160 + "offset": 7000 } ], "encodingVersion": "1", diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_dedup_decode/stdout.snap b/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_dedup_decode/stdout.snap index b4b15b07969..8e825421dd7 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_dedup_decode/stdout.snap +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_dedup_decode/stdout.snap @@ -1,6 +1,6 @@ --- source: test/tests/tests.rs -assertion_line: 115 +snapshot_kind: text --- > forc build --path test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_dedup_decode --release --ir final exit status: 0 @@ -361,4 +361,4 @@ script { !128 = fn_call_path_span !0 235 236 !129 = (!127 !128) - Finished release [optimized + fuel] target(s) [752 B] in ??? + Finished release [optimized + fuel] target(s) [744 B] in ??? diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/u256/u256_abi/json_abi_oracle_new_encoding.json b/test/src/e2e_vm_tests/test_programs/should_pass/language/u256/u256_abi/json_abi_oracle_new_encoding.json index c58838960ad..9759de1f861 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/u256/u256_abi/json_abi_oracle_new_encoding.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/u256/u256_abi/json_abi_oracle_new_encoding.json @@ -31,4 +31,4 @@ "metadataTypes": [], "programType": "script", "specVersion": "1" -} \ No newline at end of file +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/asset_ops_test/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/asset_ops_test/src/main.sw index 1c2a953fc35..faa1d135d6e 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/asset_ops_test/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/asset_ops_test/src/main.sw @@ -9,7 +9,7 @@ use test_fuel_coin_abi::*; #[cfg(experimental_new_encoding = false)] const FUEL_COIN_CONTRACT_ID = 0xec2277ebe007ade87e3d797c3b1e070dcd542d5ef8f038b471f262ef9cebc87c; #[cfg(experimental_new_encoding = true)] -const FUEL_COIN_CONTRACT_ID = 0x19c0d374734bd8a92b776787e9dffa0f105a90e3c977626f93a1916de54dd714; +const FUEL_COIN_CONTRACT_ID = 0xf2fecff29038dab2ef571397ea5507359265c9154608e7de36ccbea20ed5c8aa; #[cfg(experimental_new_encoding = false)] const BALANCE_CONTRACT_ID = 0xf6cd545152ac83225e8e7df2efb5c6fa6e37bc9b9e977b5ea8103d28668925df; diff --git a/test/src/sdk-harness/test_projects/auth/mod.rs b/test/src/sdk-harness/test_projects/auth/mod.rs index 5c167a1d927..2fefd28f8c8 100644 --- a/test/src/sdk-harness/test_projects/auth/mod.rs +++ b/test/src/sdk-harness/test_projects/auth/mod.rs @@ -624,7 +624,7 @@ async fn can_get_predicate_address() { // Setup predicate. let hex_predicate_address: &str = - "0x8b300a68337368654e71c65ae93c3d9eb3b9837d0c11d770cbf8740a6a5a8631"; + "0x5dcc82a88eebb07fb628db93d11ec38f085cbf36453a7135fea41b93cc44e118"; let predicate_address = Address::from_str(hex_predicate_address).expect("failed to create Address from string"); let predicate_bech32_address = Bech32Address::from(predicate_address); @@ -750,7 +750,7 @@ async fn when_incorrect_predicate_address_passed() { async fn can_get_predicate_address_in_message() { // Setup predicate address. let hex_predicate_address: &str = - "0x8b300a68337368654e71c65ae93c3d9eb3b9837d0c11d770cbf8740a6a5a8631"; + "0x5dcc82a88eebb07fb628db93d11ec38f085cbf36453a7135fea41b93cc44e118"; let predicate_address = Address::from_str(hex_predicate_address).expect("failed to create Address from string"); let predicate_bech32_address = Bech32Address::from(predicate_address);