Skip to content

Consider moving out-of-line module loading from parser to expansion #64197

Closed
@petrochenkov

Description

@petrochenkov
Contributor

Due to module loading parser has to do some not very appropriate for a parser things like

  • expanding cfgs on modules (duplicated with expansion)
  • keeping the current filesystem position (duplicated with expansion)

We also don't really need to load those files until we need to incorporate their contents into NodeId-entified AST, which happens during expansion.

The move will also mean never loading files in unconfigured code.
The loading is currently skipped only if cfg is placed directly on the mod m;, but not in other cases like

#[cfg(FALSE)]
mod m {
    mod n; // Still loaded
}

Activity

added
A-frontendArea: Compiler frontend (errors, parsing and HIR)
A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)
A-parserArea: The lexing & parsing of Rust source code to an AST
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Sep 5, 2019
matklad

matklad commented on Sep 7, 2019

@matklad
Member

This is on my todo list, as it is a per-requisite for moving parser into a library.

petrochenkov

petrochenkov commented on Oct 12, 2019

@petrochenkov
ContributorAuthor

The PR trying to split the libsyntax crate apart (#65324) has to use some hacks due to cfg-expansion being called from the parser.

Mark-Simulacrum

Mark-Simulacrum commented on Nov 20, 2019

@Mark-Simulacrum
Member

#66565 removes those hacks in favor of a less principled approach (revealing the tight coupling between cfg expansion and parsing).

Zoxc

Zoxc commented on Jan 17, 2020

@Zoxc
Contributor

I would like the ability to start parsing immediately when we see a mod name;, but I guess the parser could just check if any #[cfg(..)] are in scope.

17 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-frontendArea: Compiler frontend (errors, parsing and HIR)A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-parserArea: The lexing & parsing of Rust source code to an ASTT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @Zoxc@matklad@Mark-Simulacrum@petrochenkov

      Issue actions

        Consider moving out-of-line module loading from parser to expansion · Issue #64197 · rust-lang/rust