Commit graph

361 commits

Author SHA1 Message Date
Matthias Krüger
9e720a8aae
Rollup merge of #91926 - SylvanB:remove_in_band_lifetimes_from_rustc_metadata, r=nagisa
Remove `in_band_lifetimes` from `rustc_metadata`

Another for #91867
2021-12-18 14:49:39 +01:00
Matthias Krüger
a97384d94c
Rollup merge of #92001 - fee1-dead:dmbic-xcrate-fix, r=oli-obk
Fix default_method_body_is_const when used across crates

r? `@oli-obk`

unblocks #91439.
2021-12-16 17:23:13 +01:00
Deadbeef
4bb65e1c79
Fix default_method_body_is_const when used across crates 2021-12-16 21:38:54 +08:00
Sylvan Bowdler
8679e17723 Remove in_band_lifetimes from rustc_metadata 2021-12-14 17:35:27 +00:00
lcnr
dcd716fee2 extend simplify_type 2021-12-14 13:32:42 +01:00
bors
6bda5b331c Auto merge of #90716 - euclio:libloading, r=cjgillot
replace dynamic library module with libloading

This PR deletes the `rustc_metadata::dynamic_lib` module in favor of the popular and better tested [`libloading` crate](https://github.com/nagisa/rust_libloading/).

We don't benefit from `libloading`'s symbol lifetimes since we end up leaking the loaded library in all cases, but the call-sites look much nicer by improving error handling and abstracting away some transmutes. We also can remove `rustc_metadata`'s direct dependencies on `libc` and `winapi`.

This PR also adds an exception for `libloading` (and its license) to tidy, so this will need sign-off from the compiler team.
2021-12-12 17:28:52 +00:00
bors
82575a1d6f Auto merge of #91715 - the8472:bump-rmeta-fromat-version, r=Mark-Simulacrum
Bump rmeta version to fix rustc_serialize ICE

#91407 changed the serialization format which leads to ICEs for nightly users such as #91663 and linked issues. The issue can be solved by running `cargo clean`. But bumping the metadata version should lead to the cached files being discarded, avoiding the issue entirely.
2021-12-11 01:00:14 +00:00
The 8472
0696e79f27 Bump rmeta version to fix rustc_serialize ICE
#91407 changed the serialization format which leads to ICEs for nightly users such as #91663 and linked issue.
Bumping the metadata version should lead to the cached files being discarded instead.
2021-12-09 18:00:36 +01:00
est31
15de4cbc4b Remove redundant [..]s 2021-12-09 00:01:29 +01:00
Andy Russell
923f939791
replace dynamic library module with libloading 2021-12-06 12:03:47 -05:00
Michael
2ca9333011 Improve suggestion for extern crate self error message 2021-12-01 21:59:54 +00:00
Michael
62f4ce993e Stop treating extern crate loading failures as fatal errors 2021-12-01 21:04:13 +00:00
bors
90912e68ab Auto merge of #91330 - cjgillot:no-ee-features, r=Aaron1011
Remove eval_always for lib_features.

r? `@Aaron1011`
2021-11-30 07:40:08 +00:00
Camille GILLOT
877b2d79d9 Remove eval_always for lib_features. 2021-11-28 21:13:36 +01:00
Camille GILLOT
5fb4648757 Take a LocalDefId in expect_*item. 2021-11-28 21:09:45 +01:00
inquisitivecrystal
9a987b0466 Add ty::Visibility::is_public() 2021-11-09 18:35:00 -08:00
Matthias Krüger
fd5a4f42ad
Rollup merge of #90701 - michaelwoerister:more-artifact-sizes, r=davidtwco
Record more artifact sizes during self-profiling.

This PR adds artifact size recording for

- "linked artifacts" (executables, RLIBs, dylibs, static libs)
- object files
- dwo files
- assembly files
- crate metadata
- LLVM bitcode files
- LLVM IR files
- codegen unit size estimates

Currently the identifiers emitted for these are hard-coded as string literals. Is it worth adding constants to https://github.com/rust-lang/measureme/blob/master/measureme/src/rustc.rs instead? We don't do that for query names and the like -- but artifact kinds might be more stable than query names.
2021-11-09 19:00:45 +01:00
Matthias Krüger
fd74c93403
Rollup merge of #89561 - nbdd0121:const_typeck, r=nikomatsakis
Type inference for inline consts

Fixes #78132
Fixes #78174
Fixes #81857
Fixes #89964

Perform type checking/inference of inline consts in the same context as the outer def, similar to what is currently done to closure.

Doing so would require `closure_base_def_id` of the inline const to return the outer def, and since `closure_base_def_id` can be called on non-local crate (and thus have no HIR available), a new `DefKind` is created for inline consts.

The type of the generated anon const can capture lifetime of outer def, so we couldn't just use the typeck result as the type of the inline const's def. Closure has a similar issue, and it uses extra type params `CK, CS, U` to capture closure kind, input/output signature and upvars. I use a similar approach for inline consts, letting it have an extra type param `R`, and then `typeof(InlineConst<[paremt generics], R>)` would just be `R`. In borrowck region requirements are also propagated to the outer MIR body just like it's currently done for closure.

With this PR, inline consts in expression position are quitely usable now; however the usage in pattern position is still incomplete -- since those does not remain in the MIR borrowck couldn't verify the lifetime there. I have left an ignored test as a FIXME.

Some disucssions can be found on [this Zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/260443-project-const-generics/topic/inline.20consts.20typeck).
cc `````@spastorino````` `````@lcnr`````
r? `````@nikomatsakis`````

`````@rustbot````` label A-inference F-inline_const T-compiler
2021-11-09 19:00:40 +01:00
Michael Woerister
fefe1e9192 Record more artifact sizes during self-profiling. 2021-11-08 17:02:40 +01:00
bors
5fa94f3c57 Auto merge of #88368 - jyn514:metadata-error, r=petrochenkov
Improve error when an .rlib can't be parsed

This usually describes either an error in the compiler itself or some
sort of IO error. Either way, we should report it to the user rather
than just saying "crate not found".

This only gives an error if the crate couldn't be loaded at all - if the
compiler finds another .rlib or .rmeta file which was valid, it will
continue to compile the crate.

Example output:
```
error[E0785]: found invalid metadata files for crate `foo`
 --> bar.rs:3:24
  |
3 |         println!("{}", foo::FOO_11_49[0]);
  |                        ^^^
  |
  = warning: failed to parse rlib '/home/joshua/test-rustdoc/libfoo.rlib': Invalid archive extended name offset
```

cc `@ehuss`
2021-11-07 23:03:55 +00:00
bors
46b8e7488e Auto merge of #90668 - matthiaskrgr:clippy_nov7, r=jyn514
more clippy fixes
2021-11-07 20:04:54 +00:00
Matthias Krüger
5c454551da more clippy fixes 2021-11-07 16:59:05 +01:00
Joshua Nelson
257ac1b498 Improve error when an .rlib can't be parsed
This usually describes either an error in the compiler itself or some
sort of IO error. Either way, we should report it to the user rather
than just saying "crate not found".

This only gives an error if the crate couldn't be loaded at all - if the
compiler finds another .rlib or .rmeta file which was valid, it will
continue to compile the crate.

Example output:
```
error[E0785]: found invalid metadata files for crate `foo`
 --> bar.rs:3:24
  |
3 |         println!("{}", foo::FOO_11_49[0]);
  |                        ^^^
  |
  = warning: failed to parse rlib '/home/joshua/test-rustdoc/libfoo.rlib': Invalid archive extended name offset
```
2021-11-07 15:03:40 +00:00
Vadim Petrochenkov
2834f57c45 ast: Fix naming conventions in AST structures
TraitKind -> Trait
TyAliasKind -> TyAlias
ImplKind -> Impl
FnKind -> Fn

All `*Kind`s in AST are supposed to be enums.

Tuple structs are converted to braced structs for the types above, and fields are reordered in syntactic order.

Also, mutable AST visitor now correctly visit spans in defaultness, unsafety, impl polarity and constness.
2021-11-07 21:38:17 +08:00
Gary Guo
02c1774cd3 Give inline const separate DefKind 2021-11-07 03:59:06 +00:00
Eric Huss
9057936a9a Demote metadata load warning to "info". 2021-11-03 13:39:37 -07:00
Guillaume Gomez
1a1f525bb0
Rollup merge of #90202 - matthewjasper:xcrate-hygiene, r=petrochenkov
Improve and test cross-crate hygiene

- Decode the parent expansion for traits and enums in `rustc_resolve`, this was already being used for resolution in typeck
- Avoid suggesting importing names with def-site hygiene, since it's often not useful
- Add more tests

r? `@petrochenkov`
2021-10-30 20:30:27 +02:00
Michael Woerister
6771ac3f19 Update odht crate to 0.3.1 (big-endian bugfix) 2021-10-29 18:05:15 +02:00
Matthew Jasper
d8426ea636 Remove ModData from rustc_metadata
This avoids having to decode 2 `Lazy`s when decoding a modules exports.
2021-10-28 21:48:21 +01:00
Mark Rousskov
3215eeb99f
Revert "Add rustc lint, warning when iterating over hashmaps" 2021-10-28 11:01:42 -04:00
bjorn3
f5c3e83013 Avoid a branch on key being local for queries that use the same local and extern providers 2021-10-25 13:36:23 +02:00
Matthias Krüger
87822b27ee
Rollup merge of #89558 - lcnr:query-stable-lint, r=estebank
Add rustc lint, warning when iterating over hashmaps

r? rust-lang/wg-incr-comp
2021-10-24 15:48:42 +02:00
Matthew Jasper
4ecb49eba3 Handle cross-crate module ExpnIds consistently
- Always use the ExpnId serialized to `tables`
- Use the Id for traits and enums from other crates in resolution.
2021-10-21 22:07:03 +01:00
Eric Huss
6f915056a1 Don't emit a warning for empty rmeta files. 2021-10-19 16:56:47 -07:00
bors
1af55d19c7 Auto merge of #89933 - est31:let_else, r=michaelwoerister
Adopt let_else across the compiler

This performs a substitution of code following the pattern:

```
let <id> = if let <pat> = ... { identity } else { ... : ! };
```

To simplify it to:

```
let <pat> = ... { identity } else { ... : ! };
```

By adopting the `let_else` feature (cc #87335).

The PR also updates the syn crate because the currently used version of the crate doesn't support `let_else` syntax yet.

Note: Generally I'm the person who *removes* usages of unstable features from the compiler, not adds more usages of them, but in this instance I think it hopefully helps the feature get stabilized sooner and in a better state. I have written a [comment](https://github.com/rust-lang/rust/issues/87335#issuecomment-944846205) on the tracking issue about my experience and what I feel could be improved before stabilization of `let_else`.
2021-10-19 14:41:39 +00:00
bors
6f53ddfa74 Auto merge of #89514 - davidtwco:polymorphize-shims-and-predicates, r=lcnr
polymorphization: shims and predicates

Supersedes #75737 and #75414. This pull request includes up some changes to polymorphization which hadn't landed previously and gets stage2 bootstrapping and the test suite passing when polymorphization is enabled. There are still issues with `type_id` and polymorphization to investigate but this should get polymorphization in a reasonable state to work on.

- #75737 and #75414 both worked but were blocked on having the rest of the test suite pass (with polymorphization enabled) with and without the PRs. It makes more sense to just land these so that the changes are in.
- #75737's changes remove the restriction of `InstanceDef::Item` on polymorphization, so that shims can now be polymorphized. This won't have much of an effect until polymorphization's analysis is more advanced, but it doesn't hurt.
- #75414's changes remove all logic which marks parameters as used based on their presence in predicates - given #75675, this will enable more polymorphization and avoid the symbol clashes that predicate logic previously sidestepped.
- Polymorphization now explicitly checks (and skips) foreign items, this is necessary for stage2 bootstrapping to work when polymorphization is enabled.
- The conditional determining the emission of a note adding context to a post-monomorphization error has been modified. Polymorphization results in `optimized_mir` running for shims during collection where that wouldn't happen previously, some errors are emitted during `optimized_mir` and these were considered post-monomorphization errors with the existing logic (more errors and shims have a `DefId` coming from the std crate, not the local crate), adding a note that resulted in tests failing. It isn't particularly feasible to change where polymorphization runs or prevent it from using `optimized_mir`, so it seemed more reasonable to not change the conditional.
- `characteristic_def_id_of_type` was being invoked during partitioning for self types of impl blocks which had projections that depended on the value of unused generic parameters of a function - this caused a ICE in a debuginfo test. If partitioning is enabled and the instance needs substitution then this is skipped. That test still fails for me locally, but not with an ICE, but it fails in a fresh checkout too, so 🤷‍♂️.

r? `@lcnr`
2021-10-17 12:33:12 +00:00
est31
1418df5888 Adopt let_else across the compiler
This performs a substitution of code following the pattern:

let <id> = if let <pat> = ... { identity } else { ... : ! };

To simplify it to:

let <pat> = ... { identity } else { ... : ! };

By adopting the let_else feature.
2021-10-16 07:18:05 +02:00
lcnr
00e5abe9b6 allow potential_query_instability everywhere 2021-10-15 10:58:18 +02:00
Noah Lev
2e56b6f98e Include rmeta candidates in "multiple matching crates" error
Only dylib and rlib candidates were included in the error. I think the
reason is that at the time this error was originally implemented, rmeta
crate sources were represented different from dylib and rlib sources.
I wrote up more detailed analysis in [this comment][1].

The new version of the code is also a bit easier to read and should be
more robust to future changes since it uses `CrateSources::paths()`.

[1]: https://github.com/rust-lang/rust/pull/88675#issuecomment-935282436
2021-10-12 13:10:11 -07:00
Noah Lev
6792c6a851 Sort candidate libraries by source path in error
This makes the error output deterministic and thus testable.
2021-10-12 13:08:32 -07:00
Guillaume Gomez
836597a881
Rollup merge of #89649 - matthiaskrgr:clippycompl, r=jyn514
clippy::complexity fixes
2021-10-08 22:30:40 +02:00
Matthias Krüger
e6f77a1787 clippy::complexity fixes 2021-10-08 20:07:44 +02:00
Jubilee
aed1801841
Rollup merge of #89476 - cjgillot:expn-id, r=petrochenkov
Correct decoding of foreign expansions during incr. comp.

Fixes https://github.com/rust-lang/rust/issues/74946

The original issue was due to a wrong assertion in `expn_hash_to_expn_id`.

The secondary issue was due to a mismatch between the encoding and decoding paths for expansions that are created after the TyCtxt is created.
2021-10-07 20:26:14 -07:00
Jubilee
6c17601a2e
Rollup merge of #89025 - ricobbe:raw-dylib-link-ordinal, r=michaelwoerister
Implement `#[link_ordinal(n)]`

Allows the use of `#[link_ordinal(n)]` with `#[link(kind = "raw-dylib")]`, allowing Rust to link against DLLs that export symbols by ordinal rather than by name.  As long as the ordinal matches, the name of the function in Rust is not required to match the name of the corresponding function in the exporting DLL.

Part of #58713.
2021-10-07 20:26:11 -07:00
Camille GILLOT
4028b093e4 Do not ICE if some foreign expansions were not encoded.
The metadata encoder does not necessarily encode all expansions, only
those which are referenced in other metadata fields.
2021-10-06 19:10:08 +02:00
Camille GILLOT
ce21756ed3 Access Session while decoding expn_id. 2021-10-06 19:06:20 +02:00
Cameron Steffen
33b9b95305 Introduce get_diagnostic_name 2021-10-06 08:40:28 -05:00
Manish Goregaokar
5f8b1614d1
Rollup merge of #89546 - joshtriplett:grow-metadata-faster, r=petrochenkov
Make an initial guess for metadata size to reduce buffer resizes

When reading metadata, the compiler starts with a `Vec::new()`, which will need to grow repeatedly as the metadata gets decompressed into it. Reduce the number of resizes by starting out at the size of the compressed data.
2021-10-05 12:52:49 -07:00
bors
55111d656f Auto merge of #89266 - cjgillot:session-ich, r=michaelwoerister
Move ICH to rustc_query_system

Based on https://github.com/rust-lang/rust/pull/89183

The StableHashingContext does not need to be in rustc_middle.

This PR moves it to rustc_query_system. This will avoid a dependency between rustc_ast_lowering and rustc_middle in https://github.com/rust-lang/rust/pull/89124.
2021-10-05 09:45:11 +00:00
Josh Triplett
c35a700be2 Make an initial guess for metadata size to reduce buffer resizes 2021-10-04 19:23:13 -07:00