CarterFendley / fast-dep

MIT License
1 stars 1 forks source link

Pull the name of source files into a constant & disambiguate #4

Open CarterFendley opened 3 months ago

CarterFendley commented 3 months ago

Currently we use <terminal> to represent the "module name" for source code which is passed to GraphBuilder.build(...). We reference this at a couple of points in the code by a literal, which is just asking for trouble. Additionally we use the same <terminal> literal to represent the "package" for that source code, which may be confusing.

Uses for "name"

  1. https://github.com/CarterFendley/fast-dep/blob/d4ef6f517a9a3e9225d8f5ed4bc64c89d824e99f/src/core/builder.rs#L67
  2. https://github.com/CarterFendley/fast-dep/blob/d4ef6f517a9a3e9225d8f5ed4bc64c89d824e99f/src/core/builder.rs#L268 a. This one is particularly dangerous as not having <terminal> updated here but having updated in the first instance will break caching in a really bad silent failure way.

Uses for "package"

  1. https://github.com/CarterFendley/fast-dep/blob/d4ef6f517a9a3e9225d8f5ed4bc64c89d824e99f/src/core/builder.rs#L63
  2. https://github.com/CarterFendley/fast-dep/blob/d4ef6f517a9a3e9225d8f5ed4bc64c89d824e99f/src/core/builder.rs#L179
SchwartzCode commented 3 months ago

An enum might be better here:

pub enum NodeType {
  Terminal,
  Intermediate(String)
}

Intermediate isn't a great name, but this sort of setup paired with match statements on node type can allow you to explicitly handle different node types in different ways