Skip to content

Commit

Permalink
explicit configs now also used xid and forwardRules inherit the opaqu…
Browse files Browse the repository at this point in the history
…eId from the original config
  • Loading branch information
Goodwine committed Jul 20, 2022
1 parent f29f715 commit c3aeebd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 31 deletions.
32 changes: 16 additions & 16 deletions lib/src/configuration.dart
Expand Up @@ -28,20 +28,21 @@ class Configuration {
final Map<String, ConfiguredValue> _values;

/// Creates an implicit configuration with the given [values].
Configuration.implicit(this._values);
Configuration.implicit(this._values, {String? opaqueId})
: this.opaqueId = opaqueId ?? Xid.string();

/// Uniquely identifying ID for a configuration lasting across the execution
/// context.
///
/// Implicit configurations will always have different IDs.
int get opaqueId => Xid.string().hashCode;
final String opaqueId;

/// The empty configuration, which indicates that the module has not been
/// configured.
///
/// Empty configurations are always considered implicit, since they are
/// ignored if the module has already been loaded.
const Configuration.empty() : _values = const {};
factory Configuration.empty() => Configuration.implicit({});

bool get isEmpty => values.isEmpty;

Expand All @@ -52,7 +53,7 @@ class Configuration {

/// Creates a new configuration from this one based on a `@forward` rule.
Configuration throughForward(ForwardRule forward) {
if (isEmpty) return const Configuration.empty();
if (isEmpty) return Configuration.empty();
var newValues = _values;

// Only allow variables that are visible through the `@forward` to be
Expand All @@ -69,12 +70,13 @@ class Configuration {
} else if (hiddenVariables != null && hiddenVariables.isNotEmpty) {
newValues = LimitedMapView.blocklist(newValues, hiddenVariables);
}
return _withValues(newValues);
return _withValues(newValues, opaqueId: opaqueId);
}

/// Returns a copy of [this] with the given [values] map.
Configuration _withValues(Map<String, ConfiguredValue> values) =>
Configuration.implicit(values);
Configuration _withValues(Map<String, ConfiguredValue> values,
{String? opaqueId}) =>
Configuration.implicit(values, opaqueId: opaqueId);

String toString() =>
"(" +
Expand All @@ -95,15 +97,13 @@ class ExplicitConfiguration extends Configuration {
/// The node whose span indicates where the configuration was declared.
final AstNode nodeWithSpan;

ExplicitConfiguration(Map<String, ConfiguredValue> values, this.nodeWithSpan)
: super.implicit(values);

/// ID for a [configuration] created with an explicit `@use ... with` uniquely
/// identified by its [nodeWithSpan] property.
@override
int get opaqueId => nodeWithSpan.span.toString().hashCode;
ExplicitConfiguration(Map<String, ConfiguredValue> values, this.nodeWithSpan,
{String? opaqueId})
: super.implicit(values, opaqueId: opaqueId);

/// Returns a copy of [this] with the given [values] map.
Configuration _withValues(Map<String, ConfiguredValue> values) =>
ExplicitConfiguration(values, nodeWithSpan);
@override
Configuration _withValues(Map<String, ConfiguredValue> values,
{String? opaqueId}) =>
ExplicitConfiguration(values, nodeWithSpan, opaqueId: opaqueId);
}
15 changes: 8 additions & 7 deletions lib/src/visitor/async_evaluate.dart
Expand Up @@ -141,8 +141,8 @@ class _EvaluateVisitor
/// All modules that have been loaded and evaluated so far.
final _modules = <Uri, Module>{};

/// Configuration ids seen by a module by URI.
final _moduleConfigurationIds = <Uri, int>{};
/// Configuration seen by a module URI.
final _moduleConfigurations = <Uri, Configuration>{};

/// A map from canonical module URLs to the nodes whose spans indicate where
/// those modules were originally loaded.
Expand Down Expand Up @@ -305,7 +305,7 @@ class _EvaluateVisitor
/// The configuration for the current module.
///
/// If this is empty, that indicates that the current module is not configured.
var _configuration = const Configuration.empty();
var _configuration = Configuration.empty();

/// Creates a new visitor.
///
Expand Down Expand Up @@ -470,7 +470,7 @@ class _EvaluateVisitor
var withMap = arguments[1].realNull?.assertMap("with").contents;

var callableNode = _callableNode!;
var configuration = const Configuration.empty();
var configuration = Configuration.empty();
if (withMap != null) {
var values = <String, ConfiguredValue>{};
var span = callableNode.span;
Expand Down Expand Up @@ -673,7 +673,8 @@ class _EvaluateVisitor
var alreadyLoaded = _modules[url];
if (alreadyLoaded != null) {
var currentConfiguration = configuration ?? _configuration;
if (_moduleConfigurationIds[url] != currentConfiguration.opaqueId &&
if (_moduleConfigurations[url]!.opaqueId !=
currentConfiguration.opaqueId &&
currentConfiguration is ExplicitConfiguration) {
var message = namesInErrors
? "${p.prettyUri(url)} was already loaded, so it can't be "
Expand Down Expand Up @@ -755,7 +756,7 @@ class _EvaluateVisitor
var module = environment.toModule(css, extensionStore);
if (url != null) {
_modules[url] = module;
_moduleConfigurationIds[url] = _configuration.opaqueId;
_moduleConfigurations[url] = _configuration;
if (nodeWithSpan != null) _moduleNodes[url] = nodeWithSpan;
}

Expand Down Expand Up @@ -2090,7 +2091,7 @@ class _EvaluateVisitor
}

Future<Value?> visitUseRule(UseRule node) async {
var configuration = const Configuration.empty();
var configuration = Configuration.empty();
if (node.configuration.isNotEmpty) {
var values = <String, ConfiguredValue>{};
for (var variable in node.configuration) {
Expand Down
17 changes: 9 additions & 8 deletions lib/src/visitor/evaluate.dart
Expand Up @@ -5,7 +5,7 @@
// DO NOT EDIT. This file was generated from async_evaluate.dart.
// See tool/grind/synchronize.dart for details.
//
// Checksum: 6e3090c0d46489113c7a3751a37bfbf202285bc2
// Checksum: 9064ba88b38e5cfcc31fd345b185d2c334b490a6
//
// ignore_for_file: unused_import

Expand Down Expand Up @@ -149,8 +149,8 @@ class _EvaluateVisitor
/// All modules that have been loaded and evaluated so far.
final _modules = <Uri, Module<Callable>>{};

/// Configuration ids seen by a module by URI.
final _moduleConfigurationIds = <Uri, int>{};
/// Configuration seen by a module URI.
final _moduleConfigurations = <Uri, Configuration>{};

/// A map from canonical module URLs to the nodes whose spans indicate where
/// those modules were originally loaded.
Expand Down Expand Up @@ -313,7 +313,7 @@ class _EvaluateVisitor
/// The configuration for the current module.
///
/// If this is empty, that indicates that the current module is not configured.
var _configuration = const Configuration.empty();
var _configuration = Configuration.empty();

/// Creates a new visitor.
///
Expand Down Expand Up @@ -475,7 +475,7 @@ class _EvaluateVisitor
var withMap = arguments[1].realNull?.assertMap("with").contents;

var callableNode = _callableNode!;
var configuration = const Configuration.empty();
var configuration = Configuration.empty();
if (withMap != null) {
var values = <String, ConfiguredValue>{};
var span = callableNode.span;
Expand Down Expand Up @@ -678,7 +678,8 @@ class _EvaluateVisitor
var alreadyLoaded = _modules[url];
if (alreadyLoaded != null) {
var currentConfiguration = configuration ?? _configuration;
if (_moduleConfigurationIds[url] != currentConfiguration.opaqueId &&
if (_moduleConfigurations[url]!.opaqueId !=
currentConfiguration.opaqueId &&
currentConfiguration is ExplicitConfiguration) {
var message = namesInErrors
? "${p.prettyUri(url)} was already loaded, so it can't be "
Expand Down Expand Up @@ -760,7 +761,7 @@ class _EvaluateVisitor
var module = environment.toModule(css, extensionStore);
if (url != null) {
_modules[url] = module;
_moduleConfigurationIds[url] = _configuration.opaqueId;
_moduleConfigurations[url] = _configuration;
if (nodeWithSpan != null) _moduleNodes[url] = nodeWithSpan;
}

Expand Down Expand Up @@ -2082,7 +2083,7 @@ class _EvaluateVisitor
}

Value? visitUseRule(UseRule node) {
var configuration = const Configuration.empty();
var configuration = Configuration.empty();
if (node.configuration.isNotEmpty) {
var values = <String, ConfiguredValue>{};
for (var variable in node.configuration) {
Expand Down

0 comments on commit c3aeebd

Please sign in to comment.