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

Update salsa #1015

Merged
merged 14 commits into from
Jul 4, 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
1,256 changes: 504 additions & 752 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[workspace]
members = ["crates/*"]
exclude = ["crates/language-server"]
resolver = "2"

[profile.dev.package.solc]
Expand Down
3 changes: 2 additions & 1 deletion crates/common2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ description = "Provides HIR definition and lowering for Fe lang."
semver = "1.0.17"
camino = "1.1.4"
smol_str = "0.1.24"
salsa = { git = "https://github.com/salsa-rs/salsa", package = "salsa-2022" }
salsa = { git = "https://github.com/salsa-rs/salsa", rev = "a1bf3a6" }
indexmap = "2.2"
parser = { path = "../parser2", package = "fe-parser2" }
229 changes: 229 additions & 0 deletions crates/common2/src/indexmap.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
use std::{
hash::{BuildHasher, Hash, RandomState},
ops::{Deref, DerefMut},
};

use salsa::update::Update;

#[derive(Debug, Clone)]
pub struct IndexMap<K, V, S = RandomState>(indexmap::IndexMap<K, V, S>);

impl<K, V> IndexMap<K, V> {
pub fn new() -> Self {
Self(indexmap::IndexMap::new())
}

pub fn with_capacity(n: usize) -> Self {
Self(indexmap::IndexMap::with_capacity(n))
}
}

impl<K, V> Default for IndexMap<K, V> {
fn default() -> Self {
Self::new()
}
}

impl<K, V, S> IntoIterator for IndexMap<K, V, S> {
type Item = <indexmap::IndexMap<K, V, S> as IntoIterator>::Item;
type IntoIter = <indexmap::IndexMap<K, V, S> as IntoIterator>::IntoIter;
fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
}

impl<'a, K, V, S> IntoIterator for &'a IndexMap<K, V, S> {
type Item = <&'a indexmap::IndexMap<K, V, S> as IntoIterator>::Item;
type IntoIter = <&'a indexmap::IndexMap<K, V, S> as IntoIterator>::IntoIter;
fn into_iter(self) -> Self::IntoIter {
(&self.0).into_iter()
}
}

impl<'a, K, V, S> IntoIterator for &'a mut IndexMap<K, V, S> {
type Item = <&'a mut indexmap::IndexMap<K, V, S> as IntoIterator>::Item;
type IntoIter = <&'a mut indexmap::IndexMap<K, V, S> as IntoIterator>::IntoIter;
fn into_iter(self) -> Self::IntoIter {
(&mut self.0).into_iter()
}
}

impl<K, V, S> PartialEq for IndexMap<K, V, S>
where
K: Eq + Hash,
V: PartialEq,
S: BuildHasher,
{
fn eq(&self, other: &Self) -> bool {
self.0.eq(&other.0)
}
}

impl<K, V, S> Eq for IndexMap<K, V, S>
where
K: Eq + Hash,
V: Eq,
S: BuildHasher,
{
}

impl<K, V, S> FromIterator<(K, V)> for IndexMap<K, V, S>
where
K: Hash + Eq,
S: BuildHasher + Default,
{
fn from_iter<T: IntoIterator<Item = (K, V)>>(iter: T) -> Self {
Self(indexmap::IndexMap::from_iter(iter))
}
}

impl<K, V, S> Deref for IndexMap<K, V, S>
where
S: BuildHasher,
{
type Target = indexmap::IndexMap<K, V, S>;
fn deref(&self) -> &Self::Target {
&self.0
}
}

impl<K, V, S> DerefMut for IndexMap<K, V, S>
where
S: BuildHasher,
{
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}

unsafe impl<K, V, S> Update for IndexMap<K, V, S>
where
K: Update + Eq + Hash,
V: Update,
S: BuildHasher,
{
unsafe fn maybe_update(old_pointer: *mut Self, new_map: Self) -> bool {
let old_map = unsafe { &mut *old_pointer };

// Check if the keys in both maps are the same w.r.t the key order.
let is_key_same = old_map.len() == new_map.len()
|| old_map
.keys()
.zip(new_map.keys())
.all(|(old, new)| old == new);

// If the keys are different, update entire map.
if !is_key_same {
old_map.clear();
old_map.0.extend(new_map.0);
return true;
}

// Update values if it's different.
let mut changed = false;
for (i, new_value) in new_map.0.into_values().enumerate() {
let old_value = &mut old_map[i];
changed |= V::maybe_update(old_value, new_value);
}

changed
}
}

#[derive(Debug, Clone)]
pub struct IndexSet<V, S = RandomState>(indexmap::IndexSet<V, S>);

impl<V> IndexSet<V> {
pub fn new() -> Self {
Self(indexmap::IndexSet::new())
}

pub fn with_capacity(n: usize) -> Self {
Self(indexmap::IndexSet::with_capacity(n))
}
}

impl<V> Default for IndexSet<V> {
fn default() -> Self {
Self::new()
}
}

impl<V, S> IntoIterator for IndexSet<V, S> {
type Item = <indexmap::IndexSet<V, S> as IntoIterator>::Item;
type IntoIter = <indexmap::IndexSet<V, S> as IntoIterator>::IntoIter;
fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
}

impl<'a, V, S> IntoIterator for &'a IndexSet<V, S> {
type Item = <&'a indexmap::IndexSet<V, S> as IntoIterator>::Item;
type IntoIter = <&'a indexmap::IndexSet<V, S> as IntoIterator>::IntoIter;
fn into_iter(self) -> Self::IntoIter {
(&self.0).into_iter()
}
}

impl<V, S> PartialEq for IndexSet<V, S>
where
V: Hash + Eq,
S: BuildHasher,
{
fn eq(&self, other: &Self) -> bool {
self.0.eq(&other.0)
}
}

impl<V, S> Eq for IndexSet<V, S>
where
V: Eq + Hash,
S: BuildHasher,
{
}

impl<V, S> FromIterator<V> for IndexSet<V, S>
where
V: Hash + Eq,
S: BuildHasher + Default,
{
fn from_iter<T: IntoIterator<Item = V>>(iter: T) -> Self {
Self(indexmap::IndexSet::from_iter(iter))
}
}

impl<V, S> Deref for IndexSet<V, S>
where
S: BuildHasher,
{
type Target = indexmap::IndexSet<V, S>;
fn deref(&self) -> &Self::Target {
&self.0
}
}

impl<V, S> DerefMut for IndexSet<V, S>
where
S: BuildHasher,
{
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}

unsafe impl<V, S> Update for IndexSet<V, S>
where
V: Update + Eq + Hash,
S: BuildHasher,
{
unsafe fn maybe_update(old_pointer: *mut Self, new_set: Self) -> bool {
let old_set = unsafe { &mut *old_pointer };
if old_set == &new_set {
false
} else {
old_set.clear();
old_set.0.extend(new_set.0);
true
}
}
}
14 changes: 6 additions & 8 deletions crates/common2/src/input.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use std::collections::BTreeSet;

use camino::Utf8PathBuf;
use smol_str::SmolStr;

use crate::InputDb;
use crate::{indexmap::IndexSet, InputDb};

/// An ingot is a collection of files which are compiled together.
/// Ingot can depend on other ingots.
Expand All @@ -23,12 +21,12 @@ pub struct InputIngot {

/// A list of ingots which the current ingot depends on.
#[return_ref]
pub external_ingots: BTreeSet<IngotDependency>,
pub external_ingots: IndexSet<IngotDependency>,

/// A list of files which the current ingot contains.
#[return_ref]
#[set(__set_files_impl)]
pub files: BTreeSet<InputFile>,
pub files: IndexSet<InputFile>,

#[set(__set_root_file_impl)]
#[get(__get_root_file_impl)]
Expand All @@ -40,7 +38,7 @@ impl InputIngot {
path: &str,
kind: IngotKind,
version: Version,
external_ingots: BTreeSet<IngotDependency>,
external_ingots: IndexSet<IngotDependency>,
) -> InputIngot {
let path = Utf8PathBuf::from(path);
let root_file = None;
Expand All @@ -50,7 +48,7 @@ impl InputIngot {
kind,
version,
external_ingots,
BTreeSet::default(),
IndexSet::default(),
root_file,
)
}
Expand All @@ -63,7 +61,7 @@ impl InputIngot {

/// Set the list of files which the ingot contains.
/// All files must bee set before the ingot is used.
pub fn set_files(self, db: &mut dyn InputDb, files: BTreeSet<InputFile>) {
pub fn set_files(self, db: &mut dyn InputDb, files: IndexSet<InputFile>) {
self.__set_files_impl(db).to(files);
}

Expand Down
1 change: 1 addition & 0 deletions crates/common2/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod diagnostics;
pub mod indexmap;
pub mod input;

pub use input::{InputFile, InputIngot};
Expand Down
3 changes: 1 addition & 2 deletions crates/driver2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ description = "Provides Fe driver"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
salsa = { git = "https://github.com/salsa-rs/salsa", package = "salsa-2022" }
salsa = { git = "https://github.com/salsa-rs/salsa", rev = "a1bf3a6" }
codespan-reporting = "0.11"

hir = { path = "../hir", package = "fe-hir" }
common = { path = "../common2", package = "fe-common2" }
macros = { path = "../macros", package = "fe-macros" }
hir-analysis = { path = "../hir-analysis", package = "fe-hir-analysis" }
camino = "1.1.4"
clap = { version = "4.3", features = ["derive"] }
2 changes: 1 addition & 1 deletion crates/driver2/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub trait ToCsDiag {

impl<T> ToCsDiag for T
where
T: DiagnosticVoucher,
T: for<'db> DiagnosticVoucher<'db>,
{
fn to_cs(&self, db: &dyn DriverDb) -> cs_diag::Diagnostic<InputFile> {
let complete = self.to_complete(db.as_spanned_hir_db());
Expand Down
Loading
Loading