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

Restart at most once when prepopulating repository rule environment #20434

Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -516,43 +516,55 @@ public String toString() {
* potentially more expensive operations.
*/
// TODO(wyv): somehow migrate this to the base context too.
public void enforceLabelAttributes() throws EvalException, InterruptedException {
public void enforceLabelAttributes() throws EvalException, InterruptedException, NeedsSkyframeRestartException {
// TODO: If a labels fails to resolve to an existing regular file, we do not add a dependency on
// that fact - if the file is created later or changes its type, it will not trigger a rerun of
// the repository function.
StructImpl attr = getAttr();
// Batch restarts as they are expensive
boolean needsRestart = false;
for (String name : attr.getFieldNames()) {
Object value = attr.getValue(name);
if (value instanceof Label) {
dependOnLabelIgnoringErrors((Label) value);
if (dependOnLabelIgnoringErrors((Label) value)) {
needsRestart = true;
}
}
if (value instanceof Sequence) {
for (Object entry : (Sequence) value) {
if (entry instanceof Label) {
dependOnLabelIgnoringErrors((Label) entry);
if (dependOnLabelIgnoringErrors((Label) entry)) {
needsRestart = true;
}
}
}
}
if (value instanceof Dict) {
for (Object entry : ((Dict) value).keySet()) {
if (entry instanceof Label) {
dependOnLabelIgnoringErrors((Label) entry);
if (dependOnLabelIgnoringErrors((Label) entry)) {
needsRestart = true;
}
}
}
}
}

if (needsRestart) {
throw new NeedsSkyframeRestartException();
}
}

private void dependOnLabelIgnoringErrors(Label label)
throws InterruptedException, NeedsSkyframeRestartException {
private boolean dependOnLabelIgnoringErrors(Label label) throws InterruptedException {
try {
getPathFromLabel(label);
} catch (NeedsSkyframeRestartException e) {
throw e;
return true;
} catch (EvalException e) {
// EvalExceptions indicate labels not referring to existing files. This is fine,
// as long as they are never resolved to files in the execution of the rule; we allow
// non-strict rules.
}
return false;
}
}
Loading