243 Commits

Author SHA1 Message Date
Taichi Ishitani
b5e011dae1 Allow to toInt() to parse a string including "__" (#578)
Fix the issue where String#toInt() cannot parse a Int string
including sequence of "_" like "1_2__3___".
2024-07-15 10:39:17 +02:00
Philip K.F. Hölzenspies
5cc2ea2d00 Revert error coloring (for development on dedicated branch) (#565) 2024-07-03 17:25:06 +01:00
Dan Chao
8c1c10528f Run spotless apply 2024-07-01 09:24:04 -07:00
Dan Chao
7a9b571f6e Use spotless to format remaining Kotlin files
Also: fix issue where some commented out Kotlin files are invalid.
2024-07-01 09:24:04 -07:00
Thomas Purchas
3659ad8b7a Add test for colour outputs
Test two error conditions that cover all current colour outputs.
2024-07-01 10:13:16 +01:00
Thomas Purchas
0d7b95d3ff Add colours to Pkl errors in Cli output
To make error messages from Pkl eval easier to read, this change uses
the Jansi library to colour the output, making it quicker and easier to
scan error messages and understand what's happened.

The Jansi library also detects if the CLI output is a terminal capable
of handling colours, and will automatically strip out escape codes if
the output won't support them (e.g. piping the output somewhere else).
2024-07-01 10:13:16 +01:00
Daniel Chao
51d7265ec6 Do not enable TLS certificate revocation checks by default (#553)
This addresses an issue where network requests may fail if cert revocation checks
error, which may occur due to availability issues, or due to lack of internet access.

Revocation checking can still be enabled by setting JVM property com.sun.net.ssl.checkRevocation if on the JVM.

Also:
* Load built-in certs from resources, and move them to pkl-commons-cli
* Fix an issue where HttpInitException is not caught when loading a module
2024-06-28 08:57:46 -07:00
Philip K.F. Hölzenspies
0ef22a73fb Start next dev iteration 2024-06-17 19:53:30 +01:00
Philip K.F. Hölzenspies
4a27ac5bda Prepare 0.26.0 release 2024-06-17 19:53:30 +01:00
Philip K.F. Hölzenspies
d55866a04b Fix commitish detection in LanguageSnippetTest to also cover release versions (#537) 2024-06-17 18:21:22 +01:00
Daniel Chao
919de4838c Improve handling of CA certificates (#518)
Instead of bundling Pkl's built-in CA certificates as a class path resource and loading them at runtime,
pass them to the native image compiler as the default SSL context's trust store.
This results in faster SSL initialization and is more consistent with how default certificates
are handled when running on the JVM.

Further related improvements:
- Remove HttpClientBuilder methods `addDefaultCliCertificates` and `addBuiltInCertificates`.
- Remove pkl-certs subproject and the optional dependencies on it.
- Move `PklCARoots.pem` to `pkl-cli/src/certs`.
- Fix certificate related error messages that were missing an argument.
- Prevent PklBugException if initialization of `CliBaseOptions.httpClient` fails.
- Add ability to set CA certificates as a byte array
- Add CA certificates option to message passing API
2024-06-12 17:53:03 -07:00
Philip K.F. Hölzenspies
b03530ed1f Add support for HTTP proxying (#506)
* Add `--proxy` and `--no-proxy` CLI flags
* Add property `http` to `pkl:settings`
* Move `EvaluatorSettings` from `pkl:Project` to its own module and add property `http`
* Add support for proxying in server mode, and through Gradle
* Add `setProxy()` to `HttpClient`
* Add documentation
2024-06-12 11:54:22 -07:00
Daniel Chao
a4c0a271b4 Require references from typealiases to be const (#516)
This adds a language change that requires references from typealiases
to the enclosing module to be `const`.

This is required because typealiases are not late-bound.

Rationale is laid out in SPICE-0007.

Also:
* Update documentation to reflect new rules.
* Fix `Project.pkl`; mark method `const` to not break said rule.
2024-06-10 09:01:05 -07:00
Daniel Chao
d5ba8fa736 Support scheme-agnostic projects (#486)
This adds changes to support loading project dependencies in non-file based projects.

The design for this feature can be found in SPICE-0005: https://github.com/apple/pkl-evolution/pull/6

Changes:
* Consider all imports prefixed with `@` as dependency notation.
* Bugfix: fix resolution of glob expressions in a local dependency.
* Adjust pkl.Project:
  - Allow local dependencies from a scheme-local paths.
  - Disallow certain evaluator settings if not loaded as a file-based module.
* Breaking API change: `ProjectDependenciesManager` constructor now requires `ModuleResolver` and `SecurityManager`.
2024-06-04 16:52:20 -07:00
Daniel Chao
c0a7080287 Fix line endings (#513)
* Adjust gitattributes file (mark some files binary, mark bat files as using crlf endings)
* Fix remaining line endings issues
2024-06-04 07:55:33 -07:00
translatenix
207d0c78f0 Fix globbed read/import bugs (#449)
* Split MemberNode into (Regular/Shared)MemberNode

SharedMemberNode enables generating non-constant object members
at run time without generating an unbounded number of Truffle root nodes.

* Invert shouldRunTypeCheck to match its name

* Introduce VmObjectBuilder

Introduce VmObjectBuilder, a uniform way to build `VmObject`s
whose `ObjectMember`s are determined at run time.
Replace some manual object building code with VmObjectBuilder.
Add some assertions to fix IntelliJ warnings.

* Improve implementation of globbed read/import nodes

- Leverage SharedMemberNode to have a single Truffle root node per globbed
  read/import expression instead of one root node per resolved glob element.
- Remove caching in ReadGlobNode because it only works correctly if glob pattern is a string *constant*.
- Remove caching in StaticReadNode (now ReadGlobElementNode/ImportGlobElementNode)
  because it seems unnecessary and the implementation doesn't look quite right.

* Simplify code

* Fix ClassCastException when reflecting on globbed import

* Fix caching of globbed reads

Problem:
The result of a globbed read depends not only on the glob pattern but also on the current module URI.
However, ResourceManager does not take this into account when caching globbed reads, causing wrong results.

Changes:
- Cache globbed reads per read expression.
  This is also how globbed imports are cached, except that import URIs are constant.
- Make ReadGlobNode and ImportGlobNode code as similar as possible.
- Reduce code duplication by inheriting from AbstractReadNode.
- Add some tests.
2024-06-03 17:10:56 -07:00
Daniel Chao
d81a12352c Improve configuration and tests for native-image (#509)
* Don't expose JDK internal classes; instead solve msgpack issue with `--initialize-at-run-time`.
* Use quick build mode for non-release builds:  40% faster compilation, 20% smaller executable.
* Remove options that were commented out.
* Also run ServerTest against native executable
2024-06-03 17:08:30 -07:00
Daniel Chao
5b7123131f Change line endings from CRLF to LF (#511) 2024-05-30 08:41:21 -07:00
Daniel Chao
8ec06e631f Add support for Windows (#492)
This adds support for Windows.
The in-language path separator is still `/`, to ensure Pkl programs are cross-platform.

Log lines are written using CRLF endings on Windows.
Modules that are combined with `--module-output-separator` uses LF endings to ensure
consistent rendering across platforms.

`jpkl` does not work on Windows as a direct executable.
However, it can work with `java -jar jpkl`.

Additional details:

* Adjust git settings for Windows
* Add native executable for pkl cli
* Add jdk17 windows Gradle check in CI
* Adjust CI test reports to be staged within Gradle rather than by shell script.
* Fix: encode more characters that are not safe Windows paths
* Skip running tests involving symbolic links on Windows (these require administrator privileges to run).
* Introduce custom implementation of `IoUtils.relativize`
* Allow Gradle to initialize ExecutableJar `Property` values
* Add Gradle flag to enable remote JVM debugging

Co-authored-by: Philip K.F. Hölzenspies <holzensp@gmail.com>
2024-05-28 15:56:20 -07:00
Daniel Chao
d0def765a2 Make http(s) URIs their own module key (#495)
GenericUrl is a catch-all that uses URL.openConnection().
Since we now have special handling of HTTP urls, it makes more sense to
put it in its own module key.
2024-05-16 08:38:43 -07:00
Daniel Chao
5f4d475d84 Fix local dependency globbing (#496)
This fixes an issue where globbing resources within a local dependency
fails to match anything.
2024-05-16 08:36:37 -07:00
Dan Chao
a5c13e325a Encode filepaths to be safe on Windows
This changes the file paths to use characters that are safe for Windows.

Channges the output of the following:
* Package cache directory
* Generated pkl-doc files
* Kotlin generated code

Unsafe characters are encoded as (<hex>).
For example, the colon character `:` is encoded as `(3a)`.

Additionally, this changes the cache directory prefix (package-1 to
package-2).

Follows the design of https://github.com/apple/pkl-evolution/pull/3
2024-05-13 14:06:28 -07:00
Daniel Chao
21aa44cfc4 Require global settings file to use pkl:settings (#477)
This is technically a breaking change, but follows the intended use-case
and documentation of settings.

* Require that the global settings file at `~/.pkl/settings.pkl`
amends stdlib module `pkl:settings`, or otherwise sets `output.value`
to an instance of `pkl.Settings`.
* Simplify the object mapping of `PklSettings.java`
2024-05-07 07:49:00 -07:00
translatenix
aeb17588b3 Simplify implementation of RequestCapturingClient (#473) 2024-05-06 12:02:45 +02:00
Daniel Chao
d28313bca8 Declare members of http package NonnullByDefault (#471)
* Add a package-info.java with NonnullByDefault annotation
* Make RequestCapturingClient return a response to satisfy the type checker
2024-05-03 09:58:01 -07:00
Islon Scherer
27d8a030b1 Remove hidden modifier from many reflect properties for better equality/rendering (#470) 2024-05-03 11:04:15 +02:00
translatenix
ea3e8f115b Improve conditional configuration of native build tasks (#465)
- Move all conditional configuration to the `assembleNative` and `testNative` "root" tasks
- Don't build aarch64 executable on Intel Mac
2024-04-30 15:57:39 -07:00
translatenix
e49a36e318 Make Java classes final if possible
Also add private no-arg constructors for classes that aren't meant to be instantiated.
2024-04-30 15:14:14 -07:00
translatenix
ae69e4776f Fix IntelliJ warnings in Java code
Fix all IntelliJ warnings in Java production code except for
bogus spelling warnings and warnings about unused public methods.
Also fix some warnings emitted by Code->Inspect Code.

Changes made:
- use text block instead of string concatenation
- extract method to avoid code duplication
- use switch expression
- fix Javadoc syntax and spelling
- fix spelling in comment
- increase class visibility to match visibility of use site
- delete overriding method with same implementation
- use String.isEmpty() and StringBuilder.isEmpty()
- add @Serial annotation
- make field final
- remove unused field
- remove unused private method
- remove exceptions that aren't thrown from throws clause
- insert non-null assertion
- annotate overriding method with @Nonnull
- suppress warning
- delete unused class (WriteAuxiliarySlotNode)
- add final modifier
- remove unused error message
- repeat @Nullable modifier in overriding method
- remove never thrown exception from throws clause
- remove redundant suppression
2024-04-30 15:14:14 -07:00
Daniel Chao
ed1b317801 Fix formatting error (#463) 2024-04-30 07:33:36 -07:00
Mark Robinson
c3a99f8ae6 Fix error handler to use new message 2024-04-29 14:52:29 +02:00
Mark Robinson
b433500e04 Update pkl-core/src/main/resources/org/pkl/core/errorMessages.properties
Co-authored-by: Philip K.F. Hölzenspies <holzensp@gmail.com>
2024-04-29 14:52:29 +02:00
Mark Robinson
f857223511 Update pkl-core/src/main/resources/org/pkl/core/errorMessages.properties
Co-authored-by: Philip K.F. Hölzenspies <holzensp@gmail.com>
2024-04-29 14:52:29 +02:00
Mark Robinson
c331dede3c Adjust wording in error 2024-04-29 14:52:29 +02:00
Mark Robinson
b9e94b94ae Fix handling of other http error codes when creating packages 2024-04-29 14:52:29 +02:00
Daniel Chao
e28d747418 JDK version bump cleaups, bump minimum Gradle version to 8.1 (#454)
* Bump JDK when running simple gradle CI jobs
* Bump minimum Gradle version to 8.1
* Fix docs, and fix minimum version checker
2024-04-26 07:42:39 -07:00
translatenix
a7c7e51180 Leverage basic Java 17 features (#451)
- Refactor code to use the following basic Java 17 features:
  - pattern matching for instanceof
  - @Serial annotation
  - switch expressions
  - enhanced switch statements
  - StringBuilder.isEmpty()
- Replace two switch statements with simpler if statements.
- Rename a few local variables.
2024-04-25 12:52:28 -07:00
Daniel Chao
3ab9e4184e Drop java 11, bump GraalVM to 23.0 (#439)
* Remove unnecessary strictfp modifier
* Add annotations to address Truffle DSL warnings (@Idempotent, @Exclusive)
* Adjust build logic to allow building cross-arch on macOS
* Add warning suppression for specialization limit (left this one as a TODO)
2024-04-24 16:17:19 -07:00
translatenix
3a31188cc1 Improve method.isConst() check in InvokeSuperMethodNode
Check const-ness every time a method is resolved instead of every time it is called.
2024-04-19 15:35:57 -07:00
translatenix
5de90d5868 Improve method.isConst() checks in InvokeMethodVirtualNode
- Check `method.isConst()` every time a method is resolved
  instead of once per node instance (`isConstChecked`).
  Given that `needsConst` only happens in very specific circumstances,
  I'm not entirely sure if every resolved method needs to be checked.
  However, it's a cleaner solution in any case, and `method.isConst()`
  is a fast check that also never happens on the `evalCached` fast path.
- Do not check for const-ness of `FunctionN.apply` methods.
  This check seems unnecessary and would always fail if triggered.
  (According to `base.pkl`, none of the `FunctionN.apply` methods is const.)
- Remove unnecessary Truffle boundaries for modifier checks,
  which are just bitwise operations.
- Improve const/import docs.
2024-04-19 15:35:57 -07:00
Lily Ballard
76f1b92039 Enable useCustomStringDelimiters for pkl test example output (#416)
This makes the `<file>-expected.pcf` file a bit easier to read when examples contain quotes or
backslashes.
2024-04-18 12:58:05 -07:00
Stefano Baghino
81bfdb7cbd Enable caching of native image building and test tasks (#409)
Enable caching for the native image building task and improves the caching effectiveness of some of the test tasks in the project.
2024-04-18 08:28:56 -07:00
Kushal Pisavadia
31917d1556 Suppress warnings for System.getProperty("line.separator") (#432)
`class System` gets initialized at build time through `native-image`
and added to the heap. We initialize everything at build time via the
`--initialize-at-build-time=` flag.
2024-04-17 21:23:24 -07:00
translatenix
5510bf12d2 Eliminate redundant map lookup (#433) 2024-04-17 16:37:55 -07:00
translatenix
e688b4d4e1 Fix typo (#437) 2024-04-17 13:37:45 -07:00
luuvish
2f0436ff2f Cannot assign property with fixed/const in spread (#428)
When using spread syntax with typed object, properties that are fixed
or const cannot be assigned or amended.
This should be checked in the checkTypedProperty() function.
2024-04-16 14:45:33 -07:00
translatenix
90b461aa58 Support building with JDK 21 (#234)
- Update google-java-format to a version compatible with JDK 21 and run "gw spotlessApply".
- Fix wrong test assumption
  JavaCodeGenerator writes a properties file using java.util.Properties,
  which doesn't guarantee order of entries.
- Fix most deprecation warnings
- Add CI job for JDK 21
2024-04-12 13:38:31 -07:00
translatenix
bba5387f17 Update dependencies (#350)
* Update various dependencies
* Freeze kotlinx.html and kotlinx.serialization versions until Kotlin itself is updated.
2024-04-11 20:54:01 -07:00
Philip K.F. Hölzenspies
309e3ff4f6 Update expected test outcome 2024-04-10 14:02:36 +01:00
luuvish
375b88f53e Fix the sequence length in the YAML parser
The initialSize in EconomicsMaps.create() is not the actual stored size,
hence the accurate size is not determined until ObjectMembers are added
after addMembers() called.

Since the size set during the creation of VmListing cannot be changed
afterwards, the size of node.getValue() is used instead of members'
size.
2024-04-10 14:02:36 +01:00