Skip to content

Commit

Permalink
Merge branch 'trunk' of github.com:rtfeldman/roc into nix_flake_M1
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton-4 committed May 13, 2022
2 parents 913c185 + 8db3a3c commit b041a5f
Show file tree
Hide file tree
Showing 45 changed files with 1,624 additions and 468 deletions.
57 changes: 38 additions & 19 deletions BUILDING_FROM_SOURCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,41 +48,60 @@ If you plan on using `nix-shell` regularly, check out [direnv](https://direnv.ne
The editor is a :construction:WIP:construction: and not ready yet to replace your favorite editor, although if you want to try it out on nix, read on.
`cargo run edit` should work from NixOS, if you use a nix-shell from inside another OS, follow the instructions below.

#### Nvidia GPU
#### from nix flake

Running the ediotr may fail using the classic nix-shell, we recommend using the nix flake, see [enabling nix flakes](https://nixos.wiki/wiki/Flakes).

start a nix shell using `nix develop` and follow the instructions below for your graphics configuration.

##### Nvidia GPU

Outside of a nix shell, execute the following:
```
nix-channel --add https://github.com/guibou/nixGL/archive/main.tar.gz nixgl && nix-channel --update
nix-env -iA nixgl.auto.nixVulkanNvidia
nix run --override-input nixpkgs nixpkgs/nixos-21.11 --impure github:guibou/nixGL#nixVulkanNvidia -- cargo run edit
```
Running the editor does not work with `nix-shell --pure`.

If you get an error like:
```
nix-shell
error: unable to execute '/nix/store/qk6...wjla-nixVulkanNvidia-470.103.01/bin/nixVulkanNvidia': No such file or directory
```
460.91.03 may be different for you, type nixVulkanNvidia and press tab to autocomplete for your version.
The intel command should work:
```
nixVulkanNvidia-460.91.03 cargo run edit
nix run --override-input nixpkgs nixpkgs/nixos-21.11 --impure github:guibou/nixGL#nixVulkanIntel -- cargo run edit
```

#### Integrated Intel Graphics
##### Integrated Intel Graphics

:exclamation: ** Our Nix setup currently cannot run the editor with integrated intel graphics, see #1856 ** :exclamation:
```
nix run --override-input nixpkgs nixpkgs/nixos-21.11 --impure github:guibou/nixGL#nixVulkanIntel -- cargo run edit
```

Outside of a nix shell, run:
##### Other configs

```bash
git clone https://github.com/guibou/nixGL
cd nixGL
nix-env -f ./ -iA nixVulkanIntel
```
Check the [nixGL repo](https://github.com/guibou/nixGL) for other graphics configurations. Feel free to ask us for help if you get stuck.

cd to the roc repo, and run (without --pure):
#### using a classic nix-shell

##### Nvidia GPU

Outside of a nix shell, execute the following:
```
nix-channel --add https://github.com/guibou/nixGL/archive/main.tar.gz nixgl && nix-channel --update
nix-env -iA nixgl.auto.nixVulkanNvidia
```
Running the editor does not work with `nix-shell --pure`, instead run:
```
nix-shell
nixVulkanIntel cargo run edit
```
460.91.03 may be different for you, type nixVulkanNvidia and press tab to autocomplete for your version.
```
nixVulkanNvidia-460.91.03 cargo run edit
```

##### Integrated Intel Graphics

nix-shell does not work here, use the flake instead; check the section "Integrated Intel Graphics" under "from nix flake".

#### Other configs
##### Other configs

Check the [nixGL repo](https://github.com/guibou/nixGL) for other graphics configurations.

Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Most contributors execute the following commands befor pushing their code:
```
cargo test
cargo fmt --all -- --check
cargo clippy -- -D warnings
cargo clippy --workspace --tests -- -D warnings
```
Execute `cargo fmt --all` to fix the formatting.

Expand Down
2 changes: 1 addition & 1 deletion Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ check-clippy:
FROM +build-rust-test
RUN cargo clippy -V
RUN --mount=type=cache,target=$SCCACHE_DIR \
cargo clippy -- -D warnings
cargo clippy --workspace --tests -- -D warnings

check-rustfmt:
FROM +build-rust-test
Expand Down
2 changes: 1 addition & 1 deletion bindgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ bumpalo = { version = "3.8.0", features = ["collections"] }
ven_graph = { path = "../vendor/pathfinding" }
target-lexicon = "0.12.3"
clap = { version = "3.1.15", default-features = false, features = ["std", "color", "suggestions", "derive"] }
indoc = "1.0.3"

[dev-dependencies]
pretty_assertions = "1.0.0"
indoc = "1.0.3"
tempfile = "3.2.0"
83 changes: 67 additions & 16 deletions bindgen/src/bindgen.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::convert::TryInto;

use crate::structs::Structs;
use crate::types::{TypeId, Types};
use crate::{enums::Enums, types::RocType};
Expand Down Expand Up @@ -299,29 +297,82 @@ fn add_tag_union(
// Sort tags alphabetically by tag name
tags.sort_by(|(name1, _), (name2, _)| name1.cmp(name2));

let tags = tags
.into_iter()
.map(|(tag_name, payload_vars)| {
let payloads = payload_vars
.iter()
.map(|payload_var| add_type(env, *payload_var, types))
.collect::<Vec<TypeId>>();
let tags: Vec<_> =
tags.into_iter()
.map(|(tag_name, payload_vars)| {
match payload_vars.len() {
0 => {
// no payload
(tag_name, None)
}
1 => {
// there's 1 payload item, so it doesn't need its own
// struct - e.g. for `[ Foo Str, Bar Str ]` both of them
// can have payloads of plain old Str, no struct wrapper needed.
let payload_var = payload_vars.get(0).unwrap();
let payload_id = add_type(env, *payload_var, types);

(tag_name, Some(payload_id))
}
_ => {
// create a struct type for the payload and save it

(tag_name, payloads)
})
.collect();
let struct_name = format!("{}_{}", name, tag_name); // e.g. "MyUnion_MyVariant"

let fields = payload_vars.iter().enumerate().map(|(index, payload_var)| {
(format!("f{}", index).into(), *payload_var)
});
let struct_id = add_struct(env, struct_name, fields, types);

(tag_name, Some(struct_id))
}
}
})
.collect();

let typ = match env.layout_cache.from_var(env.arena, var, subs).unwrap() {
Layout::Struct { .. } => {
// a single-tag union with multiple payload values, e.g. [ Foo Str Str ]
unreachable!()
}
Layout::Union(_) => todo!(),
Layout::Union(union_layout) => {
use roc_mono::layout::UnionLayout::*;

match union_layout {
// A non-recursive tag union
// e.g. `Result ok err : [ Ok ok, Err err ]`
NonRecursive(_) => RocType::TagUnion { name, tags },
// A recursive tag union (general case)
// e.g. `Expr : [ Sym Str, Add Expr Expr ]`
Recursive(_) => {
todo!()
}
// A recursive tag union with just one constructor
// Optimization: No need to store a tag ID (the payload is "unwrapped")
// e.g. `RoseTree a : [ Tree a (List (RoseTree a)) ]`
NonNullableUnwrapped(_) => {
todo!()
}
// A recursive tag union that has an empty variant
// Optimization: Represent the empty variant as null pointer => no memory usage & fast comparison
// It has more than one other variant, so they need tag IDs (payloads are "wrapped")
// e.g. `FingerTree a : [ Empty, Single a, More (Some a) (FingerTree (Tuple a)) (Some a) ]`
// see also: https://youtu.be/ip92VMpf_-A?t=164
NullableWrapped { .. } => {
todo!()
}
// A recursive tag union with only two variants, where one is empty.
// Optimizations: Use null for the empty variant AND don't store a tag ID for the other variant.
// e.g. `ConsList a : [ Nil, Cons a (ConsList a) ]`
NullableUnwrapped { .. } => {
todo!()
}
}
}
Layout::Builtin(builtin) => match builtin {
Builtin::Int(int_width) => RocType::TagUnion {
tag_bytes: int_width.stack_size().try_into().unwrap(),
Builtin::Int(_) => RocType::Enumeration {
name,
tags,
tags: tags.into_iter().map(|(tag_name, _)| tag_name).collect(),
},
Builtin::Bool => RocType::Bool,
Builtin::Float(_)
Expand Down
Loading

0 comments on commit b041a5f

Please sign in to comment.