Merge pull request #3589 from rtfeldman/can-abilities3

Canonicalize syntactic abilities: Part 3 - solving
This commit is contained in:
Ayaz 2022-07-25 21:48:14 -05:00 committed by GitHub
commit 6b6f240acb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 594 additions and 274 deletions

View file

@ -47,7 +47,8 @@ const SYMBOL_HAS_NICHE: () =
#[cfg(debug_assertions)]
const PRETTY_PRINT_DEBUG_SYMBOLS: bool = true;
pub const BUILTIN_ABILITIES: &[Symbol] = &[Symbol::ENCODE_ENCODING];
pub const DERIVABLE_ABILITIES: &[(Symbol, &[Symbol])] =
&[(Symbol::ENCODE_ENCODING, &[Symbol::ENCODE_TO_ENCODER])];
/// In Debug builds only, Symbol has a name() method that lets
/// you look up its name in a global intern table. This table is
@ -86,8 +87,12 @@ impl Symbol {
self.module_id().is_builtin()
}
pub fn is_builtin_ability(self) -> bool {
BUILTIN_ABILITIES.contains(&self)
pub fn is_derivable_ability(self) -> bool {
self.derivable_ability().is_some()
}
pub fn derivable_ability(self) -> Option<&'static (Symbol, &'static [Symbol])> {
DERIVABLE_ABILITIES.iter().find(|(name, _)| *name == self)
}
pub fn module_string<'a>(&self, interns: &'a Interns) -> &'a ModuleName {