Skip to content

Commit bde8e74

Browse files
committed
Demo: Global language imports in snippets
1 parent 985919c commit bde8e74

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

docs/_docs/reference/experimental/capture-checking/basics.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ nightlyOf: https://docs.scala-lang.org/scala3/reference/experimental/capture-che
77
## Introduction
88

99
```scala sc-hidden sc-name:cc-context
10+
import language.experimental.captureChecking
1011
import caps.*
1112
```
1213

docs/_docs/reference/experimental/capture-checking/mutability.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ title: "Stateful Capabilities"
44
nightlyOf: https://docs.scala-lang.org/scala3/reference/experimental/capture-checking/mutability.html
55
---
66

7+
```scala sc-hidden sc-name:mut-context
8+
import language.experimental.captureChecking
9+
import language.experimental.separationChecking
10+
```
11+
712
## Introduction
813

914
An important class of effects represents accesses to mutable variables and mutable data structures. This is intimately tied with the concept of _program state_. Stateful capabilities are capabilities that allow to consult and change the program state.
@@ -13,7 +18,7 @@ We distinguish two kinds of accesses: full access that allows state changes and
1318
A common kind of stateful capabilities represent mutable variables that can be read and written.
1419
These mutable data structures are expressed with the marker trait `caps.Mutable`.
1520
For instance, consider a simple reference cell:
16-
```scala
21+
```scala sc-compile-with:mut-context
1722
import caps.Mutable
1823

1924
class Ref[T](init: T) extends Mutable:
@@ -46,7 +51,7 @@ These classes typically contain mutable variables and/or _update methods_.
4651
Update methods are declared using a new soft modifier `update`.
4752

4853
**Example:**
49-
```scala
54+
```scala sc-compile-with:mut-context
5055
//{
5156
import caps.*
5257
//}

docs/_docs/reference/experimental/capture-checking/safe.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ Full Scala 3 has elements that are incompatible with capability safety, such as
1212

1313
To distinguish between these two usage modes, there is a safe language subset that can be specified with a command-line option or a language import:
1414
```scala sc:nocompile
15-
import language.experimental.safe
15+
import language.experimental.safe
16+
```
17+
18+
```scala sc-hidden sc-name:safe-context
19+
import language.experimental.safe
1620
```
1721

1822
It makes sense for agentic tooling to subject all compilations of agent-generated code to be compiled in _safe mode_ using this language import. Safe mode imposes the following restrictions:
@@ -38,6 +42,7 @@ is done, the library module can be made available for use by safe code.
3842
This scheme is supported by a new `@assumeSafe` annotation, available in
3943
module `caps`.
4044
Modules tagged with this annotation are assumed to be callable from agent-generated code. `@assumeSafe` comes with none of the restrictions that `safe` implies. Instead it is the obligation of the programmer to verify that the module is indeed safe. For instance caching a function results could be implemented like this:
45+
<!-- FIXME: the below is rejected by the compiler! -->
4146
```scala sc:nocompile
4247
import caps.unsafe.untrackedCaptures
4348
import caps.assumeSafe

project/Build.scala

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2001,10 +2001,7 @@ object Build {
20012001
.add(GenerateAPI(false))
20022002
.add(SnippetCompiler(List(
20032003
s"${docs.getAbsolutePath}/_docs/reference/enums=compile",
2004-
s"$ccDocs=compile|-language:experimental.captureChecking",
2005-
s"$ccDocs/separation-checking=compile|-language:experimental.captureChecking|-language:experimental.separationChecking",
2006-
s"$ccDocs/mutability=compile|-language:experimental.captureChecking|-language:experimental.separationChecking",
2007-
s"$ccDocs/safe=compile|-language:experimental.safe",
2004+
s"$ccDocs=compile",
20082005
)))
20092006
}
20102007

@@ -2952,10 +2949,7 @@ object ScaladocConfigs {
29522949
.add(SnippetCompiler(
29532950
snippetCompilerTargets(s"$stdlib/src") ++ List(
29542951
"docs/_docs/reference/enums=compile",
2955-
"docs/_docs/reference/experimental/capture-checking=compile|-language:experimental.captureChecking",
2956-
"docs/_docs/reference/experimental/capture-checking/separation-checking=compile|-language:experimental.captureChecking|-language:experimental.separationChecking",
2957-
"docs/_docs/reference/experimental/capture-checking/mutability=compile|-language:experimental.captureChecking|-language:experimental.separationChecking",
2958-
"docs/_docs/reference/experimental/capture-checking/safe=compile|-language:experimental.safe",
2952+
"docs/_docs/reference/experimental/capture-checking=compile",
29592953
)))
29602954
.add(SiteRoot("docs"))
29612955
.add(ApiSubdirectory(true))

0 commit comments

Comments
 (0)