Commit Graph

2855 Commits

Author SHA1 Message Date
Ilya Gorbunov 893021f22b Introduce runningFold and runningReduce operations
runningFold is a synonym for scan,
runningReduce replaces scanReduce.

#KT-38060
2020-04-15 23:28:07 +03:00
Ilya Gorbunov ea1e16e309 Delegate properties to property references
#KT-8658
2020-04-15 18:37:33 +03:00
Abduqodiri Qurbonzoda 08ff52bee4 Introduce StringBuilder.appendLine in stdlib-common #KT-37839 2020-04-13 14:27:53 +03:00
Ilya Gorbunov ec9c7c98cd Use stubs in reduced js-ir runtime instead of new throwable extensions
To avoid bringing a lot of API required for their full implementation
to reduced runtime.
2020-04-13 09:32:42 +03:00
Ilya Gorbunov 38b1e6beab Make Throwable.printStackTrace() common
#KT-38044
2020-04-13 09:32:42 +03:00
Ilya Gorbunov 408b441a71 Rename extension toStringWithTrace to stackTraceToString
#KT-37603
2020-04-13 09:32:42 +03:00
Ilya Gorbunov 4cc9909a70 Support Firefox stack format
It doesn't include the exception type and message.
2020-04-13 09:32:42 +03:00
Ilya Gorbunov 641f1a55cb Omit common stack frames in JS full stack trace
#KT-37603
2020-04-13 09:32:41 +03:00
Ilya Gorbunov 5fe8071d71 Prevent infinite recursion in case of circular suppressed chains
#KT-37603
2020-04-13 09:32:41 +03:00
Ilya Gorbunov 552bcdb31b Introduce Throwable.toStringWithTrace
#KT-37603
2020-04-13 09:32:41 +03:00
Ilya Gorbunov 7b7263c5bf Implement common Throwable.addSuppressed/suppressed extensions
Instead of `suppressed` Array we provide `suppressedExceptions` List

#KT-23737
2020-04-13 09:32:41 +03:00
Abduqodiri Qurbonzoda f2c05bf82c IR: Move annotation @JsExport to common source set in stdlib #KT-35966 2020-04-11 04:03:57 +03:00
Abduqodiri Qurbonzoda 4a7b1b210a Add onEachIndexed similar to forEachIndexed #KT-37161 2020-04-11 03:47:47 +03:00
Ilya Gorbunov 15319eb88e Implement in-place shuffle for arrays
Minor: reorder shuffle/shuffled extensions more consistently

#KT-25651 Fixed
2020-04-10 11:04:51 +03:00
Ilya Gorbunov e58f1c8932 Introduce Sequence.shuffled
#KT-37751
2020-04-10 10:59:40 +03:00
Dmitry Petrov 9941c255b9 KT-30330 KotlinNothingValueException 2020-04-10 08:47:02 +03:00
Ilya Gorbunov fc9ac67980 Tune parameters of time-sensitive tests
Lessen CPU load on the main thread.
Remove fragile checks.
2020-04-10 01:38:46 +03:00
Mikhail Bogdanov 0ddef7e4e4 Add new options for '-Xjvm-default' 2020-04-09 07:37:33 +02:00
Mikhail Bogdanov c11f38688e Deprecate @JvmDefault 2020-04-09 07:37:31 +02:00
Alexander Udalov 9f758b4f25 Support toString for AdaptedFunctionReference subclasses
Also make it serializable like other lambdas, suspend lambdas and normal
callable references.
2020-04-08 19:16:38 +02:00
Alexander Udalov 0681231e99 Introduce AdaptedFunctionReference runtime class
It's used as a superclass for anonymous classes for adapted function
references. Its main feature is that it _doesn't_ inherit from KFunction
(as opposed to FunctionReference), as per the decision to postpone
reflection support for adapted function references in KT-36024.

 #KT-36024 Fixed
2020-04-08 19:15:38 +02:00
Ilya Gorbunov d115792d9a Move a couple ad-hoc properties to buildSrc/BuildPropertiesExt 2020-04-07 10:54:34 +03:00
Abduqodiri Qurbonzoda 508d0edd6d Add the onEach extension function to the Array #KT-28290 2020-04-07 05:34:20 +03:00
Ilya Gorbunov 01b463993b Use SinceKotlin in primitive companion objects for documentation purpose
Also suppress "div by zero" warnings in JS primitive companions.
2020-04-02 04:43:00 +03:00
Ilya Gorbunov a225842f9b Test that known Floats can fit in FloatArray without over/underflow
But some precision loss can still happen in JS.

Relates to KT-24975
2020-04-02 04:04:04 +03:00
Ilya Gorbunov d88d2cb058 Test new Double/Float constants
Split test expectations based on actual support of enforced Float range

KT-29182, KT-13887
2020-04-02 04:04:04 +03:00
Alexander Udalov 3269a7e693 Change behavior of equals/hashCode on adapted function references
Function references are now equal if they refer to the same function,
and if the parameter/return type adaptation, which happens when a
reference is used where some function type is expected, is exactly the
same. This includes the number of expected positional parameters (which
can be affected by defaults/varargs), whether the coercion of vararg
parameter to Array type happened, and whether the coercion of return
type to Unit happened.

 #KT-37543 Fixed
2020-04-01 14:18:49 +02:00
Ilya Gorbunov f3fc1197ae Add SIZE_BITS and SIZE_BYTES constants to Double and Float
#KT-29182
2020-04-01 08:06:57 +03:00
Ilya Gorbunov 1c93911279 Make Double and Float known values constant
#KT-13887
2020-04-01 08:06:57 +03:00
Ilya Gorbunov 2bb36899da Introduce 'fail' method to throw AssertionError with cause
#KT-37804
2020-03-31 13:37:03 +03:00
Miguel Serra 61ad32f012 Samples of Map functions "contains" and "isNotEmpty"
Co-authored-by: Ilya Gorbunov <ilya.gorbunov@jetbrains.com>
2020-03-31 04:54:51 +03:00
Ilya Gorbunov 606b4db48a Improve samples for partition: add destructuring 2020-03-31 02:04:56 +03:00
n-p-s 7bb7c86fa9 Add samples for partition 2020-03-31 02:04:55 +03:00
Ilya Gorbunov dd2aa3de28 Add sample for filterNot and improve sample for filter 2020-03-31 02:04:55 +03:00
Brian Plummer f887a29279 Add sample for filter 2020-03-31 02:04:55 +03:00
adammc331 840f222867 Add sample for filterNotNull 2020-03-31 02:04:55 +03:00
Scott Weber e8ee405cdb Add sample for text version of chunked 2020-03-31 02:04:55 +03:00
Ilya Gorbunov e8dff3609b Add @ExperimentalUnsignedTypes to unsigned array snapshot extensions 2020-03-26 23:30:19 +03:00
Ilya Gorbunov d7007044c2 Add a note about the Random(...) generators being not thread-safe 2020-03-24 01:37:03 +03:00
Roman Elizarov e26a3ad033 Speed up stdlib readLine function (#3185)
There are several performance optimizations:

* ByteBuffer/CharBuffer/StringBuilder objects pre-allocated and are
  reused on each call to readLine.
* The state for readLine is lazily allocated via JVM classloading
  (using a singleton object).
* There is an auto-detection heuristic for "directEOL" encodings which
  represent LF ('\n') directly as the corresponding byte
  (UTF-8 and many single-byte encodings are like that).
  When "directEOL" encoding is used, then bytes are batched into
  ByteBuffer for a single call to CharsetDecoder.decode which
  results in higher throughput. Otherwise (UTF-16, etc), slower
  byte-by-byte approach is used.
* Bytes and chars are directly moved in/out of byte/char arrays and
  ByteBuffer/CharBuffer wrappers are used only to interface with
  JVM CharsetDecoder class (which is the slowest piece).
* StringBuilder is not used at all for short lines (<=32 chars).

There are also some function improvements to readLine functionality:

* Restriction on "max chars per byte" is lifted, so readLine works with
  all encodings that JVM supports.
* It support on-the-fly changes to system default charset, because
  it rechecks current charset on each call and updates it decoder
  when needed.

All the other features of readLine function are retained:

* It does not read more bytes from System.in than needed, so it
  is compatible with other ways to read System.in. On-the-fly
  changes to System.in are supported.
* It is thread-safe. Its internal mutable state is protected by
  synchronization.
* There is an internal method for tests that supports explicit
  charset specification, but the name of this method has changed.

There are additional tests:

* Check all supported encodings on JVM to make sure that readLine
  works correctly with them all.
* Check unicode code points of different bits length with all standard
  unicode encodings (UTF-8, UTF-16, and UTF-32 in LE/HE byte orders).

Benchmarks that compare different implementations of readLine,
including this one (readLine6NoLV in the set) can be found here:
https://github.com/elizarov/ReadLineBenchmark

Taking BufferedReader as 100% baseline we see that:

* Current readLine is 7.5 times slower than BufferedReader baseline.
* New implementation in this commit is 2.5 timer slower than baseline.
  It is ~3 times faster than existing implementation of readLine.

Altogether these optimizations are enough to enable reading of
~500K lines in sports programming setting under 2s time-limit with
plenty of headroom in time. Example that is using this version of
readLine can be found here:
https://codeforces.com/contest/1322/submission/73005366

#KT-37416 Fixed
2020-03-23 14:36:55 +03:00
Zalim Bashorov 8c7562d338 [CJS BE] don't crash when intersection types passed for a reified parameter
#KT-37163 Fixed
2020-03-13 10:15:53 +03:00
Abduqodiri Qurbonzoda b1fac4e721 Implement reduceIndexedOrNull and reduceRightIndexedOrNull #KT-36866 2020-03-12 18:08:55 +03:00
Abduqodiri Qurbonzoda b60633d79a Add associateWith to Array<T> #KT-30372 2020-03-12 18:06:54 +03:00
Abduqodiri Qurbonzoda e632d58936 Nullable Array.contentEquals/contentHashCode/contentToString #KT-34161 2020-03-12 18:01:23 +03:00
Zalim Bashorov 8e788e2169 [stdlib-js-ir] Copy Boolean and String sources and add equals, hashCode, toString 2020-03-11 12:54:42 +03:00
Zalim Bashorov adfb296e45 [stdlib-js-ir] Add equals, hashCode, toString to some builtins
Namely:
* Throwable;
* primitive numbers except Long (which implemented in Kotlin).
2020-03-11 12:54:42 +03:00
Zalim Bashorov 97e86fb2ce [stdlib-js-ir] Char shouldn't be a data class 2020-03-11 12:54:41 +03:00
Zalim Bashorov 7c874ccf0c [stdlib-js-ir] Hack: mark Char.toString by JsName to force keeping it 2020-03-11 12:54:41 +03:00
Zalim Bashorov 9e7f72382f [stdlib-js-ir] Remove BitUtils object and make all members toplevel
It works slightly better with IR DCE --
we get about 6% less code on box tests.
2020-03-11 12:54:41 +03:00
Zalim Bashorov 43171f67a8 [stdlib-js-ir] Cleanup exceptions 2020-03-11 12:54:41 +03:00