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

Remove the global TypeEngine in favor of adding it to the TypeCheckContext #2483

Closed
wants to merge 12 commits into from
5 changes: 3 additions & 2 deletions forc-pkg/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{
sync::Arc,
};

use sway_core::{parse, TreeType};
use sway_core::{parse, type_system::TypeEngine, TreeType};
use sway_utils::constants;

type PatchMap = BTreeMap<String, Dependency>;
Expand Down Expand Up @@ -182,7 +182,8 @@ impl ManifestFile {
/// Parse and return the associated project's program type.
pub fn program_type(&self) -> Result<TreeType> {
let entry_string = self.entry_string()?;
let parse_res = parse(entry_string, None);
let type_engine = TypeEngine::default();
let parse_res = parse(entry_string, None, &type_engine);
match parse_res.value {
Some(parse_program) => Ok(parse_program.kind),
None => bail!(parsing_failed(&self.project.name, parse_res.errors)),
Expand Down
17 changes: 12 additions & 5 deletions forc-pkg/src/pkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ use std::{
str::FromStr,
};
use sway_core::{
semantic_analysis::namespace, source_map::SourceMap, types::*, BytecodeCompilationResult,
CompileAstResult, CompileError, CompileResult, ParseProgram, TreeType,
semantic_analysis::namespace, source_map::SourceMap, type_system::TypeEngine, types::*,
BytecodeCompilationResult, CompileAstResult, CompileError, CompileResult, ParseProgram,
TreeType,
};
use sway_types::JsonABI;
use sway_utils::constants;
Expand Down Expand Up @@ -1932,18 +1933,19 @@ pub fn check(
sway_core::clear_lazy_statics();
let mut namespace_map = Default::default();
let mut source_map = SourceMap::new();
let type_engine = TypeEngine::default();
for (i, &node) in plan.compilation_order.iter().enumerate() {
let dep_namespace = dependency_namespace(&namespace_map, &plan.graph, node);
let pkg = &plan.graph[node];
let manifest = &plan.manifest_map()[&pkg.id()];
let parsed_result = parse(manifest, silent_mode)?;
let parsed_result = parse(manifest, silent_mode, &type_engine)?;

let parse_program = match &parsed_result.value {
None => bail!("unable to parse"),
Some(program) => program,
};

let ast_result = sway_core::parsed_to_ast(parse_program, dep_namespace);
let ast_result = sway_core::parsed_to_ast(parse_program, dep_namespace, &type_engine);

let typed_program = match &ast_result {
CompileAstResult::Failure { .. } => bail!("unable to type check"),
Expand All @@ -1968,14 +1970,19 @@ pub fn check(
pub fn parse(
manifest: &ManifestFile,
silent_mode: bool,
type_engine: &TypeEngine,
) -> anyhow::Result<CompileResult<ParseProgram>> {
let profile = BuildProfile {
silent: silent_mode,
..BuildProfile::debug()
};
let source = manifest.entry_string()?;
let sway_build_config = sway_build_config(manifest.dir(), &manifest.entry_path(), &profile)?;
Ok(sway_core::parse(source, Some(&sway_build_config)))
Ok(sway_core::parse(
source,
Some(&sway_build_config),
type_engine,
))
}

/// Attempt to find a `Forc.toml` with the given project name within the given directory.
Expand Down
Loading