Commit Graph

339 Commits

Author SHA1 Message Date
Dan Chao
edf704b469 Run spotless apply 0.27.2 2025-01-22 09:04:02 -08:00
Dan Chao
d9cfb68048 Prepare 0.27.2 release 2025-01-22 08:57:27 -08:00
Daniel Chao
1e75001382 Add release notes for 0.27.2 (#894) 2025-01-21 11:56:33 -08:00
Dan Chao
376eb2bdbf Run spotless apply 2025-01-17 10:32:24 -08:00
Daniel Chao
56a3b0a193 Update license year (#871)
* Update license header file spec to use placeholder year
* Update spotless to use ratchet formatting (only format files that have changed)
2025-01-17 10:32:24 -08:00
Josh B
6c8e45b19a Fix NPE when handling ExternalReader specs with null arguments (#882) 2025-01-17 10:32:24 -08:00
Josh B
0bc1b7156e Fix page size for Linux AArch64 native executables (#875)
Graal Native Image is assuming 4k page size here, which is a naughty assumption to make in the modern Linux-on-ARM landscape.
Two very common hardware configurations require 16k minumum page size: the Raspberry Pi 5 and Asahi Linux (running on Apple Silicon hardware).

This change forces 64k pages for Linux/AArch64 native executables to guarantee compatibility with these platforms.
DEVELOPMENT.adoc is also updated to cover the additional dependencies required for building native executables on Linux.
2025-01-17 10:32:24 -08:00
Stefan M.
f0b961de81 Make Test Report locale independent (#868)
Format numbers with `.` decimals
2025-01-17 10:32:24 -08:00
Daniel Chao
3ece353e0c Download JDK for windows build (#851)
Don't use the system Java on Windows builds, instead download them from Adoptium.

Also:

* Fail job if curl returns a 4xx status code
* Add java version to `GradleJob`
2025-01-17 09:58:03 -08:00
Josh B
639cc2430e Fix CreateEvaluatorRequest decoding (#853)
Handle case when request specifies external reader with null arguments
2024-12-19 10:00:46 -08:00
Philip K.F. Hölzenspies
48a710f439 Prepare 0.27.1 release (#839) 0.27.1 2024-12-06 14:23:25 +00:00
Philip K.F. Hölzenspies
15d85b0660 Add release notes for 0.27.1 2024-12-06 13:25:39 +00:00
odenix
aeace8bb3c Improve lazy type checking of listings and mappings (#789)
Motivation:
- simplify implementation of lazy type checking
- fix correctness issues of lazy type checking (#785)

Changes:
- implement listing/mapping type cast via amendment (`parent`) instead of delegation (`delegate`)
- handle type checking of *computed* elements/entries in the same way as type checking of computed properties
  - ElementOrEntryNode is the equivalent of TypeCheckedPropertyNode
- remove fields VmListingOrMapping.delegate/typeNodeFrame/cachedMembers/checkedMembers
- fix #785 by executing all type casts between a member's owner and receiver
- fix #823 by storing owner and receiver directly
  instead of storing the mutable frame containing them (typeNodeFrame)
- remove overrides of VmObject methods that are no longer required
  - good for Truffle partial evaluation and JVM inlining
- revert a85a173faa except for added tests
- move `VmUtils.setOwner` and `VmUtils.setReceiver` and make them private
  - these methods aren't generally safe to use

Result:
- simpler code with greater optimization potential
  - VmListingOrMapping can now have both a type node and new members
- fewer changes to surrounding code
- smaller memory footprint
- better performance in some cases
- fixes https://github.com/apple/pkl/issues/785
- fixes https://github.com/apple/pkl/issues/823

Potential future optimizations:
- avoid lazy type checking overhead for untyped listings/mappings
- improve efficiency of forcing a typed listing/mapping
  - currently, lazy type checking will traverse the parent chain once per member,
    reducing the performance benefit of shallow-forcing
	  a listing/mapping over evaluating each member individually
- avoid creating an intermediate untyped listing/mapping in the following cases:
  - `new Listing<X> {...}`
  - amendment of `property: Listing<X>`
2024-12-06 14:00:23 +01:00
Islon Scherer
7b850dd6d9 Fix possible stack overflow in Listing/Mapping type checking (#826) 2024-12-06 13:58:29 +01:00
Daniel Chao
c2096f633b Exclude non file-based modules from synthesized *GatherImports task (#821)
This fixes an issue where certain modules tasks fail due to the plugin
attempting to analyze their imports, but the arguments may not actually be
Pkl modules.

For example, the pkldoc task accepts entire packages in its "sourceMoules" property.

This changes the gather imports logic to only analyze file-based modules.
This is also a performance improvement; non file-based modules are unlikely to import
files due to insufficient trust levels.

Also: fix a bug when generating pkldoc on Windows
2024-12-06 13:58:06 +01:00
translatenix
d6ba021e12 Fix length of listings with computed index (#797)
Motivation:
The following expression evaluates to 2 instead of 1:
new Listing { "value" } { [0 + 0] = "override" }.length

Changes:
- fix length computation in EntriesLiteralNode
- improve `api/listing` tests
- make snippet test failures diffable in IntelliJ

Result:
- fixes https://github.com/apple/pkl/issues/780
- improved dev experience in IntelliJ
2024-12-06 13:57:19 +01:00
Josh B
077497d9b8 Fix a possible deadlock during external reader process close (#786) (#787)
* Fix a possible deadlock during external reader process close

* Apply spotless

---------

Co-authored-by: Philip K.F. Hölzenspies <holzensp@gmail.com>
2024-11-08 13:18:13 -08:00
Nick Muerdter
552b301451 Fix broken link to documentation site in release notes (#784) 2024-11-05 12:58:43 -08:00
Dan Chao
d3ac4b288c Prepare 0.27.0 release 0.27.0 2024-11-05 09:51:48 -08:00
Daniel Chao
7eedcf1e50 Prepare 0.27.0 release notes (#756)
Co-authored-by: translatenix <119817707+translatenix@users.noreply.github.com>
Co-authored-by: Philip K.F. Hölzenspies <holzensp@gmail.com>
Co-authored-by: Islon Scherer <islonscherer@gmail.com>
2024-11-05 09:49:50 -08:00
Daniel Chao
a85a173faa Fix equals/hashCode/hasCachedValue in delegating listings/mappings (#781)
This fixes issues when a mapping/listing delegates to another mapping/listing.

The core issue is that `cachedValues` is not guaranteed to be the complete set
of the object's members; they may be stored on the delegate instead.

Therefore, it's not correct compute hash code and equality based on `cachedValues`.
Instead, it's better to use the `getCachedValue()` method, which has the correct
logic for looking up the existing cached value.
2024-11-05 09:05:36 -08:00
Daniel Chao
b402463f3c Eagerly check function arguments when called from inside iterable (#778)
This mitigates an issue where lazy mappings and listings widen an existing bug.

This is a follow-up to https://github.com/apple/pkl/pull/752.
2024-11-05 09:05:09 -08:00
translatenix
6d161ce1d4 Polish ANSI formatting and underlying code (#779)
- change line numbers from blue to faint to improve legibility on dark backgrounds
- use EnumSet throughout
- move all ANSI classes into package core.util (no need to split them over util and runtime)
- rename AnsiCodingStringBuilder to AnsiStringBuilder
2024-11-05 08:54:35 -08:00
Daniel Chao
40a08affa6 Use ANSI colors for test results; more polish (#771)
Any thrown Pkl Errors are colored in the simple test report!

Also:
* Refactor `TextFormatter` to be more generic; rename to `TextFormattingStringBuilder`
* Adjust test report slightly (no emojis, add more spacing).
* Introduce `ColorTheme` class.
* Make stack frame descriptors colored as "faint"

Also: this changes the summary so it summarizes _all_ modules, rather than a summary per module.

---------

Co-authored-by: Islon Scherer <islonscherer@gmail.com>
Co-authored-by: Philip K.F. Hölzenspies <holzensp@gmail.com>
2024-11-04 14:14:19 -08:00
Daniel Chao
4b4d81ba93 Fix semver comparison logic (#773)
Fix `isLessThan` logic between semvers
2024-11-03 20:31:04 -08:00
Josh B
9692504b5f Remove pkl.core.messaging from core APIs (#770) 2024-11-01 14:53:16 -07:00
Josh B
fa25fb46fd More external reader refinements (#766)
* org.pkl.core.Readers -> org.pkl.core.Closeables
* Remove coupling between pkl.core.module/resource and pkl.core.messaging
2024-11-01 14:05:45 -07:00
translatenix
3f38173ed5 Update commonmark and test dependencies (#767) 2024-11-01 12:48:01 -07:00
translatenix
d50179827d Update to GraalVM 23.0.6 and GraalVM for JDK 17.0.12 (#765)
GraalVM for JDK 17.0.12 is the final Critical Patch Update
made available under the GraalVM Free Terms and Conditions license.
Subsequent Critical Patch Updates require a commercial license.
2024-11-01 12:42:08 -07:00
Philip K.F. Hölzenspies
03462fefae Add color to error formatting (#746)
* Add color to error formatting

* Apply suggestions from code review

Co-authored-by: Daniel Chao <daniel.h.chao@gmail.com>

* Address reviewer comments

* Apply suggestions from code review

Co-authored-by: Daniel Chao <daniel.h.chao@gmail.com>

* Define style choices as operations on formatter (abandon semantic API)

* Adjust margin styling

* Review feedback

* Documentation nits

---------

Co-authored-by: Daniel Chao <daniel.h.chao@gmail.com>
2024-11-01 10:02:19 +00:00
Josh B
e217cfcd6f Refine external reader API (#762)
* Encapsulate message transport by removing `ExternalReaderProcess.getTransport` and adding `getModuleResolver` and `getResourceResolver` methods
* Reuse `Random` instances within `ExternalReaderProcessImpl` and module/resource resolvers
* Externalize all `ExternalReaderProcessException` messages
* Add some missing doc comments to `ModuleKeyFactories` and `ResourceReaders` methods for external readers
* Move org.pkl.core.util.Readers to org.pkl.core.Readers
2024-10-31 16:51:25 -07:00
Daniel Chao
66d751f093 Eagerly check listing/mapping in iterables (#752)
There is currently a bug around resolving variables within the iterable of a for
generator or spread syntax (https://github.com/apple/pkl/issues/741)

Normally, mappings/listings are type-checked lazily. However, this results in the said
bug getting widened, for any object members declared in the iterable.

As a workaround for now, prevent the bug from being any worse by ensuring that these
object members are eagerly typechecked.
2024-10-31 14:22:24 -07:00
translatenix
1be1fe4863 Use VmObjectBuilder in Listing.distinct(By) implementations (#760) 2024-10-31 13:28:04 -07:00
translatenix
cc72f9d160 Polish external reader API/implementation (#759)
- keep implementation classes internal to their packages
- make classes final if possible
- make namespace classes non-instantiable
- throw IllegalStateException instead of ExternalReaderProcessException for use after close
  - common convention already used by HttpClient etc.
  - programming errors should be signaled with unchecked exceptions
- use private instead of public lock object
- polish Javadoc
- delete commented out code
- don't use star import for a single class
2024-10-31 13:12:19 -07:00
Philip K.F. Hölzenspies
a03827951c Add methods from List/Map to Listing/Mapping (#683)
* Add `values` to `Mapping`

* Add `entries` to `Mapping`

* Add `containsValue` to `Mapping`

* Add `every` to `Mapping`

* Add `any` to `Mapping`

* Add `toDynamic` to `Mapping`

* Add `lastIndex` to `Listing`

* Add `getOrNull` to `Listing`

* Add `first` to `Listing`

* Add `firstOrNull` to `Listing`

* Add `last` to `Listing`

* Add `lastOrNull` to `Listing`

* Add `single` to `Listing`

* Add `singleOrNull` to `Listing`

* Add `contains` to `Listing`

* Add `any` to `Listing`

* Add `every` to `Listing`

* Fixup `any` to `Listing`

* Revert "Add `toDynamic` to `Mapping`"

This reverts commit 5551974ecd8110aa2eb8f546e992c32d3181df9b.

* Revert "Add `values` to `Mapping`"

This reverts commit 6fc78796

* Revert "Add `entries` to `Mapping`"

This reverts commit a7e8dfc4

* Annotate new members with `Since` 0.27

* Fix documentation in `base.pkl`

* Add location information to empty/single checks in `Listing` operations

* Remove additional variable for laziness preservation

* Apply spotless

* Apply suggestions from code review

Co-authored-by: Daniel Chao <daniel.h.chao@gmail.com>

---------

Co-authored-by: Daniel Chao <daniel.h.chao@gmail.com>
2024-10-31 14:54:27 +00:00
Stefan M.
71db4d0fae Replace code with italic (#753) 2024-10-30 17:15:04 +00:00
Josh B
dd16f7469e pkl-executor: fix loading projects and fix incorrectly thrown PklException
* Load `PklProject` using the same security settings and env vars passed provided via ExecutorSPIOptions
* Handle thrown `PklException` from loading `PklProject` and throw `ExecutorSPIException`
* Handle thrown `PklException` of older Pkl distributions, converting them into `ExecutorSpiException`
2024-10-29 23:29:19 -07:00
Daniel Chao
acd2222534 Polish test result running and reporting (#738)
Changes:
* Move class `TestResults` to package `org.pkl.core`, because it is a public class (it's the result of `Evaluator#evaluateTest`)
* Change examples to treat individual examples as assertions in the same test. Previously, they were considered different tests with an incrementing number. This better aligns with how facts are treated.
* Change `TestResults` to be a record, and introduce builders.
* Remove "module" test result section (it is not really a section).
* Add javadoc to `TestResults`
* Formatting fix: prefix ✍️ emoji just like we do the  and  emojis 
* Consider writing examples as failures, not successes. `pkl test` will exit with code 10 if the only failing tests are due to writing examples.
2024-10-28 21:05:13 -07:00
Josh B
666f8c3939 Implement SPICE-0009 External Readers (#660)
This adds a new feature, which allows Pkl to read resources and modules from external processes.

Follows the design laid out in SPICE-0009.

Also, this moves most of the messaging API into pkl-core
2024-10-28 18:22:14 -07:00
Daniel Chao
466ae6fd4c Exclude non-ascii files from windows native snippet tests (#739)
There is an existing bug that is preventing the CLI from loading
these files.
2024-10-26 07:56:00 -07:00
translatenix
08be6be059 codegen-java/kotlin: Support Spring Boot 3.x instead of 2.x (#729)
Motivation:
In Spring Boot 3.0, the annotation type `org.springframework.boot.context.properties.ConstructorBinding`
was deprecated in favor of `org.springframework.boot.context.properties.bind.ConstructorBinding`.
In 3.2, the old annotation type was removed.
As of 3.0, a `@ConstructorBinding` annotation is no longer required/recommended for configuration classes with a single public constructor.

Changes:
Remove generation of `@ConstructorBinding` annotations in codegen-java and codegen-kotlin.

Result:
- Generated code is compatible with Spring Boot 3.x.
  (Verified with locally updated pkl-spring.)
- Generated code is no longer compatible with Spring Boot 2.x.
  To use Pkl 0.27 and later with Spring Boot 2.x, use Pkl 0.26's code generator.
- Fixes #139.
2024-10-25 14:08:20 -07:00
translatenix
8fa3acf32f codegen-kotlin: Support Java serialization of module classes (#721)
Motivation:
- Java serialization makes as much sense for module classes as it does for regular classes.
- Offer same Java serialization support as codegen-java.

Changes:
- Move generation of `appendProperty` method and serialization code
  into new method `generateCompanionRelatedCode`.
- Improve/fix generation of serialization code.

Result:
Java serialization is also supported for module classes.
2024-10-24 22:11:35 -07:00
Islon Scherer
8b0118fec5 Store PklProject annotations in the project metadata (#708)
Write annotations to project metadata, and provide them to pkl-doc\

The following annotations have meaning for pkl-doc:
* `@Unlisted`: hide package from documentation site
* `@Deprecated`: add deprecated information
2024-10-24 17:21:58 -07:00
Islon Scherer
93cc3253eb Report error on circular local dependencies (#731)
If a stack overflow is found during project evaluation, present any
circular imports found in the dependency graph.
2024-10-24 16:45:18 -07:00
translatenix
1ceb489d78 Fix lazy type checking of UInt types (#740)
For example, Listing<UInt16> is equivalent to Listing<UInt16>, but not to Listing<UInt32>.
2024-10-24 16:19:26 -07:00
Josh B
4b6bc7bb7c Produce more helpful output when module output is overwritten (#716)
Fix a bug where overwriting `output` causes a PklBugException.

This now produces a more helpful message pointing to the actual problem.

Co-authored-by: translatenix <119817707+translatenix@users.noreply.github.com>
2024-10-24 09:41:59 -07:00
translatenix
cbbcca0d84 codegen-java: Make stateless classes instantiable (#734)
Motivation:
Currently, the condition for making a generated Java class instantiable is "class is neither abstract nor stateless".
(An instantiable class receives a public constructor and equals/hashCode/toString/with methods.)
This is inconsistent with Pkl and codegen-kotlin, both of which support instantiation of stateless classes.

Changes:
Widen condition for making a class instantiable to "class is neither abstract nor a stateless final module class".
This is consistent with codegen-kotlin, which generates object declarations (only) for stateless final module classes.

Result:
Stateless classes are instantiable in Pkl, codegen-java, and codegen-kotlin.
2024-10-24 09:29:08 -07:00
Daniel Chao
22c9a6c9f4 Exclude thrown ascii filename error from native tests (#737)
The URI encoding is not predictable here.
2024-10-24 08:20:56 -07:00
Josh B
069a5d1adc Fix test failures on main (#735) 2024-10-24 11:53:39 +01:00
Javier Maestro
86d870ba09 Improve testing with stats and errors per test section (#498)
* Emojis are moves to the left to be aligned
* A summary line is added with test counts
* Facts and Examples are grouped under their own section
2024-10-23 23:00:35 -07:00