Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [viatra-dev] Type inferrer status

Hi,

some clarifications wrt to my previous letters:

1. The Integer.parseInt calls in the “fixed” patterns are not required at all (copy-paste error); the fixed pattern should be as follows:

pattern t4(n) {
	check((n as Integer)> 2);
	n == eval(2);
}

2. The algorithm computes all type information eventually, in this case, the problem is that some become available too late.
3. The problem itself occurs if and only if the only source of a type information is the return type of an eval expression, _and_ we want to use that variable inside another check or eval exception. If the type information can come from any other source (e.g. pattern parameter, unary/binary typeconstraint, etc.), the problem does not occur.
4. There are only two ways to fix this issue for the type inferrer (a) extending the Xbase type inferrer to support such cases (might be very time-consuming); (b) providing the type information either explicitly or through a non-Xbase based constraint. Reordering the constraints, etc. does not help.

Sorry, for the confusion,
Zoli
-- Zoltán Ujhelyi

Eclipse Technologies Expert
IncQueryLabs Ltd.

> On 21 Jun 2016, at 11:52, Zoltán Ujhelyi <zoltan.ujhelyi@xxxxxxxxxxxxxxxx> wrote:
> 
> Hi all,
> 
> in order to test the new type inferrer before release, last Friday it was merged into master. In general, it does feel as fast as the old one (but no performance measurements were done), and its results are more precise as it uses a combination of the Java and EMF type system internally, and its rule-based nature is expected to make it easier to extend in the future.
> 
> We have manually evaluated the behavior of the new type over various projects, and found a few differences:
> 
> * In case of the UML surrogate queries, the old inferrer was incapable of figuring out that the name parameter of the NamedElementQualifiedName pattern is a string, and inferred object. The new inferrer _correctly_ calculates this type (this resulted in API tools error messages, as the generated API changed here).
> * In an industrial project with the help of Balázs Grill we have identified both issues and further differences (thanks for the help!):
>    * In some cases with complex multiple inheritance hierarchies in some patterns it is not possible to automatically select a single type for a variable. The old inferrer did not identify them correctly, and selected one type; the new inferrer detects this case and asks the developer to select one of the possible types (and offers all the valid selections it knows). We manually reviewed these cases, and think, it is correct.
>    * We have found an issue with evals (more details later).
>    * We have identified problematic cases with the original implementation; new type inferrer test cases were extracted from that, and they were fixed (except the eval issue, see later).
> * We made sure that our other examples, such as CPS still work correctly.
> 
> In general, this inferrer works as expected; however, yesterday we have identified an issue related to eval that I see no easy fix for. Consider the following (very artificial) pattern:
> 
> pattern t4(n) {
> 	check(n >  2);
> 	n == eval(2);
> }
> 
> In this case, the type of ’n' has to be int (or java.lang.Integer) that cannot be specified in the pattern language (yet, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=399620), so the new type inferrer has to rely on the Xbase inferrer to provide this information from the eval; however, we also have to provide this information to the Xbase inferrer for the check expression. This is problematic because the incoming types of check expressions are set by the JVM model inferrer, at which point the return type of eval is not calculable, thus we see it as java.lang.Object, causing multiple issues for the Xbase expression “n > 2”: the comparison operator is not defined for Objects, and the return type cannot be calculated to be a boolean.
> 
> However, at a later stage when the pattern matchers are initialized (using the generic API) or generated, the type of ’n’ is correctly identified as java.lang.Integer, making the error possible to be worked around, e.g. by explicitly casting the type of ’n’ in the check expression as follows:
> 
> pattern t4(n) {
> 	check((n as Integer)> 2);
> 	n == eval(Integer.parseInt("2"));
> }
> 
> I see the following ways to continue:
> 
> 1. Try to defer the input type inferrer to a later stage. There is some support built-in for this (shown by Sebastian Zarnekow at last years XtextCon), but it requires quite a deep dive into the Xbase type inferrer, that is (a) undocumented, (b) very complex. It seems possible to do it, but I cannot even guess how much time is needed for this.
> 2. We could extend the declaration of eval expressions with an optional or mandatory type specification. This would provide enough information to have everything available, but still requires the specification of Java types in the pattern language that is not supported by our current grammar (and is not entirely trivial to do in a backward compatible fashion).
> 3. Similarly, we could allow to set up types for pattern parameters, or one-parameter constraints that provides this information.
> 
> The support of Java types is already planned for 1.4, and the type inferrer can reliable fix this issues with some explicit type declarations. However, un short term (for the release 1.3), we could:
> a) either revert the type inferrer
> b) keep it in, and document this issue
> 
> 
> What do you think?
> 
> Zoli
> -- Zoltán Ujhelyi
> 
> Eclipse Technologies Expert
> IncQueryLabs Ltd.
> 
> _______________________________________________
> viatra-dev mailing list
> viatra-dev@xxxxxxxxxxx
> To change your delivery options, retrieve your password, or unsubscribe from this list, visit
> https://dev.eclipse.org/mailman/listinfo/viatra-dev


Back to the top