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

fix dca for encoding v1 autogenerated code #6006

Merged
merged 4 commits into from
May 20, 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
18 changes: 13 additions & 5 deletions sway-core/src/control_flow_analysis/dead_code_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1643,13 +1643,21 @@ fn connect_expression<'eng: 'cfg, 'cfg>(
for leaf in leaves {
graph.add_edge(*leaf, this_ix, "".into());
}
graph.add_edge(this_ix, field_ix, "".into());

if let Some(struct_node_ix) = graph
.namespace
.find_struct_decl(resolved_type_of_parent.suffix.as_str())
// autogenerated code should not increase usage of a struct field
if !engines
.se()
.is_span_in_autogenerated(&expression_span)
.unwrap_or(false)
{
graph.add_edge(this_ix, *struct_node_ix, "".into());
graph.add_edge(this_ix, field_ix, "".into());

if let Some(struct_node_ix) = graph
.namespace
.find_struct_decl(resolved_type_of_parent.suffix.as_str())
{
graph.add_edge(this_ix, *struct_node_ix, "".into());
}
}

Ok(vec![this_ix])
Expand Down
1 change: 0 additions & 1 deletion sway-core/src/type_system/unify/unifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,6 @@ impl<'a> Unifier<'a> {
self.unify(handler, rtp.type_id, etp.type_id, span);
});
} else {
dbg!(rn == en, rvs.len() == evs.len(), rtps.len() == etps.len());
let internal = format!("[{received:?}] versus [{expected:?}]");
let (received, expected) = self.assign_args(received, expected);
handler.emit_err(
Expand Down
12 changes: 2 additions & 10 deletions sway-ir/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -816,16 +816,8 @@ impl<'a, 'eng> InstructionVerifier<'a, 'eng> {

fn verify_load(&self, src_val: &Value) -> Result<(), IrError> {
// Just confirm `src_val` is a pointer.
let r = self
.get_ptr_type(src_val, IrError::VerifyLoadFromNonPointer)
.map(|_| ());

if r.is_err() {
let meta = src_val.get_metadata(self.context).unwrap();
dbg!(&self.context.metadata[meta.0], &r);
}

r
self.get_ptr_type(src_val, IrError::VerifyLoadFromNonPointer)
.map(|_| ())
}

fn verify_log(&self, log_val: &Value, log_ty: &Type, log_id: &Value) -> Result<(), IrError> {
Expand Down
8 changes: 8 additions & 0 deletions sway-types/src/source_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ impl Clone for SourceEngine {
impl SourceEngine {
const AUTOGENERATED_PATH: &'static str = "<autogenerated>";

pub fn is_span_in_autogenerated(&self, span: &crate::Span) -> Option<bool> {
span.source_id().map(|s| self.is_source_id_autogenerated(s))
}

pub fn is_source_id_autogenerated(&self, source_id: &SourceId) -> bool {
self.get_path(source_id).starts_with("<autogenerated>")
}

/// This function retrieves an integer-based source ID for a provided path buffer.
/// If an ID already exists for the given path, the function will return that
/// existing ID. If not, a new ID will be created.
Expand Down
2 changes: 1 addition & 1 deletion test/src/e2e_vm_tests/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub(crate) async fn deploy_contract(file_name: &str, run_config: &RunConfig) ->
true => BuildProfile::RELEASE.to_string(),
false => BuildProfile::DEBUG.to_string(),
},
no_encoding_v1: !dbg!(run_config.experimental.new_encoding),
no_encoding_v1: !run_config.experimental.new_encoding,
..Default::default()
})
.await
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ script;
mod utils;
use utils::Foo;


struct Bar {
value: u64
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
category = "compile"
expected_warnings = 1

expected_warnings = 0
# check: $()struct Bar {
# nextln: $()value: u64
# nextln: $()This struct field is never accessed.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ expected_result_new_encoding = { action = "return_data", value = "00000000000020
validate_abi = true
expected_warnings = 26

#check: $()pub struct S
#nextln: $()This struct field is never accessed.
#nextln: $()pub enum Enum

#check: $()pub struct S
#nextln: $()This struct field is never accessed.
#nextln: $()pub enum Enum

#check: $()pub enum Enum
#nextln: $()This enum is never used.

Expand Down
2 changes: 0 additions & 2 deletions test/src/sdk-harness/Forc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ members = [
"test_projects/asset_ops",
"test_projects/block",
"test_projects/call_frames",
# TODO Uncomment these when SDK supports encoding V1 for configurables
# https://github.com/FuelLabs/sway/issues/5727
"test_projects/configurables_in_contract",
"test_projects/configurables_in_script",
"test_projects/context",
Expand Down
Loading