Commit Graph

92 Commits

Author SHA1 Message Date
Dave Cunningham
c1825dc54d Update to latest CPP version 2022-10-26 16:13:21 +01:00
Jayme Bird
3aab052ecc fix: use rune for length over string 2022-10-25 19:30:01 +01:00
Jayme Bird
59e5a7be3f feat: add builtin stripChars go impl 2022-10-25 16:22:34 +01:00
Jayme Bird
dbe6fa55d8 feat: add builtin rStripChars go impl 2022-10-25 16:22:34 +01:00
Jayme Bird
bb0d8a9d2a feat: add builtin lStripChars go impl 2022-10-25 16:22:34 +01:00
Jayme Bird
c8492297df feat: add builtin member go impl 2022-10-25 16:22:34 +01:00
Jesse
2655afd2bd
memory align structs (#635)
feat: align most structs and add lint rule to enforce struct alignment
2022-10-19 06:19:15 +01:00
Jayme Bird
8abb4aa639 feat: implementation of manifestTomlEx in Go
Co-authored-by: Wojciech Kocjan <wojciech@kocjan.org>
2022-10-19 04:50:41 +01:00
Jesse-Cameron
b82fd4c7f5 fix: calculate the number of elements after we convert to a slice 2022-09-27 21:46:37 +01:00
Jesse-Cameron
e9a59202cf perf: use native builtin for foldl and foldr
benchmark                                 old ns/op      new ns/op      delta
Benchmark_Builtin_substr-8                17914126       16328579       -8.85%
Benchmark_Builtin_reverse-8               360776847      346691957      -3.90%
Benchmark_Builtin_parseInt-8              8686867        8314151        -4.29%
Benchmark_Builtin_base64Decode-8          22157223       21749268       -1.84%
Benchmark_Builtin_base64DecodeBytes-8     281975629      281841745      -0.05%
Benchmark_Builtin_base64-8                23824149       23716470       -0.45%
Benchmark_Builtin_base64_byte_array-8     141846327      141377054      -0.33%
Benchmark_Builtin_manifestJsonEx-8        9317781        9279067        -0.42%
Benchmark_Builtin_comparison-8            128783954      128362069      -0.33%
Benchmark_Builtin_comparison2-8           2082396660     2029123362     -2.56%
Benchmark_Builtin_foldl-8                 159908963      31278937       -80.44%
2022-09-27 21:46:37 +01:00
Jesse-Cameron
c450a168d4 perf: add size hint to map creation
in order to avoid unnecessary hashmap resizing, add size parameters when
creating maps
2022-09-16 18:26:18 +01:00
Jayme Bird
5440cc833f feat: add test data 2022-09-04 15:59:03 +01:00
Jayme Bird
6e180a9368 feat: add go implementation of std.parseInt 2022-09-04 15:59:03 +01:00
Jack Dockerty
9e9321f69a add non-negative check in second parameter for subStr 2022-03-18 02:06:06 +00:00
Greg Roodt
e6a9581713
Adds std.parseYaml (#339)
Add support for std.parseYaml.

Co-authored-by: Stanisław Barzowski <stanislaw.barzowski@gmail.com>
2021-05-20 14:16:23 +02:00
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