Repository navigation
effects: let declarations snapshot before writes - #301
Merged
Merged
Conversation
Rule 2 rejected every read of statement-written state (W) from a
declaration's initializer, wherever it sat, so a snapshot like
let before = ws
ws = ws.withNewFile("a.txt", "hi")
[before, ws]
failed to check, in scripts and in Session snippets alike, though both
give `before` the value from before the writes.
An initializer's direct read of a binding of W (not in a block argument,
`{{ }}` field, or function or type body written in it) is now allowed
when it comes before every write of the binding, all in its own file.
Scripts run declarations before statements and sessions run forms in
source order, and both see the pre-write value there, since initializers
write no top-level binding, so what each accepts still agrees. Reads
after a write, indirect reads, and reads with a write in another file of
the module are still rejected with the same message, which now cites
the first write the read doesn't precede.
Only accepts more programs, so no version gate.
Signed-off-by: Alex Suraci <[email protected]>
The mutation page, the dang-language skill and its objects reference, and the dang-internals skill now say a declaration may read statement-written state directly before every write in its file, with a working and a failing snippet on the mutation page. Signed-off-by: Alex Suraci <[email protected]>
Deploying dang with
|
| Latest commit: |
b52cf3c
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://ac684456.dang-3kk.pages.dev |
| Branch Preview URL: | https://declaration-snapshots.dang-3kk.pages.dev |
vito
added a commit
to dagger/dagger
that referenced
this pull request
Nov 12, 2026
vito/dang main past v2.4.1: analysis's opt-in diagnostic context and Render (vito/dang#298), and rule-2 snapshot reads, so `let before = ws` stays readable after `ws = …` (vito/dang#301). No language version changes: Dang's current version is still 2.4. Signed-off-by: Alex Suraci <[email protected]>
vito
added a commit
that referenced
this pull request
Nov 12, 2026
The 2.5 page covered only the string change. It now covers everything merged since v2.4.1: declaration snapshots (#301), the editor and syntax-error changes from #300, and a Go embedders section with DiagnosticContext (#298) and the AST's new string spelling. Sources and verification name the full range. Signed-off-by: Alex Suraci <[email protected]>
vito
added a commit
that referenced
this pull request
Nov 13, 2026
The 2.5 page covered only the string change. It now covers everything merged since v2.4.1: declaration snapshots (#301), the editor and syntax-error changes from #300, and a Go embedders section with DiagnosticContext (#298) and the AST's new string spelling. Sources and verification name the full range. Signed-off-by: Alex Suraci <[email protected]>
vito
added a commit
to dagger/dagger
that referenced
this pull request
Nov 14, 2026
vito/dang main past v2.4.1: analysis's opt-in diagnostic context and Render (vito/dang#298), and rule-2 snapshot reads, so `let before = ws` stays readable after `ws = …` (vito/dang#301). No language version changes: Dang's current version is still 2.4. Signed-off-by: Alex Suraci <[email protected]>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Rule 2 of top-level initialization (
toplevel_order.go) rejected every read of statement-written state (W) from a declaration's initializer, wherever it sat. So this snapshot failed to check:It failed in scripts and in
Session/Module.Evalsnippets alike, and so in the engine's DangEval. In both settingsbeforewould get the value from before the writes.The rule now
An initializer may read a binding of W if both of these hold:
{{ }}field, or a function or type body written in it. Bare{ }blocks andifbranches run in place, so reads there still count as direct.Scripts run every declaration before any statement. Sessions run forms in source order. Initializers can't write top-level bindings (rule 1), so both see the pre-write value at such a read. What a session accepts, a script still accepts, and both produce the same values.
Every other read is still rejected with the same message: reads after a write, reads between writes, indirect reads, and reads where another file writes the binding. The message now cites the first write the read doesn't come before.
The change only accepts more programs, so there is no version gate.
Changes
pkg/dang/toplevel_order.go:topForm.framerecords the frame an initializer starts in.outsideRead.directmarks reads made under that frame.topOrder.writtenkeeps every write of each binding.checkskips a direct read that comes before all the writes (firstWriteNotAfter).TestTopLevelStatementStateis replaced by cases for the snapshot (including one on the same line as a later write), a read between writes, a read after a write, and reads in a block argument, a{{ }}field, a function, a nested function and a field default.TestRunDirSnapshotAcrossFilescovers a write in the same file (values checked) and a write in another file (rejected).TestSnapshotBeforeWritesInScriptsAndSessionsruns the same program as an eager module top level and as aModule.Evalsnippet (both give[1, 2]), snapshots a module binding that a snippet reassigns, and checks that a read after a write is rejected in both.tests/test_toplevel_init.danggains a snapshot.docs/lit/types/mutation.md(with a working and adang-failuresnippet), the dang-language skill andreference/objects.md, and the dang-internals skill.go test ./pkg/dang ./tests,docsandfmt/staleall pass.