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

Directly use C2 apis from CPP2 #495

Merged
merged 5 commits into from
Jun 13, 2024
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
12 changes: 3 additions & 9 deletions core/src/hir/defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,9 @@ impl EnumDef {
}
}

impl<'a> From<&'a StructDef> for TypeDef<'a> {
fn from(x: &'a StructDef) -> Self {
TypeDef::Struct(x)
}
}

impl<'a> From<&'a OutStructDef> for TypeDef<'a> {
fn from(x: &'a OutStructDef) -> Self {
TypeDef::OutStruct(x)
impl<'a, P: TyPosition> From<&'a StructDef<P>> for TypeDef<'a> {
fn from(x: &'a StructDef<P>) -> Self {
P::wrap_struct_def(x)
}
}

Expand Down
19 changes: 16 additions & 3 deletions core/src/hir/ty_position.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::lifetimes::{Lifetime, Lifetimes, MaybeStatic};
use super::{
Borrow, LinkedLifetimes, MaybeOwn, Mutability, OutStructId, ReturnableStructPath, StructId,
StructPath, TypeContext, TypeId,
Borrow, LinkedLifetimes, MaybeOwn, Mutability, OutStructId, ReturnableStructPath, StructDef,
StructId, StructPath, TypeContext, TypeDef, TypeId,
};
use core::fmt::Debug;

Expand Down Expand Up @@ -87,7 +87,10 @@ use core::fmt::Debug;
/// Therefore, this trait allows be extremely precise about making invalid states
/// unrepresentable, while also reducing duplicated code.
///
pub trait TyPosition: Debug + Copy {
pub trait TyPosition: Debug + Copy
where
for<'tcx> TypeDef<'tcx>: From<&'tcx StructDef<Self>>,
{
const IS_OUT_ONLY: bool;

/// Type representing how we can point to opaques, which must always be behind a pointer.
Expand All @@ -102,6 +105,8 @@ pub trait TyPosition: Debug + Copy {
type StructId: Debug;

type StructPath: Debug + StructPathLike;

fn wrap_struct_def<'tcx>(def: &'tcx StructDef<Self>) -> TypeDef<'tcx>;
}

/// One of two types implementing [`TyPosition`], representing types that can be
Expand All @@ -125,13 +130,21 @@ impl TyPosition for Everywhere {
type OpaqueOwnership = Borrow;
type StructId = StructId;
type StructPath = StructPath;

fn wrap_struct_def<'tcx>(def: &'tcx StructDef<Self>) -> TypeDef<'tcx> {
TypeDef::Struct(def)
}
}

impl TyPosition for OutputOnly {
const IS_OUT_ONLY: bool = true;
type OpaqueOwnership = MaybeOwn;
type StructId = OutStructId;
type StructPath = ReturnableStructPath;

fn wrap_struct_def<'tcx>(def: &'tcx StructDef<Self>) -> TypeDef<'tcx> {
TypeDef::OutStruct(def)
}
}

pub trait StructPathLike {
Expand Down
20 changes: 0 additions & 20 deletions example/cpp2/include/ICU4XDataProvider.d.h

This file was deleted.

5 changes: 4 additions & 1 deletion example/cpp2/include/ICU4XDataProvider.d.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 0 additions & 30 deletions example/cpp2/include/ICU4XDataProvider.h

This file was deleted.

15 changes: 14 additions & 1 deletion example/cpp2/include/ICU4XDataProvider.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 0 additions & 20 deletions example/cpp2/include/ICU4XFixedDecimal.d.h

This file was deleted.

5 changes: 4 additions & 1 deletion example/cpp2/include/ICU4XFixedDecimal.d.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 0 additions & 32 deletions example/cpp2/include/ICU4XFixedDecimal.h

This file was deleted.

17 changes: 16 additions & 1 deletion example/cpp2/include/ICU4XFixedDecimal.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 0 additions & 20 deletions example/cpp2/include/ICU4XFixedDecimalFormatter.d.h

This file was deleted.

5 changes: 4 additions & 1 deletion example/cpp2/include/ICU4XFixedDecimalFormatter.d.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 0 additions & 34 deletions example/cpp2/include/ICU4XFixedDecimalFormatter.h

This file was deleted.

15 changes: 14 additions & 1 deletion example/cpp2/include/ICU4XFixedDecimalFormatter.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 0 additions & 24 deletions example/cpp2/include/ICU4XFixedDecimalFormatterOptions.d.h

This file was deleted.

Loading
Loading