aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/test/map_SUITE.erl
AgeCommit message (Collapse)Author
2018-07-13Fix a rare crash when matching on literal mapsJohn Högberg
When matching on a literal map, the map is placed into the general scratch register first. This is fine in isolation, but when the key to be matched was in a Y register it would also be placed in the scratch register, overwriting the map and crashing the emulator.
2018-04-29Introduce is_map_key/2 guard BIFMichał Muskała
This complements the `map_get/2` guard BIF introduced in #1784. Rationale. `map_get/2` allows accessing map fields in guards, but it might be problematic in more complex guard expressions, for example: foo(X) when map_get(a, X) =:= 1 or is_list(X) -> ... The `is_list/1` part of the guard could never succeed since the `map_get/2` guard would fail the whole guard expression. In this situation, this could be solved by using `;` instead of `or` to separate the guards, but it is not possible in every case. To solve this situation, this PR proposes a `is_map_key/2` guard that allows to check if a map has key inside a guard before trying to access that key. When combined with `is_map/1` this allows to construct a purely boolean guard expression testing a value of a key in a map. Implementation. Given the use case motivating the introduction of this function, the PR contains compiler optimisations that produce optimial code for the following guard expression: foo(X) when is_map(X) and is_map_key(a, X) and map_get(a, X) =:= 1 -> ok; foo(_) -> error. Given all three tests share the failure label, the `is_map_key/2` and `is_map/2` tests are optimised away. As with `map_get/2` the `is_map_key/2` BIF is allowed in match specs.
2018-04-24Introduce map_get guard-safe functionMichał Muskała
Rationale Today all compound data types except for maps can be deconstructed in guards. For tuples we have `element/2` and for lists `hd/1` and `tl/1`. Maps are completely opaque to guards. This means matching on maps can't be abstracted into macros, which is often done with repetitive guards. It also means that maps have to be always selected whole from ETS tables, even when only one field would be enough, which creates a potential efficiency issue. This PR introduces an `erlang:map_get/2` guard-safe function that allows extracting a map field in guard. An alternative to this function would be to introduce the syntax for extracting a value from a map that was planned in the original EEP: `Map#{Key}`. Even outside of guards, since this function is a guard-BIF it is more efficient than using `maps:get/2` (since it does not need to set up the stack), and more convenient from pattern matching on the map (compare: `#{key := Value} = Map, Value` to `map_get(key, Map)`). Performance considerations A common concern against adding this function is the notion that "guards have to be fast" and ideally execute in constant time. While there are some counterexamples (`length/1`), what is more important is the fact that adding those functions does not change in any way the time complexity of pattern matching - it's already possible to match on map fields today directly in patterns - adding this ability to guards will niether slow down or speed up the execution, it will only make certain programs more convenient to write. This first version is very naive and does not perform any optimizations.
2017-11-20erts: Remove erts_internal:maps_to_list/2Lukas Larsson
This function is no longer needed as maps:iterator has now been implemented.
2017-11-20erts: Implement batching maps:iteratorLukas Larsson
This iterator implementation fetches multiple elements to iterate over in one call to erts_internal:maps_next instead of one at a time. This means that the memory usage will go up for the iterator as we are buffering elements, but the usage is still bounded. In this implementation the max memory usage is 1000 words. Using this approach makes the iterator as fast as using maps:to_list, so maps:iterator/2 has been removed.
2017-10-13erts: Implement maps path iteratorLukas Larsson
2017-02-23erts: Test erts_internal:maps_to_list/2Björn-Egil Dahlberg
2017-01-25Update test cases for erlang:hash/2 removalBjörn-Egil Dahlberg
2016-07-21erts: Update maps entropy testsBjörn-Egil Dahlberg
2016-04-27erts: Add tests for maps:take/2Björn-Egil Dahlberg
2016-03-11Cleaner map_SUITEBjörn-Egil Dahlberg
2015-12-14Merge branch 'bjorn/deprecate-random/OTP-12502'Björn Gustavsson
* bjorn/deprecate-random/OTP-12502: Deprecate the 'random' module Eliminate mentions of 'random' in documentation mnesia tests: Replace 'random' with 'rand' percept tests: Replace 'random' with 'rand' system tests: Replace 'random' with 'rand' common_test tests: Replace 'random' with 'rand' gs: Remove the contribs directory wx: Replace 'random' with 'rand' stdlib tests: Replace 'random' with 'rand' kernel test: Replace 'random' with 'rand' debugger tests: Replace 'random' with 'rand' compiler tests: Replace 'random' with 'rand' Emulator test suite: Replace use of 'random' with 'rand' Use 'rand' instead of the obsolete 'random' module compile: Eliminate use of the obsolete 'random' module
2015-12-11Emulator test suite: Replace use of 'random' with 'rand'Björn Gustavsson
2015-12-09Merge branch 'sverk/dist-ctrl-msg-overflow-master' into masterSverker Eriksson
* sverk/dist-ctrl-msg-overflow-master: erts: Tweak hashmap heap size estimation erts: Fix bug for remote control message containing fat maps erts: Add test for remote exit signal with fat map erts: Fix bug in heap_factory_undo for FACTORY_HEAP_FRAGS mode
2015-12-07erts: Change erts_internal:map_type/1 into term_type/1Sverker Eriksson
to support other terms, not just maps
2015-12-07erts: Add test for remote exit signal with fat mapSverker Eriksson
2015-11-30Merge branch 'sverk/rare-gc-map-overflow/OTP-13146' into maintSverker Eriksson
* sverk/rare-gc-map-overflow/OTP-13146: erts: Fix rare case of faulty heap fragment deallocation
2015-11-27erts: Fix rare case of faulty heap fragment deallocationSverker Eriksson
after major GC. Can only be caused by distributed messages containing large maps. Bad map hashing will increase the risk.
2015-11-20erts: More testcases for map binary_to_term/1Björn-Egil Dahlberg
2015-06-30Merge branch 'sverk/map-merge-trap' into maintSverker Eriksson
* sverk/map-merge-trap: erts: Expand test map_SUITE:t_bif_merge_and_check
2015-06-22erts: Expand test map_SUITE:t_bif_merge_and_checkSverker Eriksson
with merge of randomized maps.
2015-06-18Change license text to APLv2Bruce Yinhe
2015-06-08erts: Fix faulty list optimization in make_internal_hashBjörn-Egil Dahlberg
Reported-by: Rory Byrne
2015-05-08Merge branch 'rickard/time-improvement/OTP-11997'Rickard Green
* rickard/time-improvement/OTP-11997: Allow execution of estone suite on pre OTP-18 systems Add parallel time monotonicity test-case Replace usage of erlang:now() in line-tracing Replace erlang:now() usage in emulator suite Replace erlang:now() usage in system suite Misc time improvements
2015-05-06Replace erlang:now() usage in emulator suiteRickard Green
2015-04-15Raise more descriptive error messages for failed map operationsBjörn Gustavsson
According to EEP-43 for maps, a 'badmap' exception should be generated when an attempt is made to update non-map term such as: <<>>#{a=>42} That was not implemented in the OTP 17. José Valim suggested that we should take the opportunity to improve the errors coming from map operations: http://erlang.org/pipermail/erlang-questions/2015-February/083588.html This commit implement better errors from map operations similar to his suggestion. When a map update operation (Map#{...}) or a BIF that expects a map is given a non-map term, the exception will be: {badmap,Term} This kind of exception is similar to the {badfun,Term} exception from operations that expect a fun. When a map operation requires a key that is not present in a map, the following exception will be raised: {badkey,Key} José Valim suggested that the exception should be {badkey,Key,Map}. We decided not to do that because the map could potentially be huge and cause problems if the error propagated through links to other processes. For BIFs, it could be argued that the exceptions could be simply 'badmap' and 'badkey', because the bad map and bad key can be found in the argument list for the BIF in the stack backtrace. However, for the map update operation (Map#{...}), the bad map or bad key will not be included in the stack backtrace, so that information must be included in the exception reason itself. For consistency, the BIFs should raise the same exceptions as update operation. If more than one key is missing, it is undefined which of keys that will be reported in the {badkey,Key} exception.
2015-04-13beam_emu: Slightly optimize update_map_{assoc,exact}Björn Gustavsson
In the update loop for big maps, the E variable is restored for each turn of the loop. It only needs to be restored if a garbage collection has been performed. Also add a new test case that attempts to force several garbage collections while updating a map, to help us find bugs with incorrect restoration of the E variable after a garbage collection.
2015-04-13Sort maps keys in the loaderBjörn Gustavsson
The map instructions require that the keys in the instructions are sorted (for flatmaps). But that is an implementation detail that should not exposed outside of the BEAM virtual machine. Therefore, make the sorting of the keys the responsibility of the loader and not the compiler. Also note that the sort order for maps with numeric keys or keys with numeric components has changed in OTP 18. That means that code compiled for OTP 17 that operated on maps with map keys might not work in OTP 18 without the sorting in the loader (although it is unlikely to be an issue in practice).
2015-04-13erts/map_SUITE.erl: Add a test case that tests has_map_fieldsBjörn Gustavsson
The has_map_fields instruction was not tested at all by erts/map_SUITE.erl
2015-04-13map_SUITE: Add tests of is_map/1 with literal mapsBjörn Gustavsson
To be sure that the compiler and BEAM virtual machine correctly handles literals maps, we must test it.
2015-04-10Merge branch 'egil/maps-test-coverage'Björn-Egil Dahlberg
* egil/maps-test-coverage: erts: Remove code that was commented out erts: Cover maps:values/1 for large maps erts: Test maps:from_list/1 shrinking
2015-04-09erts: Cover maps:values/1 for large mapsBjörn-Egil Dahlberg
2015-04-09erts: Test maps:from_list/1 shrinkingBjörn-Egil Dahlberg
Repeated keys will shrink map to a flatmap if the number of pairs drops below the limit.
2015-04-07erts: Fix deep colliding hash values in maps:from_list/1Björn-Egil Dahlberg
Reported-by: Jesper Louis Andersen
2015-04-01Merge branch 'egil/fix-maps-tmp-heap'Björn-Egil Dahlberg
* egil/fix-maps-tmp-heap: erts: Test deep Maps updates erts: Use halfword secure tmp heap erts: Remove unused tmp heap in make_internal_hash Conflicts: erts/emulator/test/map_SUITE.erl
2015-04-01Merge branch 'egil/fix-maps-from_list-size'Björn-Egil Dahlberg
* egil/fix-maps-from_list-size: erts: Strengthen Maps merge tests erts: Try to test deep Maps collision erts: Fix size bug in maps:from_list/1 BIF
2015-03-31erts: Test deep Maps updatesBjörn-Egil Dahlberg
2015-03-31erts: Strengthen Maps merge testsBjörn-Egil Dahlberg
2015-03-31erts: Try to test deep Maps collisionBjörn-Egil Dahlberg
Ensure maps:size/1 is correct.
2015-03-30erts: Strengthen Maps testsBjörn-Egil Dahlberg
2015-03-30Merge branch 'egil/fix-make_internal_hash-float'Björn-Egil Dahlberg
* egil/fix-make_internal_hash-float: erts: Add tests for internal_hash erts: Fix make_internal_hash for 0.0 vs -0.0
2015-03-27erts: Add tests for internal_hashBjörn-Egil Dahlberg
2015-03-27erts: Strengthen Maps testsBjörn-Egil Dahlberg
2015-03-25Merge branch 'sverk/hamt-term2bin-bug/OTP-12585'Sverker Eriksson
* sverk/hamt-term2bin-bug/OTP-12585: erts: Optimize hashmap_get erts: Remove HAMT_SUBTAG_NODE_ARRAY erts: Fix bug in binary_to_term for hamt when yielding erts: Rename to flatmap_from_validated_list
2015-03-25Merge branch 'maint'Björn-Egil Dahlberg
Conflicts: erts/emulator/beam/erl_map.c erts/emulator/test/map_SUITE.erl
2015-03-24erts: Remove HAMT_SUBTAG_NODE_ARRAYSverker Eriksson
This will also fix a bug in term_to_binary treating full nodes as tuples and emiting LIST_EXT for leafs.
2015-03-24erts: Fix comparison of exact termsBjörn-Egil Dahlberg
Comparison of exact terms could cause faulty term tests. This was caused by a faulty (too small) internal type. Symptom: -1 = erts_internal:cmp_term(2147483648,0). %% wrong Correct: 1 = erts_internal:cmp_term(2147483648,0). Reported-by: Jesper Louis Andersen
2015-03-20erts: Add test map_SUITE:t_hashmap_balanceSverker Eriksson
2015-03-19erts: Fix bug in binary_to_term with more than one big mapSverker Eriksson
2015-03-13erts: Enhance maps ordering testsBjörn-Egil Dahlberg