aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib
diff options
context:
space:
mode:
authorGravatar nharmata <nharmata@google.com>2018-03-08 16:43:45 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-03-08 16:45:57 -0800
commit62678a40664c9a43d3a05334156a3c6143127ed2 (patch)
tree443cec273b810b054818331a1699090e18c3bff4 /src/test/java/com/google/devtools/build/lib
parent55a748bb2469ecc9be40c525d3c0a979d75a0670 (diff)
Optimize GC churn of parameter bindings performed before each user defined function call.
This is the 2nd attempt at this commit. The first attempt (https://github.com/bazelbuild/bazel/commit/f1013485d41efd8503f9d4f937e17d1b4bc91ed3) was rolled back because it introduced the following two bugs: (1) The side effects of Environment#enterScope are relevant: it creates and stores a new Continuation that has a reference to the set currently referenced by 'knownGlobalVariables', and then overwrites the value of the variable. When there are e.g. nested function calls, 'knownGlobalVariables' will be wrong in the Environment used to stage the inner call (see the added test for an example). (2) The finally block in UserDefinedFunction#call assumes the env.enterScope was called. Because of the EvalException (incorrectly) thrown due to (1), this is no longer true. I restructured the code such that (2) isn't possible and I also added a unit test that would have caught the two bugs. In my first attempt, I was doing too much - I was also trying to save the CPU-costs in the env.update call (dispatches to the just-created lexical frame, and calls LexicalFrame#put, which does an unnecessary mutability sanity check, etc) and in doing so completely missed the above bugs. Sorry. RELNOTES: None PiperOrigin-RevId: 188411737
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib')
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/FunctionTest.java12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/FunctionTest.java b/src/test/java/com/google/devtools/build/lib/syntax/FunctionTest.java
index ff8dddc596..f91e2a8a72 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/FunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/FunctionTest.java
@@ -200,6 +200,18 @@ public class FunctionTest extends EvaluationTestCase {
}
@Test
+ public void testFunctionParamCanShadowGlobalVarAfterGlobalVarIsRead() throws Exception {
+ eval("a = 1",
+ "def func2(a):",
+ " return 0",
+ "def func1():",
+ " dummy = a",
+ " return func2(2)",
+ "b = func1()\n");
+ assertThat(lookup("b")).isEqualTo(0);
+ }
+
+ @Test
public void testSingleLineFunction() throws Exception {
eval("def func(): return 'a'",
"s = func()\n");