Skip to content

Commit aae58a5

Browse files
committed
Run analysis on CI
1 parent 1ebb120 commit aae58a5

File tree

9 files changed

+167
-30
lines changed

9 files changed

+167
-30
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,6 @@ jobs:
5959
- name: Build
6060
# Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
6161
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} --parallel
62+
63+
- name: Run Analysis
64+
run: ${{ steps.strings.outputs.build-output-dir }}/lute --check std batteries examples

.luaurc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"aliases": {
44
"batteries": "batteries",
55
"std": "std",
6+
"lute": "definitions"
67
}
78
}

cli/tc.cpp

Lines changed: 60 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,9 @@
44
#include "Luau/Error.h"
55
#include "Luau/Transpiler.h"
66
#include "Luau/TypeAttach.h"
7+
#include "Luau/Require.h"
78

8-
static const std::string kLuteDefinitions = R"LUTE_TYPES(
9-
-- Net api
10-
declare net: {
11-
get: (string) -> string,
12-
getAsync: (string) -> string,
13-
}
14-
-- fs api
15-
declare class file end
16-
declare fs: {
17-
-- probably not the correct sig
18-
open: (string, "r" | "w" | "a" | "r+" | "w+") -> file,
19-
close: (file) -> (),
20-
read: (file) -> string,
21-
write: (file, string) -> (),
22-
readfiletostring : (string) -> string,
23-
writestringtofile : (string, string) -> (),
24-
-- is this right? I feel like we want a promise type here
25-
readasync : (string) -> string,
26-
}
27-
28-
-- globals
29-
declare function spawn(path: string): any
30-
31-
)LUTE_TYPES";
9+
LUAU_FASTFLAG(LuauSolverV2)
3210

3311
struct LuteFileResolver : Luau::FileResolver
3412
{
@@ -57,7 +35,21 @@ struct LuteFileResolver : Luau::FileResolver
5735

5836
std::optional<Luau::ModuleInfo> resolveModule(const Luau::ModuleInfo* context, Luau::AstExpr* node) override
5937
{
60-
// TODO: Need to handle requires
38+
if (Luau::AstExprConstantString* expr = node->as<Luau::AstExprConstantString>())
39+
{
40+
std::string path{expr->value.data, expr->value.size};
41+
42+
AnalysisRequireContext requireContext{context->name};
43+
AnalysisCacheManager cacheManager;
44+
AnalysisErrorHandler errorHandler;
45+
46+
RequireResolver resolver(path, requireContext, cacheManager, errorHandler);
47+
RequireResolver::ResolvedRequire resolvedRequire = resolver.resolveRequire();
48+
49+
if (resolvedRequire.status == RequireResolver::ModuleStatus::FileRead)
50+
return {{resolvedRequire.identifier}};
51+
}
52+
6153
return std::nullopt;
6254
}
6355

@@ -69,7 +61,46 @@ struct LuteFileResolver : Luau::FileResolver
6961
}
7062

7163
private:
72-
// TODO: add require resolver;
64+
struct AnalysisRequireContext : RequireResolver::RequireContext
65+
{
66+
explicit AnalysisRequireContext(std::string path)
67+
: path(std::move(path))
68+
{
69+
}
70+
71+
std::string getPath() override
72+
{
73+
return path;
74+
}
75+
76+
bool isRequireAllowed() override
77+
{
78+
return true;
79+
}
80+
81+
bool isStdin() override
82+
{
83+
return path == "-";
84+
}
85+
86+
std::string createNewIdentifer(const std::string& path) override
87+
{
88+
return path;
89+
}
90+
91+
private:
92+
std::string path;
93+
};
94+
95+
struct AnalysisCacheManager : public RequireResolver::CacheManager
96+
{
97+
AnalysisCacheManager() = default;
98+
};
99+
100+
struct AnalysisErrorHandler : RequireResolver::ErrorHandler
101+
{
102+
AnalysisErrorHandler() = default;
103+
};
73104
};
74105

75106
struct LuteConfigResolver : Luau::ConfigResolver
@@ -182,6 +213,9 @@ static bool reportModuleResult(Luau::Frontend& frontend, const Luau::ModuleName&
182213

183214
int typecheck(const std::vector<std::string> sourceFiles)
184215
{
216+
// Lute only supports the new type solver
217+
FFlag::LuauSolverV2.value = true;
218+
185219
Luau::Mode mode = Luau::Mode::Strict;
186220
bool annotate = true;
187221
std::string basePath = "";
@@ -195,9 +229,6 @@ int typecheck(const std::vector<std::string> sourceFiles)
195229
Luau::Frontend frontend(&fileResolver, &configResolver, frontendOptions);
196230

197231
Luau::registerBuiltinGlobals(frontend, frontend.globals);
198-
Luau::LoadDefinitionFileResult loadResult =
199-
frontend.loadDefinitionFile(frontend.globals, frontend.globals.globalScope, kLuteDefinitions, "@luau", false, false);
200-
LUAU_ASSERT(loadResult.success);
201232
Luau::freeze(frontend.globals.globalTypes);
202233

203234
for (const std::string& path : sourceFiles)

definitions/fs.luau

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
local fs = {}
2+
3+
export type FileHandle = {
4+
fd: number,
5+
err: number,
6+
}
7+
8+
export type FileType = "file" | "dir" | "link" | "fifo" | "socket" | "char" | "block" | "unknown"
9+
10+
export type DirectoryEntry = {
11+
name: string,
12+
type: FileType,
13+
}
14+
15+
function fs.open(path: string): FileHandle
16+
error("not implemented")
17+
end
18+
19+
function fs.read(handle: FileHandle): string
20+
error("not implemented")
21+
end
22+
23+
function fs.write(handle: FileHandle, contents: string): ()
24+
error("not implemented")
25+
end
26+
27+
function fs.close(handle: FileHandle): ()
28+
error("not implemented")
29+
end
30+
31+
function fs.remove(path: string): ()
32+
error("not implemented")
33+
end
34+
35+
function fs.type(path: string): FileType
36+
error("not implemented")
37+
end
38+
39+
function fs.mkdir(path: string): ()
40+
error("not implemented")
41+
end
42+
43+
function fs.listdir(path: string): { DirectoryEntry }
44+
error("not implemented")
45+
end
46+
47+
function fs.rmdir(path: string): ()
48+
error("not implemented")
49+
end
50+
51+
function fs.readfiletostring(filepath: string): string
52+
error("not implemented")
53+
end
54+
55+
function fs.writestringtofile(filepath: string, contents: string): ()
56+
error("not implemented")
57+
end
58+
59+
function fs.readasync(filepath: string): string
60+
error("not implemented")
61+
end
62+
63+
return fs

definitions/luau.luau

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
local luau = {}
2+
3+
type ParseResult = {
4+
root: any,
5+
lines: number,
6+
}
7+
8+
function luau.parse(source: string): ParseResult
9+
error("not implemented")
10+
end
11+
12+
function luau.parseexpr(source: string): ParseResult
13+
error("not implemented")
14+
end
15+
16+
return luau

definitions/net.luau

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
local net = {}
2+
3+
function net.get(url: string): string
4+
error("not implemented")
5+
end
6+
7+
function net.getAsync(url: string): string
8+
error("not implemented")
9+
end
10+
11+
return net

definitions/task.luau

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
local task = {}
2+
3+
function task.defer() end
4+
5+
return task

definitions/vm.luau

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
local vm = {}
2+
3+
function vm.spawn(file: string): any
4+
error("not implemented")
5+
end
6+
7+
return vm

vm/include/lute/vm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace vm
1616
int lua_defer(lua_State* L);
1717

1818
static const luaL_Reg lib[] = {
19-
{"create", lua_spawn},
19+
{"spawn", lua_spawn},
2020
{nullptr, nullptr},
2121
};
2222

0 commit comments

Comments
 (0)