File tree Expand file tree Collapse file tree 6 files changed +46
-9
lines changed
lkql_checker/share/lkql/kp
lkql_jit/language/src/main/java/com/adacore/lkql_jit
gnatcheck/scenario_variables/rules Expand file tree Collapse file tree 6 files changed +46
-9
lines changed Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ fun kp_20229(node) =
5050 if output then
5151 stdlib.any([
5252 from r.ref through parent select first ReturnStmt
53- for r in output.p_find_all_references(units())
53+ for r in output.p_find_all_references(units().to_list )
5454 ])
5555 else false
5656 }
Original file line number Diff line number Diff line change 1717import com .adacore .lkql_jit .runtime .values .interfaces .Indexable ;
1818import com .adacore .lkql_jit .runtime .values .interfaces .Iterable ;
1919import com .adacore .lkql_jit .runtime .values .interfaces .Iterator ;
20+ import com .adacore .lkql_jit .runtime .values .lists .BaseLKQLList ;
21+ import com .adacore .lkql_jit .runtime .values .lists .LKQLLazyListStreamWrapper ;
2022import com .adacore .lkql_jit .runtime .values .lists .LKQLList ;
2123import com .adacore .lkql_jit .utils .Constants ;
2224import com .adacore .lkql_jit .utils .LKQLTypesHelper ;
@@ -556,12 +558,8 @@ abstract static class UnitsExpr extends BuiltInBody {
556558
557559 @ Specialization
558560 @ CompilerDirectives .TruffleBoundary
559- protected LKQLList alwaysTrue () {
560- return new LKQLList (
561- LKQLLanguage .getContext (this )
562- .getAllUnits ()
563- .toArray (LangkitSupport .AnalysisUnit []::new )
564- );
561+ protected BaseLKQLList alwaysTrue () {
562+ return new LKQLLazyListStreamWrapper (LKQLLanguage .getContext (this ).getAllUnits ());
565563 }
566564 }
567565
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ public ListStorage(int startSize) {
2424
2525 public void append (T item ) {
2626 if (current_size >= capacity ) {
27+ capacity = Math .max (capacity , 1 );
2728 capacity *= 2 ;
2829 var new_storage = new Object [capacity ];
2930 for (int i = 0 ; i < current_size ; i ++) {
Original file line number Diff line number Diff line change 1+ //
2+ // Copyright (C) 2005-2025, AdaCore
3+ // SPDX-License-Identifier: GPL-3.0-or-later
4+ //
5+
6+ package com .adacore .lkql_jit .runtime .values .lists ;
7+
8+ import com .adacore .lkql_jit .runtime .ListStorage ;
9+ import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
10+ import java .util .Iterator ;
11+ import java .util .stream .Stream ;
12+
13+ /**
14+ * This class is a wrapper from a Java Stream to an LKQLLazyList.
15+ * It is currently only used to wrap the units() builtin.
16+ */
17+ public class LKQLLazyListStreamWrapper extends BaseLKQLLazyList {
18+
19+ // ----- Attributes -----
20+
21+ private Iterator <? extends Object > iterator ;
22+
23+ // ----- Constructors -----
24+
25+ public LKQLLazyListStreamWrapper (Stream <? extends Object > source ) {
26+ super (new ListStorage <>(0 ));
27+ iterator = source .iterator ();
28+ }
29+
30+ // ----- Instance methods -----
31+
32+ @ TruffleBoundary
33+ protected void initCacheTo (long n ) {
34+ while ((n < 0 || cache .size () <= n ) && iterator .hasNext ()) {
35+ cache .append (iterator .next ());
36+ }
37+ }
38+ }
Original file line number Diff line number Diff line change 11@unit_check
2- fun display_units(unit) = [{message: "UNITS: " & units().img,
2+ fun display_units(unit) = [{message: "UNITS: " & units().to_list. img,
33 loc: unit.root}]
Original file line number Diff line number Diff line change 1- print(units())
1+ print(units().to_list )
You can’t perform that action at this time.
0 commit comments