Skip to content

Refactor(ErrorHandler): Move file_id into Span and compute it during parsing #347

Description

@LesterEvSe

Motivation

Currently, several AST structures in parse.rs (such as TypeAlias and Function) manually define a file_id: usize field to distinguish between identical structures across different files. It would be much cleaner to embed this file_id directly into the Span structure itself.

The Problem

During the parsing stage, we currently initialize this file_id to a dummy value (0). Later, during the driver stage, we mutate the AST to inject the actual file ID generated by the driver. This approach feels like a crutch. It is highly inconvenient because it requires the driver to reach directly into the parsed structs to mutate them.

The Solution

Instead of mutating the AST later, we should compute the file_id directly during the parsing stage. By hashing the specific file and assigning that hash as the file_id upfront, the driver will immediately have access to the correct ID. This significantly simplifies the driver's logic.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No fields configured for Task.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions