Make order of types in shared_types deterministic (#2169)
* Add missing development dependencies to flake.nix * Use BTreeMap/Set for deterministic shared types Fixes an issue where the order of types in the generated shared_types is not always deterministic.
This commit is contained in:
parent
2f85e73049
commit
c21362b696
|
@ -5,7 +5,7 @@ use inflector::Inflector;
|
||||||
use proc_macro2::TokenStream;
|
use proc_macro2::TokenStream;
|
||||||
use quote::quote;
|
use quote::quote;
|
||||||
use std::{
|
use std::{
|
||||||
collections::{BTreeMap, BTreeSet, HashMap, HashSet},
|
collections::{BTreeMap, BTreeSet},
|
||||||
fs,
|
fs,
|
||||||
io::Write,
|
io::Write,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
|
@ -178,12 +178,12 @@ impl MultiExpansion {
|
||||||
let mut shared_types = Vec::new();
|
let mut shared_types = Vec::new();
|
||||||
// this keeps track of those contracts that need to be updated after a struct was
|
// this keeps track of those contracts that need to be updated after a struct was
|
||||||
// extracted from the contract's module and moved to the shared module
|
// extracted from the contract's module and moved to the shared module
|
||||||
let mut dirty_contracts = HashSet::new();
|
let mut dirty_contracts = BTreeSet::new();
|
||||||
|
|
||||||
// merge all types if more than 1 contract
|
// merge all types if more than 1 contract
|
||||||
if expansions.len() > 1 {
|
if expansions.len() > 1 {
|
||||||
// check for type conflicts across all contracts
|
// check for type conflicts across all contracts
|
||||||
let mut conflicts: HashMap<String, Vec<usize>> = HashMap::new();
|
let mut conflicts: BTreeMap<String, Vec<usize>> = BTreeMap::new();
|
||||||
for (idx, (_, ctx)) in expansions.iter().enumerate() {
|
for (idx, (_, ctx)) in expansions.iter().enumerate() {
|
||||||
for type_identifier in ctx.internal_structs().rust_type_names().keys() {
|
for type_identifier in ctx.internal_structs().rust_type_names().keys() {
|
||||||
conflicts
|
conflicts
|
||||||
|
@ -230,7 +230,7 @@ pub struct MultiExpansionResult {
|
||||||
root: Option<PathBuf>,
|
root: Option<PathBuf>,
|
||||||
contracts: Vec<(ExpandedContract, Context)>,
|
contracts: Vec<(ExpandedContract, Context)>,
|
||||||
/// contains the indices of contracts with structs that need to be updated
|
/// contains the indices of contracts with structs that need to be updated
|
||||||
dirty_contracts: HashSet<usize>,
|
dirty_contracts: BTreeSet<usize>,
|
||||||
/// all type definitions of types that are shared by multiple contracts
|
/// all type definitions of types that are shared by multiple contracts
|
||||||
shared_types: Vec<TokenStream>,
|
shared_types: Vec<TokenStream>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,6 +88,42 @@
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"flake-utils_3": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1644229661,
|
||||||
|
"narHash": "sha256-1YdnJAsNy69bpcjuoKdOYQX0YxZBiCYZo4Twxerqv7k=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"rev": "3cecb5b042f7f209c56ffd8371b2711a290ec797",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"foundry": {
|
||||||
|
"inputs": {
|
||||||
|
"flake-utils": "flake-utils_3",
|
||||||
|
"nixpkgs": [
|
||||||
|
"nixpkgs"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1676884188,
|
||||||
|
"narHash": "sha256-jaVDZcl+YfNkvdGrmWozrvuzOjW45Iuyx8HhR/kE7Bs=",
|
||||||
|
"owner": "shazow",
|
||||||
|
"repo": "foundry.nix",
|
||||||
|
"rev": "ff07b373aaea4d27e15c7291d344d9f92b614fc6",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "shazow",
|
||||||
|
"repo": "foundry.nix",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
"gitignore": {
|
"gitignore": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"nixpkgs": [
|
"nixpkgs": [
|
||||||
|
@ -245,6 +281,7 @@
|
||||||
"devenv": "devenv",
|
"devenv": "devenv",
|
||||||
"fenix": "fenix",
|
"fenix": "fenix",
|
||||||
"flake-utils": "flake-utils_2",
|
"flake-utils": "flake-utils_2",
|
||||||
|
"foundry": "foundry",
|
||||||
"nixpkgs": "nixpkgs_2"
|
"nixpkgs": "nixpkgs_2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -6,6 +6,10 @@
|
||||||
url = "github:nix-community/fenix";
|
url = "github:nix-community/fenix";
|
||||||
inputs.nixpkgs.follows = "nixpkgs";
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
};
|
};
|
||||||
|
foundry = {
|
||||||
|
url = "github:shazow/foundry.nix";
|
||||||
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs =
|
outputs =
|
||||||
|
@ -13,6 +17,7 @@
|
||||||
, nixpkgs
|
, nixpkgs
|
||||||
, flake-utils
|
, flake-utils
|
||||||
, fenix
|
, fenix
|
||||||
|
, foundry
|
||||||
, devenv
|
, devenv
|
||||||
} @ inputs:
|
} @ inputs:
|
||||||
flake-utils.lib.eachDefaultSystem (system:
|
flake-utils.lib.eachDefaultSystem (system:
|
||||||
|
@ -28,6 +33,9 @@
|
||||||
{
|
{
|
||||||
packages = with pkgs; [
|
packages = with pkgs; [
|
||||||
solc
|
solc
|
||||||
|
gcc
|
||||||
|
foundry.defaultPackage.${system}
|
||||||
|
go-ethereum
|
||||||
] ++ lib.optionals stdenv.isDarwin (with darwin.apple_sdk; [
|
] ++ lib.optionals stdenv.isDarwin (with darwin.apple_sdk; [
|
||||||
libiconv
|
libiconv
|
||||||
frameworks.Security
|
frameworks.Security
|
||||||
|
|
Loading…
Reference in New Issue