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

introduced dedicated interface PrecomputedScopes, updated implementations of DefaultScopeComputation and DefaultScopeProvider #1788

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sailingKieler
Copy link
Contributor

With this additional method hook, customized implementations of PrecomputedScopes contributing lazily computed proposals (for the sake of memory usage optimization) can be employed, and eager in-between evaluations can be avoided by overriding the new method hook getStream(key).

Copy link
Member

@msujew msujew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you overriding MultiMap in your adopter code? This change feels like the wrong abstraction layer. I would much rather have a dedicated PrecomputedScope interface (with a default implementation based on MultiMap), than extend the data type based on a specific adopter need. You can then create your own, stream based PrecomputedScope implementation.

@msujew msujew added the scoping Scoping related issue label Jan 13, 2025
@sailingKieler
Copy link
Contributor Author

sailingKieler commented Jan 13, 2025

I introduced an

CustomPrecomputedScopes extends MultiMap<AstNode, AstNodeDescription> {

    private lazyComputations = new Map<AstNode, () => Stream<AstNodeDescription>>();
    
    ...

    public getStream(key: AstNode): Stream<AstNodeDescription> {
        const local = stream(super.get(key)); // to be replaced with `super.getStream(key)`
        const additional = this.lazyComputations.get(key);
        return local && additional ? local.concat(additional()) : local ?? additional?.() ?? stream();
    }
}

Indeed, from an outside point-of-view the additional method looks a bit weird, with the constraint in mind that the memory footprint of the precomputed scopes might get too high with a high number of documents this is the origin of the change (instead of the array-based inclusion)

const allDescriptions = precomputed.getStream(currentNode);
if (!allDescriptions.isEmpty()) {
scopes.push(stream(allDescriptions).filter(
desc => this.reflection.isSubtype(desc.type, referenceType)));
}

Motivation: Constraint-based visibility of external symbols per document.

…ations of `DefaultScopeComputation` and `DefaultScopeProvider`

* added factory method to `DefaultScopeComputation`
* added `getStream()` to new interface in addition to existing `add`, `addAll`, and `get` resembling the methods `MultiMap` in collection.ts
@sailingKieler sailingKieler changed the title added getStream() to MultiMap in collection.ts, adjusted evaluation of precomputed scopes in DefaultScopeProvider introduced dedicated interface PrecomputedScopes, updated implementations of DefaultScopeComputation and DefaultScopeProvider Jan 15, 2025
@sailingKieler
Copy link
Contributor Author

@msujew I pushed a new version. Does that one meet your idea/proposal?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scoping Scoping related issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants