about summary refs log tree commit diff
path: root/src/libsyntax/ext/base.rs
AgeCommit message (Collapse)AuthorLines
2019-08-29Rollup merge of #63867 - petrochenkov:dhelpers, r=matthewjasperMazdak Farrokhzad-1/+19
resolve: Block expansion of a derive container until all its derives are resolved So, it turns out there's one more reason to block expansion of a `#[derive]` container until all the derives inside it are resolved, beside `Copy` (https://github.com/rust-lang/rust/pull/63248). The set of derive helper attributes registered by derives in the container also has to be known before the derives themselves are expanded, otherwise it may be too late (see https://github.com/rust-lang/rust/pull/63468#issuecomment-524550872 and the `#[stable_hasher]`-related test failures in https://github.com/rust-lang/rust/pull/63468). So, we stop our attempts to unblock the container earlier, as soon as the `Copy` status is known, and just block until all its derives are resolved. After all the derives are resolved we immediately go and process their helper attributes in the item, without delaying it until expansion of the individual derives. Unblocks https://github.com/rust-lang/rust/pull/63468 r? @matthewjasper (as a reviewer of https://github.com/rust-lang/rust/pull/63248) cc @c410-f3r
2019-08-27Respect attributes on proc macro definitionsVadim Petrochenkov-2/+65
2019-08-27resolve: Block expansion of a derive container until all its derives are ↵Vadim Petrochenkov-1/+19
resolved Also mark derive helpers as known as a part of the derive container's expansion instead of expansion of the derives themselves which may happen too late.
2019-08-23Remove default macro transparenciesVadim Petrochenkov-20/+0
All transparancies are passed explicitly now. Also remove `#[rustc_macro_transparency]` annotations from built-in macros, they are no longer used. `#[rustc_macro_transparency]` only makes sense for declarative macros now.
2019-08-23Audit uses of `apply_mark` in built-in macrosVadim Petrochenkov-7/+23
Replace them with equivalents of `Span::{def_site,call_site}` from proc macro API. The new API is much less error prone and doesn't rely on macros having default transparency.
2019-08-21resolve/expand: Rename some things for clarity and add commentsVadim Petrochenkov-2/+3
2019-08-21expand: Do not do questionable span adjustment before eagerly expanding an ↵Vadim Petrochenkov-4/+1
expression Maybe it made sense when it was introduced, but now it's doing something incorrect.
2019-08-17resolve/expand: Rename some things for clarityVadim Petrochenkov-4/+4
2019-08-15hygiene: `ExpnInfo` -> `ExpnData`Vadim Petrochenkov-9/+9
For naming consistency with everything else in this area
2019-08-15hygiene: Merge `ExpnInfo` and `InternalExpnData`Vadim Petrochenkov-2/+3
2019-08-15hygiene: Remove `Option`s from functions returning `ExpnInfo`Vadim Petrochenkov-14/+7
The expansion info is not optional and should always exist
2019-08-15`Ident::with_empty_ctxt` -> `Ident::with_dummy_span`Vadim Petrochenkov-1/+1
`Ident` has had a full span rather than just a `SyntaxContext` for a long time now.
2019-08-15syntax_pos: `NO_EXPANSION`/`SyntaxContext::empty()` -> `SyntaxContext::root()`Vadim Petrochenkov-1/+1
For consistency with `ExpnId::root`. Also introduce a helper `Span::with_root_ctxt` for creating spans with `SyntaxContext::root()` context
2019-08-15Remove `Spanned` from `mk_name_value_item_str` and `expr_to_spanned_string`Vadim Petrochenkov-4/+4
2019-08-14Rollup merge of #63537 - petrochenkov:novisit, r=alexcrichtonMazdak Farrokhzad-4/+10
expand: Unimplement `MutVisitor` on `MacroExpander` Each call to `fully_expand_fragment` is something unique, interesting, and requiring attention. It represents a "root" of expansion and its use means that something unusual is happening, like eager expansion or expansion performed outside of the primary expansion pass. So, it shouldn't hide under a generic visitor call. Also, from all the implemented visitor methods only two were actually used. cc https://github.com/rust-lang/rust/pull/63468#discussion_r313504119
2019-08-14expand: Unimplement `MutVisitor` on `MacroExpander`Vadim Petrochenkov-4/+10
Each call to `fully_expand_fragment` is something unique, interesting, and requiring attention. It represents a "root" of expansion and its use means that something unusual is happening, like eager expansion or expansion performed outside of the primary expansion pass. So, it shouldn't be hide under a generic visitor call. Also, from all the implemented visitor methods only two were actually used.
2019-08-13syntax: Remove `DummyResult::expn_only`Vadim Petrochenkov-33/+6
2019-08-10resolve: Remove remaining special cases from built-in macrosVadim Petrochenkov-2/+2
2019-08-05Auto merge of #63248 - petrochenkov:nomarker, r=matthewjasperbors-2/+16
Move special treatment of `derive(Copy, PartialEq, Eq)` from expansion infrastructure to elsewhere As described in https://github.com/rust-lang/rust/pull/62086#issuecomment-515195477. Reminder: - `derive(PartialEq, Eq)` makes the type it applied to a "structural match" type, so constants of this type can be used in patterns (and const generics in the future). - `derive(Copy)` notifies other derives that the type it applied to implements `Copy`, so `derive(Clone)` can generate optimized code and other derives can generate code working with `packed` types and types with `rustc_layout_scalar_valid_range` attributes. First, the special behavior is now enabled after properly resolving the derives, rather than after textually comparing them with `"Copy"`, `"PartialEq"` and `"Eq"` in `fn add_derived_markers`. The markers are no longer kept as attributes in AST since derives cannot modify items and previously did it through hacks in the expansion infra. Instead, the markers are now kept in a "global context" available from all the necessary places, namely - resolver. For `derive(PartialEq, Eq)` the markers are created by the derive macros themselves and then consumed during HIR lowering to add the `#[structural_match]` attribute in HIR. This is still a hack, but now it's a hack local to two specific macros rather than affecting the whole expansion infra. Ideally we should find the way to put `#[structural_match]` on the impls rather than on the original item, and then consume it in `rustc_mir`, then no hacks in expansion and lowering will be required. (I'll make an issue about this for someone else to solve, after this PR lands.) The marker for `derive(Copy)` cannot be emitted by the `Copy` macro itself because we need to know it *before* the `Copy` macro is expanded for expanding other macros. So we have to do it in resolve and block expansion of any derives in a `derive(...)` container until we know for sure whether this container has `Copy` in it or not. Nasty stuff. r? @eddyb or @matthewjasper
2019-08-03Move special treatment of `derive(Copy, PartialEq, Eq)` from expansion ↵Vadim Petrochenkov-2/+16
infrastructure to elsewhere
2019-07-30Point at type ascription before macro invocation on expansion parse errorEsteban Küber-0/+2
2019-07-27syntax_ext: `proc_macro_decls` -> `proc_macro_harness`Vadim Petrochenkov-1/+1
Few other minor renamings for consistency. Remove one unused dependency from `rustc_passes`. Fix libsyntax tests. Fix rebase.
2019-07-27Break dependencies between `syntax_ext` and some other cratesVadim Petrochenkov-1/+1
Move `source_uitil` macros into `syntax_ext` Cleanup dependencies of `rustc_driver`
2019-07-26Introduce built-in macros through libcoreVadim Petrochenkov-1/+5
2019-07-23Make path::resolve a method on ExtCtxtJonas Schievink-1/+26
2019-07-19Adjust other names after the `Mark` renamingVadim Petrochenkov-7/+7
2019-07-19libsyntax: Remove `Mark` into `ExpnId`Vadim Petrochenkov-7/+7
2019-07-11hygiene: Introduce a helper method for creating new expansionsVadim Petrochenkov-0/+2
Creating a fresh expansion and immediately generating a span from it is the most common scenario. Also avoid allocating `allow_internal_unstable` lists for derive markers repeatedly. And rename `ExpnInfo::with_unstable` to `ExpnInfo::allow_unstable`, seems to be a better fitting name.
2019-07-11resolve/expand: `resolve_macro_invocation` no longer returns determinate errorsVadim Petrochenkov-13/+4
It either returns the indeterminacy error, or valid (but perhaps dummy) `SyntaxExtension`. With this change enum `Determinacy` is no longer used in libsyntax and can be moved to resolve. The regressions in diagnosics are fixed in the next commits.
2019-07-11resolve: Make proc macro stubs less stubbyVadim Petrochenkov-1/+21
Create real working and registered (even if dummy) `SyntaxExtension`s for them. This improves error recovery and allows to avoid all special cases for proc macro stubs (except for the error on use, of course). The introduced dummy `SyntaxExtension`s can be used for any other inappropriately resolved macros as well.
2019-07-11hygiene: Reuse `MacroKind` in `ExpnKind`Vadim Petrochenkov-10/+2
Orthogonality and reuse are good.
2019-07-11syntax: Make def-site span mandatory in ↵Vadim Petrochenkov-3/+1
ExpnInfo/MacroBacktrace/DiagnosticSpanMacroExpansion We have to deal with dummy spans anyway Remove def-site span from expander interfaces. It's not used by the expansion infra, only by specific expanders, which can keep it themselves if they want it.
2019-07-11expand: Get rid of `resolve_macro_path`Vadim Petrochenkov-3/+0
It was used to choose whether to apply derive markers like `#[rustc_copy_clone_marker]` or not, but it was called before all the data required for resolution is available, so it could work incorrectly in some corner cases (like user-defined derives name `Copy` or `Eq`). Delay the decision about markers until the proper resolution results are available instead.
2019-07-11Rename some things in `syntax_pos/hygiene`Vadim Petrochenkov-7/+7
More consistent with other naming: ExpnFormat -> ExpnKind ExpnKind::name -> ExpnKind::descr DesugaringKind::name -> DesugaringKind::descr Shorter, no tautology: CompilerDesugaring -> Desugaring CompilerDesugaringKind -> DesugaringKind
2019-07-11Move `MacroKind` into `libsyntax_pos`Vadim Petrochenkov-28/+1
So it can be eventually used in `ExpnInfo`
2019-07-11Remove `MacroKind::ProcMacroStub`Vadim Petrochenkov-3/+0
It's internal to resolve and always results in `Res::Err` outside of resolve. Instead put `DefKind::Fn`s themselves into the macro namespace, it's ok. Proc macro stubs are items placed into macro namespase for functions that define proc macros. https://github.com/rust-lang/rust/pull/52383 The rustdoc test is changed because the old test didn't actually reproduce the ICE it was supposed to reproduce.
2019-07-09Resolve `$crate` in all hygienic contexts for pretty-pringingVadim Petrochenkov-1/+1
Stop visiting AST to discover those contexts, just iterate through hygiene data instead
2019-07-07Support deprecation checking for macrosVadim Petrochenkov-2/+5
2019-07-07syntax: Keep full `Stability` in `SyntaxExtension`Vadim Petrochenkov-4/+4
2019-07-07resolve/expand: Move macro stability checking to an earlier pointVadim Petrochenkov-2/+0
2019-07-07syntax: Remove `NodeId` from `SyntaxExtension`Vadim Petrochenkov-4/+4
2019-06-18resolve/expand: Move expansion info setting to a single earlier pointVadim Petrochenkov-1/+1
2019-06-18syntax: Move `default_transparency` into `ExpnInfo`Vadim Petrochenkov-1/+2
2019-06-18syntax: Remove `DummyResolver`Vadim Petrochenkov-25/+0
2019-06-18syntax: Factor out common fields from `SyntaxExtension` variantsVadim Petrochenkov-61/+87
2019-06-10syntax: Rename variants of `SyntaxExtension` for consistencyVadim Petrochenkov-30/+25
2019-06-10syntax: Improve documentation of `SyntaxExtension`Vadim Petrochenkov-36/+54
2019-06-10syntax: Remove `SyntaxExtension::DeclMacro`Vadim Petrochenkov-13/+5
It's a less powerful duplicate of `SyntaxExtension::NormalTT`
2019-06-10syntax: Use `MultiItemModifier` for built-in derivesVadim Petrochenkov-5/+2
2019-06-10syntax: Remove `SyntaxExtension::MultiDecorator` and `MultiItemDecorator`Vadim Petrochenkov-33/+0