-
Notifications
You must be signed in to change notification settings - Fork 156
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
fix: Correct several issues found during #4740 #4786
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
624fe9b
feat: Add a wrapper around flux's error which uses the prettier strin…
1ad39d2
chore: Print prettier errors when failing to compile the standard lib…
0721e81
feat: Allow an AnalyzerConfig to be passed when compiling the standar…
8565e27
refactor: Allow matching on MonoType::STRING etc
d4de31a
feat: Allow labels to be parsed in types
a66fe1a
fix: Allow label types to be in the exported API of a package
6a75277
fix: Don't display bound and unbound variables the same in record's t…
bca63e0
chore: make generate
c9c149b
chore: Fix benchmark
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
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 | ||
---|---|---|---|---|
|
@@ -23,7 +23,7 @@ use crate::{ | |||
types::{ | ||||
MonoType, PolyType, PolyTypeHashMap, Record, RecordLabel, SemanticMap, Tvar, TvarKinds, | ||||
}, | ||||
Analyzer, PackageExports, | ||||
Analyzer, AnalyzerConfig, PackageExports, | ||||
}, | ||||
}; | ||||
|
||||
|
@@ -43,10 +43,16 @@ pub type SemanticPackageMap = SemanticMap<String, Package>; | |||
/// Infers the Flux standard library given the path to the source code. | ||||
/// The prelude and the imports are returned. | ||||
#[allow(clippy::type_complexity)] | ||||
pub fn infer_stdlib_dir(path: &Path) -> Result<(PackageExports, Packages, SemanticPackageMap)> { | ||||
pub fn infer_stdlib_dir( | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the second argument needs to be supplied here as well. else it will return an error. flux/libflux/flux/benches/basic.rs Line 30 in 5a828bd
|
||||
path: &Path, | ||||
config: AnalyzerConfig, | ||||
) -> Result<(PackageExports, Packages, SemanticPackageMap)> { | ||||
let ast_packages = parse_dir(path)?; | ||||
|
||||
let mut infer_state = InferState::default(); | ||||
let mut infer_state = InferState { | ||||
config, | ||||
..InferState::default() | ||||
}; | ||||
let prelude = infer_state.infer_pre(&ast_packages)?; | ||||
infer_state.infer_std(&ast_packages, &prelude)?; | ||||
|
||||
|
@@ -75,29 +81,35 @@ pub fn parse_dir(dir: &Path) -> io::Result<ASTPackageMap> { | |||
// to work with either separator. | ||||
normalized_path = normalized_path.replace('\\', "/"); | ||||
} | ||||
files.push(parser::parse_string( | ||||
let source = fs::read_to_string(entry.path())?; | ||||
let ast = parser::parse_string( | ||||
normalized_path | ||||
.rsplitn(2, "/stdlib/") | ||||
.collect::<Vec<&str>>()[0] | ||||
.to_owned(), | ||||
&fs::read_to_string(entry.path())?, | ||||
)); | ||||
&source, | ||||
); | ||||
files.push((source, ast)); | ||||
} | ||||
} | ||||
} | ||||
Ok(ast_map(files)) | ||||
} | ||||
|
||||
// Associates an import path with each file | ||||
fn ast_map(files: Vec<ast::File>) -> ASTPackageMap { | ||||
fn ast_map(files: Vec<(String, ast::File)>) -> ASTPackageMap { | ||||
files | ||||
.into_iter() | ||||
.fold(ASTPackageMap::new(), |mut acc, file| { | ||||
.fold(ASTPackageMap::new(), |mut acc, (source, file)| { | ||||
let path = file.name.rsplitn(2, '/').collect::<Vec<&str>>()[1].to_string(); | ||||
acc.insert( | ||||
path.clone(), | ||||
ast::Package { | ||||
base: ast::BaseNode { | ||||
location: ast::SourceLocation { | ||||
source: Some(source), | ||||
..ast::SourceLocation::default() | ||||
}, | ||||
..ast::BaseNode::default() | ||||
}, | ||||
path, | ||||
|
@@ -154,6 +166,7 @@ struct InferState { | |||
// types available for import | ||||
imports: Packages, | ||||
sem_pkg_map: SemanticPackageMap, | ||||
config: AnalyzerConfig, | ||||
} | ||||
|
||||
impl InferState { | ||||
|
@@ -241,8 +254,13 @@ impl InferState { | |||
.ok_or_else(|| anyhow!(r#"package import "{}" not found"#, name))?; | ||||
|
||||
let env = Environment::new(prelude.into()); | ||||
let mut analyzer = Analyzer::new_with_defaults(env, &mut self.imports); | ||||
let (exports, sem_pkg) = analyzer.analyze_ast(file).map_err(|err| err.error)?; | ||||
let mut analyzer = Analyzer::new(env, &mut self.imports, self.config.clone()); | ||||
let (exports, sem_pkg) = analyzer.analyze_ast(file).map_err(|mut err| { | ||||
if err.error.source.is_none() { | ||||
err.error.source = file.base.location.source.clone(); | ||||
} | ||||
err.error.pretty_error() | ||||
})?; | ||||
|
||||
Ok((exports, sem_pkg)) | ||||
} | ||||
|
@@ -342,7 +360,7 @@ pub fn stdlib(dir: &Path) -> Result<(PackageExports, FileSystemImporter<StdFS>)> | |||
|
||||
/// Compiles the stdlib found at the srcdir into the outdir. | ||||
pub fn compile_stdlib(srcdir: &Path, outdir: &Path) -> Result<()> { | ||||
let (_, imports, mut sem_pkgs) = infer_stdlib_dir(srcdir)?; | ||||
let (_, imports, mut sem_pkgs) = infer_stdlib_dir(srcdir, AnalyzerConfig::default())?; | ||||
// Write each file as compiled module | ||||
for (path, exports) in &imports { | ||||
if let Some(code) = sem_pkgs.remove(path) { | ||||
|
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
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.
the second argument needs to be supplied here as well. else it will return an error.
flux/libflux/flux/benches/basic.rs
Line 30 in 5a828bd