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

Reuse symbol collection namespace during typechecking #6839

Open
jjcnn opened this issue Jan 17, 2025 · 0 comments
Open

Reuse symbol collection namespace during typechecking #6839

jjcnn opened this issue Jan 17, 2025 · 0 comments
Labels
compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen performance Everything related to performance, speed wise or memory wise.

Comments

@jjcnn
Copy link
Contributor

jjcnn commented Jan 17, 2025

The symbol collection phase traverses the structure of the current package and keeps track of all name bindings using the namespace module. However, ths resulting structure is then discarded, and the typechecker rebuilds the structure:

    let collection_namespace = Namespace::new(handler, engines, initial_namespace.clone(), true)   // <-- USES CLONE OF initial_namespace
        .map_err(|error| TypeCheckFailed {
            root_module: None,
            namespace: initial_namespace.clone(),
            error,
        })?;
    // Collect the program symbols.

    let mut collection_ctx =
        ty::TyProgram::collect(handler, engines, parse_program, collection_namespace).map_err(
            |error| TypeCheckFailed {
                root_module: None,
                namespace: initial_namespace.clone(),
                error,
            },
        )?;

    let typecheck_namespace =
        Namespace::new(handler, engines, initial_namespace, true).map_err(|error| {   // <-- USES initial_namespace
            TypeCheckFailed {
                root_module: None,
                namespace: collection_ctx.namespace().root_ref().clone(),
                error,
            }
        })?;

Since initial_namespace contains all bindings in the dependency graph (minus the bindings in the current package), cloning the namespace is an expensive operation.

#6838 would make the call to initial_namespace.clone() significantly less expensive, but ideally we would like to reuse the namespace from the symbol collection phase when performing typechecking.

@jjcnn jjcnn added compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen performance Everything related to performance, speed wise or memory wise. labels Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen performance Everything related to performance, speed wise or memory wise.
Projects
None yet
Development

No branches or pull requests

1 participant