Skip to content

Commit 2ba48a9

Browse files
committed
comment out global functions that don't act right in a definitions file
1 parent 973a699 commit 2ba48a9

4 files changed

Lines changed: 61 additions & 35 deletions

File tree

generated/secondlife.d.luau

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -230,27 +230,27 @@ export type PrimParamsSetterType = typeof(
230230
)
231231

232232

233-
declare function assert<T>(value: T?, message: string?): T -- magic type
233+
-- declare function assert<T>(value: T?, message: string?): T -- magic type
234234
declare function dangerouslyexecuterequiredmodule(f: (...any) -> ...any): ...any
235235
declare function error(obj: any, level: number?): never
236236
declare function gcinfo(): number
237237
declare getfenv: nil
238-
declare function getmetatable(obj: any): {[any]: any}?
238+
-- declare function getmetatable(obj: any): {[any]: any}? -- builtin
239239
declare function ipairs<V>(t: {V}): (({V}, number) -> (number?, V), {V}, number)
240240
declare loadstring: nil
241241
declare function newproxy(mt: boolean?): any
242-
declare function next<K, V>(t: {[K]: V}, i: K?): (K, V)?
243-
declare function pairs<K, V>(t: {[K]: V}): (({[K], V}, K) -> (K?, V), {[K], V}, K)
242+
-- declare function next<K, V>(t: {[K]: V}, i: K?): (K, V)? -- builtin
243+
-- declare function pairs<K, V>(t: {[K]: V}): (({[K], V}, K) -> (K?, V), {[K], V}, K) -- builtin
244244
declare function pcall<A..., R...>(f: (A...) -> R..., A...): (boolean, R...)
245245
declare function print(...any): ()
246246
declare function rawequal(a: any, b: any): boolean
247247
declare function rawget<K, V>(t: {[K]: V}, k: K): V?
248248
declare function rawlen<K, V>(t: {[K]: V} | string): number
249249
declare function rawset<K, V>(t: {[K]: V}, k: K, v: V): {[K]: V}
250-
declare function require(target: string): any -- magic type
251-
declare function select(i: string | number, ...any): any -- magic type
250+
-- declare function require(target: string): any -- magic type
251+
-- declare function select(i: string | number, ...any): any -- magic type
252252
declare setfenv: nil
253-
declare function setmetatable(t: { [any]: any }, mt: { [any]: any }?): () -- magic type
253+
-- declare function setmetatable(t: { [any]: any }, mt: { [any]: any }?): () -- builtin, magic type
254254
declare function tonumber(s: string, base: number?): number?
255255
declare function toquaternion(val: string? | quaternion): quaternion?
256256
declare function torotation(val: string? | quaternion): quaternion?
@@ -472,23 +472,23 @@ declare quaternion: ((x: number, y: number, z: number, s: number) -> quaternion)
472472
---------------------------
473473

474474
declare string: {
475-
byte: (s: string, i: number?, j: number?) -> ...number,
476-
char: (...number) -> string,
477-
find: (s: string, pattern: string, init: number?, plain: boolean?) -> (number?, number?, ...string), -- magic type
478-
format: (formatstring: string, ...any) -> string, -- magic type
479-
gmatch: (s: string, pattern: string) -> () -> ...string, -- magic type
480-
gsub: (s: string, pattern: string, repl: string | { [string]: string } | (...string) -> string, maxn: number?) -> (string, number),
481-
len: (s: string) -> number,
482-
lower: (s: string) -> string,
483-
match: (s: string, pattern: string, init: number?) -> ...string, -- magic type
484-
pack: (fmt: string, ...any) -> string,
485-
packsize: (fmt: string) -> number,
486-
rep: (s: string, n: number) -> string,
487-
reverse: (s: string) -> string,
488-
split: (s: string, separator: string?) -> {string},
489-
sub: (s: string, i: number, j: number?) -> string,
490-
unpack: (fmt: string, s: string, init: number?) -> ...any,
491-
upper: (s: string) -> string,
475+
byte: (s: string, i: number?, j: number?) -> ...number, -- builtin
476+
char: (...number) -> string, -- builtin
477+
find: (s: string, pattern: string, init: number?, plain: boolean?) -> (number?, number?, ...string), -- builtin, magic type
478+
format: (formatstring: string, ...any) -> string, -- builtin, magic type
479+
gmatch: (s: string, pattern: string) -> () -> ...string, -- builtin, magic type
480+
gsub: (s: string, pattern: string, repl: string | { [string]: string } | (...string) -> string, maxn: number?) -> (string, number), -- builtin
481+
len: (s: string) -> number, -- builtin
482+
lower: (s: string) -> string, -- builtin
483+
match: (s: string, pattern: string, init: number?) -> ...string, -- builtin, magic type
484+
pack: (fmt: string, ...any) -> string, -- builtin
485+
packsize: (fmt: string) -> number, -- builtin
486+
rep: (s: string, n: number) -> string, -- builtin
487+
reverse: (s: string) -> string, -- builtin
488+
split: (s: string, separator: string?) -> {string}, -- builtin
489+
sub: (s: string, i: number, j: number?) -> string, -- builtin
490+
unpack: (fmt: string, s: string, init: number?) -> ...any, -- builtin
491+
upper: (s: string) -> string, -- builtin
492492
}
493493

494494

lsl_definitions/generators/slua.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ def gen_luau_lsp_defs(definitions: LSLDefinitions, slua_definitions: SLuaDefinit
5454
for func in slua_definitions.functions:
5555
if func.private or func.local_only:
5656
continue
57+
if not func.typechecker_flags.fully_defined:
58+
defs.write("-- ")
5759
defs.write("declare ")
5860
func.write_luau_global_def(defs)
5961
for module in sorted(slua_definitions.modules, key=lambda x: x.name):

lsl_definitions/slua.py

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,30 @@ def to_luau_def(self) -> str:
7171
return f"{self.name}: {self.type}"
7272

7373

74+
@dataclasses.dataclass
75+
class SLuaTypecheckerFlags:
76+
"""Flags specific to the internals of luau-analyze and luau-lsp."""
77+
78+
builtin: bool = False
79+
"""This function is defined in BuiltinDefinitions.cpp, rather than EmbeddedBuiltinDefinitions.cpp."""
80+
magic: bool = False
81+
"""The typechecker has custom logic for this function."""
82+
83+
@property
84+
def fully_defined(self) -> bool:
85+
"""True if this function is fully defined and won't cause issues for the typechecker."""
86+
return not self.builtin and not self.magic
87+
88+
@property
89+
def comment_string(self) -> str:
90+
comments = []
91+
if self.builtin:
92+
comments.append("builtin")
93+
if self.magic:
94+
comments.append("magic type")
95+
return " -- " + ", ".join(comments) if comments else ""
96+
97+
7498
@dataclasses.dataclass
7599
class SLuaFunctionBase(abc.ABC):
76100
name: str = ""
@@ -111,8 +135,10 @@ class SLuaFunction(SLuaFunctionBase):
111135
must_use: bool = False
112136
"""Emit a warning if the return value is not used.
113137
See https://kampfkarren.github.io/selene/usage/std.html#must_use."""
114-
magic_type: bool = False
115-
"""The typechecker has custom logic for this function."""
138+
typechecker_flags: SLuaTypecheckerFlags = dataclasses.field(
139+
default_factory=SLuaTypecheckerFlags
140+
)
141+
"""Flags specific to the internals of luau-analyze and luau-lsp."""
116142
overloads: List[SLuaFunctionOverload] = dataclasses.field(default_factory=list)
117143

118144
@property
@@ -163,8 +189,7 @@ def write_luau_global_def(self, f: TextIO, indent: int = 0) -> None:
163189
f.write(self.type_parameters_string)
164190
f.write(self.parameters_string)
165191
f.write(f": {self.return_type}")
166-
if self.magic_type:
167-
f.write(" -- magic type")
192+
f.write(self.typechecker_flags.comment_string)
168193
f.write("\n")
169194

170195
def write_luau_table_def(self, f: TextIO, indent: int = 0, suffix=",") -> None:
@@ -181,8 +206,7 @@ def write_luau_table_def(self, f: TextIO, indent: int = 0, suffix=",") -> None:
181206
f.write(overload.type_def_string)
182207
f.write(")")
183208
f.write(suffix)
184-
if self.magic_type:
185-
f.write(" -- magic type")
209+
f.write(self.typechecker_flags.comment_string)
186210
f.write("\n")
187211

188212

@@ -769,7 +793,7 @@ def _validate_function(
769793
local_only=data.get("local-only", False),
770794
slua_removed=data.get("slua-removed", False),
771795
must_use=data.get("must-use", False),
772-
magic_type=data.get("magic-type", False),
796+
typechecker_flags=SLuaTypecheckerFlags(**data.get("typechecker", {})),
773797
)
774798
self._validate_identifier(func.name)
775799
self._validate_scope(func.name, scope)

slua_definitions.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ functions:
408408
comment: The object to get the metatable for.
409409
type: any
410410
return-type: "{[any]: any}?"
411-
typechecker: {builtin: true}
411+
typechecker: {builtin: true} # builtin due to FFlag::LuauSolverV2
412412
fastcall: true
413413
- name: graphheap
414414
comment: Writes the contents of heap to the given file in JSON format.
@@ -460,7 +460,7 @@ functions:
460460
comment: Optional key to start traversal after.
461461
type: K?
462462
return-type: (K, V)?
463-
typechecker: {builtin: true}
463+
typechecker: {builtin: true} # builtin due to FFlag::LuauStorePolarityInline
464464
- name: pairs
465465
comment: Returns an iterator for all key-value pairs in the table.
466466
type-parameters: [K, V]
@@ -469,7 +469,7 @@ functions:
469469
comment: The table to iterate over.
470470
type: "{[K]: V}"
471471
return-type: "(({[K], V}, K) -> (K?, V), {[K], V}, K)"
472-
typechecker: {builtin: true}
472+
typechecker: {builtin: true} # builtin due to FFlag::LuauStorePolarityInline
473473
- name: pcall
474474
comment: Calls function f with parameters args, returning success and function results or an error.
475475
type-parameters: [A..., R...]
@@ -575,7 +575,7 @@ functions:
575575
type: "{ [any]: any }?"
576576
return-type: ()
577577
fastcall: true
578-
typechecker: {builtin: true, magic: true}
578+
typechecker: {builtin: true, magic: true} # builtin due to FFlag::LuauSolverV2
579579
- name: tonumber
580580
comment: Converts the input string to a number in the specified base.
581581
parameters:

0 commit comments

Comments
 (0)