46 Commits
Author SHA1 Message Date
a60d994e25 Improve Performance of the Type System (#824)
* export the checker and ensure no methods or fields are exported

* make Checker reusable

* add PatchAndCheck method to Checker, and reuse it in visitors

* avoid unnecessary map and consolidate structs

* make all Nature methods use pointer-receiver

* added cache for type and nature information

* optimize type and nature checks

* more aggressively cache some partial results and add cheap checks

* cache reused values

* reduce copying in Nature by breaking down optional fields

* enforce use of cache

* improve ergonomics of FromType and NatureOf

* improve struct method fetching

* make cache private to Nature

* first iteration improving struct reflect caching

* cleaned up struct fields data

* improve caching of functions data

* simplify checker code

* simplify and remove dead code

* add checker benchmarks

* address PR comments and minor improvements

* rename from SetCache to Bind

* make the benchmarks more fair

* fix benchmark option not being applied

* move Cache to be argument instead of field

* merge FuncData into Optional

* rename Optional to TypeData

* simplify struct logic

* cache builtin numeric types

---------

Co-authored-by: Anton Medvedev <[email protected]>
2025-09-18 14:38:27 +02:00
Anton MedvedevandGitHub 037ef3dc3d Add expr.MaxNodes() option (#799)
* Add expr.MaxNodes() option

* Fix error message

* Add more tests and comments
2025-06-03 17:31:46 +02:00
Anton Medvedev 6c8437454d Update fuzz tests 2025-03-08 16:19:30 +01:00
45bc3f7595 refactor(conf): avoid type assertion in map case branch (#749)
Simplifies the code by using the type switch variable binding instead of
performing an additional type assertion.

Signed-off-by: Ville Vesilehto <[email protected]>
Co-authored-by: Anton Medvedev <[email protected]>
2025-03-07 16:42:00 +01:00
9dd86858e1 feat: add node budget and memory limits (#762)
* feat: add node budget and memory limits

Implement compile-time and runtime safeguards against deeply nested expressions:

- Add MaxNodes limit to track and limit AST node count during parsing
- Move MemoryBudget from VM to Config for better configurability
- Add node creation tracking in parser to enforce node budget
- Refactor node creation to check limits before allocation
- Add RunWithConfig to VM for passing memory budget settings
- Set reasonable defaults in Config (10000 nodes, 1M memory)
- Add comprehensive tests for both node and memory limits

This prevents stack overflows from malicious or poorly written expressions
by failing fast with clear error messages during compilation or runtime.

Signed-off-by: Ville Vesilehto <[email protected]>

* Update parser.go

Signed-off-by: Anton Medvedev <[email protected]>

---------

Signed-off-by: Ville Vesilehto <[email protected]>
Signed-off-by: Anton Medvedev <[email protected]>
Co-authored-by: Anton Medvedev <[email protected]>
2025-03-07 14:09:41 +01:00
Anton Medvedev a8aece8708 Drop types.StrictMap and add types.Extra to define additional keys 2024-08-28 22:47:47 +02:00
Anton MedvedevandGitHub d0aa2e9136 Improve types pkg (#668) 2024-06-05 01:14:25 +02:00
Anton MedvedevandGitHub c953d0dde1 Refactor types table (#667) 2024-06-04 00:08:01 +02:00
SergeyandGitHub 377d126756 expr.Operator passes before expr.Env caused error (#606) 2024-03-17 08:51:53 +01:00
Anton MedvedevandGitHub 46d295876f Add spans 2024-02-29 20:51:34 +01:00
Anton Medvedev 96c6ad6087 Refactor operator override to be purely patcher pkg 2024-02-17 19:56:28 +01:00
Anton Medvedev 8ab750f2a2 Move operator override patcher to correct pkg 2024-02-17 19:17:27 +01:00
Nikolay MatrosovandGitHub 0ebf2c2574 feat: Operator overload from Function (#408)
* feat: rewritten Operator overload from Function

* fix: add test
2024-02-17 14:33:07 +01:00
Anton MedvedevandGitHub 0d43107999 Add concat() builtin (#565)
* Add concat() builtin

* Use pkg deref in builtin

* Use pkg deref in checker

* Use pkg deref in types_table.go

* Use pkg deref in docgen.go

* Use pkg deref in vm
2024-02-16 22:32:35 +01:00
Vladimir FetisovandGitHub c7c060ff44 Fix operator overloading (#554) 2024-02-08 21:07:58 +01:00
Anton MedvedevandGitHub e7b1a64b58 Allow to override builtins (#522)
* Allow to override builtins

* Add :: syntax to access builtin in case of override
2024-01-13 15:56:49 +01:00
Anton Medvedev 1dca2cbdc2 Move ast.Function to builtin.Function 2023-12-29 21:04:25 +01:00
Anton Medvedev 551d2a7e0f Use expr-lang/expr 2023-12-03 21:53:01 +01:00
Anton Medvedev 32f5fde2eb Replace interface{} with any 2023-08-30 11:25:15 +02:00
Anton Medvedev 9a9cab2e4a Add sort builtin 2023-08-28 14:55:44 +02:00
Anton Medvedev eb03bcb945 Remove ExperimentalPipe() 2023-08-24 15:26:36 +02:00
Anton Medvedev 4ae978d384 Allow to disable builtins 2023-08-19 22:24:42 +02:00
Anton Medvedev 05e5837996 Do not allow to override builtin function 2023-08-18 14:43:24 +02:00
Anton Medvedev a012738292 Rename env to $env 2023-08-15 23:34:16 +02:00
Anton Medvedev bac96c2c29 Add expr.ExperimentalPipes() config 2023-08-15 15:39:59 +02:00
Anton Medvedev 67bd8e364d Add string() builtin 2023-08-14 13:06:29 +02:00
Anton Medvedev f1fa30776c Add AsAny() 2023-08-14 12:46:08 +02:00
mdmcconnellandGitHub 4e57a43464 env[] keyword implemented in parser (#382) 2023-07-12 11:01:19 +02:00
Anton Medvedev 12a40c72cb Flatten builtin opcodes in vm 2023-01-30 22:24:35 +01:00
Anton Medvedev 72a4ce18e9 Add len() builtin 2023-01-29 20:34:15 +01:00
Anton Medvedev 4b7c89eff1 Add expr.Function feature 2023-01-29 20:34:15 +01:00
VladandGitHub f4ad8e3fa0 Do operator check after env is set (#309) 2023-01-20 18:42:24 +01:00
Anton Medvedev 00d167a791 Move code duplicate to conf package 2022-11-10 21:21:38 +01:00
Anton Medvedev 97b2a9e16d Simplify ast.Visitor interface 2022-11-02 22:27:34 +01:00
Anton Medvedev b8346f98f1 Optimize method calls and builtins opcodes 2022-10-27 21:23:04 +02:00
Anton Medvedev 0b523f347e Sort imports 2022-10-22 13:39:04 +02:00
Anton Medvedev c19d6d15fc Refactor operator patcher 2022-10-22 13:30:57 +02:00
Anton Medvedev 2a34731b5a Add FieldByIndex optimization 2022-10-19 00:55:01 +02:00
Anton Medvedev 3c37cd4343 Fix cycle import 2022-10-18 23:07:30 +02:00
Anton Medvedev a28d1d704e Refactor getting field name 2022-10-18 22:53:52 +02:00
Anton Medvedev c4a3d22ff1 More fixes 2022-10-13 18:59:12 +02:00
Anton Medvedev da68511d23 Add vm/runtime package 2022-10-12 15:22:14 +02:00
Anton Medvedev bbbf771d5d Improve test coverage 2022-10-09 00:24:10 +02:00
Erik GeiserandGitHub 76ccb0a468 Allow renaming struct fields using struct tags (#251) 2022-10-06 11:12:49 +02:00
Anton Medvedev 887ea6b8c8 fix ambiguous embed struct reference 2020-05-10 15:16:43 +03:00
Anton Medvedev e5049dfda3 Make conf top-level package 2020-03-16 16:29:25 +03:00