Skip to content

Commit

Permalink
Merge branch 'master' into josh/debug_fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaBatty authored Jan 15, 2025
2 parents c3cdf71 + 77d583a commit e8ae8fe
Show file tree
Hide file tree
Showing 54 changed files with 433 additions and 319 deletions.
2 changes: 1 addition & 1 deletion forc-pkg/src/pkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ impl Built {
/// Returns an iterator yielding all member built packages.
pub fn into_members<'a>(
&'a self,
) -> Box<dyn Iterator<Item = (&Pinned, Arc<BuiltPackage>)> + 'a> {
) -> Box<dyn Iterator<Item = (&'a Pinned, Arc<BuiltPackage>)> + 'a> {
// NOTE: Since pkg is a `Arc<_>`, pkg clones in this function are only reference
// increments. `BuiltPackage` struct does not get copied.`
match self {
Expand Down
2 changes: 1 addition & 1 deletion forc-pkg/src/source/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ impl fmt::Display for Pinned {
}
}

impl<'a> fmt::Display for DisplayCompiling<'a, Pinned> {
impl fmt::Display for DisplayCompiling<'_, Pinned> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self.source {
Pinned::Member(_) => self.manifest_dir.display().fmt(f),
Expand Down
2 changes: 1 addition & 1 deletion forc-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ pub struct TestCount {
pub ignored: usize,
}

impl<'a> TestFilter<'a> {
impl TestFilter<'_> {
fn filter(&self, fn_name: &str) -> bool {
if self.exact_match {
fn_name == self.filter_phrase
Expand Down
2 changes: 1 addition & 1 deletion sway-core/src/abi_generation/fuel_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct AbiContext<'a> {
pub type_ids_to_full_type_str: HashMap<String, String>,
}

impl<'a> AbiContext<'a> {
impl AbiContext<'_> {
fn to_str_context(&self, engines: &Engines, abi_full: bool) -> AbiStrContext {
AbiStrContext {
program_name: self
Expand Down
3 changes: 1 addition & 2 deletions sway-core/src/asm_generation/evm/evm_asm_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ use etk_asm::{asm::Assembler, ops::*};
/// The code that is compiled but not stored on the blockchain is thus the code needed
/// to store the correct code on the blockchain but also any logic that is contained in
/// a (potential) constructor of the contract.
pub struct EvmAsmBuilder<'ir, 'eng> {
#[allow(dead_code)]
program_kind: ProgramKind,
Expand Down Expand Up @@ -94,7 +93,7 @@ pub struct EvmAsmBuilderResult {

pub type EvmAbiResult = Vec<ethabi::operation::Operation>;

impl<'ir, 'eng> AsmBuilder for EvmAsmBuilder<'ir, 'eng> {
impl AsmBuilder for EvmAsmBuilder<'_, '_> {
fn func_to_labels(&mut self, func: &Function) -> (Label, Label) {
self.func_to_labels(func)
}
Expand Down
2 changes: 1 addition & 1 deletion sway-core/src/asm_generation/fuel/fuel_asm_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub struct FuelAsmBuilder<'ir, 'eng> {
pub(super) before_entries: Vec<Op>,
}

impl<'ir, 'eng> AsmBuilder for FuelAsmBuilder<'ir, 'eng> {
impl AsmBuilder for FuelAsmBuilder<'_, '_> {
fn func_to_labels(&mut self, func: &Function) -> (Label, Label) {
self.func_to_labels(func)
}
Expand Down
3 changes: 1 addition & 2 deletions sway-core/src/asm_generation/fuel/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ use super::{compiler_constants::NUM_ARG_REGISTERS, data_section::EntryName};
/// is used to point to the stack location of the remaining arguments.
/// Stack space for the extra arguments is allocated in the caller when
/// locals of the caller are allocated.
impl<'ir, 'eng> FuelAsmBuilder<'ir, 'eng> {
impl FuelAsmBuilder<'_, '_> {
pub(super) fn compile_call(
&mut self,
instr_val: &Value,
Expand Down Expand Up @@ -854,7 +854,6 @@ impl<'ir, 'eng> FuelAsmBuilder<'ir, 'eng> {
c,
"Cannot happen, we just checked",
);
dbg!();
init_mut_vars.push(InitMutVars {
stack_base_words,
var_size: var_size.clone(),
Expand Down
1 change: 0 additions & 1 deletion sway-core/src/asm_generation/fuel/register_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,6 @@ pub(crate) fn color_interference_graph(
/// list `self.ops`. The algorithm used is Chaitin's graph-coloring register allocation
/// algorithm (https://en.wikipedia.org/wiki/Chaitin%27s_algorithm). The individual steps of
/// the algorithm are thoroughly explained in register_allocator.rs.
pub(crate) fn allocate_registers(
ops: &[Op],
) -> Result<AllocatedAbstractInstructionSet, CompileError> {
Expand Down
26 changes: 0 additions & 26 deletions sway-core/src/asm_lang/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -866,32 +866,6 @@ fn four_regs(
}
};

impl ConstantRegister {
pub(crate) fn parse_register_name(raw: &str) -> Option<ConstantRegister> {
use ConstantRegister::*;
Some(match raw {
"zero" => Zero,
"one" => One,
"of" => Overflow,
"pc" => ProgramCounter,
"ssp" => StackStartPointer,
"sp" => StackPointer,
"fp" => FramePointer,
"hp" => HeapPointer,
"err" => Error,
"ggas" => GlobalGas,
"cgas" => ContextGas,
"bal" => Balance,
"is" => InstructionStart,
"flag" => Flags,
"retl" => ReturnLength,
"ret" => ReturnValue,
"ds" => DataSectionStart,
_ => return None,
})
}
}

// Immediate Value.
pub type ImmediateValue = u32;

Expand Down
26 changes: 26 additions & 0 deletions sway-core/src/asm_lang/virtual_register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,32 @@ pub enum ConstantRegister {
FuncArg5,
}

impl ConstantRegister {
pub(crate) fn parse_register_name(raw: &str) -> Option<ConstantRegister> {
use ConstantRegister::*;
Some(match raw {
"zero" => Zero,
"one" => One,
"of" => Overflow,
"pc" => ProgramCounter,
"ssp" => StackStartPointer,
"sp" => StackPointer,
"fp" => FramePointer,
"hp" => HeapPointer,
"err" => Error,
"ggas" => GlobalGas,
"cgas" => ContextGas,
"bal" => Balance,
"is" => InstructionStart,
"flag" => Flags,
"retl" => ReturnLength,
"ret" => ReturnValue,
"ds" => DataSectionStart,
_ => return None,
})
}
}

use crate::asm_generation::fuel::compiler_constants;

impl ConstantRegister {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ fn connect_impl_trait<'eng: 'cfg, 'cfg>(
///
/// The trait node itself has already been added (as `entry_node`), so we just need to insert that
/// node index into the namespace for the trait.
///
/// When connecting a function declaration, we are inserting a new root node into the graph that
/// has no entry points, since it is just a declaration.
/// When something eventually calls it, it gets connected to the declaration.
Expand Down
10 changes: 5 additions & 5 deletions sway-core/src/control_flow_analysis/flow_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub enum ControlFlowGraphNode<'cfg> {
},
}

impl<'cfg> GetDeclIdent for ControlFlowGraphNode<'cfg> {
impl GetDeclIdent for ControlFlowGraphNode<'_> {
fn get_decl_ident(&self, engines: &Engines) -> Option<Ident> {
match self {
ControlFlowGraphNode::OrganizationalDominator(_) => None,
Expand All @@ -118,27 +118,27 @@ impl<'cfg> GetDeclIdent for ControlFlowGraphNode<'cfg> {
}
}

impl<'cfg> std::convert::From<&ty::TyStorageField> for ControlFlowGraphNode<'cfg> {
impl std::convert::From<&ty::TyStorageField> for ControlFlowGraphNode<'_> {
fn from(other: &ty::TyStorageField) -> Self {
ControlFlowGraphNode::StorageField {
field_name: other.name.clone(),
}
}
}

impl<'cfg> std::convert::From<String> for ControlFlowGraphNode<'cfg> {
impl std::convert::From<String> for ControlFlowGraphNode<'_> {
fn from(other: String) -> Self {
ControlFlowGraphNode::OrganizationalDominator(other)
}
}

impl<'cfg> std::convert::From<&str> for ControlFlowGraphNode<'cfg> {
impl std::convert::From<&str> for ControlFlowGraphNode<'_> {
fn from(other: &str) -> Self {
other.to_string().into()
}
}

impl<'cfg> DebugWithEngines for ControlFlowGraphNode<'cfg> {
impl DebugWithEngines for ControlFlowGraphNode<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>, engines: &Engines) -> std::fmt::Result {
let text = match self {
ControlFlowGraphNode::OrganizationalDominator(s) => s.to_string(),
Expand Down
14 changes: 6 additions & 8 deletions sway-core/src/ir_generation/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ use std::collections::HashMap;
/// So in general the methods in [FnCompiler] will return a pointer if they can and will get it, be
/// forced, into a value if that is desired. All the temporary values are manipulated with simple
/// loads and stores, rather than anything more complicated like `mem_copy`s.
// Wrapper around Value to enforce distinction between terminating and non-terminating values.
///
/// Wrapper around Value to enforce distinction between terminating and non-terminating values.
struct TerminatorValue {
value: Value,
is_terminator: bool,
Expand Down Expand Up @@ -4178,12 +4178,10 @@ impl<'eng> FnCompiler<'eng> {
.get_elem_ptr_with_idx(tuple_value, field_type, idx as u64)
.add_metadatum(context, span_md_idx)
})
.ok_or_else(|| {
CompileError::Internal(
"Invalid (non-aggregate?) tuple type for TupleElemAccess.",
span,
)
})?;
.ok_or(CompileError::Internal(
"Invalid (non-aggregate?) tuple type for TupleElemAccess.",
span,
))?;
Ok(TerminatorValue::new(val, context))
}

Expand Down
9 changes: 4 additions & 5 deletions sway-core/src/language/programs.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
use sway_error::handler::ErrorEmitted;
use sway_utils::PerformanceData;

use super::{lexed::LexedProgram, parsed::ParseProgram, ty::TyProgram};
use crate::semantic_analysis::program::TypeCheckFailed;
use sway_utils::PerformanceData;

/// Contains the lexed, parsed, typed compilation stages of a program, as well
/// as compilation metrics.
#[derive(Clone, Debug)]
pub struct Programs {
pub lexed: LexedProgram,
pub parsed: ParseProgram,
pub typed: Result<TyProgram, ErrorEmitted>,
pub typed: Result<TyProgram, TypeCheckFailed>,
pub metrics: PerformanceData,
}

impl Programs {
pub fn new(
lexed: LexedProgram,
parsed: ParseProgram,
typed: Result<TyProgram, ErrorEmitted>,
typed: Result<TyProgram, TypeCheckFailed>,
metrics: PerformanceData,
) -> Programs {
Programs {
Expand Down
16 changes: 13 additions & 3 deletions sway-core/src/language/ty/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ impl TyModule {
.flat_map(|node| inside_ast_node(de, node))
.collect::<Vec<_>>()
}

/// Recursively find all test function declarations.
pub fn test_fns_recursive<'a: 'b, 'b>(
&'b self,
decl_engine: &'a DeclEngine,
) -> impl 'b + Iterator<Item = (Arc<TyFunctionDecl>, DeclRefFunction)> {
self.submodules_recursive()
.flat_map(|(_, submod)| submod.module.test_fns(decl_engine))
.chain(self.test_fns(decl_engine))
}
}

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -103,7 +113,7 @@ impl TyModule {
pub fn test_fns<'a: 'b, 'b>(
&'b self,
decl_engine: &'a DeclEngine,
) -> impl '_ + Iterator<Item = (Arc<TyFunctionDecl>, DeclRefFunction)> {
) -> impl 'b + Iterator<Item = (Arc<TyFunctionDecl>, DeclRefFunction)> {
self.all_nodes.iter().filter_map(|node| {
if let TyAstNodeContent::Declaration(TyDecl::FunctionDecl(FunctionDecl { decl_id })) =
&node.content
Expand All @@ -123,7 +133,7 @@ impl TyModule {
pub fn contract_fns<'a: 'b, 'b>(
&'b self,
engines: &'a Engines,
) -> impl '_ + Iterator<Item = DeclId<TyFunctionDecl>> {
) -> impl 'b + Iterator<Item = DeclId<TyFunctionDecl>> {
self.all_nodes
.iter()
.flat_map(move |node| node.contract_fns(engines))
Expand All @@ -133,7 +143,7 @@ impl TyModule {
pub fn contract_supertrait_fns<'a: 'b, 'b>(
&'b self,
engines: &'a Engines,
) -> impl '_ + Iterator<Item = DeclId<TyFunctionDecl>> {
) -> impl 'b + Iterator<Item = DeclId<TyFunctionDecl>> {
self.all_nodes
.iter()
.flat_map(move |node| node.contract_supertrait_fns(engines))
Expand Down
7 changes: 2 additions & 5 deletions sway-core/src/language/ty/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,11 +428,8 @@ impl TyProgram {
pub fn test_fns<'a: 'b, 'b>(
&'b self,
decl_engine: &'a DeclEngine,
) -> impl '_ + Iterator<Item = (Arc<TyFunctionDecl>, DeclRefFunction)> {
self.root
.submodules_recursive()
.flat_map(|(_, submod)| submod.module.test_fns(decl_engine))
.chain(self.root.test_fns(decl_engine))
) -> impl 'b + Iterator<Item = (Arc<TyFunctionDecl>, DeclRefFunction)> {
self.root.test_fns_recursive(decl_engine)
}

pub fn check_deprecated(&self, engines: &Engines, handler: &Handler) {
Expand Down
Loading

0 comments on commit e8ae8fe

Please sign in to comment.