Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for auto impl of AbiEncode; encoding version and better tests #5481

Merged
merged 10 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 15 additions & 33 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ fuels-accounts = "0.54.0"
# Dependencies from the `forc-wallet` repository:
forc-wallet = "0.4.2"

# Dependencies from the `fuel-abi-types` repository:
fuel-abi-types = "0.4.0"

[workspace.package]
edition = "2021"
authors = ["Fuel Labs <contact@fuel.sh>"]
Expand Down
2 changes: 1 addition & 1 deletion forc-pkg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ anyhow = "1"
cid = "0.10"
forc-tracing = { version = "0.49.1", path = "../forc-tracing" }
forc-util = { version = "0.49.1", path = "../forc-util" }
fuel-abi-types = "0.1"
fuel-abi-types = { workspace = true }
futures = "0.3"
git2 = { version = "0.17.2", features = [
"vendored-libgit2",
Expand Down
10 changes: 8 additions & 2 deletions forc-pkg/src/pkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use forc_util::{
default_output_directory, find_file_name, kebab_to_snake_case, print_compiling,
print_on_failure, print_warnings,
};
use fuel_abi_types::program_abi;
use fuel_abi_types::abi::program as program_abi;
use petgraph::{
self, dot,
visit::{Bfs, Dfs, EdgeRef, Walker},
Expand Down Expand Up @@ -1821,6 +1821,8 @@ pub fn compile(
metrics
);

const NEW_ENCODING_VERSION: &str = "1";

let mut program_abi = match pkg.target {
BuildTarget::Fuel => {
let mut types = vec![];
Expand All @@ -1834,7 +1836,11 @@ pub fn compile(
},
engines.te(),
engines.de(),
&mut types
&mut types,
profile
.experimental
.new_encoding
.then(|| NEW_ENCODING_VERSION.into()),
),
Some(sway_build_config.clone()),
metrics
Expand Down
2 changes: 1 addition & 1 deletion forc-plugins/forc-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ forc-tracing = { version = "0.49.1", path = "../../forc-tracing" }
forc-tx = { version = "0.49.1", path = "../forc-tx" }
forc-util = { version = "0.49.1", path = "../../forc-util" }
forc-wallet = { workspace = true }
fuel-abi-types = "0.3"
fuel-abi-types = { workspace = true }
fuel-core-client = { workspace = true, features = ["subscriptions"] }
fuel-crypto = { workspace = true }
fuel-tx = { workspace = true, features = ["builder"] }
Expand Down
2 changes: 1 addition & 1 deletion forc-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repository.workspace = true
[dependencies]
anyhow = "1"
forc-pkg = { version = "0.49.1", path = "../forc-pkg" }
fuel-abi-types = "0.2"
fuel-abi-types = { workspace = true }
fuel-tx = { workspace = true, features = ["builder"] }
fuel-vm = { workspace = true, features = ["random"] }
rand = "0.8"
Expand Down
2 changes: 1 addition & 1 deletion forc/src/cli/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub struct Command {
pub tests: bool,

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

Expand Down
2 changes: 1 addition & 1 deletion forc/src/cli/commands/contract_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub struct Command {
pub salt: Salt,

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

Expand Down
2 changes: 1 addition & 1 deletion forc/src/cli/commands/predicate_root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct Command {
pub build_profile: BuildProfile,

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

Expand Down
2 changes: 1 addition & 1 deletion forc/src/cli/commands/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub struct Command {
pub test_threads: Option<usize>,

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

Expand Down
2 changes: 1 addition & 1 deletion sway-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ etk-asm = { package = "fuel-etk-asm", version = "0.3.1-dev", features = [
] }
etk-dasm = { package = "fuel-etk-dasm", version = "0.3.1-dev" }
etk-ops = { package = "fuel-etk-ops", version = "0.3.1-dev" }
fuel-abi-types = "0.1"
fuel-abi-types = { workspace = true }
fuel-vm = { workspace = true, features = ["serde"] }
graph-cycles = "0.1.0"
hashbrown = "0.13.1"
Expand Down
6 changes: 5 additions & 1 deletion sway-core/src/abi_generation/fuel_abi.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use fuel_abi_types::program_abi;
use fuel_abi_types::abi::program as program_abi;
use sway_types::integer_bits::IntegerBits;

use crate::{
Expand All @@ -21,6 +21,7 @@ pub fn generate_program_abi(
type_engine: &TypeEngine,
decl_engine: &DeclEngine,
types: &mut Vec<program_abi::TypeDeclaration>,
encoding: Option<program_abi::Version>,
) -> program_abi::ProgramABI {
match &ctx.program.kind {
TyProgramKind::Contract { abi_entries, .. } => {
Expand All @@ -35,6 +36,7 @@ pub fn generate_program_abi(
let messages_types = generate_messages_types(ctx, type_engine, decl_engine, types);
let configurables = generate_configurables(ctx, type_engine, decl_engine, types);
program_abi::ProgramABI {
encoding,
types: types.to_vec(),
functions,
logged_types: Some(logged_types),
Expand All @@ -51,6 +53,7 @@ pub fn generate_program_abi(
let messages_types = generate_messages_types(ctx, type_engine, decl_engine, types);
let configurables = generate_configurables(ctx, type_engine, decl_engine, types);
program_abi::ProgramABI {
encoding,
types: types.to_vec(),
functions,
logged_types: Some(logged_types),
Expand All @@ -59,6 +62,7 @@ pub fn generate_program_abi(
}
}
_ => program_abi::ProgramABI {
encoding,
types: vec![],
functions: vec![],
logged_types: None,
Expand Down
2 changes: 1 addition & 1 deletion sway-core/src/asm_generation/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::EvmAbiResult;

#[derive(Clone, Debug)]
pub enum ProgramABI {
Fuel(fuel_abi_types::program_abi::ProgramABI),
Fuel(fuel_abi_types::abi::program::ProgramABI),
Evm(EvmAbiResult),
MidenVM(()),
}
11 changes: 3 additions & 8 deletions sway-core/src/semantic_analysis/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,9 @@ impl TyProgram {
build_config: Option<&BuildConfig>,
) -> Result<Self, ErrorEmitted> {
let mut namespace = Namespace::init_root(initial_namespace);
let ctx =
TypeCheckContext::from_root(&mut namespace, engines).with_kind(parsed.kind.clone());

let ctx = if let Some(build_config) = build_config {
ctx.with_experimental_flags(build_config.experimental)
} else {
ctx
};
let ctx = TypeCheckContext::from_root(&mut namespace, engines)
.with_kind(parsed.kind.clone())
.with_experimental_flags(build_config.map(|x| x.experimental));

let ParseProgram { root, kind } = parsed;

Expand Down
6 changes: 5 additions & 1 deletion sway-core/src/semantic_analysis/type_check_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1538,7 +1538,11 @@ impl<'a> TypeCheckContext<'a> {
.insert_for_type(self.engines, type_id);
}

pub(crate) fn with_experimental_flags(self, experimental: ExperimentalFlags) -> Self {
pub(crate) fn with_experimental_flags(self, experimental: Option<ExperimentalFlags>) -> Self {
let Some(experimental) = experimental else {
return self;
};

Self {
experimental,
..self
Expand Down
4 changes: 3 additions & 1 deletion sway-core/src/transform/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
use sway_ast::Literal;
use sway_types::{
constants::{
ALLOW_DEAD_CODE_NAME, ALLOW_DEPRECATED_NAME, CFG_PROGRAM_TYPE_ARG_NAME, CFG_TARGET_ARG_NAME,
ALLOW_DEAD_CODE_NAME, ALLOW_DEPRECATED_NAME, CFG_EXPERIMENTAL_NEW_ENCODING,
CFG_PROGRAM_TYPE_ARG_NAME, CFG_TARGET_ARG_NAME,
},
Ident, Span, Spanned,
};
Expand Down Expand Up @@ -100,6 +101,7 @@ impl AttributeKind {
AttributeKind::Cfg => Some(vec![
CFG_TARGET_ARG_NAME.to_string(),
CFG_PROGRAM_TYPE_ARG_NAME.to_string(),
CFG_EXPERIMENTAL_NEW_ENCODING.to_string(),
]),
AttributeKind::Deprecated => None,
}
Expand Down
Loading
Loading