Skip to content

Commit 7f520da

Browse files
authored
Rollup merge of rust-lang#65105 - Mark-Simulacrum:split-librustc, r=nikomatsakis
Split out some passes from librustc This is just moving them out to librustc_passes -- I've not measured compile time or run time. I don't expect any significant impact, but this seems prudent regardless.
2 parents cfd51ca + 7c3f65b commit 7f520da

File tree

11 files changed

+239
-229
lines changed

11 files changed

+239
-229
lines changed

Cargo.lock

+2
Original file line numberDiff line numberDiff line change
@@ -3613,6 +3613,8 @@ dependencies = [
36133613
"rustc",
36143614
"rustc_data_structures",
36153615
"rustc_errors",
3616+
"rustc_index",
3617+
"rustc_target",
36163618
"syntax",
36173619
"syntax_pos",
36183620
]

src/librustc/error_codes.rs

-180
Original file line numberDiff line numberDiff line change
@@ -466,66 +466,6 @@ fn main() {
466466
```
467467
"##,
468468

469-
// This shouldn't really ever trigger since the repeated value error comes first
470-
E0136: r##"
471-
A binary can only have one entry point, and by default that entry point is the
472-
function `main()`. If there are multiple such functions, please rename one.
473-
"##,
474-
475-
E0137: r##"
476-
More than one function was declared with the `#[main]` attribute.
477-
478-
Erroneous code example:
479-
480-
```compile_fail,E0137
481-
#![feature(main)]
482-
483-
#[main]
484-
fn foo() {}
485-
486-
#[main]
487-
fn f() {} // error: multiple functions with a `#[main]` attribute
488-
```
489-
490-
This error indicates that the compiler found multiple functions with the
491-
`#[main]` attribute. This is an error because there must be a unique entry
492-
point into a Rust program. Example:
493-
494-
```
495-
#![feature(main)]
496-
497-
#[main]
498-
fn f() {} // ok!
499-
```
500-
"##,
501-
502-
E0138: r##"
503-
More than one function was declared with the `#[start]` attribute.
504-
505-
Erroneous code example:
506-
507-
```compile_fail,E0138
508-
#![feature(start)]
509-
510-
#[start]
511-
fn foo(argc: isize, argv: *const *const u8) -> isize {}
512-
513-
#[start]
514-
fn f(argc: isize, argv: *const *const u8) -> isize {}
515-
// error: multiple 'start' functions
516-
```
517-
518-
This error indicates that the compiler found multiple functions with the
519-
`#[start]` attribute. This is an error because there must be a unique entry
520-
point into a Rust program. Example:
521-
522-
```
523-
#![feature(start)]
524-
525-
#[start]
526-
fn foo(argc: isize, argv: *const *const u8) -> isize { 0 } // ok!
527-
```
528-
"##,
529469

530470
E0139: r##"
531471
#### Note: this error code is no longer emitted by the compiler.
@@ -1626,33 +1566,6 @@ It is not possible to use stability attributes outside of the standard library.
16261566
Also, for now, it is not possible to write deprecation messages either.
16271567
"##,
16281568

1629-
E0512: r##"
1630-
Transmute with two differently sized types was attempted. Erroneous code
1631-
example:
1632-
1633-
```compile_fail,E0512
1634-
fn takes_u8(_: u8) {}
1635-
1636-
fn main() {
1637-
unsafe { takes_u8(::std::mem::transmute(0u16)); }
1638-
// error: cannot transmute between types of different sizes,
1639-
// or dependently-sized types
1640-
}
1641-
```
1642-
1643-
Please use types with same size or use the expected type directly. Example:
1644-
1645-
```
1646-
fn takes_u8(_: u8) {}
1647-
1648-
fn main() {
1649-
unsafe { takes_u8(::std::mem::transmute(0i8)); } // ok!
1650-
// or:
1651-
unsafe { takes_u8(0u8); } // ok!
1652-
}
1653-
```
1654-
"##,
1655-
16561569
E0517: r##"
16571570
This error indicates that a `#[repr(..)]` attribute was placed on an
16581571
unsupported item.
@@ -1847,84 +1760,6 @@ See [RFC 1522] for more details.
18471760
[RFC 1522]: https://github.com/rust-lang/rfcs/blob/master/text/1522-conservative-impl-trait.md
18481761
"##,
18491762

1850-
E0591: r##"
1851-
Per [RFC 401][rfc401], if you have a function declaration `foo`:
1852-
1853-
```
1854-
// For the purposes of this explanation, all of these
1855-
// different kinds of `fn` declarations are equivalent:
1856-
struct S;
1857-
fn foo(x: S) { /* ... */ }
1858-
# #[cfg(for_demonstration_only)]
1859-
extern "C" { fn foo(x: S); }
1860-
# #[cfg(for_demonstration_only)]
1861-
impl S { fn foo(self) { /* ... */ } }
1862-
```
1863-
1864-
the type of `foo` is **not** `fn(S)`, as one might expect.
1865-
Rather, it is a unique, zero-sized marker type written here as `typeof(foo)`.
1866-
However, `typeof(foo)` can be _coerced_ to a function pointer `fn(S)`,
1867-
so you rarely notice this:
1868-
1869-
```
1870-
# struct S;
1871-
# fn foo(_: S) {}
1872-
let x: fn(S) = foo; // OK, coerces
1873-
```
1874-
1875-
The reason that this matter is that the type `fn(S)` is not specific to
1876-
any particular function: it's a function _pointer_. So calling `x()` results
1877-
in a virtual call, whereas `foo()` is statically dispatched, because the type
1878-
of `foo` tells us precisely what function is being called.
1879-
1880-
As noted above, coercions mean that most code doesn't have to be
1881-
concerned with this distinction. However, you can tell the difference
1882-
when using **transmute** to convert a fn item into a fn pointer.
1883-
1884-
This is sometimes done as part of an FFI:
1885-
1886-
```compile_fail,E0591
1887-
extern "C" fn foo(userdata: Box<i32>) {
1888-
/* ... */
1889-
}
1890-
1891-
# fn callback(_: extern "C" fn(*mut i32)) {}
1892-
# use std::mem::transmute;
1893-
# unsafe {
1894-
let f: extern "C" fn(*mut i32) = transmute(foo);
1895-
callback(f);
1896-
# }
1897-
```
1898-
1899-
Here, transmute is being used to convert the types of the fn arguments.
1900-
This pattern is incorrect because, because the type of `foo` is a function
1901-
**item** (`typeof(foo)`), which is zero-sized, and the target type (`fn()`)
1902-
is a function pointer, which is not zero-sized.
1903-
This pattern should be rewritten. There are a few possible ways to do this:
1904-
1905-
- change the original fn declaration to match the expected signature,
1906-
and do the cast in the fn body (the preferred option)
1907-
- cast the fn item fo a fn pointer before calling transmute, as shown here:
1908-
1909-
```
1910-
# extern "C" fn foo(_: Box<i32>) {}
1911-
# use std::mem::transmute;
1912-
# unsafe {
1913-
let f: extern "C" fn(*mut i32) = transmute(foo as extern "C" fn(_));
1914-
let f: extern "C" fn(*mut i32) = transmute(foo as usize); // works too
1915-
# }
1916-
```
1917-
1918-
The same applies to transmutes to `*mut fn()`, which were observed in practice.
1919-
Note though that use of this type is generally incorrect.
1920-
The intention is typically to describe a function pointer, but just `fn()`
1921-
alone suffices for that. `*mut fn()` is a pointer to a fn pointer.
1922-
(Since these values are typically just passed to C code, however, this rarely
1923-
makes a difference in practice.)
1924-
1925-
[rfc401]: https://github.com/rust-lang/rfcs/blob/master/text/0401-coercions.md
1926-
"##,
1927-
19281763
E0593: r##"
19291764
You tried to supply an `Fn`-based type with an incorrect number of arguments
19301765
than what was expected.
@@ -1941,21 +1776,6 @@ fn main() {
19411776
```
19421777
"##,
19431778

1944-
E0601: r##"
1945-
No `main` function was found in a binary crate. To fix this error, add a
1946-
`main` function. For example:
1947-
1948-
```
1949-
fn main() {
1950-
// Your program will start here.
1951-
println!("Hello world!");
1952-
}
1953-
```
1954-
1955-
If you don't know the basics of Rust, you can go look to the Rust Book to get
1956-
started: https://doc.rust-lang.org/book/
1957-
"##,
1958-
19591779
E0602: r##"
19601780
An unknown lint was used on the command line.
19611781

src/librustc/lib.rs

-4
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,12 @@ pub mod lint;
101101
pub mod middle {
102102
pub mod expr_use_visitor;
103103
pub mod cstore;
104-
pub mod dead;
105104
pub mod dependency_format;
106105
pub mod diagnostic_items;
107-
pub mod entry;
108106
pub mod exported_symbols;
109107
pub mod free_region;
110-
pub mod intrinsicck;
111108
pub mod lib_features;
112109
pub mod lang_items;
113-
pub mod liveness;
114110
pub mod mem_categorization;
115111
pub mod privacy;
116112
pub mod reachable;

src/librustc_interface/passes.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -780,13 +780,10 @@ pub fn default_provide(providers: &mut ty::query::Providers<'_>) {
780780
ty::provide(providers);
781781
traits::provide(providers);
782782
stability::provide(providers);
783-
middle::intrinsicck::provide(providers);
784-
middle::liveness::provide(providers);
785783
reachable::provide(providers);
786784
rustc_passes::provide(providers);
787785
rustc_traits::provide(providers);
788786
middle::region::provide(providers);
789-
middle::entry::provide(providers);
790787
cstore::provide(providers);
791788
lint::provide(providers);
792789
rustc_lint::provide(providers);
@@ -892,7 +889,7 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
892889
time(sess, "misc checking 1", || {
893890
parallel!({
894891
entry_point = time(sess, "looking for entry point", || {
895-
middle::entry::find_entry_point(tcx)
892+
rustc_passes::entry::find_entry_point(tcx)
896893
});
897894

898895
time(sess, "looking for plugin registrar", || {
@@ -973,7 +970,7 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
973970
tcx.ensure().check_private_in_public(LOCAL_CRATE);
974971
});
975972
}, {
976-
time(sess, "death checking", || middle::dead::check_crate(tcx));
973+
time(sess, "death checking", || rustc_passes::dead::check_crate(tcx));
977974
}, {
978975
time(sess, "unused lib feature checking", || {
979976
stability::check_unused_or_stable_features(tcx)

src/librustc_passes/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ rustc_data_structures = { path = "../librustc_data_structures" }
1515
syntax = { path = "../libsyntax" }
1616
syntax_pos = { path = "../libsyntax_pos" }
1717
errors = { path = "../librustc_errors", package = "rustc_errors" }
18+
rustc_target = { path = "../librustc_target" }
19+
rustc_index = { path = "../librustc_index" }

src/librustc/middle/dead.rs renamed to src/librustc_passes/dead.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
// closely. The idea is that all reachable symbols are live, codes called
33
// from live codes are live, and everything else is dead.
44

5-
use crate::hir::Node;
6-
use crate::hir::{self, PatKind, TyKind};
7-
use crate::hir::intravisit::{self, Visitor, NestedVisitorMap};
8-
use crate::hir::itemlikevisit::ItemLikeVisitor;
9-
10-
use crate::hir::def::{CtorOf, Res, DefKind};
11-
use crate::hir::CodegenFnAttrFlags;
12-
use crate::hir::def_id::{DefId, LOCAL_CRATE};
13-
use crate::lint;
14-
use crate::middle::privacy;
15-
use crate::ty::{self, DefIdTree, TyCtxt};
16-
use crate::util::nodemap::FxHashSet;
5+
use rustc::hir::Node;
6+
use rustc::hir::{self, PatKind, TyKind};
7+
use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
8+
use rustc::hir::itemlikevisit::ItemLikeVisitor;
9+
10+
use rustc::hir::def::{CtorOf, Res, DefKind};
11+
use rustc::hir::CodegenFnAttrFlags;
12+
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
13+
use rustc::lint;
14+
use rustc::middle::privacy;
15+
use rustc::ty::{self, DefIdTree, TyCtxt};
16+
use rustc::util::nodemap::FxHashSet;
1717

1818
use rustc_data_structures::fx::FxHashMap;
1919

src/librustc/middle/entry.rs renamed to src/librustc_passes/entry.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
use crate::hir::map as hir_map;
2-
use crate::hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId, LOCAL_CRATE};
3-
use crate::session::{config, Session};
4-
use crate::session::config::EntryFnType;
1+
use rustc::hir::map as hir_map;
2+
use rustc::hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId, LOCAL_CRATE};
3+
use rustc::session::{config, Session};
4+
use rustc::session::config::EntryFnType;
55
use syntax::attr;
66
use syntax::entry::EntryPointType;
77
use syntax::symbol::sym;
88
use syntax_pos::Span;
9-
use crate::hir::{HirId, Item, ItemKind, ImplItem, TraitItem};
10-
use crate::hir::itemlikevisit::ItemLikeVisitor;
11-
use crate::ty::TyCtxt;
12-
use crate::ty::query::Providers;
9+
use rustc::hir::{HirId, Item, ItemKind, ImplItem, TraitItem};
10+
use rustc::hir::itemlikevisit::ItemLikeVisitor;
11+
use rustc::ty::TyCtxt;
12+
use rustc::ty::query::Providers;
1313

1414
struct EntryContext<'a, 'tcx> {
1515
session: &'a Session,

0 commit comments

Comments
 (0)