Commit Graph

526 Commits

Author SHA1 Message Date
Yiannis
bead95bfa6
Add linter support for std.strip and friends 2021-05-14 17:01:21 +02:00
Simon Let
415d036e5e Put AddPlusObject behind an option, rename FixPlusObject 2021-04-29 22:55:07 +02:00
Simon Let
be7a92aa5c jsonnetfmt: Add plus objects instead of removing them 2021-04-29 22:55:07 +02:00
Stanisław Barzowski
74b3a1b669 [Linter] Support std.member and std.repeat. 2021-03-25 18:35:13 +01:00
Leandro López
eeca44cd27 Allocate resulting slice size instead of dynamically growing it
We know for sure how big the resulting slice will be, so instead of
having Go perform checks and reallocations whenever the slice grows
too small by using `append` we calculate the resulting size earlier
and directly index each element into the output slice. This result in
only two allocations all the time, no matter how big the resulting
slice will be. With it also come big performance improvements:

name                                        old time/op    new time/op    delta
ToOrderedSlice/1_unique_identifiers-8          173ns ±10%     150ns ± 4%  -13.16%  (p=0.000 n=10+9)
ToOrderedSlice/10_unique_identifiers-8        1.24µs ± 6%    0.51µs ± 5%  -58.95%  (p=0.000 n=9+9)
ToOrderedSlice/100_unique_identifiers-8       20.4µs ±20%     4.0µs ± 5%  -80.25%  (p=0.000 n=10+9)
ToOrderedSlice/1000_unique_identifiers-8       253µs ± 9%      40µs ± 5%  -84.19%  (p=0.000 n=10+10)
ToOrderedSlice/10000_unique_identifiers-8     3.44ms ± 9%    0.37ms ± 5%  -89.32%  (p=0.000 n=9+9)
ToOrderedSlice/100000_unique_identifiers-8    48.6ms ±13%     3.6ms ± 4%  -92.49%  (p=0.000 n=10+10)

name                                        old alloc/op   new alloc/op   delta
ToOrderedSlice/1_unique_identifiers-8          40.0B ± 0%     40.0B ± 0%     ~     (all equal)
ToOrderedSlice/10_unique_identifiers-8          520B ± 0%      184B ± 0%  -64.62%  (p=0.000 n=10+10)
ToOrderedSlice/100_unique_identifiers-8       4.10kB ± 0%    1.82kB ± 0%  -55.75%  (p=0.000 n=10+10)
ToOrderedSlice/1000_unique_identifiers-8      32.8kB ± 0%    16.4kB ± 0%  -49.95%  (p=0.000 n=10+10)
ToOrderedSlice/10000_unique_identifiers-8      826kB ± 0%     164kB ± 0%  -80.16%  (p=0.000 n=10+10)
ToOrderedSlice/100000_unique_identifiers-8    9.25MB ± 0%    1.61MB ± 0%  -82.64%  (p=0.000 n=10+10)

name                                        old allocs/op  new allocs/op  delta
ToOrderedSlice/1_unique_identifiers-8           2.00 ± 0%      2.00 ± 0%     ~     (all equal)
ToOrderedSlice/10_unique_identifiers-8          6.00 ± 0%      2.00 ± 0%  -66.67%  (p=0.000 n=10+10)
ToOrderedSlice/100_unique_identifiers-8         9.00 ± 0%      2.00 ± 0%  -77.78%  (p=0.000 n=10+10)
ToOrderedSlice/1000_unique_identifiers-8        12.0 ± 0%       2.0 ± 0%  -83.33%  (p=0.000 n=10+10)
ToOrderedSlice/10000_unique_identifiers-8       21.0 ± 0%       2.0 ± 0%  -90.48%  (p=0.000 n=10+10)
ToOrderedSlice/100000_unique_identifiers-8      31.0 ± 0%       2.0 ± 0%  -93.55%  (p=0.000 n=10+10)

For ToSLice we use the same changes except the sort operation. In this
case the results are even more impressive: allocations are stable at
just 1 per operation, regardless of set size, and performance is
orders of magnitude faster:

name                                 old time/op    new time/op    delta
ToSlice/1_unique_identifiers-8         83.0ns ± 1%    92.4ns ± 0%    +11.37%  (p=0.000 n=9+8)
ToSlice/10_unique_identifiers-8         295ns ± 4%     749ns ± 3%   +154.21%  (p=0.000 n=10+10)
ToSlice/100_unique_identifiers-8       2.33µs ± 2%    4.28µs ± 2%    +83.62%  (p=0.000 n=9+8)
ToSlice/1000_unique_identifiers-8      25.4µs ±10%    34.7µs ± 1%    +36.51%  (p=0.000 n=10+10)
ToSlice/10000_unique_identifiers-8      215µs ± 2%     543µs ± 1%   +152.15%  (p=0.000 n=9+10)
ToSlice/100000_unique_identifiers-8    2.05ms ± 2%    7.17ms ± 1%   +249.53%  (p=0.000 n=9+9)

name                                 old alloc/op   new alloc/op   delta
ToSlice/1_unique_identifiers-8          16.0B ± 0%     16.0B ± 0%       ~     (all equal)
ToSlice/10_unique_identifiers-8          160B ± 0%      496B ± 0%   +210.00%  (p=0.000 n=10+10)
ToSlice/100_unique_identifiers-8       1.79kB ± 0%    4.08kB ± 0%   +127.68%  (p=0.000 n=10+10)
ToSlice/1000_unique_identifiers-8      16.4kB ± 0%    32.8kB ± 0%    +99.90%  (p=0.000 n=10+10)
ToSlice/10000_unique_identifiers-8      164kB ± 0%     826kB ± 0%   +404.12%  (p=0.000 n=8+10)
ToSlice/100000_unique_identifiers-8    1.61MB ± 0%    9.25MB ± 0%   +475.93%  (p=0.000 n=10+10)

name                                 old allocs/op  new allocs/op  delta
ToSlice/1_unique_identifiers-8           1.00 ± 0%      1.00 ± 0%       ~     (all equal)
ToSlice/10_unique_identifiers-8          1.00 ± 0%      5.00 ± 0%   +400.00%  (p=0.000 n=10+10)
ToSlice/100_unique_identifiers-8         1.00 ± 0%      8.00 ± 0%   +700.00%  (p=0.000 n=10+10)
ToSlice/1000_unique_identifiers-8        1.00 ± 0%     11.00 ± 0%  +1000.00%  (p=0.000 n=10+10)
ToSlice/10000_unique_identifiers-8       1.00 ± 0%     20.00 ± 0%  +1900.00%  (p=0.000 n=10+10)
ToSlice/100000_unique_identifiers-8      1.00 ± 0%     30.00 ± 0%  +2900.00%  (p=0.000 n=10+10)

Signed-off-by: Leandro López <leandro.lopez@grafana.com>
2021-03-25 15:44:43 +01:00
Leandro López
067dc391aa Add IdentifierSet.ToOrderedSlice and ToSlice benchmarks
This will be useful later on when implementing the performance
improvements to compare how much we gain.

Signed-off-by: Leandro López <leandro.lopez@grafana.com>
2021-03-25 15:44:43 +01:00
Hanyu Cui
63a452246d
Support different output streams than os.Stderr for std.trace (C API) (#520)
Support different output streams than os.Stderr for std.trace (C API)
2021-03-21 20:03:01 +01:00
Stanisław Barzowski
7d81091149
Linter README – replace unicode asterisks
I think they were an artifact of copying from a LaTeX-generated PDF.
2021-02-21 20:59:24 +01:00
Lucas Servén Marín
9b6cbef4ca testdata: std.manifestJsonEx text cases more types
This commit adds test cases for more types to ensure that
std.manifestJsonEx continues to work with all types that may be given
as the `value` parameter.

Signed-off-by: Lucas Servén Marín <lserven@gmail.com>
2021-02-15 14:44:08 +01:00
Lucas Servén Marín
9bba8deca0 testdata: add manifestJsonEx array test case
This commit adds a test case to prevent regressions in
std.manifestJsonEx accepting arrays as values.

Signed-off-by: Lucas Servén Marín <lserven@gmail.com>
2021-02-15 14:44:08 +01: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
Kumar Gaurav
4a3144a417 pre-commit hook to format jsonnet files 2021-02-06 14:47:43 +01:00
gotwarlost
6d6c293079 allow initialization of external and TLA code variables from an AST node.
This allows configuration of a VM with an external code variable that has been pre-parsed into an AST node.
This allows a caller to pre-parse a large object into a node and re-use that for multiple VMs. The cost
of converting the object to an ast.Node is incurred only once by the caller as opposed to having this
eagerly incurred (whether or not the object is used) before the eval.
2021-02-04 12:05:09 +01:00
Krishnan Anantheswaran
8a3fcc0302
Allow reset of ext and TLA vars for VM reuse (#509)
Allow reset of ext and TLA vars for VM reuse

Currently ext and TLA vars can be set but not reset. This makes
re-using VMs that have different variables impossible.

Add VM methods to be able to reset ext and TLA vars
2021-02-03 22:55:13 +01:00
Hanyu Cui
cd59751527
Distinguish go-jsonnet from cpp-jsonnet in version message (#497)
Distinguish the Go implementation in the version message
2021-01-13 20:46:15 +01:00
Stanisław Barzowski
31d71aaccd Add missing linter metadata for stdlib.
Fixes #483.
2021-01-01 19:17:40 +01:00
Stanisław Barzowski
6140a2f75a Better stacktrace for manifestation, +: and object assertions.
Fixes #282
2021-01-01 19:17:27 +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
4beab6633f Prevent keeping files open for too long.
Fixes #485.
2020-12-21 01:14:30 +01:00
Lucendio
fd65a61e87 Fix builds filter ro re-enable darwin builds
I was not able to find any evidences of darwin builds being disabled intentionally. Considering
the [documentation](https://goreleaser.com/customization/build/) I suspect that this was by
mistake. Currently, each list item is applied individually (OR). If I'm wrong, please discard this
PR and share your reasoning.
2020-12-12 23:49:31 +01:00
Kohei Suzuki
35acb29ff8 Add format APIs to C bindings 2020-11-26 19:23:49 +01:00
Kohei Suzuki
57e6137c93 Support creating VMs from multiple threads in C-bindings
Since all VM instances are managed by a global map, read/write of the
global map must be protected by a mutex.
2020-11-23 19:18:40 +01:00
Stanisław Barzowski
0d1d4cb812 Release 0.17.0 2020-11-22 15:45:52 +01:00
Stanisław Barzowski
5c08e370d3 Fix missing stack trace entry for assertions.
Fixes #467
2020-11-21 18:31:58 +01:00
Stanisław Barzowski
372c2ad732 Release GIL in Python bindings.
We apply the same changes as:
https://github.com/google/jsonnet/pull/814
2020-11-21 18:00:35 +01:00
Stanisław Barzowski
4f527c6f96 Add support for missing functions in C-bindings.
With this change we cover 100% of the C API.
2020-11-21 17:34:25 +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
e120148a45 Add a short script for updating cpp-jsonnet. 2020-11-21 15:26:25 +01:00
Stanisław Barzowski
2bc774a030 Update cpp-jsonnet. Stop changing cpp-jsonnet version in tests.sh. 2020-11-21 15:10:43 +01:00
Stanisław Barzowski
fe28095772 Support for array comparison 2020-10-30 20:42:46 +01:00
Zhongpeng Lin
eced33e88b Using cpp_jsonnet as external repo 2020-10-30 19:45:27 +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
Sargun Dhillon
6967a29721 Add debian package build to goreleaser
This makes the goreleaser output two debian packages. One for jsonnet,
and another for jsonnetfmt. Since we don't use cgo, we don't need to
take dependencies, as we're fully statically linked. The package
name for this package will be jsonnet-go, and jsonnetfmt-go. There
is a package that Ubuntu has released that's based on the C++
version. We have a conflict statement with it in order to
avoid people installing both.

We can ask the C++ package to rename itself to jsonnet-c++, and then
add a provides for the package name jsonnet. The reason to not name
this jsonnet immediately, even though the Go version if meant to
supercede the C++ version, is that this doesn't fully implement the
C++ version (for example, man pages).
2020-10-05 20:40:24 +02:00
Stanisław Barzowski
755ee1ee88 Change CI settings to use the latest release, but not the tip. 2020-10-05 20:39:32 +02:00
Stanisław Barzowski
b70cbd441a Anonymous Import Locations
We used to treat dummy paths like <stdin>, <std>, <extvar> as
real import locations, which causes obvious problem for importers.

After this change we consistently pass "" (an empty string) as location
for non-imported paths.

We exposed new functions to properly handle all paths.

The first function family, EvaluateFile* which allow evaluating
a Jsonnet program at a specified importable path. It should
be used in most cases.

The second function family, EvaluateAnonymousSnippet* allows evaluating
a snippet without an importable path. It should be used for situations
like the code passed as a commandline argument, stdin, etc.

The old function family, EvaluateSnippet* is now deprecated, but
works the same as before, i.e. the passed filenames are treated
as imported paths.

Changes are required to custom importers to make sure they satisfy
the refined contract.

Fixes #329.
2020-09-08 17:27:47 +02:00
Stanisław Barzowski
8fcbda5b50 Linter 2020-08-13 21:06:34 +02:00
Varun B Patil
2e346e53e7 jsonnet-deps: Jsonnet static dependency parser
Fixes #833
2020-08-08 19:59:36 +02:00
Paul Rudin
a631234631 add action to build binaries with goreleaser 2020-08-08 18:31:51 +02:00
Alexander Petrov
6a41464c6d issue-433 Address review comments: avoid indexing the map twice 2020-08-01 10:55:42 +02:00
Alexander Petrov
fc188d008d issue-433 avoid keeping all the allocated handles forever by using map
and uintptr of the allocated object.
2020-08-01 10:55:42 +02:00
Alexander Petrov
db2bf1e024 issue-433 increase the number of constructed Jsonnet handles. 2020-08-01 10:55:42 +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
Stanisław Barzowski
aaf50f5b65 Update project status in README.md 2020-07-03 17:34:29 +02:00
Stanisław Barzowski
0dd210d4a5 Sync cpp-jsonnet (for #429) 2020-07-02 23:05:04 +02:00
Robert Vollmert
9e6b0d15b7 jsonnetfmt --help: Indent subsection and break long lines
For consistency of the formatting changes to jsonnet --help.
Minor phrasing and punctuation changes for consistency.
2020-07-02 23:04:34 +02:00
Robert Vollmert
678df37686 jsonnet --help: align consistently, break long lines
This fits the help text into 80 columns.
2020-07-02 23:04:34 +02:00
Robert Vollmert
e71d28e7c2 jsonnet --help: separate sections more clearly 2020-07-02 23:04:34 +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