<commit_before>import AnzenTypes

/// A named symbol.
public class Symbol {

    public init(name: String, type: SemanticType? = nil, overloadable: Bool = false) {
        self.name           = name
        self.type           = type ?? TypeVariable()
        self.isOverloadable = overloadable
    }

    public let name: String
    public var type: SemanticType

    /// Let function symbols be marked overloadable.
    public let isOverloadable: Bool

}

/// A mapping from names to symbols.
///
/// This collection stores the symbols that are declared within a scope (e.g. a function scope).
/// It is a mapping `String -> [Symbol]`, as a symbol names may be overloaded.
open class Scope {

    public init(name: String? = nil, parent: Scope? = nil) {
        // Create a unique ID for the scope.
        self.id = Scope.nextID
        Scope.nextID += 1

        self.name   = name
        self.parent = parent
    }

    /// Returns whether or not a symbol with the given name exists in this scope.
    public func defines(name: String) -> Bool {
        if let symbols = self.symbols[name] {
            return !symbols.isEmpty
        }
        return false
    }

    /// Adds a symbol to this scope.
    public func add(symbol: Symbol) {
        self[symbol.name].append(symbol)
    }

    /// Returns the first scope in the hierarchy for which a symbol with the given name exists.
    public func findScopeDefining(name: String) -> Scope? {<commit_msg>Add a sanity check on `add(symbol:)`<commit_after>import AnzenTypes

/// A named symbol.
public class Symbol {

    public init(name: String, type: SemanticType? = nil, overloadable: Bool = false) {
        self.name           = name
        self.type           = type ?? TypeVariable()
        self.isOverloadable = overloadable
    }

    public let name: String
    public var type: SemanticType

    /// Let function symbols be marked overloadable.
    public let isOverloadable: Bool

}

/// A mapping from names to symbols.
///
/// This collection stores the symbols that are declared within a scope (e.g. a function scope).
/// It is a mapping `String -> [Symbol]`, as a symbol names may be overloaded.
public class Scope {

    public init(name: String? = nil, parent: Scope? = nil) {
        // Create a unique ID for the scope.
        self.id = Scope.nextID
        Scope.nextID += 1

        self.name   = name
        self.parent = parent
    }

    /// Returns whether or not a symbol with the given name exists in this scope.
    public func defines(name: String) -> Bool {
        if let symbols = self.symbols[name] {
            return !symbols.isEmpty
        }
        return false
    }

    /// Adds a symbol to this scope.
    public func add(symbol: Symbol) {
        precondition(self[symbol.name].forAll({ $0.isOverloadable }))
        self[symbol.name].append(symbol)
    }

    /// Returns the first scope in the hierarchy for which a symbol with the given name exists.
    public func findScopeDefining(name: String) -> Scope? {
{'fraction_non_alphanumeric': 0.09440211990725406, 'fraction_numerical': 0.0009937065253395165, 'mean_word_length': 2.2196162046908317, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4795096', 'n_tokens_mistral': 854, 'n_tokens_neox': 819, 'n_words': 327}