-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port Gleam 1.3 JS fixes to Nix (#13)
* implement compile-time bit array alignment check * fix record constructors in constants using non-aliased names * fix unnecessary gleam.nix writes * add test for cases with a single clause matching a variable This generated a bug in JS before, but seems like Nix isn't affected
- Loading branch information
Showing
17 changed files
with
259 additions
and
10 deletions.
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
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
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use crate::assert_nix; | ||
|
||
#[test] | ||
fn custom_type_constructor_imported_and_aliased() { | ||
assert_nix!( | ||
("package", "other_module", "pub type T { A }"), | ||
r#"import other_module.{A as B} | ||
pub const local = B | ||
"#, | ||
); | ||
} | ||
|
||
#[test] | ||
fn imported_aliased_ok() { | ||
assert_nix!( | ||
r#"import gleam.{Ok as Y} | ||
pub type X { | ||
Ok | ||
} | ||
pub const y = Y | ||
"#, | ||
); | ||
} | ||
|
||
#[test] | ||
fn imported_ok() { | ||
assert_nix!( | ||
r#"import gleam | ||
pub type X { | ||
Ok | ||
} | ||
pub const y = gleam.Ok | ||
"#, | ||
); | ||
} |
4 changes: 2 additions & 2 deletions
4
...er-core/src/nix/tests/snapshots/glistix_core__nix__tests__bit_arrays__explicit_sized.snap
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,10 +1,10 @@ | ||
--- | ||
source: compiler-core/src/nix/tests/bit_arrays.rs | ||
expression: "\nfn go() {\n <<256:size(4)>>\n}\n" | ||
expression: "\nfn go() {\n <<256:size(64)>>\n}\n" | ||
--- | ||
let | ||
inherit (builtins.import ./../gleam.nix) toBitArray sizedInt; | ||
|
||
go = { }: toBitArray [ (sizedInt 256 4) ]; | ||
go = { }: toBitArray [ (sizedInt 256 64) ]; | ||
in | ||
{ } |
10 changes: 10 additions & 0 deletions
10
...ler-core/src/nix/tests/snapshots/glistix_core__nix__tests__bit_arrays__negative_size.snap
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,10 @@ | ||
--- | ||
source: compiler-core/src/nix/tests/bit_arrays.rs | ||
expression: "\nfn go() {\n <<1:size(-1)>>\n}\n" | ||
--- | ||
let | ||
inherit (builtins.import ./../gleam.nix) toBitArray sizedInt; | ||
|
||
go = { }: toBitArray [ (sizedInt 1 (-1)) ]; | ||
in | ||
{ } |
5 changes: 5 additions & 0 deletions
5
...-core/src/nix/tests/snapshots/glistix_core__nix__tests__bit_arrays__not_byte_aligned.snap
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 @@ | ||
--- | ||
source: compiler-core/src/nix/tests/bit_arrays.rs | ||
expression: "\nfn thing() {\n 4\n}\nfn go() {\n <<256:4>>\n}\n" | ||
--- | ||
let inherit (builtins.import ./../gleam.nix) toBitArray; thing = { }: 4; in { } |
5 changes: 5 additions & 0 deletions
5
...ests/snapshots/glistix_core__nix__tests__bit_arrays__not_byte_aligned_explicit_sized.snap
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 @@ | ||
--- | ||
source: compiler-core/src/nix/tests/bit_arrays.rs | ||
expression: "\nfn go() {\n <<256:size(4)>>\n}\n" | ||
--- | ||
let inherit (builtins.import ./../gleam.nix) toBitArray; in { } |
10 changes: 10 additions & 0 deletions
10
.../nix/tests/snapshots/glistix_core__nix__tests__bit_arrays__not_byte_aligned_variable.snap
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,10 @@ | ||
--- | ||
source: compiler-core/src/nix/tests/bit_arrays.rs | ||
expression: "\nfn go() {\n let x = 4\n <<256:size(x)>>\n}\n" | ||
--- | ||
let | ||
inherit (builtins.import ./../gleam.nix) toBitArray sizedInt; | ||
|
||
go = { }: let x = 4; in toBitArray [ (sizedInt 256 x) ]; | ||
in | ||
{ } |
4 changes: 2 additions & 2 deletions
4
compiler-core/src/nix/tests/snapshots/glistix_core__nix__tests__bit_arrays__sized.snap
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,10 +1,10 @@ | ||
--- | ||
source: compiler-core/src/nix/tests/bit_arrays.rs | ||
expression: "\nfn go() {\n <<256:4>>\n}\n" | ||
expression: "\nfn go() {\n <<256:64>>\n}\n" | ||
--- | ||
let | ||
inherit (builtins.import ./../gleam.nix) toBitArray sizedInt; | ||
|
||
go = { }: toBitArray [ (sizedInt 256 4) ]; | ||
go = { }: toBitArray [ (sizedInt 256 64) ]; | ||
in | ||
{ } |
15 changes: 15 additions & 0 deletions
15
...core/src/nix/tests/snapshots/glistix_core__nix__tests__case__single_clause_variables.snap
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,15 @@ | ||
--- | ||
source: compiler-core/src/nix/tests/case.rs | ||
expression: "\npub fn main() {\n let text = \"first defined\"\n case \"defined again\" {\n text -> Nil\n }\n let text = \"a third time\"\n Nil\n}\n" | ||
--- | ||
let | ||
main = | ||
{ }: | ||
let | ||
text = "first defined"; | ||
_' = let _pat' = "defined again"; in let text'1 = _pat'; in null; | ||
text'1 = "a third time"; | ||
in | ||
builtins.seq _' null; | ||
in | ||
{ inherit main; } |
15 changes: 15 additions & 0 deletions
15
...nix/tests/snapshots/glistix_core__nix__tests__case__single_clause_variables_assigned.snap
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,15 @@ | ||
--- | ||
source: compiler-core/src/nix/tests/case.rs | ||
expression: "\npub fn main() {\n let text = \"first defined\"\n let other = case \"defined again\" {\n text -> Nil\n }\n let text = \"a third time\"\n Nil\n}\n" | ||
--- | ||
let | ||
main = | ||
{ }: | ||
let | ||
text = "first defined"; | ||
other = let _pat' = "defined again"; in let text'1 = _pat'; in null; | ||
text'1 = "a third time"; | ||
in | ||
null; | ||
in | ||
{ inherit main; } |
11 changes: 11 additions & 0 deletions
11
...shots/glistix_core__nix__tests__consts__custom_type_constructor_imported_and_aliased.snap
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,11 @@ | ||
--- | ||
source: compiler-core/src/nix/tests/consts.rs | ||
expression: "import other_module.{A as B}\npub const local = B\n" | ||
--- | ||
let | ||
other_module' = builtins.import ./../../package/other_module.nix; | ||
B = (builtins.import ./../../package/other_module.nix).A; | ||
|
||
local = B; | ||
in | ||
{ inherit local; } |
13 changes: 13 additions & 0 deletions
13
...r-core/src/nix/tests/snapshots/glistix_core__nix__tests__consts__imported_aliased_ok.snap
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 @@ | ||
--- | ||
source: compiler-core/src/nix/tests/consts.rs | ||
expression: "import gleam.{Ok as Y}\npub type X {\n Ok\n}\npub const y = Y\n" | ||
--- | ||
let | ||
gleam' = builtins.import ./../gleam.nix; | ||
Y = (builtins.import ./../gleam.nix).Ok; | ||
|
||
Ok = { __gleamTag = "Ok"; }; | ||
|
||
y = Y; | ||
in | ||
{ inherit Ok y; } |
12 changes: 12 additions & 0 deletions
12
compiler-core/src/nix/tests/snapshots/glistix_core__nix__tests__consts__imported_ok.snap
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,12 @@ | ||
--- | ||
source: compiler-core/src/nix/tests/consts.rs | ||
expression: "import gleam\npub type X {\n Ok\n}\npub const y = gleam.Ok\n" | ||
--- | ||
let | ||
gleam' = builtins.import ./../gleam.nix; | ||
|
||
Ok = { __gleamTag = "Ok"; }; | ||
|
||
y = gleam'.Ok; | ||
in | ||
{ inherit Ok y; } |