Skip to content

Commit b5dfaa3

Browse files
committed
starting to push through transitive re-exports of data
1 parent 0a5445a commit b5dfaa3

File tree

5 files changed

+96
-44
lines changed

5 files changed

+96
-44
lines changed

src/arr/compiler/ast-util.arr

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,10 @@ fun get-named-provides(resolved :: CS.NameResolution, uri :: URI, compile-env ::
11611161
data-provides = for fold(dp from [SD.string-dict:], d from dp-specs):
11621162
cases(A.NameSpec) d.name-spec:
11631163
| s-remote-ref(l, shadow uri, name, as-name) =>
1164-
raise("Cannot alias data right now")
1164+
# dp.set(as-name.toname(), T.t-name(T.module-uri(uri), name, l, false))
1165+
# raise("Cannot alias data right now")
1166+
1167+
dp #NOTE(joe): the type alias does the work here, and datatypes are ONLY stored on the module in which they are defined
11651168
| s-local-ref(l, name, as-name) =>
11661169
exp = resolved.env.datatypes.get-value-now(name.toname())
11671170
dp.set(exp.name, data-expr-to-datatype(exp))
@@ -1245,6 +1248,7 @@ fun find-mod(compile-env, uri) -> Option<String>:
12451248
end
12461249
end
12471250

1251+
12481252
fun transform-dict-helper(canonicalizer):
12491253
lam(d, uri, transformer):
12501254
for SD.fold-keys(s from [SD.string-dict: ], v from d):
@@ -1279,21 +1283,7 @@ fun canonicalize-provides(provides :: CS.Provides, compile-env :: CS.CompileEnvi
12791283
| t-name(origin, name, loc, inferred) =>
12801284
cases(T.NameOrigin) origin:
12811285
| local => T.t-name(T.module-uri(provides.from-uri), name, loc, inferred)
1282-
| module-uri(uri) =>
1283-
cases(Option<String>) find-mod(compile-env, uri):
1284-
| some(_) => T.t-name(T.module-uri(uri), name, loc, inferred)
1285-
| none =>
1286-
if string-index-of(uri, "builtin://") == 0:
1287-
T.t-name(T.module-uri(uri), name, loc, inferred)
1288-
else if uri == provides.from-uri:
1289-
T.t-name(T.module-uri(uri), name, loc, inferred)
1290-
else:
1291-
# TODO(joe): This should become an error once things are localized again
1292-
1293-
#T.t-name(T.module-uri(uri), name, loc)
1294-
raise("Unknown module URI for type: " + torepr(t) + " in provides for " + provides.from-uri)
1295-
end
1296-
end
1286+
| module-uri(uri) => t
12971287
| dependency(d) =>
12981288
provides-for-d = compile-env.provides-by-dep-key(d)
12991289
cases(Option<CS.Provides>) provides-for-d:
@@ -1323,18 +1313,7 @@ fun localize-provides(provides :: CS.Provides, compile-env :: CS.CompileEnvironm
13231313
if uri == provides.from-uri:
13241314
T.t-name(T.local, name, loc, inferred)
13251315
else:
1326-
cases(Option<String>) find-mod(compile-env, uri):
1327-
| some(d) => T.t-name(T.dependency(d), name, loc, inferred)
1328-
| none =>
1329-
if string-index-of(uri, "builtin://") == 0:
1330-
T.t-name(T.module-uri(uri), name, loc, inferred)
1331-
else:
1332-
# TODO(joe): This should become an error once things are localized again
1333-
#T.t-name(T.module-uri(uri), name, loc)
1334-
1335-
raise("Unknown module URI for type: " + torepr(t) + " in provides for " + provides.from-uri)
1336-
end
1337-
end
1316+
t
13381317
end
13391318
| dependency(d) =>
13401319
provides-for-d = compile-env.my-modules.get(d)
@@ -1412,7 +1391,10 @@ fun get-typed-provides(resolved, typed :: TCS.Typed, uri :: URI, compile-env ::
14121391
data-provides = for fold(dp from [SD.string-dict:], d from dp-specs):
14131392
cases(A.NameSpec) d.name-spec:
14141393
| s-remote-ref(l, shadow uri, name, as-name) =>
1415-
raise("Cannot alias data right now")
1394+
# dp.set(as-name.toname(), T.t-name(T.module-uri(uri), name, l, false))
1395+
# raise("Cannot alias data right now")
1396+
1397+
dp #NOTE(joe): the type alias does the work here, and datatypes are ONLY stored on the module in which they are defined
14161398
| s-local-ref(l, name, _) =>
14171399
exp = resolved.env.datatypes.get-value-now(name.toname())
14181400
dp.set(exp.name, canonicalize-data-type(typed.info.data-types.get-value(exp.namet.key()), uri, transformer))

src/arr/compiler/resolve-scope.arr

Lines changed: 81 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,11 +1088,30 @@ fun resolve-names(p :: A.Program, initial-env :: C.CompileEnvironment):
10881088
# names and atoms that will be exposed. The atoms will be used by code
10891089
# generation and by the type-checker/cross-module scope resolution to
10901090
# pick out information about the binding (e.g. flatness, etc)
1091+
# The actual values in the dictionaries are triples of
1092+
#
1093+
# {Srcloc; Option<URI>; Atom}
1094+
#
1095+
# The location is the location of the provide clause, the URI is none if
1096+
# the name is provided from this module, and some if it is re-provided
1097+
# from another module
10911098
provided-modules = [SD.mutable-string-dict:]
10921099
provided-values = [SD.mutable-string-dict:]
10931100
provided-types = [SD.mutable-string-dict:]
10941101
provided-datatypes = [SD.mutable-string-dict:]
10951102

1103+
fun is-hidden(hidden :: List<A.Name>, maybe-hidden-name :: String):
1104+
for lists.any(h from hidden):
1105+
h.name == maybe-hidden-name
1106+
end
1107+
end
1108+
1109+
fun maybe-add(hidden, which-dict, maybe-add-name :: String, to-add):
1110+
when not(is-hidden(hidden, maybe-add-name)):
1111+
which-dict.set-now(maybe-add-name, to-add)
1112+
end
1113+
end
1114+
10961115
fun expand-name-spec(which-dict, which-bindings, which-env, spec, pre-path):
10971116
cases(A.NameSpec) spec:
10981117
| s-star(shadow l, hidden) =>
@@ -1122,27 +1141,75 @@ fun resolve-names(p :: A.Program, initial-env :: C.CompileEnvironment):
11221141
end
11231142
end
11241143
end
1125-
fun expand-data-spec(spec, pre-path):
1144+
fun expand-data-spec(val-env, type-env, spec, pre-path, hidden):
11261145
cases(A.NameSpec) spec:
1127-
| s-star(shadow l, hidden) =>
1146+
| s-star(shadow l, _) => # NOTE(joe): Assumption is that this s-star's hiding is always empty for s-provide-data
11281147
for each(k from datatypes.keys-list-now()):
11291148
data-expr = datatypes.get-value-now(k)
1149+
1150+
# NOTE(joe): Trying this as a nice collapsing of cases
1151+
expand-data-spec(val-env, type-env, A.s-module-ref(l, [list: data-expr.name], none), hidden)
1152+
11301153
# TODO(joe): need to check datatypes from elsewhere with .new-definition?
1131-
provided-datatypes.set-now(data-expr.name, {l; maybe-uri-for-path(pre-path, initial-env, final-visitor.module-env); data-expr.namet})
1154+
# provided-datatypes.set-now(data-expr.name, {l; maybe-uri-for-path(pre-path, initial-env, final-visitor.module-env); data-expr.namet})
11321155
end
11331156
| s-module-ref(shadow l, path, as-name) =>
11341157
maybe-uri = path-uri(pre-path, path, initial-env, final-visitor.module-env)
1135-
{name; atom} = cases(Option) maybe-uri:
1136-
| none =>
1158+
cases(Option) maybe-uri block:
1159+
| none => # path must be a single element if there's no URI of a remote module
1160+
# e.g. provide: D end NOT provide: M.D end
11371161
data-expr = datatypes.get-value-now(path.first.toname())
1138-
{ data-expr.name; data-expr.namet }
1139-
| some(v) =>
1140-
{ path.last().toname(); A.s-name(l, path.last().toname()) }
1141-
end
1142-
data-expr = datatypes.get-value-now(path.first.toname())
1143-
cases(Option) as-name:
1144-
| none => provided-datatypes.set-now(data-expr.name, {l; none; data-expr.namet})
1145-
| some(n) => raise("Cannot rename data using as")
1162+
maybe-add(hidden, provided-datatypes, data-expr.name, {l; none; data-expr.namet})
1163+
data-checker-name = A.make-checker-name(data-expr.name)
1164+
data-checker-vb = val-env.get-value(data-checker-name)
1165+
maybe-add(hidden, provided-values, data-checker-name, {l; none; data-checker-vb.atom})
1166+
data-alias-tb = type-env.get-value(data-expr.name)
1167+
maybe-add(hidden, provided-types, data-expr.name, {l; none; data-alias-tb.atom})
1168+
for each(v from data-expr.variants) block:
1169+
variant-vb = val-env.get-value(v.name)
1170+
checker-name = A.make-checker-name(v.name)
1171+
variant-checker-vb = val-env.get-value(checker-name)
1172+
maybe-add(hidden, provided-values, v.name, {l; none; variant-vb.atom})
1173+
maybe-add(hidden, provided-values, checker-name, {l; none; variant-checker-vb.atom})
1174+
end
1175+
1176+
| some(uri) =>
1177+
datatype-name = path.last().toname()
1178+
providing-module = initial-env.provides-by-uri-value(uri)
1179+
maybe-datatype = providing-module.data-definitions.get(datatype-name)
1180+
{ datatype-uri; datatype } = cases(Option) maybe-datatype:
1181+
| none =>
1182+
cases(Option) providing-module.aliases.get(datatype-name):
1183+
| none => raise("Name " + datatype-name + " not defined as a type or datatype on " + uri)
1184+
| some(t) =>
1185+
cases(T.Type) t block:
1186+
| t-name(module-name, id, _, _) =>
1187+
when(not(T.is-module-uri(module-name))): raise("Expected a remote reference: " + to-repr(module-name)) end
1188+
1189+
remote-datatype = initial-env.provides-by-uri-value(module-name.uri).data-definitions.get(datatype-name)
1190+
cases(Option) remote-datatype:
1191+
| some(rd) => { module-name.uri; rd }
1192+
| none =>
1193+
raise("Cannot re-provide datatype " + datatype-name + " because it isn't a datatype in " + uri)
1194+
end
1195+
end
1196+
end
1197+
| some(datatype) => { uri; datatype }
1198+
end
1199+
fun add-value-if-defined(name):
1200+
when(providing-module.values.has-key(name)):
1201+
maybe-add(hidden, provided-values, name, {l; some(datatype-uri); A.s-name(l, name)})
1202+
end
1203+
end
1204+
# maybe-add(hidden, provided-datatypes, datatype-name, {l; some(uri); A.s-name(l, datatype-name)})
1205+
add-value-if-defined(A.make-checker-name(datatype-name))
1206+
when(providing-module.aliases.has-key(datatype-name)):
1207+
maybe-add(hidden, provided-types, datatype-name, {l; some(datatype-uri); A.s-name(l, datatype-name)})
1208+
end
1209+
for each(v from datatype.variants) block:
1210+
add-value-if-defined(v.name)
1211+
add-value-if-defined(A.make-checker-name(v.name))
1212+
end
11461213
end
11471214
end
11481215
end
@@ -1155,7 +1222,7 @@ fun resolve-names(p :: A.Program, initial-env :: C.CompileEnvironment):
11551222
| s-provide-module(shadow l, name-spec) =>
11561223
expand-name-spec(provided-modules, module-bindings, final-visitor.module-env, name-spec, path)
11571224
| s-provide-data(shadow l, name-spec, hidden) =>
1158-
expand-data-spec(name-spec, path)
1225+
expand-data-spec(final-visitor.env, final-visitor.type-env, name-spec, path, hidden)
11591226
| else => nothing
11601227
end
11611228
end

src/arr/compiler/type-check-structs.arr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,6 +1354,7 @@ fun resolve-alias(t :: Type, context :: Context) -> Type:
13541354
cases(TS.NameOrigin) a-mod:
13551355
| dependency(d) => TS.dep-error(a-mod)
13561356
| local =>
1357+
spy: aliases: context.aliases, key: a-id.key() end
13571358
cases(Option) context.aliases.get(a-id.key()):
13581359
| none => t
13591360
| some(aliased) => resolve-alias(aliased, context).set-loc(l).set-inferred(inferred)

src/arr/compiler/type-check.arr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ fun add-existentials-to-data-name(typ :: Type, context :: Context) -> FoldResult
135135
| t-name(_, _, _, inferred) =>
136136
cases(Option<DataType>) context.get-data-type(typ):
137137
| none =>
138-
fold-errors([list: C.cant-typecheck("Expected a data type but got " + tostring(typ), typ.l)])
138+
fold-errors([list: C.cant-typecheck("Expected a data type but got " + to-repr(typ), typ.l)])
139139
| some(data-type) =>
140140
if is-empty(data-type.params):
141141
fold-result(typ, context)

src/arr/compiler/type-structs.arr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,9 +575,11 @@ sharing:
575575
end, 1, SD.make-string-dict(), free-vars-list)
576576
helper(self, free-vars-mapping, SD.make-mutable-string-dict())
577577
end,
578+
#|
578579
method _output(self):
579580
VS.vs-str(self.to-string())
580581
end
582+
|#
581583
end
582584

583585
check:

0 commit comments

Comments
 (0)