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

API: Removed the CallableData trait #265

Merged
merged 2 commits into from
Oct 1, 2023
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ See the [v0.3.0 milestone] for a full list of all changes.
[#252]: https://github.com/rust-marker/marker/pull/252
[#256]: https://github.com/rust-marker/marker/pull/256
[#263]: https://github.com/rust-marker/marker/pull/263
[#265]: https://github.com/rust-marker/marker/pull/265

### Added
- [#232]: Add scope config for visitors and `for_each_expr` to `marker_utils`
Expand All @@ -50,6 +51,7 @@ See the [v0.3.0 milestone] for a full list of all changes.
- [#244]: `StmtKind` and `PatKind` no longer wrap `Kind*` directly
- [#245]: `emit_lint()` takes less arguments and returns a `DiagnosticBuilder` instance
- [#263]: Updated the [`ui_test`](https://crates.io/crates/ui_test) used by `marker_uitest` from `v0.11.7` to `v0.21.2`
- [#265]: Removed the `CallableData` trait

### Internal

Expand Down
2 changes: 0 additions & 2 deletions marker_api/src/ast/common.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
mod id;
pub use id::*;
mod callable;
pub use callable::*;
mod ast_path;
pub use ast_path::*;

Expand Down
165 changes: 0 additions & 165 deletions marker_api/src/ast/common/callable.rs

This file was deleted.

7 changes: 1 addition & 6 deletions marker_api/src/ast/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ pub enum SynTyKind<'ast> {
/// A variable length slice like [`[T]`](prim@slice)
Slice(&'ast SynSliceTy<'ast>),
// ================================
// Function types
// ================================
Closure(&'ast SynClosureTy<'ast>),
// ================================
// Pointer types
// ================================
/// A reference like [`&T`](prim@reference) or [`&mut T`](prim@reference)
Expand Down Expand Up @@ -119,7 +115,7 @@ impl<'ast> SynTyKind<'ast> {
/// Returns `true` if this is a function type.
#[must_use]
pub fn is_fn(&self) -> bool {
matches!(self, Self::FnPtr(..) | Self::Closure(..))
matches!(self, Self::FnPtr(..))
}

/// Returns `true` if this is a pointer type.
Expand Down Expand Up @@ -151,7 +147,6 @@ macro_rules! impl_syn_ty_data_fn {
impl_syn_ty_data_fn!($method() -> $return_ty,
Bool, Num, Text, Never,
Tuple, Array, Slice,
Closure,
Ref, RawPtr, FnPtr,
TraitObj, ImplTrait,
Inferred, Path
Expand Down
24 changes: 1 addition & 23 deletions marker_api/src/ast/ty/fn_ty.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use crate::ast::{generic::SemGenericArgs, impl_callable_data_trait, CommonCallableData, ItemId, TyDefId};

use super::CommonSynTyData;
use crate::ast::{generic::SemGenericArgs, ItemId, TyDefId};

/// A [function item type](https://doc.rust-lang.org/reference/types/function-item.html)
/// identifying a specific function and potentualy additional generics.
Expand Down Expand Up @@ -30,26 +28,6 @@ impl<'ast> SemFnTy<'ast> {
}
}

/// The syntactic representation of a
/// [closure type](https://doc.rust-lang.org/reference/types/closure.html).
Copy link
Contributor

Choose a reason for hiding this comment

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

That's weird how there could be a syntactic representation of a closure type because there is no syntax to denote a type of the closure except for impl Fn*. However, impl Fn* should not be coupled with closures, that's a broader concept.

So I wonder what this struct represented then

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't actually know anymore why I added this struct. My guess is that this is a left over from an old architecture. There was a time, where I planned to merge both syntactic and semantic types into a single representation. My idea was that this would make it easier, to work with types. Then you could compare syntactic and semantic types etc.

However, while working on semantic types, I quickly noticed that these are way more different than I thought. It also became clear that this combination will most likely be painful for everyone involved, with very few benefits.

During the move to split semantic and syntactic types, I just added the Syn prefix to most types. The struct might have been intended to be a semantic type, but got caught in the crossfire.

#[repr(C)]
#[derive(Debug)]
pub struct SynClosureTy<'ast> {
data: CommonSynTyData<'ast>,
callable_data: CommonCallableData<'ast>,
// FIXME: Add support for `for<'lifetime>` binder
}

#[cfg(feature = "driver-api")]
impl<'ast> SynClosureTy<'ast> {
pub fn new(data: CommonSynTyData<'ast>, callable_data: CommonCallableData<'ast>) -> Self {
Self { data, callable_data }
}
}

super::impl_ty_data!(SynClosureTy<'ast>, Closure);
impl_callable_data_trait!(SynClosureTy<'ast>);

/// The semantic representation of a
/// [closure type](https://doc.rust-lang.org/reference/types/closure.html).
///
Expand Down
69 changes: 62 additions & 7 deletions marker_api/src/ast/ty/ptr_ty.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use crate::{
ast::{generic::Lifetime, impl_callable_data_trait, Abi, CommonCallableData, Mutability, Safety},
ast::{generic::Lifetime, Abi, Mutability, Safety, SpanId},
context::with_cx,
ffi::{FfiOption, FfiSlice},
private::Sealed,
span::{HasSpan, Ident},
};

use super::{CommonSynTyData, SemTyKind, SynTyKind};
Expand Down Expand Up @@ -141,24 +144,76 @@ impl<'ast> SemRawPtrTy<'ast> {
}
}

/// The semantic representation of a function pointer, like [`fn (T) -> U`](prim@fn)
/// The syntactic representation of a function pointer, like [`fn (T) -> U`](prim@fn)
#[repr(C)]
#[derive(Debug)]
#[cfg_attr(feature = "driver-api", derive(typed_builder::TypedBuilder))]
pub struct SynFnPtrTy<'ast> {
data: CommonSynTyData<'ast>,
callable_data: CommonCallableData<'ast>,
safety: Safety,
abi: Abi,
#[cfg_attr(feature = "driver-api", builder(setter(into)))]
params: FfiSlice<'ast, FnTyParameter<'ast>>,
#[cfg_attr(feature = "driver-api", builder(setter(into)))]
return_ty: FfiOption<SynTyKind<'ast>>,
// FIXME: Add `for<'a>` bound
}

#[cfg(feature = "driver-api")]
impl<'ast> SynFnPtrTy<'ast> {
pub fn new(data: CommonSynTyData<'ast>, callable_data: CommonCallableData<'ast>) -> Self {
Self { data, callable_data }
/// Returns the [`Safety`] of this callable.
///
/// Use this to check if the function is `unsafe`.
pub fn safety(&self) -> Safety {
self.safety
}

/// Returns the [`Abi`] of the callable.
pub fn abi(&self) -> Abi {
self.abi
}

/// Returns the [`FnTyParameter`]s this function pointer accepts.
pub fn params(&self) -> &[FnTyParameter<'ast>] {
self.params.get()
}

/// The return type of this function pointer, if specified.
pub fn return_ty(&self) -> Option<&SynTyKind<'ast>> {
self.return_ty.get()
}
}

super::impl_ty_data!(SynFnPtrTy<'ast>, FnPtr);
impl_callable_data_trait!(SynFnPtrTy<'ast>);

/// A parameter for the [`SynFnPtrTy`].
#[repr(C)]
#[derive(Debug)]
#[cfg_attr(feature = "driver-api", derive(typed_builder::TypedBuilder))]
pub struct FnTyParameter<'ast> {
#[cfg_attr(feature = "driver-api", builder(setter(into)))]
ident: FfiOption<Ident<'ast>>,
span: SpanId,
ty: SynTyKind<'ast>,
}

impl<'ast> FnTyParameter<'ast> {
/// Returns the [`Ident`] of the parameter, if specified.
pub fn ident(&self) -> Option<&Ident<'ast>> {
self.ident.get()
}

/// The syntactic type of this parameter.
pub fn ty(&self) -> SynTyKind<'ast> {
self.ty
}
}

impl Sealed for FnTyParameter<'_> {}
impl<'ast> HasSpan<'ast> for FnTyParameter<'ast> {
fn span(&self) -> &crate::span::Span<'ast> {
with_cx(self, |cx| cx.span(self.span))
}
}

/// The semantic representation of a function pointer, like [`fn (T) -> U`](prim@fn)
#[repr(C)]
Expand Down
Loading