-
Notifications
You must be signed in to change notification settings - Fork 323
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
Add Warnings whenever a floating-point value is used as a Dictionary key #11417
Changes from 13 commits
f1f4033
835dba1
1c4fd38
3f2847e
2277fa5
bb9affb
f9488c0
84dbcba
90fe26b
afead1a
78d19ab
2aefd64
5cb0fc2
8894202
682381f
a900b4f
61a4e1f
6a00aca
cca8aae
5926e02
63eadb4
50691be
f665b51
0e3fa03
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
from Standard.Base import all | ||
import Standard.Base.Errors.Illegal_Argument.Illegal_Argument | ||
import Standard.Base.Errors.No_Such_Key.No_Such_Key | ||
from Standard.Base.Errors.Common import Float_Used_As_Dictionary_Key | ||
|
||
from Standard.Test import all | ||
|
||
|
@@ -269,6 +270,16 @@ add_specs suite_builder = | |
m.at 200 . should_equal 3 | ||
m.at Nothing . should_equal 1 | ||
|
||
group_builder.specify "should attach a warning when a Float is used as a key" <| | ||
m = Dictionary.empty . insert 1.2 3 | ||
m.at 1.2 . should_equal 3 | ||
Problems.expect_only_warning Float_Used_As_Dictionary_Key m | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please also add a test that checks if we have the same behaviour when we construct the dictionary using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
|
||
group_builder.specify "should attach a warning when a Float is used as a key (using from_vector)" <| | ||
m = Dictionary.from_vector [[2, 3], [1.2, 3], [4, 5]] | ||
m.at 1.2 . should_equal 3 | ||
Problems.expect_only_warning Float_Used_As_Dictionary_Key m | ||
|
||
suite_builder.group "Polyglot keys and values" group_builder-> | ||
group_builder.specify "should support polyglot keys" pending=pending_js_missing <| | ||
dict = Dictionary.singleton (js_str "A") 42 | ||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -9,13 +9,16 @@ polyglot java import org.enso.benchmark_helpers.JavaHashMapWrapper | |||||||||
options = Bench.options . set_warmup (Bench.phase_conf 2 2) . set_measure (Bench.phase_conf 2 3) | ||||||||||
|
||||||||||
type Data | ||||||||||
Value ~ints | ||||||||||
Value ~dense_ints ~sparse_ints | ||||||||||
|
||||||||||
create n = | ||||||||||
create_ints = | ||||||||||
create_dense_ints = | ||||||||||
Vector.new n _-> | ||||||||||
Random.integer 0 ((n.div 100) - 1) | ||||||||||
Data.Value create_ints | ||||||||||
create_sparse_ints = | ||||||||||
Vector.new n _-> | ||||||||||
Random.integer 0 (n - 1) | ||||||||||
Data.Value create_dense_ints create_sparse_ints | ||||||||||
|
||||||||||
type Scenario | ||||||||||
Instance map_constructor | ||||||||||
|
@@ -43,15 +46,23 @@ collect_benches = Bench.build builder-> | |||||||||
|
||||||||||
builder.group ("Enso_Hash_Map_" + n.to_text) options group_builder-> | ||||||||||
# Scenario similar to what is done in distinct | ||||||||||
# 'Sparse' ints have fewer duplicates and cause more inserts to happen. | ||||||||||
group_builder.specify "Enso_Sparse_Incremental" <| | ||||||||||
Scenario.Instance (_ -> Dictionary.empty) . run_distinct data.sparse_ints | ||||||||||
group_builder.specify "Java_Sparse_Incremental" <| | ||||||||||
Scenario.Instance (_ -> JavaHashMapWrapper.new) . run_distinct data.sparse_ints | ||||||||||
|
||||||||||
# Scenario similar to what is done in distinct | ||||||||||
# 'Dense' ints have more duplicates and cause fewer inserts to happen. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd add
Suggested change
(assuming it's true, but it feels it should be) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||||||||||
group_builder.specify "Enso_Incremental" <| | ||||||||||
Scenario.Instance (_ -> Dictionary.empty) . run_distinct data.ints | ||||||||||
Scenario.Instance (_ -> Dictionary.empty) . run_distinct data.dense_ints | ||||||||||
group_builder.specify "Java_Incremental" <| | ||||||||||
Scenario.Instance (_ -> JavaHashMapWrapper.new) . run_distinct data.ints | ||||||||||
Scenario.Instance (_ -> JavaHashMapWrapper.new) . run_distinct data.dense_ints | ||||||||||
|
||||||||||
# A scenario similar to what is done in add_row_number with grouping | ||||||||||
group_builder.specify "Enso_Replacement" <| | ||||||||||
Scenario.Instance (_ -> Dictionary.empty) . run_count_keys data.ints | ||||||||||
Scenario.Instance (_ -> Dictionary.empty) . run_count_keys data.dense_ints | ||||||||||
group_builder.specify "Java_Replacement" <| | ||||||||||
Scenario.Instance (_ -> JavaHashMapWrapper.new) . run_count_keys data.ints | ||||||||||
Scenario.Instance (_ -> JavaHashMapWrapper.new) . run_count_keys data.dense_ints | ||||||||||
|
||||||||||
main = collect_benches . run_main |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This type feels slightly redundant with already existing
Floating_Point_Equality
.However, I do like that we get a more precise message ('Float used as dictionary key'). What about merging this into the
Floating_Point_Equality
error, perhaps by distinguishing different constructors (we already have multi-constructor errors, e.g.Invalid_Value_Type
).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done -- moved
Floating_Point_Equality
intoBase
.