-
Notifications
You must be signed in to change notification settings - Fork 198
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
[experimental, for study purposes] salsa tracked core ingot input #1063
Draft
micahscopes
wants to merge
1
commit into
ethereum:master
Choose a base branch
from
micahscopes:load-core-experimental
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
use camino::Utf8PathBuf; | ||
use common::{ | ||
input::{IngotKind, Version}, | ||
InputDb, InputFile, InputIngot, | ||
}; | ||
use tracing::info; | ||
|
||
#[derive(rust_embed::RustEmbed)] | ||
#[folder = "../../library/core"] | ||
pub struct CoreLib; | ||
|
||
#[salsa::tracked] | ||
pub fn get_core_ingot(db: &dyn InputDb) -> InputIngot { | ||
InputIngot::new( | ||
db, | ||
"core", // this should be handled by the driver crate default behavior | ||
IngotKind::Core, | ||
Version::new(0, 0, 1), | ||
Default::default(), | ||
) | ||
} | ||
|
||
pub fn init_core_ingot(db: &mut dyn InputDb) -> InputIngot { | ||
info!("Loading std lib..."); | ||
|
||
// First collect all files and create the InputFiles | ||
let mut std_files = Vec::new(); | ||
let mut root_file = None; | ||
|
||
for path in CoreLib::iter() { | ||
let path: Utf8PathBuf = path.as_ref().into(); | ||
info!("Loading stdlib file: {}", path); | ||
|
||
if let Some(file) = CoreLib::get(path.as_str()) { | ||
if !path.starts_with("src") { | ||
continue; | ||
}; | ||
if let Ok(contents) = String::from_utf8(file.data.as_ref().to_vec()) { | ||
// Create InputFile with paths relative to std root | ||
let input_file = InputFile::new(db, path.clone().into(), contents); | ||
|
||
// Identify the root file (probably src/lib.fe or similar) | ||
if path.as_str() == "src/lib.fe" { | ||
root_file = Some(input_file); | ||
} | ||
|
||
std_files.push(input_file); | ||
} | ||
} | ||
} | ||
|
||
let core_ingot = get_core_ingot(db); | ||
// Set up the ingot structure | ||
if let Some(root) = root_file { | ||
core_ingot.set_root_file(db, root); | ||
} | ||
|
||
assert!(root_file.is_some(), "std library must have a root file"); | ||
|
||
// Add all files to the ingot | ||
core_ingot.set_files(db, std_files.into_iter().collect()); | ||
|
||
core_ingot | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::backend::db::LanguageServerDatabase; | ||
|
||
use super::*; | ||
|
||
#[test] | ||
fn is_core_deduplicated() { | ||
let mut db = LanguageServerDatabase::default(); | ||
let core_1 = get_core_ingot(&db); | ||
let core_2 = get_core_ingot(&db); | ||
|
||
let foo = InputFile::new(&db, "src/mod1/foo.fe".into(), "".into()); | ||
|
||
core_2.set_root_file(&mut db, foo); | ||
|
||
assert!(core_1.eq(&core_2)); | ||
assert!(core_1.root_file(&db).eq(&core_2.root_file(&db))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be better implemented in the driver of course, I just kept it here for this sketch