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

doc: fix docstrings for SymbolTable #681

Merged
merged 1 commit into from
Feb 17, 2025
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
1 change: 1 addition & 0 deletions crates/conjure_core/src/ast/declaration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ impl Declaration {
}
}

/// The name of this declaration.
pub fn name(&self) -> &Name {
&self.name
}
Expand Down
22 changes: 11 additions & 11 deletions crates/conjure_core/src/ast/symbol_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,16 @@ impl SymbolTable {
}
}

// Looks up the declaration with the given name in the current scope only.
//
// Returns `None` if there is no declaration with that name in the current scope.
/// Looks up the declaration with the given name in the current scope only.
///
/// Returns `None` if there is no declaration with that name in the current scope.
pub fn lookup_local(&self, name: &Name) -> Option<Rc<Declaration>> {
self.table.get(name).cloned()
}

// Looks up the declaration with the given name, checking all enclosing scopes.
//
// Returns `None` if there is no declaration with that name in scope.
/// Looks up the declaration with the given name, checking all enclosing scopes.
///
/// Returns `None` if there is no declaration with that name in scope.
pub fn lookup(&self, name: &Name) -> Option<Rc<Declaration>> {
self.lookup_local(name).or_else(|| {
self.parent
Expand All @@ -127,9 +127,9 @@ impl SymbolTable {
})
}

// Inserts a declaration into the symbol table.
//
// Returns `None` if there is already a symbol with this name in the local scope.
/// Inserts a declaration into the symbol table.
///
/// Returns `None` if there is already a symbol with this name in the local scope.
pub fn insert(&mut self, declaration: Rc<Declaration>) -> Option<()> {
let name = declaration.name().clone();
if let Entry::Vacant(e) = self.table.entry(name) {
Expand All @@ -140,7 +140,7 @@ impl SymbolTable {
}
}

// Updates or adds a declaration in the immediate local scope.
/// Updates or adds a declaration in the immediate local scope.
pub fn update_insert(&mut self, declaration: Rc<Declaration>) {
let name = declaration.name().clone();
self.table.insert(name, declaration);
Expand All @@ -156,7 +156,7 @@ impl SymbolTable {
self.lookup_local(name).and_then(|x| x.return_type())
}

// Looks up the domain of name if it has one and is in scope.
/// Looks up the domain of name if it has one and is in scope.
pub fn domain(&self, name: &Name) -> Option<Domain> {
// TODO: do not clone here: in the future, we might want to wrap all domains in Rc's to get
// clone-on-write behaviour (saving memory in scenarios such as matrix decomposition where
Expand Down
Loading