Skip to content

Commit 5aace03

Browse files
committed
feat(proposals): introduce evolution proposals
1 parent e5149c0 commit 5aace03

6 files changed

+273
-0
lines changed

proposals/LE-000-template.md

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Template Proposal
2+
3+
- Proposal: LE-000
4+
- Status: **Draft**
5+
- Author: [**@vknabel**](https://github.com/vknabel)
6+
7+
## Introduction
8+
9+
What is the proposed feature? What problem does it solve?
10+
11+
## Motivation
12+
13+
Why is this change important to you? How would you use it? How can it benefit other users?
14+
15+
## Proposed Solution
16+
17+
Describe the solution you'd like. Provide examples and describe how it works. Define any new terminology.
18+
19+
## Detailed Design
20+
21+
Describe the design of the solution in detail. How will it be implemented?
22+
23+
## Changes to the Standard Library
24+
25+
List any new modules, types, functions, etc. that will be added to the standard library. Highlight any breaking changes.
26+
27+
## Alternatives Considered
28+
29+
Describe alternative approaches to addressing the same problem, and why you chose this approach instead.
30+
31+
## Acknowledgements
32+
33+
List people who have contributed to the design of this proposal. Also mention any prior art, such as how other languages have solved this problem.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Sandboxing and Timeouts
2+
3+
- Proposal: LE-001
4+
- Status: **Draft**
5+
- Author: [**@vknabel**](https://github.com/vknabel)
6+
7+
## Introduction
8+
9+
In this proposal we want to discuss the possibility of adding sandboxing and timeouts to the Lithia command line interface. This will be accomplished by implementing a whitelist for external declarations on a module level.
10+
11+
To avoid infinitely running scripts, it should also be possible to set a timeout for the execution of a script.
12+
13+
## Motivation
14+
15+
In security critical or embedded environments, it is important to be able to limit the power of a program.
16+
The first practical use case for this will be the evaluation of the `Potfile`. It will be executed whenever opening the project and before actually starting the program itself.
17+
18+
The Potfile execution needs to be fast and secure.
19+
20+
## Proposed Solution
21+
22+
The Lithia CLI will get additional configuration options to allow limiting external definitions and setting timeouts.
23+
24+
```bash
25+
LITHIA_TIMEOUT=1s \
26+
LITHIA_EXTERNAL_DEFINITIONS=docs,fs,os,rx \
27+
lithia run [script]
28+
```
29+
30+
## Detailed Design
31+
32+
`LITHIA_TIMEOUT` will be used to set a timeout for the execution of a script. The default value will be `0s` which means no timeout.
33+
34+
`LITHIA_EXTERNAL_DEFINITIONS` will be used to set a whitelist for external definitions. The default value will be `*` which means all external definitions are allowed. External definitions of `prelude` are always allowed.
35+
36+
The `Potfile` will always be executed with `LITHIA_TIMEOUT=1s` and `LITHIA_EXTERNAL_DEFINITIONS=rx`. No matter what the user has set.
37+
38+
### Merging the Environment Variables
39+
40+
If the user has manually set the environment variables more strict than the default values for the `Potfile` execution, the more strict values will be used.
41+
42+
For example if the user has set `LITHIA_EXTERNAL_DEFINITIONS=docs,os,rx` and the `Potfile` contains `LITHIA_EXTERNAL_DEFINITIONS=docs,fs,os,rx`, the final value will be `docs,os,rx`.
43+
44+
## Changes to the Standard Library
45+
46+
No changes to the standard library are required.
47+
48+
## Alternatives Considered
49+
50+
In the future command line flags or configuration files might be used to set these values.
51+
52+
## Acknowledgements
53+
54+
List people who have contributed to the design of this proposal. Also mention any prior art, such as how other languages have solved this problem.

proposals/LE-002-potfile-scripting.md

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Potfile Scripting
2+
3+
- Proposal: LE-002
4+
- Status: **Draft**
5+
- Author: [**@vknabel**](https://github.com/vknabel)
6+
7+
## Introduction
8+
9+
This proposal adds some basic subcommands to the `lithia` CLI to allow user defined scripts to be executed.
10+
11+
## Motivation
12+
13+
Every project has specific jobs to be done. These jobs are often repetitive and can be automated. This proposal aims to provide simple access to these scripts.
14+
15+
## Proposed Solution
16+
17+
Within the `Potfile`, new commands that execute a specific Lithia file as a script can be defined using the `pots.cmds.script` function. Additional help context can be provided on the existing command. The command can be executed using `lithia [script]` or `lithia run [script]`.
18+
19+
```lithia
20+
let testCmd = cmds.script "test", "cmd/test.lithia"
21+
testCmd.summary "runs all tests"
22+
testCmd.flag "verbose", "verbose logging"
23+
testCmd.env "LITHIA_TESTS", "1"
24+
```
25+
26+
Similar, the `pots.cmds.bin` function can be used to define a command that executes a binary. Under the hood `/usr/bin/env` will be used to lookup the binary. In case of `lithia` itself, the currently executed `lithia` binary will be used.
27+
28+
```lithia
29+
cmds.bin "example", ["lithia", "test"]
30+
```
31+
32+
## Detailed Design
33+
34+
The user adds the commands of their choice to their `Potfile`.
35+
The Lithia interpreter will now execute it and will proceed working on the internal store structure.
36+
37+
The execution of the Potfile takes place in a sandboxed environment which whitelists possible external module imports to avoid direct access to the file system and other resources. It will also be time-restricted to at most one second using Go `context.Context`.
38+
39+
To avoid privilege escalation, scripts declared in the `Potfile` with overridden `LITHIA_TIMEOUT` or `LITHIA_EXTERNAL_DEFINITIONS`, can only restrict the environment further. They cannot allow more access to the environment.
40+
41+
## Changes to the Standard Library
42+
43+
Adds a new module `pot.cmds`:
44+
45+
- _func_ `script alias, path` - returns a `MutableCommand`.
46+
- _func_ `bin alias, path` - returns a `MutableCommand`.
47+
- _data_ `MutableCommand` - a mutable command that can be used to configure the command.
48+
- _func_ `summary text` - sets the summary text for the command.
49+
- _func_ `flag name, description` - adds a flag to the command.
50+
- _func_ `env name, value` - adds an environment variable to the command.
51+
52+
Other non-final additions are internal and include:
53+
54+
- _let_ `store` - a stateful application store which stores the commands and in the future more commands.
55+
56+
## Alternatives Considered
57+
58+
- `pot [script]`, `lithia run [script]` or `lithia pot [script]`
59+
60+
## Acknowledgements
61+
62+
`npm run [script]`, `yarn [script]`, `swift run [target]` and
63+
`archery [script]`.
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Template Proposal
2+
3+
- Proposal: LE-003
4+
- Status: **Draft**
5+
- Author: [**@vknabel**](https://github.com/vknabel)
6+
7+
## Introduction
8+
9+
Adds the ability to concatenate strings using the `..` operator.
10+
11+
## Motivation
12+
13+
Strings need to be concatnated often. The current way to do this is to use the `strings.concat` function, which feels a bit verbose in many cases.
14+
15+
A simple `..` might improve the readability of the code.
16+
17+
## Proposed Solution
18+
19+
We add a new left-associative operator `..` to the language, which is used to concatenate strings with a low precendence.
20+
21+
## Detailed Design
22+
23+
The `..` operator is left-associative, and has a precedence of 5.
24+
This allows comparisions of concatenated strings.
25+
26+
```lithia
27+
"Hello" .. " " .. "World" == "Hello World"
28+
```
29+
30+
## Changes to the Standard Library
31+
32+
Only implementations are affected.
33+
`strings.concat` will still be available, and will never be deprecated.
34+
35+
## Alternatives Considered
36+
37+
We could overload `+`. But due to the dynamic typing it may be confusing in practice.
38+
`++` is also used in different languages, but we do not want to mix up the meaning of `+` and `++`.
39+
40+
## Acknowledgements
41+
42+
Mimics the `..` operator in Lua.
+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# New Concurrency Model
2+
3+
- Proposal: LE-004
4+
- Status: **Draft**
5+
- Author: [**@vknabel**](https://github.com/vknabel)
6+
7+
## Introduction
8+
9+
The initially planned concurrency model for Lithia was based on Functional Reactive Programming. In practice this turned out to not fit the language very well. FRP is complex, yet Lithia tries to be simple. This proposal describes a new concurrency model, which is inspired by Go's channels and coroutines.
10+
11+
## Motivation
12+
13+
Lithia has a strong and dynamic type system. The current approach of FRP wraps all values and therefore forcing users to unwrap them. This forces developers to double check the docs for the return type. Otherwise this leads to avoidable runtime errors.
14+
15+
When comparing this with the Go concurrency model, where async function calls are blocking, but still return the same value as normal function calls. This should lead to a better developer experience in Lithia programs.
16+
17+
## Proposed Solution
18+
19+
The new concurrency model is based on channels and coroutines. Coroutines are similar to async functions, but they are not blocking. They can be called using the `async` function. The `async` function is followed by an expression, which is executed in a new coroutine. The coroutine can be suspended using the `await` function. The `await` keyword is followed by an expression, which is evaluated in the current coroutine. The result of the expression is returned to the coroutine, which called `await`.
20+
21+
```lithia
22+
let task = async { =>
23+
let channel = Channel 0
24+
select { on, closed =>
25+
on channel, { value =>
26+
print value
27+
}
28+
on None, { _ =>
29+
print "No value"
30+
}
31+
closed channel, { reason =>
32+
print reason
33+
}
34+
}
35+
}
36+
await task
37+
```
38+
39+
## Detailed Design
40+
41+
`Channel` is just a wrapper around a Go-channel. But in contrast to `close` in Go, `close` in Lithia takes a reason.
42+
43+
The `async` function directly creates a new Goroutine with a `Task` under the hood. It is implemented similar to `rx.Future`.
44+
45+
## Changes to the Standard Library
46+
47+
The `rx` module will be removed including the types `rx.Async`.
48+
`rx.Variable` will be moved to `prelude.Variable`. `rx.Future` will be moved to `prelude.Future`.
49+
50+
In module `prelude`:
51+
52+
- _extern_ `Channel`
53+
- can be called as `Channel bufferSize`
54+
- _func_ `send value`
55+
- _func_ `close reason`
56+
- _func_ `select func`
57+
- _extern_ `async expr`
58+
- _func_ `await future`
59+
- _extern_ `Variable` defined as before
60+
- _extern_ `Task` defined as `rx.Future` before, but with all references to `results.Result` removed. They can't fail anymore.
61+
62+
## Alternatives Considered
63+
64+
Most alternatives are more complex and might impact developer experience.
65+
The `Task` could be dropped, but it might be useful.
66+
67+
## Acknowledgements
68+
69+
This is heavily inspired by Go. `Task` is inspired by Swift.

proposals/README.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Lithia Evolution Proposals
2+
3+
The development of Lithia is now driven by evolution proposals. New proposals can be created by anyone. As a starting point, you can [copy the template](./LE-000-template.md).
4+
5+
## Proposals
6+
7+
| Proposal | Status | Title |
8+
| --------------------------------------------- | ------ | ----------------------- |
9+
| [LE-001](./LE-001-sandboxing-and-timeouts.md) | Draft | Sandboxing and Timeouts |
10+
| [LE-002](./LE-002-potfile-scripting.md) | Draft | Potfile Scripting |
11+
| [LE-003](./LE-003-string-concatenation.md) | Draft | String Concatenation |
12+
| [LE-004](./LE-004-new-concurrency-model.md) | Draft | New Concurreny Model |

0 commit comments

Comments
 (0)