Commit Graph

46711 Commits

Author SHA1 Message Date
Aaron Turon
dc45d924b6 Adjust error code 2016-03-14 15:05:15 -07:00
Aaron Turon
c4f78ad7bf Parse fail test fixes 2016-03-14 15:05:15 -07:00
Aaron Turon
e5753b4605 Fixes after rebase 2016-03-14 15:05:15 -07:00
Aaron Turon
e36620dd9c Introduce ICE when the topmost projection restriction kicks in, as per issue #32205 2016-03-14 15:05:15 -07:00
Aaron Turon
d80189d305 Test fixes, added README for tests 2016-03-14 15:05:14 -07:00
Aaron Turon
326201657a Move tests to dedicated subdirectories 2016-03-14 15:05:14 -07:00
Aaron Turon
35437c7cf6 Fixes after a rebase 2016-03-14 15:05:14 -07:00
Aaron Turon
8f0e73ef55 Address review comments 2016-03-14 15:05:13 -07:00
Aaron Turon
9bcfdb7b9c Move projection_mode to InferContext rather than SelectionContext to reduce chance of bugs 2016-03-14 15:05:13 -07:00
Aaron Turon
386f8eefc0 Forbid cross-polarity specializations 2016-03-14 15:04:41 -07:00
Aaron Turon
2651f8c147 Add regression tests from initial implementation review 2016-03-14 15:04:41 -07:00
Aaron Turon
1726c1b54a Add some debugging output for specialization graph assembly 2016-03-14 15:04:40 -07:00
Aaron Turon
eaf2f90956 Refactor core specialization and subst translation code to avoid
danger of inference variables floating around without their inference
context.

The main insight here is that, when we are translating substitutions
between two impls, *we already know that the more specific impl holds*,
so we do not need to add its obligations to the parameter
environment. Instead, we can just thread through the inference context
we used to show select the more specific impl in the first place.
2016-03-14 15:04:40 -07:00
Aaron Turon
8f20cbf030 Add more commentary for subst translation 2016-03-14 15:04:40 -07:00
Aaron Turon
940adda2ae Move specialization graph walks to iterators; make associated type
projection sensitive to "mode" (most importantly, trans vs middle).

This commit introduces several pieces of iteration infrastructure in the
specialization graph data structure, as well as various helpers for
finding the definition of a given item, given its kind and name.

In addition, associated type projection is now *mode-sensitive*, with
three possible modes:

- **Topmost**. This means that projection is only possible if there is a
    non-`default` definition of the associated type directly on the
    selected impl. This mode is a bit of a hack: it's used during early
    coherence checking before we have built the specialization
    graph (and therefore before we can walk up the specialization
    parents to find other definitions). Eventually, this should be
    replaced with a less "staged" construction of the specialization
    graph.

- **AnyFinal**. Projection succeeds for any non-`default` associated
    type definition, even if it is defined by a parent impl. Used
    throughout typechecking.

- **Any**. Projection always succeeds. Used by trans.

The lasting distinction here is between `AnyFinal` and `Any` -- we wish
to treat `default` associated types opaquely for typechecking purposes.

In addition to the above, the commit includes a few other minor review fixes.
2016-03-14 15:04:40 -07:00
Aaron Turon
462c83e272 Address basic nits from initial review 2016-03-14 15:04:39 -07:00
Aaron Turon
9734406a5f Assorted fixed after rebasing 2016-03-14 15:04:39 -07:00
Aaron Turon
c1df41e776 Add some basic comments about how specialization fits into the rest of the trait machinery 2016-03-14 15:04:39 -07:00
Aaron Turon
ed8d059d8d Adjust tests for feature gate, and add tests for the gate itself 2016-03-14 15:04:38 -07:00
Aaron Turon
e816910398 Add feature gate 2016-03-14 15:04:38 -07:00
Aaron Turon
9f16c2ce59 Adjust coherence test to reflect that only the orphan rule prevents you from adding *generalizing* impls 2016-03-14 15:04:38 -07:00
Aaron Turon
7976e36544 Adjust test for new overlap message on default trait impls 2016-03-14 15:04:38 -07:00
Aaron Turon
d8160799b5 Adjust overlap-related tests to account for cosmetic changes to error reporting behavior 2016-03-14 15:04:37 -07:00
Aaron Turon
a3825827b7 Add tests for specialization on associated types 2016-03-14 15:04:37 -07:00
Aaron Turon
b7e5112e88 Implement default associated type inheritance.
This commit leverages the specialization graph infrastructure to allow
specializing trait implementations to leave off associated types for
which their parents have provided defaults.

It also modifies the type projection code to avoid projecting associated
types unless either (1) all input types are fully known or (2) the
available associated type is "final", i.e. not marked `default`.
This restriction is required for soundness, due to examples like:

```rust
trait Foo {
    type Assoc;
}

impl<T> Foo for T {
    default type Assoc = ();
}

impl Foo for u8 {
    type Assoc = String;
}

fn generic<T>() -> <T as Foo>::Assoc {
    () //~ ERROR
}

fn main() {
    let s: String = generic::<u8>();
    println!("{}", s); // bad news
}
```
2016-03-14 15:04:37 -07:00
Aaron Turon
5dedbdaea4 Check for proper use of default keyword in specializing impls. 2016-03-14 15:04:36 -07:00
Aaron Turon
1077ff2dec Add basic specialization tests, including for default item
inheritance. Updates some of the coherence tests as well.
2016-03-14 15:04:36 -07:00
Aaron Turon
7e42a78016 Implement default method inheritance.
This commit leverages the specialization graph infrastructure to allow
specializing trait implementations to leave off methods for which their
parents have provided defaults.

It does not yet check that the `default` keyword is appropriately used
in such cases.
2016-03-14 15:04:36 -07:00
Aaron Turon
957ee5ce34 Add subst helper for inheriting FnSpace from another subst 2016-03-14 15:04:35 -07:00
Aaron Turon
1f34086e94 Initial incorporation of specialization:
- Rewrites the overlap checker to instead build up a specialization
  graph, checking for overlap errors in the process.

- Use the specialization order during impl selection.

This commit does not yet handle associated types correctly, and assumes
that all items are `default` and are overridden.
2016-03-14 15:04:35 -07:00
Aaron Turon
c5849e4dff Add specialization module.
The module contains a few important components:

- The `specialize` function, which determines whether one impl is a
  specialization of another.

- The `SpecializationGraph`, a per-trait graph recording the
  specialization tree. The main purpose of the graph is to allow
  traversals upwards (to less specialized impls) for discovering
  un-overridden defaults, and for ensuring that overridden items are
  allowed to be overridden.
2016-03-14 15:04:34 -07:00
Aaron Turon
45f4bf112a Refactor impl_trait_ref_and_oblig, making it generally available as a utility 2016-03-14 15:04:34 -07:00
Aaron Turon
991f32a6ca Hook default keyword into metadata and carry data through to typeck 2016-03-14 15:04:34 -07:00
Aaron Turon
8fe63e2342 Add default as contextual keyword, and parse it for impl items. 2016-03-14 15:04:33 -07:00
Aaron Turon
659ba09b2d Remove useless vector accumulation in type_vars_for_defs 2016-03-14 15:04:33 -07:00
Aaron Turon
736603424e Fix existing comment typo. 2016-03-14 15:04:33 -07:00
bors
01118928fc Auto merge of #30587 - oli-obk:eager_const_eval2, r=nikomatsakis
typestrong const integers

~~It would be great if someone could run crater on this PR, as this has a high danger of breaking valid code~~ Crater ran. Good to go.

----

So this PR does a few things:

1. ~~const eval array values when const evaluating an array expression~~
2. ~~const eval repeat value when const evaluating a repeat expression~~
3. ~~const eval all struct and tuple fields when evaluating a struct/tuple expression~~
4. remove the `ConstVal::Int` and `ConstVal::Uint` variants and replace them with a single enum (`ConstInt`) which has variants for all integral types
  * `usize`/`isize` are also enums with variants for 32 and 64 bit. At creation and various usage steps there are assertions in place checking if the target bitwidth matches with the chosen enum variant
5. enum discriminants (`ty::Disr`) are now `ConstInt`
6. trans has its own `Disr` type now (newtype around `u64`)

This obviously can't be done without breaking changes (the ones that are noticable in stable)
We could probably write lints that find those situations and error on it for a cycle or two. But then again, those situations are rare and really bugs imo anyway:

```rust
let v10 = 10 as i8;
let v4 = 4 as isize;
assert_eq!(v10 << v4 as usize, 160 as i8);
 ```

stops compiling because 160 is not a valid i8

```rust
struct S<T, S> {
    a: T,
    b: u8,
    c: S
}
let s = S { a: 0xff_ff_ff_ffu32, b: 1, c: 0xaa_aa_aa_aa as i32 };
```

stops compiling because `0xaa_aa_aa_aa` is not a valid i32

----

cc @eddyb @pnkfelix

related: https://github.com/rust-lang/rfcs/issues/1071
2016-03-14 11:38:23 -07:00
bors
d19f1b6299 Auto merge of #32233 - Amanieu:volatile_store, r=eddyb
Fix LLVM assert with write_volatile

Fixes #29663
2016-03-14 08:32:45 -07:00
bors
af8f85cc39 Auto merge of #32232 - jonas-schievink:issue31511, r=eddyb
Give a more accurate error on thin-to-fat ptr cast

Fixes #31511
2016-03-14 05:44:24 -07:00
Oliver Schneider
f665c399a0 rustbuild 2016-03-14 09:29:18 +01:00
bors
170f4708bb Auto merge of #32231 - ruud-v-a:avx-cmp-blend, r=alexcrichton
Define AVX compare and blend intrinsics

This defines the following intrinsics:

 * `_mm256_blendv_pd`
 * `_mm256_blendv_ps`
 * `_mm256_cmp_pd`
 * `_mm256_cmp_ps`

I verified these locally.
2016-03-14 00:30:53 -07:00
bors
211296ddab Auto merge of #32226 - andoriyu:patch-2, r=alexcrichton
Fix. FreeBSD snapshot

Previous snapshot was complied with avx2 instructions by accident.

Actual file: http://people.freebsd.org/~davide/rust/rust-stage0-2016-02-17-4d3eebf-freebsd-x86_64-f38991fbb81c1cd8d0bbda396f98f13a55b42804.tar.bz2

/cc @alexcrichton @dcci
2016-03-13 18:46:59 -07:00
bors
74b886ab14 Auto merge of #32211 - achanda:ipv6-global, r=alexcrichton
Reject unspecified IP from global

Also fixed the test
2016-03-13 16:53:09 -07:00
Jonas Schievink
be2698cb58 Fix test fallout 2016-03-13 20:35:04 +01:00
bors
d5880fff99 Auto merge of #32227 - jseyfried:fix_import_resolution_bug, r=alexcrichton
Fix import resolution bug

This fixes #32222, which was introduced in #31726.
2016-03-13 12:24:42 -07:00
Amanieu d'Antras
86fd5a02e7 Fix LLVM assert with write_volatile 2016-03-13 19:01:35 +01:00
bors
ce943eb369 Auto merge of #32184 - ollie27:win_stdout, r=alexcrichton
Fixup stout/stderr on Windows

WriteConsoleW can fail if called with a large buffer so we need to slice
any stdout/stderr output.
However the current slicing has a few problems:
 1. It slices by byte but still expects valid UTF-8.
 2. The slicing happens even when not outputting to a console.
 3. panic! output is not sliced.

This fixes these issues by moving the slice to right before
WriteConsoleW and slicing on a char boundary.
2016-03-13 09:27:17 -07:00
Jonas Schievink
298b51e982 Give a more accurate error on thin-to-fat ptr cast
Fixes #31511
2016-03-13 17:03:31 +01:00
bors
1c8b245928 Auto merge of #32229 - Manishearth:rollup, r=Manishearth
Rollup of 4 pull requests

- Successful merges: #32164, #32179, #32212, #32218
- Failed merges:
2016-03-13 07:30:14 -07:00
Ruud van Asseldonk
a394d50490 Regenerate x86 platform intrinsics
The exact command used was:

    $ cd src/etc/platform-intrinsics/x86
    $ python2 ../generator.py --format compiler-defs -i info.json   \
      sse.json sse2.json sse3.json ssse3.json sse41.json sse42.json \
      avx.json avx2.json fma.json                                   \
      > ../../../librustc_platform_intrinsics/x86.rs
2016-03-13 15:09:46 +01:00