-
Notifications
You must be signed in to change notification settings - Fork 192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error Recovery #1499
Closed
Closed
Error Recovery #1499
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0f70eeb
Starting work on error recovery
wycats c13e9d5
Fix linting for benchmarks/krausest
NullVoxPopuli 79ed194
Fix build by specifying browsers list to rollup-plugin-ts, and make n…
NullVoxPopuli 670b846
Silence a lint in @glimmer/util
NullVoxPopuli 607e745
lint fix on @glimmer/reference
NullVoxPopuli 6ec5b13
Fix/silence lint violations in @glimmer/runtime
NullVoxPopuli 41f4788
Silence a deprecation lint in @glimmer/node
NullVoxPopuli 128f306
Silence lint/deprecation messages in @glimmer/syntax
NullVoxPopuli 498e1ad
lint:fix @glimmer-workspace/integration-tests
NullVoxPopuli b4b23d0
More lint disables in the @glimmer/workspace area
NullVoxPopuli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"singleQuote": true, | ||
"trailingComma": "es5", | ||
"printWidth": 100 | ||
"printWidth": 100, | ||
"plugins": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
- [ ] Implement `#try` that takes handler | ||
- [ ] internal `{{#if isClear}}{{!-- actual code --}}{{/if}}` | ||
- [ ] if an error is encountered, unwind as-if isClear was false | ||
during the render pass | ||
- [ ] when you encounter the enter of the try, insert a marker in | ||
every VM stack. | ||
- [ ] every stack in the VM needs "unwind to nearest marker" | ||
- [ ] when a render error is encountered, unwind all the stacks | ||
- [ ] call the handler with the error | ||
- [ ] no catch | ||
- [ ] the handler has a way to clear the error | ||
- [ ] deal with user destructors that should run even during render errors | ||
- [ ] maintain the invariant that constructors and destructors are paired |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** @type {import("eslint").Linter.Config} */ | ||
module.exports = { | ||
root: false, | ||
overrides: [ | ||
{ | ||
files: ['**/*.js'], | ||
parserOptions: { | ||
ecmaVersion: 'latest', | ||
sourceType: 'module', | ||
}, | ||
}, | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -175,10 +175,6 @@ | |
{ | ||
"name": "📦 @types/puppeteer-chromium-resolver", | ||
"path": "packages/@types/puppeteer-chromium-resolver" | ||
}, | ||
{ | ||
"name": "📦 @types/qunit", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this whole package was added for one additional property -- it was causing issues on |
||
"path": "packages/@types/qunit" | ||
} | ||
], | ||
"settings": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
### Table of Contents | ||
|
||
1. [Introduction](./01-introduction.md) | ||
2. [Minification Assumptions](./02-minification.md) | ||
3. [Dev Mode Patterns](./03-devmode-patterns.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Minification Assumptions | ||
|
||
> 🚧 https://terser.org/docs/options/ | ||
|
||
- `import.meta.env.DEV` | ||
- `keep_fargs: false` | ||
|
||
## Issues | ||
|
||
### Works better in terser than swc | ||
|
||
- https://tiny.katz.zone/OfydPB | ||
- https://tiny.katz.zone/XlJrqp | ||
- https://tiny.katz.zone/6R5VdC (weird behavior involving new) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Dev Mode Patterns | ||
|
||
## Case Study: `DevMode<Description>` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Frames and Blocks | ||
|
||
Initial: | ||
|
||
```clj | ||
[ | ||
(PushFrame) | ||
[ | ||
(ReturnTo END) | ||
(Push ...Args) | ||
(Enter) | ||
[ | ||
(Assertion) ; (JumpUnless) | (AssertSame) | ||
...body | ||
] | ||
(Exit) | ||
(Return) | ||
; END | ||
] | ||
(PopFrame) | ||
] | ||
``` | ||
|
||
Update: | ||
|
||
```clj | ||
[ | ||
; restore state | ||
(ReturnTo -1) | ||
(PushArgs ...Captured) | ||
(ReEnter) | ||
; start evaluation here | ||
[ | ||
(Assertion) | ||
; (JumpUnless) | (AssertSame) | ||
...body | ||
] | ||
(Exit) | ||
(Return) | ||
] | ||
``` | ||
|
||
1. Initial | ||
1. PushFrame | ||
2. ReturnTo | ||
3. Push captured args | ||
4. Enter (optionally try frame) | ||
5. Assertion | ||
a. `JumpUnless` -> target | ||
b. `AssertSame` | ||
6. (body) | ||
7. Exit | ||
8. Return | ||
9. PopFrame | ||
2. Update (from 1.5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
# Reactivity APIs | ||
|
||
## Generic APIs | ||
|
||
## `readReactive` | ||
|
||
| Takes | Returns | | ||
| ------------------ | ----------------------------- | | ||
| 🟢🟡 Fallible Read | 🟡 Result _(throws ⚪ Never)_ | | ||
|
||
The `readReactive` function takes a reactive value and returns a `ReactiveResult`. | ||
|
||
## `unwrapReactive` | ||
|
||
The `unwrapReactive` function takes a `ReactiveResult` and returns its value, throwing an exception | ||
if the reactive produces an error (or was previously an error). | ||
|
||
| Takes | Returns | | ||
| ------------------ | ------------------------------------ | | ||
| 🟢🟡 Fallible Read | 🟢 Value _(throws 🔴 UserException)_ | | ||
|
||
## `updateReactive` | ||
|
||
The `updateReactive` function takes a _mutable_ reactive and a new value and updates it. You cannot | ||
pass an immutable reactive to this function. | ||
|
||
| Takes | Updates | | ||
| ---------- | ------------------------ | | ||
| 📝 Mutable | 🟢 Value _(or 🔴 Error)_ | | ||
|
||
## Cell APIs | ||
|
||
### Constructors | ||
|
||
```ts | ||
function Cell(value: T): MutableCell<T>; | ||
function ReadonlyCell(value: T): ReadonlyCell<T>; | ||
|
||
type Cell<T> = MutableCell<T> | ReadonlyCell<T>; | ||
``` | ||
|
||
| Type | Read | Write | | ||
| ----------------- | -------- | ------------ | | ||
| `Cell<T>` | 🟢 Value | 📝 Mutable | | ||
| `ReadonlyCell<T>` | 🟢 Value | 🚫 Immutable | | ||
|
||
### `readCell` | ||
|
||
```ts | ||
export function readCell<T>(cell: Cell<T>): T; | ||
``` | ||
|
||
The `readCell` function takes a cell and returns its value. Since cells are infallible, you can use | ||
this function to read from a cell without risking an exception (as with `unwrapReactive`). | ||
|
||
### `writeCell` | ||
|
||
```ts | ||
export function writeCell<T>(cell: MutableCell<T>, value: T): void; | ||
``` | ||
|
||
| Takes | Updates | | ||
| ---------------- | -------- | | ||
| 📝 Mutable Write | 🟢 Value | | ||
|
||
The `writeCell` function writes a new value to a mutable cell. You can't write to a readonly cell. | ||
|
||
## Formula APIs | ||
|
||
| Type | Read | Write | | ||
| ------------- | --------- | ------------ | | ||
| `Accessor<T>` | 🟡 Result | 📝 Mutable | | ||
| `Formula<T>` | 🟡 Result | 🚫 Immutable | | ||
|
||
### Constructors | ||
|
||
```ts | ||
export function Formula<T>(compute: () => T): Formula<T>; | ||
export function Accessor<T>(options: { get: () => T; set: (value: T) => void }): Accessor<T>; | ||
``` | ||
|
||
If an accessor's `set` throws an error, the reactive value will become an error. | ||
|
||
## External Markers | ||
|
||
External markers are not reactive values themselves. Instead, they _stand in_ for external storage. | ||
|
||
Here's an example using a `SimpleMap` class that uses a `Map` as its backing storage: | ||
|
||
```ts | ||
class SimpleMap<K, V> { | ||
#markers = new Map<K, ExternalMarker>(); | ||
#values = new Map<K, V>(); | ||
|
||
get(key: K): V { | ||
this.#initialized(key).consumed(); | ||
return this.#values.get(key); | ||
} | ||
|
||
has(key: K) { | ||
this.#initialized(key).consumed(); | ||
return this.#values.has(key); | ||
} | ||
|
||
set(key: K, value: V) { | ||
this.#initialized(key).updated(); | ||
this.#values.set(key, value); | ||
} | ||
|
||
#initialized(key: K) { | ||
let marker = this.#markers.get(key); | ||
|
||
if (!marker) { | ||
marker = ExternalMarker(); | ||
this.#markers.set(key, marker); | ||
} | ||
|
||
return marker; | ||
} | ||
} | ||
``` | ||
|
||
Now, reads from `has(key)` or `get(key)` will be invalidated whenever `set(key, value)` is called on | ||
the same key. | ||
|
||
The crux of the situation is that we don't want to store every value in a Cell and turn every | ||
computation into a `Formula`. Instead, we want to store our data in normal JavaScript data | ||
structures and notify the reactivity system whenever the data is accessed or modified. | ||
|
||
## Internal Reactives | ||
|
||
### `ComputedCell` | ||
|
||
A `ComputedCell` behaves like a cell, but it uses a `compute` function to compute a new value. The | ||
`compute` function must be infallible, and there is no error recovery if it fails. | ||
|
||
| Type | Read | Write | | ||
| ----------------- | -------- | ------------ | | ||
| `ComputedCell<T>` | 🟢 Value | 🚫 Immutable | |
55 changes: 55 additions & 0 deletions
55
guides/internals/09-error-recovery/A-error-recovery-references.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Error Recovery: Reactive Values | ||
|
||
Reactive values are _fallible_: they can be in an error state. | ||
|
||
## `ReactiveResult<T>` | ||
|
||
A `ReactiveResult` can be in one of two states: | ||
|
||
```ts | ||
interface Ok<T> { | ||
type: 'ok'; | ||
value: T; | ||
} | ||
``` | ||
|
||
```ts | ||
interface Error { | ||
type: 'error'; | ||
value: UserException; | ||
} | ||
``` | ||
|
||
## General Reactive APIs | ||
|
||
### `readReactive` | ||
|
||
The `readReactive` function takes a reactive value and returns a `ReactiveResult`. | ||
|
||
### `unwrapReactive` | ||
|
||
The `unwrapReactive` function takes a `ReactiveResult` and returns its value, throwing an exception | ||
if the reactive produces an error (or was previously an error). | ||
|
||
## Cell APIs | ||
|
||
### `readCell` | ||
|
||
### `writeCell` | ||
|
||
## Error Recovery | ||
|
||
Once a formula has entered the error state, it can be recovered in one of two ways: | ||
|
||
- The formula invalidates | ||
- The `clearError` function is called | ||
|
||
Examples: | ||
|
||
```ts | ||
class isError = createCell(false); | ||
|
||
const formula = FallibleFormula(() => { | ||
if () | ||
}); | ||
``` |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wycats what's this file about?