Skip to content

Let var hygiene #8103

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 67 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
df3dc14
disallow ident equality checks when contexts are not equal
jbclements Jul 10, 2013
d1cec3f
rename resolve to mtwt_resolve
jbclements Jul 9, 2013
5fa9fcb
ident->name
jbclements Jun 6, 2013
b3dfd26
compare macro tokens hygienically (commented out)
jbclements Jul 9, 2013
a2ede2d
try removing basically dead code in resolve
jbclements Jun 26, 2013
718dae8
add hygiene support fns, move them around.
jbclements Jun 25, 2013
7c7df2b
one-line comment
jbclements May 31, 2013
88fb3c0
update librustc to use name comparison in most cases, and mtwt_resolv…
jbclements Jun 26, 2013
d1d35c5
make ifn macro non-capturing
jbclements Jul 8, 2013
2638ecf
resolve test case
jbclements Jun 26, 2013
245f4c9
flip the switch on let renaming
jbclements Jun 6, 2013
5a9a3aa
renaming test cases
jbclements Jun 6, 2013
9c742a9
comments in ast.rs
jbclements Jun 6, 2013
64af970
removed unneccessary SyntaxExpander structs
jbclements May 28, 2013
cbd0674
separate ItemDecorator from ItemDecorator
jbclements May 28, 2013
1bf6981
refactor so tt_fold only requires an ident->ident fn
jbclements May 28, 2013
f33b706
adding test case to check marking/unmarking
jbclements Jun 25, 2013
085ef4a
comments only
jbclements May 29, 2013
785d6d7
remove FIXME #2888, now bug is fixed
jbclements Jun 7, 2013
5c4ba21
added FIXME comment
jbclements Jun 7, 2013
6ac5129
drop back to a simple gensym approach for fresh-name.
jbclements Jun 7, 2013
4bec5c5
comments
jbclements Jun 7, 2013
d062536
make comparison of special_idents non-hygienic
jbclements Jul 3, 2013
5d75868
use empty_ctxt to simplify downstream
jbclements Jun 7, 2013
ab72113
test case work
jbclements Jun 7, 2013
c819ed7
re-add debug version
jbclements Jun 7, 2013
37ef9b2
re-add lost call to expand_block_elts
jbclements Jun 7, 2013
e3c1cd1
test case work
jbclements Jun 7, 2013
2e8d6a7
test case support fns, remove debugging test case
jbclements Jul 9, 2013
7c9edf8
new test that uncovers bug in fold
jbclements Jun 8, 2013
e16e843
fixed bug in fold's traversal of cast exprs
jbclements Jun 8, 2013
bc603da
added test for ptr_eq on fresh_name-generated idents
jbclements Jun 25, 2013
2621899
added gensym_copy mechanism to ensure sharing of pointers in the inte…
jbclements Jun 26, 2013
bbe90c7
added IterBytes for 4-tuples
jbclements Jun 27, 2013
a3b918c
marking on both input and output from macros. nice shiny new test cas…
jbclements Jun 29, 2013
35d4c72
add test case for macro token comparison
jbclements Jul 9, 2013
a6d45e6
comments
jbclements Jul 3, 2013
5058ce7
add temporarily unused ctxt field to mac_invoc_tt
jbclements Jul 3, 2013
5b7a7f5
rework fold so that fold_tts takes an ast_fold rather than a thunk, s…
jbclements Jul 9, 2013
e1dc79a
WIP: adding context to macros
jbclements Jul 5, 2013
252a56f
add fold_mac field to fold.rs
jbclements Jul 5, 2013
87cc948
add fold_mac clause to fun_to_ctxt_folder
jbclements Jul 8, 2013
a2c97fa
capturing macros now implemented
jbclements Jul 8, 2013
03a1d76
comments
jbclements Jul 9, 2013
9d1f421
remove dead code
jbclements Jul 9, 2013
99507d4
fix one remaining token comparison, refactor token comparison to avoi…
jbclements Jul 10, 2013
e5ac12a
added utility function
jbclements Jul 10, 2013
d47303c
ident->name in NamedField, elsewhere
jbclements Jul 10, 2013
4efcfe5
uncomment mtwt_resolve calls
jbclements Jul 11, 2013
d2ff2a6
memoization for resolve
jbclements Jul 10, 2013
ae3bb6a
whitespace, reindentation, and comments only
jbclements Jul 12, 2013
b97b2b5
remove unneeded imports, clean up unused var warnings
jbclements Jul 12, 2013
34b1f85
ident->name
jbclements Jul 12, 2013
cc17a51
xfailed unhygienic test
jbclements Jul 12, 2013
b0c4676
ident->name
jbclements Jul 12, 2013
679d247
expose mtwt_marksof for testing
jbclements Jul 13, 2013
93d97c5
awesome new bug! added test case
jbclements Jul 13, 2013
f2ba71a
comment on hygienic context extension train fns
jbclements Jul 13, 2013
b0a9101
comments
jbclements Jul 14, 2013
6a29010
added string_to_tts
jbclements Jul 14, 2013
8b32e8f
WIP: adding mark-cancelling for macro_rules
jbclements Jul 14, 2013
0e05c12
fixed a bug that caused double-expand-traversal of macros that expand…
jbclements Jul 26, 2013
362b375
add display_sctable fn to ast_util
jbclements Jul 26, 2013
d950fd8
add test case, cleanup
jbclements Jul 26, 2013
67a3c1b
make macro hygienic
jbclements Jul 26, 2013
5196e85
add hygiene test, add copyright to another
jbclements Jul 26, 2013
348327d
comment fix
jbclements Jul 28, 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
Prev Previous commit
Next Next commit
whitespace, reindentation, and comments only
  • Loading branch information
jbclements authored and graydon committed Jul 31, 2013
commit ae3bb6a1e508dffe6ea588318c20c065c34f2ae9
3 changes: 2 additions & 1 deletion src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2760,7 +2760,8 @@ pub fn declare_intrinsics(llmod: ModuleRef) -> HashMap<&'static str, ValueRef> {

pub fn declare_dbg_intrinsics(llmod: ModuleRef, intrinsics: &mut HashMap<&'static str, ValueRef>) {
ifn!(intrinsics, "llvm.dbg.declare", [Type::metadata(), Type::metadata()], Type::void());
ifn!(intrinsics, "llvm.dbg.value", [Type::metadata(), Type::i64(), Type::metadata()], Type::void());
ifn!(intrinsics,
"llvm.dbg.value", [Type::metadata(), Type::i64(), Type::metadata()], Type::void());
}

pub fn trap(bcx: @mut Block) {
Expand Down
5 changes: 3 additions & 2 deletions src/librustc/middle/trans/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1139,8 +1139,9 @@ fn trans_rec_or_struct(bcx: @mut Block,
let mut need_base = vec::from_elem(field_tys.len(), true);

let numbered_fields = do fields.map |field| {
let opt_pos = field_tys.iter().position(|field_ty|
field_ty.ident.name == field.ident.name);
let opt_pos =
field_tys.iter().position(|field_ty|
field_ty.ident.name == field.ident.name);
match opt_pos {
Some(i) => {
need_base[i] = false;
Expand Down
8 changes: 7 additions & 1 deletion src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ impl Eq for ident {
if (self.ctxt == other.ctxt) {
self.name == other.name
} else {
// IF YOU SEE ONE OF THESE FAILS: it means that you're comparing
// idents that have different contexts. You can't fix this without
// knowing whether the comparison should be hygienic or non-hygienic.
// if it should be non-hygienic (most things are), just compare the
// 'name' fields of the idents. Or, even better, replace the idents
// with Name's.
fail!(fmt!("not allowed to compare these idents: %?, %?", self, other));
}
}
Expand Down Expand Up @@ -114,6 +120,7 @@ pub type fn_ident = Option<ident>;
pub struct Lifetime {
id: NodeId,
span: span,
// FIXME #7743 : change this to Name!
ident: ident
}

Expand Down Expand Up @@ -623,7 +630,6 @@ pub enum matcher_ {
// lo, hi position-in-match-array used:
match_seq(~[matcher], Option<::parse::token::Token>, bool, uint, uint),
// parse a Rust NT: name to bind, name of NT, position in match array:
// NOTE: 'name of NT' shouldnt really be represented as an ident, should it?
match_nonterminal(ident, ident, uint)
}

Expand Down
13 changes: 8 additions & 5 deletions src/libsyntax/ast_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -758,11 +758,14 @@ pub fn resolve_internal(id : ident,
match table.table[id.ctxt] {
EmptyCtxt => id.name,
// ignore marks here:
Mark(_,subctxt) => resolve_internal(ident{name:id.name, ctxt: subctxt},table,resolve_table),
Mark(_,subctxt) =>
resolve_internal(ident{name:id.name, ctxt: subctxt},table,resolve_table),
// do the rename if necessary:
Rename(ident{name,ctxt},toname,subctxt) => {
let resolvedfrom = resolve_internal(ident{name:name,ctxt:ctxt},table,resolve_table);
let resolvedthis = resolve_internal(ident{name:id.name,ctxt:subctxt},table,resolve_table);
let resolvedfrom =
resolve_internal(ident{name:name,ctxt:ctxt},table,resolve_table);
let resolvedthis =
resolve_internal(ident{name:id.name,ctxt:subctxt},table,resolve_table);
if ((resolvedthis == resolvedfrom)
&& (marksof(ctxt,resolvedthis,table)
== marksof(subctxt,resolvedthis,table))) {
Expand Down Expand Up @@ -834,9 +837,9 @@ pub fn getLast(arr: &~[Mrk]) -> uint {
pub fn path_name_eq(a : &ast::Path, b : &ast::Path) -> bool {
(a.span == b.span)
&& (a.global == b.global)
// NOTE: ident->name in lifetimes!
// FIXME #7743: ident->name in lifetimes!
&& (a.rp == b.rp)
// NOTE: can a type contain an ident?
// can types contain idents?
&& (a.types == b.types)
&& (idents_name_eq(a.idents, b.idents))
}
Expand Down
43 changes: 24 additions & 19 deletions src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,20 @@ pub fn expand_expr(extsbox: @mut SyntaxEnv,
// mark before:
let marked_before = mark_tts(*tts,fm);
let marked_ctxt = new_mark(fm, ctxt);
let expanded = match expandfun(cx, mac.span, marked_before, marked_ctxt) {
MRExpr(e) => e,
MRAny(expr_maker,_,_) => expr_maker(),
_ => {
cx.span_fatal(
pth.span,
fmt!(
"non-expr macro in expr pos: %s",
extnamestr
let expanded =
match expandfun(cx, mac.span, marked_before, marked_ctxt) {
MRExpr(e) => e,
MRAny(expr_maker,_,_) => expr_maker(),
_ => {
cx.span_fatal(
pth.span,
fmt!(
"non-expr macro in expr pos: %s",
extnamestr
)
)
)
}
};
}
};
// mark after:
let marked_after = mark_expr(expanded,fm);

Expand Down Expand Up @@ -1166,7 +1167,8 @@ mod test {
use print::pprust;
use std;
use std::vec;
use util::parser_testing::{string_to_crate, string_to_crate_and_sess, string_to_item, string_to_pat, strs_to_idents};
use util::parser_testing::{string_to_crate, string_to_crate_and_sess, string_to_item}
use util::parser_testing::{string_to_pat, strs_to_idents};
use visit::{mk_vt};
use visit;

Expand Down Expand Up @@ -1362,12 +1364,14 @@ mod test {
~[~[0]])
// FIXME #6994: the next string exposes the bug referred to in issue 6994, so I'm
// commenting it out.
// the z flows into and out of two macros (g & f) along one path, and one (just g) along the
// other, so the result of the whole thing should be "let z_123 = 3; z_123"
//"macro_rules! g (($x:ident) => ({macro_rules! f(($y:ident)=>({let $y=3;$x}));f!($x)}))
// the z flows into and out of two macros (g & f) along one path, and one
// (just g) along the other, so the result of the whole thing should
// be "let z_123 = 3; z_123"
//"macro_rules! g (($x:ident) =>
// ({macro_rules! f(($y:ident)=>({let $y=3;$x}));f!($x)}))
// fn a(){g!(z)}"
// create a really evil test case where a $x appears inside a binding of $x but *shouldnt*
// bind because it was inserted by a different macro....
// create a really evil test case where a $x appears inside a binding of $x
// but *shouldnt* bind because it was inserted by a different macro....
];
for tests.iter().advance |s| {
run_renaming_test(s);
Expand Down Expand Up @@ -1449,7 +1453,8 @@ mod test {
// find the ext_cx binding
let bindings = @mut ~[];
visit::visit_crate(crate, (bindings, mk_vt(nv)));
let cxbinds : ~[&ast::ident] = bindings.iter().filter(|b|{@"ext_cx" == (ident_to_str(*b))}).collect();
let cxbinds : ~[&ast::ident] =
bindings.iter().filter(|b|{@"ext_cx" == (ident_to_str(*b))}).collect();
let cxbind = match cxbinds {
[b] => b,
_ => fail!("expected just one binding for ext_cx")
Expand Down
1 change: 0 additions & 1 deletion src/libsyntax/ext/tt/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ pub fn add_new_extension(cx: @ExtCtxt,
// ...quasiquoting this would be nice.
let argument_gram = ~[
ms(match_seq(~[
// NOTE : probably just use an enum for the NT_name ?
ms(match_nonterminal(lhs_nm, special_idents::matchers, 0u)),
ms(match_tok(FAT_ARROW)),
ms(match_nonterminal(rhs_nm, special_idents::tt, 1u)),
Expand Down