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

Handle build hangs due to unintended template recursion. #539

Merged
merged 5 commits into from
Oct 25, 2021
Merged

Conversation

grv07
Copy link
Contributor

@grv07 grv07 commented Oct 7, 2021

Created a vector to keep track of source and extends dependency.
If the same dependency comes again throw the Err as there is some cyclic dependency between source and extends file.

Case 1: When there is a self-loop in dependency
self_loop

Case 2: When there is a cyclic dependency
cyclic_deps

@grv07 grv07 marked this pull request as ready for review October 7, 2021 18:21
Copy link
Owner

@djc djc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this!

let mut check = vec![(input.path.clone(), source)];
while let Some((path, source)) = check.pop() {
for n in parse(&source, input.syntax)? {
match n {
Node::Extends(Expr::StrLit(extends)) => {
let extends = input.config.find_template(extends, Some(&path))?;
let dependency_path = format!("{:?} --> {:?}", path, extends);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just store (path, &extends) in the dependency_graph, and only format when yielding an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review :)

dependency_graph is a vector of String, that can be easily converted to a tuple of (PathBuf, PathBuf)
but what my concern is that lifetime of dependency_graph , extends and path is diff so there will be compiler issues that extends/path does not live long enough when I will push values in the vector.

Please, let me know if I am missing something.

Copy link
Contributor Author

@grv07 grv07 Oct 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you referring to get the path and extends to String and push the owned String into the dependency_graph vector ?
In my opinion, it will not add much since we need the step to convert it into String format anyway.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have two concerns here:

  1. Should avoid unnecessary allocations outside the error path
  2. Would prefer to store structured data than "humanized" data

(PathBuf, PathBuf) seems like a fine option. It does look like both path and extends might be owned here anyway, such that we don't have to do extra allocations to store them in dependency_graph.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have done some changes pls take a look.

askama_derive/src/lib.rs Outdated Show resolved Hide resolved
@djc djc merged commit 028eb1c into djc:main Oct 25, 2021
@djc
Copy link
Owner

djc commented Oct 25, 2021

Thanks for fixing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants