Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mixed Decimal/Float operations throw error or attach warning #10725

Merged
merged 45 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
e6cdaf6
WIP idea.
jdunkerley Jul 16, 2024
5ecd4bb
typo
GregoryTravis Jul 24, 2024
23411ee
merge
GregoryTravis Jul 24, 2024
9b3556a
Merge branch 'jd-tmp' into gmt-tmp
GregoryTravis Jul 24, 2024
cdb246b
tests, keep original float
GregoryTravis Jul 24, 2024
6df2066
Merge branch 'develop' into wip/gmt/10631-mixed-err
GregoryTravis Jul 25, 2024
c0fd213
mark == warning test pending
GregoryTravis Jul 25, 2024
819d589
Merge branch 'develop' into wip/gmt/10631-mixed-err
GregoryTravis Jul 25, 2024
a7ad2f9
Merge branch 'develop' into wip/gmt/10631-mixed-err
GregoryTravis Jul 26, 2024
50d1a2b
fix test
GregoryTravis Jul 26, 2024
a542114
add IA to add ret err
GregoryTravis Jul 26, 2024
80337ed
Merge branch 'develop' into wip/gmt/10631-mixed-err
GregoryTravis Jul 29, 2024
b82a81a
fix for warning-attached Equals
GregoryTravis Jul 29, 2024
d2834bc
other operators, remove return types
GregoryTravis Jul 29, 2024
3e88b37
Merge branch 'develop' into wip/gmt/10631-mixed-err
GregoryTravis Jul 30, 2024
c4ae795
fix tests
GregoryTravis Jul 30, 2024
2bf1ed0
fix tests
GregoryTravis Jul 30, 2024
43a6c25
cleanup
GregoryTravis Jul 30, 2024
fd88c52
Merge branch 'develop' into wip/gmt/10631-mixed-err
GregoryTravis Jul 31, 2024
6508485
fix tests
GregoryTravis Jul 31, 2024
67d577b
changelog
GregoryTravis Jul 31, 2024
95fc4ae
Merge branch 'develop' into wip/gmt/10631-mixed-err
GregoryTravis Aug 1, 2024
9107cb2
most pass
GregoryTravis Aug 1, 2024
6b44dde
tests pass
GregoryTravis Aug 1, 2024
0446614
better error, do not need warning_if_from_float
GregoryTravis Aug 1, 2024
c1836f9
more attach_loss_of_numeric_precision
GregoryTravis Aug 1, 2024
7fcc5e6
doc
GregoryTravis Aug 1, 2024
0b00b8e
dec docs and test
GregoryTravis Aug 1, 2024
66048a8
cleanup
GregoryTravis Aug 1, 2024
ca14b2b
todo for return type issue
GregoryTravis Aug 1, 2024
655a267
typo
GregoryTravis Aug 1, 2024
ff92f45
warnings lib
GregoryTravis Aug 2, 2024
9ce1a0a
remove modified Float.to
GregoryTravis Aug 2, 2024
da6a3d5
private
GregoryTravis Aug 2, 2024
ab8e863
fmt
GregoryTravis Aug 2, 2024
3775568
Merge branch 'develop' into wip/gmt/10631-mixed-err
GregoryTravis Aug 5, 2024
4c960a6
merge, changelog
GregoryTravis Aug 7, 2024
2cd4d63
Merge branch 'develop' into wip/gmt/10631-mixed-err
GregoryTravis Aug 8, 2024
1381d29
remove private from Decimal ctor, merge
GregoryTravis Aug 8, 2024
cd6c243
Merge branch 'develop' into wip/gmt/10631-mixed-err
GregoryTravis Aug 12, 2024
7f02ed1
fmt
GregoryTravis Aug 12, 2024
ed356d5
move constructor test to Base_Internal_Tests
GregoryTravis Aug 12, 2024
6eac98d
put return types back
GregoryTravis Aug 12, 2024
ba8550c
Merge branch 'develop' into wip/gmt/10631-mixed-err
GregoryTravis Aug 13, 2024
3110355
missing import
GregoryTravis Aug 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
comparisons.][10614]
- [Relative paths are now resolved relative to the project location, also in the
Cloud.][10660]
- [Mixed Decimal/Float arithmetic now throws an error; mixed comparisons now
attach warnings.][10725]

[10614]: https://github.com/enso-org/enso/pull/10614
[10660]: https://github.com/enso-org/enso/pull/10660
[10725]: https://github.com/enso-org/enso/pull/10725

# Enso 2023.3

Expand Down
286 changes: 225 additions & 61 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Data/Decimal.enso

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ private
import project.Data.Decimal.Decimal
import project.Data.Numbers.Number
import project.Data.Text.Text
from project.Errors.Common import Loss_Of_Numeric_Precision
import project.Warning.Warning
from project.Data.Ordering import Comparable, Ordering

polyglot java import org.enso.base.numeric.Decimal_Utils
Expand All @@ -11,4 +13,5 @@ polyglot java import org.enso.base.numeric.Decimal_Utils
type Decimal_Comparator
compare (x : Decimal) (y : Decimal) =
Ordering.from_sign (x.big_decimal.compareTo y.big_decimal)

hash x:Decimal = Decimal_Utils.hashCodeOf x.big_decimal
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ from Standard.Base import all
import Standard.Base.Errors.Common.Index_Out_Of_Bounds
import Standard.Base.Errors.Illegal_Argument.Illegal_Argument
import Standard.Base.Errors.Illegal_State.Illegal_State
from Standard.Base.Data.Decimal import from_big_decimal, get_big_decimal

import project.Column.Column
import project.Value_Type.Bits
Expand Down Expand Up @@ -78,7 +79,7 @@ closest_storage_type value_type = case value_type of
This step is unnecessary for primitive and builtin values, but necessary for
values such as `Decimal`/`BigDecimal`.
enso_to_java x = case x of
Decimal.Value big_decimal -> big_decimal
_ : Decimal -> get_big_decimal x
_ -> x

## PRIVATE
Expand All @@ -88,7 +89,7 @@ enso_to_java x = case x of
necessary for values such as `Decimal`/`BigDecimal`.
java_to_enso x = case x of
_ : Nothing -> Nothing
_ : BigDecimal -> Decimal.Value x
_ : BigDecimal -> from_big_decimal x
_ -> x

## PRIVATE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.MaterializedFrame;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.interop.UnsupportedMessageException;
import com.oracle.truffle.api.library.CachedLibrary;
import com.oracle.truffle.api.nodes.ExplodeLoop;
import com.oracle.truffle.api.nodes.Node;
Expand All @@ -25,6 +26,7 @@
import org.enso.interpreter.runtime.data.atom.Atom;
import org.enso.interpreter.runtime.data.atom.AtomConstructor;
import org.enso.interpreter.runtime.data.atom.StructsLibrary;
import org.enso.interpreter.runtime.error.WarningsLibrary;
import org.enso.interpreter.runtime.library.dispatch.TypeOfNode;
import org.enso.interpreter.runtime.state.State;

Expand Down Expand Up @@ -91,16 +93,24 @@ boolean equalsAtomsWithCustomComparator(
@Cached(value = "customComparatorNode.execute(self)") Type cachedComparator,
@Cached(value = "findCompareMethod(cachedComparator)", allowUncached = true)
Function compareFn,
@Cached(value = "invokeCompareNode(compareFn)") InvokeFunctionNode invokeNode) {
var otherComparator = customComparatorNode.execute(other);
if (cachedComparator != otherComparator) {
return false;
@Cached(value = "invokeCompareNode(compareFn)") InvokeFunctionNode invokeNode,
@Shared @CachedLibrary(limit = "10") WarningsLibrary warnings) {
try {
var otherComparator = customComparatorNode.execute(other);
if (cachedComparator != otherComparator) {
return false;
}
var ctx = EnsoContext.get(this);
var args = new Object[] {cachedComparator, self, other};
var result = invokeNode.execute(compareFn, null, State.create(ctx), args);
assert orderingOrNullOrError(this, ctx, result, compareFn);
if (warnings.hasWarnings(result)) {
result = warnings.removeWarnings(result);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is better than instanceof. The effect on benchmark results remain to be seen. Possibly one could also use BranchProfile to lower the number of generated IR nodes in case without warnings.

}
return ctx.getBuiltins().ordering().newEqual() == result;
} catch (UnsupportedMessageException e) {
throw EnsoContext.get(this).raiseAssertionPanic(this, null, e);
}
var ctx = EnsoContext.get(this);
var args = new Object[] {cachedComparator, self, other};
var result = invokeNode.execute(compareFn, null, State.create(ctx), args);
assert orderingOrNullOrError(this, ctx, result, compareFn);
return ctx.getBuiltins().ordering().newEqual() == result;
}

@TruffleBoundary
Expand All @@ -123,16 +133,21 @@ private static boolean orderingOrNullOrError(

@Specialization(
replaces = {"equalsAtomsWithDefaultComparator", "equalsAtomsWithCustomComparator"})
boolean equalsAtomsUncached(VirtualFrame frame, Atom self, Atom other) {
boolean equalsAtomsUncached(
VirtualFrame frame,
Atom self,
Atom other,
@Shared @CachedLibrary(limit = "10") WarningsLibrary warnings) {
if (self.getConstructor() != other.getConstructor()) {
return false;
} else {
return equalsAtomsUncached(frame == null ? null : frame.materialize(), self, other);
return equalsAtomsUncached(frame == null ? null : frame.materialize(), self, other, warnings);
}
}

@CompilerDirectives.TruffleBoundary
private boolean equalsAtomsUncached(MaterializedFrame frame, Atom self, Atom other) {
private boolean equalsAtomsUncached(
MaterializedFrame frame, Atom self, Atom other, WarningsLibrary warnings) {
Type customComparator = CustomComparatorNode.getUncached().execute(self);
if (customComparator != null) {
Function compareFunc = findCompareMethod(customComparator);
Expand All @@ -144,7 +159,8 @@ private boolean equalsAtomsUncached(MaterializedFrame frame, Atom self, Atom oth
CustomComparatorNode.getUncached(),
customComparator,
compareFunc,
invokeFuncNode);
invokeFuncNode,
warnings);
}
for (int i = 0; i < self.getConstructor().getArity(); i++) {
var selfField = StructsLibrary.getUncached().getField(self, i);
Expand Down
Loading
Loading