Commit Graph

568 Commits

Author SHA1 Message Date
Matthias Krüger aa55752df2 Rollup merge of #111875 - WaffleLapkin:defer_on_drop, r=Nilstrieb
Don't leak the function that is called on drop

It probably wasn't causing problems anyway, but still, a `// this leaks, please don't pass anything that owns memory` is not sustainable.

I could implement a version which does not require `Option`, but it would require `unsafe`, at which point it's probably not worth it.
2023-05-25 08:01:08 +02:00
Manish Goregaokar 7590e4f21d Rollup merge of #111912 - WaffleLapkin:is_some_and_in_the_compiler, r=petrochenkov
Use `Option::is_some_and` and `Result::is_ok_and` in the compiler

`.is_some_and(..)`/`.is_ok_and(..)` replace `.map_or(false, ..)` and `.map(..).unwrap_or(false)`, making the code more readable.

This PR is a sibling of https://github.com/rust-lang/rust/pull/111873#issuecomment-1561316515
2023-05-24 15:05:05 -07:00
bors ee9b78acc2 Auto merge of #111673 - cjgillot:dominator-preprocess, r=cjgillot,tmiasko
Preprocess and cache dominator tree

Preprocessing dominators has a very strong effect for https://github.com/rust-lang/rust/pull/111344.
That pass checks that assignments dominate their uses repeatedly. Using the unprocessed dominator tree caused a quadratic runtime (number of bbs x depth of the dominator tree).

This PR also caches the dominator tree and the pre-processed dominators in the MIR cfg cache.

Rebase of https://github.com/rust-lang/rust/pull/107157
cc `@tmiasko`
2023-05-24 16:18:21 +00:00
Maybe Waffle cb2d555147 Use Option::is_some_and and Result::is_ok_and in the compiler 2023-05-24 14:20:41 +00:00
Maybe Waffle 93942c5f65 Don't leak the function that is called on drop 2023-05-23 14:53:36 +00:00
bors 4a5a2e2ab5 Auto merge of #111596 - cjgillot:dominator-bucket, r=Mark-Simulacrum
Process current bucket instead of parent's bucket when starting loop for dominators.

The linked paper by Georgiadis suggests in §2.2.3 to process `bucket[w]` when beginning the loop, instead of `bucket[parent[w]]` when finishing it.

In the test case, we correctly computed `idom[2] = 0` and `sdom[3] = 1`, but the algorithm returned `idom[3] = 1`, instead of the correct value 0, because of the path 0-7-2-3.

This provoked LLVM ICE in https://github.com/rust-lang/rust/pull/111061#issuecomment-1546912112. LLVM checks that SSA assignments dominate uses using its own implementation of Lengauer-Tarjan, and saw case where rustc was breaking the dominance property.

r? `@Mark-Simulacrum`
2023-05-20 07:41:15 +00:00
Camille GILLOT b714284e51 Revert spurious changes. 2023-05-18 14:36:13 +00:00
Dylan DPC 9ede663928 Rollup merge of #111707 - nnethercote:rm-WorkerLocal-Vec, r=compiler-errors
Remove unused `impl<T> WorkerLocal<Vec<T>>`.

cc ``@SparrowLii`` ``@Zoxc``
2023-05-18 17:37:10 +05:30
Nicholas Nethercote 60852ad416 Remove unused impl<T> WorkerLocal<Vec<T>>. 2023-05-18 13:14:45 +10:00
Camille GILLOT ae391bdbae Merge DominatorTree and Dominators. 2023-05-17 10:37:29 +00:00
Camille GILLOT e3b315218a Typo. 2023-05-17 10:29:12 +00:00
Camille GILLOT 99644fa0ad Remove outdated comment. 2023-05-17 10:26:04 +00:00
Tomasz Miąsko 2c634e4595 Preprocess dominator tree to answer queries in O(1) 2023-05-17 09:36:12 +00:00
Dylan DPC bd657951f9 Rollup merge of #110145 - WaffleLapkin:share_slice_of_bytes, r=Nilstrieb
Share slice of bytes

r? `@Nilstrieb`
cc `@noamtashma`
2023-05-17 11:13:55 +05:30
Maybe Waffle a1de2e343d Fixup comments 2023-05-16 12:09:24 +00:00
Maybe Waffle 80b6d4a8b2 Remove MetadataRef type alias 2023-05-16 11:55:47 +00:00
Maybe Waffle 044228637f Switch OwnedSlice to use Lrc & remove Lrc from MetadataBlob 2023-05-16 11:43:27 +00:00
Maybe Waffle 7430825d1a Merge MetadataRef type aliases 2023-05-16 11:43:25 +00:00
Camille GILLOT da43a402a2 Process current bucket instead of parent's bucket when starting loop for dominators. 2023-05-15 16:16:34 +00:00
Tomasz Miąsko 1c6fb1dddb Start node has no immediate dominator
Change the immediate_dominator return type to Option, and use None to
indicate that node has no immediate dominator.

Also fix the issue where the start node would be returned as its own
immediate dominator.
2023-05-14 16:09:58 +02:00
bors e76b131541 Auto merge of #107586 - SparrowLii:parallel-query, r=cjgillot
Introduce `DynSend` and `DynSync` auto trait for parallel compiler

part of parallel-rustc #101566

This PR introduces `DynSend / DynSync` trait and `FromDyn / IntoDyn` structure in rustc_data_structure::marker. `FromDyn` can dynamically check data structures for thread safety when switching to parallel environments (such as calling `par_for_each_in`). This happens only when `-Z threads > 1` so it doesn't affect single-threaded mode's compile efficiency.

r? `@cjgillot`
2023-05-13 13:47:53 +00:00
Matthias Krüger a908cb48de Rollup merge of #111393 - klensy:win-0.48, r=oli-obk
bump windows crate 0.46 -> 0.48

This drops duped version of crate(0.46), reduces `rustc_driver.dll` ~800kb and reduces exported functions number from 26k to 22k.

Also while here, added `tidy-alphabetical` sorting to lists in tidy allowed lists.
2023-05-12 07:11:12 +02:00
klensy 4a99c6a6e7 bump windows crate 0.46 -> 0.48 in workspace 2023-05-09 18:20:13 +03:00
Dylan DPC 85841b9abe Rollup merge of #111252 - matthewjasper:min-spec-improvements, r=compiler-errors
Min specialization improvements

- Don't allow specialization impls with no items, such implementations are probably not correct and only occur as mistakes in the compiler and standard library
- Fix a missing normalization call
- Adds spans for lifetime errors from overly general specializations

Closes #79457
Closes #109815
2023-05-09 12:33:46 +05:30
Nilstrieb f0be07a6c9 Use smaller ints for bitflags 2023-05-07 18:24:46 +02:00
SparrowLii 6fecfca352 add DynSend / DynSync for CopyTaggedPtr 2023-05-06 10:23:51 +08:00
SparrowLii 6d94d3a1f1 correct import of owned_slice 2023-05-06 09:34:55 +08:00
SparrowLii 82157f073d correct literals for dyn thread safe 2023-05-06 09:34:53 +08:00
SparrowLii 79e29c5e37 rename relative names in sync 2023-05-06 09:34:24 +08:00
SparrowLii c522bb181d fix parallel! 2023-05-06 09:34:22 +08:00
SparrowLii df51076631 fix some nits 2023-05-06 09:34:21 +08:00
SparrowLii ed1f8daeef introduce DynSend and DynSync auto trait 2023-05-06 09:34:18 +08:00
Matthew Jasper d46428d100 Disallow (min) specialization imps with no items
Such implementations are usually mistakes and are not used in the
compiler or standard library (after this commit) so forbid them with
`min_specialization`.
2023-05-05 16:19:18 +01:00
Ben Kimock 5bf36c09ff Use the full Fingerprint when stringifying Svh 2023-04-30 14:28:30 -04:00
bors d2ac06eb19 Auto merge of #107782 - Zoxc:worker-local, r=cjgillot
Move the WorkerLocal type from the rustc-rayon fork into rustc_data_structures

This PR moves the definition of the `WorkerLocal` type from `rustc-rayon` into `rustc_data_structures`. This is enabled by the introduction of the `Registry` type which allows you to group up threads to be used by `WorkerLocal` which is basically just an array with an per thread index. The `Registry` type mirrors the one in Rayon and each Rayon worker thread is also registered with the new `Registry`. Safety for `WorkerLocal` is ensured by having it keep a reference to the registry and checking on each access that we're still on the group of threads associated with the registry used to construct it.

Accessing a `WorkerLocal` is micro-optimized due to it being hot since it's used for most arena allocations.

Performance is slightly improved for the parallel compiler:
<table><tr><td rowspan="2">Benchmark</td><td colspan="1"><b>Before</b></th><td colspan="2"><b>After</b></th></tr><tr><td align="right">Time</td><td align="right">Time</td><td align="right">%</th></tr><tr><td>🟣 <b>clap</b>:check</td><td align="right">1.9992s</td><td align="right">1.9949s</td><td align="right"> -0.21%</td></tr><tr><td>🟣 <b>hyper</b>:check</td><td align="right">0.2977s</td><td align="right">0.2970s</td><td align="right"> -0.22%</td></tr><tr><td>🟣 <b>regex</b>:check</td><td align="right">1.1335s</td><td align="right">1.1315s</td><td align="right"> -0.18%</td></tr><tr><td>🟣 <b>syn</b>:check</td><td align="right">1.8235s</td><td align="right">1.8171s</td><td align="right"> -0.35%</td></tr><tr><td>🟣 <b>syntex_syntax</b>:check</td><td align="right">6.9047s</td><td align="right">6.8930s</td><td align="right"> -0.17%</td></tr><tr><td>Total</td><td align="right">12.1586s</td><td align="right">12.1336s</td><td align="right"> -0.21%</td></tr><tr><td>Summary</td><td align="right">1.0000s</td><td align="right">0.9977s</td><td align="right"> -0.23%</td></tr></table>

cc `@SparrowLii`
2023-04-27 17:43:09 +00:00
Matthias Krüger 59b033a517 Rollup merge of #110814 - WaffleLapkin:sprinkle_#inline, r=Nilstrieb
Sprinkle some `#[inline]` in `rustc_data_structures::tagged_ptr`

This is based on `nm --demangle (rustc +a --print sysroot)/lib/librustc_driver-*.so | rg CopyTaggedPtr` which shows many methods that should probably be inlined. May fix the regression in https://github.com/rust-lang/rust/pull/110795.

r? ```@Nilstrieb```
2023-04-27 15:10:53 +02:00
Matthias Krüger ccda5b5759 Rollup merge of #110615 - WaffleLapkin:impl_tag, r=cjgillot
Add `impl_tag!` macro to implement `Tag` for tagged pointer easily

r? `@Nilstrieb`

This should also lifts the need to think about safety from the callers (`impl_tag!` is robust (ish, see the macro issue)) and removes the possibility of making a "weird" `Tag` impl.
2023-04-25 21:06:33 +02:00
Maybe Waffle fefae0ea3a Add #[inline] in impl_tag 2023-04-25 17:37:12 +00:00
Maybe Waffle fe65959d81 Sprinkle some #[inline] in rustc_data_structures::tagged_ptr 2023-04-25 17:30:05 +00:00
Maybe Waffle 49376cdd32 Switch impl_tag! from explicit tags to ${index()} 2023-04-24 16:48:37 +00:00
Maybe Waffle 309d3b09f5 Split {Idx, IndexVec, IndexSlice} into their own modules 2023-04-24 13:53:35 +00:00
Maybe Waffle 5a049819e0 Simplify bits_for_tags impl 2023-04-20 19:54:10 +00:00
Maybe Waffle 55fa98df14 Remove confusing comment 2023-04-20 19:07:57 +00:00
Maybe Waffle 5badc16585 Use impl Tag for $T syntax for impl_tag! 2023-04-20 18:49:40 +00:00
Maybe Waffle 76a614034f Add impl_tag! macro to implement Tag for tagged pointer easily 2023-04-20 17:14:32 +00:00
Maybe Waffle 80141c5242 deny(unsafe_op_in_unsafe_fn) in rustc_data_structures 2023-04-19 18:00:48 +00:00
bors 4b3d0993b7 Auto merge of #110083 - saethlin:encode-hashes-as-bytes, r=cjgillot
Encode hashes as bytes, not varint

In a few places, we store hashes as `u64` or `u128` and then apply `derive(Decodable, Encodable)` to the enclosing struct/enum. It is more efficient to encode hashes directly than try to apply some varint encoding. This PR adds two new types `Hash64` and `Hash128` which are produced by `StableHasher` and replace every use of storing a `u64` or `u128` that represents a hash.

Distribution of the byte lengths of leb128 encodings, from `x build --stage 2` with `incremental = true`

Before:
```
(  1) 373418203 (53.7%, 53.7%): 1
(  2) 196240113 (28.2%, 81.9%): 3
(  3) 108157958 (15.6%, 97.5%): 2
(  4)  17213120 ( 2.5%, 99.9%): 4
(  5)    223614 ( 0.0%,100.0%): 9
(  6)    216262 ( 0.0%,100.0%): 10
(  7)     15447 ( 0.0%,100.0%): 5
(  8)      3633 ( 0.0%,100.0%): 19
(  9)      3030 ( 0.0%,100.0%): 8
( 10)      1167 ( 0.0%,100.0%): 18
( 11)      1032 ( 0.0%,100.0%): 7
( 12)      1003 ( 0.0%,100.0%): 6
( 13)        10 ( 0.0%,100.0%): 16
( 14)        10 ( 0.0%,100.0%): 17
( 15)         5 ( 0.0%,100.0%): 12
( 16)         4 ( 0.0%,100.0%): 14
```

After:
```
(  1) 372939136 (53.7%, 53.7%): 1
(  2) 196240140 (28.3%, 82.0%): 3
(  3) 108014969 (15.6%, 97.5%): 2
(  4)  17192375 ( 2.5%,100.0%): 4
(  5)       435 ( 0.0%,100.0%): 5
(  6)        83 ( 0.0%,100.0%): 18
(  7)        79 ( 0.0%,100.0%): 10
(  8)        50 ( 0.0%,100.0%): 9
(  9)         6 ( 0.0%,100.0%): 19
```

The remaining 9 or 10 and 18 or 19 are `u64` and `u128` respectively that have the high bits set. As far as I can tell these are coming primarily from `SwitchTargets`.
2023-04-18 22:27:15 +00:00
Ben Kimock 826c60b946 Add #[inline] to some new functions
Co-authored-by: Camille Gillot <gillot.camille@gmail.com>
2023-04-18 14:13:19 -04:00
Ben Kimock 0cf369ccab Document how the HashN types are different from Fingerprint 2023-04-18 10:52:47 -04:00
Ben Kimock 8548454ea4 Store hashes in special types so they aren't accidentally encoded as numbers 2023-04-18 10:52:47 -04:00