Skip to content

Let var hygiene #9026

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 72 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
6e3b2ab
move and duplicate macro defns in sha2 to make them hygienic
jbclements Sep 5, 2013
77c96d7
disallow ident equality checks when contexts are not equal
jbclements Jul 10, 2013
acad9f3
commenting out special Eq implementation for now
jbclements Sep 6, 2013
e1734f6
rename resolve to mtwt_resolve
jbclements Jul 9, 2013
9ec1623
ident->name
jbclements Jun 6, 2013
72ee6af
compare macro tokens hygienically (commented out)
jbclements Sep 5, 2013
7fd5bdc
try removing basically dead code in resolve
jbclements Jun 26, 2013
fa6c981
add hygiene support fns, move them around.
jbclements Jun 25, 2013
71e72ee
one-line comment
jbclements May 31, 2013
39ca2db
update librustc to use name comparison in most cases, and mtwt_resolv…
jbclements Jun 26, 2013
7668fb2
make ifn macro non-capturing
jbclements Jul 8, 2013
fb82283
resolve test case
jbclements Jun 26, 2013
2f6498f
flip the switch on let renaming
jbclements Jun 6, 2013
6c6d053
renaming test cases
jbclements Jun 6, 2013
d8276e7
comments in ast.rs
jbclements Jun 6, 2013
431ede4
removed unneccessary SyntaxExpander structs
jbclements May 28, 2013
93337f0
separate ItemDecorator from ItemDecorator
jbclements May 28, 2013
b7c0512
refactor so tt_fold only requires an ident->ident fn
jbclements May 28, 2013
91d3c36
adding test case to check marking/unmarking
jbclements Jun 25, 2013
98a6cbd
comments only
jbclements May 29, 2013
9de40df
remove FIXME #2888, now bug is fixed
jbclements Jun 7, 2013
7bf75ad
added FIXME comment
jbclements Jun 7, 2013
d1c0173
drop back to a simple gensym approach for fresh-name.
jbclements Jun 7, 2013
3965725
comments
jbclements Jun 7, 2013
a666ddc
make comparison of special_idents non-hygienic
jbclements Jul 3, 2013
f5ab867
use empty_ctxt to simplify downstream
jbclements Jun 7, 2013
7a9af09
test case work
jbclements Jun 7, 2013
9071ac6
re-add debug version
jbclements Jun 7, 2013
1f8e856
re-add lost call to expand_block_elts
jbclements Jun 7, 2013
62fee04
test case work
jbclements Jun 7, 2013
015ba31
test case support fns, remove debugging test case
jbclements Jul 9, 2013
d876a72
new test that uncovers bug in fold
jbclements Jun 8, 2013
cd4e637
fixed bug in fold's traversal of cast exprs
jbclements Jun 8, 2013
9d33001
added test for ptr_eq on fresh_name-generated idents
jbclements Jun 25, 2013
58e7598
added gensym_copy mechanism to ensure sharing of pointers in the inte…
jbclements Jun 26, 2013
f68aa45
added IterBytes for 4-tuples
jbclements Jun 27, 2013
963dab5
marking on both input and output from macros. nice shiny new test cas…
jbclements Jun 29, 2013
0c31c93
add test case for macro token comparison
jbclements Jul 9, 2013
3621c67
comments
jbclements Jul 3, 2013
09e6dda
add temporarily unused ctxt field to mac_invoc_tt
jbclements Jul 3, 2013
34f31e2
rework fold so that fold_tts takes an ast_fold rather than a thunk, s…
jbclements Jul 9, 2013
3261b6e
WIP: adding context to macros
jbclements Jul 5, 2013
dfa04ce
add fold_mac field to fold.rs
jbclements Jul 5, 2013
2c51e26
add fold_mac clause to fun_to_ctxt_folder
jbclements Jul 8, 2013
b9bb4ab
capturing macros now implemented
jbclements Jul 8, 2013
e29d253
remove dead code
jbclements Jul 9, 2013
bc2a44d
fix one remaining token comparison, refactor token comparison to avoi…
jbclements Jul 10, 2013
9ab2cfd
added utility function
jbclements Jul 10, 2013
d9ba61c
ident->name in NamedField, elsewhere
jbclements Jul 10, 2013
0954e66
uncomment mtwt_resolve calls
jbclements Sep 5, 2013
ec0a64d
memoization for resolve
jbclements Jul 10, 2013
60562ac
whitespace, reindentation, and comments only
jbclements Jul 12, 2013
dbf4e19
remove unneeded imports, clean up unused var warnings
jbclements Jul 12, 2013
76c1e04
ident->name
jbclements Jul 12, 2013
bba10ec
xfailed unhygienic test
jbclements Jul 12, 2013
7dca301
ident->name
jbclements Jul 12, 2013
7b548e7
expose mtwt_marksof for testing
jbclements Jul 13, 2013
dc7f3df
awesome new bug! added test case
jbclements Jul 13, 2013
1a06584
comment on hygienic context extension train fns
jbclements Jul 13, 2013
985a92e
comments
jbclements Jul 14, 2013
e681e78
added string_to_tts
jbclements Jul 14, 2013
fddc815
WIP: adding mark-cancelling for macro_rules
jbclements Jul 14, 2013
8330411
fixed a bug that caused double-expand-traversal of macros that expand…
jbclements Jul 26, 2013
fe1d21c
add display_sctable fn to ast_util
jbclements Jul 26, 2013
6c294ba
add test case, cleanup
jbclements Sep 5, 2013
d8c77e0
make macro hygienic
jbclements Jul 26, 2013
114b1a7
add hygiene test, add copyright to another
jbclements Jul 26, 2013
4664d33
comment fix
jbclements Jul 28, 2013
1ecc1e5
quote_* macros no longer need to be capturing
jbclements Sep 5, 2013
eabeba3
added index to test cases, more debugging output
jbclements Sep 5, 2013
956129c
ident->name
jbclements Sep 5, 2013
b6f3d3f
ident->name in debuginfo
jbclements Sep 7, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 40 additions & 22 deletions src/libextra/crypto/sha2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,8 @@ use cryptoutil::{write_u64_be, write_u32_be, read_u64v_be, read_u32v_be, add_byt
add_bytes_to_bits_tuple, FixedBuffer, FixedBuffer128, FixedBuffer64, StandardPadding};
use digest::Digest;


// Sha-512 and Sha-256 use basically the same calculations which are implemented by these macros.
// Inlining the calculations seems to result in better generated code.
macro_rules! schedule_round( ($t:expr) => (
W[$t] = sigma1(W[$t - 2]) + W[$t - 7] + sigma0(W[$t - 15]) + W[$t - 16];
)
)

macro_rules! sha2_round(
($A:ident, $B:ident, $C:ident, $D:ident,
$E:ident, $F:ident, $G:ident, $H:ident, $K:ident, $t:expr) => (
{
$H += sum1($E) + ch($E, $F, $G) + $K[$t] + W[$t];
$D += $H;
$H += sum0($A) + maj($A, $B, $C);
}
)
)


// A structure that represents that state of a digest computation for the SHA-2 512 family of digest
// functions
// A structure that represents that state of a digest computation for the SHA-2 512 family
// of digest functions
struct Engine512State {
H0: u64,
H1: u64,
Expand Down Expand Up @@ -108,6 +88,25 @@ impl Engine512State {

let mut W = [0u64, ..80];

// Sha-512 and Sha-256 use basically the same calculations which are implemented by
// these macros. Inlining the calculations seems to result in better generated code.
macro_rules! schedule_round( ($t:expr) => (
W[$t] = sigma1(W[$t - 2]) + W[$t - 7] + sigma0(W[$t - 15]) + W[$t - 16];
)
)

macro_rules! sha2_round(
($A:ident, $B:ident, $C:ident, $D:ident,
$E:ident, $F:ident, $G:ident, $H:ident, $K:ident, $t:expr) => (
{
$H += sum1($E) + ch($E, $F, $G) + $K[$t] + W[$t];
$D += $H;
$H += sum0($A) + maj($A, $B, $C);
}
)
)


read_u64v_be(W.mut_slice(0, 16), data);

// Putting the message schedule inside the same loop as the round calculations allows for
Expand Down Expand Up @@ -505,6 +504,25 @@ impl Engine256State {

let mut W = [0u32, ..64];

// Sha-512 and Sha-256 use basically the same calculations which are implemented
// by these macros. Inlining the calculations seems to result in better generated code.
macro_rules! schedule_round( ($t:expr) => (
W[$t] = sigma1(W[$t - 2]) + W[$t - 7] + sigma0(W[$t - 15]) + W[$t - 16];
)
)

macro_rules! sha2_round(
($A:ident, $B:ident, $C:ident, $D:ident,
$E:ident, $F:ident, $G:ident, $H:ident, $K:ident, $t:expr) => (
{
$H += sum1($E) + ch($E, $F, $G) + $K[$t] + W[$t];
$D += $H;
$H += sum0($A) + maj($A, $B, $C);
}
)
)


read_u32v_be(W.mut_slice(0, 16), data);

// Putting the message schedule inside the same loop as the round calculations allows for
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/borrowck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ impl BorrowckCtxt {
match fname {
mc::NamedField(ref fname) => {
out.push_char('.');
out.push_str(token::ident_to_str(fname));
out.push_str(token::interner_get(*fname));
}
mc::PositionalField(idx) => {
out.push_char('#'); // invent a notation here
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub fn find_entry_point(session: Session, crate: &Crate, ast_map: ast_map::map)
fn find_item(item: @item, ctxt: @mut EntryContext, visitor: &mut EntryVisitor) {
match item.node {
item_fn(*) => {
if item.ident == special_idents::main {
if item.ident.name == special_idents::main.name {
match ctxt.ast_map.find(&item.id) {
Some(&ast_map::node_item(_, path)) => {
if path.len() == 0 {
Expand Down
9 changes: 5 additions & 4 deletions src/librustc/middle/mem_categorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ use syntax::ast::{MutImmutable, MutMutable};
use syntax::ast;
use syntax::codemap::Span;
use syntax::print::pprust;
use syntax::parse::token;

#[deriving(Eq)]
pub enum categorization {
Expand Down Expand Up @@ -99,7 +100,7 @@ pub enum InteriorKind {

#[deriving(Eq, IterBytes)]
pub enum FieldName {
NamedField(ast::Ident),
NamedField(ast::Name),
PositionalField(uint)
}

Expand Down Expand Up @@ -619,7 +620,7 @@ impl mem_categorization_ctxt {
@cmt_ {
id: node.id(),
span: node.span(),
cat: cat_interior(base_cmt, InteriorField(NamedField(f_name))),
cat: cat_interior(base_cmt, InteriorField(NamedField(f_name.name))),
mutbl: base_cmt.mutbl.inherit(),
ty: f_ty
}
Expand Down Expand Up @@ -1224,9 +1225,9 @@ pub fn ptr_sigil(ptr: PointerKind) -> ~str {
}

impl Repr for InteriorKind {
fn repr(&self, tcx: ty::ctxt) -> ~str {
fn repr(&self, _tcx: ty::ctxt) -> ~str {
match *self {
InteriorField(NamedField(fld)) => tcx.sess.str_of(fld).to_owned(),
InteriorField(NamedField(fld)) => token::interner_get(fld).to_owned(),
InteriorField(PositionalField(i)) => fmt!("#%?", i),
InteriorElement(_) => ~"[]",
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/moves.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ impl VisitContext {
// specified and (2) have a type that
// moves-by-default:
let consume_with = with_fields.iter().any(|tf| {
!fields.iter().any(|f| f.ident == tf.ident) &&
!fields.iter().any(|f| f.ident.name == tf.ident.name) &&
ty::type_moves_by_default(self.tcx, tf.mt.ty)
});

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/privacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ impl PrivacyVisitor {
fn check_field(&mut self, span: Span, id: ast::DefId, ident: ast::Ident) {
let fields = ty::lookup_struct_fields(self.tcx, id);
for field in fields.iter() {
if field.ident != ident { loop; }
if field.ident.name != ident.name { loop; }
if field.vis == private {
self.tcx.sess.span_err(span, fmt!("field `%s` is private",
token::ident_to_str(&ident)));
Expand Down
Loading