Skip to content

Commit 13cae7d

Browse files
committed
Bump Luau to 0.672
1 parent 8e8f2e0 commit 13cae7d

File tree

9 files changed

+173
-48
lines changed

9 files changed

+173
-48
lines changed

luau/Ast/src/Parser.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ LUAU_FASTINTVARIABLE(LuauParseErrorLimit, 100)
2020
LUAU_FASTFLAGVARIABLE(LuauSolverV2)
2121
LUAU_FASTFLAGVARIABLE(LuauStoreCSTData2)
2222
LUAU_FASTFLAGVARIABLE(LuauAstTypeGroup3)
23-
LUAU_FASTFLAGVARIABLE(LuauFixDoBlockEndLocation)
2423
LUAU_FASTFLAGVARIABLE(LuauParseOptionalAsNode2)
2524
LUAU_FASTFLAGVARIABLE(LuauDeclareExternType)
2625
LUAU_FASTFLAGVARIABLE(LuauParseStringIndexer)
@@ -555,7 +554,7 @@ AstStat* Parser::parseDo()
555554

556555
Location endLocation = lexer.current().location;
557556
body->hasEnd = expectMatchEndAndConsume(Lexeme::ReservedEnd, matchDo);
558-
if (FFlag::LuauFixDoBlockEndLocation && body->hasEnd)
557+
if (body->hasEnd)
559558
body->location.end = endLocation.end;
560559

561560
if (FFlag::LuauStoreCSTData2 && options.storeCstData)

luau/Require/Navigator/include/Luau/RequireNavigator.h

+5
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ class Navigator
8787
[[nodiscard]] Error navigateToAlias(const std::string& alias, const std::string& value);
8888
[[nodiscard]] Error navigateToAndPopulateConfig(const std::string& desiredAlias);
8989

90+
[[nodiscard]] Error resetToRequirer();
91+
[[nodiscard]] Error jumpToAlias(const std::string& aliasPath);
92+
[[nodiscard]] Error navigateToParent(std::optional<std::string> previousComponent);
93+
[[nodiscard]] Error navigateToChild(const std::string& component);
94+
9095
NavigationContext& navigationContext;
9196
ErrorHandler& errorHandler;
9297
Luau::Config config;

luau/Require/Navigator/src/RequireNavigator.cpp

+62-21
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,11 @@
1010
#include <optional>
1111
#include <utility>
1212

13-
static constexpr char kRequireErrorAmbiguous[] = "require path could not be resolved to a unique file";
14-
static constexpr char kRequireErrorGeneric[] = "error requiring module";
15-
1613
namespace Luau::Require
1714
{
1815

1916
using Error = std::optional<std::string>;
2017

21-
static Error toError(NavigationContext::NavigateResult result)
22-
{
23-
if (result == NavigationContext::NavigateResult::Success)
24-
return std::nullopt;
25-
if (result == NavigationContext::NavigateResult::Ambiguous)
26-
return kRequireErrorAmbiguous;
27-
else
28-
return kRequireErrorGeneric;
29-
}
30-
3118
static std::string extractAlias(std::string_view path)
3219
{
3320
// To ignore the '@' alias prefix when processing the alias
@@ -53,7 +40,7 @@ Navigator::Status Navigator::navigate(std::string path)
5340
{
5441
std::replace(path.begin(), path.end(), '\\', '/');
5542

56-
if (Error error = toError(navigationContext.reset(navigationContext.getRequirerIdentifier())))
43+
if (Error error = resetToRequirer())
5744
{
5845
errorHandler.reportError(*error);
5946
return Status::ErrorReported;
@@ -98,7 +85,7 @@ Error Navigator::navigateImpl(std::string_view path)
9885

9986
// If the alias is "@self", we reset to the requirer's context and
10087
// navigate directly from there.
101-
if (Error error = toError(navigationContext.reset(navigationContext.getRequirerIdentifier())))
88+
if (Error error = resetToRequirer())
10289
return error;
10390
if (Error error = navigateThroughPath(path))
10491
return error;
@@ -114,7 +101,7 @@ Error Navigator::navigateImpl(std::string_view path)
114101

115102
if (pathType == PathType::RelativeToCurrent || pathType == PathType::RelativeToParent)
116103
{
117-
if (Error error = toError(navigationContext.toParent()))
104+
if (Error error = navigateToParent(std::nullopt))
118105
return error;
119106
if (Error error = navigateThroughPath(path))
120107
return error;
@@ -133,6 +120,7 @@ Error Navigator::navigateThroughPath(std::string_view path)
133120
components = splitPath(components.second);
134121
}
135122

123+
std::optional<std::string> previousComponent;
136124
while (!(components.first.empty() && components.second.empty()))
137125
{
138126
if (components.first == "." || components.first.empty())
@@ -142,14 +130,15 @@ Error Navigator::navigateThroughPath(std::string_view path)
142130
}
143131
else if (components.first == "..")
144132
{
145-
if (Error error = toError(navigationContext.toParent()))
133+
if (Error error = navigateToParent(previousComponent))
146134
return error;
147135
}
148136
else
149137
{
150-
if (Error error = toError(navigationContext.toChild(std::string{components.first})))
138+
if (Error error = navigateToChild(std::string{components.first}))
151139
return error;
152140
}
141+
previousComponent = components.first;
153142
components = splitPath(components.second);
154143
}
155144

@@ -167,11 +156,11 @@ Error Navigator::navigateToAlias(const std::string& alias, const std::string& va
167156
}
168157
else if (pathType == PathType::Aliased)
169158
{
170-
return "@" + alias + " cannot point to other aliases";
159+
return "alias \"@" + alias + "\" cannot point to an aliased path (\"" + value + "\")";
171160
}
172161
else
173162
{
174-
if (Error error = toError(navigationContext.jumpToAlias(value)))
163+
if (Error error = jumpToAlias(value))
175164
return error;
176165
}
177166

@@ -189,7 +178,7 @@ Error Navigator::navigateToAndPopulateConfig(const std::string& desiredAlias)
189178
{
190179
std::optional<std::string> configContents = navigationContext.getConfig();
191180
if (!configContents)
192-
return "could not get configuration file contents";
181+
return "could not get configuration file contents to resolve alias \"" + desiredAlias + "\"";
193182

194183
Luau::ConfigOptions opts;
195184
Luau::ConfigOptions::AliasOptions aliasOpts;
@@ -205,4 +194,56 @@ Error Navigator::navigateToAndPopulateConfig(const std::string& desiredAlias)
205194
return std::nullopt;
206195
}
207196

197+
Error Navigator::resetToRequirer()
198+
{
199+
NavigationContext::NavigateResult result = navigationContext.reset(navigationContext.getRequirerIdentifier());
200+
if (result == NavigationContext::NavigateResult::Success)
201+
return std::nullopt;
202+
203+
std::string errorMessage = "could not reset to requiring context";
204+
if (result == NavigationContext::NavigateResult::Ambiguous)
205+
errorMessage += " (ambiguous)";
206+
return errorMessage;
207+
}
208+
209+
Error Navigator::jumpToAlias(const std::string& aliasPath)
210+
{
211+
NavigationContext::NavigateResult result = navigationContext.jumpToAlias(aliasPath);
212+
if (result == NavigationContext::NavigateResult::Success)
213+
return std::nullopt;
214+
215+
std::string errorMessage = "could not jump to alias \"" + aliasPath + "\"";
216+
if (result == NavigationContext::NavigateResult::Ambiguous)
217+
errorMessage += " (ambiguous)";
218+
return errorMessage;
219+
}
220+
221+
Error Navigator::navigateToParent(std::optional<std::string> previousComponent)
222+
{
223+
NavigationContext::NavigateResult result = navigationContext.toParent();
224+
if (result == NavigationContext::NavigateResult::Success)
225+
return std::nullopt;
226+
227+
std::string errorMessage;
228+
if (previousComponent)
229+
errorMessage = "could not get parent of component \"" + *previousComponent + "\"";
230+
else
231+
errorMessage = "could not get parent of requiring context";
232+
if (result == NavigationContext::NavigateResult::Ambiguous)
233+
errorMessage += " (ambiguous)";
234+
return errorMessage;
235+
}
236+
237+
Error Navigator::navigateToChild(const std::string& component)
238+
{
239+
NavigationContext::NavigateResult result = navigationContext.toChild(component);
240+
if (result == NavigationContext::NavigateResult::Success)
241+
return std::nullopt;
242+
243+
std::string errorMessage = "could not resolve child component \"" + component + "\"";
244+
if (result == NavigationContext::NavigateResult::Ambiguous)
245+
errorMessage += " (ambiguous)";
246+
return errorMessage;
247+
}
248+
208249
} // namespace Luau::Require

luau/Require/Runtime/include/Luau/Require.h

+10-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ struct luarequire_Configuration
106106
luarequire_WriteResult (*get_config)(lua_State* L, void* ctx, char* buffer, size_t buffer_size, size_t* size_out);
107107

108108
// Executes the module and places the result on the stack. Returns the
109-
// number of results placed on the stack.
109+
// number of results placed on the stack. Returning -1 directs the requiring
110+
// thread to yield. In this case, this thread should be resumed with the
111+
// module result pushed onto its stack.
110112
int (*load)(lua_State* L, void* ctx, const char* path, const char* chunkname, const char* contents);
111113
};
112114

@@ -130,3 +132,10 @@ LUALIB_API int luarequire_pushproxyrequire(lua_State* L, luarequire_Configuratio
130132
// result will always be immediately returned when the given path is required.
131133
// Expects the path and table to be passed as arguments on the stack.
132134
LUALIB_API int luarequire_registermodule(lua_State* L);
135+
136+
// Clears the entry associated with the given cache key from the require cache.
137+
// Expects the cache key to be passed as an argument on the stack.
138+
LUALIB_API int luarequire_clearcacheentry(lua_State* L);
139+
140+
// Clears all entries from the require cache.
141+
LUALIB_API int luarequire_clearcache(lua_State* L);

luau/Require/Runtime/src/Navigation.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include "lua.h"
77
#include "lualib.h"
88

9+
#include <string>
10+
911
static constexpr size_t initalFileBufferSize = 1024;
1012
static constexpr size_t initalIdentifierBufferSize = 64;
1113

@@ -111,14 +113,16 @@ std::optional<std::string> RuntimeNavigationContext::getStringFromCWriter(
111113
}
112114

113115

114-
RuntimeErrorHandler::RuntimeErrorHandler(lua_State* L)
116+
RuntimeErrorHandler::RuntimeErrorHandler(lua_State* L, std::string requiredPath)
115117
: L(L)
118+
, errorPrefix("error requiring module \"" + std::move(requiredPath) + "\": ")
116119
{
117120
}
118121

119122
void RuntimeErrorHandler::reportError(std::string message)
120123
{
121-
luaL_errorL(L, "%s", message.c_str());
124+
std::string fullError = errorPrefix + std::move(message);
125+
luaL_errorL(L, "%s", fullError.c_str());
122126
}
123127

124128
} // namespace Luau::Require

luau/Require/Runtime/src/Navigation.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "Luau/RequireNavigator.h"
55
#include "Luau/Require.h"
66

7+
#include <string>
8+
79
struct lua_State;
810
struct luarequire_Configuration;
911

@@ -48,11 +50,12 @@ class RuntimeNavigationContext : public NavigationContext
4850
class RuntimeErrorHandler : public ErrorHandler
4951
{
5052
public:
51-
RuntimeErrorHandler(lua_State* L);
53+
RuntimeErrorHandler(lua_State* L, std::string requiredPath);
5254
void reportError(std::string message) override;
5355

5456
private:
5557
lua_State* L;
58+
std::string errorPrefix;
5659
};
5760

5861
} // namespace Luau::Require

luau/Require/Runtime/src/Require.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static int pushrequireclosureinternal(
5353
lua_pushlightuserdata(L, ctx);
5454

5555
// require-like closure captures config and ctx as upvalues
56-
lua_pushcclosure(L, requirelikefunc, debugname, 2);
56+
lua_pushcclosurek(L, requirelikefunc, debugname, 2, Luau::Require::lua_requirecont);
5757
return 1;
5858
}
5959

@@ -77,3 +77,13 @@ int luarequire_registermodule(lua_State* L)
7777
{
7878
return Luau::Require::registerModuleImpl(L);
7979
}
80+
81+
int luarequire_clearcacheentry(lua_State* L)
82+
{
83+
return Luau::Require::clearCacheEntry(L);
84+
}
85+
86+
int luarequire_clearcache(lua_State* L)
87+
{
88+
return Luau::Require::clearCache(L);
89+
}

0 commit comments

Comments
 (0)