Skip to content

Commit

Permalink
encoding beginh experimental flag
Browse files Browse the repository at this point in the history
  • Loading branch information
xunilrj committed Dec 21, 2023
1 parent f9f427a commit c42bde1
Show file tree
Hide file tree
Showing 35 changed files with 398 additions and 102 deletions.
14 changes: 14 additions & 0 deletions forc-pkg/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,14 @@ pub struct BuildProfile {
#[serde(default)]
pub error_on_warnings: bool,
pub reverse_results: bool,
#[serde(default)]
pub experimental: ExperimentalFlags,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Default)]
#[serde(rename_all = "kebab-case")]
pub struct ExperimentalFlags {
pub new_encoding: bool,
}

impl DependencyDetails {
Expand Down Expand Up @@ -718,6 +726,9 @@ impl BuildProfile {
json_abi_with_callpaths: false,
error_on_warnings: false,
reverse_results: false,
experimental: ExperimentalFlags {
new_encoding: false,
},
}
}

Expand All @@ -736,6 +747,9 @@ impl BuildProfile {
json_abi_with_callpaths: false,
error_on_warnings: false,
reverse_results: false,
experimental: ExperimentalFlags {
new_encoding: false,
},
}
}
}
Expand Down
30 changes: 20 additions & 10 deletions forc-pkg/src/pkg.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use crate::{
lock::Lock,
manifest::{BuildProfile, Dependency, ManifestFile, MemberManifestFiles, PackageManifestFile},
manifest::{
BuildProfile, Dependency, ExperimentalFlags, ManifestFile, MemberManifestFiles,
PackageManifestFile,
},
source::{self, IPFSNode, Source},
};
use anyhow::{anyhow, bail, Context, Error, Result};
Expand Down Expand Up @@ -308,6 +311,8 @@ pub struct BuildOpts {
pub tests: bool,
/// The set of options to filter by member project kind.
pub member_filter: MemberFilter,
/// Set of experimental flags
pub experimental: ExperimentalFlags,
}

/// The set of options to filter type of projects to build in a workspace.
Expand Down Expand Up @@ -1551,14 +1556,17 @@ pub fn sway_build_config(
manifest_dir.to_path_buf(),
build_target,
)
.print_dca_graph(build_profile.print_dca_graph.clone())
.print_dca_graph_url_format(build_profile.print_dca_graph_url_format.clone())
.print_finalized_asm(build_profile.print_finalized_asm)
.print_intermediate_asm(build_profile.print_intermediate_asm)
.print_ir(build_profile.print_ir)
.include_tests(build_profile.include_tests)
.time_phases(build_profile.time_phases)
.metrics(build_profile.metrics_outfile.clone());
.with_print_dca_graph(build_profile.print_dca_graph.clone())
.with_print_dca_graph_url_format(build_profile.print_dca_graph_url_format.clone())
.with_print_finalized_asm(build_profile.print_finalized_asm)
.with_print_intermediate_asm(build_profile.print_intermediate_asm)
.with_print_ir(build_profile.print_ir)
.with_include_tests(build_profile.include_tests)
.with_time_phases(build_profile.time_phases)
.with_metrics(build_profile.metrics_outfile.clone())
.with_experimental(sway_core::ExperimentalFlags {
new_encoding: build_profile.experimental.new_encoding,
});
Ok(build_config)
}

Expand Down Expand Up @@ -2030,6 +2038,7 @@ fn build_profile_from_opts(
metrics_outfile,
tests,
error_on_warnings,
experimental,
..
} = build_options;
let mut selected_build_profile = BuildProfile::DEBUG;
Expand Down Expand Up @@ -2083,6 +2092,7 @@ fn build_profile_from_opts(
profile.include_tests |= tests;
profile.json_abi_with_callpaths |= pkg.json_abi_with_callpaths;
profile.error_on_warnings |= error_on_warnings;
profile.experimental = experimental.clone();

Ok((selected_build_profile.to_string(), profile))
}
Expand Down Expand Up @@ -2625,7 +2635,7 @@ pub fn check(
build_target,
&profile,
)?
.include_tests(include_tests);
.with_include_tests(include_tests);

let input = manifest.entry_string()?;
let handler = Handler::default();
Expand Down
3 changes: 3 additions & 0 deletions forc-plugins/forc-client/src/cmd/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,7 @@ pub struct Command {
/// ]
#[clap(long, verbatim_doc_comment, name = "JSON_FILE_PATH")]
pub override_storage_slots: Option<String>,

#[clap(long)]
pub experimental_new_encoding: bool,
}
3 changes: 3 additions & 0 deletions forc-plugins/forc-client/src/cmd/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,7 @@ pub struct Command {
/// Arguments to pass into main function with forc run.
#[clap(long)]
pub args: Option<Vec<String>>,

#[clap(long)]
pub experimental_new_encoding: bool,
}
5 changes: 4 additions & 1 deletion forc-plugins/forc-client/src/op/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use fuel_tx::{Output, Salt, TransactionBuilder};
use fuel_vm::prelude::*;
use fuels_accounts::provider::Provider;
use futures::FutureExt;
use pkg::BuiltPackage;
use pkg::{manifest::ExperimentalFlags, BuiltPackage};
use serde::{Deserialize, Serialize};
use std::time::Duration;
use std::{
Expand Down Expand Up @@ -348,6 +348,9 @@ fn build_opts_from_cmd(cmd: &cmd::Deploy) -> pkg::BuildOpts {
build_target: BuildTarget::default(),
tests: false,
member_filter: pkg::MemberFilter::only_contracts(),
experimental: ExperimentalFlags {
new_encoding: cmd.experimental_new_encoding,
},
}
}

Expand Down
5 changes: 4 additions & 1 deletion forc-plugins/forc-client/src/op/run/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use forc_util::tx_utils::format_log_receipts;
use fuel_core_client::client::FuelClient;
use fuel_tx::{ContractId, Transaction, TransactionBuilder};
use fuels_accounts::provider::Provider;
use pkg::BuiltPackage;
use pkg::{manifest::ExperimentalFlags, BuiltPackage};
use std::time::Duration;
use std::{path::PathBuf, str::FromStr};
use sway_core::language::parsed::TreeType;
Expand Down Expand Up @@ -231,5 +231,8 @@ fn build_opts_from_cmd(cmd: &cmd::Run) -> pkg::BuildOpts {
debug_outfile: cmd.build_output.debug_file.clone(),
tests: false,
member_filter: pkg::MemberFilter::only_scripts(),
experimental: ExperimentalFlags {
new_encoding: cmd.experimental_new_encoding,
},
}
}
6 changes: 5 additions & 1 deletion forc-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use forc_pkg as pkg;
use fuel_abi_types::error_codes::ErrorSignal;
use fuel_tx as tx;
use fuel_vm::checked_transaction::builder::TransactionBuilderExt;
use fuel_vm::{self as vm};
use fuel_vm::{self as vm, fuel_asm, prelude::Instruction};
use pkg::manifest::ExperimentalFlags;
use pkg::TestPassCondition;
use pkg::{Built, BuiltPackage};
use rand::{Rng, SeedableRng};
Expand Down Expand Up @@ -147,6 +148,8 @@ pub struct Opts {
pub time_phases: bool,
/// Output compilation metrics into file.
pub metrics_outfile: Option<String>,
/// Set of experimental flags
pub experimental: ExperimentalFlags,
}

/// The set of options provided for controlling logs printed for each test.
Expand Down Expand Up @@ -405,6 +408,7 @@ impl Opts {
metrics_outfile: self.metrics_outfile,
tests: true,
member_filter: Default::default(),
experimental: self.experimental,
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions forc/src/cli/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ pub struct Command {
/// Also build all tests within the project.
#[clap(long)]
pub tests: bool,

#[clap(long)]
/// Experimental flags for the "new encoding" feature
pub experimental_new_encoding: bool,
}

pub(crate) fn exec(command: Command) -> ForcResult<()> {
Expand Down
4 changes: 4 additions & 0 deletions forc/src/cli/commands/contract_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ pub struct Command {
pub build_profile: BuildProfile,
#[clap(flatten)]
pub salt: Salt,

#[clap(long)]
/// Experimental flags for the "new encoding" feature
pub experimental_new_encoding: bool,
}

pub(crate) fn exec(cmd: Command) -> ForcResult<()> {
Expand Down
4 changes: 4 additions & 0 deletions forc/src/cli/commands/predicate_root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ pub struct Command {
pub build_output: BuildOutput,
#[clap(flatten)]
pub build_profile: BuildProfile,

#[clap(long)]
/// Experimental flags for the "new encoding" feature
pub experimental_new_encoding: bool,
}

pub(crate) fn exec(cmd: Command) -> ForcResult<()> {
Expand Down
8 changes: 8 additions & 0 deletions forc/src/cli/commands/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use clap::Parser;
use forc_pkg as pkg;
use forc_test::{TestFilter, TestRunnerCount, TestedPackage};
use forc_util::{tx_utils::format_log_receipts, ForcError, ForcResult};
use pkg::manifest::ExperimentalFlags;
use tracing::info;

/// Run the Sway unit tests for the current project.
Expand Down Expand Up @@ -38,6 +39,10 @@ pub struct Command {
/// Number of threads to utilize when running the tests. By default, this is the number of
/// threads available in your system.
pub test_threads: Option<usize>,

#[clap(long)]
/// Experimental flags for the "new encoding" feature
pub experimental_new_encoding: bool,
}

/// The set of options provided for controlling output of a test.
Expand Down Expand Up @@ -215,6 +220,9 @@ fn opts_from_cmd(cmd: Command) -> forc_test::Opts {
binary_outfile: cmd.build.output.bin_file,
debug_outfile: cmd.build.output.debug_file,
build_target: cmd.build.build_target,
experimental: ExperimentalFlags {
new_encoding: cmd.experimental_new_encoding,
},
}
}

Expand Down
4 changes: 4 additions & 0 deletions forc/src/ops/forc_build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::cli::BuildCommand;
use forc_pkg as pkg;
use forc_util::ForcResult;
use pkg::manifest::ExperimentalFlags;

pub fn build(cmd: BuildCommand) -> ForcResult<pkg::Built> {
let opts = opts_from_cmd(cmd);
Expand Down Expand Up @@ -42,5 +43,8 @@ fn opts_from_cmd(cmd: BuildCommand) -> pkg::BuildOpts {
build_target: cmd.build.build_target,
tests: cmd.tests,
member_filter: Default::default(),
experimental: ExperimentalFlags {
new_encoding: cmd.experimental_new_encoding,
},
}
}
4 changes: 4 additions & 0 deletions forc/src/ops/forc_contract_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::cli::ContractIdCommand;
use anyhow::{bail, Result};
use forc_pkg::{self as pkg, build_with_options};
use forc_tracing::println_green;
use pkg::manifest::ExperimentalFlags;
use sway_core::{fuel_prelude::fuel_tx, BuildTarget};
use tracing::info;

Expand Down Expand Up @@ -78,5 +79,8 @@ fn build_opts_from_cmd(cmd: &ContractIdCommand) -> pkg::BuildOpts {
build_target: BuildTarget::default(),
tests: false,
member_filter: pkg::MemberFilter::only_contracts(),
experimental: ExperimentalFlags {
new_encoding: cmd.experimental_new_encoding,
},
}
}
4 changes: 4 additions & 0 deletions forc/src/ops/forc_predicate_root.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::cli::PredicateRootCommand;
use anyhow::Result;
use forc_pkg::{self as pkg, build_with_options};
use pkg::manifest::ExperimentalFlags;
use sway_core::BuildTarget;

pub fn predicate_root(command: PredicateRootCommand) -> Result<()> {
Expand Down Expand Up @@ -46,5 +47,8 @@ fn build_opts_from_cmd(cmd: PredicateRootCommand) -> pkg::BuildOpts {
build_target: BuildTarget::default(),
tests: false,
member_filter: pkg::MemberFilter::only_predicates(),
experimental: ExperimentalFlags {
new_encoding: cmd.experimental_new_encoding,
},
}
}
30 changes: 22 additions & 8 deletions sway-core/src/build_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub struct BuildConfig {
pub(crate) include_tests: bool,
pub time_phases: bool,
pub metrics_outfile: Option<String>,
pub experimental: ExperimentalFlags,
}

impl BuildConfig {
Expand Down Expand Up @@ -92,52 +93,53 @@ impl BuildConfig {
include_tests: false,
time_phases: false,
metrics_outfile: None,
experimental: ExperimentalFlags::default(),
}
}

pub fn print_dca_graph(self, a: Option<String>) -> Self {
pub fn with_print_dca_graph(self, a: Option<String>) -> Self {
Self {
print_dca_graph: a,
..self
}
}

pub fn print_dca_graph_url_format(self, a: Option<String>) -> Self {
pub fn with_print_dca_graph_url_format(self, a: Option<String>) -> Self {
Self {
print_dca_graph_url_format: a,
..self
}
}

pub fn print_intermediate_asm(self, a: bool) -> Self {
pub fn with_print_intermediate_asm(self, a: bool) -> Self {
Self {
print_intermediate_asm: a,
..self
}
}

pub fn print_finalized_asm(self, a: bool) -> Self {
pub fn with_print_finalized_asm(self, a: bool) -> Self {
Self {
print_finalized_asm: a,
..self
}
}

pub fn print_ir(self, a: bool) -> Self {
pub fn with_print_ir(self, a: bool) -> Self {
Self {
print_ir: a,
..self
}
}

pub fn time_phases(self, a: bool) -> Self {
pub fn with_time_phases(self, a: bool) -> Self {
Self {
time_phases: a,
..self
}
}

pub fn metrics(self, a: Option<String>) -> Self {
pub fn with_metrics(self, a: Option<String>) -> Self {
Self {
metrics_outfile: a,
..self
Expand All @@ -149,14 +151,26 @@ impl BuildConfig {
/// This should be set to `true` by invocations like `forc test` or `forc check --tests`.
///
/// Default: `false`
pub fn include_tests(self, include_tests: bool) -> Self {
pub fn with_include_tests(self, include_tests: bool) -> Self {
Self {
include_tests,
..self
}
}

pub fn with_experimental(self, experimental: ExperimentalFlags) -> Self {
Self {
experimental,
..self
}
}

pub fn canonical_root_module(&self) -> Arc<PathBuf> {
self.canonical_root_module.clone()
}
}

#[derive(Debug, Default, Clone, Copy)]
pub struct ExperimentalFlags {
pub new_encoding: bool,
}
Loading

0 comments on commit c42bde1

Please sign in to comment.