Skip to content

Commit

Permalink
Turning an instance of HashSet into BTreeSet in asm_generation (#759)
Browse files Browse the repository at this point in the history
* Turning HashSet into BTreeSet

* fmt
  • Loading branch information
mohammadfawaz authored Feb 8, 2022
1 parent 9cdba5c commit 9100b88
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions sway-core/src/asm_generation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ impl RegisterPool {
pub(crate) fn get_register(
&mut self,
virtual_register: &VirtualRegister,
op_register_mapping: &[(RealizedOp, std::collections::HashSet<VirtualRegister>)],
op_register_mapping: &[(RealizedOp, std::collections::BTreeSet<VirtualRegister>)],
) -> Option<AllocatedRegister> {
// check if this register has already been allocated for
if let a @ Some(_) = self.registers.iter().find_map(
Expand Down Expand Up @@ -349,7 +349,7 @@ impl RegisterPool {

fn virtual_register_is_never_accessed_again(
reg: &VirtualRegister,
ops: &[(RealizedOp, std::collections::HashSet<VirtualRegister>)],
ops: &[(RealizedOp, std::collections::BTreeSet<VirtualRegister>)],
) -> bool {
!ops.iter().any(|(_, regs)| regs.contains(reg))
}
Expand Down
6 changes: 3 additions & 3 deletions sway-core/src/asm_lang/virtual_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use super::{
};
use crate::asm_generation::RegisterPool;

use std::collections::{HashMap, HashSet};
use std::collections::{BTreeSet, HashMap};

use std::fmt;

Expand Down Expand Up @@ -135,7 +135,7 @@ pub(crate) enum VirtualOp {
}

impl VirtualOp {
pub(crate) fn registers(&self) -> HashSet<&VirtualRegister> {
pub(crate) fn registers(&self) -> BTreeSet<&VirtualRegister> {
use VirtualOp::*;
(match self {
ADD(r1, r2, r3) => vec![r1, r2, r3],
Expand Down Expand Up @@ -226,7 +226,7 @@ impl VirtualOp {
pub(crate) fn allocate_registers(
&self,
pool: &mut RegisterPool,
op_register_mapping: &[(RealizedOp, HashSet<VirtualRegister>)],
op_register_mapping: &[(RealizedOp, BTreeSet<VirtualRegister>)],
ix: usize,
) -> AllocatedOpcode {
let virtual_registers = self.registers();
Expand Down
4 changes: 2 additions & 2 deletions sway-core/src/asm_lang/virtual_register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::fmt;
/// Represents virtual registers that have yet to be allocated.
/// Note that only the Virtual variant will be allocated, and the Constant variant refers to
/// reserved registers.
#[derive(Hash, PartialEq, Eq, Debug, Clone)]
#[derive(Hash, PartialEq, Eq, PartialOrd, Ord, Debug, Clone)]
pub enum VirtualRegister {
Virtual(String),
Constant(ConstantRegister),
Expand All @@ -26,7 +26,7 @@ impl fmt::Display for VirtualRegister {
}
}

#[derive(Hash, PartialEq, Eq, Debug, Clone)]
#[derive(Hash, PartialEq, Eq, PartialOrd, Ord, Debug, Clone)]
/// These are the special registers defined in the spec
pub enum ConstantRegister {
// Below are VM-reserved registers
Expand Down

0 comments on commit 9100b88

Please sign in to comment.