PR# 17439 Manifest Value Type Inference

Problem Report Summary
Submitter: saynte
Category: Other
Priority: Medium
Date: 2011/03/25
Class: Feature Request
Severity: Non-critical
Number: 17439
Release: 6.8.85940
Confidential: No
Status: Analyzed
Responsible:
Environment: Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.133 Safari/534.16
Synopsis: Manifest Value Type Inference

Description
In a program that has

  x: INTEGER_64
  ...
  x := 1000*1000*1000*1000

The operations on the RHS of the assignment will be regarded as INTEGER_32 operations, which overflow.

It would be quite useful if a simple kind of type inference were used when manifest values were assigned to a target. The target carries the information required to give a type to the manifest string/integer/etc.

This approach seems to be preferable to something such as calculating the RHS and seeing if it fits in the LHS without loss of precision, as it would also apply to strings.
To Reproduce

										
Problem Report Interactions
From:saynte    Date:2011/03/28    Download   
After thinking over the weekend, it seems that the feature I'm suggesting (although I can't say yet whether it is warranted) is that instead of the conversion being performed on the root:

i64 := (1000*10).to_integer_64

It should be performed on the leaves:

(1000).to_integer_64 * (10).to_integer_64

Although this does create sort of a special rule for the some types (possibly the strings too?), it may be useful. It follows the calculation principle of "do not round your result until the end". There is also the benefit that it would work on expressions of types like STRING_8/32 and REAL_64/32

Another alternative would be to have the manifest integers take on the machine word-size, but this would only apply to INTEGERs then.

From:manus_eiffel    Date:2011/03/25    Status: Analyzed    Download   
Inference is already done for:

i64 := 1000

However

i64 := 1000 * 10

is about the type of expression `1000 * 10' which cannot be changed so that computation is done using INTEGER_64 instead of INTEGER_32.

The only thing we can have is the compiler trying to evaluate the expression using INTEGER_32 and reports to the user that there is an overflow.