tamer: asg::air::EnvScopeKind::Pool: Remove (Visible is sufficient)

At least, I think so.

See previous commit for more information, and the commit that follows for
actually using it at Root.

DEV-13146
main
Mike Gerwitz 2023-05-16 15:03:54 -04:00
parent 33f34bf244
commit 1cf5488756
3 changed files with 34 additions and 34 deletions

View File

@ -276,8 +276,8 @@ impl AirAggregate {
use EnvScopeKind::*;
match (self, kind) {
// Pool and Hidden are fixpoints
(_, kind @ (Pool(_) | Hidden(_))) => kind,
// Hidden is a fixpoint.
(_, kind @ Hidden(_)) => kind,
// Expressions do not introduce their own environment
// (they are not containers)
@ -293,7 +293,7 @@ impl AirAggregate {
// Consequently,
// Visible at Root means that we're a package-level Visible,
// which must contribute to the pool.
(Root, Visible(x)) => Pool(x),
(Root, Visible(x)) => Visible(x),
// If we're _not_ Visible at the root,
// then we're _not_ a package-level definition,
@ -594,21 +594,26 @@ impl AirAggregateCtx {
/// and scopes slicing those layers along the y-axies.
///
/// TODO: Example visualization.
///
/// Root and Global Environment
/// ===========================
/// Identifiers are pooled without any defined hierarchy at the root.
///
/// An identifier that is part of a pool must be unique.
/// Since there is no hierarchy,
/// the system should not suggest that shadowing is not permitted and
/// should insteam emphasize that such an identifier must be unique
/// globally.
///
/// An identifier's scope can be further refined to provide more useful
/// diagnostic messages by descending into the package in which it is
/// defined and evaluating scope relative to the package.
#[derive(Debug, PartialEq, Copy, Clone)]
pub(super) enum EnvScopeKind<T = ObjectIndex<Object>> {
/// Identifiers are pooled without any defined hierarchy.
///
/// An identifier that is part of a pool must be unique.
/// Since there is no hierarchy,
/// the system should not suggest that shadowing is not permitted and
/// should insteam emphasize that such an identifier must be unique
/// globally.
///
/// This should be used only at the root.
/// An identifier's scope can be further refined to provide more useful
/// diagnostic messages by descending into the package in which it is
/// defined and evaluating scope relative to the package.
Pool(T),
/// This environment owns the identifier,
/// is descended from an environment that does,
/// or is a global pool of identifiers.
Visible(T),
/// Identifier in this environment is a shadow of a deeper environment.
///
@ -624,10 +629,6 @@ pub(super) enum EnvScopeKind<T = ObjectIndex<Object>> {
/// scope.
Shadow(T),
/// This environment owns the identifier or is an environment descended
/// from one that does.
Visible(T),
/// The identifier is not in scope.
Hidden(T),
}
@ -637,7 +638,7 @@ impl<T> EnvScopeKind<T> {
use EnvScopeKind::*;
match self {
Pool(x) | Shadow(x) | Visible(x) | Hidden(x) => x,
Shadow(x) | Visible(x) | Hidden(x) => x,
}
}
@ -646,7 +647,7 @@ impl<T> EnvScopeKind<T> {
use EnvScopeKind::*;
match self {
Pool(_) | Visible(_) => Some(self),
Visible(_) => Some(self),
Shadow(_) | Hidden(_) => None,
}
}
@ -657,7 +658,7 @@ impl<T> AsRef<T> for EnvScopeKind<T> {
use EnvScopeKind::*;
match self {
Pool(x) | Shadow(x) | Visible(x) | Hidden(x) => x,
Shadow(x) | Visible(x) | Hidden(x) => x,
}
}
}
@ -669,7 +670,6 @@ impl<T, U> Functor<T, U> for EnvScopeKind<T> {
use EnvScopeKind::*;
match self {
Pool(x) => Pool(f(x)),
Shadow(x) => Shadow(f(x)),
Visible(x) => Visible(f(x)),
Hidden(x) => Hidden(f(x)),

View File

@ -92,11 +92,11 @@ fn pkg_nested_expr_definition() {
// ENV: 1 pkg // :
ExprStart(ExprOp::Sum, S2), // :
// ENV: 1 pkg // :
BindIdent(outer), // v : p
BindIdent(outer), // v :v
// :
ExprStart(ExprOp::Sum, S4), // 1: 0
// ENV: 1 pkg // :
BindIdent(inner), // v : p
BindIdent(inner), // v :v
ExprEnd(S6), // :
ExprEnd(S7), // :
PkgEnd(S8), //- -'
@ -108,7 +108,7 @@ fn pkg_nested_expr_definition() {
assert_scope!(asg, outer, [
// The identifier is not local,
// and so its scope should extend into the global environment.
// TODO: (Root, S0, Pool),
// TODO: (Root, S0, Visible),
// Expr does not introduce a new environment,
// and so the innermost environment in which we should be able to
@ -120,7 +120,7 @@ fn pkg_nested_expr_definition() {
assert_scope!(asg, inner, [
// The identifier is not local,
// and so its scope should extend into the global environment.
// TODO: (Root, S0, Pool),
// TODO: (Root, S0, Visible),
// Expr does not introduce a new environment,
// and so just as the outer expression,
@ -148,7 +148,7 @@ fn pkg_tpl_definition() {
// ENV: 1 pkg // :
TplStart(S2), //-----. :
// ENV: 2 tpl // | :
BindIdent(tpl_outer), // |v :p
BindIdent(tpl_outer), // |v :v
// | :
TplMetaStart(S4), // | :
BindIdent(meta_outer), // vl|s :
@ -169,16 +169,16 @@ fn pkg_tpl_definition() {
ExprStart(ExprOp::Sum, S15), // | | :
BindIdent(expr_inner), // vd|s |s :
ExprEnd(S17), // | | :
TplEnd(S18), //---' | : v,s,p = EnvScopeKind
TplEnd(S18), //---' | : v,s = EnvScopeKind
TplEnd(S19), //-----' : |
PkgEnd(S20), //- - - - -' |`- l = local
]; // ^ `- d = defer
// observe: - (l)ocal shadows until root
// - (d)efer shadows until root
// - visual >|> shadow
// - visual >:> pool
// - visual >:> visual (pool)
// - shadow >|> shadow
// - shadow >:> (no pool)
// - shadow >:> (no visual/pool)
let asg = asg_from_toks_raw(toks);
@ -186,7 +186,7 @@ fn pkg_tpl_definition() {
assert_scope!(asg, tpl_outer, [
// The template is defined at the package level,
// and so is incorporated into the global environment.
// TODO: (Root, S0, Pool),
// TODO: (Root, S0, Visible),
// Definition environment.
(Pkg, m(S1, S20), Visible),

View File

@ -112,7 +112,7 @@ impl ObjectIndex<Root> {
let oi_pkg = asg.create(Pkg::new_canonical(start, name)?);
// TODO: We shouldn't be responsible for this
let eoi_pkg = EnvScopeKind::Pool(oi_pkg);
let eoi_pkg = EnvScopeKind::Visible(oi_pkg);
asg.try_index(self, name, eoi_pkg).map_err(|oi_prev| {
let prev = oi_prev.resolve(asg);