Skip to content

Commit

Permalink
Auto merge of #23593 - Manishearth:rollup, r=Manishearth
Browse files Browse the repository at this point in the history
(yay, no Saturday)
  • Loading branch information
bors committed Mar 23, 2015
2 parents b0aad7d + b4e9106 commit 809a554
Show file tree
Hide file tree
Showing 19 changed files with 347 additions and 205 deletions.
2 changes: 1 addition & 1 deletion man/rustc.1
Expand Up @@ -242,7 +242,7 @@ full debug info with variable and type information.
\fBopt\-level\fR=\fIVAL\fR
Optimize with possible levels 0\[en]3

.SH ENVIRONMENT VARIABLES
.SH ENVIRONMENT

Some of these affect the output of the compiler, while others affect programs
which link to the standard library.
Expand Down
6 changes: 3 additions & 3 deletions src/doc/reference.md
Expand Up @@ -1982,7 +1982,7 @@ the namespace hierarchy as it normally would.
## Attributes

```{.ebnf .gram}
attribute : "#!" ? '[' meta_item ']' ;
attribute : '#' '!' ? '[' meta_item ']' ;
meta_item : ident [ '=' literal
| '(' meta_seq ')' ] ? ;
meta_seq : meta_item [ ',' meta_seq ] ? ;
Expand Down Expand Up @@ -3158,7 +3158,7 @@ ten_times(|j| println!("hello, {}", j));
### While loops

```{.ebnf .gram}
while_expr : "while" no_struct_literal_expr '{' block '}' ;
while_expr : [ lifetime ':' ] "while" no_struct_literal_expr '{' block '}' ;
```

A `while` loop begins by evaluating the boolean loop conditional expression.
Expand Down Expand Up @@ -3223,7 +3223,7 @@ A `continue` expression is only permitted in the body of a loop.
### For expressions

```{.ebnf .gram}
for_expr : "for" pat "in" no_struct_literal_expr '{' block '}' ;
for_expr : [ lifetime ':' ] "for" pat "in" no_struct_literal_expr '{' block '}' ;
```

A `for` expression is a syntactic construct for looping over elements provided
Expand Down
6 changes: 3 additions & 3 deletions src/doc/trpl/SUMMARY.md
@@ -1,6 +1,6 @@
# Summary

* [I: The Basics](basic.md)
* [The Basics](basic.md)
* [Installing Rust](installing-rust.md)
* [Hello, world!](hello-world.md)
* [Hello, Cargo!](hello-cargo.md)
Expand All @@ -14,7 +14,7 @@
* [Strings](strings.md)
* [Arrays, Vectors, and Slices](arrays-vectors-and-slices.md)
* [Standard Input](standard-input.md)
* [II: Intermediate Rust](intermediate.md)
* [Intermediate Rust](intermediate.md)
* [Crates and Modules](crates-and-modules.md)
* [Testing](testing.md)
* [Pointers](pointers.md)
Expand All @@ -31,7 +31,7 @@
* [Concurrency](concurrency.md)
* [Error Handling](error-handling.md)
* [Documentation](documentation.md)
* [III: Advanced Topics](advanced.md)
* [Advanced Topics](advanced.md)
* [FFI](ffi.md)
* [Unsafe Code](unsafe.md)
* [Advanced Macros](advanced-macros.md)
Expand Down
11 changes: 1 addition & 10 deletions src/libcollections/btree/map.rs
Expand Up @@ -24,7 +24,7 @@ use core::default::Default;
use core::fmt::Debug;
use core::hash::{Hash, Hasher};
use core::iter::{Map, FromIterator, IntoIterator};
use core::ops::{Index, IndexMut};
use core::ops::{Index};
use core::{iter, fmt, mem, usize};
use Bound::{self, Included, Excluded, Unbounded};

Expand Down Expand Up @@ -925,15 +925,6 @@ impl<K: Ord, Q: ?Sized, V> Index<Q> for BTreeMap<K, V>
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<K: Ord, Q: ?Sized, V> IndexMut<Q> for BTreeMap<K, V>
where K: Borrow<Q>, Q: Ord
{
fn index_mut(&mut self, key: &Q) -> &mut V {
self.get_mut(key).expect("no entry found for key")
}
}

/// Genericises over how to get the correct type of iterator from the correct type
/// of Node ownership.
trait Traverse<N> {
Expand Down
128 changes: 128 additions & 0 deletions src/librustc/README.md
@@ -0,0 +1,128 @@
An informal guide to reading and working on the rustc compiler.
==================================================================

If you wish to expand on this document, or have a more experienced
Rust contributor add anything else to it, please get in touch:

* http://internals.rust-lang.org/
* https://chat.mibbit.com/?server=irc.mozilla.org&channel=%23rust

or file a bug:

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

Your concerns are probably the same as someone else's.

The crates of rustc
===================

Rustc consists of a number of crates, including `libsyntax`,
`librustc`, `librustc_back`, `librustc_trans`, and `librustc_driver`
(the names and divisions are not set in stone and may change;
in general, a finer-grained division of crates is preferable):

- `libsyntax` contains those things concerned purely with syntax –
that is, the AST, parser, pretty-printer, lexer, macro expander, and
utilities for traversing ASTs – are in a separate crate called
"syntax", whose files are in `./../libsyntax`, where `.` is the
current directory (that is, the parent directory of front/, middle/,
back/, and so on).

- `librustc` (the current directory) contains the high-level analysis
passes, such as the type checker, borrow checker, and so forth.
It is the heart of the compiler.

- `librustc_back` contains some very low-level details that are
specific to different LLVM targets and so forth.

- `librustc_trans` contains the code to convert from Rust IR into LLVM
IR, and then from LLVM IR into machine code, as well as the main
driver that orchestrates all the other passes and various other bits
of miscellany. In general it contains code that runs towards the
end of the compilation process.

- `librustc_driver` invokes the compiler from `libsyntax`, then the
analysis phases from `librustc`, and finally the lowering and
codegen passes from `librustc_trans`.

Roughly speaking the "order" of the three crates is as follows:

libsyntax -> librustc -> librustc_trans
| |
+-----------------+-------------------+
|
librustc_driver


Modules in the rustc crate
==========================

The rustc crate itself consists of the following submodules
(mostly, but not entirely, in their own directories):

- session: options and data that pertain to the compilation session as
a whole
- middle: middle-end: name resolution, typechecking, LLVM code
generation
- metadata: encoder and decoder for data required by separate
compilation
- plugin: infrastructure for compiler plugins
- lint: infrastructure for compiler warnings
- util: ubiquitous types and helper functions
- lib: bindings to LLVM

The entry-point for the compiler is main() in the librustc_trans
crate.

The 3 central data structures:
------------------------------

1. `./../libsyntax/ast.rs` defines the AST. The AST is treated as
immutable after parsing, but it depends on mutable context data
structures (mainly hash maps) to give it meaning.

- Many – though not all – nodes within this data structure are
wrapped in the type `spanned<T>`, meaning that the front-end has
marked the input coordinates of that node. The member `node` is
the data itself, the member `span` is the input location (file,
line, column; both low and high).

- Many other nodes within this data structure carry a
`def_id`. These nodes represent the 'target' of some name
reference elsewhere in the tree. When the AST is resolved, by
`middle/resolve.rs`, all names wind up acquiring a def that they
point to. So anything that can be pointed-to by a name winds
up with a `def_id`.

2. `middle/ty.rs` defines the datatype `sty`. This is the type that
represents types after they have been resolved and normalized by
the middle-end. The typeck phase converts every ast type to a
`ty::sty`, and the latter is used to drive later phases of
compilation. Most variants in the `ast::ty` tag have a
corresponding variant in the `ty::sty` tag.

3. `./../librustc_llvm/lib.rs` defines the exported types
`ValueRef`, `TypeRef`, `BasicBlockRef`, and several others.
Each of these is an opaque pointer to an LLVM type,
manipulated through the `lib::llvm` interface.


Control and information flow within the compiler:
-------------------------------------------------

- main() in lib.rs assumes control on startup. Options are
parsed, platform is detected, etc.

- `./../libsyntax/parse/parser.rs` parses the input files and produces
an AST that represents the input crate.

- Multiple middle-end passes (`middle/resolve.rs`, `middle/typeck.rs`)
analyze the semantics of the resulting AST. Each pass generates new
information about the AST and stores it in various environment data
structures. The driver passes environments to each compiler pass
that needs to refer to them.

- Finally, the `trans` module in `librustc_trans` translates the Rust
AST to LLVM bitcode in a type-directed way. When it's finished
synthesizing LLVM values, rustc asks LLVM to write them out in some
form (`.bc`, `.o`) and possibly run the system linker.
124 changes: 0 additions & 124 deletions src/librustc/README.txt

This file was deleted.

2 changes: 1 addition & 1 deletion src/librustc_resolve/lib.rs
Expand Up @@ -900,7 +900,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
return;
}
if self.glob_map.contains_key(&import_id) {
self.glob_map[import_id].insert(name);
self.glob_map.get_mut(&import_id).unwrap().insert(name);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_resolve/resolve_imports.rs
Expand Up @@ -603,7 +603,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {

// We've successfully resolved the import. Write the results in.
let mut import_resolutions = module_.import_resolutions.borrow_mut();
let import_resolution = &mut (*import_resolutions)[target];
let import_resolution = import_resolutions.get_mut(&target).unwrap();

{
let mut check_and_write_import = |namespace, result: &_, used_public: &mut bool| {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/README.txt
@@ -1 +1 @@
See the README.txt in ../librustc.
See the README.md in ../librustc.

0 comments on commit 809a554

Please sign in to comment.