Reserve @self require alias to prevent user-defined overrides#215
Reserve @self require alias to prevent user-defined overrides#215vrn-sn wants to merge 1 commit into
@self require alias to prevent user-defined overrides#215Conversation
|
What is the actual performance change? Is there any motivation beyond performance? |
|
In our runtime, we've kind of already made this change to prevent the implementation becoming overly complex for our |
The current performance cost depends on multiple factors - for example:
This proposed change cuts that lookup cost entirely.
Performance is one motivation, and I would say that the other is language-wide consistency across different runtime environments. The other basic navigation operations are consistently defined (e.g. |
In #109, I had initially proposed that we allow users to override
@selfin their user-defined alias maps, as the semantics would then be similar to how thescriptglobal in Roblox scripts could be shadowed. We didn't want to encourage this pattern, but I didn't really see any harm at the time.Over a year later, we have now exposed generalized
requiresemantics through theLuau.Requirelibrary, and I've realized we made the wrong move (oops!). Using@selfis turning out to be extremely common, both for code that runs in filesystem-targeting runtimes (e.g. Lute) and even in Roblox (e.g. Roblox's own Character Controller Library).By allowing
@selfto be overridden, the generalized require resolver is forced to check all parent directories for a user-defined@selfalias before proceeding with navigation, which is horrible for performance. If we forbid user-defined overrides of@self, we can immediately continue on with path navigation without this unnecessary cost.Although we discussed these two options in the original RFC comments, it turns out nothing was ever cemented in the RFC document itself. In this PR, I've spelled these semantics out explicitly.
Backwards-compatibility: if anyone is currently overriding
@self, this will be a breaking change. I think this is an acceptable cost for a few reasons:@selfalias is the most commonly used alias today, and we should be optimizing for the common use case.