From 755a0a10e14c4fe4c2ff3b71af9f99d5d1a924cf Mon Sep 17 00:00:00 2001 From: shreyax Date: Mon, 19 Mar 2018 20:47:37 -0700 Subject: Automated rollback of commit 72d28f3efc2842510a34cacd930c0204143f7412. Fix skylark caching to properly include transitive dependencies when there is a diamond-like dependency in the loaded bzl files. Also add guards to make sure we're not attempting to cache skylark files that transitively request a dependency that is in error. *** Reason for rollback *** Looking for source of non-determinism *** Original change description *** Automated rollback of commit 7ba939dfd5df48903929e9c14ebd0449656403e4. *** Reason for rollback *** Likely cause for non-determinism in skyframe *** Original change description *** Cache SkylarkLookupImportValues in memory so that we don't recompute them multiple times. PiperOrigin-RevId: 189686604 --- .../skyframe/RecordingSkyFunctionEnvironment.java | 280 +++++++++++++++++++++ 1 file changed, 280 insertions(+) create mode 100644 src/main/java/com/google/devtools/build/skyframe/RecordingSkyFunctionEnvironment.java (limited to 'src/main/java/com/google/devtools/build/skyframe') diff --git a/src/main/java/com/google/devtools/build/skyframe/RecordingSkyFunctionEnvironment.java b/src/main/java/com/google/devtools/build/skyframe/RecordingSkyFunctionEnvironment.java new file mode 100644 index 0000000000..115fea1a7f --- /dev/null +++ b/src/main/java/com/google/devtools/build/skyframe/RecordingSkyFunctionEnvironment.java @@ -0,0 +1,280 @@ +// Copyright 2018 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package com.google.devtools.build.skyframe; + +import com.google.devtools.build.lib.events.ExtendedEventHandler; +import com.google.devtools.build.lib.util.GroupedList; +import com.google.devtools.build.skyframe.SkyFunction.Environment; +import java.util.Map; +import java.util.function.Consumer; +import javax.annotation.Nullable; + +/** An environment that can observe the deps requested through getValue(s) calls. */ +public class RecordingSkyFunctionEnvironment implements Environment { + + private final Environment delegate; + private final Consumer skyKeyReceiver; + private final Consumer> skyKeysReceiver; + private final Consumer exceptionReceiver; + + public RecordingSkyFunctionEnvironment( + Environment delegate, + Consumer skyKeyReceiver, + Consumer> skyKeysReceiver, + Consumer exceptionReceiver) { + this.delegate = delegate; + this.skyKeyReceiver = skyKeyReceiver; + this.skyKeysReceiver = skyKeysReceiver; + this.exceptionReceiver = exceptionReceiver; + } + + private void recordDep(SkyKey key) { + skyKeyReceiver.accept(key); + } + + @SuppressWarnings("unchecked") // Cast Iterable to Iterable. + private void recordDeps(Iterable keys) { + skyKeysReceiver.accept((Iterable) keys); + } + + private void noteException(Exception e) { + exceptionReceiver.accept(e); + } + + public Environment getDelegate() { + return delegate; + } + + @Nullable + @Override + public SkyValue getValue(SkyKey valueName) throws InterruptedException { + recordDep(valueName); + return delegate.getValue(valueName); + } + + @Nullable + @Override + public SkyValue getValueOrThrow(SkyKey depKey, Class exceptionClass) + throws E, InterruptedException { + recordDep(depKey); + try { + return delegate.getValueOrThrow(depKey, exceptionClass); + } catch (Exception e) { + noteException(e); + throw e; + } + } + + @Nullable + @Override + public SkyValue getValueOrThrow( + SkyKey depKey, Class exceptionClass1, Class exceptionClass2) + throws E1, E2, InterruptedException { + recordDep(depKey); + try { + return delegate.getValueOrThrow(depKey, exceptionClass1, exceptionClass2); + } catch (Exception e) { + noteException(e); + throw e; + } + } + + @Nullable + @Override + public + SkyValue getValueOrThrow( + SkyKey depKey, + Class exceptionClass1, + Class exceptionClass2, + Class exceptionClass3) + throws E1, E2, E3, InterruptedException { + recordDep(depKey); + try { + return delegate.getValueOrThrow(depKey, exceptionClass1, exceptionClass2, exceptionClass3); + } catch (Exception e) { + noteException(e); + throw e; + } + } + + @Nullable + @Override + public + SkyValue getValueOrThrow( + SkyKey depKey, + Class exceptionClass1, + Class exceptionClass2, + Class exceptionClass3, + Class exceptionClass4) + throws E1, E2, E3, E4, InterruptedException { + recordDep(depKey); + try { + return delegate.getValueOrThrow( + depKey, exceptionClass1, exceptionClass2, exceptionClass3, exceptionClass4); + } catch (Exception e) { + noteException(e); + throw e; + } + } + + @Nullable + @Override + public < + E1 extends Exception, + E2 extends Exception, + E3 extends Exception, + E4 extends Exception, + E5 extends Exception> + SkyValue getValueOrThrow( + SkyKey depKey, + Class exceptionClass1, + Class exceptionClass2, + Class exceptionClass3, + Class exceptionClass4, + Class exceptionClass5) + throws E1, E2, E3, E4, E5, InterruptedException { + recordDep(depKey); + try { + return delegate.getValueOrThrow( + depKey, + exceptionClass1, + exceptionClass2, + exceptionClass3, + exceptionClass4, + exceptionClass5); + } catch (Exception e) { + noteException(e); + throw e; + } + } + + @Override + public Map getValues(Iterable depKeys) throws InterruptedException { + recordDeps(depKeys); + return delegate.getValues(depKeys); + } + + @Override + public Map> getValuesOrThrow( + Iterable depKeys, Class exceptionClass) throws InterruptedException { + recordDeps(depKeys); + try { + return delegate.getValuesOrThrow(depKeys, exceptionClass); + } catch (Exception e) { + noteException(e); + throw e; + } + } + + @Override + public + Map> getValuesOrThrow( + Iterable depKeys, Class exceptionClass1, Class exceptionClass2) + throws InterruptedException { + recordDeps(depKeys); + try { + return delegate.getValuesOrThrow(depKeys, exceptionClass1, exceptionClass2); + } catch (Exception e) { + noteException(e); + throw e; + } + } + + @Override + public + Map> getValuesOrThrow( + Iterable depKeys, + Class exceptionClass1, + Class exceptionClass2, + Class exceptionClass3) + throws InterruptedException { + recordDeps(depKeys); + try { + return delegate.getValuesOrThrow(depKeys, exceptionClass1, exceptionClass2, exceptionClass3); + } catch (Exception e) { + noteException(e); + throw e; + } + } + + @Override + public + Map> getValuesOrThrow( + Iterable depKeys, + Class exceptionClass1, + Class exceptionClass2, + Class exceptionClass3, + Class exceptionClass4) + throws InterruptedException { + recordDeps(depKeys); + try { + return delegate.getValuesOrThrow( + depKeys, exceptionClass1, exceptionClass2, exceptionClass3, exceptionClass4); + } catch (Exception e) { + noteException(e); + throw e; + } + } + + @Override + public < + E1 extends Exception, + E2 extends Exception, + E3 extends Exception, + E4 extends Exception, + E5 extends Exception> + Map> getValuesOrThrow( + Iterable depKeys, + Class exceptionClass1, + Class exceptionClass2, + Class exceptionClass3, + Class exceptionClass4, + Class exceptionClass5) + throws InterruptedException { + recordDeps(depKeys); + try { + return delegate.getValuesOrThrow( + depKeys, + exceptionClass1, + exceptionClass2, + exceptionClass3, + exceptionClass4, + exceptionClass5); + } catch (Exception e) { + noteException(e); + throw e; + } + } + + @Override + public boolean valuesMissing() { + return delegate.valuesMissing(); + } + + @Override + public ExtendedEventHandler getListener() { + return delegate.getListener(); + } + + @Override + public boolean inErrorBubblingForTesting() { + return delegate.inErrorBubblingForTesting(); + } + + @Nullable + @Override + public GroupedList getTemporaryDirectDeps() { + return delegate.getTemporaryDirectDeps(); + } +} -- cgit v1.2.3