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

Support Option and similar enums as type of static variable with linkage attribute #104799

Merged
merged 3 commits into from
Dec 7, 2022

Commits on Dec 5, 2022

  1. Move linkage type check to HIR analysis and fix semantics issues.

    This ensures that the error is printed even for unused variables,
    as well as unifying the handling between the LLVM and GCC backends.
    
    This also fixes unusual behavior around exported Rust-defined variables
    with linkage attributes. With the previous behavior, it appears to be
    impossible to define such a variable such that it can actually be imported
    and used by another crate. This is because on the importing side, the
    variable is required to be a pointer, but on the exporting side, the
    type checker rejects static variables of pointer type because they do
    not implement `Sync`. Even if it were possible to import such a type, it
    appears that code generation on the importing side would add an unexpected
    additional level of pointer indirection, which would break type safety.
    
    This highlighted that the semantics of linkage on Rust-defined variables
    is different to linkage on foreign items. As such, we now model the
    difference with two different codegen attributes: linkage for Rust-defined
    variables, and import_linkage for foreign items.
    
    This change gives semantics to the test
    src/test/ui/linkage-attr/auxiliary/def_illtyped_external.rs which was
    previously expected to fail to compile. Therefore, convert it into a
    test that is expected to successfully compile.
    
    The update to the GCC backend is speculative and untested.
    pcc committed Dec 5, 2022
    Configuration menu
    Copy the full SHA
    5873ebe View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    f44a015 View commit details
    Browse the repository at this point in the history
  3. Reimplement weak! using Option.

    pcc committed Dec 5, 2022
    Configuration menu
    Copy the full SHA
    b4278b0 View commit details
    Browse the repository at this point in the history