Skip to content

Clean up suspicious preprocessing logic #21

@viluon

Description

@viluon

The preprocess method of PreprocessorState has some dubious control flow.

pub fn preprocess(&mut self, input: &mut VecDeque<(FileId, Token, Span)>) -> Vec<(FileId, Token, Span)> {

It looks like it would report a recursive import error if a single file were included non-recursively from multiple locations. The check for that should compare the vertex state of the included file against VertexState::Open, not just see whether it has any state at all (i.e. whether it was seen yet). To make that work, however, preprocess() needs to manage the vertex states reasonably, which it doesn't presently do. The top of the while loop checks whether the incoming token comes from a different file than the tokens up to this point. This is not enough. We need a proper stack of #includes here, because the input stream can mix tokens from different source files, and a change in the source doesn't imply that we're done with said source. The #include stack should correspond to the path of FileId's for the resolved output tokens. We only associate a single FileId and Span with each token at the moment.

Currently, the while loop leaves the last processed file in the open vertex state, which is incorrect (and a possible concern for caching).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions