Commit Graph

77 Commits

Author SHA1 Message Date
Lucas Servén Marín
5d0f3fb5ed builtins.go: fix builtinManifestJSONEx regression
This commit fixes a regression in std.manifestJsonEx that caused the
standard library function to error when the given value was an array.

Signed-off-by: Lucas Servén Marín <lserven@gmail.com>
2021-02-15 14:44:08 +01:00
Hanyu Cui
f742f2463e
Allow setting a different output stream than os.Stderr for std.trace (#514)
Allow std.trace output to other streams
2021-02-09 14:44:23 +01:00
Hanyu Cui
7d3bda3911
Add std. manifestJsonMinified (#492)
Pick up std changes in cpp and update builtinManifestJSONEx
2020-12-31 11:20:31 +01:00
Stanisław Barzowski
797bfd89ed Better handling of stack traces.
Fixes multiple issues with stack traces leading to missing
stack trace lines. Also, we no longer put builtin context
on the line which *calls* the builtin as if it was a part
of the builtin itself.

Code for stack trace handling was centralized. We no longer
need traceElement argument in ~every function. Now the stack
trace state is kept solely in the interpreter.
2020-11-21 15:36:05 +01:00
Stanisław Barzowski
fe28095772 Support for array comparison 2020-10-30 20:42:46 +01:00
Stanisław Barzowski
570101d43c Desugar locals in object comprehension.
Desugar the locals in object comprehensions
"traditionally" instead of handling them manually.

Object comprehensions allow the locals to depend
on the index variable which means that they are separate
for each field. It doesn't make sense to treat them as
a property of the whole object.

Fixes #358.
2020-10-22 14:54:50 +02:00
Stanisław Barzowski
8fcbda5b50 Linter 2020-08-13 21:06:34 +02:00
Stanisław Barzowski
a1f3af26dc Support strings in the builtin std.flatMap.
Fixes #438.
2020-07-28 19:50:22 +02:00
Benoit Gagnon
0856640baf Fix std.manifestJsonEx parameter names
documented as "value" and "indent" in the standard library reference
2020-07-17 21:36:14 +02:00
Weston McNamee
d767ab7bf5 fix(stdlib): 🐛 manifestJsonEx was escaping HTML
minimal repo: https://play.golang.org/p/GQBNMe6k_nm

https://stackoverflow.com/questions/28595664/how-to-stop-json-marshal-from-escaping-and\nminimal

fix proof: https://play.golang.org/p/SJM3KLkYW-

resolves #423
2020-06-13 21:59:31 +02:00
Weston McNamee
3563a21847 perf(stdlib): ️ implement manifestJsonEx as native Go
❯ make benchmark FILTER=Builtin_manifestJsonEx
go build ./cmd/jsonnet
./benchmark.sh Builtin_manifestJsonEx
Running Before Test... (10s)
Running After Test... (10s)
benchmark                               old ns/op     new ns/op     delta
Benchmark_Builtin_manifestJsonEx-16     22656394      7502016       -66.89%
2020-06-13 19:53:42 +02:00
Alexander Petrov
3bd1fb82ba
Throw an error on negative shifts (#421)
Throw an error on negative shifts
2020-06-12 20:42:02 +02:00
Stanisław Barzowski
2824579c7d Update cpp-jsonnet 2020-05-22 14:54:20 +02:00
Stanisław Barzowski
9ada769ce4 Make golangci-lint happy
Some of the suggestions are minor bug fixes (missing error handling).
2020-03-05 14:54:27 +01:00
Dave Cunningham
0e67cc3c68 Refactor to allow interleaving optional and positional params 2020-03-05 09:33:21 +01:00
Robert-André Mauchin
f5778853ed Prevent int overflow
Fix #376
2020-02-14 08:18:22 +01:00
Stanisław Barzowski
03f5ad2dc0 Add explicit bounds checks for bitwise operators 2020-02-02 13:28:29 +01:00
Wes McNamee
399a61ca31 feat: improve std.base64Decode performance 97%+ (#346)
feat: improve std.base64Decode performance 97%+

Provides a Go-native implementation of std.base64Decode and std.base64DecodeBytes

benchmark                                  old ns/op       new ns/op     delta
Benchmark_Builtin_base64Decode-16          10946388307     25004135      -99.77%
Benchmark_Builtin_base64DecodeBytes-16     6420742757      181513016     -97.17%

related to #111
2020-01-27 14:31:45 +01:00
Wes McNamee
e8bd3f4ff8 feat: improve stdlib base64 performance by 98.58%+
Implements std.base64 in native Go, improving performance

benchmark                                 old ns/op       new ns/op     delta
Benchmark_Builtin_base64-16               10805730974     23158636      -99.79%
Benchmark_Builtin_base64_bytearray-16     8682808704      123360964     -98.58%
2020-01-27 09:40:21 +01:00
Stanisław Barzowski
492503d13b Fix formatting 2020-01-26 22:21:59 +01:00
Wes McNamee
3b580145f4 feat: improve std.reverse performance by 73.39%
Implements std.reverse in native Go, improving performance

benchmark                        old ns/op     new ns/op     delta
Benchmark_Builtin_reverse-16     869191619     231309458     -73.39%

part of #111
2020-01-26 22:11:59 +01:00
Weston McNamee
27b4c60bc7 feat: Improve performance of substr by 84.44%
This pulls in the implementation of substr into native Go instead of interpretted Jsonnet.

benchmark                       old ns/op     new ns/op     delta
Benchmark_Builtin_substr-16     97121527      15115905      -84.44%

part of #111
2020-01-26 09:20:58 +01:00
Stanisław Barzowski
fe82a78401 Adaptive string representation
When adding long strings, don't copy them immediately. Instead
build long strings only when their contents are requested.

This allows to build a long string from parts, using a regular
operator+ in linear time. This lets users to worry much less
about using std.join etc.

If indexing the string is mixed with building it using operator+
the behavior can still be quadratic. We may want to address it in
a later change.
2020-01-04 23:28:21 +01:00
alldroll
8f0e634bb6 Disallow unary + on Object 2019-09-23 13:07:05 +02:00
alldroll
f00242da42 Add runtime check for binary +-* operations for numbers 2019-09-19 14:34:14 +01:00
Stanisław Barzowski
85fd887750 Unexport a bunch of symbols
Many things were exported for no particular reason.
2019-09-09 16:11:00 +02:00
Stanisław Barzowski
6490cb1973 Builtin implementation for std.sort
Sort is something that is highly optimized in most languages
and users can expect it to be fast. We can piggyback on
the Go implementation.

This change results in 100x speedup on bench.06.jsonnet.
2019-09-09 13:37:12 +02:00
Stanisław Barzowski
82f949e7fe Extract AST processing to separate packages
Making it independent from the jsonnet package breaks the circular
dependency during stdast generation.
2019-08-28 20:16:47 +01:00
Stanisław Barzowski
11e63b6703 Make golint happy (#296) 2019-07-24 13:02:12 -04:00
Stanisław Barzowski
3190aff1d4 Fix crash when using empty object comprehension (#301)
The object was not properly created when object comprehension
was empty.
2019-07-24 12:58:59 -04:00
Stanisław Barzowski
e5e27c0f01 Object field caching
This change adds caching to objects fields, i.e. now subsequent
references to an object field are going to be served from cache.

Cache is kept within an object. Objects created with operator +
start with a clean cache (they have to, because in general all
the fields may have changed their values due to late binding).

This change comes naturally with a change of structure of objects,
now valueObject is a concrete struct which keeps "uncachedObject"
which is roughly equivalent to old objects.
2019-07-23 21:57:36 +02:00
Stanisław Barzowski
83ed0b939f Proper env for obj locals in comprehensions
We didn't set the environment (upvalues) for objects
created as comprehensions - we set them for each field
separately, but that meant missing the locals.
2019-05-13 17:42:04 +02:00
Stanisław Barzowski
33b6dcfa53
Keep object locals only once in AST (#263)
Keep object locals only once in AST

For example this reduces the size of stdlib ast file
roughly 3x. Note that this change doesn't regenerate the stdlib,
so that the diff here is sane.

It is likely to slightly improve performance of code using
a lot of locals (~10% on bench.05.gen.jsonnet).

The desugaring is more strightforward now, and we're back
to desugaring each node exactly once.
2019-05-07 22:43:55 +02:00
Stanisław Barzowski
181c86d815 Add builtin implementation of std.split 2019-04-24 12:42:40 +02:00
Stanisław Barzowski
c1743b9a2a Add std.encodeUTF8 and std.decodeUTF8 2019-03-04 09:41:01 -05:00
Stanisław Barzowski
767f100fd6 std.parseJson - a builtin for parsing json 2018-12-13 13:45:39 -05:00
Dave Cunningham
b4603b0c32 match change to cpp version re: unrecognized native returning null 2018-07-19 14:32:32 -04:00
Dave Cunningham
2973e24152
Internal refactor to improve performance (#225)
* Internal refactor to improve performance
2018-06-01 10:52:20 -04:00
Stanisław Barzowski
530cf7b07c Implement operators == and != as builtins (#221)
People use these operators in tight loops, without even
thinking about it, and it's previous implementation required
multiple object lookups (std.), string comparisons (for types)
and multiple jsonnet function calls.

This change introduces builtin, efficient implementation.
It results in ~3x speedup in strContains benchmark that
Angus provided on Slack.

Additional benefit is that equals/primitiveEquals distinction
is now obsolete, which made things simpler for everyone.
2018-05-23 22:26:30 -04:00
Dave Cunningham
d9b833b8a0
Bump C++ version, implement std.trace, fix parsing of -$, update std (#224) 2018-05-23 22:24:12 -04:00
Marcelo Cantos
ed5f280c59 Apply golint recommendations (#196)
* Apply golint recommendations
2018-02-26 14:12:25 -05:00
Stanisław Barzowski
61b33d1a2a Fast, native implementation of strReplace 2018-01-31 15:27:59 -05:00
Stanisław Barzowski
d6623a98cb Oldest version known to work = Go 1.8, closes #177
It seems like it was broken on older compilers
since pregenerated stdlib AST.

It adds go 1.8.x to travis, so that we have a chance
of catching when our "known to work" no longer holds.
2018-01-18 12:48:20 -05:00
Dave Cunningham
7d821fde83 std.join silently steps over null (match std.jsonnet version) 2018-01-11 09:37:26 -05:00
Stanisław Barzowski
8ade994928 Efficient native implementation of std.join
It changes the behavior slightly - mixing strings
and arrays in join is no longer allowed.
2017-12-13 18:09:56 -05:00
Stanisław Barzowski
f7eea3b545 Native implementation of std.range 2017-12-08 17:17:17 -05:00
Liang Mingqiang
8f568c1115 remove escLocalFS (#150)
* remove escLocalFS

* update README
2017-11-10 09:55:22 -05:00
Liang Mingqiang
aeda6138e5 experiment dump ast to source code (#101)
* Add facility to dump part of Go heap as Go code.

* Generate stdlib AST as Go code

* Use hardcoded stdlib AST instead of parsing it
2017-11-07 23:31:11 -05:00
Dave Cunningham
f965f9ee04
For compatability, emit the \n within the library, not the cmd (#137)
* For compatability, emit the \n within the library, not the commandline tool
* Also add manifestString to library
2017-10-29 21:41:01 -04:00
Dave Cunningham
3eaf189897 Allow bitwise operations on floats, according to Spec (and Javascript behavior) 2017-10-26 20:26:16 -04:00