Skip to content

Commit

Permalink
Add check for type redefinition
Browse files Browse the repository at this point in the history
When using the debugger it may occur that the same
type is loaded from different assemblies. This commit
adds checks to avoid conflicts and duplication
in such scenarios.
  • Loading branch information
hyazinthh committed Jul 6, 2023
1 parent 37415a1 commit 9c9ca73
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Libs/FShade.Imperative/Compiler.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1388,13 +1388,13 @@ module Compiler =

| NewTuple(fields) ->
let! s = State.get
let! ctor = e.Type |> Constructors.tuple s.moduleState.backend |> CompilerState.useCtor e.Type
let! ctor = e.Type |> Constructors.tuple s.moduleState.backend |> CompilerState.useCtor (typeName e.Type)
let! fields = fields |> List.mapS toCExprS |>> List.toArray
return CCall(ctor, fields)

| NewRecord(t, fields) ->
let! s = State.get
let! ctor = t |> Constructors.record s.moduleState.backend |> CompilerState.useCtor t
let! ctor = t |> Constructors.record s.moduleState.backend |> CompilerState.useCtor (typeName t)
let! fields = fields |> List.mapS toCExprS |>> List.toArray
return CCall(ctor, fields)

Expand Down
16 changes: 15 additions & 1 deletion src/Libs/FShade.Imperative/ModuleCompiler.fs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,21 @@ module ModuleCompiler =
let set = System.Collections.Generic.HashSet()
for t in graphs do visit set t

set |> Seq.toArray |> Array.sort |> Array.toList |> List.choose (fun t -> t.Definition)
set
|> Seq.toArray
|> Array.sort
|> Array.toList
|> List.choose (fun t -> t.Definition)
|> List.distinct
|> List.groupBy (fun (CStructDef(n, _)) -> n)
|> List.map (fun (n, defs) ->
if defs.Length > 1 then
let nl = Environment.NewLine
let defs = defs |> List.map string |> String.concat nl
failwithf $"[FShade] Multiple conflicting type definitions with name {n}:{nl}{defs}"
else
defs.Head
)

let ofTypes (types : list<CType>) =
let compile =
Expand Down

0 comments on commit 9c9ca73

Please sign in to comment.