diff options
author | Iain Buclaw <ibuclaw@gdcproject.org> | 2022-10-29 09:05:54 +0200 |
---|---|---|
committer | Iain Buclaw <ibuclaw@gdcproject.org> | 2022-10-29 13:02:26 +0200 |
commit | 7e7ebe3e350fde90fe49ab41ce3b92a811bb6370 (patch) | |
tree | be7a6dd9ae43a807ff7107d51ed03069a4a336f2 /libphobos/src/std/exception.d | |
parent | cfd85418051e8413e84ae7011cb5cb99cd8e337c (diff) | |
download | gcc-7e7ebe3e350fde90fe49ab41ce3b92a811bb6370.zip gcc-7e7ebe3e350fde90fe49ab41ce3b92a811bb6370.tar.gz gcc-7e7ebe3e350fde90fe49ab41ce3b92a811bb6370.tar.bz2 |
d: Merge upstream dmd, druntime e4f8919591, phobos 3ad507b51.
D front-end changes:
- Import dmd v2.101.0-beta.1.
- Add predefined version `D_Optimized' when compiling with `-O'.
- Shortened method syntax (DIP1043) is now enabled by default.
- Array literals assigned to `scope' array variables are now
allocated on the stack.
- Implement `@system' variables (DIP1035), available behind the
preview feature flag `-fpreview=systemvariables'.
D runtime changes:
- Import druntime v2.101.0-beta.1.
Phobos changes:
- Import phobos v2.101.0-beta.1.
- Added `std.typecons.SafeRefCounted', that can be used in `@safe'
code with `-fpreview=dip1000'.
gcc/d/ChangeLog:
* d-attribs.cc (apply_user_attributes): Update for new front-end
interface.
* d-builtins.cc (d_init_versions): Predefine `D_Optimized' with
compiling with optimizations enabled.
* d-lang.cc (d_handle_option): Update for new front-end interface.
Handle new option `-fpreview=systemvariables'.
* dmd/MERGE: Merge upstream dmd e4f8919591.
* dmd/VERSION: Bump version to v2.101.0-beta.1.
* expr.cc (ExprVisitor::visit (AssignExp *)): Treat construction of
static arrays from a call expression as a simple assignment.
(ExprVisitor::visit (ArrayLiteralExp *)): Handle array literals with
`scope' storage.
* gdc.texi: Update documentation of `-fpreview=' options.
* lang.opt (fpreview=shortenedmethods): Remove.
(fpreview=systemvariables): New option.
libphobos/ChangeLog:
* libdruntime/MERGE: Merge upstream druntime e4f8919591.
* src/MERGE: Merge upstream phobos 3ad507b51.
gcc/testsuite/ChangeLog:
* gdc.dg/simd19630.d: Move tests with errors to ...
* gdc.dg/simd19630b.d: ... here. New test.
* gdc.dg/simd19630c.d: New test.
* gdc.dg/simd_ctfe.d: Removed.
* gdc.dg/simd18867.d: New test.
* gdc.dg/simd19788.d: New test.
* gdc.dg/simd21469.d: New test.
* gdc.dg/simd21672.d: New test.
* gdc.dg/simd23077.d: New test.
* gdc.dg/simd23084.d: New test.
* gdc.dg/simd23085.d: New test.
* gdc.dg/torture/simd19632.d: New test.
* gdc.dg/torture/simd20041.d: New test.
* gdc.dg/torture/simd21673.d: New test.
* gdc.dg/torture/simd21676.d: New test.
* gdc.dg/torture/simd22438.d: New test.
* gdc.dg/torture/simd23009.d: New test.
* gdc.dg/torture/simd23077.d: New test.
* gdc.dg/torture/simd8.d: New test.
* gdc.dg/torture/simd9.d: New test.
* gdc.dg/torture/simd_prefetch.d: New test.
Diffstat (limited to 'libphobos/src/std/exception.d')
-rw-r--r-- | libphobos/src/std/exception.d | 203 |
1 files changed, 101 insertions, 102 deletions
diff --git a/libphobos/src/std/exception.d b/libphobos/src/std/exception.d index 94a2e7a..129c05d 100644 --- a/libphobos/src/std/exception.d +++ b/libphobos/src/std/exception.d @@ -799,108 +799,107 @@ enum emptyExceptionMsg = "<Empty Exception Message>"; } /** - * Casts a mutable array to an immutable array in an idiomatic - * manner. Technically, `assumeUnique` just inserts a cast, - * but its name documents assumptions on the part of the - * caller. `assumeUnique(arr)` should only be called when - * there are no more active mutable aliases to elements of $(D - * arr). To strengthen this assumption, `assumeUnique(arr)` - * also clears `arr` before returning. Essentially $(D - * assumeUnique(arr)) indicates commitment from the caller that there - * is no more mutable access to any of `arr`'s elements - * (transitively), and that all future accesses will be done through - * the immutable array returned by `assumeUnique`. - * - * Typically, `assumeUnique` is used to return arrays from - * functions that have allocated and built them. - * - * Params: - * array = The array to cast to immutable. - * - * Returns: The immutable array. - * - * Example: - * - * $(RUNNABLE_EXAMPLE - * ---- - * string letters() - * { - * char[] result = new char['z' - 'a' + 1]; - * foreach (i, ref e; result) - * { - * e = cast(char)('a' + i); - * } - * return assumeUnique(result); - * } - * ---- - * ) - * - * The use in the example above is correct because `result` - * was private to `letters` and is inaccessible in writing - * after the function returns. The following example shows an - * incorrect use of `assumeUnique`. - * - * Bad: - * - * $(RUNNABLE_EXAMPLE - * ---- - * private char[] buffer; - * string letters(char first, char last) - * { - * if (first >= last) return null; // fine - * auto sneaky = buffer; - * sneaky.length = last - first + 1; - * foreach (i, ref e; sneaky) - * { - * e = cast(char)('a' + i); - * } - * return assumeUnique(sneaky); // BAD - * } - * ---- - * ) - * - * The example above wreaks havoc on client code because it is - * modifying arrays that callers considered immutable. To obtain an - * immutable array from the writable array `buffer`, replace - * the last line with: - * - * ---- - * return to!(string)(sneaky); // not that sneaky anymore - * ---- - * - * The call will duplicate the array appropriately. - * - * Note that checking for uniqueness during compilation is - * possible in certain cases, especially when a function is - * marked as a pure function. The following example does not - * need to call assumeUnique because the compiler can infer the - * uniqueness of the array in the pure function: - * - * $(RUNNABLE_EXAMPLE - * ---- - * string letters() pure - * { - * char[] result = new char['z' - 'a' + 1]; - * foreach (i, ref e; result) - * { - * e = cast(char)('a' + i); - * } - * return result; - * } - * ---- - * ) - * - * For more on infering uniqueness see the $(B unique) and - * $(B lent) keywords in the - * $(HTTP www.cs.cmu.edu/~aldrich/papers/aldrich-dissertation.pdf, ArchJava) - * language. - * - * The downside of using `assumeUnique`'s - * convention-based usage is that at this time there is no - * formal checking of the correctness of the assumption; - * on the upside, the idiomatic use of `assumeUnique` is - * simple and rare enough to be tolerable. - * +Casts a mutable array to an immutable array in an idiomatic +manner. Technically, `assumeUnique` just inserts a cast, +but its name documents assumptions on the part of the +caller. `assumeUnique(arr)` should only be called when +there are no more active mutable aliases to elements of $(D +arr). To strengthen this assumption, `assumeUnique(arr)` +also clears `arr` before returning. Essentially $(D +assumeUnique(arr)) indicates commitment from the caller that there +is no more mutable access to any of `arr`'s elements +(transitively), and that all future accesses will be done through +the immutable array returned by `assumeUnique`. + +Typically, `assumeUnique` is used to return arrays from +functions that have allocated and built them. + +Params: + array = The array to cast to immutable. + +Returns: The immutable array. + +Example: + +$(RUNNABLE_EXAMPLE +---- +string letters() +{ + char[] result = new char['z' - 'a' + 1]; + foreach (i, ref e; result) + { + e = cast(char)('a' + i); + } + return assumeUnique(result); +} +---- +) + +The use in the example above is correct because `result` +was private to `letters` and is inaccessible in writing +after the function returns. The following example shows an +incorrect use of `assumeUnique`. + +Bad: + +$(RUNNABLE_EXAMPLE +---- +char[] buffer; +string letters(char first, char last) +{ + if (first >= last) return null; // fine + auto sneaky = buffer; + sneaky.length = last - first + 1; + foreach (i, ref e; sneaky) + { + e = cast(char)('a' + i); + } + return assumeUnique(sneaky); // BAD +} +---- +) + +The example above wreaks havoc on client code because it is +modifying arrays that callers considered immutable. To obtain an +immutable array from the writable array `buffer`, replace +the last line with: + +---- +return to!(string)(sneaky); // not that sneaky anymore +---- + +The call will duplicate the array appropriately. + +Note that checking for uniqueness during compilation is +possible in certain cases, especially when a function is +marked as a pure function. The following example does not +need to call `assumeUnique` because the compiler can infer the +uniqueness of the array in the pure function: + +$(RUNNABLE_EXAMPLE +---- +static string letters() pure +{ + char[] result = new char['z' - 'a' + 1]; + foreach (i, ref e; result) + { + e = cast(char)('a' + i); + } + return result; +} +---- +) + +For more on infering uniqueness see the $(B unique) and +$(B lent) keywords in the +$(HTTP www.cs.cmu.edu/~aldrich/papers/aldrich-dissertation.pdf, ArchJava) +language. + +The downside of using `assumeUnique`'s +convention-based usage is that at this time there is no +formal checking of the correctness of the assumption; +on the upside, the idiomatic use of `assumeUnique` is +simple and rare enough to be tolerable. */ immutable(T)[] assumeUnique(T)(T[] array) pure nothrow { |