-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Fold compound expressions with literal arguments into literals #5279
Conversation
Example generated code for a color curve with beforefunction e4() { return "red" }
var v5 = [e4];
function e6() { return $this.toColor(v5) } aftervar v4 = (new $this.Color(1, 0, 0, 1));
function e5() { return v4 } |
aced1fb
to
31a20a7
Compare
Very cool! |
31a20a7
to
0567a8f
Compare
Rebased, generalized, and updated benchmarks. |
@@ -13,7 +13,6 @@ const { | |||
toString, | |||
checkSubtype} = require('./types'); | |||
const {Color, typeOf} = require('./values'); | |||
const Curve = require('./definitions/curve'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason for these changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Breaking a new dependency cycle, which was introduced by parse_expression
now depending on evaluation_context
. I guess it's better to break it there instead (especially since we're already doing so in that module)
} | ||
|
||
if (typeof this.value === 'object' && this.value !== null) { | ||
const v = ctx.addVariable(value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: return ctx.addVariable(value);
@@ -68,4 +87,21 @@ function parseExpression(expr: mixed, context: ParsingContext): ?Expression { | |||
} | |||
} | |||
|
|||
const nonConstantExpressions = [ 'error', 'get', 'has', 'properties', 'id', 'geometry-type', 'zoom' ]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks similar to isFeatureConstant
/isZoomConstant
. Can they share more code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 I almost did that, and then stopped myself because I thought I was prematurely abstracting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, actually the code itself is a bit different. isConstant
only looks one level deep (because that's sufficient for the way we're using it). We could consolidate the base case code, though
0567a8f
to
c027323
Compare
@jfirebaugh updated to address your notes/questions |
When parsing an expression, if its arguments are all Literals, then evaluate it immediately and yield a Literal instead.
Yields a modest perf improvement in
tile_layout_dds
:More importantly, this means we get validation errors at compile time rather than evaluation time for the common case of color curves defined like
[curve, [linear], [zoom], 0, "red", 10, "bleu mispelled"]