Skip to content

Commit

Permalink
New encoding for contract calls (#5427)
Browse files Browse the repository at this point in the history
## Description

This PR implements the new encoding for contracts/scripts/predicates.
#5512 and
#5513

### Contract Calls

When the new encoding is turned on using `--experimental-new-encoding`,
contract calls like the example below will be "desugarized" differently
now.

```sway
let base_asset_id = BASE_ASSET_ID;
let other_contract_id = ContractId::from(0xa38576787f8900d66e6620548b6da8142b8bb4d129b2338609acd121ca126c10);

let test_contract = abi(ContextTesting, other_contract_id.into());
let returned_contract_id = test_contract.get_id { gas: gas, coins: 0, asset_id: BASE_ASSET_ID.value}(1, 2, 3);
```

and will be transformed to

```sway
let base_asset_id = BASE_ASSET_ID;
let other_contract_id = ContractId::from(0xa38576787f8900d66e6620548b6da8142b8bb4d129b2338609acd121ca126c10);

let test_contract = abi(ContextTesting, other_contract_id.into());
let returned_contract_id = contract_call::<ContractId, _>(other_contract_id.into(), "get_id", (1, 2, 3), coins, asset_id, gas);
```

And the important part is the `contract_call` function in the std
library. This function does all the encoding as necessary and delegates
the actual call to an intrinsic function `__contract_call`. Allowing the
protocol to evolve entirely in Sway.

```sway
pub fn contract_call<T, TArgs>(contract_id: b256, method_name: str, args: TArgs, coins: u64, asset_id: b256, gas: u64) -> T
where
    TArgs: AbiEncode
{
    let first_parameter = encode(method_name);
    let second_parameter = encode(args);
    let params = encode(
        (
            contract_id,
            asm(a: first_parameter.ptr()) { a: u64 },
            asm(a: second_parameter.ptr()) { a: u64 },
        )
    );
    __contract_call::<T>(params.ptr(), coins, asset_id, gas)
}
```

### Contracts

On the other side, when the flag `--expiremental-new-encoding` is turned
on, the contract specification like the one below is being transformed
into all the decoding and encoding necessary.

The mains points are:

- The compiler generates a function called `__entry` that decodes the
method name and its arguments. The method is selected with a bunch of
`if`s at the moment, because we don´t have `match` for string slices.
Then we `decode` the arguments using the correct type, which is a tuple
with all the function arguments, and expand this tuple calling the
function;
- All the contract functions are converted to global functions prefixed
with `__contract_method`;
- Results are encoded and returned using the intrinsic call `__retd`.

Example:

```sway
abi SomeContract {
    fn some_function(a: u64) -> u64;
}

impl SomeContract for Contract {
    fn some_function(a: u64) -> u64 {
        1
    }
}
```

will be transformed into 

```sway
fn __entry() {
    let method_name = decode_first_parameter();
    if method_name == "some_function" {
        let args = decode_second_parameter::<(u64,)>();
        let result = __contract_method_some_function(args.0);
        __retd(encode(result));
    }
    __revert(0);
}
```

### Scripts and Predicates

The protocol to call scripts and predicates will also change and will be
very similar to contracts. See more above. Now when the flag is turned
on, the `main` function will not be entry point anymore. The compiler
will actually generate an `__entry` function that will decode arguments
and encode the result, like contracts.

For example:

```sway
fn main(a: u64) -> u64 {
    1
}
```

will be transformed into

```sway
fn __entry() {
    let args = decode_script_data::<(u64,)();
    let result = main(args.0);
    __retd(encode(result));
}

fn main(a: u64) -> u64 {
    1
}
```

## Tests

To facilitate testing this PR introduces three changes to our test
harness:

1 - A new parameter can be called to update test output files (abi and
storage json). This facilitates when we only want to copy and paste
these output files to their respective oracles. Brings the framework
closer to a snapshot one.

``` 
> cargo r -p test --release -- --update-output-files
```

2 - Depending on the configuration at `test.toml` multiple executions of
the same test will be scheduled. At the moment, tests that depend on the
encoding will run with the `--experimental-new-encoding` flag
automatically. For example:

```
Testing should_pass/language/main_args/main_args_copy_copy ... ok
Testing should_pass/language/main_args/main_args_copy_copy (New Encoding) ... ok
```

3 - A new `script_data_new_encoding` was created because we want to
support and run tests with the two encoding for a time. This is also
what flags tests to run with the flag on automatically.

## Checklist

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
  • Loading branch information
xunilrj committed Mar 6, 2024
1 parent c393984 commit c24d731
Show file tree
Hide file tree
Showing 142 changed files with 5,584 additions and 1,439 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

30 changes: 27 additions & 3 deletions forc-pkg/src/pkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1594,12 +1594,18 @@ pub fn dependency_namespace(
node: NodeIx,
engines: &Engines,
contract_id_value: Option<ContractIdConst>,
experimental: sway_core::ExperimentalFlags,
) -> Result<namespace::Module, vec1::Vec1<CompileError>> {
// TODO: Clean this up when config-time constants v1 are removed.
let node_idx = &graph[node];
let name = Some(Ident::new_no_span(node_idx.name.clone()));
let mut namespace = if let Some(contract_id_value) = contract_id_value {
namespace::Module::default_with_contract_id(engines, name.clone(), contract_id_value)?
namespace::Module::default_with_contract_id(
engines,
name.clone(),
contract_id_value,
experimental,
)?
} else {
namespace::Module::default()
};
Expand Down Expand Up @@ -1633,6 +1639,7 @@ pub fn dependency_namespace(
engines,
name.clone(),
contract_id_value,
experimental,
)?;
ns.is_external = true;
ns.name = name;
Expand Down Expand Up @@ -2087,7 +2094,9 @@ 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();
profile.experimental = ExperimentalFlags {
new_encoding: experimental.new_encoding,
};

Ok(profile)
}
Expand Down Expand Up @@ -2119,6 +2128,7 @@ pub fn build_with_options(build_options: BuildOpts) -> Result<Built> {
pkg,
build_target,
member_filter,
experimental,
..
} = &build_options;

Expand Down Expand Up @@ -2158,7 +2168,15 @@ pub fn build_with_options(build_options: BuildOpts) -> Result<Built> {
// Build it!
let mut built_workspace = Vec::new();
let build_start = std::time::Instant::now();
let built_packages = build(&build_plan, *build_target, &build_profile, &outputs)?;
let built_packages = build(
&build_plan,
*build_target,
&build_profile,
&outputs,
sway_core::ExperimentalFlags {
new_encoding: experimental.new_encoding,
},
)?;
let output_dir = pkg.output_directory.as_ref().map(PathBuf::from);

let finished = ansi_term::Colour::Green.bold().paint("Finished");
Expand Down Expand Up @@ -2261,6 +2279,7 @@ pub fn build(
target: BuildTarget,
profile: &BuildProfile,
outputs: &HashSet<NodeIx>,
experimental: sway_core::ExperimentalFlags,
) -> anyhow::Result<Vec<(NodeIx, BuiltPackage)>> {
let mut built_packages = Vec::new();

Expand Down Expand Up @@ -2339,6 +2358,7 @@ pub fn build(
node,
&engines,
None,
experimental,
) {
Ok(o) => o,
Err(errs) => return fail(&[], &errs),
Expand Down Expand Up @@ -2402,6 +2422,7 @@ pub fn build(
node,
&engines,
contract_id_value.clone(),
experimental,
) {
Ok(o) => o,
Err(errs) => {
Expand Down Expand Up @@ -2595,6 +2616,7 @@ fn update_json_type_declaration(
/// Compile the entire forc package and return the lexed, parsed and typed programs
/// of the dependencies and project.
/// The final item in the returned vector is the project.
#[allow(clippy::too_many_arguments)]
pub fn check(
plan: &BuildPlan,
build_target: BuildTarget,
Expand All @@ -2603,6 +2625,7 @@ pub fn check(
include_tests: bool,
engines: &Engines,
retrigger_compilation: Option<Arc<AtomicBool>>,
experimental: sway_core::ExperimentalFlags,
) -> anyhow::Result<Vec<(Option<Programs>, Handler)>> {
let mut lib_namespace_map = Default::default();
let mut source_map = SourceMap::new();
Expand Down Expand Up @@ -2633,6 +2656,7 @@ pub fn check(
node,
engines,
contract_id_value,
experimental,
)
.expect("failed to create dependency namespace");

Expand Down
5 changes: 5 additions & 0 deletions forc-plugins/forc-debug/src/server/handlers/handle_launch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ impl DapServer {
}
}

let experimental = sway_core::ExperimentalFlags {
new_encoding: false,
};

// 1. Build the packages
let manifest_file = forc_pkg::manifest::ManifestFile::from_dir(&self.state.program_path)
.map_err(|err| AdapterError::BuildFailed {
Expand Down Expand Up @@ -105,6 +109,7 @@ impl DapServer {
..Default::default()
},
&outputs,
experimental,
)
.map_err(|err| AdapterError::BuildFailed {
reason: format!("build packages: {:?}", err),
Expand Down
3 changes: 3 additions & 0 deletions forc-plugins/forc-doc/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,7 @@ pub struct Command {

#[cfg(test)]
pub(crate) doc_path: Option<String>,

#[clap(long)]
pub experimental_new_encoding: bool,
}
10 changes: 9 additions & 1 deletion forc-plugins/forc-doc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,13 @@ struct ProgramInfo<'a> {
pub fn main() -> Result<()> {
let build_instructions = Command::parse();

let (doc_path, pkg_manifest) = compile_html(&build_instructions, &get_doc_dir)?;
let (doc_path, pkg_manifest) = compile_html(
&build_instructions,
&get_doc_dir,
sway_core::ExperimentalFlags {
new_encoding: build_instructions.experimental_new_encoding,
},
)?;

// CSS, icons and logos
static ASSETS_DIR: Dir<'_> = include_dir!("$CARGO_MANIFEST_DIR/src/static.files");
Expand Down Expand Up @@ -169,6 +175,7 @@ fn write_content(rendered_docs: RenderedDocumentation, doc_path: &Path) -> Resul
pub fn compile_html(
build_instructions: &Command,
get_doc_dir: &dyn Fn(&Command) -> String,
experimental: sway_core::ExperimentalFlags,
) -> Result<(PathBuf, Box<PackageManifestFile>)> {
// get manifest directory
let dir = if let Some(ref path) = build_instructions.manifest_path {
Expand Down Expand Up @@ -221,6 +228,7 @@ pub fn compile_html(
tests_enabled,
&engines,
None,
experimental,
)?;

let raw_docs = if !build_instructions.no_deps {
Expand Down
29 changes: 26 additions & 3 deletions forc-plugins/forc-doc/src/tests/expects/impl_trait/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::{
collections::HashSet,
path::{Path, PathBuf},
};
use sway_core::ExperimentalFlags;

/// The path to the generated HTML of the type the traits are implemented on.
const IMPL_FOR: &str = "bar/struct.Bar.html";
Expand All @@ -25,7 +26,14 @@ fn test_impl_traits_default() {
doc_path: Some(doc_dir_name.into()),
..Default::default()
};
let (doc_path, _) = compile_html(&command, &get_doc_dir).unwrap();
let (doc_path, _) = compile_html(
&command,
&get_doc_dir,
ExperimentalFlags {
new_encoding: false,
},
)
.unwrap();
assert_index_html(
&doc_path,
project_name,
Expand All @@ -37,19 +45,27 @@ fn test_impl_traits_default() {
assert_search_js(
&doc_path,
&expect![[r#"
var SEARCH_INDEX={"core":[{"html_filename":"trait.AsRawSlice.html","module_info":["core","raw_slice"],"name":"AsRawSlice","preview":"Trait to return a type as a <code>raw_slice</code>.\n","type_name":"trait"},{"html_filename":"fn.from_str_array.html","module_info":["core","str"],"name":"from_str_array","preview":"","type_name":"function"},{"html_filename":"trait.Add.html","module_info":["core","ops"],"name":"Add","preview":"Trait for the addition of two values.\n","type_name":"trait"},{"html_filename":"trait.Subtract.html","module_info":["core","ops"],"name":"Subtract","preview":"Trait for the subtraction of two values.\n","type_name":"trait"},{"html_filename":"trait.Multiply.html","module_info":["core","ops"],"name":"Multiply","preview":"Trait for the multiplication of two values.\n","type_name":"trait"},{"html_filename":"trait.Divide.html","module_info":["core","ops"],"name":"Divide","preview":"Trait for the division of two values.\n","type_name":"trait"},{"html_filename":"trait.Mod.html","module_info":["core","ops"],"name":"Mod","preview":"Trait for the modulo of two values.\n","type_name":"trait"},{"html_filename":"trait.Not.html","module_info":["core","ops"],"name":"Not","preview":"Trait to invert a type.\n","type_name":"trait"},{"html_filename":"trait.Eq.html","module_info":["core","ops"],"name":"Eq","preview":"Trait to evaluate if two types are equal.\n","type_name":"trait"},{"html_filename":"trait.Ord.html","module_info":["core","ops"],"name":"Ord","preview":"Trait to evaluate if one value is greater or less than another of the same type.\n","type_name":"trait"},{"html_filename":"trait.BitwiseAnd.html","module_info":["core","ops"],"name":"BitwiseAnd","preview":"Trait to bitwise AND two values of the same type.\n","type_name":"trait"},{"html_filename":"trait.BitwiseOr.html","module_info":["core","ops"],"name":"BitwiseOr","preview":"Trait to bitwise OR two values of the same type.\n","type_name":"trait"},{"html_filename":"trait.BitwiseXor.html","module_info":["core","ops"],"name":"BitwiseXor","preview":"Trait to bitwise XOR two values of the same type.\n","type_name":"trait"},{"html_filename":"trait.Shift.html","module_info":["core","ops"],"name":"Shift","preview":"Trait to bit shift a value.\n","type_name":"trait"},{"html_filename":"struct.StorageKey.html","module_info":["core","storage"],"name":"StorageKey","preview":"Describes a location in storage.\n","type_name":"struct"},{"html_filename":"struct.Buffer.html","module_info":["core","codec"],"name":"Buffer","preview":"","type_name":"struct"},{"html_filename":"trait.AbiEncode.html","module_info":["core","codec"],"name":"AbiEncode","preview":"","type_name":"trait"},{"html_filename":"fn.encode.html","module_info":["core","codec"],"name":"encode","preview":"","type_name":"function"}],"impl_traits":[{"html_filename":"trait.Foo.html","module_info":["impl_traits","foo"],"name":"Foo","preview":"","type_name":"trait"},{"html_filename":"trait.Baz.html","module_info":["impl_traits","foo"],"name":"Baz","preview":"","type_name":"trait"},{"html_filename":"struct.Bar.html","module_info":["impl_traits","bar"],"name":"Bar","preview":"","type_name":"struct"}]};
var SEARCH_INDEX={"core":[{"html_filename":"trait.AsRawSlice.html","module_info":["core","raw_slice"],"name":"AsRawSlice","preview":"Trait to return a type as a <code>raw_slice</code>.\n","type_name":"trait"},{"html_filename":"fn.from_str_array.html","module_info":["core","str"],"name":"from_str_array","preview":"","type_name":"function"},{"html_filename":"trait.Add.html","module_info":["core","ops"],"name":"Add","preview":"Trait for the addition of two values.\n","type_name":"trait"},{"html_filename":"trait.Subtract.html","module_info":["core","ops"],"name":"Subtract","preview":"Trait for the subtraction of two values.\n","type_name":"trait"},{"html_filename":"trait.Multiply.html","module_info":["core","ops"],"name":"Multiply","preview":"Trait for the multiplication of two values.\n","type_name":"trait"},{"html_filename":"trait.Divide.html","module_info":["core","ops"],"name":"Divide","preview":"Trait for the division of two values.\n","type_name":"trait"},{"html_filename":"trait.Mod.html","module_info":["core","ops"],"name":"Mod","preview":"Trait for the modulo of two values.\n","type_name":"trait"},{"html_filename":"trait.Not.html","module_info":["core","ops"],"name":"Not","preview":"Trait to invert a type.\n","type_name":"trait"},{"html_filename":"trait.Eq.html","module_info":["core","ops"],"name":"Eq","preview":"Trait to evaluate if two types are equal.\n","type_name":"trait"},{"html_filename":"trait.Ord.html","module_info":["core","ops"],"name":"Ord","preview":"Trait to evaluate if one value is greater or less than another of the same type.\n","type_name":"trait"},{"html_filename":"trait.BitwiseAnd.html","module_info":["core","ops"],"name":"BitwiseAnd","preview":"Trait to bitwise AND two values of the same type.\n","type_name":"trait"},{"html_filename":"trait.BitwiseOr.html","module_info":["core","ops"],"name":"BitwiseOr","preview":"Trait to bitwise OR two values of the same type.\n","type_name":"trait"},{"html_filename":"trait.BitwiseXor.html","module_info":["core","ops"],"name":"BitwiseXor","preview":"Trait to bitwise XOR two values of the same type.\n","type_name":"trait"},{"html_filename":"trait.Shift.html","module_info":["core","ops"],"name":"Shift","preview":"Trait to bit shift a value.\n","type_name":"trait"},{"html_filename":"fn.ok_str_eq.html","module_info":["core","ops"],"name":"ok_str_eq","preview":"","type_name":"function"},{"html_filename":"struct.StorageKey.html","module_info":["core","storage"],"name":"StorageKey","preview":"Describes a location in storage.\n","type_name":"struct"},{"html_filename":"struct.Buffer.html","module_info":["core","codec"],"name":"Buffer","preview":"","type_name":"struct"},{"html_filename":"struct.BufferReader.html","module_info":["core","codec"],"name":"BufferReader","preview":"","type_name":"struct"},{"html_filename":"trait.AbiDecode.html","module_info":["core","codec"],"name":"AbiDecode","preview":"","type_name":"trait"},{"html_filename":"trait.AbiEncode.html","module_info":["core","codec"],"name":"AbiEncode","preview":"","type_name":"trait"},{"html_filename":"fn.encode.html","module_info":["core","codec"],"name":"encode","preview":"","type_name":"function"},{"html_filename":"fn.abi_decode.html","module_info":["core","codec"],"name":"abi_decode","preview":"","type_name":"function"},{"html_filename":"fn.contract_call.html","module_info":["core","codec"],"name":"contract_call","preview":"","type_name":"function"},{"html_filename":"fn.decode_script_data.html","module_info":["core","codec"],"name":"decode_script_data","preview":"","type_name":"function"},{"html_filename":"fn.decode_first_param.html","module_info":["core","codec"],"name":"decode_first_param","preview":"","type_name":"function"},{"html_filename":"fn.decode_second_param.html","module_info":["core","codec"],"name":"decode_second_param","preview":"","type_name":"function"}],"impl_traits":[{"html_filename":"trait.Foo.html","module_info":["impl_traits","foo"],"name":"Foo","preview":"","type_name":"trait"},{"html_filename":"trait.Baz.html","module_info":["impl_traits","foo"],"name":"Baz","preview":"","type_name":"trait"},{"html_filename":"struct.Bar.html","module_info":["impl_traits","bar"],"name":"Bar","preview":"","type_name":"struct"}]};
"object"==typeof exports&&"undefined"!=typeof module&&(module.exports=SEARCH_INDEX);"#]],
);
assert_file_tree(
doc_dir_name,
project_name,
vec![
"core/all.html",
"core/codec/fn.abi_decode.html",
"core/codec/fn.contract_call.html",
"core/codec/fn.decode_first_param.html",
"core/codec/fn.decode_script_data.html",
"core/codec/fn.decode_second_param.html",
"core/codec/fn.encode.html",
"core/codec/index.html",
"core/codec/struct.Buffer.html",
"core/codec/struct.BufferReader.html",
"core/codec/trait.AbiDecode.html",
"core/codec/trait.AbiEncode.html",
"core/index.html",
"core/ops/fn.ok_str_eq.html",
"core/ops/index.html",
"core/ops/trait.Add.html",
"core/ops/trait.BitwiseAnd.html",
Expand Down Expand Up @@ -91,7 +107,14 @@ fn test_impl_traits_no_deps() {
no_deps: true,
..Default::default()
};
let (doc_path, _) = compile_html(&command, &get_doc_dir).unwrap();
let (doc_path, _) = compile_html(
&command,
&get_doc_dir,
ExperimentalFlags {
new_encoding: false,
},
)
.unwrap();
assert_index_html(
&doc_path,
project_name,
Expand Down
4 changes: 4 additions & 0 deletions forc/src/cli/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ pub struct Command {
/// Possible values: PUBLIC, LOCAL, <GATEWAY_URL>
#[clap(long)]
pub ipfs_node: Option<IPFSNode>,

/// Set of experimental flags
#[clap(long)]
pub experimental_new_encoding: bool,
}

pub(crate) fn exec(command: Command) -> ForcResult<()> {
Expand Down
6 changes: 5 additions & 1 deletion forc/src/ops/forc_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use forc_pkg as pkg;
use forc_pkg::manifest::GenericManifestFile;
use pkg::manifest::ManifestFile;
use std::path::PathBuf;
use sway_core::{language::ty, Engines};
use sway_core::{language::ty, Engines, ExperimentalFlags};
use sway_error::handler::Handler;

pub fn check(command: CheckCommand, engines: &Engines) -> Result<(Option<ty::TyProgram>, Handler)> {
Expand All @@ -16,6 +16,7 @@ pub fn check(command: CheckCommand, engines: &Engines) -> Result<(Option<ty::TyP
locked,
disable_tests,
ipfs_node,
experimental_new_encoding,
} = command;

let this_dir = if let Some(ref path) = path {
Expand Down Expand Up @@ -43,6 +44,9 @@ pub fn check(command: CheckCommand, engines: &Engines) -> Result<(Option<ty::TyP
tests_enabled,
engines,
None,
ExperimentalFlags {
new_encoding: experimental_new_encoding,
},
)?;
let (res, handler) = v
.pop()
Expand Down
6 changes: 6 additions & 0 deletions sway-ast/src/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ pub enum Intrinsic {
Smo,
Not,
JmpMem,
ContractCall, // __contract_call(params, coins, asset_id, gas)
ContractRet, // __contract_ret(ptr, len)
}

impl fmt::Display for Intrinsic {
Expand Down Expand Up @@ -75,6 +77,8 @@ impl fmt::Display for Intrinsic {
Intrinsic::Smo => "smo",
Intrinsic::Not => "not",
Intrinsic::JmpMem => "jmp_mem",
Intrinsic::ContractCall => "contract_call",
Intrinsic::ContractRet => "contract_ret",
};
write!(f, "{s}")
}
Expand Down Expand Up @@ -118,6 +122,8 @@ impl Intrinsic {
"__smo" => Smo,
"__not" => Not,
"__jmp_mem" => JmpMem,
"__contract_call" => ContractCall,
"__contract_ret" => ContractRet,
_ => return None,
})
}
Expand Down
6 changes: 3 additions & 3 deletions sway-core/src/abi_generation/evm_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ pub fn generate_abi_program(program: &TyProgram, engines: &Engines) -> EvmAbiRes
.iter()
.map(|x| generate_abi_function(x, type_engine, decl_engine))
.collect(),
TyProgramKind::Script { main_function, .. }
| TyProgramKind::Predicate { main_function, .. } => {
TyProgramKind::Script { entry_function, .. }
| TyProgramKind::Predicate { entry_function, .. } => {
vec![generate_abi_function(
main_function,
entry_function,
type_engine,
decl_engine,
)]
Expand Down
10 changes: 8 additions & 2 deletions sway-core/src/abi_generation/fuel_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,14 @@ pub fn generate_program_abi(
configurables: Some(configurables),
}
}
TyProgramKind::Script { main_function, .. }
| TyProgramKind::Predicate { main_function, .. } => {
TyProgramKind::Script {
entry_function: main_function,
..
}
| TyProgramKind::Predicate {
entry_function: main_function,
..
} => {
let main_function = decl_engine.get_function(main_function);
let functions =
vec![main_function.generate_abi_function(ctx, type_engine, decl_engine, types)];
Expand Down
16 changes: 12 additions & 4 deletions sway-core/src/asm_generation/from_ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ use super::{
MidenVMAsmBuilder,
};

use crate::{BuildConfig, BuildTarget};
use crate::{BuildConfig, BuildTarget, ExperimentalFlags};

use sway_error::handler::{ErrorEmitted, Handler};
use sway_ir::*;
use sway_ir::{Context, Kind, Module};

pub fn compile_ir_to_asm(
handler: &Handler,
Expand Down Expand Up @@ -106,8 +106,16 @@ fn compile_module_to_asm(
})
.collect();

let abstract_program =
AbstractProgram::new(kind, data_section, entries, non_entries, reg_seqr);
let abstract_program = AbstractProgram::new(
kind,
data_section,
entries,
non_entries,
reg_seqr,
ExperimentalFlags {
new_encoding: context.experimental.new_encoding,
},
);

if build_config
.map(|cfg| cfg.print_intermediate_asm)
Expand Down
Loading

0 comments on commit c24d731

Please sign in to comment.