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

[Rust] Fixed interface genArgs lookup #3922

Merged
merged 1 commit into from
Oct 9, 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
33 changes: 20 additions & 13 deletions src/Fable.Transforms/Rust/Fable2Rust.fs
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,8 @@ module TypeInfo =
| _ -> isTypeOfType com isDefaultableType isDefaultableEntity entNames typ

let isDefaultableEntity com entNames (ent: Fable.Entity) =
not (ent.IsInterface)
ent.IsValueType
&& not (ent.IsInterface)
&& not (ent.IsFSharpUnion) // deriving 'Default' on enums is experimental
&& (isEntityOfType com isDefaultableType entNames ent)

Expand Down Expand Up @@ -4046,7 +4047,7 @@ module Util =

loop body

let makeAssocMemberItem
let makeMemberAssocItem
com
ctx
(memb: Fable.MemberFunctionOrValue)
Expand Down Expand Up @@ -4393,7 +4394,7 @@ module Util =
else
None

makeAssocMemberItem com ctx memb args bodyOpt
makeMemberAssocItem com ctx memb args bodyOpt
)

let transformInterface (com: IRustCompiler) ctx (ent: Fable.Entity) (decl: Fable.ClassDecl) =
Expand Down Expand Up @@ -4664,12 +4665,19 @@ module Util =
// "ToString"
// ]

let ignoredInterfaceNames = set [ Types.ienumerable; Types.ienumerator ]
let findInterfaceGenArgs (com: IRustCompiler) (ent: Fable.Entity) (ifcEntRef: Fable.EntityRef) =
let ifcOpt =
ent.AllInterfaces
|> Seq.tryFind (fun ifc -> ifc.Entity.FullName = ifcEntRef.FullName)

let getDeclaringEntities (members: Fable.MemberFunctionOrValue list) =
members
|> List.choose (fun memb -> memb.DeclaringEntity)
|> List.distinctBy (fun entRef -> entRef.FullName)
match ifcOpt with
| Some ifc -> ifc.GenericArgs
| _ ->
// shouldn't really happen
let ifcEnt = com.GetEntity(ifcEntRef)
FSharp2Fable.Util.getEntityGenArgs ifcEnt

let ignoredInterfaceNames = set [ Types.ienumerable; Types.ienumerator ]

let transformClassMembers (com: IRustCompiler) ctx genArgs (classDecl: Fable.ClassDecl) =
let entRef = classDecl.Entity
Expand Down Expand Up @@ -4735,19 +4743,18 @@ module Util =

let interfaceTraitImpls =
interfaceMembers
|> List.map snd
|> getDeclaringEntities
|> List.choose (fun (d, m) -> m.DeclaringEntity)
|> List.distinctBy (fun ifcEntRef -> ifcEntRef.FullName)
|> List.filter (fun ifcEntRef ->
// throws out anything on the ignored interfaces list
not (ignoredInterfaceNames |> Set.contains ifcEntRef.FullName)
)
|> List.collect (fun ifcEntRef ->
let ifcGenArgs =
if ent.IsInterface then
if isObjectExpr then
genArgs
else
let ifcEnt = com.GetEntity(ifcEntRef)
FSharp2Fable.Util.getEntityGenArgs ifcEnt
ifcEntRef |> findInterfaceGenArgs com ent

let memberNames = getInterfaceMemberNames com ifcEntRef

Expand Down
16 changes: 8 additions & 8 deletions src/fable-library-rust/src/HashMap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ pub mod HashMap_ {
comparer: LrcPtr<dyn IEqualityComparer_1<K>>,
}

impl<K, V: Clone> Default for HashMap<K, V>
where
K: Clone + Hash + PartialEq + 'static,
{
fn default() -> HashMap<K, V> {
new_empty()
}
}
// impl<K, V: Clone> Default for HashMap<K, V>
// where
// K: Clone + Hash + PartialEq + 'static,
// {
// fn default() -> HashMap<K, V> {
// new_empty()
// }
// }

impl<K: Clone, V: Clone> core::ops::Deref for HashMap<K, V> {
type Target = Lrc<MutHashMap<K, V>>;
Expand Down
16 changes: 8 additions & 8 deletions src/fable-library-rust/src/HashSet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ pub mod HashSet_ {
comparer: LrcPtr<dyn IEqualityComparer_1<T>>,
}

impl<T> Default for HashSet<T>
where
T: Clone + Hash + PartialEq + 'static,
{
fn default() -> HashSet<T> {
new_empty()
}
}
// impl<T> Default for HashSet<T>
// where
// T: Clone + Hash + PartialEq + 'static,
// {
// fn default() -> HashSet<T> {
// new_empty()
// }
// }

impl<T: Clone> core::ops::Deref for HashSet<T> {
type Target = Lrc<MutHashSet<T>>;
Expand Down
Loading