mirror of
https://github.com/apple/pkl.git
synced 2026-01-11 22:30:54 +01:00
Vendor paguro's RrbTree, fix an int overflow breaking large Lists (#1337)
This commit is contained in:
@@ -120,6 +120,9 @@ tasks.test {
|
||||
excludeEngines("AlpineLanguageSnippetTestsEngine")
|
||||
excludeEngines("WindowsLanguageSnippetTestsEngine")
|
||||
}
|
||||
|
||||
// testing very large lists requires more memory than the default 512m!
|
||||
maxHeapSize = "1g"
|
||||
}
|
||||
|
||||
val testJavaExecutable by
|
||||
@@ -135,6 +138,9 @@ val testJavaExecutable by
|
||||
// executable;
|
||||
// to verify that we don't want to include them here)
|
||||
(configurations.testRuntimeClasspath.get() - configurations.runtimeClasspath.get())
|
||||
|
||||
// testing very large lists requires more memory than the default 512m!
|
||||
maxHeapSize = "1g"
|
||||
}
|
||||
|
||||
tasks.check { dependsOn(testJavaExecutable) }
|
||||
|
||||
@@ -19,9 +19,6 @@ import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import org.organicdesign.fp.collections.RrbTree;
|
||||
import org.organicdesign.fp.collections.RrbTree.ImRrbt;
|
||||
import org.organicdesign.fp.collections.RrbTree.MutRrbt;
|
||||
import org.organicdesign.fp.collections.UnmodCollection;
|
||||
import org.organicdesign.fp.collections.UnmodIterable;
|
||||
import org.pkl.core.ast.ConstantNode;
|
||||
@@ -29,6 +26,9 @@ import org.pkl.core.ast.ExpressionNode;
|
||||
import org.pkl.core.runtime.Iterators.ReverseTruffleIterator;
|
||||
import org.pkl.core.runtime.Iterators.TruffleIterator;
|
||||
import org.pkl.core.util.Nullable;
|
||||
import org.pkl.core.util.paguro.RrbTree;
|
||||
import org.pkl.core.util.paguro.RrbTree.ImRrbt;
|
||||
import org.pkl.core.util.paguro.RrbTree.MutRrbt;
|
||||
|
||||
// currently the backing collection is realized at the end of each VmList operation
|
||||
// this trades efficiency for ease of understanding, as it eliminates the complexity
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,13 +22,13 @@ import java.util.function.Consumer;
|
||||
import org.organicdesign.fp.collections.ImMap;
|
||||
import org.organicdesign.fp.collections.MutMap;
|
||||
import org.organicdesign.fp.collections.PersistentHashMap;
|
||||
import org.organicdesign.fp.collections.RrbTree;
|
||||
import org.organicdesign.fp.collections.RrbTree.ImRrbt;
|
||||
import org.organicdesign.fp.collections.RrbTree.MutRrbt;
|
||||
import org.pkl.core.ast.ConstantNode;
|
||||
import org.pkl.core.ast.ExpressionNode;
|
||||
import org.pkl.core.util.CollectionUtils;
|
||||
import org.pkl.core.util.Nullable;
|
||||
import org.pkl.core.util.paguro.RrbTree;
|
||||
import org.pkl.core.util.paguro.RrbTree.ImRrbt;
|
||||
import org.pkl.core.util.paguro.RrbTree.MutRrbt;
|
||||
|
||||
public final class VmMap extends VmValue implements Iterable<Map.Entry<Object, Object>> {
|
||||
public static final VmMap EMPTY = new VmMap(PersistentHashMap.empty(), RrbTree.empty());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,15 +21,15 @@ import java.util.Set;
|
||||
import org.organicdesign.fp.collections.ImSet;
|
||||
import org.organicdesign.fp.collections.MutSet;
|
||||
import org.organicdesign.fp.collections.PersistentHashSet;
|
||||
import org.organicdesign.fp.collections.RrbTree;
|
||||
import org.organicdesign.fp.collections.RrbTree.ImRrbt;
|
||||
import org.organicdesign.fp.collections.RrbTree.MutRrbt;
|
||||
import org.pkl.core.ast.ConstantNode;
|
||||
import org.pkl.core.ast.ExpressionNode;
|
||||
import org.pkl.core.runtime.Iterators.ReverseTruffleIterator;
|
||||
import org.pkl.core.runtime.Iterators.TruffleIterator;
|
||||
import org.pkl.core.util.CollectionUtils;
|
||||
import org.pkl.core.util.Nullable;
|
||||
import org.pkl.core.util.paguro.RrbTree;
|
||||
import org.pkl.core.util.paguro.RrbTree.ImRrbt;
|
||||
import org.pkl.core.util.paguro.RrbTree.MutRrbt;
|
||||
|
||||
public final class VmSet extends VmCollection {
|
||||
public static final VmSet EMPTY = new VmSet(PersistentHashSet.empty(), RrbTree.empty());
|
||||
|
||||
1934
pkl-core/src/main/java/org/pkl/core/util/paguro/RrbTree.java
Normal file
1934
pkl-core/src/main/java/org/pkl/core/util/paguro/RrbTree.java
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* This package contains source code from:
|
||||
*
|
||||
* <p>https://github.com/GlenKPeterson/Paguro
|
||||
*
|
||||
* <p>Paguro contains some code that is licensed under the Eclipse Public License 1.0. This code is
|
||||
* not included in the Pkl source. Only Paguro code licensed under Apache 2.0 is included here.
|
||||
*
|
||||
* <p>Original license:
|
||||
*
|
||||
* <p>Copyright 2016-05-28 PlanBase Inc. & Glen Peterson
|
||||
*
|
||||
* <p>Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
|
||||
* except in compliance with the License.
|
||||
*
|
||||
* <p>You may obtain a copy of the License at
|
||||
*
|
||||
* <p>http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* <p>Unless required by applicable law or agreed to in writing, software distributed under the
|
||||
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
||||
* express or implied.
|
||||
*
|
||||
* <p>See the License for the specific language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
@NonnullByDefault
|
||||
package org.pkl.core.util.paguro;
|
||||
|
||||
import org.pkl.core.util.NonnullByDefault;
|
||||
@@ -238,6 +238,7 @@ examples {
|
||||
List().repeat(1)
|
||||
List().repeat(5)
|
||||
module.catch(() -> list1.repeat(-1))
|
||||
List(0).repeat(118866785).length // triggers an overflow wraparound in original paguro impl
|
||||
}
|
||||
|
||||
["sortWith()"] {
|
||||
|
||||
@@ -192,6 +192,7 @@ examples {
|
||||
List()
|
||||
List()
|
||||
"Expected a positive number, but got `-1`."
|
||||
118866785
|
||||
}
|
||||
["sortWith()"] {
|
||||
List()
|
||||
|
||||
Reference in New Issue
Block a user