summary refs log tree commit diff
path: root/src/librustc/metadata/tyencode.rs
AgeCommit message (Collapse)AuthorLines
2015-04-30Stop using Rc in TraitRef and TraitDefAriel Ben-Yehuda-6/+6
The former stopped making sense when we started interning substs and made TraitRef a 2-word copy type, and I'm moving the latter into an arena as they live as long as the type context.
2015-04-17Create a struct to represent early-bound regionsNiko Matsakis-5/+5
2015-04-04Encode more precise scoping rules for function params.Felix S. Klock II-1/+3
Function params which outlive everything in the body (incl temporaries). Thus if we assign them their own `CodeExtent`, the region inference can properly show that it is sound to have temporaries with destructors that reference the parameters (because such temporaries will be dropped before the parameters are). This allows us to address issue 23338 in a clean way. As a drive-by, fix a mistake in the tyencode for `CodeExtent::BlockRemainder`.
2015-03-25rustc: Remove support for int/uintAlex Crichton-2/+2
This commit removes all parsing, resolve, and compiler support for the old and long-deprecated int/uint types.
2015-03-13Fallout of std::old_io deprecationAlex Crichton-0/+1
2015-03-03metadata: Implement relaxation of short RBML lengths.Kang Seonghoon-33/+35
We try to move the data when the length can be encoded in the much smaller number of bytes. This interferes with indices and type abbreviations however, so this commit introduces a public interface to get and mark a "stable" (i.e. not affected by relaxation) position of the current pointer. The relaxation logic only moves a small data, currently at most 256 bytes, as moving the data can be costly. There might be further opportunities to allow more relaxation by moving fields around, which I didn't seriously try.
2015-03-02Remove the synthetic "region bound" from closures and instead update howNiko Matsakis-2/+1
type-outlives works for closure types so that it ensures that all upvars outlive the region in question. This gives the same guarantees but without introducing artificial regions (and gives better error messages to boot).
2015-02-24Remove bounds struct from TypeParameterDef. Bounds information is nowNiko Matsakis-5/+12
exclusively stored in the where clauses.
2015-02-24Remove ty_open and treat Unsized lvalues as *Unsized.Eduard Burtescu-3/+0
2015-02-16Detect and store object-lifetime-defaults.Niko Matsakis-0/+15
2015-02-11Added DestructionScope variant to CodeExtent, representing the areaFelix S. Klock II-1/+7
immediately surrounding a node that is a terminating_scope (e.g. statements, looping forms) during which the destructors run (the destructors for temporaries from the execution of that node, that is). Introduced DestructionScopeData newtype wrapper around ast::NodeId, to preserve invariant that FreeRegion and ScopeChain::BlockScope carry destruction scopes (rather than arbitrary CodeExtents). Insert DestructionScope and block Remainder into enclosing CodeExtents hierarchy. Add more doc for DestructionScope, complete with ASCII art. Switch to constructing DestructionScope rather than Misc in a number of places, mostly related to `ty::ReFree` creation, and use destruction-scopes of node-ids at various calls to liberate_late_bound_regions. middle::resolve_lifetime: Map BlockScope to DestructionScope in `fn resolve_free_lifetime`. Add the InnermostDeclaringBlock and InnermostEnclosingExpr enums that are my attempt to clarify the region::Context structure, and that later commmts build upon. Improve the debug output for `CodeExtent` attached to `ty::Region::ReScope`. Loosened an assertion in `rustc_trans::trans::cleanup` to account for `DestructionScope`. (Perhaps this should just be switched entirely over to `DestructionScope`, rather than allowing for either `Misc` or `DestructionScope`.) ---- Even though the DestructionScope is new, this particular commit should not actually change the semantics of any current code.
2015-02-02`for x in xs.iter()` -> `for x in &xs`Jorge Aparicio-8/+8
2015-01-27Add `CodeExtent::Remainder` variant; pre-req for new scoping/drop rules.Felix S. Klock II-1/+3
This new variant introduces finer-grain code extents, i.e. we now track that a binding lives only for a suffix of a block, and (importantly) will be dropped when it goes out of scope *before* the bindings that occurred earlier in the block. Both of these notions are neatly captured by marking the block (and each suffix) as an enclosing scope of the next suffix beneath it. This is work that is part of the foundation for issue #8861. (It actually has been seen in earlier posted pull requests; I have just factored it out into its own PR to ease my own rebasing.) ---- These finer grained scopes do mean that some code is newly rejected by `rustc`; for example: ```rust let mut map : HashMap<u8, &u8> = HashMap::new(); let tmp = Box::new(2); map.insert(43, &*tmp); ``` This will now fail to compile with a message that `*tmp` does not live long enough, because the scope of `tmp` is now strictly smaller than that of `map`, and the use of `&u8` in map's type requires that the borrowed references are all to data that live at least as long as the map. The usual fix for a case like this is to move the binding for `tmp` up above that of `map`; note that you can still leave the initialization in the original spot, like so: ```rust let tmp; let mut map : HashMap<u8, &u8> = HashMap::new(); tmp = box 2; map.insert(43, &*tmp); ``` Similarly, one can encounter an analogous situation with `Vec`: one would need to rewrite: ```rust let mut vec = Vec::new(); let tmp = 'c'; vec.push(&tmp); ``` as: ``` let tmp; let mut vec = Vec::new(); tmp = 'c'; vec.push(&tmp); ``` ---- In some corner cases, it does not suffice to reorder the bindings; in particular, when the types for both bindings need to reflect exactly the *same* code extent, and a parent/child relationship between them does not work. In pnkfelix's experience this has arisen most often when mixing uses of cyclic data structures while also allowing a lifetime parameter `'a` to flow into a type parameter context where the type is *invariant* with respect to the type parameter. An important instance of this is `arena::TypedArena<T>`, which is invariant with respect to `T`. (The reason that variance is relevant is this: *if* `TypedArena` were covariant with respect to its type parameter, then we could assign it the longer lifetime when it is initialized, and then convert it to a subtype (via covariance) with a shorter lifetime when necessary. But `TypedArena` is invariant with respect to its type parameter, and thus if `S` is a subtype of `T` (in particular, if `S` has a lifetime parameter that is shorter than that of `T`), then a `TypedArena<S>` is unrelated to `TypedArena<T>`.) Concretely, consider code like this: ```rust struct Node<'a> { sibling: Option<&'a Node<'a>> } struct Context<'a> { // because of this field, `Context<'a>` is invariant with respect to `'a`. arena: &'a TypedArena<Node<'a>>, ... } fn new_ctxt<'a>(arena: &'a TypedArena<Node<'a>>) -> Context<'a> { ... } fn use_ctxt<'a>(fcx: &'a Context<'a>) { ... } let arena = TypedArena::new(); let ctxt = new_ctxt(&arena); use_ctxt(&ctxt); ``` In these situations, if you try to introduce two bindings via two distinct `let` statements, each is (with this commit) assigned a distinct extent, and the region inference system cannot find a single region to assign to the lifetime `'a` that works for both of the bindings. So you get an error that `ctxt` does not live long enough; but moving its binding up above that of `arena` just shifts the error so now the compiler complains that `arena` does not live long enough. SO: What to do? The easiest fix in this case is to ensure that the two bindings *do* get assigned the same static extent, by stuffing both bindings into the same let statement, like so: ```rust let (arena, ctxt): (TypedArena, Context); arena = TypedArena::new(); ctxt = new_ctxt(&arena); use_ctxt(&ctxt); ``` Due to the new code rejections outlined above, this is a ... [breaking-change]
2015-01-26std: Rename Writer::write to Writer::write_allAlex Crichton-1/+1
In preparation for upcoming changes to the `Writer` trait (soon to be called `Write`) this commit renames the current `write` method to `write_all` to match the semantics of the upcoming `write_all` method. The `write` method will be repurposed to return a `usize` indicating how much data was written which differs from the current `write` semantics. In order to head off as much unintended breakage as possible, the method is being deprecated now in favor of a new name. [breaking-change]
2015-01-26Remove "unboxed" attribute in code referring to new closures.Eduard Burtescu-1/+1
2015-01-20Remove onceness & bounds - they don't do anything.Ariel Ben-Yehuda-9/+0
2015-01-20Kill TraitStoreAriel Ben-Yehuda-12/+0
2015-01-08Store deprecated status of i/u-suffixed literals.Huon Wilson-2/+2
2015-01-06syntax/rustc: implement isize/usizeCorey Richardson-2/+2
2015-01-05remove ty_closureJorge Aparicio-4/+0
2015-01-03sed -i -s 's/\bmod,/self,/g' **/*.rsJorge Aparicio-1/+1
2014-12-30Remove the def-id from type parameters. Having this def-id was bad for ↵Niko Matsakis-2/+2
several reasons: 1. Produced more unique types than is necessary. This increases memory consumption. 2. Linking the type parameter to its definition *seems* like a good idea, but it encourages reliance on the bounds listing. 3. It made pretty-printing harder and in particular was causing bad error messages when errors occurred before the `TypeParameterDef` entries were fully stored.
2014-12-30Integrate projection bounds to `ExistentialBounds` but do not use them for ↵Niko Matsakis-3/+8
anything.
2014-12-30Convert to use `Rc<TraitRef>` in object types (finally!).Niko Matsakis-2/+2
2014-12-30Implement associated type projection and normalization.Niko Matsakis-4/+24
2014-12-30More rebase fixes.Huon Wilson-7/+7
2014-12-29Store Substs in an arena in the tcx.Huon Wilson-1/+1
This current inflates memory use more than 3 times.
2014-12-22Adjust metadata for new fields and enum variants. Yawn.Niko Matsakis-1/+6
2014-12-20rustc: use Ty instead of passing ty::sty around.Eduard Burtescu-100/+97
2014-12-19Make all predicates higher-ranked, not just trait references.Niko Matsakis-3/+3
2014-12-19Centralize on using `Binder` to introduce new binding levels, rather than ↵Niko Matsakis-7/+7
having FnSig carry an implicit binding level. This means that we be more typesafe in general, since things that instantiate bound regions can drop the Binder to reflect that.
2014-12-19Create distinct types for a PolyTraitRef (with bindings) and a normal TraitRef.Niko Matsakis-3/+3
2014-12-18librustc: Always parse `macro!()`/`macro![]` as expressions if notPatrick Walton-1/+1
followed by a semicolon. This allows code like `vec![1i, 2, 3].len();` to work. This breaks code that uses macros as statements without putting semicolons after them, such as: fn main() { ... assert!(a == b) assert!(c == d) println(...); } It also breaks code that uses macros as items without semicolons: local_data_key!(foo) fn main() { println("hello world") } Add semicolons to fix this code. Those two examples can be fixed as follows: fn main() { ... assert!(a == b); assert!(c == d); println(...); } local_data_key!(foo); fn main() { println("hello world") } RFC #378. Closes #18635. [breaking-change]
2014-12-14Rename FnStyle trait to Unsafety.Niko Matsakis-5/+5
2014-12-13librustc: use unboxed closuresJorge Aparicio-5/+9
2014-12-12Switch to using predicates to drive checking. Correct various tests --Niko Matsakis-0/+27
in most cases, just the error message changed, but in some cases we are reporting new errors that OUGHT to have been reported before but we're overlooked (mostly involving the `'static` bound on `Send`).
2014-11-20Refactored new CodeExtent type for improved abstraction.Felix S. Klock II-3/+14
(Previously, statically identifiable scopes/regions were solely identified with NodeId's; this refactoring prepares for a future where that 1:1 correspondence does not hold.)
2014-11-19rustc: middle: remove obsolete ty::get.Eduard Burtescu-1/+1
2014-11-19rustc: fix fallout of adding the `'tcx` lifetime to `Ty`.Eduard Burtescu-17/+26
2014-11-19rustc: middle: rename `ty::t` to `Ty` and use it unqualified everywhere.Eduard Burtescu-3/+3
2014-11-19rustc: avoid `use`-ing `syntax::ast::*`.Eduard Burtescu-22/+21
2014-11-18Switch the code to use De Bruijn indices rather than binder-ids.Niko Matsakis-2/+2
2014-11-16Try to remove ty_nil, some kind of error in exhaustiveness checkingNiko Matsakis-1/+0
2014-11-10Use FnvHashMap instead of HashMap in rustcAriel Ben-Yehuda-2/+2
2014-11-07Make TyTrait embed a `TraitRef`, so that when we extend TraitRef, it ↵Niko Matsakis-7/+4
naturally carries over to object types. I wanted to embed an `Rc<TraitRef>`, but I was foiled by the current static rules, which prohibit non-Sync values from being stored in static locations. This means that the constants for `ty_int` and so forth cannot be initialized.
2014-11-06Fallout from collection conventionsAlexis Beingessner-1/+1
2014-10-28Remove ty_bot from the type systemJakub Bukaj-2/+8
We now instead use a fresh variable for expressions that diverge.
2014-10-27Fix monomorphization of unboxed closuresBrian Koropoff-2/+4
This adds a `Substs` field to `ty_unboxed_closure` and plumbs basic handling of it throughout the compiler. trans now correctly monomorphizes captured free variables and llvm function defs. This fixes uses of unboxed closures which reference a free type or region parameter from their environment in either their signature or free variables. Closes #16791
2014-10-22Part of #6993. Moved a bunch of uses of Ident to NameJonathan S-1/+1
2014-10-16Fix soundness bug in treatment of closure upvars by regionckBrian Koropoff-0/+3
- Unify the representations of `cat_upvar` and `cat_copied_upvar` - In `link_reborrowed_region`, account for the ability of upvars to change their mutability due to later processing. A map of recursive region links we may want to establish in the future is maintained, with the links being established when the kind of the borrow is adjusted. - When categorizing upvars, add an explicit deref that represents the closure environment pointer for closures that do not take the environment by value. The region for the implicit pointer is an anonymous free region type introduced for this purpose. This creates the necessary constraint to prevent unsound reborrows from the environment. - Add a note to categorizations to make it easier to tell when extra dereferences have been inserted by an upvar without having to perform deep pattern matching. - Adjust borrowck to deal with the changes. Where `cat_upvar` and `cat_copied_upvar` were previously treated differently, they are now both treated roughly like local variables within the closure body, as the explicit derefs now ensure proper behavior. However, error diagnostics had to be changed to explicitly look through the extra dereferences to avoid producing confusing messages about references not present in the source code. Closes issue #17403. Remaining work: - The error diagnostics that result from failed region inference are pretty inscrutible and should be improved. Code like the following is now rejected: let mut x = 0u; let f = || &mut x; let y = f(); let z = f(); // multiple mutable references to the same location This also breaks code that uses a similar construction even if it does not go on to violate aliasability semantics. Such code will need to be reworked in some way, such as by using a capture-by-value closure type. [breaking-change]