Skip to content

Commit

Permalink
Experimental StorageKey feature
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammadfawaz committed Mar 23, 2023
1 parent 31dc809 commit 0fa7196
Show file tree
Hide file tree
Showing 55 changed files with 3,824 additions and 98 deletions.
3 changes: 3 additions & 0 deletions forc-pkg/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ pub struct BuildProfile {
pub include_tests: bool,
pub json_abi_with_callpaths: bool,
pub error_on_warnings: bool,
pub experimental_storage: bool,
}

impl Dependency {
Expand Down Expand Up @@ -602,6 +603,7 @@ impl BuildProfile {
include_tests: false,
json_abi_with_callpaths: false,
error_on_warnings: false,
experimental_storage: false,
}
}

Expand All @@ -617,6 +619,7 @@ impl BuildProfile {
include_tests: false,
json_abi_with_callpaths: false,
error_on_warnings: false,
experimental_storage: false,
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion forc-pkg/src/pkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ pub struct BuildOpts {
pub tests: bool,
/// The set of options to filter by member project kind.
pub member_filter: MemberFilter,
/// Enable the experimental storage implementation and UI.
pub experimental_storage: bool,
}

/// The set of options to filter type of projects to build in a workspace.
Expand Down Expand Up @@ -1510,7 +1512,8 @@ pub fn sway_build_config(
.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);
.include_tests(build_profile.include_tests)
.experimental_storage(build_profile.experimental_storage);
Ok(build_config)
}

Expand Down Expand Up @@ -1952,6 +1955,7 @@ fn build_profile_from_opts(
time_phases,
tests,
error_on_warnings,
experimental_storage,
..
} = build_options;
let mut selected_build_profile = BuildProfile::DEBUG;
Expand Down Expand Up @@ -1997,6 +2001,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_storage |= experimental_storage;

Ok((selected_build_profile.to_string(), profile))
}
Expand Down
1 change: 1 addition & 0 deletions forc-plugins/forc-client/src/op/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,6 @@ fn build_opts_from_cmd(cmd: &cmd::Deploy) -> pkg::BuildOpts {
build_target: BuildTarget::default(),
tests: false,
member_filter: pkg::MemberFilter::only_contracts(),
experimental_storage: cmd.build_profile.experimental_storage,
}
}
1 change: 1 addition & 0 deletions forc-plugins/forc-client/src/op/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,6 @@ 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_storage: cmd.build_profile.experimental_storage,
}
}
3 changes: 3 additions & 0 deletions forc-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ pub struct Opts {
pub error_on_warnings: bool,
/// Output the time elapsed over each part of the compilation process.
pub time_phases: bool,
/// Enable the experimental storage implementation and UI.
pub experimental_storage: bool,
}

/// The set of options provided for controlling logs printed for each test.
Expand Down Expand Up @@ -360,6 +362,7 @@ impl Opts {
time_phases: self.time_phases,
tests: true,
member_filter: Default::default(),
experimental_storage: self.experimental_storage,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions forc/src/cli/commands/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,5 +180,6 @@ 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_storage: cmd.build.profile.experimental_storage,
}
}
3 changes: 3 additions & 0 deletions forc/src/cli/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ pub struct BuildProfile {
/// Treat warnings as errors.
#[clap(long)]
pub error_on_warnings: bool,
/// Enable the experimental storage implementation and UI.
#[clap(long)]
pub experimental_storage: bool,
}

/// Options related to printing stages of compiler output.
Expand Down
1 change: 1 addition & 0 deletions forc/src/ops/forc_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ fn opts_from_cmd(cmd: BuildCommand) -> pkg::BuildOpts {
build_target: cmd.build.build_target,
tests: cmd.tests,
member_filter: Default::default(),
experimental_storage: cmd.build.profile.experimental_storage,
}
}
1 change: 1 addition & 0 deletions sway-ast/src/item/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ pub enum FnArgs {
self_token: SelfToken,
ref_self: Option<RefToken>,
mutable_self: Option<MutToken>,
ty: Option<(ColonToken, Ty)>,
args_opt: Option<(CommaToken, Punctuated<FnArg, CommaToken>)>,
},
}
Expand Down
9 changes: 9 additions & 0 deletions sway-core/src/build_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub struct BuildConfig {
pub(crate) print_finalized_asm: bool,
pub(crate) print_ir: bool,
pub(crate) include_tests: bool,
pub(crate) experimental_storage: bool,
}

impl BuildConfig {
Expand Down Expand Up @@ -86,6 +87,7 @@ impl BuildConfig {
print_finalized_asm: false,
print_ir: false,
include_tests: false,
experimental_storage: false,
}
}

Expand Down Expand Up @@ -117,6 +119,13 @@ impl BuildConfig {
}
}

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

/// Whether or not to include test functions in parsing, type-checking and codegen.
///
/// This should be set to `true` by invocations like `forc test` or `forc check --tests`.
Expand Down
5 changes: 5 additions & 0 deletions sway-core/src/ir_generation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub fn compile_program(
program: &ty::TyProgram,
include_tests: bool,
engines: Engines<'_>,
experimental_storage: bool,
) -> Result<Context, CompileError> {
let declaration_engine = engines.de();

Expand Down Expand Up @@ -59,6 +60,7 @@ pub fn compile_program(
&logged_types,
&messages_types,
&test_fns,
experimental_storage,
),
ty::TyProgramKind::Predicate { main_function } => compile::compile_predicate(
engines,
Expand All @@ -69,6 +71,7 @@ pub fn compile_program(
&logged_types,
&messages_types,
&test_fns,
experimental_storage,
),
ty::TyProgramKind::Contract { abi_entries } => compile::compile_contract(
&mut ctx,
Expand All @@ -79,6 +82,7 @@ pub fn compile_program(
&messages_types,
&test_fns,
engines,
experimental_storage,
),
ty::TyProgramKind::Library { .. } => compile::compile_library(
engines,
Expand All @@ -88,6 +92,7 @@ pub fn compile_program(
&logged_types,
&messages_types,
&test_fns,
experimental_storage,
),
}?;
ctx.verify()
Expand Down
24 changes: 24 additions & 0 deletions sway-core/src/ir_generation/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub(super) fn compile_script(
logged_types_map: &HashMap<TypeId, LogId>,
messages_types_map: &HashMap<TypeId, MessageId>,
test_fns: &[(ty::TyFunctionDecl, DeclRefFunction)],
experimental_storage: bool,
) -> Result<Module, CompileError> {
let module = Module::new(context, Kind::Script);
let mut md_mgr = MetadataManager::default();
Expand All @@ -52,6 +53,7 @@ pub(super) fn compile_script(
logged_types_map,
messages_types_map,
None,
experimental_storage,
)?;
compile_tests(
engines,
Expand All @@ -61,6 +63,7 @@ pub(super) fn compile_script(
logged_types_map,
messages_types_map,
test_fns,
experimental_storage,
)?;

Ok(module)
Expand All @@ -76,6 +79,7 @@ pub(super) fn compile_predicate(
logged_types: &HashMap<TypeId, LogId>,
messages_types: &HashMap<TypeId, MessageId>,
test_fns: &[(ty::TyFunctionDecl, DeclRefFunction)],
experimental_storage: bool,
) -> Result<Module, CompileError> {
let module = Module::new(context, Kind::Predicate);
let mut md_mgr = MetadataManager::default();
Expand All @@ -98,6 +102,7 @@ pub(super) fn compile_predicate(
&HashMap::new(),
&HashMap::new(),
None,
experimental_storage,
)?;
compile_tests(
engines,
Expand All @@ -107,6 +112,7 @@ pub(super) fn compile_predicate(
logged_types,
messages_types,
test_fns,
experimental_storage,
)?;

Ok(module)
Expand All @@ -122,6 +128,7 @@ pub(super) fn compile_contract(
messages_types_map: &HashMap<TypeId, MessageId>,
test_fns: &[(ty::TyFunctionDecl, DeclRefFunction)],
engines: Engines<'_>,
experimental_storage: bool,
) -> Result<Module, CompileError> {
let module = Module::new(context, Kind::Contract);
let mut md_mgr = MetadataManager::default();
Expand All @@ -144,6 +151,7 @@ pub(super) fn compile_contract(
logged_types_map,
messages_types_map,
engines,
experimental_storage,
)?;
}
compile_tests(
Expand All @@ -154,11 +162,13 @@ pub(super) fn compile_contract(
logged_types_map,
messages_types_map,
test_fns,
experimental_storage,
)?;

Ok(module)
}

#[allow(clippy::too_many_arguments)]
pub(super) fn compile_library(
engines: Engines<'_>,
context: &mut Context,
Expand All @@ -167,6 +177,7 @@ pub(super) fn compile_library(
logged_types_map: &HashMap<TypeId, LogId>,
messages_types_map: &HashMap<TypeId, MessageId>,
test_fns: &[(ty::TyFunctionDecl, DeclRefFunction)],
experimental_storage: bool,
) -> Result<Module, CompileError> {
let module = Module::new(context, Kind::Library);
let mut md_mgr = MetadataManager::default();
Expand All @@ -188,6 +199,7 @@ pub(super) fn compile_library(
logged_types_map,
messages_types_map,
test_fns,
experimental_storage,
)?;

Ok(module)
Expand Down Expand Up @@ -307,6 +319,7 @@ pub(super) fn compile_function(
messages_types_map: &HashMap<TypeId, MessageId>,
is_entry: bool,
test_decl_ref: Option<DeclRefFunction>,
experimental_storage: bool,
) -> Result<Option<Function>, CompileError> {
let type_engine = engines.te();
let decl_engine = engines.de();
Expand All @@ -333,6 +346,7 @@ pub(super) fn compile_function(
logged_types_map,
messages_types_map,
test_decl_ref,
experimental_storage,
)
.map(Some)
}
Expand All @@ -348,6 +362,7 @@ pub(super) fn compile_entry_function(
logged_types_map: &HashMap<TypeId, LogId>,
messages_types_map: &HashMap<TypeId, MessageId>,
test_decl_ref: Option<DeclRefFunction>,
experimental_storage: bool,
) -> Result<Function, CompileError> {
let is_entry = true;
compile_function(
Expand All @@ -360,10 +375,12 @@ pub(super) fn compile_entry_function(
messages_types_map,
is_entry,
test_decl_ref,
experimental_storage,
)
.map(|f| f.expect("entry point should never contain generics"))
}

#[allow(clippy::too_many_arguments)]
pub(super) fn compile_tests(
engines: Engines<'_>,
context: &mut Context,
Expand All @@ -372,6 +389,7 @@ pub(super) fn compile_tests(
logged_types_map: &HashMap<TypeId, LogId>,
messages_types_map: &HashMap<TypeId, MessageId>,
test_fns: &[(ty::TyFunctionDecl, DeclRefFunction)],
experimental_storage: bool,
) -> Result<Vec<Function>, CompileError> {
test_fns
.iter()
Expand All @@ -385,6 +403,7 @@ pub(super) fn compile_tests(
logged_types_map,
messages_types_map,
Some(decl_ref.clone()),
experimental_storage,
)
})
.collect()
Expand Down Expand Up @@ -423,6 +442,7 @@ fn compile_fn_with_args(
logged_types_map: &HashMap<TypeId, LogId>,
messages_types_map: &HashMap<TypeId, MessageId>,
test_decl_ref: Option<DeclRefFunction>,
experimental_storage: bool,
) -> Result<Function, CompileError> {
let type_engine = engines.te();
let decl_engine = engines.de();
Expand Down Expand Up @@ -496,6 +516,7 @@ fn compile_fn_with_args(
returns_by_ref,
logged_types_map,
messages_types_map,
experimental_storage,
);
let mut ret_val = compiler.compile_code_block(context, md_mgr, body)?;

Expand Down Expand Up @@ -566,6 +587,7 @@ fn compile_impl(
}
*/

#[allow(clippy::too_many_arguments)]
fn compile_abi_method(
context: &mut Context,
md_mgr: &mut MetadataManager,
Expand All @@ -574,6 +596,7 @@ fn compile_abi_method(
logged_types_map: &HashMap<TypeId, LogId>,
messages_types_map: &HashMap<TypeId, MessageId>,
engines: Engines<'_>,
experimental_storage: bool,
) -> Result<Function, CompileError> {
let type_engine = engines.te();
let decl_engine = engines.de();
Expand Down Expand Up @@ -629,5 +652,6 @@ fn compile_abi_method(
logged_types_map,
messages_types_map,
None,
experimental_storage,
)
}
Loading

0 comments on commit 0fa7196

Please sign in to comment.