From f3e8c2e4a97ba54c36593c98120c4f0cc8f44cd9 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sat, 5 Oct 2019 09:58:51 -0700 Subject: [PATCH 01/16] Update codegen option documentation. --- src/doc/rustc/src/codegen-options/index.md | 204 ++++++++++++++++---- src/doc/rustc/src/command-line-arguments.md | 99 +++++++--- 2 files changed, 235 insertions(+), 68 deletions(-) diff --git a/src/doc/rustc/src/codegen-options/index.md b/src/doc/rustc/src/codegen-options/index.md index f5d5f2089d7e7..b9252b461bb0a 100644 --- a/src/doc/rustc/src/codegen-options/index.md +++ b/src/doc/rustc/src/codegen-options/index.md @@ -9,9 +9,12 @@ This option is deprecated and does nothing. ## linker -This flag lets you control which linker `rustc` invokes to link your code. +This flag lets you control which linker `rustc` invokes to link your code. It +takes a path to the linker executable. If this flag is not specified, the +linker will be inferred based on the target. See also the +[linker-flavor](#linker-flavor) flag for another way to specify the linker. -## link-arg=val +## link-arg This flag lets you append a single extra argument to the linker invocation. @@ -25,9 +28,27 @@ options should be separated by spaces. ## linker-flavor This flag lets you control the linker flavor used by `rustc`. If a linker is given with the -`-C linker` flag described above then the linker flavor is inferred from the value provided. If no +[`-C linker` flag](#linker), then the linker flavor is inferred from the value provided. If no linker is given then the linker flavor is used to determine the linker to use. Every `rustc` target -defaults to some linker flavor. +defaults to some linker flavor. Valid options are: + +* `em`: Uses [Emscripten `emcc`](https://emscripten.org/docs/tools_reference/emcc.html). +* `gcc`: Uses the `cc` executable, which is typically gcc or clang on many systems. +* `ld`: Uses the `ld` executable. +* `msvc`: Uses the `link.exe` executable from Microsoft Visual Studio MSVC. +* `ptx-linker`: Uses + [`rust-ptx-linker`](https://github.com/denzp/rust-ptx-linker) for Nvidia + NVPTX GPGPU support. +* `wasm-ld`: Uses the [`wasm-ld`](https://lld.llvm.org/WebAssembly.html) + executable, a port of LLVM `lld` for WebAssembly. +* `ld64.lld`: Uses the LLVM `lld` executable with the [`-flavor darwin` + flag][lld-flavor] for Apple's `ld`. +* `ld.lld`: Uses the LLVM `lld` executable with the [`-flavor gnu` + flag][lld-flavor] for GNU binutils' `ld`. +* `lld-link`: Uses the LLVM `lld` executable with the [`-flavor link` + flag][lld-flavor] for Microsoft's `link.exe`. + +[lld-flavor]: https://lld.llvm.org/Driver.html ## link-dead-code @@ -39,11 +60,36 @@ metrics. ## lto This flag instructs LLVM to use [link time -optimizations](https://llvm.org/docs/LinkTimeOptimization.html). +optimizations](https://llvm.org/docs/LinkTimeOptimization.html) to produce +better optimized code using whole-program analysis at the cost of longer +linking time. -It takes one of two values, `thin` and `fat`. 'thin' LTO [is a new feature of -LLVM](http://blog.llvm.org/2016/06/thinlto-scalable-and-incremental-lto.html), -'fat' referring to the classic version of LTO. +This flag may take one of the following values: + +* `y`, `yes`, `on`, `fat`, or no value: Performs "fat" LTO which attempts to + perform optimizations across all crates within the dependency graph. +* `n`, `no`, `off`: Disables LTO. +* `thin`: Performs ["thin" + LTO](http://blog.llvm.org/2016/06/thinlto-scalable-and-incremental-lto.html). + This is similar to "fat", but takes substantially less time to run while + still achieving performance gains similar to "fat". + +If `-C lto` is not specified, then it will attempt to perform "thin local LTO" +which performs "thin" LTO on the local crate only across its [codegen +units](#codegen-units). In this case, LTO is disabled if codegen units is 1 or +optimizations are disabled ([`-C opt-level=0`](#opt-level)). + +See also [linker-plugin-lto](#linker-plugin-lto) for cross-language LTO. + +## linker-plugin-lto + +Defers LTO optimizations to the linker. See +[linkger-plugin-LTO](../linker-plugin-lto.md) for more details. Takes one of +the following values: + +* `y`, `yes`, `on`, or no value: Enabled. +* `n`, `no`, or `off`: Disabled (default). +* A path to the linker plugin. ## target-cpu @@ -51,30 +97,47 @@ This instructs `rustc` to generate code specifically for a particular processor. You can run `rustc --print target-cpus` to see the valid options to pass here. Additionally, `native` can be passed to use the processor of the host -machine. +machine. Each target has a default base CPU. ## target-feature Individual targets will support different features; this flag lets you control -enabling or disabling a feature. +enabling or disabling a feature. Each feature should be prefixed with a `+` to +enable it or `-` to disable it. Separate multiple features with commas. To see the valid options and an example of use, run `rustc --print target-features`. -Using this flag is unsafe and might result in [undefined runtime behavior](../targets/known-issues.md). +Using this flag is unsafe and might result in [undefined runtime +behavior](../targets/known-issues.md). + +See also the [`target_feature` +attribute](../../reference/attributes/codegen.md#the-target_feature-attribute) +for controlling features per-function. + +This also supports the feature `+crt-static` and `-crt-static` to control +[static C runtime linkage](../../reference/linkage.html#static-and-dynamic-c-runtimes). + +Each target and [`target-cpu`](#target-cpu) has a default set of enabled +features. ## passes -This flag can be used to add extra LLVM passes to the compilation. +This flag can be used to add extra [LLVM +passes](http://llvm.org/docs/Passes.html) to the compilation. The list must be separated by spaces. +See also the [`no-prepopulate-passes`](#no-prepopulate-passes) flag. + ## llvm-args This flag can be used to pass a list of arguments directly to LLVM. The list must be separated by spaces. +Pass `--help` to see a list of options. + ## save-temps `rustc` will generate temporary files during compilation; normally it will @@ -83,16 +146,21 @@ preserved instead of removed. ## rpath -This option allows you to set the value of +This option allows you to enable [`rpath`](https://en.wikipedia.org/wiki/Rpath). ## overflow-checks -This flag allows you to control the behavior of integer overflow. This flag -can be passed many options: +This flag allows you to control the behavior of [runtime integer +overflow](../../reference/expressions/operator-expr.md#overflow). When +overflow-checks are enabled, a panic will occur on overflow. This flag takes +one of the following values: + +* `y`, `yes`, `on`, or no value: Enable overflow checks. +* `n`, `no`, or `off`: Disable overflow checks. -* To turn overflow checks on: `y`, `yes`, or `on`. -* To turn overflow checks off: `n`, `no`, or `off`. +If not specified, overflow checks are enabled if +[debug-assertions](#debug-assertions) are enabled, disabled otherwise. ## no-prepopulate-passes @@ -125,25 +193,30 @@ make it use dynamic linking instead. ## no-integrated-as -LLVM comes with an internal assembler; this option will let you use an -external assembler instead. +`rustc` normally uses the LLVM internal assembler to create object code. This +flag will disable the internal assembler and emit assembly code to be +translated using an external assembler, currently the linker such as `cc`. ## no-redzone This flag allows you to disable [the red zone](https://en.wikipedia.org/wiki/Red_zone_\(computing\)). This flag can -be passed many options: +be passed one of the following options: -* To enable the red zone: `y`, `yes`, or `on`. -* To disable it: `n`, `no`, or `off`. +* `y`, `yes`, `on`, or no value: Disables the red zone. +* `n`, `no`, or `off`: Enables the red zone. + +The default if not specified depends on the target. ## relocation-model -This option lets you choose which relocation model to use. +This option lets you choose which +[relocation](https://en.wikipedia.org/wiki/Relocation_\(computing\)) model to +use. To find the valid options for this flag, run `rustc --print relocation-models`. -## code-model=val +## code-model This option lets you choose which code model to use. @@ -151,23 +224,31 @@ To find the valid options for this flag, run `rustc --print code-models`. ## metadata -This option allows you to control the metadata used for symbol mangling. +This option allows you to control the metadata used for symbol mangling. This +takes a space-separated list of strings. Mangled symbols will incorporate a +hash of the metadata. This may be used, for example, to differentiate symbols +between two different versions of the same crate being linked. ## extra-filename -This option allows you to put extra data in each output filename. +This option allows you to put extra data in each output filename. It takes a +string to add as a suffix to the filename. See the [`--emit` +flag][option-emit] for more information. ## codegen-units -This flag lets you control how many threads are used when doing -code generation. +This flag lets you control how many threads are used when doing code +generation. It takes an integer greater than 0. + +Increasing parallelism may speed up compile times, but may also produce slower +code. Setting this to 1 may improve the performance of generated code, but may +be slower to compile. -Increasing parallelism may speed up compile times, but may also -produce slower code. +The default if not specified is 16. ## remark -This flag lets you print remarks for these optimization passes. +This flag lets you print remarks for optimization passes. The list of passes should be separated by spaces. @@ -181,30 +262,47 @@ This option is deprecated and does nothing. This flag lets you control debug information: -* `0`: no debug info at all +* `0`: no debug info at all (default) * `1`: line tables only * `2`: full debug info +Note: The [`-g` flag][option-g-debug] is an alias for `-C debuginfo=2`. + ## opt-level This flag lets you control the optimization level. -* `0`: no optimizations, also turn on `cfg(debug_assertions)`. +* `0`: no optimizations, also turn on [`cfg(debug_assertions)`](#debug-assertions). * `1`: basic optimizations * `2`: some optimizations * `3`: all optimizations * `s`: optimize for binary size * `z`: optimize for binary size, but also turn off loop vectorization. +Note: The [`-O` flag][option-o-optimize] is an alias for `-C opt-level=2`. + +The default is `0`. + ## debug-assertions -This flag lets you turn `cfg(debug_assertions)` on or off. +This flag lets you turn `cfg(debug_assertions)` [conditional +compilation](../../reference/conditional-compilation.md#debug_assertions) on +or off. It takes one of the following values: + +* `y`, `yes`, `on`, or no value: Enable debug-assertions. +* `n`, `no`, or `off`: Disable debug-assertions. + +If not specified, debug assertions are enabled only if the +[opt-level](#opt-level) is 0. ## inline-threshold -This option lets you set the threshold for inlining a function. +This option lets you set the threshold for inlining a function. It takes a +positive integer as a value. Inlining is based on a cost model, where a higher +threshold will allow more inlining. -The default is 225. +The default depends on the [opt-level](#opt-level). Current values are between +25 to 275. ## panic @@ -213,9 +311,14 @@ This option lets you control what happens when the code panics. * `abort`: terminate the process upon panic * `unwind`: unwind the stack upon panic +If not specified, the default depends on the target. + ## incremental -This flag allows you to enable incremental compilation. +This flag allows you to enable incremental compilation, which allows `rustc` +to save information after compiling a crate to be reused when recompiling the +crate, improving re-compile times. This takes a path to a directory where +incremental files will be stored. ## profile-generate @@ -232,4 +335,31 @@ optimization (PGO). The flag takes a mandatory argument which is the path to a valid `.profdata` file. See the chapter on [profile-guided optimization] for more information. +## force-frame-pointers + +This flag forces the use of frame pointers. It takes one of the following +values: + +* `y`, `yes`, `on`, or no value: Frame pointers are forced to be enabled. +* `n`, `no`, or `off`: Frame pointers are not forced to be enabled. This does + not necessarily mean frame pointers will be removed. + +The default if not specified depends on the target. + +## default-linker-libraries + +This flag controls whether or not the linker includes its default libraries. +It takes one of the following values: + +* `y`, `yes`, `on`, or no value: Default libraries are included. +* `n`, `no`, or `off`: Default libraries are **not** included. + +For example, for gcc flavor linkers, this issues the `-nodefaultlibs` flag to +the linker. + +The default is `yes` if not specified. + +[option-emit]: ../command-line-arguments.md#option-emit +[option-o-optimize]: ../command-line-arguments.md#option-o-optimize [profile-guided optimization]: ../profile-guided-optimization.md +[option-g-debug]: ../command-line-arguments.md#option-g-debug diff --git a/src/doc/rustc/src/command-line-arguments.md b/src/doc/rustc/src/command-line-arguments.md index bdb3c5196585e..79b4f7542f9b0 100644 --- a/src/doc/rustc/src/command-line-arguments.md +++ b/src/doc/rustc/src/command-line-arguments.md @@ -2,19 +2,23 @@ Here's a list of command-line arguments to `rustc` and what they do. + ## `-h`/`--help`: get help This flag will print out help information for `rustc`. + ## `--cfg`: configure the compilation environment -This flag can turn on or off various `#[cfg]` settings. +This flag can turn on or off various `#[cfg]` settings for [conditional +compilation](../reference/conditional-compilation.md). The value can either be a single identifier or two identifiers separated by `=`. For examples, `--cfg 'verbose'` or `--cfg 'feature="serde"'`. These correspond to `#[cfg(verbose)]` and `#[cfg(feature = "serde")]` respectively. + ## `-L`: add a directory to the library search path When looking for external crates or libraries, a directory passed to this flag @@ -31,6 +35,7 @@ KIND=PATH` where `KIND` may be one of: - `all` — Search for all library kinds in this directory. This is the default if `KIND` is not specified. + ## `-l`: link the generated crate to a native library This flag allows you to specify linking to a specific native library when building @@ -55,6 +60,7 @@ and `LINK_NAME` is the name of the actual library that will be linked. [link-attribute]: ../reference/items/external-blocks.html#the-link-attribute + ## `--crate-type`: a list of types of crates for the compiler to emit This instructs `rustc` on which crate type to build. This flag accepts a @@ -80,10 +86,12 @@ More details may be found in the [linkage chapter] of the reference. [linkage chapter]: ../reference/linkage.html [crate_type]: ../reference/linkage.html + ## `--crate-name`: specify the name of the crate being built This informs `rustc` of the name of your crate. + ## `--edition`: specify the edition to use This flag takes a value of `2015` or `2018`. The default is `2015`. More @@ -91,8 +99,8 @@ information about editions may be found in the [edition guide]. [edition guide]: ../edition-guide/introduction.html + ## `--emit`: specifies the types of output files to generate - This flag controls the types of output files generated by the compiler. It accepts a comma-separated list of values, and may be specified multiple times. @@ -117,22 +125,24 @@ The valid emit kinds are: - `obj` — Generates a native object file. The default output filename is `CRATE_NAME.o`. -The output filename can be set with the `-o` flag. A suffix may be added to -the filename with the `-C extra-filename` flag. The files are written to the -current directory unless the `--out-dir` flag is used. Each emission type may -also specify the output filename with the form `KIND=PATH`, which takes -precedence over the `-o` flag. +The output filename can be set with the [`-o` flag](#option-o-output). A +suffix may be added to the filename with the [`-C extra-filename` +flag](codegen-options/index.md#extra-filename). The files are written to the +current directory unless the [`--out-dir` flag](#option-out-dir) is used. Each +emission type may also specify the output filename with the form `KIND=PATH`, +which takes precedence over the `-o` flag. [LLVM bitcode]: https://llvm.org/docs/BitCodeFormat.html [LLVM IR]: https://llvm.org/docs/LangRef.html + ## `--print`: print compiler information This flag prints out various information about the compiler. This flag may be specified multiple times, and the information is printed in the order the flags are specified. Specifying a `--print` flag will usually disable the -`--emit` step and will only print the requested information. The valid types -of print values are: +[`--emit`](#option-emit) step and will only print the requested information. +The valid types of print values are: - `crate-name` — The name of the crate. - `file-names` — The names of the files created by the `link` emit kind. @@ -142,14 +152,17 @@ of print values are: - `target-list` — List of known targets. The target may be selected with the `--target` flag. - `target-cpus` — List of available CPU values for the current target. The - target CPU may be selected with the `-C target-cpu=val` flag. + target CPU may be selected with the [`-C target-cpu=val` + flag](codegen-options/index.md#target-cpu). - `target-features` — List of available target features for the current - target. Target features may be enabled with the `-C target-feature=val` - flag. This flag is unsafe. See [known issues](targets/known-issues.md) for more details. + target. Target features may be enabled with the [`-C target-feature=val` + flag](codegen-options/index.md#target-feature). This flag is unsafe. See + [known issues](targets/known-issues.md) for more details. - `relocation-models` — List of relocation models. Relocation models may be - selected with the `-C relocation-model=val` flag. + selected with the [`-C relocation-model=val` + flag](codegen-options/index.md#relocation-model). - `code-models` — List of code models. Code models may be selected with the - `-C code-model=val` flag. + [`-C code-model=val` flag](codegen-options/index.md#code-model). - `tls-models` — List of Thread Local Storage models supported. The model may be selected with the `-Z tls-model=val` flag. - `native-static-libs` — This may be used when creating a `staticlib` crate @@ -160,53 +173,65 @@ of print values are: [conditional compilation]: ../reference/conditional-compilation.html + ## `-g`: include debug information -A synonym for `-C debuginfo=2`, for more see [here](codegen-options/index.md#debuginfo). +A synonym for [`-C debuginfo=2`](codegen-options/index.md#debuginfo). + ## `-O`: optimize your code -A synonym for `-C opt-level=2`, for more see [here](codegen-options/index.md#opt-level). +A synonym for [`-C opt-level=2`](codegen-options/index.md#opt-level). + ## `-o`: filename of the output This flag controls the output filename. + ## `--out-dir`: directory to write the output in The outputted crate will be written to this directory. This flag is ignored if -the `-o` flag is used. +the [`-o` flag](#option-o-output) is used. + ## `--explain`: provide a detailed explanation of an error message Each error of `rustc`'s comes with an error code; this will print out a longer explanation of a given error. + ## `--test`: build a test harness When compiling this crate, `rustc` will ignore your `main` function and instead produce a test harness. + ## `--target`: select a target triple to build This controls which [target](targets/index.md) to produce. + ## `-W`: set lint warnings This flag will set which lints should be set to the [warn level](lints/levels.md#warn). + ## `-A`: set lint allowed This flag will set which lints should be set to the [allow level](lints/levels.md#allow). + ## `-D`: set lint denied This flag will set which lints should be set to the [deny level](lints/levels.md#deny). + ## `-F`: set lint forbidden This flag will set which lints should be set to the [forbid level](lints/levels.md#forbid). + ## `-Z`: set unstable options This flag will allow you to set unstable options of rustc. In order to set multiple options, @@ -214,35 +239,41 @@ the -Z flag can be used multiple times. For example: `rustc -Z verbose -Z time`. Specifying options with -Z is only available on nightly. To view all available options run: `rustc -Z help`. + ## `--cap-lints`: set the most restrictive lint level This flag lets you 'cap' lints, for more, [see here](lints/levels.md#capping-lints). + ## `-C`/`--codegen`: code generation options This flag will allow you to set [codegen options](codegen-options/index.md). + ## `-V`/`--version`: print a version This flag will print out `rustc`'s version. + ## `-v`/`--verbose`: use verbose output This flag, when combined with other flags, makes them produce extra output. + ## `--extern`: specify where an external library is located This flag allows you to pass the name and location of an external crate that will be linked into the crate you are building. This flag may be specified multiple times. The format of the value should be `CRATENAME=PATH`. + ## `--sysroot`: Override the system root The "sysroot" is where `rustc` looks for the crates that come with the Rust distribution; this flag allows that to be overridden. + ## `--error-format`: control how errors are produced - This flag lets you control the format of messages. Messages are printed to stderr. The valid options are: @@ -251,6 +282,7 @@ stderr. The valid options are: - `json` — Structured JSON output. See [the JSON chapter] for more detail. - `short` — Short, one-line messages. + ## `--color`: configure coloring of output This flag lets you control color settings of the output. The valid options @@ -260,6 +292,7 @@ are: - `always` — Always use colors. - `never` — Never colorize output. + ## `--remap-path-prefix`: remap source names in output Remap source path prefixes in all output, including compiler diagnostics, @@ -274,13 +307,14 @@ replacement is purely textual, with no consideration of the current system's pathname syntax. For example `--remap-path-prefix foo=bar` will match `foo/lib.rs` but not `./foo/lib.rs`. + ## `--json`: configure json messages printed by the compiler - -When the `--error-format=json` option is passed to rustc then all of the -compiler's diagnostic output will be emitted in the form of JSON blobs. The -`--json` argument can be used in conjunction with `--error-format=json` to -configure what the JSON blobs contain as well as which ones are emitted. +When the [`--error-format=json` option](#option-error-format) is passed to +rustc then all of the compiler's diagnostic output will be emitted in the form +of JSON blobs. The `--json` argument can be used in conjunction with +`--error-format=json` to configure what the JSON blobs contain as well as +which ones are emitted. With `--error-format=json` the compiler will always emit any compiler errors as a JSON blob, but the following options are also available to the `--json` flag @@ -296,20 +330,23 @@ to customize the output: indicates that the diagnostic should have embedded ANSI color codes intended to be used to colorize the message in the manner rustc typically already does for terminal outputs. Note that this is usefully combined with crates like - `fwdansi` to translate these ANSI codes on Windows to console commands or - `strip-ansi-escapes` if you'd like to optionally remove the ansi colors - afterwards. + [`fwdansi`](https://crates.io/crates/fwdansi) to translate these ANSI codes + on Windows to console commands or + [`strip-ansi-escapes`](https://crates.io/crates/strip-ansi-escapes) if you'd + like to optionally remove the ansi colors afterwards. - `artifacts` - this instructs rustc to emit a JSON blob for each artifact that - is emitted. An artifact corresponds to a request from the `--emit` CLI - argument, and as soon as the artifact is available on the filesystem a - notification will be emitted. + is emitted. An artifact corresponds to a request from the [`--emit` CLI + argument](#option-emit), and as soon as the artifact is available on the + filesystem a notification will be emitted. -Note that it is invalid to combine the `--json` argument with the `--color` -argument, and it is required to combine `--json` with `--error-format=json`. +Note that it is invalid to combine the `--json` argument with the +[`--color`](#option-color) argument, and it is required to combine `--json` +with `--error-format=json`. See [the JSON chapter] for more detail. + ## `@path`: load command-line flags from a path If you specify `@path` on the command-line, then it will open `path` and read From bd70c032273b873a0318636aea8f7a5b22b60e31 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sat, 26 Oct 2019 09:05:57 -0700 Subject: [PATCH 02/16] Apply suggestions from kinnison Co-Authored-By: Daniel Silverstone --- src/doc/rustc/src/codegen-options/index.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/doc/rustc/src/codegen-options/index.md b/src/doc/rustc/src/codegen-options/index.md index b9252b461bb0a..a35a14c8abcf1 100644 --- a/src/doc/rustc/src/codegen-options/index.md +++ b/src/doc/rustc/src/codegen-options/index.md @@ -61,7 +61,7 @@ metrics. This flag instructs LLVM to use [link time optimizations](https://llvm.org/docs/LinkTimeOptimization.html) to produce -better optimized code using whole-program analysis at the cost of longer +better optimized code, using whole-program analysis, at the cost of longer linking time. This flag may take one of the following values: @@ -74,7 +74,7 @@ This flag may take one of the following values: This is similar to "fat", but takes substantially less time to run while still achieving performance gains similar to "fat". -If `-C lto` is not specified, then it will attempt to perform "thin local LTO" +If `-C lto` is not specified, then the compiler will attempt to perform "thin local LTO" which performs "thin" LTO on the local crate only across its [codegen units](#codegen-units). In this case, LTO is disabled if codegen units is 1 or optimizations are disabled ([`-C opt-level=0`](#opt-level)). @@ -244,7 +244,7 @@ Increasing parallelism may speed up compile times, but may also produce slower code. Setting this to 1 may improve the performance of generated code, but may be slower to compile. -The default if not specified is 16. +The default, if not specified, is 16. ## remark @@ -272,7 +272,7 @@ Note: The [`-g` flag][option-g-debug] is an alias for `-C debuginfo=2`. This flag lets you control the optimization level. -* `0`: no optimizations, also turn on [`cfg(debug_assertions)`](#debug-assertions). +* `0`: no optimizations, also turns on [`cfg(debug_assertions)`](#debug-assertions). * `1`: basic optimizations * `2`: some optimizations * `3`: all optimizations @@ -292,7 +292,7 @@ or off. It takes one of the following values: * `y`, `yes`, `on`, or no value: Enable debug-assertions. * `n`, `no`, or `off`: Disable debug-assertions. -If not specified, debug assertions are enabled only if the +If not specified, debug assertions are automatically enabled only if the [opt-level](#opt-level) is 0. ## inline-threshold From c6bfe28b9563dc6d4d03f4d632048b6b6ae76317 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sat, 26 Oct 2019 09:05:06 -0700 Subject: [PATCH 03/16] Be more specific with -C inline-threshold. --- src/doc/rustc/src/codegen-options/index.md | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/doc/rustc/src/codegen-options/index.md b/src/doc/rustc/src/codegen-options/index.md index a35a14c8abcf1..686313ea3d0cf 100644 --- a/src/doc/rustc/src/codegen-options/index.md +++ b/src/doc/rustc/src/codegen-options/index.md @@ -297,12 +297,20 @@ If not specified, debug assertions are automatically enabled only if the ## inline-threshold -This option lets you set the threshold for inlining a function. It takes a -positive integer as a value. Inlining is based on a cost model, where a higher -threshold will allow more inlining. - -The default depends on the [opt-level](#opt-level). Current values are between -25 to 275. +This option lets you set the default threshold for inlining a function. It +takes an unsigned integer as a value. Inlining is based on a cost model, where +a higher threshold will allow more inlining. + +The default depends on the [opt-level](#opt-level): + +| opt-level | Threshold | +|-----------|-----------| +| 0 | N/A, only inlines always-inline functions | +| 1 | N/A, only inlines always-inline functions and LLVM lifetime intrinsics | +| 2 | 225 | +| 3 | 275 | +| s | 75 | +| z | 25 | ## panic From 096c99b6ebbf0b015e920f75ac84f2b3b71b291f Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Mon, 28 Oct 2019 13:01:02 -0700 Subject: [PATCH 04/16] [doc] add a possessive apostrophe in `OpenOptionsExt::mode` --- src/libstd/sys/unix/ext/fs.rs | 2 +- src/libstd/sys/vxworks/ext/fs.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libstd/sys/unix/ext/fs.rs b/src/libstd/sys/unix/ext/fs.rs index c033c60cbe9e1..2236ecea910d5 100644 --- a/src/libstd/sys/unix/ext/fs.rs +++ b/src/libstd/sys/unix/ext/fs.rs @@ -306,7 +306,7 @@ pub trait OpenOptionsExt { /// If a new file is created as part of a `File::open_opts` call then this /// specified `mode` will be used as the permission bits for the new file. /// If no `mode` is set, the default of `0o666` will be used. - /// The operating system masks out bits with the systems `umask`, to produce + /// The operating system masks out bits with the system's `umask`, to produce /// the final permissions. /// /// # Examples diff --git a/src/libstd/sys/vxworks/ext/fs.rs b/src/libstd/sys/vxworks/ext/fs.rs index 7ab7f2a1a2645..a0147460a424d 100644 --- a/src/libstd/sys/vxworks/ext/fs.rs +++ b/src/libstd/sys/vxworks/ext/fs.rs @@ -307,7 +307,7 @@ pub trait OpenOptionsExt { /// If a new file is created as part of a `File::open_opts` call then this /// specified `mode` will be used as the permission bits for the new file. /// If no `mode` is set, the default of `0o666` will be used. - /// The operating system masks out bits with the systems `umask`, to produce + /// The operating system masks out bits with the system's `umask`, to produce /// the final permissions. /// /// # Examples From 624e7d7cd0ed643e5064b9312d78634caff41e1a Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Mon, 28 Oct 2019 13:03:18 -0700 Subject: [PATCH 05/16] [doc] fix the reference to using `OpenOptions::open` --- src/libstd/sys/unix/ext/fs.rs | 2 +- src/libstd/sys/vxworks/ext/fs.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libstd/sys/unix/ext/fs.rs b/src/libstd/sys/unix/ext/fs.rs index 2236ecea910d5..0c52dc5b81b0e 100644 --- a/src/libstd/sys/unix/ext/fs.rs +++ b/src/libstd/sys/unix/ext/fs.rs @@ -303,7 +303,7 @@ impl PermissionsExt for Permissions { pub trait OpenOptionsExt { /// Sets the mode bits that a new file will be created with. /// - /// If a new file is created as part of a `File::open_opts` call then this + /// If a new file is created as part of an `OpenOptions::open` call then this /// specified `mode` will be used as the permission bits for the new file. /// If no `mode` is set, the default of `0o666` will be used. /// The operating system masks out bits with the system's `umask`, to produce diff --git a/src/libstd/sys/vxworks/ext/fs.rs b/src/libstd/sys/vxworks/ext/fs.rs index a0147460a424d..4a9cc3bd0693c 100644 --- a/src/libstd/sys/vxworks/ext/fs.rs +++ b/src/libstd/sys/vxworks/ext/fs.rs @@ -304,7 +304,7 @@ impl PermissionsExt for Permissions { pub trait OpenOptionsExt { /// Sets the mode bits that a new file will be created with. /// - /// If a new file is created as part of a `File::open_opts` call then this + /// If a new file is created as part of an `OpenOptions::open` call then this /// specified `mode` will be used as the permission bits for the new file. /// If no `mode` is set, the default of `0o666` will be used. /// The operating system masks out bits with the system's `umask`, to produce From e1974a4f1f05fc5c1c10d87cb20937ef87a68d9d Mon Sep 17 00:00:00 2001 From: Kevin Cox Date: Wed, 30 Oct 2019 12:56:54 +0000 Subject: [PATCH 06/16] Fix logic in example. The example claims SuperiorThanZero and presumably Zero is not Superior than itself so it should not be allowed. --- src/libcore/convert.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/convert.rs b/src/libcore/convert.rs index 3cd2337ee59a5..0cef6707e47e6 100644 --- a/src/libcore/convert.rs +++ b/src/libcore/convert.rs @@ -444,7 +444,7 @@ pub trait TryInto: Sized { /// type Error = &'static str; /// /// fn try_from(value: i32) -> Result { -/// if value < 0 { +/// if value <= 0 { /// Err("SuperiorThanZero only accepts value superior than zero!") /// } else { /// Ok(SuperiorThanZero(value)) From a844e59d2b9a1271576a3ee043f3a634b63cc16b Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Thu, 31 Oct 2019 14:02:38 +0200 Subject: [PATCH 07/16] docs: improve disclaimer regarding LinkedList --- src/liballoc/collections/linked_list.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/liballoc/collections/linked_list.rs b/src/liballoc/collections/linked_list.rs index 702df250999fb..48f9865b87036 100644 --- a/src/liballoc/collections/linked_list.rs +++ b/src/liballoc/collections/linked_list.rs @@ -3,11 +3,11 @@ //! The `LinkedList` allows pushing and popping elements at either end //! in constant time. //! -//! Almost always it is better to use `Vec` or [`VecDeque`] instead of -//! [`LinkedList`]. In general, array-based containers are faster, -//! more memory efficient and make better use of CPU cache. +//! NOTE: It is almost always better to use [`Vec`] or [`VecDeque`] because +//! array-based containers are generally faster, +//! more memory efficient, and make better use of CPU cache. //! -//! [`LinkedList`]: ../linked_list/struct.LinkedList.html +//! [`Vec`]: ../../vec/struct.Vec.html //! [`VecDeque`]: ../vec_deque/struct.VecDeque.html #![stable(feature = "rust1", since = "1.0.0")] @@ -31,9 +31,9 @@ mod tests; /// The `LinkedList` allows pushing and popping elements at either end /// in constant time. /// -/// Almost always it is better to use `Vec` or `VecDeque` instead of -/// `LinkedList`. In general, array-based containers are faster, -/// more memory efficient and make better use of CPU cache. +/// NOTE: It is almost always better to use `Vec` or `VecDeque` because +/// array-based containers are generally faster, +/// more memory efficient, and make better use of CPU cache. #[stable(feature = "rust1", since = "1.0.0")] pub struct LinkedList { head: Option>>, From 595d8186567966addaa930e3e8b5939b536a7dcb Mon Sep 17 00:00:00 2001 From: Oleg Nosov Date: Fri, 1 Nov 2019 18:00:25 +0300 Subject: [PATCH 08/16] Fixed std::iter::Chain documentation --- src/libcore/iter/adapters/chain.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/iter/adapters/chain.rs b/src/libcore/iter/adapters/chain.rs index c9612596b1ba0..3b669cad1c40f 100644 --- a/src/libcore/iter/adapters/chain.rs +++ b/src/libcore/iter/adapters/chain.rs @@ -3,7 +3,7 @@ use crate::usize; use super::super::{Iterator, DoubleEndedIterator, FusedIterator, TrustedLen}; -/// An iterator that strings two iterators together. +/// An iterator that links two iterators together, in a chain. /// /// This `struct` is created by the [`chain`] method on [`Iterator`]. See its /// documentation for more. From d9ec5fa88ca0c082aa2089b372e7981f9d514e82 Mon Sep 17 00:00:00 2001 From: Jeff Dickey <216188+jdxcode@users.noreply.github.com> Date: Fri, 1 Nov 2019 19:42:33 -0700 Subject: [PATCH 09/16] doc(str): show example of chars().count() under len() the docs are great at explaining that .len() isn't like in other languages but stops short of explaining how to get the character length. r? @steveklabnik --- src/liballoc/string.rs | 9 +++++++-- src/libcore/str/mod.rs | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index d9927c642b2d8..0e5746d0d9df0 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -1402,7 +1402,9 @@ impl String { &mut self.vec } - /// Returns the length of this `String`, in bytes. + /// Returns the length of this `String`, in bytes, not [`char`]s or + /// graphemes. In other words, it may not be what a human considers the + /// length of the string. /// /// # Examples /// @@ -1410,8 +1412,11 @@ impl String { /// /// ``` /// let a = String::from("foo"); - /// /// assert_eq!(a.len(), 3); + /// + /// let fancy_f = String::from("ƒoo"); + /// assert_eq!(fancy_f.len(), 4); + /// assert_eq!(fancy_f.chars().count(), 3); /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index f67012d8f2fce..1968919f5541c 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -2085,8 +2085,8 @@ impl str { /// let len = "foo".len(); /// assert_eq!(3, len); /// - /// let len = "ƒoo".len(); // fancy f! - /// assert_eq!(4, len); + /// assert_eq!("ƒoo".len(), 4); // fancy f! + /// assert_eq!("ƒoo".chars().count(), 3); /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] From 5558fe8a9207b000b1cab9f3d521b06b144d6f8f Mon Sep 17 00:00:00 2001 From: Ohad Ravid Date: Fri, 1 Nov 2019 13:50:36 +0100 Subject: [PATCH 10/16] Suggest correct code when encountering an incorrect trait bound referencing the current trait --- src/librustc_typeck/astconv.rs | 18 +++++++++++++++++- src/librustc_typeck/check/mod.rs | 4 ++++ src/librustc_typeck/collect.rs | 4 ++++ .../associated-types-in-ambiguous-context.rs | 7 +++++++ ...ssociated-types-in-ambiguous-context.stderr | 10 ++++++++-- 5 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index aa05a08686a99..8bcf51eb9e3c0 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -43,6 +43,8 @@ pub struct PathSeg(pub DefId, pub usize); pub trait AstConv<'tcx> { fn tcx<'a>(&'a self) -> TyCtxt<'tcx>; + fn item_def_id(&self) -> Option; + /// Returns predicates in scope of the form `X: Foo`, where `X` is /// a type parameter `X` with the given id `def_id`. This is a /// subset of the full set of predicates. @@ -1759,17 +1761,31 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { -> Ty<'tcx> { let tcx = self.tcx(); + let trait_def_id = tcx.parent(item_def_id).unwrap(); + debug!("qpath_to_ty: trait_def_id={:?}", trait_def_id); + self.prohibit_generics(slice::from_ref(item_segment)); let self_ty = if let Some(ty) = opt_self_ty { ty } else { let path_str = tcx.def_path_str(trait_def_id); + + // If the trait in segment is the same as the trait defining the item, + // use the `` syntax in the error. + debug!("qpath_to_ty: self.item_def_id()={:?}", self.item_def_id()); + + let type_name = if self.item_def_id() == Some(trait_def_id) { + "Self" + } else { + "Type" + }; + self.report_ambiguous_associated_type( span, - "Type", + type_name, &path_str, item_segment.ident.name, ); diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index f7132cd868aac..a2af29aef094b 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -2279,6 +2279,10 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> { self.tcx } + fn item_def_id(&self) -> Option { + None + } + fn get_type_parameter_bounds(&self, _: Span, def_id: DefId) -> ty::GenericPredicates<'tcx> { let tcx = self.tcx; let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 001d98aece2a0..7ef842cb7579c 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -182,6 +182,10 @@ impl AstConv<'tcx> for ItemCtxt<'tcx> { self.tcx } + fn item_def_id(&self) -> Option { + Some(self.item_def_id) + } + fn get_type_parameter_bounds(&self, span: Span, def_id: DefId) -> ty::GenericPredicates<'tcx> { self.tcx .at(span) diff --git a/src/test/ui/associated-types/associated-types-in-ambiguous-context.rs b/src/test/ui/associated-types/associated-types-in-ambiguous-context.rs index 1b1ea9d52a98d..202eecfa7b7f5 100644 --- a/src/test/ui/associated-types/associated-types-in-ambiguous-context.rs +++ b/src/test/ui/associated-types/associated-types-in-ambiguous-context.rs @@ -12,6 +12,13 @@ trait Grab { //~^ ERROR ambiguous associated type } +trait Bar {} + +trait Foo where Foo::Assoc: Bar { +//~^ ERROR ambiguous associated type + type Assoc; +} + type X = std::ops::Deref::Target; //~^ ERROR ambiguous associated type diff --git a/src/test/ui/associated-types/associated-types-in-ambiguous-context.stderr b/src/test/ui/associated-types/associated-types-in-ambiguous-context.stderr index 83667b54807e2..db6dec6e899dc 100644 --- a/src/test/ui/associated-types/associated-types-in-ambiguous-context.stderr +++ b/src/test/ui/associated-types/associated-types-in-ambiguous-context.stderr @@ -5,7 +5,13 @@ LL | fn get(x: T, y: U) -> Get::Value {} | ^^^^^^^^^^ help: use fully-qualified syntax: `::Value` error[E0223]: ambiguous associated type - --> $DIR/associated-types-in-ambiguous-context.rs:15:10 + --> $DIR/associated-types-in-ambiguous-context.rs:17:17 + | +LL | trait Foo where Foo::Assoc: Bar { + | ^^^^^^^^^^ help: use fully-qualified syntax: `::Assoc` + +error[E0223]: ambiguous associated type + --> $DIR/associated-types-in-ambiguous-context.rs:22:10 | LL | type X = std::ops::Deref::Target; | ^^^^^^^^^^^^^^^^^^^^^^^ help: use fully-qualified syntax: `::Target` @@ -16,6 +22,6 @@ error[E0223]: ambiguous associated type LL | fn grab(&self) -> Grab::Value; | ^^^^^^^^^^^ help: use fully-qualified syntax: `::Value` -error: aborting due to 3 previous errors +error: aborting due to 4 previous errors For more information about this error, try `rustc --explain E0223`. From 8c909344ed19c9f9a51f82c8e270ded09671fd8b Mon Sep 17 00:00:00 2001 From: Ohad Ravid Date: Sat, 2 Nov 2019 09:49:05 +0100 Subject: [PATCH 11/16] Suggest more likely code when encountering an incorrect assoc item referencing the current trait --- src/librustc_typeck/astconv.rs | 14 ++++++++++++-- .../associated-types-in-ambiguous-context.rs | 3 +++ .../associated-types-in-ambiguous-context.stderr | 14 ++++++++++---- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 8bcf51eb9e3c0..b14121da79f59 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -1773,11 +1773,21 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { } else { let path_str = tcx.def_path_str(trait_def_id); + let def_id = self.item_def_id(); + + debug!("qpath_to_ty: self.item_def_id()={:?}", def_id); + + let parent_def_id = def_id.and_then(|def_id| tcx.hir().as_local_hir_id(def_id)) + .map(|hir_id| tcx.hir().get_parent_did(hir_id)); + + debug!("qpath_to_ty: parent_def_id={:?}", parent_def_id); + // If the trait in segment is the same as the trait defining the item, // use the `` syntax in the error. - debug!("qpath_to_ty: self.item_def_id()={:?}", self.item_def_id()); + let is_part_of_self_trait_constraints = def_id == Some(trait_def_id); + let is_part_of_fn_in_self_trait = parent_def_id == Some(trait_def_id); - let type_name = if self.item_def_id() == Some(trait_def_id) { + let type_name = if is_part_of_self_trait_constraints || is_part_of_fn_in_self_trait { "Self" } else { "Type" diff --git a/src/test/ui/associated-types/associated-types-in-ambiguous-context.rs b/src/test/ui/associated-types/associated-types-in-ambiguous-context.rs index 202eecfa7b7f5..51b53908f98c3 100644 --- a/src/test/ui/associated-types/associated-types-in-ambiguous-context.rs +++ b/src/test/ui/associated-types/associated-types-in-ambiguous-context.rs @@ -10,6 +10,9 @@ trait Grab { type Value; fn grab(&self) -> Grab::Value; //~^ ERROR ambiguous associated type + + fn get(&self) -> Get::Value; + //~^ ERROR ambiguous associated type } trait Bar {} diff --git a/src/test/ui/associated-types/associated-types-in-ambiguous-context.stderr b/src/test/ui/associated-types/associated-types-in-ambiguous-context.stderr index db6dec6e899dc..77835c5f6766e 100644 --- a/src/test/ui/associated-types/associated-types-in-ambiguous-context.stderr +++ b/src/test/ui/associated-types/associated-types-in-ambiguous-context.stderr @@ -5,13 +5,13 @@ LL | fn get(x: T, y: U) -> Get::Value {} | ^^^^^^^^^^ help: use fully-qualified syntax: `::Value` error[E0223]: ambiguous associated type - --> $DIR/associated-types-in-ambiguous-context.rs:17:17 + --> $DIR/associated-types-in-ambiguous-context.rs:20:17 | LL | trait Foo where Foo::Assoc: Bar { | ^^^^^^^^^^ help: use fully-qualified syntax: `::Assoc` error[E0223]: ambiguous associated type - --> $DIR/associated-types-in-ambiguous-context.rs:22:10 + --> $DIR/associated-types-in-ambiguous-context.rs:25:10 | LL | type X = std::ops::Deref::Target; | ^^^^^^^^^^^^^^^^^^^^^^^ help: use fully-qualified syntax: `::Target` @@ -20,8 +20,14 @@ error[E0223]: ambiguous associated type --> $DIR/associated-types-in-ambiguous-context.rs:11:23 | LL | fn grab(&self) -> Grab::Value; - | ^^^^^^^^^^^ help: use fully-qualified syntax: `::Value` + | ^^^^^^^^^^^ help: use fully-qualified syntax: `::Value` -error: aborting due to 4 previous errors +error[E0223]: ambiguous associated type + --> $DIR/associated-types-in-ambiguous-context.rs:14:22 + | +LL | fn get(&self) -> Get::Value; + | ^^^^^^^^^^ help: use fully-qualified syntax: `::Value` + +error: aborting due to 5 previous errors For more information about this error, try `rustc --explain E0223`. From e7fd580e7cd68f68cdc585a2f785d49c8fe7fefa Mon Sep 17 00:00:00 2001 From: Kevin Cox Date: Sat, 2 Nov 2019 13:12:07 +0000 Subject: [PATCH 12/16] Rename SuperiorThanZero -> GreaterThanZero --- src/libcore/convert.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libcore/convert.rs b/src/libcore/convert.rs index 0cef6707e47e6..16045f64d461e 100644 --- a/src/libcore/convert.rs +++ b/src/libcore/convert.rs @@ -438,16 +438,16 @@ pub trait TryInto: Sized { /// ``` /// use std::convert::TryFrom; /// -/// struct SuperiorThanZero(i32); +/// struct GreaterThanZero(i32); /// -/// impl TryFrom for SuperiorThanZero { +/// impl TryFrom for GreaterThanZero { /// type Error = &'static str; /// /// fn try_from(value: i32) -> Result { /// if value <= 0 { -/// Err("SuperiorThanZero only accepts value superior than zero!") +/// Err("GreaterThanZero only accepts value superior than zero!") /// } else { -/// Ok(SuperiorThanZero(value)) +/// Ok(GreaterThanZero(value)) /// } /// } /// } From 567962d22090bbd23c1c3dc0e04229ac8c681ea8 Mon Sep 17 00:00:00 2001 From: Simon Heath Date: Wed, 23 Oct 2019 09:08:26 -0400 Subject: [PATCH 13/16] Add FFI bindings for Module::getInstructionCount() Just to make it useable for profiling and such inside rustc itself. It was vaguely useful in https://wiki.alopex.li/WhereRustcSpendsItsTime and I figured I might as well upstream it; I may or may not ever get around to doing more with it (hopefully I will), but it may be useful for others. --- src/librustc_codegen_llvm/llvm/ffi.rs | 1 + src/rustllvm/RustWrapper.cpp | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/src/librustc_codegen_llvm/llvm/ffi.rs b/src/librustc_codegen_llvm/llvm/ffi.rs index b07214fdc03f3..773451a36cd58 100644 --- a/src/librustc_codegen_llvm/llvm/ffi.rs +++ b/src/librustc_codegen_llvm/llvm/ffi.rs @@ -1729,6 +1729,7 @@ extern "C" { ) -> LLVMRustResult; pub fn LLVMRustSetLLVMOptions(Argc: c_int, Argv: *const *const c_char); pub fn LLVMRustPrintPasses(); + pub fn LLVMRustGetInstructionCount(M: &Module) -> u32; pub fn LLVMRustSetNormalizedTarget(M: &Module, triple: *const c_char); pub fn LLVMRustAddAlwaysInlinePass(P: &PassManagerBuilder, AddLifetimes: bool); pub fn LLVMRustRunRestrictionPass(M: &Module, syms: *const *const c_char, len: size_t); diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp index 16d08ee534edc..e6c45b8e3628b 100644 --- a/src/rustllvm/RustWrapper.cpp +++ b/src/rustllvm/RustWrapper.cpp @@ -87,6 +87,14 @@ extern "C" char *LLVMRustGetLastError(void) { return Ret; } +extern "C" unsigned int LLVMRustGetInstructionCount(LLVMModuleRef M) { +#if LLVM_VERSION_GE(7, 0) + return unwrap(M)->getInstructionCount(); +#else + report_fatal_error("Module::getInstructionCount not available before LLVM 7"); +#endif +} + extern "C" void LLVMRustSetLastError(const char *Err) { free((void *)LastError); LastError = strdup(Err); From 9b9d6512880d09722e2af3f8c6e154314fd071af Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sat, 2 Nov 2019 09:47:14 -0700 Subject: [PATCH 14/16] Attempt to clarify LTO and codegen-units. --- src/doc/rustc/src/codegen-options/index.md | 31 +++++++++++++++------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/doc/rustc/src/codegen-options/index.md b/src/doc/rustc/src/codegen-options/index.md index 686313ea3d0cf..70c7acccd3638 100644 --- a/src/doc/rustc/src/codegen-options/index.md +++ b/src/doc/rustc/src/codegen-options/index.md @@ -74,10 +74,18 @@ This flag may take one of the following values: This is similar to "fat", but takes substantially less time to run while still achieving performance gains similar to "fat". -If `-C lto` is not specified, then the compiler will attempt to perform "thin local LTO" -which performs "thin" LTO on the local crate only across its [codegen -units](#codegen-units). In this case, LTO is disabled if codegen units is 1 or -optimizations are disabled ([`-C opt-level=0`](#opt-level)). +If `-C lto` is not specified, then the compiler will attempt to perform "thin +local LTO" which performs "thin" LTO on the local crate only across its +[codegen units](#codegen-units). When `-C lto` is not specified, LTO is +disabled if codegen units is 1 or optimizations are disabled ([`-C +opt-level=0`](#opt-level)). That is: + +* When `-C lto` is not specified: + * `codegen-units=1`: Disables LTO. + * `opt-level=0`: Disables LTO. +* When `-C lto=true`: + * `lto=true`: 16 codegen units, performs fat LTO across crates. + * `codegen-units=1` + `lto=true`: 1 codegen unit, fat LTO across crates. See also [linker-plugin-lto](#linker-plugin-lto) for cross-language LTO. @@ -237,14 +245,17 @@ flag][option-emit] for more information. ## codegen-units -This flag lets you control how many threads are used when doing code -generation. It takes an integer greater than 0. +This flag controls how many code generation units the crate is split into. It +takes an integer greater than 0. -Increasing parallelism may speed up compile times, but may also produce slower -code. Setting this to 1 may improve the performance of generated code, but may -be slower to compile. +When a crate is split into multiple codegen units, LLVM is able to process +them in parallel. Increasing parallelism may speed up compile times, but may +also produce slower code. Setting this to 1 may improve the performance of +generated code, but may be slower to compile. -The default, if not specified, is 16. +The default, if not specified, is 16. This flag is ignored if +[incremental](#incremental) is enabled, in which case an internal heuristic is +used to split the crate. ## remark From 417c09ab2705b38f23b87daa82b1ace0a03a8117 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Sun, 3 Nov 2019 16:52:27 -0500 Subject: [PATCH 15/16] Do not needlessly write-lock --- src/librustc_lint/unused.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs index af43030d0f2ae..3f85e6d772ec1 100644 --- a/src/librustc_lint/unused.rs +++ b/src/librustc_lint/unused.rs @@ -309,7 +309,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedAttributes { } } - let plugin_attributes = cx.sess().plugin_attributes.borrow_mut(); + let plugin_attributes = cx.sess().plugin_attributes.borrow(); for &(name, ty) in plugin_attributes.iter() { if ty == AttributeType::Whitelisted && attr.check_name(name) { debug!("{:?} (plugin attr) is whitelisted with ty {:?}", name, ty); From c8ae2819c5e8eeaa9a1f6435148f8d05fb5f8c56 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Mon, 4 Nov 2019 13:09:02 -0800 Subject: [PATCH 16/16] Add tests for loop constructs in consts These errors are suboptimal, but they will be fixed by the new `check_consts` pass. --- src/test/ui/consts/const-loop.rs | 58 +++++++++++++++++++++++++++ src/test/ui/consts/const-loop.stderr | 60 ++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 src/test/ui/consts/const-loop.rs create mode 100644 src/test/ui/consts/const-loop.stderr diff --git a/src/test/ui/consts/const-loop.rs b/src/test/ui/consts/const-loop.rs new file mode 100644 index 0000000000000..954f269d30e59 --- /dev/null +++ b/src/test/ui/consts/const-loop.rs @@ -0,0 +1,58 @@ +const _: i32 = { + let mut x = 0; + + while x < 4 { + //~^ ERROR constant contains unimplemented expression type + //~| ERROR constant contains unimplemented expression type + x += 1; + } + + while x < 8 { + x += 1; + } + + x +}; + +const _: i32 = { + let mut x = 0; + + for i in 0..4 { + //~^ ERROR constant contains unimplemented expression type + //~| ERROR constant contains unimplemented expression type + //~| ERROR references in constants may only refer to immutable values + //~| ERROR calls in constants are limited to constant functions, tuple + // structs and tuple variants + x += i; + } + + for i in 0..4 { + x += i; + } + + x +}; + +const _: i32 = { + let mut x = 0; + + loop { + x += 1; + if x == 4 { + //~^ ERROR constant contains unimplemented expression type + //~| ERROR constant contains unimplemented expression type + break; + } + } + + loop { + x += 1; + if x == 8 { + break; + } + } + + x +}; + +fn main() {} diff --git a/src/test/ui/consts/const-loop.stderr b/src/test/ui/consts/const-loop.stderr new file mode 100644 index 0000000000000..e6e4e2f5bb808 --- /dev/null +++ b/src/test/ui/consts/const-loop.stderr @@ -0,0 +1,60 @@ +error[E0019]: constant contains unimplemented expression type + --> $DIR/const-loop.rs:4:11 + | +LL | while x < 4 { + | ^^^^^ + +error[E0019]: constant contains unimplemented expression type + --> $DIR/const-loop.rs:4:5 + | +LL | / while x < 4 { +LL | | +LL | | +LL | | x += 1; +LL | | } + | |_____^ + +error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants + --> $DIR/const-loop.rs:20:14 + | +LL | for i in 0..4 { + | ^^^^ + +error[E0019]: constant contains unimplemented expression type + --> $DIR/const-loop.rs:20:14 + | +LL | for i in 0..4 { + | ^^^^ + +error[E0017]: references in constants may only refer to immutable values + --> $DIR/const-loop.rs:20:14 + | +LL | for i in 0..4 { + | ^^^^ constants require immutable values + +error[E0019]: constant contains unimplemented expression type + --> $DIR/const-loop.rs:20:9 + | +LL | for i in 0..4 { + | ^ + +error[E0019]: constant contains unimplemented expression type + --> $DIR/const-loop.rs:41:12 + | +LL | if x == 4 { + | ^^^^^^ + +error[E0019]: constant contains unimplemented expression type + --> $DIR/const-loop.rs:41:9 + | +LL | / if x == 4 { +LL | | +LL | | +LL | | break; +LL | | } + | |_________^ + +error: aborting due to 8 previous errors + +Some errors have detailed explanations: E0015, E0017, E0019. +For more information about an error, try `rustc --explain E0015`.