-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: generalized imports supporting pattern matching and selective field import #3076
Changes from 49 commits
b46e72a
e6e9915
67500bf
2d40582
1556274
3b120ee
bcf3fcb
59efd68
957f912
a1ee29c
91c3708
8d7fb3c
8fe6866
ddcef0f
f581947
0eff5af
999d654
c32448f
58c629c
ad314b7
2e9df25
7293902
93dcc88
1a0a069
e72ce22
d43c7ab
3669465
6efb5f6
b109d6d
4c94e00
1eef8dc
e3ee5f1
968cadc
9c911ca
2c3f4aa
2503343
0e0b65a
656b48c
9dc287a
c59e85a
a2aeae4
d0dff31
2d9b797
37b2838
c763ff8
feec77b
988c27f
c98c798
a3ac786
2ae3cbb
3e8226c
b5ed7d0
1ddcf93
95a93a8
ca01c14
af6941a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,15 +23,16 @@ let comp_unit_of_prog as_lib (prog : prog) : comp_unit = | |
let open Source in | ||
let f = prog.note in | ||
|
||
let finish imports u = { it = { imports; body = u }; note = f; at = no_region } in | ||
let finish imports u = | ||
{ it = { imports = List.rev imports; body = u }; note = f; at = no_region } in | ||
let prog_typ_note = { empty_typ_note with note_typ = Type.unit } in | ||
|
||
let rec go imports ds : comp_unit = | ||
match ds with | ||
(* imports *) | ||
| {it = LetD ({it = VarP n; _}, ({it = ImportE (url, ri); _} as e)); _} :: ds' -> | ||
let i : import = { it = (n, url, ri); note = e.note.note_typ; at = e.at } in | ||
go (imports @ [i]) ds' | ||
| {it = LetD (p, ({it = ImportE (url, ri); _} as e)); _} :: ds' -> | ||
let i : import = { it = (p, url, ri); note = e.note.note_typ; at = e.at } in | ||
go (i :: imports) ds' | ||
|
||
(* terminal expressions *) | ||
| [{it = ExpD ({it = ObjBlockE ({it = Type.Module; _}, fields); _} as e); _}] when as_lib -> | ||
|
@@ -88,14 +89,15 @@ let obj_decs obj_sort at note id_opt fields = | |
let decs_of_lib (cu : comp_unit) = | ||
let open Source in | ||
let { imports; body = cub; _ } = cu.it in | ||
let import_decs = List.map (fun { it = (id, fp, ri); at; note} -> | ||
{ it = LetD ( | ||
{ it = VarP id; at; note; }, | ||
{ it = ImportE (fp, ri); | ||
at; | ||
note = { note_typ = note; note_eff = Type.Triv} }); | ||
at; | ||
note = { note_typ = note; note_eff = Type.Triv } }) imports | ||
let import_decs = | ||
List.map (fun { it = (pat, fp, ri); at; note} -> | ||
{ it = LetD (pat, | ||
{ it = ImportE (fp, ri); | ||
at; | ||
note = { note_typ = note; note_eff = Type.Triv} }); | ||
at; | ||
note = { note_typ = note; note_eff = Type.Triv } } | ||
) imports | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the identation style on the left - I think that's what Andreas was advocating... (at least my understanding of it). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is what There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
in | ||
import_decs, | ||
match cub.it with | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import "depri" = "text-module"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module { public let why = 42 } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
import "lib/not-static" | ||
ggreif marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import _ = "lib/not-static" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
text-module.mo:0.1: warning [M0142], deprecated syntax: an imported library should be a module or named actor class | ||
error-imports.mo:1.8-1.15: type error [M0050], literal of type | ||
Text | ||
does not have expected type | ||
module {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Return code 1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
refutable-import.mo:1.8-1.20: type error [M0145], this pattern of type | ||
module {why : Nat} | ||
does not cover value | ||
{why = 0 or 1 or _} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Return code 1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
self-import.mo:1.1-1.21: import error [M0003], file self-import.mo must not depend on itself | ||
self-import.mo:1.1-1.25: import error [M0003], file self-import.mo must not depend on itself |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
type-error-imports.mo:4.8-4.14: type error [M0112], tuple pattern cannot consume expected type | ||
module {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Return code 1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { why = 42 } = "nat-module"; | ||
|
||
//SKIP run | ||
//SKIP run-ir | ||
//SKIP run-low | ||
//SKIP comp |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
import "self-import"; | ||
ggreif marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import _ = "self-import"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"depri" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import _ "empty-module"; | ||
import {} "empty-module"; | ||
|
||
import (_, _) = "empty-module"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#!/usr/bin/env bash | ||
moc -v -i <<__END__ | ||
import "lib/empty"; | ||
import "lib/empty"; | ||
import _ = "lib/empty"; | ||
import _ = "lib/empty"; | ||
__END__ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
import "ic:em77e-bvlzu-aq"; | ||
import "canister:alias"; | ||
import _ = "ic:em77e-bvlzu-aq"; | ||
import _ = "canister:alias"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import A "nested/a"; | ||
import "nested/b"; | ||
import _ = "nested/b"; | ||
|
||
let i = A.i; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
import "a" | ||
import _ = "a" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/usr/bin/env bash | ||
moc -v -i <<__END__ | grep Parsing | ||
import "lib/nested"; | ||
import _ = "lib/nested"; | ||
__END__ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,14 +8,12 @@ Motoko compiler (source XXX) | |
-- Interpreting empty.mo: | ||
-- Interpreting stdin: | ||
-- Finished stdin: | ||
let anon-import-1.1 : module {...} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess these are gone, because the wildcard pattern has a side-effect-less RHS. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think its gone because we don't have the optional ? production which would introduce a gensym-ed, anonymous binding (not a wildcard). |
||
|
||
-- Parsing stdin: | ||
> -- Checking stdin: | ||
-- Definedness stdin: | ||
-- Interpreting stdin: | ||
-- Finished stdin: | ||
let anon-import-2.1 : module {...} | ||
|
||
-- Parsing stdin: | ||
> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason this isn't just
<pat>
as forlet
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want
(?(#foo))
here, do we?<pat>
just doesn't have any sensible use-case in this place.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but I don't think we should enforce typing properties using the grammar.
Also, it keeps the grammar closer to the informal language reference.
Plus, you might want a type annotation on the pattern without having to parenthesize it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can I do this tomorrow in a new PR? I am totally burnt out, sorry.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tomorrow is saturday. Monday!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't work: #3076 (comment)