Feature #9868
Support generics introduced in Progress 12.x
100%
Related issues
History
#1 Updated by Ioana-Cristina Prioteasa over 1 year ago
- Related to Feature #9488: implement all built-in OO classes using the open source ADE code from 12.8.4 added
#2 Updated by Ioana-Cristina Prioteasa over 1 year ago
- File TestMultipleImplements.cls added
- File MultipleImplements.cls added
Progress 12.x introduced built-in classes that use generics, such as Progress.Collections.HashMap and Progress.Collections.List.
- Declaring variables with generics:
def private serializable var mBackingList as Progress.Collections.IList<Object>.var private HashMap<ILongcharHolder, Object> mBackingHashMap.
- Instantiating generic objects:
this-object(new Progress.Collections.List<Object>()).constructor private List (input pBackingList as Progress.Collections.IList<Object>):
- Navigating generic structures:
var Progress.Collections.IIterator<KeyValuePair<ILongcharHolder, Object>> iter. assign hValue = iter:Current:Value.
Here,Valueis a property fromKeyValuePair.
Additional considerations:
- A class can implement the same interface multiple times with different type parameters:
CLASS MultipleImplements IMPLEMENTS IComparable<OpenEdge.Core.Integer>, IComparable<OpenEdge.Core.Decimal>:
Here the class needs to contain 2compareTomethods:METHOD PUBLIC INTEGER CompareTo(other AS OpenEdge.Core.Integer):METHOD PUBLIC INTEGER CompareTo(other AS OpenEdge.Core.Decimal):
I attached the completedMultipleImplements.clsandTestMultipleImplements.cls- an unit test on this matter.
- Instantiating a generic class without type parameters is invalid syntax in Progress 12. This is not permitted:
myList = NEW List().
#3 Updated by Greg Shah over 1 year ago
For convenience, I'm reproducing my post from #9488-131:
Greg: considering that the #9457 project doesn't use generics in the app code, I want to find a way to delay this implementation. One of the 'weird' parts is:
[...]Note how you can implement the same interface but with different generic types. This is not allowed in Java.
Yuck. Some things to record for posterity:
- OO 4GL currently (as of the latest 12.8 LTS) doesn't have generics support that can be used by end user code. These references are only in the built-ins. Presumeably, they implement this limited special support in the native code of the OE runtime.
- OE is shrinking (dying actually) annually and the next LTS release is not expected until at least 2027 (best case) as explained by Progress Software Corp's (PSC) themselves. Most (all?) commercial ISVs would never deploy an OE release that is not LTS. That means that no one will be deploying the post-12.8 LTS until 2027 or possibly long after that.
- Supposedly PSC is working on generics for OO 4GL but generics can't appear in real OO 4GL code that goes to customers until that next LTS release is available so we have years to go before end user code will ever have direct access to generics.
- I wonder if OE will still exist in 2028 or if it will just be in maintenance mode. Actually, it is already kind of in maintenance mode since the amount of development on OE itself is very limited. But for the sake of argument, let's say that maintenance mode is in the future somewhere. My suggestion is that given the pace of decline, maintenance mode is possibly not that far in the future. Under those conditions we may never have to implement generics in the FWD implementation of the OO 4GL.
- Nevertheless, the current approach chosen by PSC seems to match the C# concept of generics which uses runtime information and tends to be much slower than generics in Java which use type erasure and are fast but have more type limitations on the implementation. As you note, we can't directly implement two parameterized interfaces using Java generics because of the type erasure implementation.
If it is feasible to defer the work on generics to another task, I am OK with that so long as that work can be deferred to after the current projects are complete. My point here is that if we defer the work but then just have to work it again in order to finish some current projects, then the deferral doesn't help too much. So, I'd like to know if we need it in the short term or not. If not, then we should defer it.
#4 Updated by Greg Shah over 1 year ago
I'm guessing that there is no syntax in the built-in classes which shows how to define a parameterized type (e.g. T like in a Java definition public class MyGenericisedClazz<T> { /* references to type T */ }). Is that correct?
In other words, they have some sytnax to reference existing classes that implement generics but not to define them in a class.
#6 Updated by Octavian Adrian Gavril about 2 months ago
- Assignee set to Octavian Adrian Gavril
- Status changed from New to WIP
#7 Updated by Octavian Adrian Gavril about 2 months ago
Evaluated the v13 user-defined generics support. It looks compatible and I think one implementation covers both cases.
Progress says as much in the 13.0 release notes: user-defined generics extend the same generic programming model the built-in collections already use, it's not a separate mechanism. That also answers what you asked in note #9868-4: 13.0 does have syntax to define a parameterized type, for classes and interfaces both:
CLASS class-name <type-param AS type-constraint [, type-param AS type-constraint]...>
The reason the built-in usage comes along for the ride is that in FWD the built-ins aren't special. They're the fakeout .cls skeletons under skeleton/oo4gl/, parsed by the same parser as any application class. Right now those skeletons are non-generic, everything flattened to Progress.Lang.Object. We stripped the generics by hand when the skeletons were generated, since the parser can't accept <> in a 4GL type name. Once it can, we rewrite them with the real signatures and the built-ins are generic for free. However, with all the work done in #9638, we will only need the implementations and we won't need the skeletons anymore.
Roughly the work is:
- accept
<...>in the grammar, both in type references and in class/interface declarations; - carry type parameters and arguments through
ClassDefinition/MemberData/MethodDataand substitute them on member lookup; - add
GetTypeParameters()andGetTypeArguments()toLegacyClass. We only haveisGeneric()today, andGetTypeArguments()isn't optional, it's the documented way around theNEW T()restriction; - finish the built-ins themselves:
HashMap,KeyValuePairandIIteratorare still non-generic andIMapis single-parameter.
The one real extra problem is the case you raised in #9488-131, implementing the same interface with different type arguments. I don't think it's a blocker. Java overloads on the signature, so two methods with the same name and different parameter types are fine as they are, and where the signatures would actually collide we already apply suffixes (that's what produces write_1 / write_2 in converted output). Either way the two CompareTo methods are covered. For the implements clause I think we should emit the interface once, unparameterized, and generate a bridge method that dispatches on the runtime argument type to the suffixed ones. We can't simply drop the implements, since LegacyClass relies on Class.isAssignableFrom for TYPE-OF and CAST.
#8 Updated by Greg Shah about 2 months ago
It isn't clear to me how the converted code will change to support type parameters. Are you saying that we should not support it directly in Java syntax but instead handle the overloading purely via name suffixes?
This is OK for cases that don't map directly to Java but for those cases that could be supported by Java generics, we would want to leverage those if possible because the converted code outcome is much better.
Please focus on writing a complete test suite (added to Testcases), the various cases can be written as OO classes and then ABLUnit tests to use those classes and prove conformance.
#9 Updated by Octavian Adrian Gavril about 2 months ago
Greg Shah wrote:
Please focus on writing a complete test suite (added to Testcases), the various cases can be written as OO classes and then ABLUnit tests to use those classes and prove conformance.
I successfully set up an OE environment using v12.8, as the OE Developer Kit for v13.0 isn't available yet.
#10 Updated by Octavian Adrian Gavril 7 days ago
The work covers the generics which OpenEdge 12.8 supports, which are the built-in generic classes used with type arguments.
The test suite is committed to testcases in 1995, under tests/oo/progress/collections (TestSuite.cls runs it). The 45 generics tests in it pass on OpenEdge 12.8.4, and the existing TestList tests complete it:
| Class | Tests | What it covers |
|---|---|---|
TestGenericDeclarations |
7 | declaration forms, two and nested type arguments, a derived class as type argument, a non-hashable map key |
TestGenericVarStatement |
1 | VAR with a generic type (the VAR statement itself is #9767) |
TestGenericMemberTyping |
9 | members typed by the type argument, used without CAST |
TestGenericTypeIdentity |
13 | TYPE-OF, CAST, DYNAMIC-CAST, GET-CLASS, TypeName, DYNAMIC-NEW |
TestGenericReflection |
8 | IsGeneric, GetTypeParameters, GetTypeArguments |
TestMultipleImplements |
7 | one generic interface implemented twice with different type arguments |
TestList |
13 | List<Object> (existing tests) |
The compile-time restrictions (NEW without type arguments, a wrong number of type arguments, a scalar type argument, an assignment between different type arguments) were confirmed on 12.8 as well. They stay out of the suite, since FWD converts code which OpenEdge has already compiled.
NEW List<T>.without parentheses, shown in the documentation, does not compile.- A map key type which does not implement
IHashablecompiles, butHashMap:Addrefuses such a key at run time (error 20576). CASTto a different type argument always compiles. The exact-match rule is checked only at run time.
12.8 keeps the type arguments at run time, as C# does. TYPE-OF of a List<Alpha> against List<Beta> is false, the two TypeName values differ, and GetTypeArguments() returns the real arguments. Java generics alone cannot answer these, because Java erases the type arguments.
It isn't clear to me how the converted code will change to support type parameters. Are you saying that we should not support it directly in Java syntax but instead handle the overloading purely via name suffixes?
The converted code uses Java generics directly. A member typed by a type parameter is typed by the type argument, so no cast is needed:
DEFINE VARIABLE myList AS List<Alpha> NO-UNDO. DEFINE VARIABLE got AS Alpha NO-UNDO. got = myList:Get(1).
converts to:
object<? extends List<Alpha>> myList = TypeFactory.object(List.class); object<? extends Alpha> got = TypeFactory.object(Alpha.class); got.assign(myList.ref().get(new integer(1)));
Since 12.8 keeps the type arguments at run time, every generic instance and every generic class reference in the converted code also carries its type arguments. They answer TYPE-OF, CAST, GET-CLASS, TypeName and the reflection methods. Name suffixes and a dispatch method are used only for a class which implements one generic interface with two different type arguments, which Java cannot express.
The implementation is in progress in 9868a. Trunk 16848 converts none of the tests yet, because the parser rejects < in a type name. HashMap, KeyValuePair and SortedSet are still runtime stubs, and #9488 skips them as generic classes, so I implement them in this task as well. The VAR test passes once #9767 is merged.
#11 Updated by Octavian Adrian Gavril 5 days ago
- Status changed from WIP to Review
- % Done changed from 0 to 100
- reviewer Greg Shah added
The implementation is committed to 9868a in 16849. It supports the generics of OpenEdge 12.8, which are the built-in generic types used with type arguments, as described in #9868-10. User-defined generics (13.0) are not part of this implementation. I will add them once I have access to an OpenEdge 13.0 environment to test them.
The converted code works as follows:- The parser accepts type arguments in every type name: definitions,
VAR, parameters,NEW,CAST,TYPE-OF,DYNAMIC-NEWandIMPLEMENTS. - A member typed by a type parameter is typed by the type argument, through Java generics, so no
CASTis needed (see the example in #9868-10). - Every generic instance and generic class reference carries its type arguments at run time. They answer
TYPE-OF,CAST,DYNAMIC-CAST,GET-CLASS,DYNAMIC-NEW,TypeName,IsGeneric,GetTypeParametersandGetTypeArgumentsas 12.8 does. - A class which implements one generic interface with two type arguments (
IComparable<Alpha>andIComparable<Beta>) implements the Java interface once. Its methods get name suffixes, and a dispatch method calls the right one by the runtime type of the argument. HashMap,KeyValuePairandSortedSetwere runtime stubs and are now implemented, together with theKeySetreturned byHashMap:Keys. They raise the same errors as 12.8 (18193, 20475, 20575, 20576, 20711).GetTypeArgumentsandGetTypeParametersare added toProgress.Lang.Classin the skeleton project in 132.
The work also fixes a trunk defect in the loading of a cached class definition, which kept only the first interface of an IMPLEMENTS list. A List<T> argument was then refused where an ICollection<T> parameter was expected, as in List:AddAll, once the built-in classes came from the cache.
The test suite is extended in testcases 1999, under tests/oo/progress/collections (TestSuite.cls runs it). All 92 tests pass on OpenEdge 12.8.4. With 9868a, 91 pass on FWD. TestGenericVarStatement converts once #9767 adds the VAR statement.
| Class | Tests | What it covers |
|---|---|---|
TestGenericDeclarations |
9 | declaration forms, two and nested type arguments, a derived class as type argument, a non-hashable map key, parameters, return values and undoable variables of generic types |
TestGenericVarStatement |
1 | VAR with a generic type |
TestGenericMemberTyping |
14 | members typed by the type argument, used without CAST, and AddAll with generic collections |
TestGenericTypeIdentity |
18 | TYPE-OF, CAST, DYNAMIC-CAST, GET-CLASS, TypeName, DYNAMIC-NEW |
TestGenericReflection |
9 | IsGeneric, GetTypeParameters, GetTypeArguments |
TestMultipleImplements |
7 | one generic interface implemented twice with different type arguments |
TestCollectionBehaviour |
9 | HashMap and its read-only key set |
TestSortedSetBehaviour |
2 | SortedSet errors for unknown and non-comparable elements |
TestCollectionUnknownValues |
10 | unknown values and keys in List, HashMap, SortedSet and the key set |
TestList |
13 | List<Object> (existing tests) |
I also ran the existing testcases tests which use the changed classes (the OpenEdge.Core list and timestamp tests and the HTTP client tests) with trunk 16848 and with 9868a. None got worse, and 5 list tests which failed on trunk now pass.
- The skeleton
OpenEdge/Core/Collections/List.clsusesObjectwithout aUSINGfor it. - A cached interface definition keeps only the first interface of an
INHERITSlist. No 12.8 built-in interface is affected. - The inheritance check of an interface does not follow the interfaces which that interface inherits.
- A
SHAREDobject variable raises error 391, also for a non-generic class. DYNAMIC-NEWlooks up the class file with case-sensitive names.DEFINE ... LIKEan object variable in a class method makes the conversion fail with aNullPointerException.- An
EXTENT OUTPUTargument to a method of the same class does not compile in the converted code. LegacyListIteratorcan loop forever.- One cookie jar test fails intermittently on trunk, because of an expiry check made with
< 0.
Greg, please review 9868a 16849.
#12 Updated by Octavian Adrian Gavril 3 days ago
The OO tests are now documented in Testcases, as asked in #9868-8. The new page OO 4GL Tests is a row of Base Language Testcases and covers all the tests under tests/oo, not only the generics tests of this task.
The page lists 8909 tests in 19 areas, from the OO language itself (classes, inheritance, overloading, events, serialization) to the built-in class libraries (Progress.Lang, Progress.Reflect, Progress.Collections, Progress.Json, OpenEdge.Core, OpenEdge.Net, OpenEdge.Web). For each area it gives what is tested, the path, and how many tests compile and pass on OpenEdge and convert, compile and pass on FWD. It also says how to run the tests on OpenEdge and on FWD.
tests/oo folder:
- 7873 tests pass on OpenEdge. The 700 test classes which use 12.x APIs were run on OpenEdge 12.8, the others on OpenEdge 11.6.
- 5871 tests pass on FWD trunk 16843. The
Progress.Collectionstests are counted as not converting there, since the generics support is in 9868a, which is not merged yet.