Skip to content

feat(semantic): Warn when an extern type/function is declared outside the corelib.#10147

Open
orizi wants to merge 1 commit into
mainfrom
orizi/06-22-feat_semantic_warn_when_an_extern_type_function_is_declared_outside_the_corelib
Open

feat(semantic): Warn when an extern type/function is declared outside the corelib.#10147
orizi wants to merge 1 commit into
mainfrom
orizi/06-22-feat_semantic_warn_when_an_extern_type_function_is_declared_outside_the_corelib

Conversation

@orizi

@orizi orizi commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Summary

Introduces a new extern_outside_corelib lint (warning E2201) that fires when extern fn or extern type items are declared outside the core library. The warning message reads: "Extern types and functions should only be declared in the core library." It can be suppressed with #[allow(extern_outside_corelib)].

The lint is registered as a known allow-able lint in declared_allows, and the check is implemented in report_extern_item_outside_corelib, which is called from both extern_function.rs and extern_type.rs during semantic analysis. The constant EXTERN_OUTSIDE_CORELIB is added to cairo-lang-syntax's attribute consts.

All existing test fixtures that declare extern fn or extern type outside the corelib have been updated with #[allow(extern_outside_corelib)] to suppress the new warning, and line numbers in expected diagnostics have been adjusted accordingly. New test cases in diagnostic_test_data/allow verify that the warning is emitted without the attribute and suppressed with it.


Type of change

Please check one:

  • Bug fix (fixes incorrect behavior)
  • New feature
  • Performance improvement
  • Documentation change with concrete technical impact
  • Style, wording, formatting, or typo-only change

Why is this change needed?

Declaring extern fn and extern type outside the core library is an advanced, low-level operation that bypasses Cairo's type system guarantees and directly names Sierra libfuncs. Allowing this silently in user code makes it easy to accidentally introduce unsound or non-portable declarations. The lint surfaces this as a warning so developers are aware of the risk, while still allowing it when explicitly opted in.


What was the behavior or documentation before?

extern fn and extern type could be declared anywhere without any diagnostic.


What is the behavior or documentation after?

Declaring extern fn or extern type outside the core library emits warning E2201. The warning is silenced by annotating the item with #[allow(extern_outside_corelib)].


Related issue or discussion (if any)


Additional context

The error code E2201 is assigned to this diagnostic. The severity is Warning, consistent with other lint-style diagnostics such as unused_variables and unused_imports.

@reviewable-StarkWare

Copy link
Copy Markdown

This change is Reviewable

orizi commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@orizi orizi marked this pull request as ready for review June 22, 2026 11:19
@cursor

cursor Bot commented Jun 22, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Compiler lint and diagnostic plumbing only; no runtime or corelib behavior change beyond new warnings for non-core crates.

Overview
Adds warning E2201 when extern fn or extern type is declared outside the core crate, with message that extern items should only live in the core library. Semantic analysis calls report_extern_item_outside_corelib from extern function and extern type declaration paths; the lint is registered in declared_allows and can be suppressed with #[allow(extern_outside_corelib)] via the new EXTERN_OUTSIDE_CORELIB allow constant.

Test and fixture code that intentionally declares externs outside corelib is updated with that attribute, and allow-lint tests cover both the warning and suppression.

Reviewed by Cursor Bugbot for commit 01c3432. Bugbot is set up for automated code reviews on this repo. Configure here.

@TomerStarkware TomerStarkware left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

:lgtm:

@TomerStarkware reviewed 78 files and all commit messages, and made 1 comment.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on eytan-starkware).

@orizi orizi added this pull request to the merge queue Jul 3, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 3, 2026
… the corelib.

Adds the `extern_outside_corelib` warning (E2201), emitted on any `extern type`
or `extern fn` declared outside the core crate. Silenceable per-item with
`#[allow(extern_outside_corelib)]`; internal tests that declare externs are
annotated accordingly.
@orizi orizi force-pushed the orizi/06-22-feat_semantic_warn_when_an_extern_type_function_is_declared_outside_the_corelib branch from f8af227 to 01c3432 Compare July 3, 2026 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants