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

fix(lsp): Ensure stdlib is always added before the check_crate phase #1840

Merged
merged 1 commit into from
Jul 4, 2023
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 change: 0 additions & 1 deletion crates/nargo_cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ mod tests {
Box::new(acvm::pwg::default_is_opcode_supported(acvm::Language::R1CS)),
);
driver.create_local_crate(&root_file, CrateType::Binary);
crate::resolver::add_std_lib(&mut driver);

let result = driver.check_crate(false);
let success = result.is_ok();
Expand Down
11 changes: 1 addition & 10 deletions crates/nargo_cli/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
use acvm::{acir::circuit::Opcode, Language};
use nargo::manifest::{Dependency, PackageManifest};
use noirc_driver::Driver;
use noirc_frontend::graph::{CrateId, CrateName, CrateType};
use noirc_frontend::graph::{CrateId, CrateType};
use thiserror::Error;

use crate::{git::clone_git_repo, InvalidPackageError};
Expand Down Expand Up @@ -85,7 +85,6 @@ impl<'a> Resolver<'a> {
let pkg_root = manifest_path.parent().expect("Every manifest path has a parent.");
resolver.resolve_manifest(crate_id, manifest, pkg_root)?;

add_std_lib(&mut driver);
Ok(driver)
}

Expand Down Expand Up @@ -167,11 +166,3 @@ impl<'a> Resolver<'a> {
}
}
}

// This needs to be public to support the tests in `cli/mod.rs`.
pub(crate) fn add_std_lib(driver: &mut Driver) {
let std_crate_name = "std";
let path_to_std_lib_file = PathBuf::from(std_crate_name).join("lib.nr");
let std_crate = driver.create_non_local_crate(path_to_std_lib_file, CrateType::Library);
driver.propagate_dep(std_crate, &CrateName::new(std_crate_name).unwrap());
}
9 changes: 9 additions & 0 deletions crates/noirc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,15 @@ impl Driver {
/// This returns a (possibly empty) vector of any warnings found on success.
/// On error, this returns a non-empty vector of warnings and error messages, with at least one error.
pub fn check_crate(&mut self, deny_warnings: bool) -> Result<Warnings, ErrorsAndWarnings> {
// Add the stdlib before we check the crate
// TODO: This should actually be done when constructing the driver and then propagated to each dependency when added;
// however, the `create_non_local_crate` panics if you add the stdlib as the first crate in the graph and other
// parts of the code expect the `0` FileID to be the crate root. See also #1681
let std_crate_name = "std";
let path_to_std_lib_file = PathBuf::from(std_crate_name).join("lib.nr");
let std_crate = self.create_non_local_crate(path_to_std_lib_file, CrateType::Library);
self.propagate_dep(std_crate, &CrateName::new(std_crate_name).unwrap());

let mut errors = vec![];
CrateDefMap::collect_defs(LOCAL_CRATE, &mut self.context, &mut errors);

Expand Down
3 changes: 0 additions & 3 deletions crates/wasm/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ pub fn compile(args: JsValue) -> JsValue {
add_noir_lib(&mut driver, dependency.as_str());
}

// We are always adding std lib implicitly. It comes bundled with binary.
add_noir_lib(&mut driver, "std");

driver.check_crate(false).expect("Crate check failed");

if options.contracts {
Expand Down