Commit Graph
406 Commits
Author SHA1 Message Date
f96fba00e1 Add a CPU profiler (#1823)
This introduces a way to run CPU profiling.

The profiler produces output in pprof format.

CLI users can enable CPU profiling via command line flags.
Profiling is otherwise not offered as an API.

Co-authored-by: Jen Basch <jbasch94@gmail.com>
Co-authored-by: Islon Scherer <islonscherer@gmail.com>
2026-10-15 15:57:55 +00:00
Alexandre Kohler f4ad0da658 Fix lookaround regexes in String.lastIndexOf and replaceLast (#1908) 2026-10-13 11:32:12 -07:00
Daniel Chao f973fd6717 Change how VmValueRenderer renders Typed values (#1412)
This changes it to render the qualified name instead of the simple name.

* Module classes render the module name
* Classes within module render the module name and the class name joined by `#`
* Rendering of members of `pkl:base` does not change

For example:

* `new k8s.core.v1.Service {}` instead of `new ModuleClass {}`.
* `new k8s.core.v1.Service#ServiceSpec {}` instead of `new ServiceSpec {}`
* `new pkl.Project {}` instead of `new ModuleClass {}`

This affects the following:

* `toString()`
* `trace()`
* Error messages
* REPL
2026-10-08 13:32:26 -07:00
Vladimir Matveev 66fb5c133b Module cache directory propagation (#1900)
Currently the module cache directory in CLI commands (and thus in Gradle tasks, since they use CLI commands under the hood) is only used for the "primary" task. For example, for an eval command, the module cache directory will be used for the evaluation of the target module.

However, most commands also work with projects, and for projects the `PklProject` file must be evaluated. This is done via `Project.loadFromPath`, which internally builds an evaluator with the default module cache path. Therefore, all evaluations of project manifests always use default cache path instead of whatever is configured through the CLI option/Gradle task property. This, in turn, may result in unexpected behavior: in general, the user would expect that if they specify the cache directory, it will be used for all evaluations (e.g. when they pre-populate the cache and expect evaluations to work offline).

The same is true for settings evaluation, although for settings it is significantly less important since settings scripts can't have remote dependencies.

This PR propagates cache path into the project evaluator (as well as the settings evaluator, for consistency). This will result in the user-specified cache directory being used for `PklProject` evaluations as well.
2026-10-07 13:58:40 -07:00
Islon Scherer 862c61f2e2 Add net stdlib module with URL support (#1834) 2026-10-06 15:23:32 +02:00
Daniel Chao dbcecd9677 Fix decoding of pkl-binary into Java Pattern (#1895)
Patterns that originate from the language runtime will add
`Pattern.UNICODE_CHARACTER_CLASS | Pattern.UNICODE_CASE` as implicit
regex flags, so we need to do the same on the binary decoding side.
2026-10-05 09:09:30 -07:00
Daniel Chao ba25f4820c Perf improvements for String.endWith(Regex) (#1884)
* Compute a derived regex expression with `\z` anchor
* Ensure derived regex can't be messed up with comments (in extended mode) or quote start

Follow up to #1880
2026-10-05 09:09:03 -07:00
Jen Basch adaafc4045 Fix external reader process leak in pkl-server (#1885) 2026-10-02 14:16:25 -07:00
Daniel Chao 82fe176c69 Improve cases where type nodes can turn into TypeNode.UnionOfStringLiterals (#1875)
This adds logic to UnresolvedTypeNode to create a `UnionOfStringLiterals`
type node if a member is a typealias who is a string or a string literal union.

Also, this fixes an issue where marking a duplicate string literal with the
default marker throws an index out of bounds exception.
2026-10-02 09:16:25 -07:00
Daniel Chao b8c7a42318 Make typechecking more PE friendly (#1871)
This makes various improvements to help truffle do partial
evaluation of code related to typechecking.

* Split `UnionTypeNode` into `UnionTypeNodeExploded` and
 `UnionTypeNodeLooped` to avoid gigantic graphs. This especially helps
  in the case of typealiases, because they are inlined into their usage
  sites.

* Move constraint-failure exception construction in
  `TypeConstraintNode` behind `@TruffleBoundary` helper methods
  instead of `transferToInterpreterAndInvalidate`, since building the
  exception is a rare, off-hot-path operation.

* Move `ClassNode`'s one-time class-initialization logic behind a
  `@TruffleBoundary` method (`initClass`), store `VmLanguage` as a
  field instead of recomputing it via `VmLanguage.get(this)`, and use
  `transferToInterpreterAndInvalidate` since class init never needs to
  re-run on the compiled path.

* Pass `VmLanguage` explicitly into `TypeTestNode` and `ClassNode`
  (via `AstBuilder`) rather than resolving it with
  `VmLanguage.get(this)` on a hot path.

* Fix various issues where the partial evaluator determines that a frame
  should have been materialized but was not.

* Pre-initialize call targets in `ObjectMember.setMemberNode()` and
  `FunctionLiteralNode` so the first invocation doesn't trigger a
  compilation invalidation.

* Fix truffle node tree issues (don't mark `@RootNode` as child,
  deepCopy instead of passing an already adopted node).

* Remove unnecessary interpreter transfers when throwing type mismatch exceptions
2026-09-30 07:16:54 -07:00
Alexandre Kohler 8331570aaf Fix String.endsWith for overlapping regex matches (#1880) 2026-09-29 21:52:12 -07:00
Jen Basch 1271da2741 Fixes to commands where (sub)commands never extend pkl:Command (#1882) 2026-09-29 23:19:28 +00:00
Daniel Chao d1e043be4e Make join call overriden toString() (#1872)
This changes the `join` method in `List`/`Set`/`Listing` to
call the overridden `toString()` method.

This is a breaking change, but is considered a bugfix.
2026-09-25 09:24:16 -07:00
Daniel Chao 43e132a383 Fix "unchecked or unsafe operations" warning in javac (#1874)
Fix this printed warning during java compilation:

"Note: Some input files use unchecked or unsafe operations. Recompile with -Xlint:unchecked for details"

* Add `-Xlint:unchecked` as a javac flag
* Fix the various warnings
2026-09-24 09:28:49 -07:00
Daniel Chao 119b1571bb Switch ad-hoc vmobject building to use VmObjectBuilder (#1873) 2026-09-24 07:32:30 -07:00
Daniel Chao d5a7dc021e Switch inferred new {} expressions in method args to using frame slots (#1857)
This changes the logic for inferring `new {}` expressions in method
arguments to using regular frame slots, instead of auxiliary slots.

Overall, this is a performance improvement: no looking up auxiliary slot
numbers, which makes this code much more PE friendly.

* At parse time, get or create a frame slot that holds the method
* Introduce `ArgInfo` record (preserve primitive int) over using `Pair`
* Remove unneeded `isImplicitNewExpr` method; this is not needed because
  we can just keep track of the method slot on the frame descriptor
  builder.
2026-09-22 12:12:57 -07:00
Jen Basch 7ed88e250b Add VmType intermediate representation for types (#1838) 2026-09-22 08:26:03 -07:00
Daniel Chao cbffd6c114 Improve error message when amending a property with no value set (#1867)
Improve error message when amending a property with no value set

This decorates error messages with the amendment node.
2026-09-21 06:54:22 -07:00
Daniel Chao e0b3b87e19 Fix native image build (#1865)
PE code can't call `Object.equals`
2026-09-17 21:57:35 -07:00
Daniel Chao cec08c651e Optimize super property and super subscript nodes (#1853)
This adds cacheing to ReadSuper* nodes so that the same
node being executed can possibly re-use a previously cached value.
2026-09-17 20:46:03 -07:00
Jen Basch c71b107e32 Add inference for let bindings (#1824) 2026-09-15 05:20:42 +00:00
Daniel Chao d0de24b85b Avoid using Object.toString() for in-language API (#1850)
This changes code so that the in-language `toString()` doesn't use
Java's `Object.toString()`.
Additionally, the existing `toString()` implementation is switched over
to using `VmValueRenderer`, which does not force (leaves `?` in place of
unforced values).

This helps improve ergonomics when working on the language (can enable
automatically calling `toString()` on debug values).

Additionally, external tools might call toString(); for example,
Truffle's compiler sometimes will stringify node fields (e.g.
when -Dengine.CompilationFailureAction=Throw) is set.
2026-09-11 23:08:26 +00:00
Jen Basch 574ad844f3 Use ChoiceFormat for better plurals in error messages (#1848) 2026-09-10 22:03:05 +00:00
Yarden Bar c95b3d11f4 Add netrc helpers in EvaluatorSettings.pkl (#1817)
This adds the `netRcHeaders` helper method that parses netrc file contents, and returns a mapping suitable to be used as Http headers.
2026-09-09 14:25:06 -07:00
Daniel Chao 713adac824 Make generator nodes more PE friendly (#1844)
* In GeneratorWhenNode, need to move individual iterations into their
  own methods so that the @ExplodeLoop sees a constant number of
  iterations whenever that method is called.
* In the other nodes, the lambda passed to
  `forceAndIterateMemberValues` needs to capture the materialized frame,
  not the virtual frame.
2026-09-08 15:11:10 -07:00
Dylan Pulver f3efcbfc9b Escape characters that YAML cannot carry literally (#1846)
YamlEmitter only routed a string into YamlEscaper when it held a
character below 0x20, so 0x7F, the C1 block, U+2028 and U+2029 went out
as plain scalars. They are not `c-printable` (YAML 1.2 spec 5.1), and
NEL, LS and PS are line breaks in YAML 1.1, so the rendered document is
either rejected or silently split by a reader.

The escapes added in #1165 for 0x85, 0xA0, U+2028, and U+2029 could only
fire when some other character happened to open that gate. Share one
predicate between the two sites that decide, and give 0x7F-0x9F the
8-bit escape they lack.
2026-09-04 13:46:09 -07:00
Jen Basch f284a0560a Error when inferring a self type in a method argument (#1847) 2026-09-03 23:03:34 +00:00
Jen Basch 249e563291 Optimize new inference in method args (#1845) 2026-09-03 13:16:17 -07:00
Jen Basch 7f5ae2a712 Add inference for implicitly typed new in method arguments (#1768) 2026-09-02 23:55:24 +00:00
Daniel Chao 92b26aca17 Optimize annotations without object bodies (#1843)
This skips some unnecessary steps when evaluating annotations that
have no attached object bodies by returning an EmptyObjectLiteralNode
instead of a PropertiesLiteralNode
2026-09-02 13:04:26 -07:00
Daniel Chao 0035199176 Improve partial-evaluation when amending null parents (#1836)
GraalVM's partial evaulator can't handle recursive calls into the same
node.

The current implementation around evaluating `VmNull` as a parent causes
the partial evaluator to bail out, leaving Pkl stuck in interpreter
mode.

This rewrites the various object literals to add individual
specializations for each type of default value we can see from a VmNull
parent.

Also:
* Fix `isTypeObjectClass` impl
* Fix bug when amending with generator object literal node with object params
2026-09-02 18:18:55 +00:00
Daniel Chao 2c2f50113d Make enclosing frame lookup more PE friendly (#1842)
The truffle compiler currently _always_ bails out of compilation for
`VmUtils.getFrame()` calls, because it determines that some branch
of this code can possibly return a materialized frame.

This adjusts the code so that the hot path (levelsUp == 0)
does not touch `VmUtils.getFrame()`, and avoids unnecessarily
materializing the frame.
2026-09-02 10:01:25 -07:00
Daniel Chao 9f28c1cb11 Make listing/mapping typecasts more PE-friendly (#1837)
This rewrites the listing/mapping typecast nodes to be more friendly
to partial-evaluation.

This is because the compiler bails out of deeply recursive calls.
2026-09-02 10:00:59 -07:00
Jen Basch 2b697015c7 Add this as a self type (#1708) 2026-09-02 09:04:15 -07:00
Daniel Chao 1208fa9438 Improve reading of const members (#1835)
The previous implementation can cause the JIT compiler to permanently
bail out when reading const memebrs.
2026-08-28 09:18:56 -07:00
Jen Basch 1cfdd3d30d Fix native build (#1832) 2026-08-26 22:45:18 +00:00
Jen Basch cb01d6275b Correctly type check Class<T> (#1698) 2026-08-26 05:29:34 +00:00
Sergio Salvi a90eb74c2d Fix reflect crash on modules using glob imports (#1816)
This excludes glob imports when creating a module's mirror
2026-08-25 12:04:45 -07:00
Jen Basch ae9160df51 Enforce max collection sizes when decoding pkl-binary (#1831) 2026-08-25 08:28:28 -07:00
Daniel ChaoandFlorin Ungur 6551a59f9e Use XDG base directories and Known Folders on Windows (#1809)
This changes logic that previously read/wrote from `~/.pkl` to use
XDG base directories (all OSes), and Known Folders locations on Windows.

For example, Pkl will look for `settings.pkl` in:

1. `$XDG_CONFIG_HOME/pkl/settings.pkl`
2. `%APPDATA/pkl/settings.pkl`
3. `~/.pkl/settings.pkl`
4. Path pkl/settings/pkl within `$XDG_CONFIG_DIRS`
5. `/etc/xdg/pkl/settings.pkl`

---------

Co-authored-by: Florin Ungur <florin@florinungur.com>
2026-08-20 21:50:24 +00:00
Daniel ChaoandIslon Scherer 4dd37219c0 Fix name resolution of types in constraints (#1826)
This fixes an issue where type names are resolved incorrectly
in typealias constraints.

Co-authored-by: Islon Scherer <islonscherer@gmail.com>
2026-08-19 11:10:32 -07:00
Jen Basch ac43bdbb17 Add hex/binary/octal support to String.toInt() (#1808) 2026-08-18 09:44:02 -04:00
Jen BaschandDan Chao 762db144ce Enforce that abstract methods are implemented (#1785)
This adds a check that abstract members must be implemented.
If any members lack an implementation, an error is thrown describing
the missing members.

Co-authored-by: Dan Chao <dan.chao@apple.com>
2026-08-17 21:52:54 +00:00
Jen Basch 5333d55269 Skip loading known-bad certs (#1806) 2026-07-30 22:54:08 +00:00
Daniel Chao a55a3d7c33 Improve evaluation of typealiases (#1796)
This simplifies the resolution of names in typealias constraints.
This removes the existing logic around swapping out the frame's
owner/receiver, and instead favors resolving the variable at parse time.

* During variable resolution, create read variable nodes that read off of
  a receiver node
* Introduce `GetTypeAliasModuleNode` that provides the typealias's
  enclosing module
* Inject the enclosing module during typealias instantiation
2026-07-30 17:22:45 +00:00
Jen Basch 2ca2aaf9ec Add pkl project package --install to local cache (#1795) 2026-07-30 07:26:21 +00:00
Jen Basch 50a09f59dc Remove abstract properties (#1781) 2026-07-29 15:05:19 -07:00
Daniel Chao be03023499 Fix snippet test mismatch between hotspot and native test (#1797) 2026-07-28 18:18:36 +00:00
Islon Scherer 1a3dc52a96 Fix bug in force (#1790) 2026-07-28 09:19:15 +02:00
67df676359 Introduce C library for Pkl (#1238)
This uses native-image to generate a C library for Pkl.
This generated library from native-image is wrapped with our own library,
in `pkl.h`.

This produces a static and a dynamic library for each os/arch variant
that Pkl currently supports.

Co-authored-by: Kushal Pisavadia <kushal.p@apple.com>
Co-authored-by: Jen Basch <jbasch94@gmail.com>
Co-authored-by: Islon Scherer <i_desouzascherer@apple.com>
2026-07-25 04:15:26 +00:00