Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions crates/cairo-lang-filesystem/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ pub struct ExperimentalFeaturesConfig {
/// Allows using user defined inline macros.
#[serde(default)]
pub user_defined_inline_macros: bool,
/// Allows using reference types (&T), which desugar to BoxTrait<@T>.
/// Allows using representation pointer types (&T), which desugar to BoxTrait<@T>.
#[serde(default)]
pub references: bool,
pub repr_ptrs: bool,
}

/// Function to get a virtual file from an external id.
Expand Down Expand Up @@ -413,7 +413,7 @@ pub fn init_dev_corelib(db: &mut dyn salsa::Database, core_lib_dir: PathBuf) {
associated_item_constraints: true,
coupons: true,
user_defined_inline_macros: true,
references: true,
repr_ptrs: true,
},
},
cache_file: None,
Expand Down
2 changes: 1 addition & 1 deletion crates/cairo-lang-lowering/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ cairo_lang_test_utils::test_file_test!(
members: "members",
panic: "panic",
rebindings: "rebindings",
reference: "reference",
repr_ptr: "repr_ptr",
snapshot: "snapshot",
struct_: "struct",
tests: "tests",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ extern fn baz(y: &u32) nopanic;
edition = "2024_07"

[experimental_features]
references = true
repr_ptrs = true

//! > semantic_diagnostics

Expand Down Expand Up @@ -67,7 +67,7 @@ extern fn bar(x: &u32, y: &&u32, z: &&&u32) nopanic;
edition = "2024_07"

[experimental_features]
references = true
repr_ptrs = true

//! > semantic_diagnostics

Expand Down Expand Up @@ -111,7 +111,7 @@ extern fn bar(x: &u32) nopanic;
edition = "2024_07"

[experimental_features]
references = true
repr_ptrs = true

//! > semantic_diagnostics

Expand Down Expand Up @@ -149,7 +149,7 @@ extern fn bar(x: &@u32) nopanic;
edition = "2024_07"

[experimental_features]
references = true
repr_ptrs = true

//! > semantic_diagnostics

Expand Down Expand Up @@ -190,7 +190,7 @@ extern fn bar(x: &u32) nopanic;
edition = "2024_07"

[experimental_features]
references = true
repr_ptrs = true

//! > semantic_diagnostics

Expand Down
2 changes: 1 addition & 1 deletion crates/cairo-lang-parser/src/parser_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ cairo_lang_test_utils::test_file_test!(
while_: "while",
for_: "for",
range: "range",
reference: "reference",
repr_ptr: "repr_ptr",
use_: "use",
type_alias: "type_alias",
macro_declaration: "macro_declaration",
Expand Down
10 changes: 5 additions & 5 deletions crates/cairo-lang-project/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fn test_serde() {
associated_item_constraints: false,
coupons: false,
user_defined_inline_macros: false,
references: false,
repr_ptrs: false,
},
cfg_set: Default::default(),
},
Expand Down Expand Up @@ -76,7 +76,7 @@ fn test_serde() {
associated_item_constraints = false
coupons = false
user_defined_inline_macros = false
references = false
repr_ptrs = false

[config.override.crate1]
edition = "2023_10"
Expand All @@ -88,7 +88,7 @@ fn test_serde() {
associated_item_constraints = false
coupons = false
user_defined_inline_macros = false
references = false
repr_ptrs = false

[config.override.crate3]
edition = "2023_01"
Expand All @@ -100,7 +100,7 @@ fn test_serde() {
associated_item_constraints = false
coupons = false
user_defined_inline_macros = false
references = false
repr_ptrs = false
"# }
);
assert_eq!(config, toml::from_str(&serialized).unwrap());
Expand Down Expand Up @@ -133,7 +133,7 @@ fn test_serde_defaults() {
associated_item_constraints = false
coupons = false
user_defined_inline_macros = false
references = false
repr_ptrs = false

[config.override]
"# };
Expand Down
20 changes: 10 additions & 10 deletions crates/cairo-lang-semantic/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -953,13 +953,13 @@ impl<'db> DiagnosticEntry<'db> for SemanticDiagnostic<'db> {
coupons experimental feature in the crate config."
.into()
}
SemanticDiagnosticKind::ReferencesDisabled => {
"Reference types are disabled in the current crate.\nYou can enable them by \
enabling the `references` experimental feature in the crate config."
SemanticDiagnosticKind::ReprPtrsDisabled => {
"Representation pointers are disabled in the current crate.\nYou can enable them \
by enabling the `repr_ptrs` experimental feature in the crate config."
.into()
}
SemanticDiagnosticKind::AssignmentToReferencedVariable { .. } => {
"Cannot assign to a variable that has been referenced".into()
SemanticDiagnosticKind::AssignmentToReprPtrVariable { .. } => {
"Cannot assign to a variable with a taken pointer".into()
}
SemanticDiagnosticKind::StructBaseStructExpressionNotLast => {
"The base struct must always be the last argument.".into()
Expand Down Expand Up @@ -1156,7 +1156,7 @@ impl<'db> DiagnosticEntry<'db> for SemanticDiagnostic<'db> {
fn notes(&self, _db: &dyn Database) -> &[DiagnosticNote<'_>] {
match &self.kind {
SemanticDiagnosticKind::InnerFailedConstantCalculation(_, notes) => notes,
SemanticDiagnosticKind::AssignmentToReferencedVariable(notes) => notes,
SemanticDiagnosticKind::AssignmentToReprPtrVariable(notes) => notes,
_ => &[],
}
}
Expand Down Expand Up @@ -1512,10 +1512,10 @@ pub enum SemanticDiagnosticKind<'db> {
CouponArgumentNoModifiers,
/// Coupons are disabled in the current crate.
CouponsDisabled,
/// Reference types are disabled in the current crate.
ReferencesDisabled,
/// Cannot assign to a variable that has been referenced.
AssignmentToReferencedVariable(Vec<DiagnosticNote<'db>>),
/// Representation pointers are disabled in the current crate.
ReprPtrsDisabled,
/// Cannot assign to a variable with a taken pointer.
AssignmentToReprPtrVariable(Vec<DiagnosticNote<'db>>),
FixedSizeArrayTypeNonSingleType,
FixedSizeArrayTypeEmptySize,
FixedSizeArrayNonNumericSize,
Expand Down
12 changes: 6 additions & 6 deletions crates/cairo-lang-semantic/src/expr/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,14 +510,14 @@ impl<'ctx> VariableTracker<'ctx> {

if let Some(&referenced_at) = self.referenced_mut_vars.get(var_id) {
let note = DiagnosticNote::with_location(
"variable was referenced here".into(),
"variable pointer taken here".into(),
StableLocation::new(referenced_at).diagnostic_location(db),
);
diagnostics.report(error_ptr, AssignmentToReferencedVariable(vec![note]));
diagnostics.report(error_ptr, AssignmentToReprPtrVariable(vec![note]));
}
}

/// Marks an expression as referenced if it refers to a mutable variable.
/// Marks an expression as pointed to if it refers to a mutable variable.
pub fn mark_referenced(
&mut self,
expr: &ExprAndId<'ctx>,
Expand Down Expand Up @@ -1060,12 +1060,12 @@ fn compute_expr_unary_semantic<'db>(
}
(UnaryOperator::Reference(_), inner) => {
let stable_ptr = syntax.stable_ptr(db);
if !crate::types::are_references_enabled(ctx.db, ctx.resolver.module_id) {
return Err(ctx.diagnostics.report(stable_ptr, ReferencesDisabled));
if !crate::types::are_repr_ptrs_enabled(ctx.db, ctx.resolver.module_id) {
return Err(ctx.diagnostics.report(stable_ptr, ReprPtrsDisabled));
}
let inner_expr = compute_expr_semantic(ctx, inner);

// Disable mutability from referenced variable.
// Disable mutability from repr ptr variable.
ctx.variable_tracker.mark_referenced(&inner_expr, stable_ptr.untyped());

// Snapshot inner expression.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -681,11 +681,11 @@ FunctionCall(
)

//! > expected_diagnostics
error: Cannot assign to a variable that has been referenced
error: Cannot assign to a variable with a taken pointer
--> lib.cairo:7:18
modify_value(ref value)
^^^^^
note: variable was referenced here:
note: variable pointer taken here:
--> lib.cairo:6:9
let r = &value; {
^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion crates/cairo-lang-semantic/src/expr/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ cairo_lang_test_utils::test_file_test!(
range: "range",
const_: "const",
use_: "use",
reference: "reference",
repr_ptr: "repr_ptr",
},
test_expr_semantics
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,20 +279,20 @@ foo
//! > module_code

//! > expected_diagnostics
error: Cannot assign to a variable that has been referenced
error: Cannot assign to a variable with a taken pointer
--> lib.cairo:4:5
x = 5;
^^^^^
note: variable was referenced here:
note: variable pointer taken here:
--> lib.cairo:3:14
let _r = &x;
^^

error: Cannot assign to a variable that has been referenced
error: Cannot assign to a variable with a taken pointer
--> lib.cairo:8:5
y = 10;
^^^^^^
note: variable was referenced here:
note: variable pointer taken here:
--> lib.cairo:7:14
let _s = &y;
^^
2 changes: 1 addition & 1 deletion crates/cairo-lang-semantic/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ pub fn setup_test_crate_ex<'a>(
associated_item_constraints: true,
coupons: true,
user_defined_inline_macros: true,
references: true,
repr_ptrs: true,
},
cfg_set: Default::default(),
}
Expand Down
10 changes: 5 additions & 5 deletions crates/cairo-lang-semantic/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,8 @@ fn maybe_resolve_type<'db>(
ast::Expr::Unary(unary_syntax)
if matches!(unary_syntax.op(db), ast::UnaryOperator::Reference(_)) =>
{
if !are_references_enabled(db, resolver.module_id) {
return Err(diagnostics.report(ty_syntax.stable_ptr(db), ReferencesDisabled));
if !are_repr_ptrs_enabled(db, resolver.module_id) {
return Err(diagnostics.report(ty_syntax.stable_ptr(db), ReprPtrsDisabled));
}
let inner_ty = resolve_type_ex(db, diagnostics, resolver, &unary_syntax.expr(db), ctx);
let snapshot_ty = TypeLongId::Snapshot(inner_ty).intern(db);
Expand Down Expand Up @@ -1170,11 +1170,11 @@ pub(crate) fn are_coupons_enabled(db: &dyn Database, module_id: ModuleId<'_>) ->
config.settings.experimental_features.coupons
}

/// Returns `true` if reference types are enabled in the module.
pub(crate) fn are_references_enabled(db: &dyn Database, module_id: ModuleId<'_>) -> bool {
/// Returns `true` if representation pointers are enabled in the module.
pub(crate) fn are_repr_ptrs_enabled(db: &dyn Database, module_id: ModuleId<'_>) -> bool {
let owning_crate = module_id.owning_crate(db);
db.crate_config(owning_crate)
.is_some_and(|config| config.settings.experimental_features.references)
.is_some_and(|config| config.settings.experimental_features.repr_ptrs)
}

/// Trait for types-related semantic queries.
Expand Down