Commit graph

464 commits

Author SHA1 Message Date
Arseny Kapoulkine
1c6a7e61a6
RFC: Do not implement safe navigation operator
This meta-RFC proposes removing the previously accepted RFC on safe navigation operator. This is probably going to be disappointing but I feel like this is the best course of action that reflects our ideals in language evolution.

## Problem

The RFC specifies a new navigation operator, `?.`, that returns `nil` when the left hand side is `nil`, as well as skipping the rest of the indexed chain evaluation (e.g. `vehicle.Turret?.Frame.CFrame.LookVector` evaluates to `nil` if `vehicle.Turret` is `nil`). Initially the RFC only specifies this one operator, although future extensions like `?:`, `?[]`, `?()` are possible -- the RFC stands on its own, but it opens the path to more "nil-safe" operators in the future.

Unfortunately, we discovered a significant problem (after the RFC was merged) in the operator, in its interaction with the Roblox instance hierarchy. This is a userdata based DOM tree that (unfortunately) overloads __index to access children, and (fortunately?) attempting to access a non-existent child raises an error. As such, it's not compatible with this proposal in the sense that trying to use `?.` in combination with the instance hierarchy will only work if the child is present, and will raise an error otherwise.

## Alternatives

There are several ways to address that problem and still ship this; all of them are unsatisfactory:

1. We can change the instance hierarchy at Roblox to return `nil` instead. If Luau existed 15 years ago with `?.` feature, we probably would not have implemented dot-access in the first place, or maybe had it return `nil`... However, at present this is a very significant change that very dramatically changes the contract around instance access and may have large unintended consequences. It's something that isn't obviously a good idea in the first place, and not something we'd want to do for a single language feature as other features may pull us into maintaining the status quo instead.

2. We can ignore this footgun and/or try to help with static analysis. The issue here is that static analysis must depend on us knowing the precise type and tree location of the first object in the chain, something that will very often not work reliably, and the pattern is too convenient and too common - so we should probably admit that with or without analysis, people will be hitting this often accidentally. This can be treated as a reasonable compromise - we're adding a convenient feature that requires a little care around some constructs, and as long as the users "know what they are doing" it's going to be okay - but my perspective is that we should try to keep the language as free of footguns / as orthogonal / as simple as possible, and any feature that has significant issues around these must be a critical feature we can't live without for us to tolerate these.

3. We can introduce a new metamethod, `__safeindex`, that will be called for `?.` instead of `__index`, if present. This metamethod can then be defined for Roblox instance hierarchy to return `nil`. My perspective here is that while it removes the footgun, it violates the orthogonality / simplicity of the null safety operators in general - just for this one operator it now requires new VM opcodes, new table lookup functions that use either `__safeindex` or `__index` metamethods, and creates questions for any future null safety operators wrt whether or not we will go through the same process for consistency (eventually yielding `__safecall`, `__safenewindex`, `__safeadd` etc. in the extreme), or if `__safeindex` is a one-off ad hoc addition to solve a specific problem we have for one of the (well, largest) users of Luau language. This turns the safe navigation operator from "cheap convenient syntax sugar" to "full blown operator every element of the stack must be aware of", which - again, in my perspective - shifts the balance for this feature, as the costs no longer seem to justify the benefit.

## Conclusion

While we have ways forward for this proposal, they either make the language less robust [when used in Roblox environment], mean this feature is much less orthogonal/simple than initially understood, or mean we need to dramatically change the access rules [in Roblox environment] for a single small language feature.

While it's unusual to judge a feature of a general purpose language based on a single user of the said language, given Luau's heritage and the fact that the majority of the programmers who interact with Luau presently use it in context of Roblox, I think we must take this into account. These situations will probably happen rarely - in fact it's the first feature proposal like this! - but when they do, we should strive to keep the language simple and devoid of footguns, thus I believe it's overall beneficial to maintain the status quo and not implement this proposal.

As suggested in the RFC, this still means you can use `and` operator as a replacement for very basic single-element chains, e.g. `dog and dog.name`, but for more complex chains with `nil`s unfortunately the existing longer patterns must be used. We plan to look into common subexpression elimination that, under certain conditions, will allow us to maximally efficiently evaluate seemingly redundant expressions like `foo and foo.bar and foo.bar.baz`, and if that doesn't work you'd need to settle for multiple expressions to evaluate these chains efficiently in presence of nils - that said, I think in this case shorter code for some cases like this is not a strong enough motivation to ship the feature in the face of the problem discussed above.

cc @Kampfkarren for visibility
2022-05-24 16:31:04 -07:00
Petri Häkkinen
fb9c4311d8
Add lua_tolightuserdata, optimized lua_topointer (#496)
Co-authored-by: Petri Häkkinen <petrih@rmd.remedy.fi>
2022-05-24 08:59:12 -07:00
Arseny Kapoulkine
70ff6b4347
Update performance.md (#494)
Add a section on table length optimizations and reword the table iteration section a bit to account for generalized iteration.
2022-05-20 13:00:53 -07:00
Arseny Kapoulkine
f5923aefeb
Sync to upstream/release/527 (#491) 2022-05-19 17:02:24 -07:00
JohnnyMorganz
8b4c6aabc2
Fix findAstAncestry when position is at eof (#490) 2022-05-18 16:26:05 -07:00
JohnnyMorganz
f2191b9e4d
Respect useLineBreaks for union/intersect toString (#487)
* Respect useLineBreaks for union/intersect toString

* Apply suggestions from code review

Co-authored-by: Andy Friesen <andy.friesen@gmail.com>

Co-authored-by: Andy Friesen <andy.friesen@gmail.com>
2022-05-17 11:22:54 -07:00
JohnnyMorganz
ab4bb355a3
Add ToStringOptions.hideFunctionSelfArgument (#486)
Adds an option to hide the `self: type` argument as the first argument in the string representation of a named function type var if the ftv hasSelf.

Also added in a test for the original output (i.e., if the option was disabled)

I didn't apply this option in the normal `Luau::toString()` function, just the `Luau::toStringNamedFunction()` one (for my usecase, that is enough + I felt like a named function would include the method colon `:` to signify self). If this is unintuitive, I can also add it to the general `Luau::toString()` function.
2022-05-16 09:50:15 -07:00
Arseny Kapoulkine
a36b1eb29b
Sync to upstream/release/527 (#481) 2022-05-13 12:36:37 -07:00
Arseny Kapoulkine
87fe15ac51
Update STATUS.md
Mark last table subtyping RFC as implemented
2022-05-12 10:08:36 -07:00
Arseny Kapoulkine
a775e6dc8e
Mark last table subtyping RFC as implemented 2022-05-12 10:08:10 -07:00
Arseny Kapoulkine
105e74c7d9
Update STATUS.md
Both generalized iteration and LBC are implemented but not fully enabled in Roblox yet.
2022-05-11 15:14:51 -07:00
Arseny Kapoulkine
f3f231ea6b
Update compatibility.md
Update `__pairs` note with `__iter`, change `__len` to unsure as with `__iter` lack of `__len` on tables is the only issue preventing complete user created containers.
2022-05-09 18:38:10 -07:00
Arseny Kapoulkine
be0b7d07e2
Update sandbox.md
Replace debug.getinfo with debug.info
2022-05-09 18:34:31 -07:00
Arseny Kapoulkine
7935f9f8b6
Update sandbox.md
Reword the GC docs to avoid back-referencing the thread identity mechanism, since it's entirely Roblox-side and isn't fully documented here anymore.
2022-05-09 18:33:53 -07:00
Arseny Kapoulkine
72d8d44343
Add documentation for generalized iteration (#475) 2022-05-05 17:05:57 -07:00
Arseny Kapoulkine
e9cc76a3d5
Sync to upstream/release/526 (#477) 2022-05-05 17:03:43 -07:00
phoebe
57016582a7
fix feed link (#476) 2022-05-05 14:37:27 -07:00
byte-chan™
9156b5ae6d
Fix non-C locale issues in REPL (#474) 2022-05-04 12:27:12 -07:00
Alexander McCord
47a8d28aa9
Fix a typo in recap. (#472) 2022-05-03 16:12:59 -07:00
Andy Friesen
9bc71c4b13
April 2022 recap (#470) 2022-05-03 15:29:01 -07:00
Andy Friesen
448f03218f
Add attribution for Result.ts (#468) 2022-04-29 09:33:30 -07:00
Arseny Kapoulkine
bd6d44f5e3
Sync to upstream/release/525 (#467) 2022-04-28 18:24:24 -07:00
Alan Jeffrey
74c84815a0
Prototyping type normalizaton (#466)
* Added type normalization
2022-04-28 15:00:55 -05:00
Arseny Kapoulkine
e0a6461173
Sync to upstream/release/524 (#462) 2022-04-21 14:44:27 -07:00
Alan Jeffrey
5bb9f379b0
Unified strict and nonstrict mode in the prototype (#458) 2022-04-15 19:19:42 -05:00
Arseny Kapoulkine
8e7845076b
Sync to upstream/release/523 (#459) 2022-04-14 16:57:43 -07:00
Alan Jeffrey
d37d0c857b
Prototype: Renamed any/none to unknown/never (#447)
* Renamed any/none to unknown/never
* Pin hackage version
* Update Agda version
2022-04-09 00:07:08 -05:00
Lily Brown
510aed7d3f
Fix JsonEncoder for AstExprTable (#454)
JsonEncoder wasn't producing valid JSON for `AstExprTable`s. This PR fixes it. The new output looks like
```json
{
    "type": "AstStatBlock",
    "location": "0,0 - 6,4",
    "body": [
        {
            "type": "AstStatLocal",
            "location": "1,8 - 5,9",
            "vars": [
                {
                    "name": "x",
                    "location": "1,14 - 1,15"
                }
            ],
            "values": [
                {
                    "type": "AstExprTable",
                    "location": "3,12 - 5,9",
                    "items": [
                        {
                            "kind": "record",
                            "key": {
                                "type": "AstExprConstantString",
                                "location": "4,12 - 4,15",
                                "value": "foo"
                            },
                            "value": {
                                "type": "AstExprConstantNumber",
                                "location": "4,18 - 4,21",
                                "value": 123
                            }
                        }
                    ]
                }
            ]
        }
    ]
}
```
2022-04-08 11:26:47 -07:00
Arseny Kapoulkine
de1381e3f1
Sync to upstream/release/522 (#450) 2022-04-07 14:29:01 -07:00
Alexander McCord
ffff25a9e5
Improve the UX of reading tagged unions a smidge. (#449)
The page is a little narrow, and having to scroll on this horizontally isn't too nice. This fixes the UX for this specific part.
2022-04-07 09:16:44 -07:00
Alan Jeffrey
dc32a3253e
Add short example of width subtyping (#444) 2022-03-31 18:44:41 -05:00
Alan Jeffrey
916c83fdc4
Prototype: Added a discussion of set-theoretic models of subtyping (#431)
* Added a discussion of set-theoretic models of subtyping to the prototype
2022-03-31 18:29:42 -05:00
Arseny Kapoulkine
20308bed20 Merge branch 'merge' 2022-03-31 14:04:40 -07:00
Arseny Kapoulkine
4c1f208d7a
Sync to upstream/release/521 (#443) 2022-03-31 14:01:51 -07:00
Arseny Kapoulkine
a9489893b0 Merge branch 'upstream' into merge 2022-03-31 13:39:48 -07:00
Arseny Kapoulkine
b9b0382a5a Merge branch 'master' into merge 2022-03-31 13:39:46 -07:00
Arseny Kapoulkine
83c1c48e09 Sync to upstream/release/521 2022-03-31 13:37:49 -07:00
Alexander McCord
ba60730e0f
Add documentation on singleton types and tagged unions to typecheck.md. (#440)
Update the typecheck.md page to talk about singleton types and their uses, tagged unions.

As a driveby, improve the documentation on type refinements. And delete the unknown symbols part, this is really dated.

* Update docs/_pages/typecheck.md to fix a typo

Co-authored-by: Arseny Kapoulkine <arseny.kapoulkine@gmail.com>
2022-03-31 11:54:06 -07:00
Alan Jeffrey
06bbfd90b5
Fix code sample in March 2022 Recap (#442) 2022-03-31 09:31:06 -05:00
Alan Jeffrey
f3ea2f96f7
Recap March 2022 (#439)
* March Recap

Co-authored-by: Arseny Kapoulkine <arseny.kapoulkine@gmail.com>
2022-03-30 18:38:55 -05:00
Arseny Kapoulkine
af64680a5e
Mark singleton types and unsealed table literals RFCs as implemented (#438) 2022-03-29 16:58:59 -07:00
Andy Friesen
75bccce3db
RFC: Lower Bounds Calculation (#388)
Co-authored-by: vegorov-rbx <75688451+vegorov-rbx@users.noreply.github.com>
2022-03-29 12:37:14 -07:00
Arseny Kapoulkine
2c339d52c0
Sync to upstream/release/520 (#427) 2022-03-24 15:04:14 -07:00
Arseny Kapoulkine
d13b50de16 Merge branch 'upstream' into merge 2022-03-24 14:49:30 -07:00
Arseny Kapoulkine
44405223ce Merge branch 'master' into merge 2022-03-24 14:49:29 -07:00
Arseny Kapoulkine
373da161e9 Sync to upstream/release/520 2022-03-24 14:49:08 -07:00
Arseny Kapoulkine
5e7e462104
Update STATUS.md 2022-03-24 13:10:56 -07:00
Arseny Kapoulkine
ab64a097cd
Mark sealed table subtyping RFC as implemented 2022-03-24 13:10:30 -07:00
Arseny Kapoulkine
2335b26ffc
Update library.md
Add documentation for table.clone
2022-03-24 09:31:18 -07:00
Arseny Kapoulkine
b8e025311b
Mark table.clone as implemented 2022-03-24 09:29:20 -07:00