Skip to content

Commit

Permalink
feat: add env configuration for resolve depth (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
Millione authored Feb 23, 2024
1 parent 497c221 commit 9d2c0a7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
5 changes: 2 additions & 3 deletions pilota-build/src/codegen/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
fmt::fmt_file,
middle::context::{CrateId, DefLocation},
rir::{self, ItemPath},
Codegen, CodegenBackend, Context, DefId,
Codegen, CodegenBackend, Context, DefId, MAX_RESOLVE_DEPTH,
};

#[derive(Clone)]
Expand Down Expand Up @@ -161,7 +161,6 @@ where

fn collect_def_ids(&self, input: &[DefId]) -> FxHashMap<DefId, DefLocation> {
use crate::middle::ty::Visitor;
const MAX_RECURSION_DEPTH: usize = 64;
struct PathCollector<'a> {
map: &'a mut FxHashMap<DefId, DefLocation>,
cx: &'a Context,
Expand All @@ -180,7 +179,7 @@ where
map: &mut FxHashMap<DefId, DefLocation>,
mut depth: usize,
) {
if map.contains_key(&def_id) || depth > MAX_RECURSION_DEPTH {
if map.contains_key(&def_id) || depth > *MAX_RESOLVE_DEPTH {
return;
}
depth += 1;
Expand Down
7 changes: 7 additions & 0 deletions pilota-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ use salsa::Durability;
pub use symbol::{DefId, IdentName};
pub use tags::TagId;

lazy_static::lazy_static! {
pub(crate) static ref MAX_RESOLVE_DEPTH: usize = std::env::var("MAX_RESOLVE_DEPTH")
.ok()
.and_then(|s| s.parse().ok())
.unwrap_or(256);
}

pub trait MakeBackend: Sized {
type Target: CodegenBackend;
fn make_backend(self, context: Context) -> Self::Target;
Expand Down
5 changes: 2 additions & 3 deletions pilota-build/src/middle/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::{
symbol::{DefId, FileId, IdentName, Symbol},
tags::{EnumMode, TagId, Tags},
ty::{AdtDef, AdtKind, CodegenTy, Visitor},
Plugin,
Plugin, MAX_RESOLVE_DEPTH,
};

#[derive(Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Clone)]
Expand Down Expand Up @@ -272,7 +272,6 @@ impl ContextBuilder {
&self,
input: &[DefId],
) -> FxHashMap<DefId, DefLocation> {
const MAX_RECURSION_DEPTH: usize = 64;
struct PathCollector<'a> {
map: &'a mut FxHashMap<DefId, DefLocation>,
cx: &'a ContextBuilder,
Expand All @@ -291,7 +290,7 @@ impl ContextBuilder {
map: &mut FxHashMap<DefId, DefLocation>,
mut depth: usize,
) {
if map.contains_key(&def_id) || depth > MAX_RECURSION_DEPTH {
if map.contains_key(&def_id) || depth > *MAX_RESOLVE_DEPTH {
return;
}
depth += 1;
Expand Down

0 comments on commit 9d2c0a7

Please sign in to comment.