Skip to content
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
4d3dd10
make items under [project] ordered alphabetically in forc.toml
Jun 7, 2022
2fdb299
Merge branch 'master' of https://github.com/seem-less/sway
Jun 7, 2022
7c05681
Merge branch 'FuelLabs:master' into master
seem-less Jun 7, 2022
2e01bf8
Merge branch 'FuelLabs:master' into master
seem-less Jun 7, 2022
01a1472
Merge branch 'FuelLabs:master' into master
seem-less Jun 7, 2022
2674f96
Merge branch 'FuelLabs:master' into master
seem-less Jun 9, 2022
59ce52b
issue #1893store/show bytecode hash
Jun 9, 2022
4d4d55a
Merge branch 'FuelLabs:master' into master
seem-less Jun 9, 2022
d346732
formatted
Jun 9, 2022
317ff13
Merge branch 'master' of https://github.com/seem-less/sway
Jun 9, 2022
242a8fc
added cargo lock file
Jun 9, 2022
6490218
cargo toml dependencies in alphabetical order
Jun 9, 2022
3c4852d
hash bin of script or predicate only
Jun 9, 2022
d0b4c32
format
Jun 9, 2022
e72e788
Merge branch 'FuelLabs:master' into master
seem-less Jun 9, 2022
ef9d4dd
generating bytecode hash only on scripts and predicates
Jun 10, 2022
ec3f350
Merge branch 'FuelLabs:master' into master
seem-less Jun 10, 2022
2c76471
Merge branch 'master' of https://github.com/seem-less/sway
Jun 10, 2022
50b3645
Merge branch 'FuelLabs:master' into master
seem-less Jun 12, 2022
7681e12
removed option from Compiled::tree_type
Jun 12, 2022
55dc5f8
ran clippy
Jun 12, 2022
6562b39
added to forc_build documentation
Jun 12, 2022
26faa22
Merge branch 'FuelLabs:master' into master
seem-less Jun 12, 2022
6de2c09
made filename suffix containing bin hash a constant
Jun 13, 2022
22b0168
Merge branch 'master' of https://github.com/seem-less/sway
Jun 13, 2022
459e3d9
Merge branch 'FuelLabs:master' into master
seem-less Jun 13, 2022
0eecbc6
Merge branch 'master' into master
mohammadfawaz Jun 14, 2022
cb4e317
Merge branch 'FuelLabs:master' into master
seem-less Jun 14, 2022
2349caa
Merge branch 'FuelLabs:master' into master
seem-less Jun 15, 2022
aaeb822
get root of predicate bytecode
Jun 15, 2022
46731c1
Merge branch 'FuelLabs:master' into master
seem-less Jun 15, 2022
539d7eb
Apply suggestions from code review
seem-less Jun 16, 2022
b390cd6
if let to match on program type
Jun 16, 2022
af8d58d
Merge branch 'FuelLabs:master' into master
seem-less Jun 16, 2022
9df4f90
Update forc/src/cli/commands/build.rs
seem-less Jun 16, 2022
44b10c1
Merge branch 'FuelLabs:master' into master
seem-less Jun 20, 2022
d81cbf7
Merge branch 'FuelLabs:master' into master
seem-less Jun 22, 2022
9dc6545
added benchmarks for compilation process
Jun 23, 2022
ac881eb
Merge branch 'master' of https://github.com/FuelLabs/sway
Jun 23, 2022
cffc5b7
use macro instead of closure for wrapping parts of compilation process
Jun 23, 2022
7f61c62
Merge branch 'master' into master
otrho Jun 24, 2022
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
2 changes: 2 additions & 0 deletions forc-pkg/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ impl Manifest {
print_finalized_asm: false,
print_intermediate_asm: false,
silent: false,
time_phases: false,
},
);
}
Expand All @@ -315,6 +316,7 @@ impl Manifest {
print_finalized_asm: false,
print_intermediate_asm: false,
silent: false,
time_phases: false,
},
);
}
Expand Down
40 changes: 40 additions & 0 deletions forc-pkg/src/pkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ pub struct BuildConfig {
pub print_finalized_asm: bool,
pub print_intermediate_asm: bool,
pub silent: bool,
pub time_phases: bool,
}

/// Error returned upon failed parsing of `PinnedId::from_str`.
Expand Down Expand Up @@ -1416,12 +1417,41 @@ pub fn compile(
namespace: namespace::Module,
source_map: &mut SourceMap,
) -> Result<(Compiled, Option<namespace::Root>)> {
let get_time_now = || {
if build_config.time_phases {
Some(std::time::Instant::now())
} else {
None
}
};

let time_elapsed =
|time_period_description: &str, start_time: Option<std::time::Instant>| -> Result<()> {
if build_config.time_phases {
info!(
" Time elapsed to {}: {:?}",
time_period_description,
start_time
.ok_or_else(|| anyhow!(
"start_time should have a value if --time-phases flag is used"
))?
.elapsed()
);
}
Ok(())
};

let sway_build_config_start = get_time_now();
let entry_path = manifest.entry_path();
let sway_build_config = sway_build_config(manifest.dir(), &entry_path, build_config)?;
let silent_mode = build_config.silent;
time_elapsed("produce `sway_core::BuildConfig`", sway_build_config_start)?;

// First, compile to an AST. We'll update the namespace and check for JSON ABI output.
let compile_to_ast_start = get_time_now();
let ast_res = compile_ast(manifest, build_config, namespace)?;
time_elapsed("compile to ast", compile_to_ast_start)?;

match &ast_res {
CompileAstResult::Failure { warnings, errors } => {
print_on_failure(silent_mode, warnings, errors);
Expand All @@ -1431,7 +1461,10 @@ pub fn compile(
typed_program,
warnings,
} => {
let generate_json_abi_start = get_time_now();
let json_abi = typed_program.kind.generate_json_abi();
time_elapsed("generate JSON ABI", generate_json_abi_start)?;

let tree_type = typed_program.kind.tree_type();
match tree_type {
// If we're compiling a library, we don't need to compile any further.
Expand All @@ -1450,8 +1483,14 @@ pub fn compile(

// For all other program types, we'll compile the bytecode.
TreeType::Contract | TreeType::Predicate | TreeType::Script => {
let ast_to_asm_start = get_time_now();
let asm_res = sway_core::ast_to_asm(ast_res, &sway_build_config);
time_elapsed("compile ast to asm", ast_to_asm_start)?;

let asm_to_bytecode_start = get_time_now();
let bc_res = sway_core::asm_to_bytecode(asm_res, source_map);
time_elapsed("compile asm to bytecode", asm_to_bytecode_start)?;

match bc_res {
BytecodeCompilationResult::Success { bytes, warnings } => {
print_on_success(silent_mode, &pkg.name, &warnings, &tree_type);
Expand Down Expand Up @@ -1529,6 +1568,7 @@ pub fn check(
print_finalized_asm: false,
print_intermediate_asm: false,
silent: silent_mode,
time_phases: false,
};

let mut namespace_map = Default::default();
Expand Down
3 changes: 3 additions & 0 deletions forc/src/cli/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ pub struct Command {
/// If --build-profile is also provided, forc omits this flag and uses provided build-profile.
#[clap(long)]
pub release: bool,
/// Output the time elapsed over each part of the compilation process.
#[clap(long)]
pub time_phases: bool,
}

pub(crate) fn exec(command: Command) -> Result<()> {
Expand Down
3 changes: 3 additions & 0 deletions forc/src/cli/commands/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ pub struct Command {
/// If --build-profile is also provided, forc omits this flag and uses provided build-profile.
#[clap(long)]
pub release: bool,
/// Output the time elapsed over each part of the compilation process.
#[clap(long)]
pub time_phases: bool,
}

pub(crate) async fn exec(command: Command) -> Result<()> {
Expand Down
4 changes: 4 additions & 0 deletions forc/src/cli/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ pub struct Command {
#[clap(long = "silent", short = 's')]
pub silent_mode: bool,

/// Output the time elapsed over each part of the compilation process.
#[clap(long)]
pub time_phases: bool,

/// Pretty-print the outputs from the node.
#[clap(long = "pretty-print", short = 'r')]
pub pretty_print: bool,
Expand Down
5 changes: 4 additions & 1 deletion forc/src/ops/forc_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub fn build(command: BuildCommand) -> Result<pkg::Compiled> {
locked,
build_profile,
release,
time_phases,
} = command;

let key_debug: String = "debug".to_string();
Expand Down Expand Up @@ -64,10 +65,12 @@ pub fn build(command: BuildCommand) -> Result<pkg::Compiled> {
print_finalized_asm,
print_intermediate_asm,
silent: silent_mode,
time_phases,
};

// Check if any cli parameter is passed by the user if not fetch the build profile from manifest.
if !print_ir && !print_intermediate_asm && !print_finalized_asm && !silent_mode {
if !print_ir && !print_intermediate_asm && !print_finalized_asm && !silent_mode && !time_phases
{
config = manifest
.build_profile
.as_ref()
Expand Down
2 changes: 2 additions & 0 deletions forc/src/ops/forc_deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub async fn deploy(command: DeployCommand) -> Result<fuel_tx::ContractId> {
url,
build_profile,
release,
time_phases,
} = command;

let build_command = BuildCommand {
Expand All @@ -53,6 +54,7 @@ pub async fn deploy(command: DeployCommand) -> Result<fuel_tx::ContractId> {
locked,
build_profile,
release,
time_phases,
};

let compiled = forc_build::build(build_command)?;
Expand Down
1 change: 1 addition & 0 deletions forc/src/ops/forc_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub async fn run(command: RunCommand) -> Result<Vec<fuel_tx::Receipt>> {
locked: command.locked,
build_profile: None,
release: false,
time_phases: command.time_phases,
};

let compiled = forc_build::build(build_command)?;
Expand Down