Skip to content

Commit dead37d

Browse files
committed
---
yaml --- r: 92851 b: refs/heads/auto c: e0a6910 h: refs/heads/master i: 92849: bb441ab 92847: a163c21 v: v3
1 parent a48b61a commit dead37d

File tree

41 files changed

+503
-497
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+503
-497
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1313
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1414
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1515
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
16-
refs/heads/auto: 1502b1197b78624aad5180fa8eff3f77f6f0abfc
16+
refs/heads/auto: e0a6910f7092ffff33331a08f2fafb55eed46835
1717
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1818
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1919
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/.gitignore

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,6 @@ src/.DS_Store
7575
/doc/latex
7676
/doc/std
7777
/doc/extra
78-
/doc/green
79-
/doc/native
80-
/doc/rustc
81-
/doc/syntax
8278
/nd/
8379
/llvm/
8480
version.md

branches/auto/doc/rust.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -610,12 +610,12 @@ the behavior of the compiler.
610610

611611
~~~~
612612
// Package ID
613-
#[ crate_id = "projx#2.5" ];
613+
#[ pkgid = "projx#2.5" ];
614614
615615
// Additional metadata attributes
616616
#[ desc = "Project X" ];
617617
#[ license = "BSD" ];
618-
#[ comment = "This is a comment on Project X." ];
618+
#[ author = "Jane Doe" ];
619619
620620
// Specify the output type
621621
#[ crate_type = "lib" ];
@@ -776,9 +776,9 @@ as the `ident` provided in the `extern_mod_decl`.
776776
The external crate is resolved to a specific `soname` at compile time, and a
777777
runtime linkage requirement to that `soname` is passed to the linker for
778778
loading at runtime. The `soname` is resolved at compile time by scanning the
779-
compiler's library path and matching the optional `crateid` provided as a string literal
780-
against the `crateid` attributes that were declared on the external crate when
781-
it was compiled. If no `crateid` is provided, a default `name` attribute is
779+
compiler's library path and matching the optional `pkgid` provided as a string literal
780+
against the `pkgid` attributes that were declared on the external crate when
781+
it was compiled. If no `pkgid` is provided, a default `name` attribute is
782782
assumed, equal to the `ident` given in the `extern_mod_decl`.
783783

784784
Four examples of `extern mod` declarations:
@@ -1729,7 +1729,7 @@ names are effectively reserved. Some significant attributes include:
17291729
* The `cfg` attribute, for conditional-compilation by build-configuration.
17301730
* The `lang` attribute, for custom definitions of traits and functions that are known to the Rust compiler (see [Language items](#language-items)).
17311731
* The `link` attribute, for describing linkage metadata for a extern blocks.
1732-
* The `crate_id` attribute, for describing the package ID of a crate.
1732+
* The `pkgid` attribute, for describing the package ID of a crate.
17331733
* The `test` attribute, for marking functions as unit tests.
17341734
* The `allow`, `warn`, `forbid`, and `deny` attributes, for
17351735
controlling lint checks (see [Lint check attributes](#lint-check-attributes)).
@@ -3792,7 +3792,7 @@ specified then log level 4 is assumed. Debug messages can be omitted
37923792
by passing `--cfg ndebug` to `rustc`.
37933793

37943794
As an example, to see all the logs generated by the compiler, you would set
3795-
`RUST_LOG` to `rustc`, which is the crate name (as specified in its `crate_id`
3795+
`RUST_LOG` to `rustc`, which is the crate name (as specified in its `pkgid`
37963796
[attribute](#attributes)). To narrow down the logs to just crate resolution,
37973797
you would set it to `rustc::metadata::creader`. To see just error logging
37983798
use `rustc=0`.

branches/auto/doc/rustdoc.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ comments":
1313
~~~
1414
// the "link" crate attribute is currently required for rustdoc, but normally
1515
// isn't needed.
16-
#[crate_id = "universe"];
16+
#[pkgid = "universe"];
1717
#[crate_type="lib"];
1818
1919
//! Tools for dealing with universes (this is a doc comment, and is shown on
@@ -132,10 +132,9 @@ specifiers that can be used to dictate how a code block is tested:
132132
~~~
133133

134134
Rustdoc also supplies some extra sugar for helping with some tedious
135-
documentation examples. If a line is prefixed with `# `, then the line
136-
will not show up in the HTML documentation, but it will be used when
137-
testing the code block (NB. the space after the `#` is required, so
138-
that one can still write things like `#[deriving(Eq)]`).
135+
documentation examples. If a line is prefixed with a `#` character, then the
136+
line will not show up in the HTML documentation, but it will be used when
137+
testing the code block.
139138

140139
~~~
141140
```rust

branches/auto/doc/rustpkg.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ then both `bar` and `bar/extras/baz` are valid package identifiers
9090
in the workspace `foo`.
9191

9292
Because rustpkg uses generic source file names as the main inputs, you will
93-
need to specify the package identifier in them using the `crate_id` attribute
93+
need to specify the package identifier in them using the `pkgid` attribute
9494
on the crate.
9595

9696
## Source files

branches/auto/src/etc/combine-tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def scrub(b):
4545
"""
4646
// AUTO-GENERATED FILE: DO NOT EDIT
4747
#[crate_id=\"run_pass_stage2#0.1\"];
48-
#[crate_id=\"run_pass_stage2#0.1\"];
48+
#[pkgid=\"run_pass_stage2#0.1\"];
4949
#[feature(globs, macro_rules, struct_variant, managed_boxes)];
5050
#[allow(warnings)];
5151
"""

branches/auto/src/libextra/num/rational.rs

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use std::cmp;
1515
use std::from_str::FromStr;
1616
use std::num::{Zero,One,ToStrRadix,FromStrRadix,Round};
17-
use super::bigint::BigInt;
17+
use super::bigint::{BigInt, BigUint, Sign, Plus, Minus};
1818

1919
/// Represents the ratio between 2 numbers.
2020
#[deriving(Clone)]
@@ -107,6 +107,27 @@ impl<T: Clone + Integer + Ord>
107107
}
108108
}
109109

110+
impl Ratio<BigInt> {
111+
/// Converts a float into a rational number
112+
pub fn from_float<T: Float>(f: T) -> Option<BigRational> {
113+
if !f.is_finite() {
114+
return None;
115+
}
116+
let (mantissa, exponent, sign) = f.integer_decode();
117+
let bigint_sign: Sign = if sign == 1 { Plus } else { Minus };
118+
if exponent < 0 {
119+
let one: BigInt = One::one();
120+
let denom: BigInt = one << ((-exponent) as uint);
121+
let numer: BigUint = FromPrimitive::from_u64(mantissa).unwrap();
122+
Some(Ratio::new(BigInt::from_biguint(bigint_sign, numer), denom))
123+
} else {
124+
let mut numer: BigUint = FromPrimitive::from_u64(mantissa).unwrap();
125+
numer = numer << (exponent as uint);
126+
Some(Ratio::from_integer(BigInt::from_biguint(bigint_sign, numer)))
127+
}
128+
}
129+
}
130+
110131
/* Comparisons */
111132

112133
// comparing a/b and c/d is the same as comparing a*d and b*c, so we
@@ -621,4 +642,42 @@ mod test {
621642
test(s);
622643
}
623644
}
645+
646+
#[test]
647+
fn test_from_float() {
648+
fn test<T: Float>(given: T, (numer, denom): (&str, &str)) {
649+
let ratio: BigRational = Ratio::from_float(given).unwrap();
650+
assert_eq!(ratio, Ratio::new(
651+
FromStr::from_str(numer).unwrap(),
652+
FromStr::from_str(denom).unwrap()));
653+
}
654+
655+
// f32
656+
test(3.14159265359f32, ("13176795", "4194304"));
657+
test(2f32.pow(&100.), ("1267650600228229401496703205376", "1"));
658+
test(-2f32.pow(&100.), ("-1267650600228229401496703205376", "1"));
659+
test(1.0 / 2f32.pow(&100.), ("1", "1267650600228229401496703205376"));
660+
test(684729.48391f32, ("1369459", "2"));
661+
test(-8573.5918555f32, ("-4389679", "512"));
662+
663+
// f64
664+
test(3.14159265359f64, ("3537118876014453", "1125899906842624"));
665+
test(2f64.pow(&100.), ("1267650600228229401496703205376", "1"));
666+
test(-2f64.pow(&100.), ("-1267650600228229401496703205376", "1"));
667+
test(684729.48391f64, ("367611342500051", "536870912"));
668+
test(-8573.5918555, ("-4713381968463931", "549755813888"));
669+
test(1.0 / 2f64.pow(&100.), ("1", "1267650600228229401496703205376"));
670+
}
671+
672+
#[test]
673+
fn test_from_float_fail() {
674+
use std::{f32, f64};
675+
676+
assert_eq!(Ratio::from_float(f32::NAN), None);
677+
assert_eq!(Ratio::from_float(f32::INFINITY), None);
678+
assert_eq!(Ratio::from_float(f32::NEG_INFINITY), None);
679+
assert_eq!(Ratio::from_float(f64::NAN), None);
680+
assert_eq!(Ratio::from_float(f64::INFINITY), None);
681+
assert_eq!(Ratio::from_float(f64::NEG_INFINITY), None);
682+
}
624683
}

branches/auto/src/librustc/back/link.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use syntax::ast;
4141
use syntax::ast_map::{path, path_mod, path_name, path_pretty_name};
4242
use syntax::attr;
4343
use syntax::attr::AttrMetaMethods;
44-
use syntax::crateid::CrateId;
44+
use syntax::pkgid::PkgId;
4545

4646
#[deriving(Clone, Eq)]
4747
pub enum output_type {
@@ -444,13 +444,13 @@ pub mod write {
444444
*
445445
* So here is what we do:
446446
*
447-
* - Consider the package id; every crate has one (specified with crate_id
447+
* - Consider the package id; every crate has one (specified with pkgid
448448
* attribute). If a package id isn't provided explicitly, we infer a
449449
* versionless one from the output name. The version will end up being 0.0
450450
* in this case. CNAME and CVERS are taken from this package id. For
451451
* example, github.com/mozilla/CNAME#CVERS.
452452
*
453-
* - Define CMH as SHA256(crateid).
453+
* - Define CMH as SHA256(pkgid).
454454
*
455455
* - Define CMH8 as the first 8 characters of CMH.
456456
*
@@ -469,13 +469,13 @@ pub fn build_link_meta(sess: Session,
469469
symbol_hasher: &mut Sha256)
470470
-> LinkMeta {
471471
// This calculates CMH as defined above
472-
fn crate_hash(symbol_hasher: &mut Sha256, crateid: &CrateId) -> @str {
472+
fn crate_hash(symbol_hasher: &mut Sha256, pkgid: &PkgId) -> @str {
473473
symbol_hasher.reset();
474-
symbol_hasher.input_str(crateid.to_str());
474+
symbol_hasher.input_str(pkgid.to_str());
475475
truncated_hash_result(symbol_hasher).to_managed()
476476
}
477477

478-
let crateid = match attr::find_crateid(attrs) {
478+
let pkgid = match attr::find_pkgid(attrs) {
479479
None => {
480480
let stem = session::expect(
481481
sess,
@@ -487,10 +487,10 @@ pub fn build_link_meta(sess: Session,
487487
Some(s) => s,
488488
};
489489

490-
let hash = crate_hash(symbol_hasher, &crateid);
490+
let hash = crate_hash(symbol_hasher, &pkgid);
491491

492492
LinkMeta {
493-
crateid: crateid,
493+
pkgid: pkgid,
494494
crate_hash: hash,
495495
}
496496
}
@@ -509,7 +509,7 @@ pub fn symbol_hash(tcx: ty::ctxt,
509509
// to be independent of one another in the crate.
510510

511511
symbol_hasher.reset();
512-
symbol_hasher.input_str(link_meta.crateid.name);
512+
symbol_hasher.input_str(link_meta.pkgid.name);
513513
symbol_hasher.input_str("-");
514514
symbol_hasher.input_str(link_meta.crate_hash);
515515
symbol_hasher.input_str("-");
@@ -669,7 +669,7 @@ pub fn mangle_exported_name(ccx: &CrateContext,
669669
let hash = get_symbol_hash(ccx, t);
670670
return exported_name(ccx.sess, path,
671671
hash,
672-
ccx.link_meta.crateid.version_or_default());
672+
ccx.link_meta.pkgid.version_or_default());
673673
}
674674

675675
pub fn mangle_internal_name_by_type_only(ccx: &CrateContext,
@@ -710,9 +710,9 @@ pub fn mangle_internal_name_by_path(ccx: &CrateContext, path: path) -> ~str {
710710

711711
pub fn output_lib_filename(lm: &LinkMeta) -> ~str {
712712
format!("{}-{}-{}",
713-
lm.crateid.name,
713+
lm.pkgid.name,
714714
lm.crate_hash.slice_chars(0, 8),
715-
lm.crateid.version_or_default())
715+
lm.pkgid.version_or_default())
716716
}
717717

718718
pub fn get_cc_prog(sess: Session) -> ~str {

branches/auto/src/librustc/driver/driver.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,12 +1030,12 @@ pub fn build_output_filenames(input: &input,
10301030
str_input(_) => @"rust_out"
10311031
};
10321032

1033-
// If a crateid is present, we use it as the link name
1034-
let crateid = attr::find_crateid(attrs);
1035-
match crateid {
1033+
// If a pkgid is present, we use it as the link name
1034+
let pkgid = attr::find_pkgid(attrs);
1035+
match pkgid {
10361036
None => {}
1037-
Some(crateid) => {
1038-
stem = crateid.name.to_managed()
1037+
Some(pkgid) => {
1038+
stem = pkgid.name.to_managed()
10391039
}
10401040
}
10411041

branches/auto/src/librustc/front/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ fn mk_tests(cx: &TestCtxt) -> @ast::item {
384384
}
385385

386386
fn is_extra(crate: &ast::Crate) -> bool {
387-
match attr::find_crateid(crate.attrs) {
387+
match attr::find_pkgid(crate.attrs) {
388388
Some(ref s) if "extra" == s.name => true,
389389
_ => false
390390
}

branches/auto/src/librustc/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,18 +292,18 @@ pub fn run_compiler(args: &[~str], demitter: @diagnostic::Emitter) {
292292
let t_outputs = d::build_output_filenames(&input, &odir, &ofile,
293293
attrs, sess);
294294
if crate_id || crate_name {
295-
let crateid = match attr::find_crateid(attrs) {
296-
Some(crateid) => crateid,
295+
let pkgid = match attr::find_pkgid(attrs) {
296+
Some(pkgid) => pkgid,
297297
None => {
298298
sess.fatal("No crate_id and --crate-id or \
299299
--crate-name requested")
300300
}
301301
};
302302
if crate_id {
303-
println(crateid.to_str());
303+
println(pkgid.to_str());
304304
}
305305
if crate_name {
306-
println(crateid.name);
306+
println(pkgid.name);
307307
}
308308
}
309309

branches/auto/src/librustc/metadata/common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
use std::cast;
12-
use syntax::crateid::CrateId;
12+
use syntax::pkgid::PkgId;
1313

1414
// EBML enum definitions and utils shared by the encoder and decoder
1515

@@ -206,6 +206,6 @@ pub static tag_native_libraries_kind: uint = 0x106;
206206

207207
#[deriving(Clone)]
208208
pub struct LinkMeta {
209-
crateid: CrateId,
209+
pkgid: PkgId,
210210
crate_hash: @str,
211211
}

0 commit comments

Comments
 (0)