Why can't the same filename be used twice

I think there's a point where we can accept that everyone else is doing it and if they're not having issues with it maybe we'll be fine.

Also if we store them in caches and such by relative path, which we should've always done, this is a non-issue.
If someone is using #fileID for something critical instead of just debugging then it was probably a bad idea to begin with.

Would a compiler flag be a reasonable option here? It could be introduced off by default, allowing people to opt in to the multi-file behavior, and then eventually be switched to enabled by default. Library code like NSCoding could warn when the flag is enabled to alert users of the potential for data loss or other consequences.

A flag obviously comes with a maintenance burden, but it is something that could put the language on a path to phasing out unwanted old behavior.

1 Like

It's used by NSCoding? That explains why it matters so much, and why I never encountered it!

Thank you for that insight!

1 Like

That came from @jrose's blog posts. One of the difficulties of changing how names are mangled is that the mangled names have been used in archives created with NSCoding, which means the mangled names have trickled all the way to end-user space. It sounds like great pains have to be taken to make changes to the mangled names to avoid end-user facing breakages.

It's a real bummer of a situation.

1 Like

There could be a more of less safe way out:

  1. the project doesn't use duplicated file names.
    Let's consider it doesn't use NSCoding (we could consider that use case later)
  2. a file with a duplicated name is introduced to the project.
  3. at this point Xcode complains and prompts: "you've just added a file with a duplicated name. That's an error unless you enable this new compiler flag"
  4. user enables that compile flag - Xcode now allows the compilation.
  5. user adds NSCoding - archives are now archived using a new method because of the new compiler flag
  6. user deletes the duplicated file name (or renames the file)
  7. archives are still using the new method of archiving (due to the setting that is still on)
  8. Only when the user switches that compiler flag off – there would be a trouble.

IOW there could be a new compilation flag that affects NSCoding archives, and duplicated file names are only allowed when this compilation flag is on.

2 Likes

That's pretty much what I was thinking.

Bonus points for a migration strategy for old use cases like existing NSCoding archives. Bonus bonus points if we can ensure that the new mangled names can no longer trickle into user space.

1 Like