Skip to content

Commit 2b84e01

Browse files
committed
Implement a command to dump impls for a given type
Closes #7286.
1 parent 05e667d commit 2b84e01

File tree

15 files changed

+187
-16
lines changed

15 files changed

+187
-16
lines changed

forc-pkg/src/manifest/build_profile.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use serde::{Deserialize, Serialize};
22
use sway_core::{Backtrace, OptLevel, PrintAsm, PrintIr};
33

4+
use crate::DumpOpts;
5+
46
/// Parameters to pass through to the `sway_core::BuildConfig` during compilation.
57
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
68
#[serde(rename_all = "kebab-case")]
@@ -11,6 +13,7 @@ pub struct BuildProfile {
1113
pub print_ast: bool,
1214
pub print_dca_graph: Option<String>,
1315
pub print_dca_graph_url_format: Option<String>,
16+
pub dump: DumpOpts,
1417
#[serde(default)]
1518
pub print_ir: PrintIr,
1619
#[serde(default)]
@@ -47,6 +50,7 @@ impl BuildProfile {
4750
pub fn debug() -> Self {
4851
Self {
4952
name: Self::DEBUG.into(),
53+
dump: DumpOpts::default(),
5054
print_ast: false,
5155
print_dca_graph: None,
5256
print_dca_graph_url_format: None,
@@ -69,6 +73,7 @@ impl BuildProfile {
6973
pub fn release() -> Self {
7074
Self {
7175
name: Self::RELEASE.to_string(),
76+
dump: DumpOpts::default(),
7277
print_ast: false,
7378
print_dca_graph: None,
7479
print_dca_graph_url_format: None,

forc-pkg/src/pkg.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,19 @@ pub struct MinifyOpts {
279279
/// Represents a compiled contract ID as a pub const in a contract.
280280
type ContractIdConst = String;
281281

282+
#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq, Eq)]
283+
pub struct DumpOpts {
284+
/// Dump all trait implementations for the given type name.
285+
pub dump_impls: Option<String>,
286+
}
287+
282288
/// The set of options provided to the `build` functions.
283289
#[derive(Default, Clone)]
284290
pub struct BuildOpts {
285291
pub pkg: PkgOpts,
286292
pub print: PrintOpts,
287293
pub minify: MinifyOpts,
294+
pub dump: DumpOpts,
288295
/// If set, generates a JSON file containing the hex-encoded script binary.
289296
pub hex_outfile: Option<String>,
290297
/// If set, outputs a binary file representing the script bytes.
@@ -1724,7 +1731,7 @@ pub fn compile(
17241731
&handler,
17251732
engines,
17261733
source,
1727-
namespace,
1734+
namespace.clone(),
17281735
Some(&sway_build_config),
17291736
&pkg.name,
17301737
None,
@@ -1754,6 +1761,10 @@ pub fn compile(
17541761
return fail(handler);
17551762
}
17561763

1764+
if let Some(typename) = &profile.dump.dump_impls {
1765+
sway_core::check_dump_impls(engines, &namespace, typename);
1766+
}
1767+
17571768
let asm_res = time_expr!(
17581769
pkg.name,
17591770
"compile ast to asm",
@@ -2108,6 +2119,7 @@ fn build_profile_from_opts(
21082119
metrics_outfile,
21092120
tests,
21102121
error_on_warnings,
2122+
dump,
21112123
..
21122124
} = build_options;
21132125

@@ -2128,6 +2140,7 @@ fn build_profile_from_opts(
21282140
BuildProfile::default()
21292141
});
21302142
profile.name = selected_profile_name.into();
2143+
profile.dump = dump.clone();
21312144
profile.print_ast |= print.ast;
21322145
if profile.print_dca_graph.is_none() {
21332146
profile.print_dca_graph.clone_from(&print.dca_graph);

forc-plugins/forc-client/src/op/deploy.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::{
1212
},
1313
};
1414
use anyhow::{bail, Context, Result};
15-
use forc_pkg::{self as pkg, PackageManifestFile};
15+
use forc_pkg::{self as pkg, DumpOpts, PackageManifestFile};
1616
use forc_pkg::{manifest::GenericManifestFile, MemberFilter};
1717
use forc_tracing::{println_action_green, println_warning};
1818
use forc_util::default_output_directory;
@@ -814,6 +814,7 @@ fn build_opts_from_cmd(cmd: &cmd::Deploy, member_filter: pkg::MemberFilter) -> p
814814
ir: cmd.print.ir(),
815815
reverse_order: cmd.print.reverse_order,
816816
},
817+
dump: DumpOpts::default(),
817818
time_phases: cmd.print.time_phases,
818819
profile: cmd.print.profile,
819820
metrics_outfile: cmd.print.metrics_outfile.clone(),

forc-plugins/forc-client/src/op/run/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::{
88
},
99
};
1010
use anyhow::{anyhow, bail, Context, Result};
11-
use forc_pkg::{self as pkg, fuel_core_not_running, PackageManifestFile};
11+
use forc_pkg::{self as pkg, fuel_core_not_running, DumpOpts, PackageManifestFile};
1212
use forc_tracing::println_warning;
1313
use forc_util::tx_utils::format_log_receipts;
1414
use fuel_core_client::client::FuelClient;
@@ -256,6 +256,7 @@ fn build_opts_from_cmd(cmd: &cmd::Run) -> pkg::BuildOpts {
256256
json_abi: cmd.minify.json_abi,
257257
json_storage_slots: cmd.minify.json_storage_slots,
258258
},
259+
dump: DumpOpts::default(),
259260
build_target: BuildTarget::default(),
260261
build_profile: cmd.build_profile.build_profile.clone(),
261262
release: cmd.build_profile.release,

forc-test/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::setup::{
77
ContractDeploymentSetup, ContractTestSetup, DeploymentSetup, ScriptTestSetup, TestSetup,
88
};
99
use ecal::EcalSyscallHandler;
10-
use forc_pkg::{self as pkg, BuildOpts};
10+
use forc_pkg::{self as pkg, BuildOpts, DumpOpts};
1111
use forc_util::tx_utils::RevertInfo;
1212
use fuel_abi_types::abi::program::ProgramABI;
1313
use fuel_tx as tx;
@@ -452,6 +452,7 @@ impl From<TestOpts> for pkg::BuildOpts {
452452
pkg: val.pkg,
453453
print: val.print,
454454
minify: val.minify,
455+
dump: DumpOpts::default(),
455456
binary_outfile: val.binary_outfile,
456457
debug_outfile: val.debug_outfile,
457458
hex_outfile: val.hex_outfile,
@@ -477,6 +478,7 @@ impl TestOpts {
477478
pkg: self.pkg,
478479
print: self.print,
479480
minify: self.minify,
481+
dump: DumpOpts::default(),
480482
binary_outfile: self.binary_outfile,
481483
debug_outfile: self.debug_outfile,
482484
hex_outfile: self.hex_outfile,

forc/src/cli/commands/check.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ pub struct Command {
4545
#[clap(long)]
4646
pub ipfs_node: Option<IPFSNode>,
4747

48+
/// Dump all trait implementations for the given type name.
49+
#[clap(long = "dump-impls", value_name = "TYPE")]
50+
pub dump_impls: Option<String>,
51+
4852
#[clap(flatten)]
4953
pub experimental: sway_features::CliFields,
5054
}

forc/src/cli/shared.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ pub struct Build {
9191
/// Build target to use for code generation.
9292
#[clap(long, value_enum, default_value_t = BuildTarget::default(), alias="target")]
9393
pub build_target: BuildTarget,
94+
#[clap(flatten)]
95+
pub dump: Dump,
9496
}
9597

9698
/// Build output file options.
@@ -126,6 +128,14 @@ pub struct BuildProfile {
126128
pub error_on_warnings: bool,
127129
}
128130

131+
/// Dump options.
132+
#[derive(Args, Debug, Default)]
133+
pub struct Dump {
134+
/// Dump all trait implementations for the given type name.
135+
#[clap(long = "dump-impls", value_name = "TYPE")]
136+
pub dump_impls: Option<String>,
137+
}
138+
129139
/// Options related to printing stages of compiler output.
130140
#[derive(Args, Debug, Default)]
131141
pub struct Print {

forc/src/ops/forc_build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ fn opts_from_cmd(cmd: BuildCommand) -> pkg::BuildOpts {
2929
ir: cmd.build.print.ir(),
3030
reverse_order: cmd.build.print.reverse_order,
3131
},
32+
dump: pkg::DumpOpts {
33+
dump_impls: cmd.build.dump.dump_impls,
34+
},
3235
time_phases: cmd.build.print.time_phases,
3336
profile: cmd.build.print.profile,
3437
metrics_outfile: cmd.build.print.metrics_outfile,

forc/src/ops/forc_contract_id.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::cli::ContractIdCommand;
22
use anyhow::{bail, Result};
3-
use forc_pkg::{self as pkg, build_with_options};
3+
use forc_pkg::{self as pkg, build_with_options, DumpOpts};
44
use forc_tracing::println_green;
55
use sway_core::{fuel_prelude::fuel_tx, BuildTarget};
66
use tracing::info;
@@ -63,6 +63,7 @@ fn build_opts_from_cmd(cmd: &ContractIdCommand) -> pkg::BuildOpts {
6363
ir: cmd.print.ir(),
6464
reverse_order: cmd.print.reverse_order,
6565
},
66+
dump: DumpOpts::default(),
6667
time_phases: cmd.print.time_phases,
6768
profile: cmd.print.profile,
6869
metrics_outfile: cmd.print.metrics_outfile.clone(),

forc/src/ops/forc_predicate_root.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::cli::PredicateRootCommand;
22
use anyhow::Result;
3-
use forc_pkg::{self as pkg, build_with_options};
3+
use forc_pkg::{self as pkg, build_with_options, DumpOpts};
44
use sway_core::BuildTarget;
55

66
pub fn predicate_root(command: PredicateRootCommand) -> Result<()> {
@@ -32,6 +32,7 @@ fn build_opts_from_cmd(cmd: PredicateRootCommand) -> pkg::BuildOpts {
3232
ir: cmd.print.ir(),
3333
reverse_order: cmd.print.reverse_order,
3434
},
35+
dump: DumpOpts::default(),
3536
time_phases: cmd.print.time_phases,
3637
profile: cmd.print.profile,
3738
metrics_outfile: cmd.print.metrics_outfile,

0 commit comments

Comments
 (0)