summary refs log tree commit diff
path: root/compiler/rustc_span/src
AgeCommit message (Collapse)AuthorLines
2020-12-25Auto merge of #79762 - Swatinem:remap-doctest-coverage, r=Swatinembors-1/+1
Remap instrument-coverage line numbers in doctests This uses the `SourceMap::doctest_offset_line` method to re-map line numbers from doctests. Remapping columns is not yet done, and rustdoc still does not output the correct filename when running doctests in a workspace. Part of #79417 although I dont consider that fixed until both filenames and columns are mapped correctly. r? `@richkadel` I might jump on zulip the comming days. Still need to figure out how to properly write tests for this, and deal with other doctest issues in the meantime.
2020-12-23Rollup merge of #80297 - jyn514:more-docs, r=bjorn3Guillaume Gomez-1/+1
Add some intra-doc links to compiler docs r? `@pierwill`
2020-12-22Add some intra-doc links to compiler docsJoshua Nelson-1/+1
2020-12-21rustc_span: Provide a reserved identifier check for a specific editionVadim Petrochenkov-11/+32
Edition evaluation is kept lazy because it may be expensive.
2020-12-19Remap instrument-coverage line numbers in doctestsArpad Borsos-1/+1
This uses the `SourceMap::doctest_offset_line` method to re-map line numbers from doctests. Remapping columns is not yet done. Part of issue #79417.
2020-12-18Rollup merge of #80130 - pierwill:patch-7, r=oli-obkRalf Jung-1/+1
docs: Edit rustc_span::symbol::Symbol method Edit wording of the doc comment for [rustc_span::symbol::Symbol::can_be_raw](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/symbol/struct.Symbol.html#method.can_be_raw) to match related methods.
2020-12-17Stop using intermediate macros in definition of symbolsArlie Davis-8/+8
Currently, the rustc_macros::symbols macro generates two `macro_rules!` macros as its output. These two macros are used in rustc_span/src/symbol.rs. This means that each Symbol that we define is represented in the AST of rustc_symbols twice: once in the definition of the `define_symbols!` macro (similarly for the `keywords! macro), and once in the rustc_span::symbols definition. That would be OK if there were only a handful of symbols, but currently we define over 1100 symbols. The definition of the `define_symbols!` macro contains the expanded definition of each symbol, so that's a lot of AST storage wasted on a macro that is used exactly once. This commit removes the `define_symbols` macro, and simply allows the proc macro to directly generate the `rustc_symbols::symbol::sym` module. The benefit is mainly in reducing memory wasted during compilation of rustc itself. It should also reduce memory used by Rust Analyzer. This commit also reduces the size of the AST for symbol definitions, by moving two `#[allow(...)]` attributes from the symbol constants to the `sym` module. This eliminates 2200+ attribute nodes. This commit also eliminates the need for the `digits_array` constant. There's no need to store an array of Symbol values for digits. We can simply define a constant of the base value, and add to that base value.
2020-12-17docs: Edit rustc_span::symbol::Symbol methodpierwill-1/+1
Edit wording of the doc comment for rustc_span::symbol::Symbol::can_be_raw to match related methods.
2020-12-14Switch to Symbol for item.nameJoshua Nelson-0/+4
This decreases the size of `Item` from 680 to 616 bytes. It also does a lot less work since it no longer has to copy as much.
2020-12-10Use Symbol for inline asm register class namesArlie Davis-0/+23
This takes care of one "FIXME": // FIXME: use direct symbol comparison for register class names Instead of using string literals, this uses Symbol for register class names.
2020-12-09Accept arbitrary expressions in key-value attributes at parse timeVadim Petrochenkov-0/+1
2020-12-04Rollup merge of #79678 - jyn514:THE-PAPERCLIP-COMETH, r=varkorDylan DPC-18/+11
Fix some clippy lints Happy to revert these if you think they're less readable, but personally I like them better now (especially the `else { if { ... } }` to `else if { ... }` change).
2020-12-03Fix some clippy lintsJoshua Nelson-18/+11
2020-12-01add const_allocate intrisicVishnunarayan K I-0/+1
2020-11-29Rollup merge of #79464 - GuillaumeGomez:doc-keyword-ident, r=jyn514Dylan DPC-5/+0
Extend doc keyword feature by allowing any ident Part of #51315. As suggested by ``@danielhenrymantilla`` in [this comment](https://github.com/rust-lang/rust/issues/51315#issuecomment-733879934), this PR extends `#[doc(keyword = "...")]` to allow any ident to be used as keyword. The final goal is to allow (proc-)macro crates' owners to write documentation of the keywords they might introduce. r? ``@jyn514``
2020-11-27Remove unused is_doc_keyword functionGuillaume Gomez-5/+0
2020-11-26Rollup merge of #79000 - sivadeilra:user/ardavis/lev_distance, r=wesleywiserJonas Schievink-0/+161
Move lev_distance to rustc_ast, make non-generic rustc_ast currently has a few dependencies on rustc_lexer. Ideally, an AST would not have any dependency its lexer, for minimizing design-time dependencies. Breaking this dependency would also have practical benefits, since modifying rustc_lexer would not trigger a rebuild of rustc_ast. This commit does not remove the rustc_ast --> rustc_lexer dependency, but it does remove one of the sources of this dependency, which is the code that handles fuzzy matching between symbol names for making suggestions in diagnostics. Since that code depends only on Symbol, it is easy to move it to rustc_span. It might even be best to move it to a separate crate, since other tools such as Cargo use the same algorithm, and have simply contain a duplicate of the code. This changes the signature of find_best_match_for_name so that it is no longer generic over its input. I checked the optimized binaries, and this function was duplicated for nearly every call site, because most call sites used short-lived iterator chains, generic over Map and such. But there's no good reason for a function like this to be generic, since all it does is immediately convert the generic input (the Iterator impl) to a concrete Vec<Symbol>. This has all of the costs of generics (duplicated method bodies) with no benefit. Changing find_best_match_for_name to be non-generic removed about 10KB of code from the optimized binary. I know it's a drop in the bucket, but we have to start reducing binary size, and beginning to tame over-use of generics is part of that.
2020-11-24Move lev_distance to rustc_ast, make non-genericArlie Davis-0/+161
rustc_ast currently has a few dependencies on rustc_lexer. Ideally, an AST would not have any dependency its lexer, for minimizing unnecessarily design-time dependencies. Breaking this dependency would also have practical benefits, since modifying rustc_lexer would not trigger a rebuild of rustc_ast. This commit does not remove the rustc_ast --> rustc_lexer dependency, but it does remove one of the sources of this dependency, which is the code that handles fuzzy matching between symbol names for making suggestions in diagnostics. Since that code depends only on Symbol, it is easy to move it to rustc_span. It might even be best to move it to a separate crate, since other tools such as Cargo use the same algorithm, and have simply contain a duplicate of the code. This changes the signature of find_best_match_for_name so that it is no longer generic over its input. I checked the optimized binaries, and this function was duplicated at nearly every call site, because most call sites used short-lived iterator chains, generic over Map and such. But there's no good reason for a function like this to be generic, since all it does is immediately convert the generic input (the Iterator impl) to a concrete Vec<Symbol>. This has all of the costs of generics (duplicated method bodies) with no benefit. Changing find_best_match_for_name to be non-generic removed about 10KB of code from the optimized binary. I know it's a drop in the bucket, but we have to start reducing binary size, and beginning to tame over-use of generics is part of that.
2020-11-23Rename `optin_builtin_traits` to `auto_traits`Camelid-0/+1
They were originally called "opt-in, built-in traits" (OIBITs), but people realized that the name was too confusing and a mouthful, and so they were renamed to just "auto traits". The feature flag's name wasn't updated, though, so that's what this PR does. There are some other spots in the compiler that still refer to OIBITs, but I don't think changing those now is worth it since they are internal and not particularly relevant to this PR. Also see <https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/opt-in.2C.20built-in.20traits.20(auto.20traits).20feature.20name>.
2020-10-19Also apply panic_fmt lint suggestions to debug_assert!().Mara Bos-0/+1
2020-10-18Expand assert!(expr) to panic() function instead of panic!() macro.Mara Bos-0/+1
The panic message might contain braces which should never be interpreted as format placeholders, which panic!() will do in a future edition.
2020-10-18Make panic_fmt lint work properly for assert!(expr, msg) too.Mara Bos-0/+1
2020-10-18Specialize panic_fmt lint for the {core,std}::panic!() macros.Mara Bos-0/+2
It now only reacts to expansion of those macros, and suggests inserting `"{}", ` in the right place.
2020-11-17Auto merge of #78801 - sexxi-goose:min_capture, r=nikomatsakisbors-0/+2
RFC-2229: Implement Precise Capture Analysis ### This PR introduces - Feature gate for RFC-2229 (incomplete) `capture_disjoint_field` - Rustc Attribute to print out the capture analysis `rustc_capture_analysis` - Precise capture analysis ### Description of the analysis 1. If the feature gate is not set then all variables that are not local to the closure will be added to the list of captures. (This is for backcompat) 2. The rest of the analysis is based entirely on how the captured `Place`s are used within the closure. Precise information (i.e. projections) about the `Place` is maintained throughout. 3. To reduce the amount of information we need to keep track of, we do a minimization step. In this step, we determine a list such that no Place within this list represents an ancestor path to another entry in the list. Check rust-lang/project-rfc-2229#9 for more detailed examples. 4. To keep the compiler functional as before we implement a Bridge between the results of this new analysis to existing data structures used for closure captures. Note the new capture analysis results are only part of MaybeTypeckTables that is the information is only available during typeck-ing. ### Known issues - Statements like `let _ = x` will make the compiler ICE when used within a closure with the feature enabled. More generally speaking the issue is caused by `let` statements that create no bindings and are init'ed using a Place expression. ### Testing We removed the code that would handle the case where the feature gate is not set, to enable the feature as default and did a bors try and perf run. More information here: #78762 ### Thanks This has been slowly in the works for a while now. I want to call out `@Azhng` `@ChrisPardy` `@null-sleep` `@jenniferwills` `@logmosier` `@roxelo` for working on this and the previous PRs that led up to this, `@nikomatsakis` for guiding us. Closes rust-lang/project-rfc-2229#7 Closes rust-lang/project-rfc-2229#9 Closes rust-lang/project-rfc-2229#6 Closes rust-lang/project-rfc-2229#19 r? `@nikomatsakis`
2020-11-12Auto merge of #76256 - tgnottingham:issue-74890, r=nikomatsakisbors-5/+26
incr-comp: hash and serialize span end line/column Hash both the length and the end location (line/column) of a span. If we hash only the length, for example, then two otherwise equal spans with different end locations will have the same hash. This can cause a problem during incremental compilation wherein a previous result for a query that depends on the end location of a span will be incorrectly reused when the end location of the span it depends on has changed. A similar analysis applies if some query depends specifically on the length of the span, but we only hash the end location. So hash both. Fix #46744, fix #59954, fix #63161, fix #73640, fix #73967, fix #74890, fix #75900 --- See #74890 for a more in-depth analysis. I haven't thought about what other problems this root cause could be responsible for. Please let me know if anything springs to mind. I believe the issue has existed since the inception of incremental compilation.
2020-11-10Indroduce feature flag for RFC-2229Aman Arora-0/+2
Signed-off-by: Aman Arora <me@aman-arora.com>
2020-11-09Add `#[cfg(panic = "...")]`David Hewitt-0/+1
2020-11-09Rollup merge of #78748 - fanzier:tuple-assignment, r=petrochenkovDylan DPC-0/+1
Implement destructuring assignment for tuples This is the first step towards implementing destructuring assignment (RFC: https://github.com/rust-lang/rfcs/pull/2909, tracking issue: #71126). This PR is the first part of #71156, which was split up to allow for easier review. Quick summary: This change allows destructuring the LHS of an assignment if it's a (possibly nested) tuple. It is implemented via a desugaring (AST -> HIR lowering) as follows: ```rust (a,b) = (1,2) ``` ... becomes ... ```rust { let (lhs0,lhs1) = (1,2); a = lhs0; b = lhs1; } ``` Thanks to `@varkor` who helped with the implementation, particularly around default binding modes. r? `@petrochenkov`
2020-11-07Implement destructuring assignment for tuplesFabian Zaiser-0/+1
Co-authored-by: varkor <github@varkor.com>
2020-11-04fix a couple of clippy warnings:Matthias Krüger-1/+1
filter_next manual_strip redundant_static_lifetimes single_char_pattern unnecessary_cast unused_unit op_ref redundant_closure useless_conversion
2020-11-04incr-comp: hash span end line/columnTyson Nottingham-5/+26
Hash both the length and the end location (line/column) of a span. If we hash only the length, for example, then two otherwise equal spans with different end locations will have the same hash. This can cause a problem during incremental compilation wherein a previous result for a query that depends on the end location of a span will be incorrectly reused when the end location of the span it depends on has changed. A similar analysis applies if some query depends specifically on the length of the span, but we only hash the end location. So hash both. Fix #46744, fix #59954, fix #63161, fix #73640, fix #73967, fix #74890, fix #75900
2020-11-03Auto merge of #78711 - m-ou-se:rollup-pxqnny7, r=m-ou-sebors-1/+8
Rollup of 7 pull requests Successful merges: - #77950 (Add support for SHA256 source file hashing) - #78624 (Sync rustc_codegen_cranelift) - #78626 (Improve errors about #[deprecated] attribute) - #78659 (Corrected suggestion for generic parameters in `function_item_references` lint) - #78687 (Suggest library/std when running all stage 0 tests) - #78699 (Show more error information in lldb_batchmode) - #78709 (Fix panic in bootstrap for non-workspace path dependencies.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2020-11-03Rollup merge of #77950 - arlosi:sha256, r=eddybMara Bos-1/+8
Add support for SHA256 source file hashing Adds support for `-Z src-hash-algorithm sha256`, which became available in LLVM 11. Using an older version of LLVM will cause an error `invalid checksum kind` if the hash algorithm is set to sha256. r? `@eddyb` cc #70401 `@est31`
2020-11-03Auto merge of #76931 - oli-obk:const_prop_inline_lint_madness, r=wesleywiserbors-0/+3
Properly handle lint spans after MIR inlining The first commit shows what happens when we apply mir inlining and then cause lints on the inlined MIR. The second commit fixes that. r? `@wesleywiser`
2020-10-30Rollup merge of #78524 - tmiasko:source-files-borrow, r=Aaron1011Yuki Okushi-4/+4
Avoid BorrowMutError with RUSTC_LOG=debug ```console $ touch empty.rs $ env RUSTC_LOG=debug rustc +stage1 --crate-type=lib empty.rs ``` Fails with a `BorrowMutError` because source map files are already borrowed while `features_query` attempts to format a log message containing a span. Release the borrow before the query to avoid the issue.
2020-10-29Rollup merge of #78423 - tgnottingham:caching_source_map_bounds_check, r=oli-obkJonas Schievink-17/+46
rustc_span: improve bounds checks in byte_pos_to_line_and_col The effect of this change is to consider edge-case spans that start or end at the position one past the end of a file to be valid during span hashing and encoding. This change means that these spans will be preserved across incremental compilation sessions when they are part of a serialized query result, instead of causing the dummy span to be used.
2020-10-29Use RwLock instead of Lock for SourceMap::filesTomasz Miąsko-4/+4
2020-10-28Auto merge of #78415 - tgnottingham:expn_id_tag_hash, r=Aaron1011bors-2/+1
rustc_span: avoid hashing ExpnId tag when using cached hash
2020-10-28Auto merge of #78458 - Dylan-DPC:rollup-tan044s, r=Dylan-DPCbors-2/+3
Rollup of 10 pull requests Successful merges: - #78152 (Separate unsized locals) - #78297 (Suggest calling await on method call and field access) - #78351 (Move "mutable thing in const" check from interning to validity) - #78365 (check object safety of generic constants) - #78379 (Tweak invalid `fn` header and body parsing) - #78391 (Add const_fn in generics test) - #78401 (resolve: private fields in tuple struct ctor diag) - #78408 (Remove tokens from foreign items in `TokenStripper`) - #78447 (Fix typo in comment) - #78453 (Fix typo in comments) Failed merges: r? `@ghost`
2020-10-28Rollup merge of #78447 - bugadani:typo, r=matthewjasperDylan DPC-2/+2
Fix typo in comment I hope I got all the typos in that word. :)
2020-10-28Rollup merge of #78152 - spastorino:separate-unsized-locals, r=oli-obkDylan DPC-0/+1
Separate unsized locals Closes #71694 Takes over again #72029 and #74971 cc @RalfJung @oli-obk @pnkfelix @eddyb as they've participated in previous reviews of this PR.
2020-10-27Auto merge of #75671 - nathanwhit:cstring-temp-lint, r=oli-obkbors-0/+7
Uplift `temporary-cstring-as-ptr` lint from `clippy` into rustc The general consensus seems to be that this lint covers a common enough mistake to warrant inclusion in rustc. The diagnostic message might need some tweaking, as I'm not sure the use of second-person perspective matches the rest of rustc, but I'd like to hear others' thoughts on that. (cc #53224). r? `@oli-obk`
2020-10-27rustc_span: represent line bounds with RangeTyson Nottingham-30/+24
2020-10-27Add unsized_fn_params featureSantiago Pastorino-0/+1
2020-10-27Fix typo in commentDániel Buga-2/+2
2020-10-27Changed lint to check for `std::fmt::Pointer` and `transmute`Ayrton-0/+2
The lint checks arguments in calls to `transmute` or functions that have `Pointer` as a trait bound and displays a warning if the argument is a function reference. Also checks for `std::fmt::Pointer::fmt` to handle formatting macros although it doesn't depend on the exact expansion of the macro or formatting internals. `std::fmt::Pointer` and `std::fmt::Pointer::fmt` were also added as diagnostic items and symbols.
2020-10-27Show the inline stack of MIR lints that only occur after inliningOliver Scherer-0/+3
2020-10-27Rollup merge of #78396 - josephlr:ermsb, r=petrochenkovYuki Okushi-0/+1
Add compiler support for LLVM's x86_64 ERMSB feature This change is needed for compiler-builtins to check for this feature when implementing memcpy/memset. See: https://github.com/rust-lang/compiler-builtins/pull/365 Without this change, the following code compiles, but does nothing: ```rust #[cfg(target_feature = "ermsb")] pub unsafe fn ermsb_memcpy() { ... } ``` The change just does compile-time detection. I think that runtime detection will have to come in a follow-up CL to std-detect. Like all the CPU feature flags, this just references #44839 Signed-off-by: Joe Richey <joerichey@google.com>
2020-10-26rustc_span: improve bounds checks in byte_pos_to_line_and_colTyson Nottingham-4/+39
The effect of this change is to consider edge-case spans that start or end at the position one past the end of a file to be valid during span hashing and encoding. This change means that these spans will be preserved across incremental compilation sessions when they are part of a serialized query result, instead of causing the dummy span to be used.
2020-10-26Address review commentsNathan Whitaker-0/+1