Skip to content
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

fix: Print comptime::Value better #5655

Merged
merged 4 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions compiler/noirc_frontend/src/elaborator/comptime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,11 @@ impl<'context> Elaborator<'context> {
elaborator.introduce_generics_into_scope(meta.all_generics.clone());
}

elaborator.comptime_scopes = std::mem::take(&mut self.comptime_scopes);
elaborator.populate_scope_from_comptime_scopes();

let result = f(&mut elaborator);
elaborator.check_and_pop_function_context();

self.comptime_scopes = elaborator.comptime_scopes;
self.errors.append(&mut elaborator.errors);
result
}
Expand All @@ -74,7 +72,7 @@ impl<'context> Elaborator<'context> {
// Take the comptime scope to be our runtime scope.
// Iterate from global scope to the most local scope so that the
// later definitions will naturally shadow the former.
for scope in &self.comptime_scopes {
for scope in &self.interner.comptime_scopes {
for definition_id in scope.keys() {
let definition = self.interner.definition(*definition_id);
let name = definition.name.clone();
Expand Down Expand Up @@ -156,7 +154,7 @@ impl<'context> Elaborator<'context> {

if value != Value::Unit {
let items = value
.into_top_level_items(location)
.into_top_level_items(location, self.interner)
.map_err(|error| error.into_compilation_error_pair())?;

self.add_items(items, generated_items, location);
Expand Down
11 changes: 1 addition & 10 deletions compiler/noirc_frontend/src/elaborator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use std::{
use crate::{
ast::{FunctionKind, UnresolvedTraitConstraint},
hir::{
comptime::Value,
def_collector::dc_crate::{
filter_literal_globals, CompilationError, ImplMap, UnresolvedGlobal, UnresolvedStruct,
UnresolvedTypeAlias,
Expand All @@ -27,8 +26,7 @@ use crate::{
SecondaryAttribute, StructId,
},
node_interner::{
DefinitionId, DefinitionKind, DependencyId, ExprId, FuncId, GlobalId, ReferenceId, TraitId,
TypeAliasId,
DefinitionKind, DependencyId, ExprId, FuncId, GlobalId, ReferenceId, TraitId, TypeAliasId,
},
Shared, Type, TypeVariable,
};
Expand Down Expand Up @@ -68,7 +66,6 @@ mod unquote;
use fm::FileId;
use iter_extended::vecmap;
use noirc_errors::{Location, Span};
use rustc_hash::FxHashMap as HashMap;

use self::traits::check_trait_impl_method_matches_declaration;

Expand Down Expand Up @@ -157,11 +154,6 @@ pub struct Elaborator<'context> {

crate_id: CrateId,

/// Each value currently in scope in the comptime interpreter.
/// Each element of the Vec represents a scope with every scope together making
/// up all currently visible definitions. The first scope is always the global scope.
pub(crate) comptime_scopes: Vec<HashMap<DefinitionId, Value>>,

/// The scope of --debug-comptime, or None if unset
debug_comptime_in_file: Option<FileId>,

Expand Down Expand Up @@ -209,7 +201,6 @@ impl<'context> Elaborator<'context> {
trait_bounds: Vec::new(),
function_context: vec![FunctionContext::default()],
current_trait_impl: None,
comptime_scopes: vec![HashMap::default()],
debug_comptime_in_file,
unresolved_globals: BTreeMap::new(),
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/noirc_frontend/src/elaborator/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ impl<'context> Elaborator<'context> {

pub fn push_scope(&mut self) {
self.scopes.start_scope();
self.comptime_scopes.push(Default::default());
self.interner.comptime_scopes.push(Default::default());
}

pub fn pop_scope(&mut self) {
let scope = self.scopes.end_scope();
self.comptime_scopes.pop();
self.interner.comptime_scopes.pop();
self.check_for_unused_variables_in_scope_tree(scope.into());
}

Expand Down
Loading
Loading