Skip to content

Commit 2b58e3c

Browse files
committed
v0.16.0+luau700
1 parent f5c54a4 commit 2b58e3c

File tree

9 files changed

+117
-36
lines changed

9 files changed

+117
-36
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "luau0-src"
3-
version = "0.15.11+luau697"
3+
version = "0.16.0+luau700"
44
authors = ["Aleksandr Orlenko <[email protected]>"]
55
edition = "2021"
66
repository = "https://github.com/mlua-rs/luau-src-rs"
File renamed without changes.
File renamed without changes.

luau/Config/include/Luau/Config.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,6 @@ struct Config
5454
DenseHashMap<std::string, std::unique_ptr<std::string>> configLocationCache{""};
5555
};
5656

57-
struct ConfigResolver
58-
{
59-
virtual ~ConfigResolver() {}
60-
61-
virtual const Config& getConfig(const ModuleName& name) const = 0;
62-
};
63-
64-
struct NullConfigResolver : ConfigResolver
65-
{
66-
Config defaultConfig;
67-
68-
virtual const Config& getConfig(const ModuleName& name) const override;
69-
};
70-
7157
std::optional<std::string> parseModeString(Mode& mode, const std::string& modeString, bool compat = false);
7258
std::optional<std::string> parseLintRuleString(
7359
LintOptions& enabledLints,

luau/Config/src/Config.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,12 @@ bool isValidAlias(const std::string& alias)
173173
if (!aliasIsNotAPath)
174174
return false;
175175

176-
for (char ch : alias)
176+
for (size_t i = 0; i < alias.size(); i++)
177177
{
178+
char ch = alias[i];
179+
if (i == 0 && ch == '@')
180+
continue;
181+
178182
bool isupper = 'A' <= ch && ch <= 'Z';
179183
bool islower = 'a' <= ch && ch <= 'z';
180184
bool isdigit = '0' <= ch && ch <= '9';
@@ -366,9 +370,4 @@ Error parseConfig(const std::string& contents, Config& config, const ConfigOptio
366370
);
367371
}
368372

369-
const Config& NullConfigResolver::getConfig(const ModuleName& name) const
370-
{
371-
return defaultConfig;
372-
}
373-
374373
} // namespace Luau

luau/Require/include/Luau/RequireNavigator.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ struct lua_State;
2727
namespace Luau::Require
2828
{
2929

30+
class AliasCycleTracker;
31+
3032
// The ErrorHandler interface is used to report errors during navigation.
3133
// The default implementation does nothing but can be overridden to enable
3234
// custom error handling behavior.
@@ -110,8 +112,8 @@ class Navigator
110112
using Error = std::optional<std::string>;
111113
[[nodiscard]] Error navigateImpl(std::string_view path);
112114
[[nodiscard]] Error navigateThroughPath(std::string_view path);
113-
[[nodiscard]] Error navigateToAlias(const std::string& alias, const std::string& value);
114-
[[nodiscard]] Error navigateToAndPopulateConfig(const std::string& desiredAlias);
115+
[[nodiscard]] Error navigateToAlias(const std::string& alias, const Config& config, AliasCycleTracker cycleTracker);
116+
[[nodiscard]] Error navigateToAndPopulateConfig(const std::string& desiredAlias, Config& config);
115117

116118
[[nodiscard]] Error resetToRequirer();
117119
[[nodiscard]] Error jumpToAlias(const std::string& aliasPath);
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
2+
#include "AliasCycleTracker.h"
3+
4+
#include "Luau/DenseHash.h"
5+
#include "Luau/StringUtils.h"
6+
7+
#include <optional>
8+
#include <string>
9+
#include <vector>
10+
11+
namespace Luau::Require
12+
{
13+
14+
std::optional<std::string> AliasCycleTracker::add(std::string alias)
15+
{
16+
if (seen.contains(alias))
17+
return Luau::format("detected alias cycle (%s)", getStringifiedCycle(alias).c_str());
18+
19+
seen.insert(alias);
20+
ordered.push_back(std::move(alias));
21+
return std::nullopt;
22+
}
23+
24+
std::string AliasCycleTracker::getStringifiedCycle(const std::string& repeated) const
25+
{
26+
std::string result;
27+
bool inCycle = false;
28+
for (const std::string& item : ordered)
29+
{
30+
if (inCycle)
31+
{
32+
result += " -> ";
33+
result += "@" + item;
34+
}
35+
if (item == repeated)
36+
{
37+
inCycle = true;
38+
result += "@" + item;
39+
}
40+
}
41+
result += " -> " + ("@" + repeated);
42+
return result;
43+
}
44+
45+
} // namespace Luau::Require
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
2+
#pragma once
3+
4+
#include "Luau/DenseHash.h"
5+
6+
#include <optional>
7+
#include <string>
8+
#include <vector>
9+
10+
namespace Luau::Require
11+
{
12+
13+
class AliasCycleTracker
14+
{
15+
public:
16+
std::optional<std::string> add(std::string alias);
17+
18+
private:
19+
std::string getStringifiedCycle(const std::string& repeated) const;
20+
21+
DenseHashSet<std::string> seen{""};
22+
std::vector<std::string> ordered;
23+
};
24+
25+
} // namespace Luau::Require

luau/Require/src/RequireNavigator.cpp

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "Luau/RequireNavigator.h"
44

5+
#include "AliasCycleTracker.h"
56
#include "PathUtilities.h"
67

78
#include "Luau/Config.h"
@@ -76,10 +77,11 @@ Error Navigator::navigateImpl(std::string_view path)
7677
}
7778
);
7879

79-
if (Error error = navigateToAndPopulateConfig(alias))
80+
Config config;
81+
if (Error error = navigateToAndPopulateConfig(alias, config))
8082
return error;
8183

82-
if (!foundAliasValue)
84+
if (!config.aliases.contains(alias))
8385
{
8486
if (alias != "self")
8587
return "@" + alias + " is not a valid alias";
@@ -94,7 +96,7 @@ Error Navigator::navigateImpl(std::string_view path)
9496
return std::nullopt;
9597
}
9698

97-
if (Error error = navigateToAlias(alias, *foundAliasValue))
99+
if (Error error = navigateToAlias(alias, config, {}))
98100
return error;
99101
if (Error error = navigateThroughPath(path))
100102
return error;
@@ -146,8 +148,9 @@ Error Navigator::navigateThroughPath(std::string_view path)
146148
return std::nullopt;
147149
}
148150

149-
Error Navigator::navigateToAlias(const std::string& alias, const std::string& value)
151+
Error Navigator::navigateToAlias(const std::string& alias, const Config& config, AliasCycleTracker cycleTracker)
150152
{
153+
std::string value = config.aliases.find(alias)->value;
151154
PathType pathType = getPathType(value);
152155

153156
if (pathType == PathType::RelativeToCurrent || pathType == PathType::RelativeToParent)
@@ -157,7 +160,33 @@ Error Navigator::navigateToAlias(const std::string& alias, const std::string& va
157160
}
158161
else if (pathType == PathType::Aliased)
159162
{
160-
return "alias \"@" + alias + "\" cannot point to an aliased path (\"" + value + "\")";
163+
if (Error error = cycleTracker.add(alias))
164+
return error;
165+
166+
std::string nextAlias = extractAlias(value);
167+
if (config.aliases.contains(nextAlias))
168+
{
169+
if (Error error = navigateToAlias(nextAlias, config, std::move(cycleTracker)))
170+
return error;
171+
}
172+
else
173+
{
174+
Config parentConfig;
175+
if (Error error = navigateToAndPopulateConfig(nextAlias, parentConfig))
176+
return error;
177+
if (parentConfig.aliases.contains(nextAlias))
178+
{
179+
if (Error error = navigateToAlias(nextAlias, parentConfig, {}))
180+
return error;
181+
}
182+
else
183+
{
184+
return "@" + nextAlias + " is not a valid alias";
185+
}
186+
}
187+
188+
if (Error error = navigateThroughPath(value))
189+
return error;
161190
}
162191
else
163192
{
@@ -168,11 +197,9 @@ Error Navigator::navigateToAlias(const std::string& alias, const std::string& va
168197
return std::nullopt;
169198
}
170199

171-
Error Navigator::navigateToAndPopulateConfig(const std::string& desiredAlias)
200+
Error Navigator::navigateToAndPopulateConfig(const std::string& desiredAlias, Config& config)
172201
{
173-
Luau::Config config;
174-
175-
while (!foundAliasValue)
202+
while (!config.aliases.contains(desiredAlias))
176203
{
177204
NavigationContext::NavigateResult result = navigationContext.toParent();
178205
if (result == NavigationContext::NavigateResult::Ambiguous)
@@ -193,7 +220,7 @@ Error Navigator::navigateToAndPopulateConfig(const std::string& desiredAlias)
193220
{
194221
if (navigationContext.getConfigBehavior() == NavigationContext::ConfigBehavior::GetAlias)
195222
{
196-
foundAliasValue = navigationContext.getAlias(desiredAlias);
223+
config.setAlias(desiredAlias, *navigationContext.getAlias(desiredAlias), /* configLocation = */ "unused");
197224
break;
198225
}
199226

@@ -221,9 +248,6 @@ Error Navigator::navigateToAndPopulateConfig(const std::string& desiredAlias)
221248
if (Error error = Luau::extractLuauConfig(*configContents, config, std::move(opts.aliasOptions), std::move(callbacks)))
222249
return error;
223250
}
224-
225-
if (config.aliases.contains(desiredAlias))
226-
foundAliasValue = config.aliases[desiredAlias].value;
227251
}
228252
};
229253

0 commit comments

Comments
 (0)