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
7 changes: 4 additions & 3 deletions api/python/slint/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::cell::RefCell;
use std::collections::HashMap;
use std::path::PathBuf;
use std::rc::Rc;
use std::sync::Arc;

use i_slint_compiler::generator::python::ident;
use pyo3::IntoPyObjectExt;
Expand Down Expand Up @@ -249,7 +250,7 @@ impl CompilationResult {
fn lookup_signature(
definition: &slint_interpreter::ComponentDefinition,
name: &str,
) -> Option<Rc<SlintFunction>> {
) -> Option<Arc<SlintFunction>> {
let normalized = normalize_identifier(name);
definition.properties_and_callbacks().find_map(|(prop_name, (ty, _))| {
(normalize_identifier(&prop_name) == normalized)
Expand All @@ -266,7 +267,7 @@ fn lookup_global_signature(
definition: &slint_interpreter::ComponentDefinition,
global_name: &str,
name: &str,
) -> Option<Rc<SlintFunction>> {
) -> Option<Arc<SlintFunction>> {
let normalized = normalize_identifier(name);
definition.global_properties_and_callbacks(global_name)?.find_map(|(prop_name, (ty, _))| {
(normalize_identifier(&prop_name) == normalized)
Expand Down Expand Up @@ -653,7 +654,7 @@ impl GcVisibleCallbacks {
&self,
name: String,
callable: Py<PyAny>,
signature: Option<Rc<SlintFunction>>,
signature: Option<Arc<SlintFunction>>,
) -> impl Fn(&[Value]) -> Value + 'static {
self.callables.borrow_mut().insert(name.clone(), callable);

Expand Down
2 changes: 1 addition & 1 deletion internal/compiler/benches/semantic_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ fn parse_source(source: &str) -> parser::SyntaxNode {
let mut diagnostics = BuildDiagnostics::default();
let tokens = i_slint_compiler::lexer::lex(source);
let source_file: SourceFile =
Rc::new(SourceFileInner::new(PathBuf::from("bench.slint"), source.to_string()));
Arc::new(SourceFileInner::new(PathBuf::from("bench.slint"), source.to_string()));
parser::parse_tokens(tokens, source_file, &mut diagnostics)
}

Expand Down
10 changes: 5 additions & 5 deletions internal/compiler/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use std::io::Read;
use std::path::{Path, PathBuf};
use std::rc::Rc;
use std::sync::Arc;

use crate::parser::TextSize;
use std::collections::BTreeSet;
Expand Down Expand Up @@ -73,7 +73,7 @@ pub struct SourceFileInner {
source: Option<String>,

/// The offset of each linebreak
line_offsets: std::cell::OnceCell<Vec<usize>>,
line_offsets: std::sync::OnceLock<Vec<usize>>,
}

impl std::fmt::Debug for SourceFileInner {
Expand All @@ -92,8 +92,8 @@ impl SourceFileInner {
}

/// Create a SourceFile that has just a path, but no contents
pub fn from_path_only(path: PathBuf) -> Rc<Self> {
Rc::new(Self { path, ..Default::default() })
pub fn from_path_only(path: PathBuf) -> Arc<Self> {
Arc::new(Self { path, ..Default::default() })
}

/// Returns a tuple with the line (starting at 1) and column number (starting at 1)
Expand Down Expand Up @@ -187,7 +187,7 @@ pub enum ByteFormat {
Utf16,
}

pub type SourceFile = Rc<SourceFileInner>;
pub type SourceFile = Arc<SourceFileInner>;

pub fn load_from_path(path: &Path) -> Result<String, Diagnostic> {
let string = (if path == Path::new("-") {
Expand Down
38 changes: 19 additions & 19 deletions internal/compiler/expression_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use smol_str::{SmolStr, format_smolstr};
use std::cell::Cell;
use std::collections::BTreeMap;
use std::rc::{Rc, Weak};
use std::sync::Arc;

// FIXME remove the pub
pub use crate::namedreference::NamedReference;
Expand Down Expand Up @@ -177,20 +178,20 @@ macro_rules! declare_builtin_function_types {
($( $Name:ident $(($Pattern:tt))? : ($( $Arg:expr ),*) -> $ReturnType:expr $(,)? )*) => {
#[allow(non_snake_case)]
pub struct BuiltinFunctionTypes {
$(pub $Name : Rc<Function>),*
$(pub $Name : Arc<Function>),*
}
impl BuiltinFunctionTypes {
pub fn new() -> Self {
Self {
$($Name : Rc::new(Function{
$($Name : Arc::new(Function{
args: vec![$($Arg),*],
return_type: $ReturnType,
arg_names: Vec::new(),
})),*
}
}

pub fn ty(&self, function: &BuiltinFunction) -> Rc<Function> {
pub fn ty(&self, function: &BuiltinFunction) -> Arc<Function> {
match function {
$(BuiltinFunction::$Name $(($Pattern))? => self.$Name.clone()),*
}
Expand Down Expand Up @@ -243,21 +244,21 @@ declare_builtin_function_types!(
StringEndsWith: (Type::String, Type::String) -> Type::Bool,
KeysToString: (Type::Keys) -> Type::String,
ImplicitLayoutInfo(..): (Type::ElementReference, Type::Float32) -> typeregister::layout_info_type().into(),
ColorRgbaStruct: (Type::Color) -> Type::Struct(Rc::new(Struct::new(IntoIterator::into_iter([
ColorRgbaStruct: (Type::Color) -> Type::Struct(Arc::new(Struct::new(IntoIterator::into_iter([
(SmolStr::new_static("red"), Type::Int32),
(SmolStr::new_static("green"), Type::Int32),
(SmolStr::new_static("blue"), Type::Int32),
(SmolStr::new_static("alpha"), Type::Int32),
])
.collect(), BuiltinStruct::Color))),
ColorHsvaStruct: (Type::Color) -> Type::Struct(Rc::new(Struct::new(IntoIterator::into_iter([
ColorHsvaStruct: (Type::Color) -> Type::Struct(Arc::new(Struct::new(IntoIterator::into_iter([
(SmolStr::new_static("hue"), Type::Float32),
(SmolStr::new_static("saturation"), Type::Float32),
(SmolStr::new_static("value"), Type::Float32),
(SmolStr::new_static("alpha"), Type::Float32),
])
.collect(), BuiltinStruct::Color))),
ColorOklchStruct: (Type::Color) -> Type::Struct(Rc::new(Struct::new(IntoIterator::into_iter([
ColorOklchStruct: (Type::Color) -> Type::Struct(Arc::new(Struct::new(IntoIterator::into_iter([
(SmolStr::new_static("lightness"), Type::Float32),
(SmolStr::new_static("chroma"), Type::Float32),
(SmolStr::new_static("hue"), Type::Float32),
Expand All @@ -269,7 +270,7 @@ declare_builtin_function_types!(
ColorTransparentize: (Type::Brush, Type::Float32) -> Type::Brush,
ColorWithAlpha: (Type::Brush, Type::Float32) -> Type::Brush,
ColorMix: (Type::Color, Type::Color, Type::Float32) -> Type::Color,
ImageSize: (Type::Image) -> Type::Struct(Rc::new(Struct::new(IntoIterator::into_iter([
ImageSize: (Type::Image) -> Type::Struct(Arc::new(Struct::new(IntoIterator::into_iter([
(SmolStr::new_static("width"), Type::Int32),
(SmolStr::new_static("height"), Type::Int32),
])
Expand All @@ -283,7 +284,7 @@ declare_builtin_function_types!(
Hsv: (Type::Float32, Type::Float32, Type::Float32, Type::Float32) -> Type::Color,
Oklch: (Type::Float32, Type::Float32, Type::Float32, Type::Float32) -> Type::Color,
ColorScheme: () -> Type::Enumeration(
typeregister::BUILTIN.with(|e| e.enums.ColorScheme.clone()),
typeregister::BUILTIN.enums.ColorScheme.clone(),
),
AccentColor: () -> Type::Color,
SupportsNativeMenuBar: () -> Type::Bool,
Expand All @@ -295,9 +296,9 @@ declare_builtin_function_types!(
MonthOffset: (Type::Int32, Type::Int32) -> Type::Int32,
FormatDate: (Type::String, Type::Int32, Type::Int32, Type::Int32) -> Type::String,
TextInputFocused: () -> Type::Bool,
DateNow: () -> Type::Array(Rc::new(Type::Int32)),
DateNow: () -> Type::Array(Arc::new(Type::Int32)),
ValidDate: (Type::String, Type::String) -> Type::Bool,
ParseDate: (Type::String, Type::String) -> Type::Array(Rc::new(Type::Int32)),
ParseDate: (Type::String, Type::String) -> Type::Array(Arc::new(Type::Int32)),
SetTextInputFocused: (Type::Bool) -> Type::Void,
ItemAbsolutePosition: (Type::ElementReference) -> typeregister::logical_point_type().into(),
RegisterCustomFontByPath: (Type::String) -> Type::Void,
Expand All @@ -308,7 +309,7 @@ declare_builtin_function_types!(
Use24HourFormat: () -> Type::Bool,
UpdateTimers: () -> Type::Void,
DetectOperatingSystem: () -> Type::Enumeration(
typeregister::BUILTIN.with(|e| e.enums.OperatingSystemType.clone()),
typeregister::BUILTIN.enums.OperatingSystemType.clone(),
),
StartTimer: (Type::ElementReference) -> Type::Void,
StopTimer: (Type::ElementReference) -> Type::Void,
Expand All @@ -327,11 +328,10 @@ impl Default for BuiltinFunctionTypes {
}

impl BuiltinFunction {
pub fn ty(&self) -> Rc<Function> {
thread_local! {
static TYPES: BuiltinFunctionTypes = BuiltinFunctionTypes::new();
}
TYPES.with(|types| types.ty(self))
pub fn ty(&self) -> Arc<Function> {
static TYPES: std::sync::LazyLock<BuiltinFunctionTypes> =
std::sync::LazyLock::new(BuiltinFunctionTypes::new);
TYPES.ty(self)
}

/// It is const if the return value only depends on its argument and has no side effect
Expand Down Expand Up @@ -848,7 +848,7 @@ pub enum Expression {
values: Vec<Expression>,
},
Struct {
ty: Rc<Struct>,
ty: Arc<Struct>,
values: BTreeMap<SmolStr, Expression>,
},

Expand Down Expand Up @@ -1080,7 +1080,7 @@ impl Expression {
}
}
Expression::UnaryOp { sub, .. } => sub.ty(),
Expression::Array { element_ty, .. } => Type::Array(Rc::new(element_ty.clone())),
Expression::Array { element_ty, .. } => Type::Array(Arc::new(element_ty.clone())),
Expression::Struct { ty, .. } => ty.clone().into(),
Expression::PathData { .. } => Type::PathData,
Expression::EmptyDataTransfer => Type::DataTransfer,
Expand Down Expand Up @@ -1763,7 +1763,7 @@ impl Expression {
},
Type::Easing => Expression::EasingCurve(EasingCurve::default()),
Type::MouseCursor => {
let e = crate::typeregister::BUILTIN.with(|e| e.enums.BuiltInMouseCursor.clone());
let e = crate::typeregister::BUILTIN.enums.BuiltInMouseCursor.clone();
Expression::MouseCursor(MouseCursorInner::BuiltIn(Box::new(
Expression::EnumerationValue(e.default_value()),
)))
Expand Down
17 changes: 9 additions & 8 deletions internal/compiler/generator/cpp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,7 @@ fn generate_struct(
unit: &llr::CompilationUnit,
conditional_includes: &ConditionalIncludes,
) {
let StructName::User { name: user_name, node } = &the_struct.name else {
let StructName::User { name: user_name, .. } = &the_struct.name else {
panic!("internal error: Cannot generate anonymous struct");
};
// Constant expressions cannot access the globals; make sure a bug in that
Expand All @@ -1342,13 +1342,14 @@ fn generate_struct(
},
);
let name = ident(user_name);
let mut members = node
.ObjectTypeMember()
.map(|n| crate::parser::identifier_text(&n).unwrap())
// Emit members in declaration order: C++ users initialize structs positionally.
let mut members = the_struct
.field_order()
.iter()
.map(|name| {
// When any field has a declared default value, initialize the remaining fields, too,
// so that default construction is fully deterministic, like in the other language backends.
let init = match the_struct.field_defaults.get(&name) {
let init = match the_struct.field_defaults.get(name) {
Some(default_value) => {
Some(compile_expression(&lower_constant_expression(default_value), &ctx))
}
Expand All @@ -1358,8 +1359,8 @@ fn generate_struct(
(
Access::Public,
Declaration::Var(Var {
ty: the_struct.fields.get(&name).unwrap().cpp_type().unwrap(),
name: ident(&name),
ty: the_struct.fields.get(name).unwrap().cpp_type().unwrap(),
name: ident(name),
init,
..Default::default()
}),
Expand All @@ -1381,7 +1382,7 @@ fn generate_struct(
file.declarations.push(Declaration::Struct(Struct { name, members, ..Default::default() }))
}

fn generate_enum(file: &mut File, en: &std::rc::Rc<Enumeration>) {
fn generate_enum(file: &mut File, en: &std::sync::Arc<Enumeration>) {
file.declarations.push(Declaration::Enum(Enum {
name: ident(&en.name),
values: (0..en.values.len())
Expand Down
11 changes: 6 additions & 5 deletions internal/compiler/generator/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
// cSpell:ignore cmath constexpr cstdlib decltype intptr itertools nullptr prepended struc subcomponent uintptr vals enumty fundecl pycompo pyenum structty

use std::collections::HashMap;
use std::collections::HashSet;
use std::sync::Arc;
use std::sync::OnceLock;
use std::{collections::HashSet, rc::Rc};

use smol_str::{SmolStr, StrExt, format_smolstr};

Expand Down Expand Up @@ -154,10 +155,10 @@ pub struct PyStruct {

pub struct AnonymousStruct;

impl TryFrom<&Rc<crate::langtype::Struct>> for PyStruct {
impl TryFrom<&Arc<crate::langtype::Struct>> for PyStruct {
type Error = AnonymousStruct;

fn try_from(structty: &Rc<crate::langtype::Struct>) -> Result<Self, Self::Error> {
fn try_from(structty: &Arc<crate::langtype::Struct>) -> Result<Self, Self::Error> {
let StructName::User { name, .. } = &structty.name else {
return Err(AnonymousStruct);
};
Expand Down Expand Up @@ -234,8 +235,8 @@ pub struct PyEnum {
aliases: Vec<SmolStr>,
}

impl From<&Rc<crate::langtype::Enumeration>> for PyEnum {
fn from(enumty: &Rc<crate::langtype::Enumeration>) -> Self {
impl From<&Arc<crate::langtype::Enumeration>> for PyEnum {
fn from(enumty: &Arc<crate::langtype::Enumeration>) -> Self {
Self {
name: ident(&enumty.name),
variants: enumty
Expand Down
Loading
Loading