Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c22ba27
Stop emulating cross-crate hygiene with gensyms
matthewjasper Aug 11, 2019
f3a589a
Make built-in derives opaque macros
matthewjasper Aug 9, 2019
dd9a5b8
Make fmt-internal functions private
matthewjasper Aug 11, 2019
ade2c8f
Remove gensyms from built-in derives
matthewjasper Aug 11, 2019
1b0b505
Move type parameter shadowing errors to resolve
matthewjasper Aug 11, 2019
6f00e1e
Remove SyntaxContext from {ast, hir}::{GlobalAsm, InlineAsm}
matthewjasper Aug 12, 2019
01587b1
Remove unused `SyntaxContext` serialization impls
matthewjasper Aug 13, 2019
417f9ea
Utilize -Zbinary-dep-depinfo for dependency tracking
Mark-Simulacrum Aug 11, 2019
0b713ae
typeck: extract ban_private_field_access
Centril Aug 13, 2019
5e019de
typeck: extract ban_take_value_of_method
Centril Aug 13, 2019
9805846
typeck: extract maybe_suggest_array_indexing
Centril Aug 13, 2019
039c789
typeck: extract suggest_first_deref_field
Centril Aug 13, 2019
01e96dc
typeck: extract suggest_fields_on_recordish
Centril Aug 13, 2019
0741441
typeck: restructure check_field a bit
Centril Aug 13, 2019
88398a4
typeck: on wrong <expr>.await suggest -> 2018
Centril Aug 13, 2019
9287eb6
typeck: add tests for suggesting -> 2018 on wrong <expr>.await
Centril Aug 13, 2019
4272864
Feature gate 'yield ?' pre-expansion.
Centril Aug 14, 2019
4fe201c
Simplify pre-expansion gating in general.
Centril Aug 14, 2019
1ab9e52
Update rustc-demangle to 0.1.16.
eddyb Aug 14, 2019
c1758d5
rustc_codegen_utils: account for 1-indexed anonymous lifetimes in v0 …
eddyb Aug 14, 2019
f54503c
libcore: more cleanups using associated_type_bounds
Centril Aug 15, 2019
acf2315
Rollup merge of #63462 - matthewjasper:hygienic-builtin-derives, r=pe…
Centril Aug 15, 2019
3ee6036
Rollup merge of #63470 - Mark-Simulacrum:rustc-depdep, r=alexcrichton
Centril Aug 15, 2019
9d9518d
Rollup merge of #63539 - Centril:2015.await, r=oli-obk
Centril Aug 15, 2019
430e403
Rollup merge of #63545 - Centril:gate-yield-preexp, r=oli-obk
Centril Aug 15, 2019
52e78c5
Rollup merge of #63548 - eddyb:unicode-demangling, r=alexcrichton
Centril Aug 15, 2019
74e9002
Rollup merge of #63559 - eddyb:v0-mangling-off-by-1, r=estebank
Centril Aug 15, 2019
5908574
Rollup merge of #63584 - Centril:cleanup-core-with-more-atb, r=alexreg
Centril Aug 15, 2019
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
Remove gensyms from built-in derives
Also make them generally more hygienic with name resolution.
  • Loading branch information
matthewjasper committed Aug 12, 2019
commit ade2c8fd2fdebc89bce842d1b7f22e81004dbea2
59 changes: 30 additions & 29 deletions src/libsyntax_ext/deriving/cmp/ord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,18 @@ pub fn expand_deriving_ord(cx: &mut ExtCtxt<'_>,
}


pub fn ordering_collapsed(cx: &mut ExtCtxt<'_>,
span: Span,
self_arg_tags: &[ast::Ident])
-> P<ast::Expr> {
pub fn ordering_collapsed(
cx: &mut ExtCtxt<'_>,
span: Span,
self_arg_tags: &[ast::Ident],
) -> P<ast::Expr> {
let lft = cx.expr_ident(span, self_arg_tags[0]);
let rgt = cx.expr_addr_of(span, cx.expr_ident(span, self_arg_tags[1]));
cx.expr_method_call(span, lft, cx.ident_of("cmp"), vec![rgt])
cx.expr_method_call(span, lft, ast::Ident::new(sym::cmp, span), vec![rgt])
}

pub fn cs_cmp(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> P<Expr> {
let test_id = cx.ident_of("cmp").gensym();
let test_id = ast::Ident::new(sym::cmp, span);
let equals_path = cx.path_global(span, cx.std_path(&[sym::cmp, sym::Ordering, sym::Equal]));

let cmp_path = cx.std_path(&[sym::cmp, sym::Ord, sym::cmp]);
Expand All @@ -75,34 +76,34 @@ pub fn cs_cmp(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> P<
// as the outermost one, and the last as the innermost.
false,
|cx, span, old, self_f, other_fs| {
// match new {
// ::std::cmp::Ordering::Equal => old,
// cmp => cmp
// }
// match new {
// ::std::cmp::Ordering::Equal => old,
// cmp => cmp
// }

let new = {
let other_f = match other_fs {
[o_f] => o_f,
_ => cx.span_bug(span, "not exactly 2 arguments in `derive(Ord)`"),
};
let new = {
let other_f = match other_fs {
[o_f] => o_f,
_ => cx.span_bug(span, "not exactly 2 arguments in `derive(Ord)`"),
};

let args = vec![
cx.expr_addr_of(span, self_f),
cx.expr_addr_of(span, other_f.clone()),
];
let args = vec![
cx.expr_addr_of(span, self_f),
cx.expr_addr_of(span, other_f.clone()),
];

cx.expr_call_global(span, cmp_path.clone(), args)
};
cx.expr_call_global(span, cmp_path.clone(), args)
};

let eq_arm = cx.arm(span,
vec![cx.pat_path(span, equals_path.clone())],
old);
let neq_arm = cx.arm(span,
vec![cx.pat_ident(span, test_id)],
cx.expr_ident(span, test_id));
let eq_arm = cx.arm(span,
vec![cx.pat_path(span, equals_path.clone())],
old);
let neq_arm = cx.arm(span,
vec![cx.pat_ident(span, test_id)],
cx.expr_ident(span, test_id));

cx.expr_match(span, new, vec![eq_arm, neq_arm])
},
cx.expr_match(span, new, vec![eq_arm, neq_arm])
},
cx.expr_path(equals_path.clone()),
Box::new(|cx, span, (self_args, tag_tuple), _non_self_args| {
if self_args.len() != 2 {
Expand Down
15 changes: 8 additions & 7 deletions src/libsyntax_ext/deriving/cmp/partial_ord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,12 @@ pub enum OrderingOp {
GeOp,
}

pub fn some_ordering_collapsed(cx: &mut ExtCtxt<'_>,
span: Span,
op: OrderingOp,
self_arg_tags: &[ast::Ident])
-> P<ast::Expr> {
pub fn some_ordering_collapsed(
cx: &mut ExtCtxt<'_>,
span: Span,
op: OrderingOp,
self_arg_tags: &[ast::Ident],
) -> P<ast::Expr> {
let lft = cx.expr_ident(span, self_arg_tags[0]);
let rgt = cx.expr_addr_of(span, cx.expr_ident(span, self_arg_tags[1]));
let op_str = match op {
Expand All @@ -108,11 +109,11 @@ pub fn some_ordering_collapsed(cx: &mut ExtCtxt<'_>,
GtOp => "gt",
GeOp => "ge",
};
cx.expr_method_call(span, lft, cx.ident_of(op_str), vec![rgt])
cx.expr_method_call(span, lft, ast::Ident::from_str_and_span(op_str, span), vec![rgt])
}

pub fn cs_partial_cmp(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> P<Expr> {
let test_id = cx.ident_of("cmp").gensym();
let test_id = ast::Ident::new(sym::cmp, span);
let ordering = cx.path_global(span, cx.std_path(&[sym::cmp, sym::Ordering, sym::Equal]));
let ordering_expr = cx.expr_path(ordering.clone());
let equals_expr = cx.expr_some(span, ordering_expr);
Expand Down
8 changes: 4 additions & 4 deletions src/libsyntax_ext/deriving/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>
// We want to make sure we have the ctxt set so that we can use unstable methods
let span = span.with_ctxt(cx.backtrace());
let name = cx.expr_lit(span, ast::LitKind::Str(ident.name, ast::StrStyle::Cooked));
let builder = Ident::from_str("debug_trait_builder").gensym();
let builder = Ident::from_str_and_span("debug_trait_builder", span);
let builder_expr = cx.expr_ident(span, builder.clone());

let fmt = substr.nonself_args[0].clone();
Expand All @@ -73,7 +73,7 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>
// tuple struct/"normal" variant
let expr =
cx.expr_method_call(span, fmt, Ident::from_str("debug_tuple"), vec![name]);
stmts.push(cx.stmt_let(DUMMY_SP, true, builder, expr));
stmts.push(cx.stmt_let(span, true, builder, expr));

for field in fields {
// Use double indirection to make sure this works for unsized types
Expand All @@ -82,7 +82,7 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>

let expr = cx.expr_method_call(span,
builder_expr.clone(),
Ident::with_empty_ctxt(sym::field),
Ident::new(sym::field, span),
vec![field]);

// Use `let _ = expr;` to avoid triggering the
Expand All @@ -106,7 +106,7 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>
let field = cx.expr_addr_of(field.span, field);
let expr = cx.expr_method_call(span,
builder_expr.clone(),
Ident::with_empty_ctxt(sym::field),
Ident::new(sym::field, span),
vec![name, field]);
stmts.push(stmt_let_undescore(cx, span, expr));
}
Expand Down
6 changes: 3 additions & 3 deletions src/libsyntax_ext/deriving/decodable.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! The compiler code necessary for `#[derive(Decodable)]`. See encodable.rs for more.
//! The compiler code necessary for `#[derive(RustcDecodable)]`. See encodable.rs for more.

use crate::deriving::{self, pathvec_std};
use crate::deriving::pathvec_std;
use crate::deriving::generic::*;
use crate::deriving::generic::ty::*;

Expand All @@ -17,7 +17,7 @@ pub fn expand_deriving_rustc_decodable(cx: &mut ExtCtxt<'_>,
item: &Annotatable,
push: &mut dyn FnMut(Annotatable)) {
let krate = "rustc_serialize";
let typaram = &*deriving::hygienic_type_parameter(item, "__D");
let typaram = "__D";

let trait_def = TraitDef {
span,
Expand Down
21 changes: 12 additions & 9 deletions src/libsyntax_ext/deriving/encodable.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
//! The compiler code necessary to implement the `#[derive(Encodable)]`
//! (and `Decodable`, in `decodable.rs`) extension. The idea here is that
//! type-defining items may be tagged with `#[derive(Encodable, Decodable)]`.
//! The compiler code necessary to implement the `#[derive(RustcEncodable)]`
//! (and `RustcDecodable`, in `decodable.rs`) extension. The idea here is that
//! type-defining items may be tagged with
//! `#[derive(RustcEncodable, RustcDecodable)]`.
//!
//! For example, a type like:
//!
//! ```
//! #[derive(Encodable, Decodable)]
//! #[derive(RustcEncodable, RustcDecodable)]
//! struct Node { id: usize }
//! ```
//!
Expand Down Expand Up @@ -40,15 +41,17 @@
//! references other non-built-in types. A type definition like:
//!
//! ```
//! # #[derive(Encodable, Decodable)] struct Span;
//! #[derive(Encodable, Decodable)]
//! # #[derive(RustcEncodable, RustcDecodable)]
//! # struct Span;
//! #[derive(RustcEncodable, RustcDecodable)]
//! struct Spanned<T> { node: T, span: Span }
//! ```
//!
//! would yield functions like:
//!
//! ```
//! # #[derive(Encodable, Decodable)] struct Span;
//! # #[derive(RustcEncodable, RustcDecodable)]
//! # struct Span;
//! # struct Spanned<T> { node: T, span: Span }
//! impl<
//! S: Encoder<E>,
Expand Down Expand Up @@ -82,7 +85,7 @@
//! }
//! ```

use crate::deriving::{self, pathvec_std};
use crate::deriving::pathvec_std;
use crate::deriving::generic::*;
use crate::deriving::generic::ty::*;

Expand All @@ -98,7 +101,7 @@ pub fn expand_deriving_rustc_encodable(cx: &mut ExtCtxt<'_>,
item: &Annotatable,
push: &mut dyn FnMut(Annotatable)) {
let krate = "rustc_serialize";
let typaram = &*deriving::hygienic_type_parameter(item, "__S");
let typaram = "__S";

let trait_def = TraitDef {
span,
Expand Down
11 changes: 7 additions & 4 deletions src/libsyntax_ext/deriving/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ impl<'a> MethodDef<'a> {

for (ty, name) in self.args.iter() {
let ast_ty = ty.to_ty(cx, trait_.span, type_ident, generics);
let ident = cx.ident_of(name).gensym();
let ident = ast::Ident::from_str_and_span(name, trait_.span);
arg_tys.push((ident, ast_ty));

let arg_expr = cx.expr_ident(trait_.span, ident);
Expand Down Expand Up @@ -1210,7 +1210,7 @@ impl<'a> MethodDef<'a> {
let vi_idents = self_arg_names.iter()
.map(|name| {
let vi_suffix = format!("{}_vi", &name[..]);
cx.ident_of(&vi_suffix[..]).gensym()
ast::Ident::from_str_and_span(&vi_suffix[..], trait_.span)
})
.collect::<Vec<ast::Ident>>();

Expand Down Expand Up @@ -1387,7 +1387,10 @@ impl<'a> MethodDef<'a> {
let variant_value =
deriving::call_intrinsic(cx, sp, "discriminant_value", vec![self_addr]);

let target_ty = cx.ty_ident(sp, cx.ident_of(target_type_name));
let target_ty = cx.ty_ident(
sp,
ast::Ident::from_str_and_span(target_type_name, sp),
);
let variant_disr = cx.expr_cast(sp, variant_value, target_ty);
let let_stmt = cx.stmt_let(sp, false, ident, variant_disr);
index_let_stmts.push(let_stmt);
Expand Down Expand Up @@ -1588,7 +1591,7 @@ impl<'a> TraitDef<'a> {
let mut ident_exprs = Vec::new();
for (i, struct_field) in struct_def.fields().iter().enumerate() {
let sp = struct_field.span.with_ctxt(self.span.ctxt());
let ident = cx.ident_of(&format!("{}_{}", prefix, i)).gensym();
let ident = ast::Ident::from_str_and_span(&format!("{}_{}", prefix, i), self.span);
paths.push(ident.with_span_pos(sp));
let val = cx.expr_path(cx.path_ident(sp, ident));
let val = if use_temporaries {
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax_ext/deriving/generic/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl<'a> Path<'a> {
self_ty: Ident,
self_generics: &Generics)
-> ast::Path {
let mut idents = self.path.iter().map(|s| cx.ident_of(*s)).collect();
let mut idents = self.path.iter().map(|s| Ident::from_str_and_span(*s, span)).collect();
let lt = mk_lifetimes(cx, span, &self.lifetime);
let tys: Vec<P<ast::Ty>> =
self.params.iter().map(|t| t.to_ty(cx, span, self_ty, self_generics)).collect();
Expand Down Expand Up @@ -209,7 +209,7 @@ fn mk_ty_param(cx: &ExtCtxt<'_>,
cx.trait_bound(path)
})
.collect();
cx.typaram(span, cx.ident_of(name), attrs.to_owned(), bounds, None)
cx.typaram(span, ast::Ident::from_str_and_span(name, span), attrs.to_owned(), bounds, None)
}

fn mk_generics(params: Vec<ast::GenericParam>, span: Span) -> Generics {
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax_ext/deriving/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn expand_deriving_hash(cx: &mut ExtCtxt<'_>,

let path = Path::new_(pathvec_std!(cx, hash::Hash), None, vec![], PathKind::Std);

let typaram = &*deriving::hygienic_type_parameter(item, "__H");
let typaram = "__H";

let arg = Path::new_local(typaram);
let hash_trait_def = TraitDef {
Expand Down
27 changes: 0 additions & 27 deletions src/libsyntax_ext/deriving/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,33 +54,6 @@ impl MultiItemModifier for BuiltinDerive {
}
}

/// Construct a name for the inner type parameter that can't collide with any type parameters of
/// the item. This is achieved by starting with a base and then concatenating the names of all
/// other type parameters.
// FIXME(aburka): use real hygiene when that becomes possible
fn hygienic_type_parameter(item: &Annotatable, base: &str) -> String {
let mut typaram = String::from(base);
if let Annotatable::Item(ref item) = *item {
match item.node {
ast::ItemKind::Struct(_, ast::Generics { ref params, .. }) |
ast::ItemKind::Enum(_, ast::Generics { ref params, .. }) => {
for param in params {
match param.kind {
ast::GenericParamKind::Type { .. } => {
typaram.push_str(&param.ident.as_str());
}
_ => {}
}
}
}

_ => {}
}
}

typaram
}

/// Constructs an expression that calls an intrinsic
fn call_intrinsic(cx: &ExtCtxt<'_>,
span: Span,
Expand Down
Loading