-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: Absolute Require Syntax #80
base: master
Are you sure you want to change the base?
Conversation
This really sounds how we wanted to have libraries to work initially. |
|
||
## Motivation | ||
|
||
It should be possible for all users of Luau to write code that is capable of running, without modification, on many different platforms. Unfortunately, we identified an issue with the current syntax that would make it difficult for users of certain tools to adopt. As paths are relative to the file calling require, any tools that adjust the file hierarchy would also need to update require paths to match. While we know there may not be a perfect solution that works for all use-cases, we think the current syntax should be amended to support these cases or at least not require them to translate require paths in files. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, we identified an issue with the current syntax that would make it difficult for users of certain tools to adopt.
Which tools?
As paths are relative to the file calling require, any tools that adjust the file hierarchy would also need to update require paths to match.
What tools would adjust the file hierarchy other than a human moving files around?
This can be solved with code refactoring tools. In TypeScript, if you have some statement
import ... from "./foo"
You can press F2 on "./foo"
and it will rename the file, and also applies renaming over other imports that resolves to the same file, ditto any kind of action of moving files around as long as the action of moving files around happens through LSP.
I'm not a fan of any RFCs that wants to cop out from motivating the need for better tooling, similar to postfix !
to remove nil
, and this RFC feels like it has the same problem.
|
||
## Alternatives | ||
|
||
We have already considered (and even approved) some alternatives to this approach, however there are drawbacks with each of them that ultimately led us in this direction. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can I see this section reworked? As it is, it requires you to read all the RFCs and filtering out irrelevant information wrt what this RFC is trying to solve. It's also not really "alternatives" either.
Had to read all the related RFCs that was spawned in the last week surrounding Given this filesystem:
With such contents:
Piping this through Rojo gives this DataModel structure:
To make matters worse, there is supposed to be a bijectivity between the require by string and require by DM paths:
This presents a counterexample: Consequently Following this line of thinking, you can see another diverging behavior in the other direction: In Lune, if you have the above filesystem structure and its contents and you run This leads me to conclude that it might have been a benign design bug in Rojo's mapping between filesystem <-> DM. I say benign because it has always existed and was never shown to be a problem until now, just like The question I have now: is this a language design issue, or is this an issue elsewhere? I don't want to want to jump to the conclusion about whose issue it is, but it doesn't feel like a language issue to me. Perspective: Luau needs to change somethingIf you adopt the view that the language has to change to fix the problem, you get these RFCs:
The last 3 RFCs listed here got me looking at this and think about what I could do to step in and defuse the situation. My stance is that none of the above fixes the problem where the filesystem and the DM are observationally different. Perspective: Rojo needs to change somethingIf you shift perspective and think that Rojo should change to fix the problem, you will be able to see better progression towards a real resolution by adding a constraint where the filesystem and the DM must be structure preserving to maintain bijection. Currently, it conflates flattening with mapping, where a folder containing By removing the flattening part out of Rojo, you end up with this structure, exactly equivalent to one in the filesystem.
Way better. Indeed, we have two issues that arises from doing this:
This means Rojo was bludgeoned into a corner, and only one way out left: Roblox. Perspective: Roblox needs to change somethingIf you again shift perspective and think that Roblox is missing something, then you can ponder why flattening was added in Rojo in the first place. The reason was purely a syntactic convenience. Without it, you had to settle on a convention on which script was the entry point for a collection of modules. You would also have to deal with one extra This boils down to a missing instance type, call it
This effectively does the flattening for Rojo, without making flattening a destructive operation done by Rojo, allowing Rojo a full and faithful functor to represent the original filesystem used to map over into Roblox for the purpose of resolving requires without any observable differences. With a
Rojo no longer has to flatten this out, since Roblox supports it first-class, and restores all backward incompatibilities that was not resolvable with This feature exists with First shot
I think we should take this issue as a growing pain towards having a Until such an instance exist, Rojo is literally incapable of doing anything. It can't change the way it maps the filesystem to the DM without breaking one require style or the other. This means that require by string and require by DM paths are mutually exclusive to each other if you're using Rojo. Libraries gives Rojo a way out of this mutual exclusion problem. Then it becomes obvious that all RFCs proposing to change the language can be thrown out, closed, and forgotten about. All of this just stems from the lack of confluence in semantics between each style of requires, which needed to be resolved. My point I want to get across is that some of the proposals (RFC 78 and 80) feels like a knee-jerk reaction to resolve the problem today at the cost of sacrificing the design principles that was used to develop require by string RFC, which explains why RFC 79 was submitted in the first place. |
The idea that Roblox could change to support the filesystem is indeed a nice idea, but you also have to consider the users. To some extent you can rely on the "if we build it they will come" mentality, but you have to remember this is a convention that has existed in Roblox for over a decade. Is it really worth breaking that convention, and the way Rojo syncs projects (which will make string requires unusable without significant modification to existing Rojo projects), to better align with the file system? I don't think that it is. I think a better idea is to change the way we think about the file system to instead match how the datamodel functions. This is helpful for Rojo, as it won't have to change, but also helpful for Roblox when they create their own tooling to put projects in the filesystem. |
Yeah, I checked in with Dekkonot and when you add in a few other edge cases that Rojo has to account for, the libraries suggestion is not enough, and there's no good solution other than to give up the view that the DM could model the filesystem faithfully. I'm beginning to think that URIs are a good idea as long as it doesn't interact with the language design, because this is still a Roblox-ism. I had hoped that Rojo could change the way it maps over to the DM and still be backward compatible with the older version of Rojo in the DM, but I do recognize that requires extra code that amounts to doing a database migration. I also glossed over the fact that users might actually care about the DM structure that Rojo outputs to, even to the degree that |
This is not correct, requiring a Folder instance will require 'folder/init' module in the current Roblox implementation. Changing the value of |
This works using require by string. Not by DM paths, which was what the sentence says. |
Thanks for clearing that up, I incorrectly assumed it talked about string path in a DM. |
This RFC proposes additional syntax for require by string that allows modules to be resolved relative to the root of a project or library. It is based on #78 which proposed the same changes but also removed relative paths.
Rendered.