diff options
author | Yigit Boyar <yboyar@google.com> | 2016-03-25 18:26:31 -0700 |
---|---|---|
committer | Yigit Boyar <yboyar@google.com> | 2016-03-28 12:11:26 -0700 |
commit | f58c3bd412f9bdc5ec589fdcfed470889abb6ea6 (patch) | |
tree | 343eb0caa5dfb85d946e62072bd1e0a16e6d6f7c /compiler/src/main | |
parent | 11df39c91611b9ff2d7c87a9a9829251a015bccf (diff) | |
download | data-binding-f58c3bd412f9bdc5ec589fdcfed470889abb6ea6.tar.gz |
Fix expression evaluation problem
This CL fixes a bug in expression evaluator where we would
elevate a conditional dependency by mistake when it is not
read completely. This was caused by marking bit paths as
read in the same cycle.
There is still a potential bug in the code path where we
detect a variable would've already been calculated for a
dependency to be calculated (e.g. a ? a : b) but this
change is a fairly safe compared to making a big change
in that logic.
Bug: 895468
Change-Id: I60a704a59c3b5b8e4f833f060c6233d356dab6c8
Diffstat (limited to 'compiler/src/main')
3 files changed, 15 insertions, 12 deletions
diff --git a/compiler/src/main/java/android/databinding/tool/expr/Expr.java b/compiler/src/main/java/android/databinding/tool/expr/Expr.java index 768a59a5..42d98a19 100644 --- a/compiler/src/main/java/android/databinding/tool/expr/Expr.java +++ b/compiler/src/main/java/android/databinding/tool/expr/Expr.java @@ -553,7 +553,8 @@ abstract public class Expr implements VersionProvider, LocationScopeProvider { allCovered = false; break; } - final BitSet readForConditional = (BitSet) expr.findConditionalFlags().clone(); + final BitSet readForConditional = (BitSet) expr + .getShouldReadFlagsWithConditionals().clone(); // FIXME: this does not do full traversal so misses some cases // to calculate that conditional, i should've read /readForConditional/ flags diff --git a/compiler/src/main/java/android/databinding/tool/expr/ExprModel.java b/compiler/src/main/java/android/databinding/tool/expr/ExprModel.java index e9cdfab2..87169cee 100644 --- a/compiler/src/main/java/android/databinding/tool/expr/ExprModel.java +++ b/compiler/src/main/java/android/databinding/tool/expr/ExprModel.java @@ -589,15 +589,17 @@ public class ExprModel { } } } - for (Expr partialRead : markedSomeFlagsAsRead) { - // even if all paths are not satisfied, we can elevate certain conditional dependencies - // if all of their paths are satisfied. - for (Dependency dependency : partialRead.getDependants()) { - Expr dependant = dependency.getDependant(); - if (dependant.isConditional() && dependant.getAllCalculationPaths() - .areAllPathsSatisfied(partialRead.mReadSoFar)) { - if (dependant.considerElevatingConditionals(partialRead)) { - elevated = true; + if (!elevated) { + for (Expr partialRead : markedSomeFlagsAsRead) { + // even if all paths are not satisfied, we can elevate certain conditional + // dependencies if all of their paths are satisfied. + for (Dependency dependency : partialRead.getDependants()) { + Expr dependant = dependency.getDependant(); + if (dependant.isConditional() && dependant.getAllCalculationPaths() + .areAllPathsSatisfied(partialRead.mReadSoFar)) { + if (dependant.considerElevatingConditionals(partialRead)) { + elevated = true; + } } } } diff --git a/compiler/src/main/kotlin/android/databinding/tool/writer/LayoutBinderWriter.kt b/compiler/src/main/kotlin/android/databinding/tool/writer/LayoutBinderWriter.kt index 6147519b..30b2583d 100644 --- a/compiler/src/main/kotlin/android/databinding/tool/writer/LayoutBinderWriter.kt +++ b/compiler/src/main/kotlin/android/databinding/tool/writer/LayoutBinderWriter.kt @@ -207,7 +207,7 @@ val Expr.callbackLocalName by lazyProp { expr : Expr -> } val Expr.executePendingLocalName by lazyProp { expr : Expr -> - if(expr.needsLocalField) "${expr.model.ext.getUniqueName(expr.readableName, Scope.EXECUTE_PENDING_METHOD, false)}" + if(expr.isDynamic || expr.needsLocalField) "${expr.model.ext.getUniqueName(expr.readableName, Scope.EXECUTE_PENDING_METHOD, false)}" else expr.toCode().generate() } @@ -898,7 +898,7 @@ class LayoutBinderWriter(val layoutBinder : LayoutBinder) { if (model.flagMapping != null) { val mapping = model.flagMapping for (i in mapping.indices) { - tab("flag $i: ${mapping[i]}") + tab("flag $i (${longToBinary(1L + i)}): ${model.findFlagExpression(i)}") } } nl("flag mapping end*/") |